示例#1
0
        private string Copy(AssetPropertyGraph propertyGraph, object assetValue)
        {
            var copiedText = service.CopyFromAsset(propertyGraph, propertyGraph.Id, assetValue, false);

            Assert.False(string.IsNullOrEmpty(copiedText));
            return(copiedText);
        }
示例#2
0
        public override Task Paste(IPasteItem pasteResultItem, AssetPropertyGraph assetPropertyGraph, ref NodeAccessor nodeAccessor, ref PropertyContainer container)
        {
            if (pasteResultItem == null)
            {
                throw new ArgumentNullException(nameof(pasteResultItem));
            }

            var propertyGraph = (UIAssetPropertyGraph)assetPropertyGraph;
            var parentElement = nodeAccessor.RetrieveValue() as UIElement;

            // 1. try to paste as hierarchy
            var hierarchy = pasteResultItem.Data as AssetCompositeHierarchyData <UIElementDesign, UIElement>;

            if (hierarchy != null)
            {
                // Note: check that adding or inserting is supported is done in CanPaste()
                foreach (var rootUIElement in hierarchy.RootParts)
                {
                    var asset       = (UIAssetBase)propertyGraph.Asset;
                    var insertIndex = parentElement == null ? asset.Hierarchy.RootParts.Count : ((parentElement as Panel)?.Children.Count ?? 0);
                    propertyGraph.AddPartToAsset(hierarchy.Parts, hierarchy.Parts[rootUIElement.Id], parentElement, insertIndex);
                }
            }
            return(Task.CompletedTask);
        }
示例#3
0
        private void Paste(AssetPropertyGraph propertyGraph, string copiedText, Type deserializedType, Type expectedType, Func <IObjectNode, IGraphNode> targetNodeResolver, NodeIndex index, bool replace)
        {
            var asset = propertyGraph.RootNode.Retrieve();

            Assert.True(service.CanPaste(copiedText, asset.GetType(), expectedType));
            var result = service.DeserializeCopiedData(copiedText, asset, expectedType);

            Assert.NotNull(result);
            Assert.NotNull(result.Items);
            Assert.Equal(1, result.Items.Count);

            var item = result.Items[0];

            Assert.NotNull(item);
            Assert.NotNull(item.Data);
            Assert.Equal(deserializedType, item.Data.GetType());
            Assert.NotNull(item.Processor);

            var targetNode        = targetNodeResolver(propertyGraph.RootNode);
            var nodeAccessor      = new NodeAccessor(targetNode, index);
            var propertyContainer = new PropertyContainer {
                { AssetPropertyPasteProcessor.IsReplaceKey, replace }
            };

            item.Processor.Paste(item, propertyGraph, ref nodeAccessor, ref propertyContainer);
        }
示例#4
0
 public void RegisterGraph([NotNull] AssetPropertyGraph graph)
 {
     if (graph == null)
     {
         throw new ArgumentNullException(nameof(graph));
     }
     registeredGraphs.Add(graph.Id, graph);
 }
示例#5
0
 private void PasteIntoEntity(AssetPropertyGraph propertyGraph, string copiedText, Type componentType, Entity entity, NodeIndex index, bool replace)
 {
     if (index == NodeIndex.Empty)
     {
         Paste(propertyGraph, copiedText, componentType, typeof(EntityComponent), x => x["Hierarchy"].Target["Parts"].Target.IndexedTarget(new NodeIndex(entity.Id))["Entity"].Target["Components"], index, replace);
     }
     else
     {
         Paste(propertyGraph, copiedText, componentType, typeof(EntityComponent), x => x["Hierarchy"].Target["Parts"].Target.IndexedTarget(new NodeIndex(entity.Id))["Entity"].Target["Components"].Target, index, replace);
     }
 }
 private static void SerializeAndCompare(AssetItem assetItem, AssetPropertyGraph graph, string expectedYaml, bool isDerived)
 {
     assetItem.Asset.Id = isDerived ? DerivedId : BaseId;
     Assert.AreEqual(isDerived, assetItem.Asset.Archetype != null);
     if (isDerived)
         assetItem.Asset.Archetype = new AssetReference(BaseId, assetItem.Asset.Archetype?.Location);
     graph.PrepareForSave(null, assetItem);
     var stream = new MemoryStream();
     AssetFileSerializer.Save(stream, assetItem.Asset, null, (Dictionary<YamlAssetPath, OverrideType>)assetItem.Overrides);
     stream.Position = 0;
     var streamReader = new StreamReader(stream);
     var yaml = streamReader.ReadToEnd();
     Assert.AreEqual(expectedYaml, yaml);
 }
            public List <ItemToReload> Run([NotNull] AssetPropertyGraph assetPropertyGraph)
            {
                if (assetPropertyGraph == null)
                {
                    throw new ArgumentNullException(nameof(assetPropertyGraph));
                }
                Reset();
                propertyGraph = assetPropertyGraph;
                var result = ItemsToReload = new List <ItemToReload>();

                Visit(assetPropertyGraph.RootNode.Retrieve());
                ItemsToReload = null;
                return(result);
            }
