Skip to content

Commit

Permalink
Update project and workflow settings
Browse files Browse the repository at this point in the history
  • Loading branch information
dogzz9445 committed Jun 24, 2024
1 parent 6ab0609 commit 75d9c21
Show file tree
Hide file tree
Showing 23 changed files with 628 additions and 54 deletions.
8 changes: 4 additions & 4 deletions src/Apps/Corathing.Organizer.UnitTests/AppUnitTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ private static async void _internalRunApplicationAction(Action<Application> acti
[TestMethod]
public void App_ConfigureServices_Test()
{
var thread = RunApplicationAction(application =>
{
//var thread = RunApplicationAction(application =>
//{

});
thread.Join();
//});
//thread.Join();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Corathing.Organizer.UnitTests.Helpers;

[TestClass]
public class FileHelperUnitTest
{
[TestMethod]
public void GenerateUniqueFolder_TestGuid(Guid guid)
{

}
}
8 changes: 6 additions & 2 deletions src/Apps/Corathing.Organizer/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
using Wpf.Ui;

using Application = System.Windows.Application;
using INavigationService = Corathing.Contracts.Services.INavigationService;
using IThemeService = Corathing.Contracts.Services.IThemeService;
using MessageBox = System.Windows.MessageBox;
using NavigationService = Corathing.Organizer.Services.NavigationService;
using ThemeService = Corathing.Organizer.Services.ThemeService;

namespace Corathing.Organizer;
Expand Down Expand Up @@ -174,6 +176,7 @@ private static IServiceProvider ConfigureServices(string[] args)
serviceCollection.AddSingleton<IAuthService, AuthService>();
serviceCollection.AddSingleton<IDialogService, DialogService>();
serviceCollection.AddSingleton<ILocalizationService>(LocalizationService.Instance);
serviceCollection.AddSingleton<INavigationService, NavigationService>();
serviceCollection.AddSingleton<IPackageService, PackageService>();
serviceCollection.AddSingleton<IResourceDictionaryService, ResourceDictionaryService>();
serviceCollection.AddSingleton<ISecretService, ModelVersionSecretService>();
Expand All @@ -188,8 +191,9 @@ private static IServiceProvider ConfigureServices(string[] args)
serviceCollection.AddScoped<WidgetSettingsViewModel>();
serviceCollection.AddScoped<ProjectSettingsViewModel>();
serviceCollection.AddScoped<WorkflowSettingsViewModel>();
serviceCollection.AddScoped<ProjectContext>();
serviceCollection.AddScoped<WorkflowContext>();
serviceCollection.AddTransient<ProjectContext>();
serviceCollection.AddTransient<ProjectSettingsContext>();
serviceCollection.AddTransient<WorkflowContext>();

// TODO:
// Logger 및 Localizer 설정
Expand Down
17 changes: 15 additions & 2 deletions src/Apps/Corathing.Organizer/Models/ProjectContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public partial class ProjectContext : ObservableObject
/// </summary>
/// <value>The title.</value>
[ObservableProperty]
private string _title = "My Project";
private string _name = "My Project";

[DefaultValue(false)]
[ObservableProperty]
Expand Down Expand Up @@ -64,7 +64,7 @@ public ObservableCollection<WorkflowContext> Workflows
public void AddWorkflow()
{
var appState = _services.GetService<IAppStateService>();
var workflow = appState.AddWorkflow();
var workflow = appState.CreateAddWorkflow();
//appState.NewWorkflowState();
var workflowContext = _services.GetService<WorkflowContext>();
workflowContext.WorkflowId = workflow.Id;
Expand All @@ -82,6 +82,19 @@ public ProjectContext(IServiceProvider services)
Workflows = new ObservableCollection<WorkflowContext>();
}

public static ProjectContext Create(ProjectState? state = null)
{
if (state == null)
{
var appStateService = App.Current.Services.GetService<IAppStateService>();
state = appStateService.CreateAddProject();
}
var context = App.Current.Services.GetService<ProjectContext>();
context.Name = state.Settings.Name;

return context;
}

public void UpdateProject(ProjectState projectState)
{
var packageService = _services.GetService<IPackageService>();
Expand Down
36 changes: 36 additions & 0 deletions src/Apps/Corathing.Organizer/Models/ProjectSettingsContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using CommunityToolkit.Mvvm.ComponentModel;

using Corathing.Contracts.Bases;

namespace Corathing.Organizer.Models;

public partial class ProjectSettingsContext : ObservableObject
{
#region Readonly Properties
private IServiceProvider _services;
#endregion
public Guid ProjectId { get; set; }
public Guid OriginalProjectId { get; set; }
public bool IsAdded { get; set; }
public bool IsRemoved { get; set; }
public bool IsDuplicated { get; set; }
public ProjectState ProjectState { get; set; }

/// <summary>
/// Gets or sets the title.
/// </summary>
/// <value>The title.</value>
[ObservableProperty]
private string _name = "My Project";

public ProjectSettingsContext(IServiceProvider services)
{
_services = services;
}
}
6 changes: 6 additions & 0 deletions src/Apps/Corathing.Organizer/Natives/FileHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Windows.Media;
using System.Windows;
using System.Drawing;
using Corathing.Organizer.Utils;

namespace Corathing.Organizer.Natives;

Expand All @@ -20,4 +21,9 @@ public static ImageSource GetIcon(string fileName)
Int32Rect.Empty,
BitmapSizeOptions.FromEmptyOptions());
}

public static string GenerateUniqueFolder(Guid guid)
{
return ZBase32Encoder.ToString(guid.ToByteArray());
}
}
84 changes: 80 additions & 4 deletions src/Apps/Corathing.Organizer/Services/AppStateService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public bool TryGetProject(Guid id, out ProjectState project)
if (_cachedAppDashboardState == null)
ReadOrCreateAppStateByAppSettings().Wait();

