Пример #1
0
        /// <summary>
        ///   執行使用者動作介面
        /// </summary>
        /// <param name="updated">是否 chart 之前曾刷新</param>
        internal void Action(bool updated)
        {
            if (this.Enabled)
            {
                __cParameter.Updated = updated;

                if (__cCurrent == null)
                {
                    int iCount = __cActions.Count;
                    for (int i = 0; i < iCount; i++)
                    {
                        IAction cAction = __cActions[i];
                        cAction.Action(__cParameter);

                        if (__cParameter.IsAction)
                        {
                            __cCurrent = cAction;
                            break;
                        }
                    }
                }
                else
                {
                    __cCurrent.Action(__cParameter);
                    if (!__cParameter.IsAction)
                    {
                        __cCurrent = null;
                    }
                }
            }
        }
Пример #2
0
    public void OnOrderClick()
    {
        if (savedItems.Count == 2)
        {
            if (IsGranded())
            {
                Item queueTicketClone = Instantiate(queueTicket);

                prefToSpawn.GetComponent <ItemCell>().item = queueTicketClone;
                Instantiate(prefToSpawn, vendorPosition, Quaternion.identity);
                prefToSpawn.name = Global.DROPED_ITEM_PREFIX + queueTicketClone.name;

                statusText.text = SetTextColor("Your order in queue #13", TextColor.Green);

                // option
                if (action != null)
                {
                    action.Action();
                }
            }
            else
            {
                statusText.text = SetTextColor("Invalid form", TextColor.Red);
            }
        }
        else
        {
            InitStatus();
        }
    }
Пример #3
0
        private void ProcessThread()
        {
            IAction task = null;

            while (true)
            {
                if (tasks.Count != 0)
                {
                    lock (locker)
                    {
                        if (tasks.Count != 0)
                        {
                            task = tasks.Dequeue();
                        }
                    }

                    if (task != null)
                    {
                        task.Action();
                        task = null;
                    }
                }
                else
                {
                    Thread.Yield();
                }
            }
        }
Пример #4
0
        public static void Time(string name, int iteration, IAction action)
        {
            if (String.IsNullOrEmpty(name))
            {
                return;
            }

            if (action == null)
            {
                return;
            }

            //1. Print name
            ConsoleColor currentForeColor = Console.ForegroundColor;

            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine(name);

            // 2. Record the latest GC counts
            //GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);
            GC.Collect(GC.MaxGeneration);
            int[] gcCounts = new int[GC.MaxGeneration + 1];
            for (int i = 0; i <= GC.MaxGeneration; i++)
            {
                gcCounts[i] = GC.CollectionCount(i);
            }

            // 3. Run action
            Stopwatch watch = new Stopwatch();

            watch.Start();
            long ticksFst = GetCurrentThreadTimes(); //100 nanosecond one tick

            for (int i = 0; i < iteration; i++)
            {
                action.Action();
            }
            long ticks = GetCurrentThreadTimes() - ticksFst;

            watch.Stop();

            // 4. Print CPU
            Console.ForegroundColor = currentForeColor;
            Console.WriteLine("\tTime Elapsed:\t\t" +
                              watch.ElapsedMilliseconds.ToString("N0") + "ms");
            Console.WriteLine("\tTime Elapsed (one time):" +
                              (watch.ElapsedMilliseconds / iteration).ToString("N0") + "ms");
            Console.WriteLine("\tCPU time:\t\t" + (ticks * 100).ToString("N0")
                              + "ns");
            Console.WriteLine("\tCPU time (one time):\t" + (ticks * 100 /
                                                            iteration).ToString("N0") + "ns");

            // 5. Print GC
            for (int i = 0; i <= GC.MaxGeneration; i++)
            {
                int count = GC.CollectionCount(i) - gcCounts[i];
                Console.WriteLine("\tGen " + i + ": \t\t\t" + count);
            }
            Console.WriteLine();
        }
 private void OnMouseDown()
 {
     if (isDisabled)
     {
         return;
     }
     action.Action();
 }
Пример #6
0
        private void ChangeBitMap(Image image)
        {
            if (image is IInputElement element)
            {
                MouseElement = element;

                _clickAction.Action(this);
            }
        }
Пример #7
0
 public void ExecuteAction()
 {
     try
     {
         _action.Action(_rover);
     }
     catch (MovementException mEx)
     {
         throw new MovementException(ExceptionHelper.GetExceptionMessage(mEx) + Environment.NewLine + $"Last position of rover is {_rover.xPos} {_rover.yPos} {_rover.dir}.");
     }
 }
