コード例 #1
0
ファイル: Utils.cs プロジェクト: Isuroku/GUIBuilder
        public static SWinKeyInfo[] GetWinKeyInfos(IKey inWinKeyParent, CWindowTypeDescrs inWindowTypeDescrs, ILogPrinter inLogger)
        {
            int count = inWinKeyParent.GetChildCount();
            List <SWinKeyInfo> res = new List <SWinKeyInfo>(count);

            for (int i = 0; i < count; i++)
            {
                IKey window_key = inWinKeyParent.GetChild(i);

                var info = new SWinKeyInfo();

                info.WinKey = window_key;

                info.Name = Utils.GetWindowNameFromKey(window_key, i.ToString(), inLogger);

                string[] a = Utils.TryGetParamsByNameFromSubKey("Type", window_key, inLogger, true, 1);
                if (a.Length > 0)
                {
                    string stype = a[0];

                    NamedId?id = inWindowTypeDescrs.GetWinType(stype);

                    if (id.HasValue)
                    {
                        info.WinType = id.Value;
                        res.Add(info);
                    }
                    else
                    {
                        inLogger.LogError(string.Format("Undefined type. Key [{0}]!", window_key.GetPath()));
                    }
                }
            }
            return(res.ToArray());
        }
コード例 #2
0
ファイル: Utils.cs プロジェクト: Isuroku/GUIBuilder
 public static void CopyChilds(this IKey key, ICollection <IKey> outList)
 {
     for (int i = 0; i < key.GetChildCount(); i++)
     {
         outList.Add(key.GetChild(i));
     }
 }
コード例 #3
0
ファイル: CascadeSerializer.cs プロジェクト: Isuroku/Cascade
        void SerializeGenericDictionary(object instance, Type declaredType, IKey inKey, int inInheriteDeep, ILogPrinter inLogger)
        {
            var dictionary = instance as IDictionary;

            Type[] gen_args = declaredType.GetGenericArguments();
            if (gen_args.Length < 2)
            {
                LogError(inLogger, string.Format("SerializeGenericDictionary: Generic Arguments are None. Type {0}. Instance {1}", declaredType.Name, instance));
                return;
            }

            Type keyDeclaredType   = gen_args[0];
            Type valueDeclaredType = gen_args[1];

            if (!keyDeclaredType.IsAtomic())
            {
                LogError(inLogger, "Dictionary must simple key.");
            }
            else
            {
                IKey tree_key = inKey;
                if (tree_key.GetChildCount() > 0)
                {
                    tree_key = inKey.CreateChildKey("BaseDictionary");
                }

                foreach (var key in dictionary.Keys)
                {
                    IKey child = tree_key.CreateChildKey(key.ToString());
                    Serialize(dictionary[key], valueDeclaredType, child, 0, inLogger);
                }
            }
        }
コード例 #4
0
ファイル: CascadeSerializer.cs プロジェクト: Isuroku/Cascade
        bool AllChildsAreArray(IKey inKey)
        {
            if (inKey.GetChildCount() == 0)
            {
                return(false);
            }

            bool all = true;

            for (int i = 0; i < inKey.GetChildCount() && all; ++i)
            {
                if (!inKey.GetChild(i).IsArrayKey())
                {
                    all = false;
                }
            }

            return(all);
        }
コード例 #5
0
ファイル: Utils.cs プロジェクト: Isuroku/GUIBuilder
 public static IKey FindChildByName(this IKey key, string inName, StringComparison comparisonType = StringComparison.InvariantCulture)
 {
     for (int i = 0; i < key.GetChildCount(); i++)
     {
         if (string.Equals(key.GetChild(i).GetName(), inName, comparisonType))
         {
             return(key.GetChild(i));
         }
     }
     return(null);
 }
コード例 #6
0
ファイル: CascadeSerializer.cs プロジェクト: Isuroku/Cascade
        int[] FindArrayDimension(IKey inKey, bool IsAtomicElementType)
        {
            List <int> lst = new List <int>();
            IKey       ck  = inKey;

            while (ck.GetChildCount() > 0 && ck.GetValuesCount() == 0 && AllChildsAreArray(ck))
            {
                lst.Add(ck.GetChildCount());
                ck = ck.GetChild(0);
            }
            if (IsAtomicElementType)
            {
                lst.Add(ck.GetValuesCount());
            }
            else if (lst.Count == 0 && ck.GetChildCount() > 0)
            {
                lst.Add(1);
            }
            return(lst.ToArray());
        }
コード例 #7
0
ファイル: Utils.cs プロジェクト: Isuroku/GUIBuilder
 public static int FindChildIndex(this IKey key, IKey child, ILogPrinter inLogger)
 {
     for (int i = 0; i < key.GetChildCount(); i++)
     {
         if (key.GetChild(i) == child)
         {
             return(i);
         }
     }
     inLogger.LogError(string.Format("Can't FindChildIndex"));
     return(-1);
 }
コード例 #8
0
ファイル: CascadeSerializer.cs プロジェクト: Isuroku/Cascade
        IKey GetKeyByArrayIndex(IKey inParent, int[] indicies)
        {
            IKey key = inParent;

            //indicies.Length - 1 - last array to one key
            for (int i = 0; i < indicies.Length - 1; i++)
            {
                int index = indicies[i];
                if (index >= key.GetChildCount())
                {
                    return(null);
                }
                key = key.GetChild(index);
            }
            return(key);
        }
