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; }
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()); } } }