コード例 #1
0
ファイル: CommandInput.cs プロジェクト: 243107645/JenkinsTest
        public void ParseConsoleCommandStr(string input)
        {
            string[] cmdPeer = input.Split(' ');
            if (cmdPeer.Length != 0)
            {
                string commandName = cmdPeer[0];

                // Find command
                if (_commandDic.ContainsKey(commandName))
                {
                    if (cmdPeer.Length > 1)
                    {
                        // Invoke callback with arguments
                        List <string> args = new List <string>(cmdPeer);
                        args.RemoveAt(0);

                        _commandDic[commandName].callback(args);
                    }
                    else
                    {
                        // Or invoke callback with null
                        _commandDic[commandName].callback(null);
                    }
                }
                else
                {
                    Watchdog.Log(ComponentName(), "Command '" + commandName + "' not found");
                }
            }
        }
コード例 #2
0
        private FieldInfo GetFieldInfo(object obj, string field)
        {
            // Get field info from type
            Type type = obj.GetType();

            // Find field info iteratively
            FieldInfo fieldInfo = null;

            foreach (int one in Enum.GetValues(typeof(BindingFlags)))
            {
                foreach (int two in Enum.GetValues(typeof(BindingFlags)))
                {
                    fieldInfo = type.GetField(field, (BindingFlags)one | (BindingFlags)two);
                    if (fieldInfo != null)
                    {
                        goto next;
                    }
                }
            }

next:

            if (fieldInfo == null)
            {
                Watchdog.Log(GetType().ToString(), string.Format("Field '{0}' not found in {1}", field, obj));
                return(null);
            }
            else
            {
                return(fieldInfo);
            }
        }
コード例 #3
0
        private void Callback(List <string> pars)
        {
            if (finder == null)
            {
                Watchdog.LogError(GetType().ToString(), "Finder has not been assigned!");
            }
            else
            {
                if (pars == null || pars.Count != 2)
                {
                    Watchdog.LogError(GetType().ToString(), "Parameter count incorrect");
                }
                else
                {
                    Queue <string> fieldQueue = new Queue <string>(pars[0].Split('.').ToList());

                    // First object supported by finder
                    string firstField = fieldQueue.Dequeue();
                    object curObj     = finder.Find(firstField);

                    if (curObj == null)
                    {
                        Watchdog.LogError(GetType().ToString(), string.Format("{0} doesn't implemented in finder", firstField));
                    }
                    else
                    {
                        // Support dot hierarchy
                        FieldInfo fieldInfo = null;


                        // Parse sub-obj iteratively
                        while (fieldQueue.Count > 0)
                        {
                            fieldInfo = GetFieldInfo(curObj, fieldQueue.Dequeue());
                            if (fieldInfo == null)
                            {
                                return;
                            }

                            curObj = fieldInfo.GetValue(curObj);
                        }

                        // Display the last object
                        fieldInfo = GetFieldInfo(curObj, pars[1]);
                        if (fieldInfo == null)
                        {
                            return;
                        }

                        // Display the field name, value, and attributes.
                        Watchdog.Log(GetType().ToString(), string.Format("{0} = \"{1}\"; attributes: {2}",
                                                                         fieldInfo.Name, fieldInfo.GetValue(curObj), fieldInfo.Attributes));
                    }
                }
            }
        }
コード例 #4
0
 public void LogNotCompleteProgress()
 {
     _progress.ForEach((x) =>
     {
         if (!x.IsCompleted)
         {
             Watchdog.Log("ParallelProgressFlow", x.ToString());
         }
     });
 }
コード例 #5
0
        private void _Init()
        {
            // Add build-in components
            componentsList = new List <ConsoleComponent>();
            AddConsoleComponent(new FpsDetector());
            AddConsoleComponent(new MainMenuTrigger());

            AddComponentToMainMenu(new WatchdogViewer());
            AddComponentToMainMenu(new CommandButtonPanel());
            AddComponentToMainMenu(new TimerScaler());

            AddConsoleCommand(new FieldReflectCommand());

            GetMainMenu().SetCurrentComponent <CommandButtonPanel>();

            // Log success info
            Watchdog.Log("DebugConsole", "**Initialized**");
        }
コード例 #6
0
        private void DoChangeState(string stateName, object param)
        {
            if (CurrentState != null && CurrentState.StateName == stateName)
            {
                return;
            }

            // Get new state
            var newState = GetStateByName(stateName);

            if (newState == null)
            {
                throw new Exception("fsm: Invalid state name " + stateName);
            }

            if (CurrentState != null)
            {
                // Exit current state
                CurrentState.OnExit();
            }

            PreviousState = CurrentState;
            CurrentState  = newState;

            if (EnableDebug)
            {
                Watchdog.Log(Name,
                             string.Format("Change state from {0} to {1}", PreviousState, CurrentState));
            }

            // Enter new state
            CurrentState.OnEnter(param);

            if (OnStateChanged != null)
            {
                OnStateChanged(PreviousState, CurrentState);
            }
        }