Esempio n. 1
0
        bool RollActivityPart(ref OMSDIO ini, ref int MessID, ref int LogStep, int ToStep)
        {
            if (LogStep > ToStep)
            {
                return(false);
            }

            if (MessID <= ini.GetMessageCount())
            {
                string s = ini.GetMessage(MessID);
                if (!string.IsNullOrEmpty(s))
                {
                    EventConsumer.FireLogStepEvent(s);
                }
                MessID++;
                int MC = ini.GetMessageOfs(LogStep + 1);
                if ((MC > 0) && (MessID >= MC))
                {
                    if ((ini.GetFailBits() & (1 << LogStep)) == 0)
                    //if ((ini.GetPassBits() & (1 << LogStep)) != 0)
                    {
                        EventConsumer.FireStepPassed();
                        InStep = false;
                    }
                    else
                    {
                        string ErrorLine;
                        GetErrorDescription(out ErrorLine);
                        throw new VideoException(ErrorLine);
                    }

                    do
                    {   // bypassing steps
                        LogStep++;
                        MC = ini.GetMessageOfs(LogStep);
                        System.Threading.Thread.Sleep(1);
                    }while ((MC > 0) && (MessID >= MC));
                    LogStep--;

                    if (LogStep <= ToStep)
                    {
                        EventConsumer.FireBeginStep(StepNames[LogStep]);
                        InStep = true;
                    }
                }
                return(true);
            }
            else
            {
                System.Threading.Thread.Sleep(100);
                return(false);
            }
        }
Esempio n. 2
0
        private void LogOutput(ref int MsgFrom, OMSDIO Ini, int LogStep)
        {
            int MsgTo = Ini.GetMessageOfs(LogStep + 1);

            if ((MsgTo == 0) || (MsgTo < MsgFrom))
            {
                MsgTo = Ini.GetMessageCount() + 1;
            }
            while (MsgFrom < MsgTo)
            {
                string s = Ini.GetMessage(MsgFrom++);
                if (!string.IsNullOrEmpty(s))
                {
                    EventConsumer.FireLogStepEvent(s);
                }
            }
        }
Esempio n. 3
0
        private void DoCommand(
            bool condition, Action commandAction, int stepFrom, int stepTo,
            Action successAction, ContainerState successState, int stepToSetState)
        {
            if (!condition)
            {
                return;
            }
            if ((TestControl == null) || (MediaControl == null))
            {
                throw new VideoException("Internal error in AV engine");
            }
            Exception ex            = null;
            Action    CommandAction = new Action(() =>
            {
                try
                {
                    commandAction();
                }
                catch (Exception e)
                {
                    ex = e;
                }
            });

            OMSDIO ini = new OMSDIO(omsdFileName);

            ini.WriteString("Test State", "StepEnded", "0");
            int MsgFirst = ini.GetMessageCount() + 1;

            int StepEnded = 0;
            int LogStep   = stepFrom;
            int StepState = 0;
            int MsgCurr   = ini.GetMessageCount() + 1;

            IAsyncResult Result = CommandAction.BeginInvoke(null, null);

            try
            {
                DateTime Till = DateTime.Now.AddSeconds(Timeout / 1000);
                if (EventConsumer != null)
                {
                    EventConsumer.FireBeginStep(StepNames[LogStep]);

                    while (StepState != stepTo && LogStep <= stepTo && DateTime.Now < Till)
                    {
                        StepState = ini.ReadInt("Test State", "StepEnded", 0);
                        StepEnded = Math.Min(Math.Abs(StepState), stepTo);
                        // pass steps which has been ended till this moment
                        while (LogStep < StepEnded)
                        {
                            LogOutput(ref MsgCurr, ini, LogStep);

                            EventConsumer.FireStepPassed();
                            EventConsumer.FireBeginStep(StepNames[++LogStep]);
                        }
                        // check if step is ended
                        if (StepEnded != LogStep)
                        {
                            System.Threading.Thread.Sleep(100);
                            // output current messages from this step
                            LogOutput(ref MsgCurr, ini, LogStep);
                            continue;
                        }
                        // output remaining messages from this step
                        LogOutput(ref MsgCurr, ini, LogStep);

                        // step passed
                        if (StepState > 0)
                        {
                            EventConsumer.FireStepPassed();
                        }
                        // step failed
                        if (StepState < 0)
                        {
                            string ErrorLine;
                            GetErrorDescription(out ErrorLine);
                            throw new VideoException(ErrorLine);
                        }
                        // begin next step
                        if (LogStep < stepTo)
                        {
                            EventConsumer.FireBeginStep(StepNames[++LogStep]);
                        }
                    }
                }
                else
                {
                    Result.AsyncWaitHandle.WaitOne(Timeout);
                }
                if (!Result.IsCompleted)
                {   // timeout, no exception in stack
                    throw new VideoException("Connection Timeout");
                }
                if (ex != null)
                {   // action ends with exception
                    if (!InStep && (EventConsumer != null))
                    {
                        EventConsumer.FireBeginStep("Verifying connection state");
                    }
                    throw ex;
                }
            }
            catch (Exception exp)
            {
                if (StepEnded > stepToSetState || (StepEnded == stepToSetState && StepState > 0))
                {
                    State = successState;
                }
                if (exp.Message == "Error HRESULT E_FAIL has been returned from a call to a COM component.")
                {
                    throw new Exception("Operation failed");
                }
                else
                {
                    throw exp;
                }
            }

            successAction();
            State = successState;
        }