|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RehostedDesigner.Designer.ViewModels.Contracts;
using RehostedDesigner.ToolboxModule.Contracts;
using Selen.WorkflowDesigner.Storage.Contracts;
using Selen.WorkflowDesigner.Contracts;
using System.Diagnostics;
using RehostedDesigner.LoadErrorHandling;
namespace Selen.WorkflowTypeManagementModule.ViewModels
{
public class LoadWorkflow
{
private ReloadToolbox reloadToolbox;
private IMainViewModel mainViewModel;
private WorkflowStorageData storageData;
private IDesignerViewModel designerViewModel;
public LoadWorkflow(IMainViewModel mainViewModel, WorkflowStorageData storageData, IDesignerViewModel designerViewModel, ReloadToolbox reloadToolbox)
{
this.reloadToolbox = reloadToolbox;
this.mainViewModel = mainViewModel;
this.storageData = storageData;
this.designerViewModel = designerViewModel;
}
public void Load(IWorkflowType type, object key)
{
new Task(() =>
{
this.mainViewModel.PostStatus("Loading ...");
this.mainViewModel.BeginProgress();
if (!this.reloadToolbox.LoadToolbox(type))
{
this.mainViewModel.PostStatus("Load Toolbox failed");
}
else if (!this.LoadDesignerModel(type, key))
{
this.mainViewModel.PostStatus("Load failed");
}
else
{
this.mainViewModel.PostStatus("Load succeded");
}
this.mainViewModel.EndProgress();
}).Start();
}
private bool LoadErrorDesinerModel(LoadWorkflowException loadEx)
{
if (!(this.designerViewModel is ILoadErrorDesignerViewModel))
{
this.mainViewModel.On_DisplayErrors(new DesignerErrorDefinition[] { new DesignerErrorDefinition() { ErrorMessage = "Invalid xaml" } });
return false;
}
try
{
((ILoadErrorDesignerViewModel)this.designerViewModel).ReloadError(loadEx.XAMLDefinition);
this.storageData.DesignerModel = loadEx.DesignerModel;
return true;
}
catch (ApplicationException apEx)
{
this.mainViewModel.On_DisplayErrors(new DesignerErrorDefinition[] { new DesignerErrorDefinition() { ErrorMessage = "Load invalid xaml error: " + apEx.Message } });
Trace.TraceError(apEx.Message);
return false;
}
catch (Exception ex)
{
this.mainViewModel.On_DisplayErrors(new DesignerErrorDefinition[] { new DesignerErrorDefinition() { ErrorMessage = "Load invalid xaml error: internal error" } });
Trace.TraceError(ex.Message);
return false;
}
}
private bool LoadDesignerModel(IWorkflowType type, object key)
{
try
{
this.storageData.WorkflowType = type;
this.storageData.DesignerModel = type.StorageAdapter.GetDesignerModel(key);
if (this.storageData.DesignerModel != null)
{
this.designerViewModel.ReloadDesigner(this.storageData.DesignerModel.RootActivity);
return true;
}
else
{
this.mainViewModel.On_DisplayErrors(new DesignerErrorDefinition[] { new DesignerErrorDefinition() { ErrorMessage = "Load error: Nothing to load" } });
return false;
}
}
catch (LoadWorkflowException loadEx)
{
return this.LoadErrorDesinerModel(loadEx);
}
catch (ApplicationException apEx)
{
this.mainViewModel.On_DisplayErrors(new DesignerErrorDefinition[] { new DesignerErrorDefinition() { ErrorMessage = "Load error: " + apEx.Message } });
Trace.TraceError(apEx.ToString());
return false;
}
catch (Exception ex)
{
this.mainViewModel.On_DisplayErrors(new DesignerErrorDefinition[] { new DesignerErrorDefinition() { ErrorMessage = "Load error: internal error" } });
Trace.TraceError(ex.ToString());
return false;
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.