Пример #1
0
        public IEnumerator <ITask> UpdateFormatHandler(UpdateFormat update)
        {
            Format format = update.Body;

            if (_state.Selected != null &&
                _state.Selected.Started)
            {
                yield return((Choice)StopCapture());

                yield return((Choice)SetFormat(format));

                yield return((Choice)StartCapture());

                _state.Selected.Format = format;
                if (format.MaxFramesPerSecond > 0)
                {
                    _state.Selected.Format.MaxFramesPerSecond = format.MaxFramesPerSecond;
                }
                if (format.MinFramesPerSecond > 0)
                {
                    _state.Selected.Format.MinFramesPerSecond = format.MinFramesPerSecond;
                }
                _state.ImageSize = new physics.Vector2(format.Width, format.Height);
                update.ResponsePort.Post(DefaultUpdateResponseType.Instance);
            }
            else
            {
                update.ResponsePort.Post(
                    Fault.FromCodeSubcodeReason(
                        W3C.Soap.FaultCodes.Receiver,
                        DsspFaultCodes.OperationFailed,
                        "No camera is currently selected"
                        )
                    );
            }
        }
Пример #2
0
        void UpdateFormatInternal(UpdateFormat update)
        {
            Format format = update.Body;

            if (_state.Selected != null &&
                _state.Selected.FrameGrabber != null)
            {
                vision.FrameGrabber grabber = _state.Selected.FrameGrabber;

                grabber.StopCapture();
                grabber.Format = (vision.Format)format;
                grabber.StartCapture();
                _state.Selected.Format = new Format(grabber.Format);
                update.ResponsePort.Post(DefaultUpdateResponseType.Instance);
            }
            else
            {
                update.ResponsePort.Post(
                    Fault.FromCodeSubcodeReason(FaultCodes.Receiver,
                                                DsspFaultCodes.OperationFailed,
                                                "No camera is currently selected")
                    );
            }
        }
Пример #3
0
        public IEnumerator <ITask> HttpPostHandler(HttpPost post)
        {
            Fault fault = null;
            NameValueCollection collection = null;

            ReadFormData readForm = new ReadFormData(post);

            _utilitiesPort.Post(readForm);

            yield return(Arbiter.Choice(
                             readForm.ResultPort,
                             delegate(NameValueCollection col)
            {
                collection = col;
            },
                             delegate(Exception e)
            {
                fault = Fault.FromException(e);
                LogError(null, "Error processing form data", fault);
            }
                             ));

            if (fault != null)
            {
                post.ResponsePort.Post(fault);
                yield break;
            }

            if (!string.IsNullOrEmpty(collection["ChangeCamera"]))
            {
                string device = string.Empty;
                try
                {
                    device = collection["Camera"];
                }
                catch (Exception e)
                {
                    fault = Fault.FromException(e);
                    LogError(null, "Error reading form data", fault);
                }

                if (fault != null)
                {
                    post.ResponsePort.Post(fault);
                    yield break;
                }

                UpdateDeviceRequest request = new UpdateDeviceRequest();
                request.Selected.DevicePath = device;

                UpdateDevice update = new UpdateDevice();
                update.Body = request;

                SpawnIterator(update, UpdateDeviceHandler);

                yield return(Arbiter.Choice(
                                 update.ResponsePort,
                                 delegate(DefaultUpdateResponseType success)
                {
                    SaveState(_state);
                },
                                 delegate(Fault f)
                {
                    fault = f;
                    LogError(null, "Unable to change camera", fault);
                }
                                 ));
            }
            else if (!string.IsNullOrEmpty(collection["ChangeFormat"]))
            {
                int    formatIndex = 0;
                Format format      = null;
                try
                {
                    formatIndex = int.Parse(collection["CaptureFormat"]);
                    format      = _state.Selected.SupportedFormats[formatIndex - 1];
                }
                catch (Exception e)
                {
                    fault = Fault.FromException(e);
                    LogError(null, "Error parsing form data", fault);
                }

                if (fault != null)
                {
                    post.ResponsePort.Post(fault);
                    yield break;
                }

                UpdateFormat update = new UpdateFormat();
                update.Body = format;

                SpawnIterator(update, UpdateFormatHandler);

                yield return(Arbiter.Choice(
                                 update.ResponsePort,
                                 delegate(DefaultUpdateResponseType success)
                {
                    SaveState(_state);
                },
                                 delegate(Fault f)
                {
                    fault = f;
                    LogError(null, "Unable to change format", fault);
                }
                                 ));
            }

            if (fault != null)
            {
                post.ResponsePort.Post(fault);
                yield break;
            }

            post.ResponsePort.Post(new HttpResponseType(HttpStatusCode.OK, _state, _transform));
            yield break;
        }
