Skip to content

Commit 29bed63

Browse files
authored
Merge pull request #190 from Nfactor26/download-latest-data-model-and-initialize-script-files-before-editing
Download latest data model and initialize script files before editing
2 parents 91ddf80 + 7f530ff commit 29bed63

File tree

18 files changed

+266
-25
lines changed

18 files changed

+266
-25
lines changed

src/Pixel.Automation.AppExplorer.ViewModels/Pixel.Automation.AppExplorer.ViewModels.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
<ProjectReference Include="..\Pixel.Automation.Editor.Notifications\Pixel.Automation.Editor.Notifications.csproj" />
2525
<ProjectReference Include="..\Pixel.Persistence.Services.Client\Pixel.Persistence.Services.Client.csproj" />
2626
<ProjectReference Include="..\Pixel.Scripting.Editor.Core\Pixel.Scripting.Editor.Core.csproj" />
27-
<ProjectReference Include="..\Pixel.Scripting.Reference.Manager\Pixel.Scripting.Reference.Manager.csproj" />
2827
</ItemGroup>
2928

3029
<ItemGroup>

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

Lines changed: 2 additions & 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())
@@ -160,6 +161,7 @@ public async Task EditScriptAsync()
160161
{
161162
try
162163
{
164+
await this.projectManager.DownloadFileByNameAsync(Constants.InitializeEnvironmentScript);
163165
var entityManager = this.EntityManager;
164166
var fileSystem = entityManager.GetCurrentFileSystem();
165167
var scriptFile = Path.Combine(fileSystem.ScriptsDirectory, Constants.InitializeEnvironmentScript);

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

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,23 @@ public class AutomationProjectManager : ProjectManager, IAutomationProjectManage
2525
private AutomationProject activeProject;
2626
private VersionInfo loadedVersion;
2727

28+
/// <summary>
29+
/// constructor
30+
/// </summary>
31+
/// <param name="serializer"></param>
32+
/// <param name="entityManager"></param>
33+
/// <param name="projectFileSystem"></param>
34+
/// <param name="typeProvider"></param>
35+
/// <param name="argumentTypeProvider"></param>
36+
/// <param name="codeEditorFactory"></param>
37+
/// <param name="scriptEditorFactory"></param>
38+
/// <param name="scriptEngineFactory"></param>
39+
/// <param name="codeGenerator"></param>
40+
/// <param name="applicationDataManager"></param>
41+
/// <param name="referenceManagerFactory"></param>
42+
/// <param name="projectDataManager"></param>
43+
/// <param name="prefabDataManager"></param>
44+
/// <param name="projectAssetDataManager"></param>
2845
public AutomationProjectManager(ISerializer serializer, IEntityManager entityManager, IProjectFileSystem projectFileSystem, ITypeProvider typeProvider, IArgumentTypeProvider argumentTypeProvider,
2946
ICodeEditorFactory codeEditorFactory, IScriptEditorFactory scriptEditorFactory, IScriptEngineFactory scriptEngineFactory, ICodeGenerator codeGenerator, IApplicationDataManager applicationDataManager,
3047
IReferenceManagerFactory referenceManagerFactory, IProjectDataManager projectDataManager, IPrefabDataManager prefabDataManager, IProjectAssetsDataManager projectAssetDataManager)
@@ -37,7 +54,7 @@ public AutomationProjectManager(ISerializer serializer, IEntityManager entityMan
3754
this.prefabDataManager = Guard.Argument(prefabDataManager, nameof(prefabDataManager)).NotNull().Value;
3855
}
3956

40-
#region Load Project
57+
#region methods
4158

4259
public async Task<Entity> Load(AutomationProject activeProject, VersionInfo versionToLoad)
4360
{
@@ -141,9 +158,7 @@ private Entity DeserializeProject()
141158
{
142159
var entity = this.Load<Entity>(this.projectFileSystem.ProcessFile);
143160
return entity;
144-
}
145-
146-
#endregion Load Project
161+
}
147162

148163
/// <summary>
149164
/// Save and load project again. Update services to use new data model . One time registration of services is skipped unlike load.
@@ -154,35 +169,43 @@ private Entity DeserializeProject()
154169
/// <param name="entityManager"></param>
155170
/// <returns></returns>
156171
public override async Task Reload()
157-
{
172+
{
158173

159174
logger.Information($"{this.GetProjectName()} will be re-loaded");
160175
var reference = this.fileSystem.LoadFile<ProjectReferences>(this.fileSystem.ReferencesFile);
161176
this.referenceManager.SetProjectReferences(reference);
162177
var dataModel = CompileAndCreateDataModel(Constants.AutomationProcessDataModelName);
163178
ConfigureScriptEngine(this.referenceManager, dataModel);
164-
ConfigureScriptEditor(this.referenceManager, dataModel);
179+
ConfigureScriptEditor(this.referenceManager, dataModel);
165180
this.entityManager.Arguments = dataModel;
166181
SetupInitializationScriptProject(dataModel);
167-
await ExecuteInitializationScript();
182+
await ExecuteInitializationScript();
168183
ConfigureArgumentTypeProvider(this.entityManager.Arguments.GetType().Assembly);
169184
this.RootEntity.ResetHierarchy();
170-
serializer.Serialize(this.projectFileSystem.ProcessFile, this.RootEntity, typeProvider.GetKnownTypes());
171-
185+
serializer.Serialize(this.projectFileSystem.ProcessFile, this.RootEntity, typeProvider.GetKnownTypes());
186+
172187
var rootEntity = DeserializeProject();
173188
//we don't want any launched applications to be lost. Copy over ApplicationDetails from each ApplicationEntity in to newly loaded root entity.
174-
foreach(var applicationEntity in this.entityManager.RootEntity.GetComponentsOfType<ApplicationEntity>(SearchScope.Descendants))
189+
foreach (var applicationEntity in this.entityManager.RootEntity.GetComponentsOfType<ApplicationEntity>(SearchScope.Descendants))
175190
{
176191
var newApplicationEntity = rootEntity.GetComponentById(applicationEntity.Id, SearchScope.Descendants) as IApplicationEntity;
177192
newApplicationEntity.SetTargetApplicationDetails(applicationEntity.GetTargetApplicationDetails());
178-
}
193+
}
179194
this.RootEntity = rootEntity;
180195
RestoreParentChildRelation(this.RootEntity);
181196
await Task.CompletedTask;
182197
logger.Information($"Reload completed for project {this.GetProjectName()}");
183198

184199
}
185200

201+
///<inheritdoc/>
202+
public async Task DownloadFileByNameAsync(string fileName)
203+
{
204+
await this.projectDataManager.DownloadProjectDataFileByNameAsync(this.activeProject, this.loadedVersion as ProjectVersion, fileName);
205+
}
206+
207+
#endregion methods
208+
186209
#region overridden methods
187210

188211
///<inheritdoc/>
@@ -197,6 +220,12 @@ public override async Task DeleteDataFileAsync(string fileToDelete)
197220
await this.projectDataManager.DeleteDataFileAsync(this.activeProject, this.loadedVersion as ProjectVersion, fileToDelete);
198221
}
199222

223+
///<inheritdoc/>
224+
public override async Task DownloadDataModelFilesAsync()
225+
{
226+
await this.projectDataManager.DownloadDataModelFilesAsync(this.activeProject, this.loadedVersion as ProjectVersion);
227+
}
228+
200229
///<inheritdoc/>
201230
protected override string GetProjectName()
202231
{

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: 9 additions & 1 deletion
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.
@@ -58,7 +64,9 @@ public interface IProjectManager
5864

5965
public interface IAutomationProjectManager: IProjectManager
6066
{
61-
Task<Entity> Load(AutomationProject activeProject, VersionInfo versionToLoad);
67+
Task<Entity> Load(AutomationProject activeProject, VersionInfo versionToLoad);
68+
69+
Task DownloadFileByNameAsync(string fileName);
6270
}
6371

6472

src/Pixel.Automation.RunTime/Pixel.Automation.RunTime.csproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@
3131
<ProjectReference Include="..\Pixel.Automation.Core.Components\Pixel.Automation.Core.Components.csproj">
3232
<Private>false</Private>
3333
</ProjectReference>
34-
<ProjectReference Include="..\Pixel.Automation.Reference.Manager\Pixel.Automation.Reference.Manager.csproj" />
35-
<ProjectReference Include="..\Pixel.Scripting.Reference.Manager\Pixel.Scripting.Reference.Manager.csproj" />
34+
<ProjectReference Include="..\Pixel.Automation.Reference.Manager\Pixel.Automation.Reference.Manager.csproj" />
3635
</ItemGroup>
3736

3837
</Project>

src/Pixel.Persistence.Respository/FilesRepository.cs

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ public async Task<ProjectDataFile> GetFileAsync(string projectId, string project
112112
ProjectId = projectId,
113113
ProjectVersion = projectVersion,
114114
FileName = fileInfo.Filename,
115-
FilePath = fileInfo.Metadata[this.filePathField].AsString
115+
FilePath = fileInfo.Metadata[this.filePathField].AsString,
116+
Bytes = fileData
116117
};
117118
}
118119
}
@@ -158,6 +159,41 @@ public async IAsyncEnumerable<ProjectDataFile> GetFilesAsync(string projectId, s
158159
}
159160
}
160161

