Пример #1
0
 protected bool InsertCommandIntoTree(TreeNodeData currentNodeData, Command newCommand)
 {
     if (IsProperty(currentNodeData))
     {
         if (IsNotAcceptableType(currentNodeData, newCommand))
         {
             return false;
         }
         return InsertCommandIntoPropertyNode(currentNodeData, currentNodeData.Property, newCommand);
     }
     else
     {
         if (IsCommand(currentNodeData))
         {
             CommandTreeNode parentNode = currentNodeData.Node.Parent;
             if (parentNode == null)
             {
                 return false;
             }
             if (IsNotAcceptableType(parentNode.Data, newCommand))
             {
                 return false;
             }
             PropertyInfo property;
             int nestedCommandsCount = NestedCommandsCount(currentNodeData, out property);
             if (nestedCommandsCount == 1)
             {
                 return InsertCommandIntoPropertyNode(currentNodeData, property, newCommand);
             }
             else
             {
                 return InsertCommandIntoParentProperty(currentNodeData, newCommand);
             }
         }
         else
         {
             return false;
         }
     }
 }
Пример #2
0
 private int NestedCommandsCount(TreeNodeData currentNodeData, out PropertyInfo searchProperty)
 {
     Type commandType = currentNodeData.Command.GetType();
     int nestedCommandsCount = 0;
     searchProperty = null;
     foreach (var p in commandType.GetProperties())
     {
         bool isNestedCommand = p.GetCustomAttributes(typeof(GinArgumentCommandAttribute), false).FirstOrDefault() != null;
         if (isNestedCommand)
         {
             nestedCommandsCount++;
             searchProperty = p;
         }
     }
     if (nestedCommandsCount > 1)
     {
         searchProperty = null;
     }
     return nestedCommandsCount;
 }
Пример #3
0
 private bool ReplaceCommandIntoProperty(TreeNodeData currentNodeData, Command newCommand)
 {
     DialogResult dialogResult = DialogResult.OK;
     if (!IsEmptyProperty(currentNodeData, currentNodeData.Property))
     {
         dialogResult = MessageBox.Show("Заменить?", "Заменить?", MessageBoxButtons.OKCancel);
     }
     if (dialogResult == DialogResult.OK)
     {
         currentNodeData.Node.ClearChilds();
         AppendCommandAfter(currentNodeData.Node, newCommand, null);
         return true;
     }
     return false;
 }
Пример #4
0
 private CommandTreeNode IntermediateWithSequence(TreeNodeData currentNodeData)
 {
     CommandTreeNode sequenceCommandsTreeNode = null;
     GinMetaData metaData = GinMetaData.GetInstance();
     ExternalCommand sequence = metaData.Commands.Where(c => c.Instance is CommandSequence).FirstOrDefault();
     if (sequence != null)
     {
         IEnumerable<CommandTreeNode> removedNodes = currentNodeData.Node.Childs;
         currentNodeData.Node.ClearChilds();
         CommandTreeNode sequenceTreeNode = AppendCommandAfter(currentNodeData.Node, sequence.Instance, null);
         sequenceCommandsTreeNode = sequenceTreeNode.Childs.FirstOrDefault();
         foreach (CommandTreeNode node in removedNodes)
         {
             AppendCommandAfter(sequenceCommandsTreeNode, node.Data.Command, null);
         }
     }
     return sequenceCommandsTreeNode;
 }
Пример #5
0
        private bool IsNotAcceptableType(TreeNodeData currentNodeData, Command newCommand)
        {
            bool accepted = false;
            if (currentNodeData.AcceptedTypes != null && currentNodeData.AcceptedTypes.Count() > 0)
            {
                foreach (var type in currentNodeData.AcceptedTypes)
                {
                    accepted |= type.IsInstanceOfType(newCommand);
                }
            }
            else
            {
                accepted |= true;
            }

            if (currentNodeData.NotAcceptedTypes != null && currentNodeData.NotAcceptedTypes.Count() > 0)
            {
                foreach (var type in currentNodeData.NotAcceptedTypes)
                {
                    accepted &= !type.IsInstanceOfType(newCommand);
                }
            }
            else
            {
                accepted &= true;
            }
            return !accepted;
        }
