Пример #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();
        }
Пример #2
0
        static void ExecuteCommand_Insert(CKey inParent, CTokenLine line, ITreeBuildSupport inSupport, CKey inRoot)
        {
            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 = inRoot;

            if (!string.IsNullOrEmpty(file_name))
            {
                root = (CKey)inSupport.GetTree(file_name);
            }
            //else
            //  root = inParent.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;
                }
            }

            CKey destination_key  = inParent;
            bool insert_in_parent = line.CommandParams.ContainsKey("insert_in_parent");

            if (insert_in_parent)
            {
                if (inParent.Parent != null)
                {
                    destination_key = inParent.Parent;
                }
                else
                {
                    inSupport.GetLogger().LogError(EErrorCode.KeyMustHaveParent, line);
                }
            }

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

            if (add_key)
            {
                copy_key.SetParent(destination_key);
            }
            else
            {
                destination_key.TakeAllElements(copy_key, false);
            }
            destination_key.CheckOnOneArray();
        }