162+
/// <inheritdoc/>
163+
public async IAsyncEnumerable<ProjectDataFile> GetFilesOfTypeAsync(string projectId, string projectVersion, string fileExtension)
164+
{
165+
Guard.Argument(projectId, nameof(projectId)).NotNull().NotEmpty();
166+
Guard.Argument(projectVersion, nameof(projectVersion)).NotNull().NotEmpty();
167+
Guard.Argument(fileExtension, nameof(fileExtension)).NotNull().NotEmpty();
168+
169+
var filter = Builders<GridFSFileInfo>.Filter.Eq(x => x.Metadata[this.IdField], projectId) &
170+
Builders<GridFSFileInfo>.Filter.Eq(x => x.Metadata[this.versionField], projectVersion) &
171+
Builders<GridFSFileInfo>.Filter.Regex(x => x.Filename, $"({fileExtension})$");
172+
173+
var sort = Builders<GridFSFileInfo>.Sort.Descending(x => x.UploadDateTime);
174+
var options = new GridFSFindOptions
175+
{
176+
Sort = sort
177+
};
178+
179+
using (var cursor = await bucket.FindAsync(filter, options))
180+
{
181+
foreach (var file in (await cursor.ToListAsync()))
182+
{
183+
var fileData = await bucket.DownloadAsBytesAsync(file.Id);
184+
yield return new ProjectDataFile()
185+
{
186+
ProjectId = projectId,
187+
ProjectVersion = projectVersion,
188+
FileName = file.Filename,
189+
FilePath = file.Metadata[this.filePathField].AsString,
190+
Tag = file.Metadata[this.tagField].AsString,
191+
Bytes = fileData
192+
};
193+
}
194+
}
195+
}
196+
161197
/// <inheritdoc/>
162198
public async Task AddOrUpdateFileAsync(string projectId, string projectVersion, ProjectDataFile dataFile)
163199
{

src/Pixel.Persistence.Respository/Interfaces/IFilesRepository.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,23 @@ public interface IFilesRepository
2525
/// <returns></returns>
2626
IAsyncEnumerable<ProjectDataFile> GetFilesAsync(string projectId, string projectVersion, string[] tags);
2727

28+
/// <summary>
29+
/// Get all the files with a matching extension
30+
/// </summary>
31+
/// <param name="projectId"></param>
32+
/// <param name="projectVersion"></param>
33+
/// <param name="fileExtension"></param>
34+
/// <returns></returns>
35+
IAsyncEnumerable<ProjectDataFile> GetFilesOfTypeAsync(string projectId, string projectVersion, string fileExtension);
36+
2837
/// <summary>
2938
/// Get a file by name for a given version of project
3039
/// </summary>
3140
/// <param name="projectId"></param>
3241
/// <param name="projectVersion"></param>
3342
/// <param name="fileName"></param>
3443
/// <returns></returns>
35-
Task<ProjectDataFile> GetFileAsync(string projectId, string projectVersion, string fileName);
44+
Task<ProjectDataFile> GetFileAsync(string projectId, string projectVersion, string fileName);
3645

3746
/// <summary>
3847
/// Add a new file to a given version of project

0 commit comments

Comments
 (0)