Пример #6
0
        private bool InsertCommandIntoParentProperty(TreeNodeData currentNodeData, Command newCommand)
        {
            //CommandTreeNode parent = currentNodeData.Node.Parent;
            //var commandAttr = newCommand.GetType().GetCustomAttributes(false).OfType<GinNameAttribute>().FirstOrDefault();
            //parent.InsertAfter(newCommand, commandAttr, currentNodeData.Node);

            CommandTreeNode parent = currentNodeData.Node.Parent;
            AppendCommandAfter(parent, newCommand, currentNodeData.Node);

            //CommandTreeNode parent = currentNodeData.Node.Parent;
            //return InsertCommandIntoPropertyNode(parent.Data, parent.Data.Property, newCommand);

            return true;
        }
Пример #7
0
 private bool InsertCommandIntoPropertyNode(TreeNodeData currentNodeData, PropertyInfo property, Command newCommand)
 {
     if (IsEmptyProperty(currentNodeData, property))
     {
         return ReplaceCommandIntoProperty(currentNodeData, newCommand);
     }
     if (IsEnumerableProperty(currentNodeData, property))
     {
         CommandTreeNode node = currentNodeData.Node;
         if (currentNodeData.Property == null || currentNodeData.Property != property)
         {
             IEnumerable<CommandTreeNode> childs = currentNodeData.Node.Childs;
             node = childs.Where(c => c.Data.Property == property).FirstOrDefault();
         }
         AppendCommandAfter(node, newCommand, null);
         return true;
     }
     else
     {
         AppendNodeType appendType = AskUserToDo();
         switch (appendType)
         {
             case AppendNodeType.Append:
                 CommandTreeNode sequenceTreeNode = IntermediateWithSequence(currentNodeData);
                 AppendCommandAfter(sequenceTreeNode, newCommand, null);
                 return true;
             case AppendNodeType.Replace:
                 return ReplaceCommandIntoProperty(currentNodeData, newCommand);
         }
     }
     return false;
 }
Пример #8
0
 protected void RemoveNodes(TreeNodeData currentNodeData)
 {
     if (IsCommand(currentNodeData))
     {
         if (MessageBox.Show("Удалить команду <" + currentNodeData.CommandAttribute.Name + ">?", "Вы уверены?", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) == DialogResult.OK)
         {
             currentNodeData.Node.Remove();
         }
         return;
     }
     if (IsProperty(currentNodeData) && currentNodeData.Node.HasChilds)
     {
         if (MessageBox.Show("Удалить все команды, вложенные в <" + currentNodeData.CommandAttribute.Name + ": " + currentNodeData.PropertyAttribute.Name + ">?", "Вы уверены?", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) == DialogResult.OK)
         {
             currentNodeData.Node.ClearChilds();
         }
         return;
     }
 }
Пример #9
0
 protected bool IsProperty(TreeNodeData currentNodeData)
 {
     return (currentNodeData != null) && (currentNodeData.Command != null) && (currentNodeData.Property != null);
 }
Пример #10
0
 protected bool IsEnumerableProperty(TreeNodeData currentNodeData, PropertyInfo property)
 {
     GinArgumentCommandAttribute attr = (GinArgumentCommandAttribute)property.GetCustomAttributes(typeof(GinArgumentCommandAttribute), false).FirstOrDefault();
     bool isEnumerable = attr != null && attr.IsEnumerable;
     return isEnumerable;
 }
Пример #11
0
 protected bool IsEmptyProperty(TreeNodeData currentNodeData, PropertyInfo property)
 {
     return !currentNodeData.Node.HasChilds;
 }
Пример #12
0
 private bool IsProperty(TreeNodeData data)
 {
     return data != null && data.Command != null && data.Property != null;
 }