示例#8
0
        public static void SerializeAndCompare(AssetItem assetItem, AssetPropertyGraph graph, string expectedYaml, bool isDerived)
        {
            assetItem.Asset.Id = isDerived ? DerivedId : BaseId;
            Assert.Equal(isDerived, assetItem.Asset.Archetype != null);
            if (isDerived)
            {
                assetItem.Asset.Archetype = new AssetReference(BaseId, assetItem.Asset.Archetype?.Location);
            }
            graph.PrepareForSave(null, assetItem);
            var stream = new MemoryStream();

            AssetFileSerializer.Save(stream, assetItem.Asset, assetItem.YamlMetadata, null);
            stream.Position = 0;
            var streamReader = new StreamReader(stream);
            var yaml         = streamReader.ReadToEnd();

            Assert.Equal(expectedYaml, yaml);
        }
示例#9
0
        protected void ApplyMetadata(SessionTemplateGeneratorParameters parameters)
        {
            // Create graphs for all assets in the session
            EnsureGraphs(parameters);

            // Then apply metadata from each asset item to the graph
            foreach (var package in parameters.Session.LocalPackages)
            {
                foreach (var asset in package.Assets)
                {
                    var graph     = graphContainer.TryGetGraph(asset.Id) ?? graphContainer.InitializeAsset(asset, parameters.Logger);
                    var overrides = asset.YamlMetadata.RetrieveMetadata(AssetObjectSerializerBackend.OverrideDictionaryKey);
                    if (graph != null && overrides != null)
                    {
                        graph.RefreshBase();
                        AssetPropertyGraph.ApplyOverrides(graph.RootNode, overrides);
                    }
                }
            }
        }
        private static void PostAssemblyReloading(IUndoRedoService actionService, SessionNodeContainer nodeContainer, ReloadingVisitor reloaderVisitor, ILogger log, Dictionary <AssetViewModel, List <ItemToReload> > assetItemsToReload)
        {
            log?.Info("Updating components with newly loaded assemblies");

            // Recreate new objects from Yaml streams
            foreach (var asset in assetItemsToReload)
            {
                // Deserialize objects with reloaded types from Yaml
                reloaderVisitor.Run(asset.Key.Asset, asset.Value);

                // Set new values
                var overrides = new YamlAssetMetadata <OverrideType>();
                foreach (var itemToReload in asset.Value)
                {
                    // Set (members) or add nodes (collections) with values created using newly loaded assemblies
                    ReplaceNode(actionService, asset.Key, itemToReload);
                    if (itemToReload.Overrides != null)
                    {
                        var extendedPath = itemToReload.GraphPath.Clone();
                        if (itemToReload.GraphPathIndex != NodeIndex.Empty)
                        {
                            extendedPath.PushIndex(itemToReload.GraphPathIndex);
                        }

                        var pathToPrepend = AssetNodeMetadataCollectorBase.ConvertPath(extendedPath);

                        foreach (var entry in itemToReload.Overrides)
                        {
                            var path = pathToPrepend.Append(entry.Key);
                            overrides.Set(path, entry.Value);
                        }
                    }
                }

                FixupObjectReferences.RunFixupPass(asset.Key.Asset, reloaderVisitor.ObjectReferences, true, false, log);

                var rootNode = (IAssetNode)nodeContainer.GetNode(asset.Key.Asset);
                AssetPropertyGraph.ApplyOverrides(rootNode, overrides);
            }
        }