Пример #8
0
 // Update is called once per frame
 void Update()
 {
     if (null != trigger)
     {
         if (trigger.IsTriggered(target))
         {
             if (null != action)
             {
                 action.Action(target);
             }
         }
     }
 }
Пример #9
0
        internal override bool Update(ActionSequence actionSequence, float deltaTime)
        {
            actionSequence.UpdateTimeAxis(deltaTime);
            if (null != action)
            {
                try
                {
                    action.Action(id, actionSequence.cycles);
                }
                catch (Exception e)
                {
                    Debug.LogException(e);
                    actionSequence.Stop();
                }
            }

            return(true);
        }
Пример #10
0
        static void Main(string[] args)
        {
            Console.WriteLine("Enter the Amount");
            String input = Console.ReadLine();

            double money;
            bool   result = Double.TryParse(input, out money);

            if (!result)
            {
                Console.WriteLine("Sorry Try again");

                return;
            }

            Console.WriteLine("Enter the needed action(Deposit or Wirhdrow) ");
            ActionFactory AF  = new ActionFactory();
            IAction       obj = AF.GetUserAction(Console.ReadLine());

            obj.Action(money);
        }
Пример #11
0
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                ShowHelp();
            }
            else
            {
                string  actionName = args[0];
                IAction action     = ActionManager.Instance.GetAction(actionName);

                if (action != null)
                {
                    action.Action(args);
                }
                else
                {
                    Console.WriteLine("Commande inconnue");
                }
            }
        }
Пример #12
0
        public static void Time(string name, int iteration, IAction action)
        {
            if (String.IsNullOrEmpty(name))
            {
                return;
            }

            if (action == null)
            {
                return;
            }

            //1. Print name
            ConsoleColor currentForeColor = Console.ForegroundColor;
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine(name);

            // 2. Record the latest GC counts
            //GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);
            GC.Collect(GC.MaxGeneration);
            int[] gcCounts = new int[GC.MaxGeneration + 1];
            for (int i = 0; i <= GC.MaxGeneration; i++)
            {
                gcCounts[i] = GC.CollectionCount(i);
            }

            // 3. Run action
            Stopwatch watch = new Stopwatch();
            watch.Start();
            long ticksFst = GetCurrentThreadTimes(); //100 nanosecond one tick

            for (int i = 0; i < iteration; i++) action.Action();
            long ticks = GetCurrentThreadTimes() - ticksFst;
            watch.Stop();

            // 4. Print CPU
            Console.ForegroundColor = currentForeColor;
            Console.WriteLine("\tTime Elapsed:\t\t" +
               watch.ElapsedMilliseconds.ToString("N0") + "ms");
            Console.WriteLine("\tTime Elapsed (one time):" +
               (watch.ElapsedMilliseconds / iteration).ToString("N0") + "ms");

            Console.WriteLine("\tCPU time:\t\t" + (ticks * 100).ToString("N0")
                + "ns");
            Console.WriteLine("\tCPU time (one time):\t" + (ticks * 100 /
                iteration).ToString("N0") + "ns");

            // 5. Print GC
            for (int i = 0; i <= GC.MaxGeneration; i++)
            {
                int count = GC.CollectionCount(i) - gcCounts[i];
                Console.WriteLine("\tGen " + i + ": \t\t\t" + count);
            }

            Console.WriteLine();
        }