Пример #4
0
        IEnumerator <ITask> GetInitialState(WebCamState initialState)
        {
            bool deviceSelected = false;

            try
            {
                WebCamState state = new WebCamState();
                state.CaptureFile    = initialState.CaptureFile;
                state.Quality        = initialState.Quality;
                state.FramesOnDemand = initialState.FramesOnDemand;

#if !URT_MINCLR
                yield return(InitializeInternalService());
#endif


                Port <EmptyValue> completion = new Port <EmptyValue>();

                SpawnIterator(state, completion, RefreshCameraList);

                yield return(Arbiter.Receive(false, completion, EmptyHandler));

                state.Image = null;

                Replace replace = new Replace();
                replace.Body = state;
                _fwdPort.Post(replace);

                yield return(Arbiter.Choice(
                                 replace.ResponsePort,
                                 delegate(DefaultReplaceResponseType success) { },
                                 delegate(Fault fault)
                {
                    LogError(null, "Unable to set camera list", fault);
                }
                                 ));

                int deviceIndex;

                if (initialState.Selected != null &&
                    (!string.IsNullOrEmpty(initialState.Selected.DevicePath) ||
                     !string.IsNullOrEmpty(initialState.Selected.FriendlyName)))
                {
                    deviceIndex = -1;
                }
                else
                {
                    deviceIndex = 0;
                }

                bool gotDevice = false;
                while (deviceIndex < state.Cameras.Count && !gotDevice)
                {
                    UpdateDeviceRequest request = new UpdateDeviceRequest();

                    if (deviceIndex < 0)
                    {
                        request.Selected       = initialState.Selected;
                        request.Selected.InUse = false;
                    }
                    else if (deviceIndex < state.Cameras.Count)
                    {
                        request.Selected = state.Cameras[deviceIndex];
                    }

                    if (!request.Selected.InUse)
                    {
                        UpdateDevice update = new UpdateDevice();
                        update.Body = request;
                        _fwdPort.Post(update);

                        yield return(Arbiter.Choice(
                                         update.ResponsePort,
                                         success => gotDevice = true,
                                         fault => LogInfo("Unable to select camera: " + deviceIndex + ": " + fault)
                                         ));
                    }
                    else
                    {
                        LogInfo("Not trying camera (InUse = true): " + deviceIndex);
                    }

                    deviceIndex++;
                }

                if (!gotDevice)
                {
                    LogError("Unable to select device");
                    yield break;
                }

                deviceSelected = true;

                if (initialState.Selected == null ||
                    initialState.Selected.Format == null)
                {
                    yield break;
                }

                UpdateFormat updateFormat = new UpdateFormat();
                updateFormat.Body = initialState.Selected.Format;

                _fwdPort.Post(updateFormat);

                yield return(Arbiter.Choice(
                                 updateFormat.ResponsePort,
                                 delegate(DefaultUpdateResponseType success) { },
                                 delegate(Fault fault)
                {
                    LogError(null, "Unable to select format", fault);
                }
                                 ));
            }
            finally
            {
                if (deviceSelected)
                {
                    DirectoryInsert();
                }
                else
                {
                    LogWarning(LogGroups.Console, "Dropping webcam service, no cameras found");
                    _fwdPort.Post(new DsspDefaultDrop());
                }
            }
        }
