Skip to content

Commit

Permalink
feat: Load Project From Stream
Browse files Browse the repository at this point in the history
  • Loading branch information
furesoft committed Nov 16, 2024
1 parent 31a7e12 commit e0fcbfe
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,4 @@
</Reference>
</ItemGroup>

<ItemGroup>
<None Update="test.zip">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Avalonia.Controls.ApplicationLifetimes;
using System.Reflection;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Platform.Storage;
using Avalonia.PropertyGrid.Services;
using CommunityToolkit.Mvvm.Input;
Expand Down Expand Up @@ -43,7 +44,7 @@ public MainViewViewModel()
root.Navigate.Execute("Home");
}

OpenedProject = new Project();//Project.Load("test.zip");
OpenedProject = Project.Load(Assembly.GetExecutingAssembly().GetManifestResourceStream("Furesoft.LowCode.test.zip"));

OpenDocument(OpenedProject.Items[1]);
SetInitialSelectedDocument();
Expand Down Expand Up @@ -343,7 +344,7 @@ private async Task Open()
{
await using var stream = await file.OpenReadAsync();

OpenedProject = Project.Load(file.Path.ToString());
OpenedProject = Project.Load(stream);
}
}

Expand Down
8 changes: 8 additions & 0 deletions src/Core/Furesoft.LowCode/Furesoft.LowCode.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,12 @@
<Folder Include="Designer\Layout\Views\Documents\NewEditor\" />
</ItemGroup>


<ItemGroup>
<None Remove="test.zip" />
<EmbeddedResource Include="test.zip">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource>
</ItemGroup>

</Project>
24 changes: 21 additions & 3 deletions src/Core/Furesoft.LowCode/ProjectSystem/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,32 @@ public Project()

[JsonIgnore] public string Path { get; set; }

public static Project Load(string path)
public static Project Create()
{
using var zip = ZipFile.OpenRead(path);
var project = new Project();

project.Name = "New Project";
project.Version = "1.0.0.0";
project.MainGraph = "Main Graph";

var factory = new DrawingNodeFactory();
//var drawing = factory.
/* project.Items = new ObservableCollection<ProjectItem>()
{
new GraphItem("Main Graph", drawing, new GraphProps())
};
*/
return project;
}

public static Project Load(Stream path)
{
using var zip = new ZipArchive(path);
using var jsonStream = zip.GetEntry("meta.json")!.Open();
var optionsEntry = zip.GetEntry("options.json");

var proj = JsonConvert.DeserializeObject<Project>(new StreamReader(jsonStream).ReadToEnd());
proj.Path = path;
// proj.Path = path;

if (optionsEntry != null)
{
Expand Down
File renamed without changes.

0 comments on commit e0fcbfe

Please sign in to comment.