Пример #13
0
        public void Action(ChartParameter parameter)
        {
            __cGDI.ClearRops(true);
            __cGDI.ClearRops(__cLineInfos, __cTextInfos, !parameter.Updated);

            InputDeviceStatus cStatus = parameter.Status;

            if (cStatus.Event == EInputDeviceEvent.MouseMove)
            {
                ZChart         cChart    = parameter.Chart;
                AxisX          cAxisX    = cChart.AxisX;
                ChartProperty  cProperty = cChart.ChartProperty;
                MouseEventArgs e         = cStatus.GetCurrentMouseArgs();

                int    iOldBKColor = __cGDI.SelectBackground(cProperty.BackgroundColor);
                IntPtr cOldFont    = __cGDI.SelectFont(cProperty.AxisFont);
                IntPtr cPen        = Gdi.CreatePen(new PowerLanguage.PenStyle(cProperty.ForeColor, 1));

                int iBarNumber = cAxisX.ConvertBarNumberFromX(e.X);
                if (iBarNumber > cAxisX.DataCount)
                {
                    return;
                }
                else
                {
                    Rectangle cAxisXRect = cAxisX.AxisRectangle;
                    AxisXUnit cUnit      = cAxisX.ConvertBarNumberToWidth(iBarNumber);
                    cAxisXRect.X     = cUnit.CenterPoint;
                    cAxisXRect.Width = cAxisX.FontMetrics.Width * 12;

                    DateTime cDateTime = cAxisX.ConvertBarNumberToTime(iBarNumber);
                    __cLineInfos.Add(__cGDI.DrawRopLine(cPen, cUnit.CenterPoint, 0, cUnit.CenterPoint, cAxisXRect.Y));
                    __cTextInfos.Add(__cGDI.DrawRopString(cDateTime.ToString("MM/dd HH:mm"), cProperty.BackgroundColor, cProperty.ForeColor, 2, 5, cAxisXRect));
                }

                List <Layer> cLayers = cChart.Layers;
                int          iCount  = cLayers.Count;
                for (int i = 0; i < iCount; i++)
                {
                    Layer cLayer = cLayers[i];
                    if (__cLineInfos.Count == 1 && cLayer.IsLayerScope(e.X, e.Y))
                    {
                        AxisY     cAxisY     = cLayer.AxisY;
                        Rectangle cAxisYRect = cAxisY.AxisRectangle;
                        cAxisYRect.Y      = e.Y;
                        cAxisYRect.Height = cAxisY.FontMetrics.Height;

                        __cLineInfos.Add(__cGDI.DrawRopLine(cPen, 0, e.Y, cAxisYRect.X, e.Y));
                        __cTextInfos.Add(__cGDI.DrawRopString(Math.Round(cAxisY.ConvertValueFromY(e.Y), cAxisY.Decimals).ToString(), cProperty.BackgroundColor, cProperty.ForeColor, 5, 0, cAxisYRect));
                    }

                    cLayer.LegendIndex = iBarNumber;
                    __cEngine.DrawLegend(cLayer, cProperty);
                }

                __cGDI.RemoveObject(__cGDI.SelectFont(cOldFont));
                __cGDI.SelectBackground(iOldBKColor);
            }

            //如果使用者使用十字線功能, 如果有在選擇繪圖功能會在 CustomPainter 屬性儲存繪圖功能的類別名稱
            //如果有繪圖類別名稱就取出使用
            string sName = parameter.CustomPainter;

            if (__cCustomPainter == null && sName != null)
            {
                __cCustomPainter = parameter.Behavior.GetCustomAction(sName);
                if (__cCustomPainter == null || !(__cCustomPainter is IDrawable))
                {
                    parameter.CustomPainter = null;
                }
            }

            if (__cCustomPainter != null)
            {
                __cCustomPainter.Action(parameter);

                //如果繪圖類別名稱 == null 表示繪圖已經完畢
                if (parameter.CustomPainter == null)
                {
                    __cCustomPainter = null;
                }
            }
        }
Пример #14
0
        public static CodeTimerResult Time(string name, int iteration, IAction action)
        {
            if (String.IsNullOrEmpty(name))
            {
                return null;
            }

            if (action == null)
            {
                return null;
            }

            var result = new CodeTimerResult();
            result = result.Reset();
            result.Name = name;
            result.Iteration = iteration;

            GC.Collect(GC.MaxGeneration);
            var gcCounts = new int[GC.MaxGeneration + 1];
            for (int i = 0; i <= GC.MaxGeneration; i++)
            {
                gcCounts[i] = GC.CollectionCount(i);
            }

            // 3. Run action
            var watch = new Stopwatch();
            watch.Start();
            long ticksFst = GetCurrentThreadTimes(); //100 nanosecond one tick

            for (int i = 0; i < iteration; i++) action.Action();
            long ticks = GetCurrentThreadTimes() - ticksFst;
            watch.Stop();

            // 4. Print CPU
            result.TimeElapsed = watch.ElapsedMilliseconds;
            result.CpuCycles = ticks*100;

            // 5. Print GC
            for (int i = 0; i <= GC.MaxGeneration; i++)
            {
                int count = GC.CollectionCount(i) - gcCounts[i];
                result.GenerationList[i] = count;
            }
            return result;
        }
Пример #15
0
 public void Action()
 {
     action?.Action();
 }