Exemplo n.º 1
0
 public void Add(ICmd newCmd)
 {
     mCmds.Add(newCmd);      //Add to the mCmds list
     c   = newCmd.GetCell(); //Update c
     t   = c.Text;           //Update t
     bgc = c.BGColor;        //Update bgc
 }
Exemplo n.º 2
0
        public static void Initialise()
        {
            if (initialised)
            {
                return;
            }

            // Load ICmds
            var type = typeof(ICmd);

            Commands = new Dictionary <string, ICmd>();
            foreach (var ctype in AppDomain.CurrentDomain.GetAssemblies()
                     .SelectMany(s => s.GetTypes())
                     .Where(p => type.IsAssignableFrom(p) && !p.IsAbstract))
            {
                ICmd cmd = (ICmd)Activator.CreateInstance(ctype);
                Commands[cmd.Name] = cmd;
            }

            // Load Internals
            Internals = new Dictionary <string, Internal>();
            foreach (string name in Tools.GetEnumNames <Internal>())
            {
                Internals[name] = (Internal)Enum.Parse(typeof(Internal), name);
            }

            // Load Constants
            ImportConstants <Direction>();
            ImportConstants <Job>();
            ImportConstants <Event>();
            ImportConstants <ListenerExpiry>();
            ImportConstants <Action>();

            initialised = true;
        }
