Exemplo n.º 1
0
        public void HydrateValue(object obj, string text, IGraph uow)
        {
            IGraph actualUow = null;

            //if we don't have a uow we use the default one
            if (uow == null)
            {
                actualUow = Graph.NewDefault();
            }

            var arr = LengthEncoder.LengthDecodeList(text);

            Condition.Requires(arr.Count).IsEqualTo(this.Maps.Count);

            //iterate thru the Mappings and lines in parallel.
            for (int i = 0; i < arr.Count; i++)
            {
                var map = this.Maps[i];
                MemberMapping <T> eachMap = (MemberMapping <T>)map;

                var line = arr[i];
                //note we inject a null check decoration below
                var mgr = actualUow.ChainOfResponsibility.GetValueManagerById(map.ValueManagerId).DecorateWithNullCheck();
                if (mgr == null)
                {
                    continue;
                }

                var val = mgr.HydrateValue(line, actualUow);
                eachMap.Set((T)obj, val);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// deserializes into a list of nodes
        /// </summary>
        /// <param name="storeText"></param>
        /// <returns></returns>
        public static List <GraphNode> HydrateNodeList(string storeText)
        {
            if (string.IsNullOrEmpty(storeText))
            {
                return(null);
            }

            var lines = LengthEncoder.LengthDecodeList(storeText);

            var list = new List <GraphNode>();

            for (int i = 0; i < lines.Count; i = i + 1)
            {
                if (string.IsNullOrEmpty(lines[i]))
                {
                    continue;
                }

                string    line = lines[i];
                GraphNode node = line;

                list.Add(node);
            }
            return(list);
        }
Exemplo n.º 3
0
        public object HydrateValue(string nodeText, IGraph uow)
        {
            if (string.IsNullOrEmpty(nodeText))
            {
                return(null);
            }

            var list = LengthEncoder.LengthDecodeList(nodeText);

            Condition.Requires(list).HasLength(2);

            var mgr = uow.ChainOfResponsibility.GetValueManagerById(list.ElementAt(0));

            if (mgr == null)
            {
                return(null);
            }

            //if the chain of responsibility produces This as manager, we're in an infinite loop situation and should back out
            if (mgr != null && mgr is UndeclaredValueManager)
            {
                return(null);
            }

            var obj = mgr.HydrateValue(list.ElementAt(1), uow);

            return(obj);
        }
Exemplo n.º 4
0
        void IStringable.Parse(string text)
        {
            var list = LengthEncoder.LengthDecodeList(text);

            Condition.Requires(list).HasLength(3);

            this.Id             = list[0];
            this.InstanceType   = TheTypeLocator.Instance.Locator.FindAssemblyQualifiedType(list[1]);
            this.SerializedData = list[2];
        }
Exemplo n.º 5
0
        public object HydrateValue(string nodeText, IGraph uow)
        {
            var list = LengthEncoder.LengthDecodeList(nodeText);

            Condition.Requires(list).HasLength(2);
            var  typeName = list.ElementAt(0);
            var  serData  = list.ElementAt(1);
            Type type     = TheTypeLocator.Instance.Locator.FindAssemblyQualifiedType(typeName);
            var  obj      = BinarySerializationUtil.Deserialize(type, serData);

            return(obj);
        }
Exemplo n.º 6
0
        public void Parse(string text)
        {
            Condition.Requires(text).IsNotNullOrEmpty();
            var arr = LengthEncoder.LengthDecodeList(text);

            Condition.Requires(arr).IsNotEmpty();
            Condition.Requires(arr).HasLength(4);
            this.TraversalIndex = int.Parse(arr[0]);
            this.ValueManagerId = arr[1];
            this.Id             = arr[2];
            this.Context        = arr[3];

            this.ValidateIsHydrated();
        }
Exemplo n.º 7
0
        public void Parse(string text)
        {
            Condition.Requires(text).IsNotNullOrEmpty();
            var list = LengthEncoder.LengthDecodeList(text);

            List <INodeValueManager> plugins = null;
            //strategy to load the managers (via assembly interrogation/plugin loading)
            Action initPlugins = () =>
            {
                TypeContainer <INodeValueManager> types = TypeContainer <INodeValueManager> .NewDefault();

                plugins = new List <INodeValueManager>();
                foreach (var each in types.ContainedTypes)
                {
                    try
                    {
                        INodeValueManager mgr = Activator.CreateInstance(each) as INodeValueManager;
                        if (list.Contains(mgr.Id))
                        {
                            plugins.Add(mgr);
                        }
                    }
                    catch { }
                }
            };

            //hydrate the managers list in the specified order
            var newList = new List <INodeValueManager>();

            foreach (var each in list)
            {
                //get the mgr by id from the current managers (we want to use managers that we've explicitly added, first)
                //  if it can't be found, get it from the plugins
                var mgr = this.ValueManagers.Find(x => x.Id == each);
                if (mgr == null)
                {
                    //we can't find the manager so load the plugins
                    if (plugins == null)
                    {
                        initPlugins();
                    }

                    mgr = plugins.Find(x => x.Id == each);
                }

                Condition.Requires(mgr).IsNotNull();
                newList.Add(mgr);
            }
            this.ValueManagers = newList;
        }
        public object HydrateValue(string nodeText, IGraph uow)
        {
            var list = LengthEncoder.LengthDecodeList(nodeText);

            Condition.Requires(list).HasLength(2);

            //this is where we examine our context to see if we have the value manager required , if not we return null
            var mgr = uow.ChainOfResponsibility.GetValueManagerById(list[0]);

            if (mgr != null)
            {
                var rv = mgr.HydrateValue(list[1], uow);
                return(rv);
            }
            return(null);
        }
Exemplo n.º 9
0
        public object HydrateValue(string nodeText, IGraph uow)
        {
            var list = LengthEncoder.LengthDecodeList(nodeText);

            Condition.Requires(list).HasLength(2);

            Type cType = TheTypeLocator.Instance.Locator.FindAssemblyQualifiedType(list[0]);

            Condition.Requires(cType).IsNotNull();
            var obj = ReflectionUtil.CreateUninitializedObject(cType);
            IHasHydrationMap hasMap = obj as IHasHydrationMap;
            var map = hasMap.GetHydrationMap();

            map.HydrateValue(obj, list[1], uow);
            return(obj);
        }
Exemplo n.º 10
0
        public void Parse(string text)
        {
            Condition.Requires(text).IsNotNullOrEmpty();
            var arr = LengthEncoder.LengthDecodeList(text);

            Condition.Requires(arr).HasLength(2);
            var storeText   = arr[1];
            var managerText = arr[0];

            var set = ValueManagerChainOfResponsibility.New();

            set.Parse(managerText);
            this.ChainOfResponsibility = set;
            var store = NodeStoreUtil.HydrateNodeStore(storeText);

            this.ReconstituteFromNodeStore(store);
        }
Exemplo n.º 11
0
        public static IStore DeserializeStore(string data, ValueManagerChainOfResponsibility managerSet)
        {
            if (string.IsNullOrEmpty(data))
            {
                return(null);
            }

            var list  = LengthEncoder.LengthDecodeList(data);
            var store = NaturalInMemoryStore.New();

            list.WithEach(each =>
            {
                var item   = DeserializeItem(each, managerSet);
                IHasId obj = item as IHasId;
                store.SaveItem(obj);
            });
            return(store);
        }
Exemplo n.º 12
0
        public object HydrateValue(string nodeText, IGraph uow)
        {
            var list = LengthEncoder.LengthDecodeList(nodeText);

            Condition.Requires(list).HasLength(2);

            var type = PrimitivesUtil.GetSystemPrimitiveTypeBySimpleName(list.ElementAt(0));
            var val  = PrimitivesUtil.ConvertStringToSystemPrimitive(list.ElementAt(1), type);

            if (type == typeof(string))
            {
                var stringVal = val.ToString();
                return(stringVal);
            }
            else
            {
                return(val);
            }
        }
Exemplo n.º 13
0
        public object HydrateValue(string nodeText, IGraph uow)
        {
            var list = LengthEncoder.LengthDecodeList(nodeText);

            Condition.Requires(list).HasLength(2);
            var typeName = list.ElementAt(0);
            var serData  = list.ElementAt(1);

            //instantiate the type, uninitialized
            Type type = TheTypeLocator.Instance.Locator.FindAssemblyQualifiedType(typeName);
            var  obj  = ReflectionUtil.CreateUninitializedObject(type);

            //since it's stringable, we use stringable's parsing to initialize
            IStringable s = obj as IStringable;

            s.Parse(serData);

            return(obj);
        }