/// <summary> /// Helper function to initialize Kinect camera. /// </summary> /// <returns>CCR Iterator</returns> protected IEnumerator <ITask> InitializeKinect() { var finishedInitialization = new SuccessFailurePort(); ThreadPool.QueueUserWorkItem( param => { try { this.InitializeKinectDevice(); finishedInitialization.Post(SuccessResult.Instance); } catch (Exception e) { LogError(e); finishedInitialization.Post(new Exception(Resources.InitializeFailed)); } }); yield return(finishedInitialization.Choice( success => { base.Start(); this.StartPollingBehavior(); // Merge the internal update ports into the main interleave MainPortInterleave.CombineWith( new Interleave( new ExclusiveReceiverGroup( Arbiter.Receive( true, this.alternateContractUpdatePort, this.OnUpdateAlternates)), new ConcurrentReceiverGroup( Arbiter.Receive( true, this.scheduleNextFrameReadPort, this.OnScheduleNextFrameRead)))); LogInfo(Resources.Initialized); }, fault => { LogError(fault); base.StartFailed(); })); }
public IEnumerator <ITask> SubscribeHandler(Subscribe subscribe) { SuccessFailurePort responsePort = SubscribeHelper(this.submgrPort, subscribe.Body, subscribe.ResponsePort); yield return(responsePort.Choice()); var success = (SuccessResult)responsePort; if (success != null) { SendNotificationToTarget <Replace>(subscribe.Body.Subscriber, this.submgrPort, this.state); } yield break; }
/// <summary> /// Shutdown or kill process /// </summary> /// <returns>ITask enumerator</returns> private IEnumerator <ITask> ShutdownSuccessfullyOrKillProcess() { var shutdownOrTimedOut = new SuccessFailurePort(); Activate(TimeoutPort(DefaultProcessTimeout).Receive(dateTime => shutdownOrTimedOut.Post(new Exception()))); Activate(shutdownOrTimedOut.Choice( success => { }, /*cleanly shutdown*/ failure => /*timed out*/ System.Diagnostics.Process.GetCurrentProcess().Kill())); ControlPanelPort.Post(new DsspDefaultDrop()); Activate(Arbiter.ReceiveWithIterator <DsspDefaultDrop>(false, this.mainPort, this.DropHandler)); shutdownOrTimedOut.Post(SuccessResult.Instance); yield break; }