Пример #5
0
        static void Main(string[] args)
        {
            // start ticker
            watch.Start();

            ///////////////////////////////////////////////////////////////////////
            // parse commandline arguments and set UpdateFormat.

            // CLASSIC CLIENT USING CMD ARGS
            if ((args.Length == 6 || args.Length == 7) &&
                args[1].Contains("UPDATE"))
            {
                updateFormat = (args.Length == 6) ?
                               UpdateFormat.Classic6Arg :
                               UpdateFormat.Classic7Arg;

                ReadCommandLineArgumentsClassic(args);
            }

            // OGRE CLIENT
            else if (args.Length > 0 || File.Exists(DOTNETURLDATAFILE))
            {
                updateFormat = UpdateFormat.DotNet;
                ReadCommandLineArguments(args);
            }

            // CLASSIC CLIENT USING FILE
            else if (File.Exists(CLASSICURLDATAFILE))
            {
                updateFormat = UpdateFormat.ClassicManual;
            }

            ///////////////////////////////////////////////////////////////////////
            // create UI if not-headless
            if (!isHeadless)
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                // create ui
                form             = new DownloadForm(files, languageHandler, jsonFileProgress);
                form.FormClosed += OnFormClosed;
                form.Show();
            }

            ///////////////////////////////////////////////////////////////////////
            // read url data file if necessary

            switch (updateFormat)
            {
            case UpdateFormat.DotNet:
                if (!ReadUrlDataFile())
                {
                    return;
                }
                break;

            case UpdateFormat.Classic6Arg:
            case UpdateFormat.Classic7Arg:
                // No need to parse file.
                break;

            case UpdateFormat.ClassicManual:
                if (!ReadUrlDataFileClassic())
                {
                    return;
                }
                break;

            case UpdateFormat.None:
                if (!isHeadless)
                {
                    MessageBox.Show(String.Format(languageHandler.UrlInfoMissing, DOTNETURLDATAFILE),
                                    languageHandler.ErrorText, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                break;
            }

            ///////////////////////////////////////////////////////////////////////
            // create worker-instances and start them

            for (int i = 0; i < workers.Length; i++)
            {
                workers[i] = new Worker(
                    PATCHERPATH,
                    baseUrl,
                    queue,
                    queueHashed,
                    queueDone,
                    queueErrors);

                workers[i].Start();
            }

            ///////////////////////////////////////////////////////////////////////
            // start download of patchinfo.txt

            if (updateStage != UpdateStage.Abort)
            {
                if (!isHeadless)
                {
                    form.DisplayStatus(String.Format(languageHandler.DownloadingPatch, MaxStages));
                }

                UpdateStage = UpdateStage.DownloadingJson;

                webClient.DownloadDataCompleted   += OnWebClientDownloadDataCompleted;
                webClient.DownloadProgressChanged += OnWebClientDownloadProgressChanged;
                webClient.DownloadDataAsync(new Uri(jsonUrl));
            }
            ///////////////////////////////////////////////////////////////////////
            // mainthread loop

            long transitionMsTick = 0;

            while (updateStage != UpdateStage.Finished && updateStage != UpdateStage.Abort)
            {
                long   tick   = watch.ElapsedTicks;
                double mstick = (double)tick / MSTICKDIVISOR;

                switch (updateStage)
                {
                case UpdateStage.HashingFiles:
                    if (transitionMsTick == 0)
                    {
                        transitionMsTick = (long)mstick;
                    }
                    // handle transition from scanning to downloading
                    if (files.Count > 0 && queue.Count == 0 &&
                        mstick - transitionMsTick > MINHASHTRANSITIONTIME)
                    {
                        UpdateStage = UpdateStage.DownloadingFiles;
                        if (!isHeadless)
                        {
                            form.DisplayStatus(String.Format(languageHandler.DownloadInit, MaxStages));
                        }
                        transitionMsTick = 0;
                    }
                    break;

                case UpdateStage.DownloadingFiles:
                    // handle PatchFile instances returned by workers
                    ProcessQueues();
                    break;

                case UpdateStage.Ngen:
                    ProcessNgen();
                    break;

                case UpdateStage.FinishedTransition:
                    if (transitionMsTick == 0 && !isHeadless)
                    {
                        transitionMsTick = (long)mstick;
                        if (clientFilesUpdated)
                        {
                            form.DisplayStatus(languageHandler.ClientWasUpdated);
                        }
                        else
                        {
                            form.DisplayStatus(languageHandler.ClientUpToDate);
                        }
                    }
                    if (mstick - transitionMsTick > MINFINISHTRANSITIONTIME)
                    {
                        UpdateStage = UpdateStage.Finished;
                    }
                    break;

                default:
                    break;
                }

                // update UI
                if (!isHeadless)
                {
                    // tick ui
                    if (form != null)
                    {
                        form.Tick(mstick, MaxStages, x64NgenDone, x86NgenDone);
                    }

                    // process messages
                    Application.DoEvents();
                }

                // sleep a bit (-> ~60 FPS)
                Thread.Sleep(16);
            }

            ///////////////////////////////////////////////////////////////////////

            // also stop worker-instances
            foreach (Worker w in workers)
            {
                if (w != null)
                {
                    w.Stop();
                }
            }

            // in case patching went well
            if (updateStage != UpdateStage.Abort)
            {
                // make sure the client executable really exists
                if (File.Exists(Path.Combine(clientPath, clientExecutable)))
                {
                    ProcessStartInfo pi;
                    Process          process;

                    // start client
                    pi                  = new ProcessStartInfo();
                    pi.FileName         = clientExecutable;
                    pi.Arguments        = "";
                    pi.UseShellExecute  = true;
                    pi.WorkingDirectory = clientPath;

                    process           = new Process();
                    process.StartInfo = pi;
                    process.Start();
                }
                else
                {
                    MessageBox.Show(languageHandler.ClientExecutableMissing,
                                    languageHandler.ErrorText, MessageBoxButtons.OK);
                }
            }
        }
Пример #6
0
 IEnumerator <ITask> UpdateFormatHandler(UpdateFormat update)
 {
     UpdateFormatInternal(update);
     yield break;
 }
Пример #7
0
        IEnumerator <ITask> GetInitialState(Srv1CameraState initialState)
        {
            Srv1CameraState state = new Srv1CameraState();

            state.CaptureFile = initialState.CaptureFile;
            state.Quality     = initialState.Quality;

            yield return(InitializeInternalService());

            foreach (object obj in new vision.CameraCollection())
            {
                using (vision.Camera camera = obj as vision.Camera)
                {
                    CameraInstance instance = new CameraInstance();
                    instance.FriendlyName     = camera.Name;
                    instance.DevicePath       = camera.Path;
                    instance.SupportedFormats = ConvertFormats(camera.Formats);

                    state.Cameras.Add(instance);
                }
            }

            state.Image = null;

            Replace replace = new Replace();

            replace.Body = state;
            _fwdPort.Post(replace);

            yield return(Arbiter.Choice(
                             replace.ResponsePort,
                             delegate(DefaultReplaceResponseType success) { },
                             delegate(Fault fault)
            {
                LogError(null, "Unable to set camera list", fault);
            }
                             ));

            UpdateDeviceRequest request = new UpdateDeviceRequest();

            if (initialState.Selected != null)
            {
                request.Selected = initialState.Selected;
            }
            else if (state.Cameras.Count > 0)
            {
                request.Selected = state.Cameras[0];
            }
            else
            {
                yield break;
            }
            UpdateDevice update = new UpdateDevice();

            update.Body = request;
            _fwdPort.Post(update);

            yield return(Arbiter.Choice(
                             update.ResponsePort,
                             delegate(DefaultUpdateResponseType success) { },
                             delegate(Fault fault)
            {
                LogError(null, "Unable to select camera", fault);
            }
                             ));

            if (initialState.Selected == null ||
                initialState.Selected.Format == null)
            {
                yield break;
            }

            UpdateFormat updateFormat = new UpdateFormat();

            updateFormat.Body = initialState.Selected.Format;

            _fwdPort.Post(updateFormat);

            yield return(Arbiter.Choice(
                             updateFormat.ResponsePort,
                             delegate(DefaultUpdateResponseType success) { },
                             delegate(Fault fault)
            {
                LogError(null, "Unable to select format", fault);
            }
                             ));
        }