Exemple #1
0
        private static UTinySystem.Reference ParseSystemReference(object obj)
        {
            if (obj is UTinySystem.Reference)
            {
                return((UTinySystem.Reference)obj);
            }

            UTinyId id;
            string  name;
            var     reference = TryParseReference(obj, out id, out name) ? new UTinySystem.Reference(id, name) : new UTinySystem.Reference();

            return(UTinyUpdater.UpdateReference(reference));
        }
Exemple #2
0
        private static UTinyType.Reference ParseTypeReference(object obj, bool updateReference = true)
        {
            if (obj is UTinyType.Reference)
            {
                return((UTinyType.Reference)obj);
            }

            UTinyId id;
            string  name;
            var     reference = TryParseReference(obj, out id, out name) ? new UTinyType.Reference(id, name) : new UTinyType.Reference();

            return(updateReference ? UTinyUpdater.UpdateReference(reference) : reference);
        }
Exemple #3
0
        private static void ParseUTinyList(IRegistry registry, UTinyList uTinyList, IDictionary <string, object> dictionary)
        {
            var typeReference = ParseTypeReference(GetValue(dictionary, "Type"), false);

            IList <object> itemsList;

            if (TryGetValue(dictionary, "Items", out itemsList))
            {
                foreach (var obj in itemsList)
                {
                    var valueDictionary = obj as IDictionary <string, object>;
                    if (valueDictionary != null)
                    {
                        if (valueDictionary.ContainsKey("$TypeId"))
                        {
                            uTinyList.Add(ParseCustomObjectType(registry, valueDictionary));
                        }
                        // @HACK We assume an object `Properties` OR `Type` keys is a `UTinyObject`
                        else if (valueDictionary.ContainsKey("Properties") || valueDictionary.ContainsKey("Type"))
                        {
                            var @object = new UTinyObject(registry, typeReference, null, false);
                            @object.Refresh(null, true);
                            ParseUTinyObject(registry, @object, valueDictionary);
                            uTinyList.Add(@object);
                        }
                        else
                        {
                            throw new NotImplementedException("CommandStream.FrontEnd Failed to deserialize UTinyList item");
                        }
                    }
                    else
                    {
                        uTinyList.Add(obj);
                    }
                }
            }

            uTinyList.Type = UTinyUpdater.UpdateReference(uTinyList.Type);
        }
Exemple #4
0
        private static void ParseUTinyObject(IRegistry registry, UTinyObject uTinyObject, IDictionary <string, object> dictionary)
        {
            IDictionary <string, object> propertiesDictionary;

            if (!TryGetValue(dictionary, "Properties", out propertiesDictionary))
            {
                UTinyUpdater.UpdateObject(uTinyObject);
                return;
            }

            var type = uTinyObject.Type.Dereference(registry);

            foreach (var kvp in propertiesDictionary)
            {
                var valueDictionary = kvp.Value as IDictionary <string, object>;

                if (valueDictionary != null)
                {
                    if (valueDictionary.ContainsKey("Properties"))
                    {
                        if (uTinyObject.HasProperty(kvp.Key))
                        {
                            ParseUTinyObject(registry, uTinyObject[kvp.Key] as UTinyObject, valueDictionary);
                        }
                        else
                        {
                            var typeReference = ParseTypeReference(GetValue(valueDictionary, "Type"), false);
                            var obj           = new UTinyObject(registry, typeReference, null, false);
                            obj.Refresh(null, true);
                            ParseUTinyObject(registry, obj, valueDictionary);
                            obj.Refresh(null, true);
                            uTinyObject[kvp.Key] = obj;
                        }
                    }
                    else if (valueDictionary.ContainsKey("Items"))
                    {
                        if (uTinyObject.HasProperty(kvp.Key))
                        {
                            ParseUTinyList(registry, uTinyObject[kvp.Key] as UTinyList, valueDictionary);
                        }
                        else
                        {
                            var obj = new UTinyList(registry, ParseTypeReference(GetValue(valueDictionary, "Type"), false));
                            ParseUTinyList(registry, obj, valueDictionary);
                            uTinyObject[kvp.Key] = obj;
                        }
                    }
                    else if (valueDictionary.ContainsKey("$TypeId"))
                    {
                        var value = ParseCustomObjectType(registry, valueDictionary);

                        var field = type?.FindFieldByName(kvp.Key);
                        if (field != null)
                        {
                            value = UTinyUpdater.UpdateField(field.Id, value);
                        }

                        uTinyObject[kvp.Key] = value;
                    }
                }
                else
                {
                    var value = kvp.Value;

                    var field = type?.FindFieldByName(kvp.Key);
                    if (field != null)
                    {
                        value = UTinyUpdater.UpdateField(field.Id, value);
                    }

                    uTinyObject[kvp.Key] = value;
                }
            }

            UTinyUpdater.UpdateObject(uTinyObject);
        }