/// <summary> /// Convert ResourceModel back to resource and/or update its properties /// </summary> public Resource FromModel(ResourceModel model, HashSet <Resource> resourcesToSave, Resource resource = null) { // Break recursion if we converted this instance already // Try to load by real id first if (_resourceCache.ContainsKey(model.Id)) { return(_resourceCache[model.Id]); } // Otherwise by reference id if (model.Id == 0 && _resourceCache.ContainsKey(model.ReferenceId)) { return(_resourceCache[model.ReferenceId]); } // Only fetch resource object if it was not given if (resource == null) { resource = model.Id == 0 ? _resourceGraph.Instantiate(model.Type) : _resourceGraph.Get(model.Id); } // Write to cache because following calls might only have an empty reference if (model.Id == 0) { _resourceCache[model.ReferenceId] = resource; } else { _resourceCache[model.Id] = resource; } // Do not copy values from partially loaded models if (model.PartiallyLoaded) { return(resource); } // Add to list if object was created or modified if (model.Id == 0 || model.DifferentFrom(resource, _serialization)) { resourcesToSave.Add(resource); } // Copy standard properties resource.Name = model.Name; resource.Description = model.Description; // Copy extended properties EntryConvert.UpdateInstance(resource.Descriptor, model.Properties, _serialization); // Set all other references UpdateReferences(resource, resourcesToSave, model); return(resource); }
public override IReadOnlyList <Resource> Execute(IResourceGraph graph) { var machine = graph.Instantiate <Machine>(); machine.Name = Config.MachineName; var someGate = graph.Instantiate <GateResource>(); someGate.Name = "Some Gate"; someGate.Parent = machine; machine.Children.Add(someGate); var anotherGate = graph.Instantiate <GateResource>(); anotherGate.Name = "Another Gate"; anotherGate.Parent = machine; machine.Children.Add(anotherGate); return(new Resource[] { machine }); }
/// <summary> /// Convert ResourceModel back to resource and/or update its properties /// </summary> public Resource FromModel(ResourceModel model, HashSet <Resource> resourcesToSave, Resource resource = null) { // Break recursion if we converted this instance already if (_resourceCache.ContainsKey(model)) { return(_resourceCache[model]); } // Only fetch resource object if it was not given if (resource == null) { // Get or create resource resource = model.Id == 0 ? _resourceGraph.Instantiate(model.Type) : _resourceGraph.Get(model.Id); _resourceCache[model] = resource; } // Add to list if object was created or modified if (model.Id == 0 || model.DifferentFrom(resource, _serialization)) { resourcesToSave.Add(resource); } // Copy standard properties resource.Name = model.Name; resource.Description = model.Description; // Copy extended properties if (model.Properties != null) { EntryConvert.UpdateInstance(resource.Descriptor, model.Properties, _serialization); } // Set all other references if (model.References != null) { UpdateReferences(resource, resourcesToSave, model); } return(resource); }
/// <inheritdoc /> public override IReadOnlyList <Resource> Execute(IResourceGraph graph) { var interactionHost = graph.Instantiate <ResourceInteractionHost>(); return(new[] { interactionHost }); }