Exemplo n.º 1
0
        /// <summary>
        /// Perform common initialization/finalization. Run test action.
        /// </summary>
        /// <param name="action">Test "body"</param>
        /// <param name="cleanUpAction">Clean-up </param>
        protected void RunTest(Action action, Action cleanUpAction)
        {
            if (allPassedModeOn())
            {
                return;
            }

            try
            {
                _halted = false;
                Exception exc = null;

                try
                {
                    System.Diagnostics.Debug.WriteLine("Begin test - inside 1");
                    BeginTest();

                    if (this is IBaseOnvifService)
                    {
                        (this as IBaseOnvifService).GeneralInitialize();
                    }

                    System.Diagnostics.Debug.WriteLine("Begin test - do action");
                    action();
                    System.Diagnostics.Debug.WriteLine("Begin test - action done");

                    if (cleanUpAction == null)
                    {
                        System.Diagnostics.Debug.WriteLine("Begin test - to end test");
                        EndTest(TestStatus.Passed);
                        return;
                    }
                }
                catch (StopEventException)
                {
                    System.Diagnostics.Debug.WriteLine("HALT");

                    if (_videoForm != null)
                    {
                        _videoForm.CloseWindow();
                    }
                    if (NewGenVideo != null)
                    {
                        NewGenVideo.CloseWindow();
                    }

                    Release();
                    _halted = true;

                    LogStepEvent("Halted");
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine("Begin test - Exception in action");
                    StepFailed(ex);
                    System.Diagnostics.Debug.WriteLine("Begin test - fail reported");

                    if (InternalLog)
                    {
                        InternalLogger.GetInstance().SwitchOnForCurrentThread();
                    }
                    else
                    {
                        InternalLogger.GetInstance().SwitchOffForCurrentThread();
                    }

                    InternalLogger.GetInstance().LogMessage("Uncaught exception is thrown during the test!");
                    InternalLogger.GetInstance().LogException(ex);

                    if (cleanUpAction == null)
                    {
                        System.Diagnostics.Debug.WriteLine("Begin test - doing Release");
                        Release();
                        TestFailed(ex);
                        return;
                    }
                    else
                    {
                        exc = ex;
                    }
                }

                if (cleanUpAction != null && !_halted)
                {
                    try
                    {
                        System.Diagnostics.Debug.WriteLine("Clean up");
                        cleanUpAction();
                    }
                    catch (Exception ex)
                    {
                        System.Diagnostics.Debug.WriteLine("Exception when trying to restore settings");
                        StepFailed(ex);
                        exc = ex;
                    }

                    if (exc == null)
                    {
                        System.Diagnostics.Debug.WriteLine("End test - passed");
                        EndTest(TestStatus.Passed);
                    }
                    else
                    {
                        System.Diagnostics.Debug.WriteLine("Test failed");
                        try
                        {
                            Release();
                        }
                        catch (Exception)
                        {
                        }
                        TestFailed(exc);
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("new catch - Test failed");
                TestFailed(ex);
            }
        }
Exemplo n.º 2
0
            public static void VW(object param)
            {
                VideoStreamForm vsf = (VideoStreamForm)param;

                try
                {
                    lock (vsf.eventConsumer)
                    {
                        vsf.streamUri = vsf.getStreamUri(vsf.streamSetup, vsf.profile.token);
                    }
                }
                catch (Exception ex)
                {
                    vsf.exception = ex;
                }

                if (vsf.exception == null)
                {
                    VideoContainer2 videoForm = new VideoContainer2();
                    //videoForm.NICIndex = vsf.NICIndex;
                    VideoUtils.AdjustGeneral2(
                        videoForm, vsf.username, vsf.password, vsf.messageTimeout, vsf.streamSetup.Transport.Protocol,
                        vsf.streamSetup.Stream, vsf.streamUri);
                    VideoUtils.AdjustVideo2(
                        videoForm, vsf.profile.VideoEncoderConfiguration);
                    //videoForm.SetSequence(1);

                    bool VideoIsOpened = false;
                    try
                    {
                        VideoIsOpened       = true;
                        videoForm.EventSink = vsf;
#if false
                        videoForm.SilentStart();
                        ((AutoResetEvent)vsf.eventOpened).Set();
                        vsf.signalCloseWindow.WaitOne();
                        videoForm.SilentStop();
#else
                        videoForm.OpenWindow(false);

                        ((AutoResetEvent)vsf.eventOpened).Set();
                        vsf.signalCloseWindow.WaitOne();

                        videoForm.CloseWindow();
#endif
                        VideoIsOpened = false;
                    }
                    catch (Exception ex)
                    {
                        vsf.exception = ex;
                    }
                    finally
                    {
                        if (VideoIsOpened)
                        {
                            videoForm.CloseWindow();
                        }
                        videoForm = null;
                    }
                }
                ((ManualResetEvent)vsf.eventWorkEnded).Set();
                ((AutoResetEvent)vsf.signalCloseWindow).Set();
            }