Ejemplo n.º 1
0
        public void Travel(IReadVisitor visitor, TDictionary graph)
        {
            var valueArgs = VisitArgs.DictionaryValue;

            TValue TravelValue()
            {
                TValue value;

                if (_valueVisitor != null)
                {
                    if (!_valueVisitor.TryVisitValue(visitor, valueArgs, out value))
                    {
                        throw new InvalidGraphException("There were no corresponding value to the dictionary key.");
                    }
                    return(value);
                }

                if (visitor.TryVisit(valueArgs) != ValueState.Found)
                {
                    throw new InvalidGraphException("There were no corresponding value to the dictionary key.");
                }
                value = (TValue)_instanceFactory.CreateInstance(_valueType);
                _valueTraveller.Travel(visitor, value);
                visitor.Leave(valueArgs);
                return(value);
            }

            var keyArgs = VisitArgs.DictionaryKey;

            if (_keyVisitor != null)
            {
                while (_keyVisitor.TryVisitValue(visitor, keyArgs, out var key))
                {
                    var value = TravelValue();
                    graph.Add(key, value);
                }
                return;
            }
            while (visitor.TryVisit(keyArgs) == ValueState.Found)
            {
                var key = (TKey)_instanceFactory.CreateInstance(_keyType);
                _keyTraveller.Travel(visitor, key);
                visitor.Leave(keyArgs);

                var value = TravelValue();
                graph.Add(key, value);
            }
        }
Ejemplo n.º 2
0
        public void Travel(IReadVisitor visitor, TCollection graph)
        {
            var itemArgs = VisitArgs.CollectionItem;

            if (_valueVisitor != null)
            {
                while (_valueVisitor.TryVisitValue(visitor, itemArgs, out var value))
                {
                    graph.Add(value);
                }
                return;
            }
            while (visitor.TryVisit(itemArgs) == ValueState.Found)
            {
                var element = (TElement)_instanceFactory.CreateInstance(_elementType);
                _elementTraveller.Travel(visitor, element);
                graph.Add(element);
                visitor.Leave(itemArgs);
            }
        }
Ejemplo n.º 3
0
        public void Travel(IWriteVisitor visitor, DataBlock graph)
        {
            visitor.VisitValue(graph.Id, _argsId);
            visitor.VisitValue(graph.String, _argsString);
            visitor.VisitValue(graph.Int16, _argsInt16);
            visitor.VisitValue(graph.Int32, _argsInt32);
            visitor.VisitValue(graph.Int64, _argsInt64);
            visitor.VisitValue(graph.UInt16, _argsUInt16);
            visitor.VisitValue(graph.UInt32, _argsUInt32);
            visitor.VisitValue(graph.UInt64, _argsUInt64);
            visitor.VisitValue(graph.Single, _argsSingle);
            visitor.VisitValue(graph.Double, _argsDouble);
            visitor.VisitValue(graph.TimeSpan, _argsTimeSpan);
            visitor.VisitValue(graph.Decimal, _argsDecimal);
            visitor.VisitValue(graph.DateTime, _argsDateTime);
            visitor.VisitValue(graph.Byte, _argsByte);
            visitor.VisitValue(graph.Boolean, _argsBoolean);
            visitor.VisitValue(graph.Blob, _argsBlob);

            {
                var c = graph.Messages;
                visitor.Visit(c, _argsMessages);

                if (c != null)
                {
                    foreach (var cv in c)
                    {
                        visitor.VisitValue(cv, VisitArgs.CollectionItem);
                    }
                }

                visitor.Leave(c, _argsMessages);
            }

            {
                var c = (ICollection <DateTime>)graph.Stamps;
                visitor.Visit(c, _argsStamps);
                if (c != null)
                {
                    foreach (var cv in c)
                    {
                        visitor.VisitValue(cv, VisitArgs.CollectionItem);
                    }
                }

                visitor.Leave(c, _argsStamps);
            }

            {
                var c = graph.Relation;
                visitor.Visit(c, _argsRelation);
                if (c != null)
                {
                    _travellerRelation0.Travel(visitor, c);
                }
                visitor.Leave(c, _argsRelation);
            }

            {
                var c = graph.DummyRelation;
                visitor.Visit(c, _argsDummyRelation);
                if (c != null)
                {
                    _travellerRelation0.Travel(visitor, c);
                }
                visitor.Leave(c, _argsDummyRelation);
            }

            {
                var c = (ICollection <Relation>)graph.SecondaryRelations;
                visitor.Visit(c, _argsSecondaryRelations);
                if (c != null)
                {
                    foreach (var cv in c)
                    {
                        visitor.Visit(cv, VisitArgs.CollectionItem);
                        _travellerRelation0.Travel(visitor, cv);
                        visitor.Leave(cv, VisitArgs.CollectionItem);
                    }
                }

                visitor.Leave(c, _argsSecondaryRelations);
            }

            {
                var c = (IDictionary <string, int>)graph.IndexedValues;
                visitor.Visit(c, _argsIndexedValues);
                if (c != null)
                {
                    foreach (var ckv in c)
                    {
                        visitor.VisitValue(ckv.Key, VisitArgs.DictionaryKey);
                        visitor.VisitValue(ckv.Value, VisitArgs.DictionaryValue);
                    }
                }
                visitor.Leave(c, _argsIndexedValues);
            }

            {
                var c = (IDictionary <Identifier, Category>)graph.Categories;
                visitor.Visit(c, _argsCategories);
                if (c != null)
                {
                    foreach (var ckv in c)
                    {
                        visitor.Visit(ckv.Key, VisitArgs.DictionaryKey);
                        _travellerIdentifier1.Travel(visitor, ckv.Key);
                        visitor.Leave(ckv.Key, VisitArgs.DictionaryKey);

                        visitor.Visit(ckv.Value, VisitArgs.DictionaryValue);
                        _travellerCategory2.Travel(visitor, ckv.Value);
                        visitor.Leave(ckv.Value, VisitArgs.DictionaryValue);
                    }
                }
                visitor.Leave(c, _argsCategories);
            }
        }