示例#11
0
        public override Task Paste(IPasteItem pasteResultItem, AssetPropertyGraph assetPropertyGraph, ref NodeAccessor nodeAccessor, ref PropertyContainer propertyContainer)
        {
            if (pasteResultItem == null)
            {
                throw new ArgumentNullException(nameof(pasteResultItem));
            }

            var    propertyGraph = (EntityHierarchyPropertyGraph)assetPropertyGraph;
            var    parentEntity  = nodeAccessor.RetrieveValue() as Entity;
            string targetFolder;

            propertyContainer.TryGetValue(TargetFolderKey, out targetFolder);

            var hierarchy = pasteResultItem.Data as AssetCompositeHierarchyData <EntityDesign, Entity>;

            if (hierarchy != null)
            {
                foreach (var rootEntity in hierarchy.RootParts)
                {
                    var insertIndex  = parentEntity?.Transform.Children.Count ?? propertyGraph.Asset.Hierarchy.RootParts.Count;
                    var entityDesign = hierarchy.Parts[rootEntity.Id];
                    var folder       = targetFolder;
                    if (!string.IsNullOrEmpty(entityDesign.Folder))
                    {
                        if (!string.IsNullOrEmpty(targetFolder))
                        {
                            folder = folder + "/" + entityDesign.Folder;
                        }
                        else
                        {
                            folder = entityDesign.Folder;
                        }
                    }
                    entityDesign.Folder = folder ?? string.Empty;
                    propertyGraph.AddPartToAsset(hierarchy.Parts, entityDesign, parentEntity, insertIndex);
                }
            }

            return(Task.CompletedTask);
        }
            protected override bool ProcessObject(object obj, Type expectedType)
            {
                // TODO: More advanced checks if IUnloadable is supposed to be a type from the unloaded assembly (this would avoid processing unecessary IUnloadable)
                if (obj != null && (UnloadedAssemblies.Contains(obj.GetType().Assembly) || obj is IUnloadable))
                {
                    NodeIndex index;
                    var       settings = new SerializerContextSettings(Log);
                    var       path     = GraphNodePath.From(propertyGraph.RootNode, CurrentPath, out index);

                    var overrides = AssetPropertyGraph.GenerateOverridesForSerialization(path.GetNode());
                    overrides = RemoveFirstIndexInYamlPath(overrides, index);
                    if (overrides != null)
                    {
                        settings.Properties.Add(AssetObjectSerializerBackend.OverrideDictionaryKey, overrides);
                    }

                    var objectReferences = propertyGraph.GenerateObjectReferencesForSerialization(path.GetNode());
                    objectReferences = RemoveFirstIndexInYamlPath(objectReferences, index);
                    if (objectReferences != null)
                    {
                        settings.Properties.Add(AssetObjectSerializerBackend.ObjectReferencesKey, objectReferences);
                    }

                    var parsingEvents = new List <ParsingEvent>();
                    AssetYamlSerializer.Default.Serialize(new ParsingEventListEmitter(parsingEvents), obj, expectedType, settings);

                    // Buid parent path
                    var parentPath = CurrentPath.Clone();
                    parentPath.Pop();

                    ItemsToReload.Add(new ItemToReload(parentPath, CurrentPath.Clone(), parsingEvents, expectedType));

                    // Don't recurse inside
                    return(true);
                }
                return(false);
            }
示例#13
0
 public void SetPropertyGraph([NotNull] AssetPropertyGraph assetPropertyGraph)
 {
     PropertyGraph = assetPropertyGraph ?? throw new ArgumentNullException(nameof(assetPropertyGraph));
 }
示例#14
0
 public AssetSlimContainer(IUndoRedoService undoRedoService, AssetPropertyGraph propertyGraph)
 {
     this.undoRedoService = undoRedoService;
     this.propertyGraph   = propertyGraph;
 }
示例#15
0
 /// <inheritdoc />
 public override Task Paste(IPasteItem pasteResultItem, AssetPropertyGraph propertyGraph, ref NodeAccessor nodeAccessor, ref PropertyContainer propertyContainer)
 {
     propertyContainer.TryGetValue(IsReplaceKey, out bool replace);
     Paste(pasteResultItem, nodeAccessor.Node, nodeAccessor.Index, replace);
     return(Task.CompletedTask);
 }
示例#16
0
 public AssetToBaseNodeLinker([NotNull] AssetPropertyGraph propertyGraph)
     : base(propertyGraph.Definition)
 {
     this.propertyGraph = propertyGraph;
 }
示例#17
0
 /// <inheritdoc/>
 public string CopyFromAsset(AssetPropertyGraph propertyGraph, AssetId?sourceId, object value, bool isObjectReference)
 {
     return(value != null?CopyFromAssets(new[] { (propertyGraph, sourceId, value, isObjectReference) }, value.GetType()) : null);
示例#18
0
 /// <inheritdoc />
 public virtual Task Paste(IPasteItem pasteResultItem, AssetPropertyGraph propertyGraph, ref NodeAccessor nodeAccessor, ref PropertyContainer propertyContainer)
 {
     // default implementation does nothing
     return(Task.CompletedTask);
 }
示例#19
0
 public AssetBaseToDerivedRegistry(AssetPropertyGraph propertyGraph)
 {
     this.propertyGraph = propertyGraph;
 }