コード例 #9
0
ファイル: CascadeSerializer.cs プロジェクト: Isuroku/Cascade
        IKey GetOrCreateKeyByArrayIndex(IKey inParent, int[] indicies, int[] lengthes, bool atomic_elems)
        {
            IKey key         = inParent;
            int  keys_length = indicies.Length - 1; //length of key chaine

            //indicies.Length - 1 - last array to one key

            for (int i = 0; i < keys_length; i++)
            {
                int index  = indicies[i];
                int length = lengthes[i];
                while (index >= key.GetChildCount())
                {
                    key.CreateArrayKey();
                }

                key = key.GetChild(index);
            }
            return(key);
        }
コード例 #10
0
        void AddToTree(IKey key, TreeNodeCollection nc)
        {
            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < key.GetValuesCount(); i++)
            {
                IKeyValue value = key.GetValue(i);

                string val_comments = string.Empty;
                if (!string.IsNullOrEmpty(value.Comments))
                {
                    val_comments = string.Format("[//{0}]", value.Comments);
                }

                sb.AppendFormat("{0}{1}, ", value, val_comments);
            }

            string arr_flag = string.Empty;

            if (key.IsArrayKey())
            {
                arr_flag = "[a]";
            }

            string key_comments = string.Empty;

            if (!string.IsNullOrEmpty(key.Comments))
            {
                key_comments = string.Format(" //{0}", key.Comments);
            }

            TreeNode tn = new TreeNode(string.Format("{0}{1}: {2}{3}", key.GetName(), arr_flag, sb, key_comments));

            nc.Add(tn);

            for (int i = 0; i < key.GetChildCount(); i++)
            {
                IKey el = key.GetChild(i);
                AddToTree(el, tn.Nodes);
            }
        }
コード例 #11
0
ファイル: CascadeSerializer.cs プロジェクト: Isuroku/Cascade
        void SerializeGenericCollection(object instance, Type type, IKey inKey, int inInheriteDeep, ILogPrinter inLogger)
        {
            var collection = instance as IEnumerable;

            Type[] gen_args = type.GetGenericArguments();
            if (gen_args.Length == 0)
            {
                LogError(inLogger, string.Format("SerializeGenericCollection: Generic Arguments are None. Type {0}. Instance {1}", type.Name, instance));
                return;
            }

            Type declaredItemType = gen_args[0];
            bool atomic_member    = declaredItemType.IsAtomic();

            IKey tree_key = inKey;

            if (tree_key.GetValuesCount() > 0 || tree_key.GetChildCount() > 0)
            {
                tree_key = inKey.CreateChildKey("BaseCollection");
            }

            if (atomic_member)
            {
                foreach (var item in collection)
                {
                    AddValueToKey(tree_key, item);
                }
            }
            else
            {
                foreach (var item in collection)
                {
                    IKey child = tree_key.CreateArrayKey();
                    Serialize(item, declaredItemType, child, 0, inLogger);
                }
            }
        }
コード例 #12
0
ファイル: CascadeSerializer.cs プロジェクト: Isuroku/Cascade
        object DeserializeArray(IKey inKey, Type type, int inStructDeep, ILogPrinter inLogger)
        {
            if (inKey.IsEmpty)
            {
                return(null);
            }

            IKey key = inKey;

            Array multi_dim_array  = null;
            Type  declaredItemType = type.GetElementType();

            bool is_atomic_elems = declaredItemType.IsAtomic();
            bool is_array_elems  = declaredItemType.IsArray;

            int[] dims;
            if (is_array_elems)
            {
                dims = new int[] { key.GetChildCount() }
            }
            ;
            else
            {
                dims = FindArrayDimension(key, is_atomic_elems);
            }

            if (dims.Length == 0)
            {
                return(null);
            }

            object instance = Array.CreateInstance(declaredItemType, dims);

            multi_dim_array = instance as Array;

            CMultiArrayIndexer indexer = new CMultiArrayIndexer(multi_dim_array);

            while (indexer.MoveNext())
            {
                IKey dim_child = GetKeyByArrayIndex(key, indexer.Current);
                if (dim_child == null)
                {
                    LogError(inLogger, string.Format("Cant get value for multi array index {0}", indexer));
                }
                else
                {
                    object obj_value;
                    int    last_index = indexer.Current[indexer.Current.Length - 1];
                    if (is_atomic_elems)
                    {
                        string str_value;
                        if (dim_child.GetValuesCount() == 0)
                        {
                            str_value = string.Empty;
                        }
                        else
                        {
                            str_value = dim_child.GetValueAsString(last_index);
                        }
                        if (!ReflectionHelper.StringToAtomicValue(str_value, declaredItemType, out obj_value, _reflectionProvider, inLogger))
                        {
                            LogError(inLogger, string.Format("Key {0} [{3}] for collection with element type {1} can't convert value {2}",
                                                             key, declaredItemType.Name, str_value, key.GetPath()));
                        }
                    }
                    else
                    {
                        IKey child = dim_child.GetChild(last_index);
                        obj_value = DeserializeInternal(null, child, declaredItemType, 0, inStructDeep + 1, inLogger);
                    }

                    multi_dim_array.SetValue(obj_value, indexer.Current);
                }
            }

            return(instance);
        }