Ejemplo n.º 1
0
        static void ExecuteCommand_Insert(CKey arr_key, CTokenLine line, ITreeBuildSupport inSupport)
        {
            string file_name = line.CommandParams["file"];
            string key_path  = line.CommandParams["key"];

            if (string.IsNullOrEmpty(file_name) && string.IsNullOrEmpty(key_path))
            {
                inSupport.GetLogger().LogError(EErrorCode.PathEmpty, line);
            }

            CKey root = null;

            if (!string.IsNullOrEmpty(file_name))
            {
                root = (CKey)inSupport.GetTree(file_name);
            }
            else
            {
                root = arr_key.GetRoot();
            }

            if (root == null)
            {
                inSupport.GetLogger().LogError(EErrorCode.CantFindInsertFile, line);
                return;
            }

            if (root.KeyCount == 1 && root.GetKey(0).IsArrayKey())
            {
                root = root.GetKey(0);
            }

            CKey key = root;

            if (!string.IsNullOrEmpty(key_path))
            {
                key = (CKey)root.FindKey(key_path);
                if (key == null)
                {
                    inSupport.GetLogger().LogError(EErrorCode.CantFindKey, line);
                    return;
                }
            }

            bool insert_parent = line.CommandParams.ContainsKey("parent");
            CKey copy_key      = key.GetCopy() as CKey;

            if (insert_parent)
            {
                copy_key.SetParent(arr_key);
            }
            else
            {
                arr_key.TakeAllElements(copy_key, false);
            }
            arr_key.CheckOnOneArray();
        }