protected virtual void Dispose(bool disposing) { if (_status == ContextStatus.Disposed) { return; } if (disposing) { if (_driverName != null) { if (_useDriverBarrier) { WebDriverManager.Instance.ReleaseBarrier(_driverName); } WebDriverManager.Instance.ReleaseReference(_driverName); } else { _webDriver?.Quit(); } _barrier?.Set(); } _status = ContextStatus.Disposed; }
public Context(MposBridge bridge, IProvider provider) { this.bridge = bridge; this.provider = provider; locker = new SemaphoreSlim(1, 1); status = ContextStatus.Uninitialized; }
/// <summary> /// Stop the current playing sequnce. Does not effect scheduled sequences. /// </summary> /// <returns></returns> public static ContextStatus StopSequence(Sequence sequence) { var status = new ContextStatus() { Sequence = sequence, State = ContextStatus.States.Stopped }; IEnumerable <IContext> contexts = VixenSystem.Contexts.Where(x => x.Name.Equals(sequence.Name) && (x.IsRunning || x.IsPaused)); if (!contexts.Any()) { status.Message = "Sequence not found."; } else { foreach (var context in contexts) { context.Stop(); } status.Message = string.Format(@"Sequence {0} stopped.", sequence.Name); } return(status); }
/// <summary> /// Set the current command context. /// </summary> /// <param name="status">The status of the context you are setting.</param> /// <param name="command">The command to be set as the contexted command.</param> /// <param name="args">The arguments to be set as the contexted arguments.</param> /// <param name="text">The custom text to display next to the command line.</param> public void Set(ContextStatus status, string command, string[] args, string text) { if (this.Status == ContextStatus.Passive) if (status == ContextStatus.Forced) this.Backup(); this.Status = status; this.Command = command; this.Args = args; this.Text = text; }
/// <summary> /// Play a sequence of a given file name. /// </summary> /// <param name="sequence"></param> /// <returns></returns> public static ContextStatus PlaySequence(Sequence sequence) { var status = new ContextStatus(); if (sequence == null) { throw new ArgumentNullException("sequence"); } IEnumerable <IContext> contexts = VixenSystem.Contexts.Where(x => x.Name.Equals(sequence.Name) && (x.IsRunning || x.IsPaused)); if (contexts.Any(x => x.IsPaused)) { foreach (var context in contexts) { if (context.IsPaused) { context.Resume(); } } status.Message = string.Format("Resumed {0}", sequence.Name); } else { string fileName = HttpUtility.UrlDecode(sequence.FileName); ISequence seq = SequenceService.Instance.Load(fileName); if (seq != null) { Logging.Info(string.Format("Web - Prerendering effects for sequence: {0}", sequence.Name)); Parallel.ForEach(seq.SequenceData.EffectData.Cast <IEffectNode>(), effectNode => effectNode.Effect.PreRender()); ISequenceContext context = VixenSystem.Contexts.CreateSequenceContext( new ContextFeatures(ContextCaching.NoCaching), seq); context.ContextEnded += context_ContextEnded; context.Play(TimeSpan.Zero, seq.Length); status.State = ContextStatus.States.Playing; status.Sequence = new Sequence() { Name = context.Sequence.Name, FileName = fileName }; status.Message = string.Format("Playing sequence {0} of length {1}", sequence.Name, seq.Length); } else { status.Message = string.Format("Sequence {0} not found.", fileName); } } return(status); }
public async Task Close() { try { await provider.Close(); } catch { // Doesn't matter, we're resetting anyway } status = ContextStatus.Uninitialized; }
/// <summary> /// Set the current command context. /// </summary> /// <param name="status">The status of the context you are setting.</param> /// <param name="command">The command to be set as the contexted command.</param> /// <param name="args">The arguments to be set as the contexted arguments.</param> /// <param name="text">The custom text to display next to the command line.</param> public void Set(ContextStatus status, string command, string[] args, string text) { if (this.Status == ContextStatus.Passive) { if (status == ContextStatus.Forced) { this.Backup(); } } this.Status = status; this.Command = command; this.Args = args; this.Text = text; }
private void UpdateContextStatus(object state) { _contextStatuses.Clear(); foreach (var context in VixenSystem.Contexts) { if (@"Web Server".Equals(context.Name)) { //Skip the web server context. continue; } var status = new ContextStatus() { Sequence = new Sequence() { Name = context.Name }, Position = context.GetTimeSnapshot() }; var sequenceContext = context as ISequenceContext; if (sequenceContext != null) { status.Sequence.FileName = Path.GetFileName(sequenceContext.Sequence.FilePath); } if (context.IsPaused) { status.State = ContextStatus.States.Paused; } else if (context.IsRunning) { status.State = ContextStatus.States.Playing; } else { status.State = ContextStatus.States.Stopped; status.Position = TimeSpan.Zero; //Ensure reported time is set to zero when context is stopped } _contextStatuses.Add(status); } BroadcastContextStates(); }
public async Task <IActionResult> Put(int thingId, string context, [FromBody] ContextStatus contextStatus, [FromQuery] bool recurrent = false) { if (context != contextStatus.context) { ModelState.AddModelError("context", "The Contexts didn match."); } if (ModelState.IsValid) { var curStatus = await _contextStatusService.updateCurrentContextStatus(thingId, context, contextStatus, recurrent); if (curStatus == null) { return(NotFound()); } return(NoContent()); } return(BadRequest(ModelState)); }
public async Task <Boolean?> Initialize(InitializeRequest request, Action <Int32> onError) { if (status == ContextStatus.Ready) { return(false); } await locker.WaitAsync(); try { var device = bridge.DeviceManager.GetById(request.DeviceId); var dataPath = ensureDataPath(device, request.EncryptionKey); var completedInit = await provider.Open(new InitializationOptions { Device = device, EncryptionKey = request.EncryptionKey, StoragePath = dataPath, BaudRate = request.BaudRate, OnError = onError }).SetTimeout(request.TimeoutMilliseconds); if (!completedInit) { return(null); } if (!request.SimpleInitialize) { await provider.SynchronizeTables(false); } this.device = device; status = ContextStatus.Ready; } finally { locker.Release(1); } return(true); }
public async Task <ProcessPaymentResponse> ProcessPayment(ProcessPaymentRequest request) { await locker.WaitAsync(); if (status != ContextStatus.Ready) { throw new InvalidOperationException("Another operation is in progress"); } try { status = ContextStatus.InUse; return(await provider.ProcessPayment(request)); } finally { status = ContextStatus.Ready; locker.Release(1); } }
public async Task FinishPayment(FinishPaymentRequest request) { await locker.WaitAsync(); if (status != ContextStatus.Ready) { throw new InvalidOperationException("Another operation is in progress"); } try { status = ContextStatus.InUse; await provider.FinishPayment(request); } finally { status = ContextStatus.Ready; locker.Release(1); } }
/// <summary> /// Set the current command context. /// </summary> /// <param name="status">The status of the context you are setting.</param> /// <param name="command">The command to be set as the contexted command.</param> /// <param name="args">The arguments to be set as the contexted arguments.</param> /// <param name="text">The custom text to display next to the command line.</param> public void SetContext(ContextStatus status, string command, string[] args, string text) { if (_terminalEvents.OnBeforeSetContext != null) { _terminalEvents.OnBeforeSetContext(this); } if (CommandContext.Status == ContextStatus.Passive) { if (status == ContextStatus.Forced) { BackupContext(); } } CommandContext.Status = status; CommandContext.Command = command; CommandContext.Args = args; CommandContext.Text = text; if (_terminalEvents.OnSetContext != null) { _terminalEvents.OnSetContext(this); } }
/// <summary> /// Create a context /// </summary> public bool CreateContext() { CheckContextClosed(); int result = NativeMethods.CreateWipeContext(out _contextId); if(result == NativeMethods.ERRORCODE_SUCCESS) { _isOpen = true; _status = ContextStatus.Stopped; } return ValidResult(result); }
/// <summary> /// Get the status from the native context /// </summary> public bool GetContextStatus(out ContextStatus status) { CheckContextOpen(); status = ContextStatus.Stopped; int result = NativeMethods.GetContextStatus(_contextId); if(result != NativeMethods.ERRORCODE_INVALID_CONTEXT) { switch(result) { case NativeMethods.STATUS_PAUSED: { status = ContextStatus.Paused; break; } case NativeMethods.STATUS_STOPPED: { status = ContextStatus.Stopped; break; } case NativeMethods.STATUS_WIPE: { status = ContextStatus.Wipe; break; } } // synchronize the native status with the managed one _status = status; return true; } return false; }
/// <summary> /// Set the current command context. /// </summary> /// <param name="status">The status of the context you are setting.</param> /// <param name="command">The command to be set as the contexted command.</param> /// <param name="args">The arguments to be set as the contexted arguments.</param> /// <param name="text">The custom text to display next to the command line.</param> public void SetContext(ContextStatus status, string command, string[] args, string text) { if (_terminalEvents.OnBeforeSetContext != null) _terminalEvents.OnBeforeSetContext(this); if (CommandContext.Status == ContextStatus.Passive) if (status == ContextStatus.Forced) BackupContext(); CommandContext.Status = status; CommandContext.Command = command; CommandContext.Args = args; CommandContext.Text = text; if (_terminalEvents.OnSetContext != null) _terminalEvents.OnSetContext(this); }
/// <summary> /// Set the status of the context (wipe,paused,stopped) /// </summary> public bool SetContextStatus(ContextStatus newStatus) { CheckContextInitialized(); int result = NativeMethods.ERRORCODE_SUCCESS; switch(newStatus) { case ContextStatus.Wipe: { if(_status == ContextStatus.Stopped) { result = NativeMethods.StartWipeContext(_contextId); } else if(_status == ContextStatus.Paused) { result = NativeMethods.ResumeWipeContext(_contextId); } break; } case ContextStatus.Paused: { if(_status == ContextStatus.Wipe) { result = NativeMethods.PauseWipeContext(_contextId); } break; } case ContextStatus.Stopped: { if(_status == ContextStatus.Wipe || _status == ContextStatus.Paused) { result = NativeMethods.StopWipeContext(_contextId); } break; } } _status = newStatus; return ValidResult(result); }
public WipeContext() { _status = ContextStatus.Stopped; }
private void Impl_Run() { try { this.Status = ContextStatus.Started; this.Run(); this.Status = ContextStatus.Completed; } catch (TrackerError e) { this.Status = ContextStatus.Error; this.ErrorString = e.Message; if (this.OnError != null) this.OnError.Invoke(e.ErrorType, e.Message); } catch (Exception e) { this.Status = ContextStatus.Error; this.ErrorString = e.Message; if (this.OnError != null) this.OnError.Invoke(TrackerErrorType.Unknown, this.ErrorString); } }
public void Begin() { this.Status = ContextStatus.Pending; this.ErrorString = null; if (this.OnBegin != null) this.OnBegin.Invoke(); this.Connection.Start(); }
public virtual async Task InitializeAsync(Type?contextType = null) { contextType ??= GetType(); Task?waitForInitialization = null; lock (@lock) { if (_status == ContextStatus.Initialized) { return; } else if (_status == ContextStatus.Initializing) { waitForInitialization = _initializeEvent.ToTask((int)BarrierManager.WaitHandleTimeout.TotalMilliseconds); } else { _status = ContextStatus.Initializing; } } if (waitForInitialization != null) { await waitForInitialization; return; } DriverContextAttribute?useDriverAttr = contextType.GetCustomAttribute <DriverContextAttribute>(true); if (useDriverAttr != null) { _driverName = useDriverAttr.DriverName; _navigate = !useDriverAttr.DisableNavigation; if (useDriverAttr.WaitForBarrier) { _webDriver = await WebDriverManager.Instance.WaitForDriver(_driverName); } else { int references = useDriverAttr.MaxReference <= 0 ? GetDriverReferences(_driverName, contextType) : useDriverAttr.MaxReference; _webDriver = WebDriverManager.Instance.CreateDriver(_driverType, _driverName, references); _useDriverBarrier = true; _webDriver.Manage().Window.Maximize(); } } else { _webDriver = WebDriverManager.CreateDriver(_driverType); _webDriver.Manage().Window.Maximize(); } var barrierDefAttr = contextType.GetCustomAttribute <BarrierAttribute>(); if (barrierDefAttr != null) { _barrier = BarrierManager.Manager.GetWaitHandler(barrierDefAttr.BarrierName ?? contextType.Name); } var barriersAttr = contextType.GetCustomAttributes <WaitForBarrierAttribute>(); if (barriersAttr != null && barriersAttr.Any()) { await Task.WhenAll(barriersAttr.Select(x => BarrierManager.Manager.Wait(x.BarrierName))); } _status = ContextStatus.Initialized; _initializeEvent.Set(); }
public async Task <List <ContextStatus> > updateCurrentContextStatus(int thingId, string context, ContextStatus newContextStatus, bool recurrent = false) { var thingUpdateList = new List <int>(); thingUpdateList.Add(thingId); if (recurrent) { for (int i = 0; i < thingUpdateList.Count; i++) { var(childrenThings, status) = await _thingService.getChildrenThingList(thingUpdateList[i]); if (status == HttpStatusCode.OK && childrenThings.Count != 0) { thingUpdateList.AddRange(childrenThings.Select(x => x.thingId)); } } } var returnstatusList = new List <ContextStatus>(); foreach (var item in thingUpdateList) { var status = await updateThingCurrentStatus(item, context, JsonConvert.SerializeObject(newContextStatus)); returnstatusList.Add(status); } return(returnstatusList); }
/// <summary> /// Destroy a context /// </summary> public bool DestroyContext() { CheckContextOpen(); int result = NativeMethods.ERRORCODE_SUCCESS; // stop the context if(_status != ContextStatus.Stopped) { result = NativeMethods.StopWipeContext(_contextId); } if(result == NativeMethods.ERRORCODE_SUCCESS) { // destroy the context result = NativeMethods.DestroyWipeContext(_contextId); if(result == NativeMethods.ERRORCODE_SUCCESS) { _isOpen = false; _isInitialized = false; _status = ContextStatus.Stopped; } } return ValidResult(result); }