コード例 #1
0
        public void AddJob(DeviceJob job)
        {
            if (!m_jobMutex.WaitOne(1000))
            {
                throw new Exception("Failed to get access to job list");
            }

            m_jobs.Add(job);

            m_jobMutex.ReleaseMutex();
        }
コード例 #2
0
        private void RunJob(DeviceJob job)
        {
            job.Lock();

            bool runNow = m_jobs.IsEmpty;

            m_jobs.AddJob(job);
            if (runNow)
            {
                ProcessWaitingJob();
            }

            if (!job.WaitDone())
            {
                throw new Exception("Job failed to run, state machine unstable");
            }
        }
コード例 #3
0
        public DeviceJob TakeJob(int waitForMs = 1000)
        {
            if (!m_jobMutex.WaitOne(waitForMs))
            {
                throw new Exception("Failed to get access to job list");
            }

            DeviceJob result = null;

            if (m_jobs.Count() > 0)
            {
                result = m_jobs[0];
                m_jobs.RemoveAt(0);
            }

            m_jobMutex.ReleaseMutex();
            return(result);
        }
コード例 #4
0
        private DeviceJob AutomateGetToPrivExec()
        {
            var newJob = new DeviceJob();

            newJob.AddTask(new DeviceJobTask
            {
                Name           = "Start",
                Command        = "",
                ResultHandlers = new List <DeviceJobResultHandler>
                {
                    new DeviceJobResultHandler
                    {
                        Expression = _userModePrompt,
                        NextTask   = "Enable"
                    },
                    new DeviceJobResultHandler
                    {
                        Expression = _privExecPrompt,
                        NextTask   = "PrivExecReady"
                    },
                    new DeviceJobResultHandler
                    {
                        Expression = _configPrompt,
                        NextTask   = "ExitConfigMode"
                    }
                }
            });
            newJob.AddTask(new DeviceJobTask
            {
                Name           = "ExitConfigMode",
                Command        = "end",
                ResultHandlers = new List <DeviceJobResultHandler>
                {
                    new DeviceJobResultHandler
                    {
                        Expression = _userModePrompt,
                        NextTask   = "Enable"
                    },
                    new DeviceJobResultHandler
                    {
                        Expression = _privExecPrompt,
                        NextTask   = "PrivExecReady"
                    },
                    new DeviceJobResultHandler
                    {
                        Expression  = _configPrompt,
                        NextTask    = "Error",
                        ErrorString = "Failed to exit config mode"
                    }
                }
            });
            newJob.AddTask(new DeviceJobTask
            {
                Name           = "Enable",
                Command        = "enable",
                ResultHandlers = new List <DeviceJobResultHandler>
                {
                    new DeviceJobResultHandler
                    {
                        Expression  = _userModePrompt,
                        NextTask    = "Error",
                        ErrorString = "Device ignored enabled request"
                    },
                    new DeviceJobResultHandler
                    {
                        Expression = _privExecPrompt,
                        NextTask   = "PrivExecReady"
                    },
                    new DeviceJobResultHandler
                    {
                        Expression = _passwordPrompt,
                        NextTask   = "SendEnablePassword"
                    }
                }
            });
            newJob.AddTask(new DeviceJobTask
            {
                Name           = "SendEnablePassword",
                Command        = EnablePassword,
                ResultHandlers = new List <DeviceJobResultHandler>
                {
                    new DeviceJobResultHandler
                    {
                        Expression  = _userModePrompt,
                        NextTask    = "Error",
                        ErrorString = "Enable password failed"
                    },
                    new DeviceJobResultHandler
                    {
                        Expression = _privExecPrompt,
                        NextTask   = "PrivExecReady"
                    },
                    new DeviceJobResultHandler
                    {
                        Expression  = _passwordPrompt,
                        NextTask    = "Error",
                        ErrorString = "Enable password failed"
                    }
                }
            });

            return(newJob);
        }