project = new ProjectState();
project = ProjectState.Create();
return true;
}

Expand All @@ -138,7 +138,7 @@ public bool TryGetWorkflow(Guid id, out WorkflowState workflow)
if (_cachedAppDashboardState == null)
ReadOrCreateAppStateByAppSettings().Wait();

workflow = new WorkflowState();
workflow = WorkflowState.Create();
return true;
}

Expand Down Expand Up @@ -205,20 +205,94 @@ public async void UpdateWidget(WidgetState widget)
await PendingWriteAppState();
}

public ProjectState AddProject()
public ProjectState CreateAddProject()
{
var project = ProjectState.Create();
_cachedAppDashboardState.AddProject(project);
return project;
}

public WorkflowState AddWorkflow()
public WorkflowState CreateAddWorkflow()
{
var workflow = WorkflowState.Create();
_cachedAppDashboardState.AddWorkflow(workflow);
return workflow;
}

public ProjectState CopyProject(Guid originalProjectId)
{
if (!TryGetProject(originalProjectId, out var originalProject))
{
// TODO:
// Change Exception Type;
throw new Exception();
}
return CopyProject(originalProject);
}

public ProjectState CopyProject(ProjectState originalProject)
{
var cloneProject = ProjectState.Create();
foreach (var originalWorkflowId in originalProject.WorkflowIds)
{
var workflowState = CopyWorkflow(originalWorkflowId);
cloneProject.WorkflowIds.Add(workflowState.Id);
}
return cloneProject;
}

public WorkflowState CopyWorkflow(Guid originalWorkflowId)
{
if (!TryGetWorkflow(originalWorkflowId, out var originalWorkflow))
{
// TODO:
// Change Exception Type
throw new Exception();
}
return CopyWorkflow(originalWorkflow);
}

public WorkflowState CopyWorkflow(WorkflowState workflowState)
{
var cloneWorkflow = WorkflowState.Create();


_cachedAppDashboardState.AddWorkflow(cloneWorkflow);
return cloneWorkflow;
}

public void RemoveProject(Guid projectid)
{
if (!TryGetProject(projectid, out var project))
{
// TODO:
// Change Exception Type;
throw new Exception();
}
RemoveProject(project);
}

public async void RemoveProject(ProjectState project)
{
_cachedAppDashboardState.RemoveProject(project);

await PendingWriteAppState();
}

public void RemoveWorkflow(Guid guid)
{

}

public async void RemoveWorkflow(WorkflowState workflow)
{
_cachedAppDashboardState.RemoveWorkflow(workflow);



await PendingWriteAppState();
}

#region Private Methods

private async Task<AppSettings> ReadOrCreateAppSettingsFromAppPath()
Expand Down Expand Up @@ -331,6 +405,8 @@ private async Task ReadOrCreateAppStateFromPath(string path)
_cachedAppDashboardState = document.RootElement
.GetProperty("Dashboards")
.Deserialize<AppDashboardState>();

_cachedAppDashboardState.Refresh();
}
}

Expand Down
12 changes: 12 additions & 0 deletions src/Apps/Corathing.Organizer/Services/ApplicationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

using Corathing.Contracts.Services;

using Microsoft.Extensions.DependencyInjection;

namespace Corathing.Organizer.Services
{
public class ApplicationService : IApplicationService
Expand All @@ -21,5 +23,15 @@ public async Task<TResult> DispatchAsync<TResult>(Func<Task<TResult>> callback)
var result = await App.Current.Dispatcher.InvokeAsync(callback);
return result.Result;
}

public IServiceProvider GetServiceProvider()
{
return App.Current.Services;
}

public TService GetService<TService>()
{
return App.Current.Services.GetService<TService>();
}
}
}
47 changes: 47 additions & 0 deletions src/Apps/Corathing.Organizer/Services/NavigationService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Corathing.Contracts.Services;

namespace Corathing.Organizer.Services;

public class NavigationService : INavigationService
{
public bool GoBack()
{
throw new NotImplementedException();
}

public bool Navigate(Type pageType)
{
throw new NotImplementedException();
}

public bool Navigate(Type pageType, object? dataContext)
{
throw new NotImplementedException();
}

public bool Navigate(string pageIdOrTargetTag)
{
throw new NotImplementedException();
}

public bool Navigate(string pageIdOrTargetTag, object? dataContext)
{
throw new NotImplementedException();
}

public bool NavigateWithHierarchy(Type pageType)
{
throw new NotImplementedException();
}

public bool NavigateWithHierarchy(Type pageType, object? dataContext)
{
throw new NotImplementedException();
}
}
Loading

0 comments on commit 75d9c21

Please sign in to comment.