Esempio n. 1
0
 public T Convert(IKeySetting keySetting)
 {
     if (keySetting == null)
     {
         return(default(T));
     }
     return(keySetting.Accept(this));
 }
Esempio n. 2
0
        public IExcuteTarget ParserToCommand(string[] commands)
        {
            //检查命令格式
            if (commands == null)
            {
                PrintError("GitHeaderTool 需要参数处理");
                return(default(IExcuteTarget));
            }
            if (commands.Length == 1 && commands[0].ToString() == "-help" || commands[0].ToString() == "help")
            {
                PrintHelpInfo();
                return(default(IExcuteTarget));;
            }
            //分配命令
            var commandPairs = GetCommandPairs(commands);

            //检查分配的命令
            if (commandPairs.Count < 2)
            {
                PrintError("命令缺失");
                return(default(IExcuteTarget));
            }
            if (commandPairs.First().CommandLevel != ECommandLevel.f)
            {
                PrintError("命令最少要包含 -f 操作");
                return(default(IExcuteTarget));
            }
            //分配KeySetting
            IKeySetting   fileSearchKey = KeyFactory.Instance.CreateBy(commandPairs.First());
            IExcuteTarget excuteTarget  = ((ITarget)fileSearchKey).CreateTarget();
            IExcuteTarget contextTarget = excuteTarget;

            #region 配置处理链
            IKeySetting templateKeySetting = null;
            IKeySetting templateKeyTail    = null;
            for (int index = 1, length = commandPairs.Count; index < length; index++)
            {
                if (index == 1)
                {
                    templateKeySetting = KeyFactory.Instance.CreateBy(commandPairs[index]);
                    templateKeyTail    = templateKeySetting;
                }
                else
                {
                    templateKeyTail.CommandExcute.NextKeySetting = KeyFactory.Instance.CreateBy(commandPairs[index]);
                    templateKeyTail = templateKeyTail.CommandExcute.NextKeySetting;
                }
            }
            #endregion
            #region 配置处理链的上下文
            while (contextTarget != null)
            {
                contextTarget.Header.NextKeySetting = templateKeySetting;
                contextTarget = contextTarget.NextTarget;
            }
            #endregion
            return(excuteTarget);
        }
Esempio n. 3
0
 /// <summary>
 /// 创建处理目标
 /// </summary>
 /// <returns></returns>
 public IExcuteTarget CreateTarget()
 {
     if (Value.Contains(CommandParser.ParamterSplit))
     {
         var           p              = Value.Split(CommandParser.ParamterSplit[0]);
         string        dir            = p[0];
         string        searchConditon = p[1];
         var           files          = searchConditon.GetFiles(dir);
         IExcuteTarget targetHeader   = null;
         IExcuteTarget targetTail     = null;
         for (int index = 0, length = files.Count; index < length; index++)
         {
             if (index == 0)
             {
                 var         commandPair   = new CommandPair("-f", files[index]);
                 IKeySetting fileSearchKey = KeyFactory.Instance.CreateBy(commandPair);
                 targetHeader = ((ITarget)fileSearchKey).CreateTarget();
                 targetTail   = targetHeader;
             }
             else
             {
                 var         commandPair   = new CommandPair("-f", files[index]);
                 IKeySetting fileSearchKey = KeyFactory.Instance.CreateBy(commandPair);
                 targetTail.NextTarget = ((ITarget)fileSearchKey).CreateTarget();
                 targetTail            = targetTail.NextTarget;
             }
         }
         return(targetHeader);
     }
     //当时文件的情况
     if (File.Exists(Value))
     {
         var target = new GitFile(Value, CommandExcute);
         return(target);
     }
     return(default(IExcuteTarget));
 }
Esempio n. 4
0
 public FileCreateCommand(IKeySetting keySetting)
 {
     CommandKey = keySetting;
 }
Esempio n. 5
0
 public FileContentRemoveCommand(IKeySetting keySetting)
 {
     CommandKey = keySetting;
 }
Esempio n. 6
0
 public FileContentAddCommand(IKeySetting keySetting)
 {
     CommandKey = keySetting;
 }
 public FileSearchCommand(IKeySetting keySetting)
 {
     CommandKey = keySetting;
 }
 public ContentCatCommand(IKeySetting keySetting)
 {
     CommandKey = keySetting;
 }