Skip to content

Commit 782a4b7

Browse files
committed
Download data model files before editing data model
1 parent 98a6d8c commit 782a4b7

File tree

10 files changed

+95
-2
lines changed

10 files changed

+95
-2
lines changed

src/Pixel.Automation.Designer.ViewModels/AutomationBuilder/AutomationEditorViewModel.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ public override async Task EditDataModelAsync()
9999
try
100100
{
101101
logger.Information($"Opening code editor for editing data model for project : {this.CurrentProject.Name}");
102+
await this.projectManager.DownloadDataModelFilesAsync();
102103
var editorFactory = this.EntityManager.GetServiceOfType<ICodeEditorFactory>();
103104
var projectFileSystem = this.projectManager.GetProjectFileSystem();
104105
using (var editor = editorFactory.CreateMultiCodeEditorScreen())

src/Pixel.Automation.Designer.ViewModels/AutomationBuilder/AutomationProjectManager.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,12 @@ public override async Task DeleteDataFileAsync(string fileToDelete)
197197
await this.projectDataManager.DeleteDataFileAsync(this.activeProject, this.loadedVersion as ProjectVersion, fileToDelete);
198198
}
199199

200+
///<inheritdoc/>
201+
public override async Task DownloadDataModelFilesAsync()
202+
{
203+
await this.projectDataManager.DownloadDataModelFilesAsync(this.activeProject, this.loadedVersion as ProjectVersion);
204+
}
205+
200206
///<inheritdoc/>
201207
protected override string GetProjectName()
202208
{

src/Pixel.Automation.Designer.ViewModels/AutomationBuilder/PrefabEditorViewModel.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public async Task DoLoad(PrefabProject prefabProject, VersionInfo versionToLoad
6161
/// <returns></returns>
6262
public override async Task EditDataModelAsync()
6363
{
64+
await this.projectManager.DownloadDataModelFilesAsync();
6465
var editorFactory = this.EntityManager.GetServiceOfType<ICodeEditorFactory>();
6566
var prefabFileSystem = this.projectManager.GetProjectFileSystem();
6667
using (var editor = editorFactory.CreateMultiCodeEditorScreen())

src/Pixel.Automation.Designer.ViewModels/AutomationBuilder/PrefabProjectManager.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,12 @@ public override async Task DeleteDataFileAsync(string fileToDelete)
222222
await this.prefabDataManager.DeleteDataFileAsync(this.prefabProject, this.loadedVersion, fileToDelete);
223223
}
224224

225+
///<inheritdoc/>
226+
public override async Task DownloadDataModelFilesAsync()
227+
{
228+
await this.prefabDataManager.DownloadDataModelFilesAsync(this.prefabProject, this.loadedVersion);
229+
}
230+
225231
/// <inheritdoc/>
226232
protected override string GetProjectName()
227233
{

src/Pixel.Automation.Designer.ViewModels/AutomationBuilder/ProjectManager.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ public ProjectManager(ISerializer serializer, IEntityManager entityManager, IFil
7373
///<inheritdoc/>
7474
public abstract Task DeleteDataFileAsync(string fileToDelete);
7575

76+
///<inheritdoc/>
77+
public abstract Task DownloadDataModelFilesAsync();
78+
7679
///<inheritdoc/>
7780
public abstract Task Save();
7881

src/Pixel.Automation.Editor.Core/Interfaces/IProjectManager.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ public interface IProjectManager
3434
/// <returns></returns>
3535
Task DeleteDataFileAsync(string fileToDelete);
3636

37+
/// <summary>
38+
/// Download the data model files (*.cs) belonging the the loaded version of project
39+
/// </summary>
40+
/// <returns></returns>
41+
Task DownloadDataModelFilesAsync();
42+
3743
/// <summary>
3844
/// Deserialize the contents of a file to given type while ensuring that any references to data model assembly in file are replaced with current session's
3945
/// data model assembly. Use this to load a process file, prefab file or a test file.

src/Pixel.Persistence.Services.Client/DataManagers/PrefabDataManager.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,33 @@ bool HasMostRecentDataAlreadyAvailable()
134134
}
135135
}
136136

137+
/// <inheritdoc/>
138+
public async Task DownloadDataModelFilesAsync(PrefabProject prefabProject, PrefabVersion prefabVersion)
139+
{
140+
Guard.Argument(prefabProject, nameof(prefabProject)).NotNull();
141+
Guard.Argument(prefabVersion, nameof(prefabVersion)).NotNull();
142+
143+
if (IsOnlineMode)
144+
{
145+
var dataModelsDirectory = Path.Combine(this.applicationFileSystem.GetPrefabProjectWorkingDirectory(prefabProject, prefabVersion), Constants.DataModelDirectory);
146+
if (Directory.Exists(dataModelsDirectory))
147+
{
148+
Directory.Delete(dataModelsDirectory, true);
149+
}
150+
Directory.CreateDirectory(dataModelsDirectory);
151+
var zippedContent = await this.filesClient.DownloadProjectDataFilesOfType(prefabProject.PrefabId, prefabVersion.ToString(), "cs");
152+
if (zippedContent.Length > 0)
153+
{
154+
string versionDirectory = this.applicationFileSystem.GetPrefabProjectWorkingDirectory(prefabProject, prefabVersion);
155+
using (var memoryStream = new MemoryStream(zippedContent, false))
156+
{
157+
var zipArchive = new ZipArchive(memoryStream, ZipArchiveMode.Read);
158+
zipArchive.ExtractToDirectory(versionDirectory, true);
159+
}
160+
}
161+
}
162+
}
163+
137164
///<inheritdoc/>
138165
public async Task DownloadPrefabsAsync()
139166
{

src/Pixel.Persistence.Services.Client/DataManagers/ProjectDataManager.cs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,33 @@ public async Task DownloadProjectDataFilesAsync(AutomationProject automationProj
104104
}
105105
}
106106

107+
/// <inheritdoc/>
108+
public async Task DownloadDataModelFilesAsync(AutomationProject automationProject, ProjectVersion projectVersion)
109+
{
110+
Guard.Argument(automationProject, nameof(automationProject)).NotNull();
111+
Guard.Argument(projectVersion, nameof(projectVersion)).NotNull();
112+
113+
if (IsOnlineMode)
114+
{
115+
var dataModelsDirectory = Path.Combine(this.applicationFileSystem.GetAutomationProjectWorkingDirectory(automationProject, projectVersion), Constants.DataModelDirectory);
116+
if (Directory.Exists(dataModelsDirectory))
117+
{
118+
Directory.Delete(dataModelsDirectory, true);
119+
}
120+
Directory.CreateDirectory(dataModelsDirectory);
121+
var zippedContent = await this.filesClient.DownloadProjectDataFilesOfType(automationProject.ProjectId, projectVersion.ToString(), "cs");
122+
if (zippedContent.Length > 0)
123+
{
124+
string versionDirectory = this.applicationFileSystem.GetAutomationProjectWorkingDirectory(automationProject, projectVersion);
125+
using (var memoryStream = new MemoryStream(zippedContent, false))
126+
{
127+
var zipArchive = new ZipArchive(memoryStream, ZipArchiveMode.Read);
128+
zipArchive.ExtractToDirectory(versionDirectory, true);
129+
}
130+
}
131+
}
132+
}
133+
107134
/// <summary>
108135
/// Download all the files having specific tags belonging to the version of the AutomationProject being managed
109136
/// </summary>
@@ -141,7 +168,7 @@ async Task DownloadFilesWithTagsAsync(AutomationProject automationProject, Proje
141168
}
142169
}
143170
}
144-
171+
145172
/// <inheritdoc/>
146173
public IEnumerable<AutomationProject> GetAllProjects()
147174
{

src/Pixel.Persistence.Services.Client/Interfaces/IPrefabDataManager.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ public interface IPrefabDataManager
4444
/// <returns></returns>
4545
Task DownloadPrefabDataAsync(PrefabProject prefabProject, PrefabVersion prefabVersion);
4646

47+
/// <summary>
48+
/// Download dta model files (*.cs) for a given version of prefab
49+
/// </summary>
50+
/// <param name="prefabProject"></param>
51+
/// <param name="prefabVersion"></param>
52+
/// <returns></returns>
53+
Task DownloadDataModelFilesAsync(PrefabProject prefabProject, PrefabVersion prefabVersion);
54+
4755
/// <summary>
4856
/// Add a new prefab
4957
/// </summary>

src/Pixel.Persistence.Services.Client/Interfaces/IProjectDataManager.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,19 @@ public interface IProjectDataManager
6666

6767

6868
/// <summary>
69-
/// Download all the data files belong to the version of AutomationProject being managed
69+
/// Download all the data files belonging to the version of AutomationProject being managed
7070
/// </summary>
7171
/// <returns></returns>
7272
Task DownloadProjectDataFilesAsync(AutomationProject automationProject, ProjectVersion projectVersion);
7373

74+
/// <summary>
75+
/// Download data model files (*.cs) belonging to the version of AutomationProject being managed
76+
/// </summary>
77+
/// <param name="automationProject"></param>
78+
/// <param name="projectVersion"></param>
79+
/// <returns></returns>
80+
Task DownloadDataModelFilesAsync(AutomationProject automationProject, ProjectVersion projectVersion);
81+
7482
/// <summary>
7583
/// Save the data files belonging to the version of AutomationProject being managed
7684
/// </summary>

0 commit comments

Comments
 (0)