Exemplo n.º 3
0
        private bool Next()
        {
            ICmd CmdHandle = CurrentCmd;

            if (CmdHandle == null)
            {
                return(false);
            }
            lock (CmdHandle)
            {
                if (CmdHandle.IsReapteCmd)
                {
                    return(true);
                }
                else if (CmdQueue.Count > 1 && CmdHandle.IsSuccess)
                {
                    CmdQueue.Dequeue();
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
        public void executeUndo()           //execute the command on the top of the undo stack
        {
            redoMessage = getUndoMessage(); //get the redo message
            ICmd cmd = undo.Pop();          //pop the command to undo from the undo stack

            redo.Push(cmd.Exec());          //execute the undo command and add it to the redo stack
        }
Exemplo n.º 5
0
    public override void ProcessCmd(ICmd cmd)
    {
        if (CurrentState.ProcessCmd(cmd))
        {
            NextState = null;
        }
        else
        {
            if (cmd is CmdMove)
            {
                NextState = GetState(E_StateType.Move);
            }
            else if (cmd is CmdAttack)
            {
                NextState = GetState(E_StateType.Attack);
            }
            else if (cmd is CmdDeath)
            {
                NextState = GetState(E_StateType.Death);
            }
            else if (cmd is CmdWeaponShow)
            {
                NextState = GetState(E_StateType.Idle);
            }
        }

        if (NextState == null)
        {
            return;
        }
        ChangeState(cmd);
    }
Exemplo n.º 6
0
    // 添加cmd 并执行一次
    public void AddCmd(ICmd cmd)
    {
        if (cmdCur != cmdCounter.Cur - cmdOffset)
        {
            syncCmd();
        }

#if UNITY_4_1
        Undo.IncrementCurrentEventIndex();
#endif

        // 清除当前位置之后的cmd
        if (cmdList.Count > cmdCur)
        {
            cmdList.RemoveRange(cmdCur, cmdList.Count - cmdCur);
        }

        cmdList.Add(cmd);
        cmd.execute();
        cmdCur++;

#if UNITY_4_3 || UNITY_4_5 || UNITY_4_6
        Undo.RegisterCompleteObjectUndo(cmdCounter, cmd.CmdName);
#elif (UNITY_3_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5 || UNITY_3_6 || UNITY_3_7 || UNITY_3_8 || UNITY_3_9)
        Undo.RegisterUndo(cmdCounter, cmd.CmdName);
#else
        Undo.RecordObject(cmdCounter, cmd.CmdName);
#endif
        cmdCounter.Cur++;
    }
Exemplo n.º 7
0
 private void CmdTask()
 {
     while (true)
     {
         ICmd cmdHandle = CurrentCmd;
         if (cmdHandle == null)
         {
             return;
         }
         cmdHandle.SyncExcute(PacketHandle);
         IsPrivateCmd = false;
         double ResponsedTime = 0;
         if (cmdHandle.IsSuccess)
         {
             ResponsedTime = (cmdHandle.ResponsedTime - cmdHandle.RequestedTime).TotalMilliseconds;
         }
         CmdCostTime += ResponsedTime;
         if (!IsPrivateCmd)
         {
             Log.info("本次命令执行耗时" + ResponsedTime.ToString() + "ms!");
         }
         if (Next())
         {
             if (!IsPrivateCmd)
             {
                 Log.info("将执行下一条命令!");
             }
             CmdEvent.Set();
         }
         else
         {
             return;
         }
     }
 }
Exemplo n.º 8
0
        private void redoCellTextChangeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ICmd temp = mySpreadsheet.popRedo();

            mySpreadsheet.AddUndo(temp.Exec());
            undoCellTextChangeToolStripMenuItem.Enabled = true;
        }
Exemplo n.º 9
0
    public override bool ProcessCmd(ICmd cmd)
    {
        if (cmd is CmdMove)
        {
            if (Cmd != null)
            {
                Cmd.SetSuccess();
            }
            SetFinished(false);

            Initialize(cmd);
            return(true);
        }

        if (cmd is CmdWeaponShow)
        {
            cmd.SetSuccess();
            PlayAnim(GetMotionType());
            return(true);
        }

        if (cmd is CmdIdle)
        {
            cmd.SetSuccess();
            SetFinished(true);
        }

        return(false);
    }
Exemplo n.º 10
0
 public void ProcessCmd(ICmd cmd)
 {
     if (cmd != null && cmd.IsFailed)
     {
         return;
     }
     FSM.ProcessCmd(cmd);
 }
Exemplo n.º 11
0
 public bool Add(ICmd cmd)
 {
     lock (CmdLock)
     {
         CmdQueue.Enqueue(cmd);
         return(true);
     }
 }
Exemplo n.º 12
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="cmdStr"></param>
        /// <returns></returns>
        internal static ICmd ParseSqlCmdString(string cmdStr, CoreEA.ICoreEAHander dbe)
        {
            ICmd curCmd = null;

            if (string.IsNullOrEmpty(cmdStr))
            {
                ProcessException.DisplayErrors(new Exception("Empty Command"));
                return(null);
            }
            try
            {
                cmdStr = cmdStr.TrimStart();
                cmdStr = cmdStr.TrimEnd();

                //Can't to lower , otherwise the insert data will never 大写
                //cmdText = cmdText.ToLower();
                string tempCmdText = cmdStr.ToLower();
                if (tempCmdText.StartsWith("select"))
                {
                    curCmd = new SelectCmd(dbe);
                }
                else if (tempCmdText.StartsWith("insert"))
                {
                    curCmd = new InsertCmd(dbe);
                }
                else if (tempCmdText.StartsWith("update"))
                {
                    curCmd = new UpdateCmd(dbe);
                }
                else if (tempCmdText.StartsWith("delete"))
                {
                    curCmd = new DeleteCmd(dbe);
                }
                else if (tempCmdText.StartsWith("alter") || (tempCmdText.StartsWith("drop")))
                {
                    curCmd = new SpecialCmd(dbe);
                }
                else if (tempCmdText.StartsWith("create"))
                {
                    curCmd = new CreateCmd(dbe);
                }
                else if (tempCmdText.StartsWith("sp_rename"))
                {
                    curCmd = new SpecialCmd(dbe);
                }
                else
                {
                    curCmd = null;
                    //throw new Exception("ErrorMsg_CannotParseSqlCmd".GetFromResourece());
                }
            }
            catch (Exception ee)
            {
                ProcessException.DisplayErrors(ee);
            }

            return(curCmd);
        }
Exemplo n.º 13
0
 /// <summary>
 /// 添加命令进行派发
 /// </summary>
 /// <param name="cmd"></param>
 public void AddCmd(ICmd cmd)
 {
     IdleTimer = 0f;
     ActiveCmds.Add(cmd);
     for (int i = 0; i < CmdHandlers.Count; i++)
     {
         CmdHandlers[i].ProcessCmd(cmd);
     }
 }
Exemplo n.º 14
0
Arquivo: Trap.cs Projeto: FriyaYe/ciga
 //接收命令
 public void ReceiveCmd(EnumCmdType cmd, ICmd data)
 {
     if (!dicCmds.ContainsKey(cmd))
     {
         Debug.LogError("Error: " + _name + " 对象不存在此命令:" + cmd + " 触发命令失败");
         return;
     }
     dicCmds[cmd].Invoke(data);
 }
Exemplo n.º 15
0
 public LatestVersionService(
     ICmd cmd,
     IStartInstanceService startInstanceService,
     WorkingFolder workingFolder)
 {
     this.cmd = cmd;
     this.startInstanceService = startInstanceService;
     this.workingFolder        = workingFolder;
 }
Exemplo n.º 16
0
 static void Run(ICmd <int> cmd, After after)
 {
     try {
         cmd.Execute();
         after.ProcessOk();
     } catch (Exception e) {
         after.ProcessFailed(e);
     }
 }
Exemplo n.º 17
0
        public static bool AllowedCmd(ICmd cmd, SocketUser user)
        {
            bool isOwner = false;

            if (user is IGuildUser guildUser)
            {
                isOwner = guildUser.RoleIds.Any((role) => role == Bot.Config.OwnerRoleId);
            }
            return(isOwner || !cmd.OwnerOnly);
        }
Exemplo n.º 18
0
        public static Disposable <(ICmd, CommandResultValidation)> ChangeResultValidation(
            this ICmd cmd, CommandResultValidation newResultValidation)
        {
            var oldValue = cmd.ResultValidation;

            cmd.ResultValidation = newResultValidation;
            return(Disposable.New(
                       (Cmd: cmd, OldValue: oldValue),
                       state => state.Cmd.ResultValidation = state.OldValue));
        }
Exemplo n.º 19
0
        /// <summary>
        /// 撤销
        /// </summary>
        public virtual void Undo()
        {
            if (!this.CanUndo)
            {
                return;
            }
            ICmd cmd = cmdHistories[CurrentPosition--];

            cmd.Revoke();
        }
Exemplo n.º 20
0
        /// <summary>
        /// 重做
        /// </summary>
        public virtual void Redo()
        {
            if (!this.CanRedo)
            {
                return;
            }
            ICmd cmd = cmdHistories[++CurrentPosition];

            cmd.Excute();
        }
Exemplo n.º 21
0
    protected override void Initialize(ICmd cmd)
    {
        base.Initialize(cmd);
        Cmd = cmd as CmdMove;

        FinalRotation.SetLookRotation(Owner.BlackBoard.DesiredDirection);
        StartRotation = Owner.Transform.rotation;
        Owner.BlackBoard.MotionType = GetMotionType();
        RotationProgress            = 0;
    }
Exemplo n.º 22
0
 public override void Execute()
 {
     if (WeaponCmd != null && TimeToFinishCmd < Time.timeSinceLevelLoad)
     {
         WeaponCmd.SetSuccess();
         WeaponCmd = null;
         //todo: play id anim.
         PlayIdleAnim();
     }
 }
Exemplo n.º 23
0
        static async Task Run(ICmd <Task> cmd, After after)
        {
            try {
                await cmd.Execute();

                after.ProcessOk();
            } catch (Exception e) {
                after.ProcessFailed(e);
            }
        }
Exemplo n.º 24
0
 static R Run <R>(ICmd <R> cmd, R fail, After after)
 {
     try {
         var result = cmd.Execute();
         after.ProcessOk();
         return(result);
     } catch (Exception e) {
         after.ProcessFailed(e);
         return(fail);
     }
 }
Exemplo n.º 25
0
 public Installer(
     ICommandLine commandLine,
     ICmd cmd,
     IGitEnvironmentService gitEnvironmentService,
     IProgressService progressService)
 {
     this.commandLine           = commandLine;
     this.cmd                   = cmd;
     this.gitEnvironmentService = gitEnvironmentService;
     this.progressService       = progressService;
 }
Exemplo n.º 26
0
    /// <summary>
    /// 放回缓存
    /// </summary>
    /// <param name="cmd"></param>
    public static void Return(ICmd cmd)
    {
        if (cmd == null)
        {
            return;
        }
        cmd.SetUnused();
        UnusedCmds[cmd.Type].Enqueue(cmd);
#if DEBUG
        UsedCmds.Remove(cmd);
#endif
    }
Exemplo n.º 27
0
 public void Clear()
 {
     lock (CmdLock)
     {
         ICmd cmdhandle = CurrentCmd;
         CmdQueue.Clear();
         if (cmdhandle != null)
         {
             cmdhandle.IsCmdStop = true;
         }
     }
 }
Exemplo n.º 28
0
        static async Task <R> Run <R>(ICmd <Task <R> > cmd, R fail, After after)
        {
            try {
                var result = await cmd.Execute();

                after.ProcessOk();
                return(result);
            } catch (Exception e) {
                after.ProcessFailed(e);
                return(fail);
            }
        }
Exemplo n.º 29
0
 public DiffService(
     WorkingFolder workingFolder,
     IGitDiffService gitDiffService,
     IGitStatusService gitStatusService,
     IGitDiffParser diffParser,
     ICmd cmd)
 {
     this.workingFolder    = workingFolder;
     this.gitDiffService   = gitDiffService;
     this.gitStatusService = gitStatusService;
     this.diffParser       = diffParser;
     this.cmd = cmd;
 }
Exemplo n.º 30
0
    protected override void Initialize(ICmd cmd)
    {
        base.Initialize(cmd);

        Owner.BlackBoard.MotionType = E_MotionType.None;
        Owner.BlackBoard.MoveDir    = Vector3.zero;
        Owner.BlackBoard.Speed      = 0;

        if (WeaponCmd == null)
        {
            PlayIdleAnim();
        }
    }
Exemplo n.º 31
0
        /// <summary>
        /// The residence of the listening-socket thread, one for each of the <see cref="ICmd"/>
        /// </summary>
        /// <param name="cmd"></param>
        /// <param name="cmdPort"></param>
        protected internal void HostCmd(ICmd cmd, int cmdPort)
        {
            using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
            {
                //this should NOT be reachable from any other machine
                var endPt = new IPEndPoint(IPAddress.Loopback, cmdPort);
                socket.Bind(endPt);
                socket.Listen(Constants.SOCKET_LISTEN_NUM);

                for (; ; )//ever
                {
                    try
                    {
                        var buffer = new List<byte>();

                        var client = socket.Accept();
                        PrintToConsole($"Connect from port {cmdPort}");
                        var data = new byte[Constants.DEFAULT_BLOCK_SIZE];

                        //park for first data received
                        client.Receive(data, 0, data.Length, SocketFlags.None);
                        buffer.AddRange(data.Where(b => b != (byte)'\0'));
                        while (client.Available > 0)
                        {
                            if (client.Available < Constants.DEFAULT_BLOCK_SIZE)
                            {
                                data = new byte[client.Available];
                                client.Receive(data, 0, client.Available, SocketFlags.None);
                            }
                            else
                            {
                                data = new byte[Constants.DEFAULT_BLOCK_SIZE];
                                client.Receive(data, 0, (int)Constants.DEFAULT_BLOCK_SIZE, SocketFlags.None);
                            }
                            buffer.AddRange(data.Where(b => b != (byte)'\0'));
                        }

                        var output = cmd.Execute(buffer.ToArray());
                        client.Send(output);
                        client.Close();

                    }
                    catch (Exception ex)
                    {
                        PrintToConsole(ex);
                    }
                }
            }
        }