/// public override async Task Save() { IsBusy = true; try { foreach (var aspect in Aspects.Items.Cast <IResourceAspect>()) { await aspect.Save(); } var updated = await ResourceServiceModel.SaveResource(EditableObject.Model); EditableObject.UpdateModel(updated); } catch { //TODO throw; } finally { IsBusy = false; } }
private async Task ShowAspectConfigurator(object obj) { var typeTree = await ResourceServiceModel.GetTypeTree(); var allTypes = typeTree.DerivedTypes.Flatten(t => t.DerivedTypes); var dialog = AspectConfiguratorFactory.Create(Config.AspectConfigurations, allTypes.Select(p => p.Name).ToArray()); dialog.DisplayName = "Configuration"; await DialogManager.ShowDialogAsync(dialog); AspectConfiguratorFactory.Destroy(dialog); }
/// <summary> /// If an resource was loaded (new or existing), the resource /// can be assigned to this view model /// </summary> private async Task AssignLoadedResource(ResourceModel resource) { IsBusy = true; try { // Load type from type tree var typeTreeModel = await ResourceServiceModel.GetTypeTree(); var flatTypeTree = typeTreeModel.DerivedTypes.Flatten(t => t.DerivedTypes).SingleOrDefault(t => t.Name == resource.Type); Type = new ResourceTypeViewModel(flatTypeTree); EditableObject = new ResourceViewModel(resource, Type); if (AspectUsage) { var typedAspects = Config.AspectConfigurations.FirstOrDefault(ac => ac.TypeName == resource.Type); List <AspectConfiguration> aspectConfigurations; if (typedAspects == null || typedAspects.Aspects.Count == 0) { aspectConfigurations = Config.DefaultAspects; } else { aspectConfigurations = typedAspects.Aspects; } var aspects = aspectConfigurations.Select(ca => (IResourceAspect)AspectFactory.Create(ca.PluginName)) .Where(a => a.IsRelevant(EditableObject)).ToArray(); var aspectLoadTask = new List <Task>(aspects.Select(aspect => aspect.Load(EditableObject))); await Task.WhenAll(aspectLoadTask); Aspects.Items.AddRange(aspects); } Logger.Log(LogLevel.Trace, "Loaded resource with id {0}.", EditableObject.Id); } catch (Exception e) { //TODO throw; } finally { IsBusy = false; } }
private async Task InvokeMethod(object parameters) { var vm = (ResourceMethodViewModel) parameters; vm.CopyToModel(); var result = await ResourceServiceModel.InvokeMethod(Resource.Id, ((ResourceMethodViewModel) parameters).Model); var resultEntry = result.ToSerializationEntry(); if (resultEntry == null) MethodInvocationResult = new EntryViewModel(new Entry()); else if (resultEntry.Value.Type >= EntryValueType.Class) MethodInvocationResult = new EntryViewModel(resultEntry); else MethodInvocationResult = new EntryViewModel(new List<Entry> { resultEntry }); }
////guyang 2018年2月28日09:57:58 //public List<string> GetExportServiceNames() //{ // List<string> ServiceNames = new List<string>(); // ServiceNames.Add("GetOrderList"); // ServiceNames.Add("GetStatus"); // return ServiceNames; // //return null; //} public List <ResourceServiceModel> GetExportServices() { var services = new List <ResourceServiceModel>(); var newService1 = new ResourceServiceModel { Name = "GetOrderList", Parameters = null }; services.Add(newService1); var newService2 = new ResourceServiceModel { Name = "GetStatus", Parameters = null }; services.Add(newService2); return(services); }
private async Task InvokeMethod(object parameters) { var resultEntry = await ResourceServiceModel.InvokeMethod(Resource.Id, ((ResourceMethodViewModel)parameters).Model); if (resultEntry == null) { MethodInvocationResult = new EntryViewModel(new Entry()); } else if (resultEntry.Value.Type >= EntryValueType.Class) { MethodInvocationResult = new EntryViewModel(resultEntry); } else { MethodInvocationResult = new EntryViewModel(new List <Entry> { resultEntry }); } }
/// <summary> /// Refreshes the resource tree and loads all data from the controller. /// </summary> private async Task UpdateTreeAsync() { try { IsBusy = true; var treeTask = ResourceServiceModel.GetResourceTree(); var typeTask = ResourceServiceModel.GetTypeTree(); var refreshedTree = await treeTask; await typeTask; Tree.MergeTree(refreshedTree, new ResourceTreeMergeStrategy()); } catch (Exception e) { Tree?.Clear(); ShowEmpty(); } finally { IsBusy = false; } }
/// protected override void OnInitialize() { DisplayName = Strings.ModuleController_DisplayName; // Register aspect factory Container.Register <IAspectFactory>(); // Load resource aspects to this container Container.Register <IAspectConfigurator, AspectConfiguratorViewModel>(); Container.Register <IAspectConfiguratorFactory>(); Container.LoadComponents <IResourceAspect>(); // Load ResourceDetails to this container Container.LoadComponents <IResourceDetails>(); // Register and start service model var clientFactory = Container.Resolve <IWcfClientFactory>(); var logger = Container.Resolve <IModuleLogger>(); IResourceServiceModel serviceModel = new ResourceServiceModel(clientFactory, logger); Container.SetInstance(serviceModel); serviceModel.Start(); }
/// <inheritdoc /> public virtual async Task Load(long resourceId) { var resources = await ResourceServiceModel.GetDetails(resourceId); await AssignLoadedResource(resources[0]); }