public static YamlAssetPath ConvertPath(GraphNodePath path, int inNonIdentifiableType)
        {
            var currentNode = (AssetNode)path.RootNode;
            var result      = new YamlAssetPath();
            var i           = 0;

            foreach (var item in path.Path)
            {
                switch (item.Type)
                {
                case GraphNodePath.ElementType.Member:
                    var member = (string)item.Value;
                    result.PushMember(member);
                    currentNode = (AssetNode)((IGraphNode)currentNode).TryGetChild(member);
                    break;

                case GraphNodePath.ElementType.Target:
                    if (i < path.Path.Count - 1)
                    {
                        currentNode = (AssetNode)((IGraphNode)currentNode).Target;
                    }
                    break;

                case GraphNodePath.ElementType.Index:
                    var index = (Index)item.Value;
                    if (inNonIdentifiableType > 0 || currentNode.IsNonIdentifiableCollectionContent)
                    {
                        result.PushIndex(index.Value);
                    }
                    else
                    {
                        var id = currentNode.IndexToId(index);
                        // Create a new id if we don't have any so far
                        if (id == ItemId.Empty)
                        {
                            id = ItemId.New();
                        }
                        result.PushItemId(id);
                    }
                    if (i < path.Path.Count - 1)
                    {
                        currentNode = (AssetNode)((IGraphNode)currentNode).IndexedTarget(index);
                    }
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
                ++i;
            }
            return(result);
        }
Пример #2
0
        public void TestAbstractReferenceableDictionarySerialization()
        {
            var obj  = new CollectionContainer();
            var item = new Referenceable {
                Id = GuidGenerator.Get(1), Value = "Test"
            };

            obj.AbstractRefDictionary.Add("Item1", item);
            obj.AbstractRefDictionary.Add("Item2", item);
            var objectReferences = new YamlAssetMetadata <Guid>();
            var ids = CollectionItemIdHelper.GetCollectionItemIds(obj.AbstractRefDictionary);

            ids["Item1"] = IdentifierGenerator.Get(1);
            ids["Item2"] = IdentifierGenerator.Get(2);
            var path = new YamlAssetPath();

            path.PushMember(nameof(CollectionContainer.AbstractRefDictionary));
            path.PushItemId(IdentifierGenerator.Get(1));
            objectReferences.Set(path, GuidGenerator.Get(1));
            var yaml = SerializeAsString(obj, objectReferences);

            Assert.AreEqual(AbstractReferenceableDictionaryYaml, yaml);
        }
Пример #3
0
        public void TestConcreteReferenceableListSerialization()
        {
            var obj  = new CollectionContainer();
            var item = new Referenceable {
                Id = GuidGenerator.Get(1), Value = "Test"
            };

            obj.ConcreteRefList.Add(item);
            obj.ConcreteRefList.Add(item);
            var objectReferences = new YamlAssetMetadata <Guid>();
            var ids = CollectionItemIdHelper.GetCollectionItemIds(obj.ConcreteRefList);

            ids[0] = IdentifierGenerator.Get(1);
            ids[1] = IdentifierGenerator.Get(2);
            var path = new YamlAssetPath();

            path.PushMember(nameof(CollectionContainer.ConcreteRefList));
            path.PushItemId(IdentifierGenerator.Get(1));
            objectReferences.Set(path, GuidGenerator.Get(1));
            var yaml = SerializeAsString(obj, objectReferences);

            Assert.AreEqual(ConcreteReferenceableListYaml, yaml);
        }
Пример #4
0
        public static YamlAssetPath ConvertPath(GraphNodePath path, int inNonIdentifiableType)
        {
            var currentNode = (IAssetNode)path.RootNode;
            var result      = new YamlAssetPath();
            var i           = 0;

            foreach (var item in path.Path)
            {
                switch (item.Type)
                {
                case GraphNodePath.ElementType.Member:
                    var member = (string)item.Value;
                    result.PushMember(member);
                    var objectNode = currentNode as IObjectNode;
                    if (objectNode == null)
                    {
                        throw new InvalidOperationException($"An IObjectNode was expected when processing the path [{path}]");
                    }
                    currentNode = (IAssetNode)objectNode.TryGetChild(member);
                    break;

                case GraphNodePath.ElementType.Target:
                    if (i < path.Path.Count - 1)
                    {
                        var targetingMemberNode = currentNode as IMemberNode;
                        if (targetingMemberNode == null)
                        {
                            throw new InvalidOperationException($"An IMemberNode was expected when processing the path [{path}]");
                        }
                        currentNode = (IAssetNode)targetingMemberNode.Target;
                    }
                    break;

                case GraphNodePath.ElementType.Index:
                    var index      = (Index)item.Value;
                    var memberNode = currentNode as AssetMemberNode;
                    if (memberNode == null)
                    {
                        throw new InvalidOperationException($"An AssetMemberNode was expected when processing the path [{path}]");
                    }
                    if (inNonIdentifiableType > 0 || memberNode.IsNonIdentifiableCollectionContent)
                    {
                        result.PushIndex(index.Value);
                    }
                    else
                    {
                        var id = memberNode.IndexToId(index);
                        // Create a new id if we don't have any so far
                        if (id == ItemId.Empty)
                        {
                            id = ItemId.New();
                        }
                        result.PushItemId(id);
                    }
                    if (i < path.Path.Count - 1)
                    {
                        currentNode = (IAssetNode)currentNode.IndexedTarget(index);
                    }
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
                ++i;
            }
            return(result);
        }
        public static YamlAssetPath ConvertPath([NotNull] GraphNodePath path, int inNonIdentifiableType = 0)
        {
            if (path == null)
            {
                throw new ArgumentNullException(nameof(path));
            }
            var currentNode = (IAssetNode)path.RootNode;
            var result      = new YamlAssetPath();
            var i           = 0;

            foreach (var item in path.Path)
            {
                switch (item.Type)
                {
                case GraphNodePath.ElementType.Member:
                {
                    var member = item.Name;
                    result.PushMember(member);
                    var objectNode = currentNode as IObjectNode;
                    if (objectNode == null)
                    {
                        throw new InvalidOperationException($"An IObjectNode was expected when processing the path [{path}]");
                    }
                    currentNode = (IAssetNode)objectNode.TryGetChild(member);
                    break;
                }

                case GraphNodePath.ElementType.Target:
                {
                    if (i < path.Path.Count - 1)
                    {
                        var targetingMemberNode = currentNode as IMemberNode;
                        if (targetingMemberNode == null)
                        {
                            throw new InvalidOperationException($"An IMemberNode was expected when processing the path [{path}]");
                        }
                        currentNode = (IAssetNode)targetingMemberNode.Target;
                    }
                    break;
                }

                case GraphNodePath.ElementType.Index:
                {
                    var index      = item.Index;
                    var objectNode = currentNode as AssetObjectNode;
                    if (objectNode == null)
                    {
                        throw new InvalidOperationException($"An IObjectNode was expected when processing the path [{path}]");
                    }
                    if (inNonIdentifiableType > 0 || !CollectionItemIdHelper.HasCollectionItemIds(objectNode.Retrieve()))
                    {
                        result.PushIndex(index.Value);
                    }
                    else
                    {
                        var id = objectNode.IndexToId(index);
                        // Create a new id if we don't have any so far
                        if (id == ItemId.Empty)
                        {
                            id = ItemId.New();
                        }
                        result.PushItemId(id);
                    }
                    if (i < path.Path.Count - 1)
                    {
                        currentNode = (IAssetNode)objectNode.IndexedTarget(index);
                    }
                    break;
                }

                default:
                    throw new ArgumentOutOfRangeException();
                }
                ++i;
            }
            return(result);
        }
 public static YamlAssetPath ConvertPath(GraphNodePath path, int inNonIdentifiableType)
 {
     var currentNode = (AssetNode)path.RootNode;
     var result = new YamlAssetPath();
     var i = 0;
     foreach (var item in path.Path)
     {
         switch (item.Type)
         {
             case GraphNodePath.ElementType.Member:
                 var member = (string)item.Value;
                 result.PushMember(member);
                 currentNode = (AssetNode)((IGraphNode)currentNode).TryGetChild(member);
                 break;
             case GraphNodePath.ElementType.Target:
                 if (i < path.Path.Count - 1)
                 {
                     currentNode = (AssetNode)((IGraphNode)currentNode).Target;
                 }
                 break;
             case GraphNodePath.ElementType.Index:
                 var index = (Index)item.Value;
                 if (inNonIdentifiableType > 0 || currentNode.IsNonIdentifiableCollectionContent)
                 {
                     result.PushIndex(index.Value);
                 }
                 else
                 {
                     var id = currentNode.IndexToId(index);
                     // Create a new id if we don't have any so far
                     if (id == ItemId.Empty)
                         id = ItemId.New();
                     result.PushItemId(id);
                 }
                 if (i < path.Path.Count - 1)
                 {
                     currentNode = (AssetNode)((IGraphNode)currentNode).IndexedTarget(index);
                 }
                 break;
             default:
                 throw new ArgumentOutOfRangeException();
         }
         ++i;
     }
     return result;
 }