public StoryWaitEvent(WaitMode mode) : base() { Type = StoryEventType.Wait; Mode = mode; }
public StoryWaitEvent() : base() { Type = StoryEventType.Wait; Mode = WaitMode.Continue; }
public async Task <byte[]> WaitAsync(int count, WaitMode mode, AsyncOperationInfo operationInfo) { throwIfDisposed(); _responseReadTimeout.ThrowIfTimeout(); operationInfo.CancellationToken.ThrowIfCancellationRequested(); byte[] waitResult = null; try { using (_waitTimeout.RestartMode) { switch (mode) { case WaitMode.EXACT: var buffer = new List <byte>(count); while (buffer.Count != count) { _responseReadTimeout.ThrowIfTimeout(); var result = await _pipe.ReadAsync(new PipeReadParameters(count - buffer.Count), _cancellation); if (result.Status.IsOneOf(IOBase.ReadStatus.DONE, IOBase.ReadStatus.PATIALLY_DONE)) { buffer.AddRange(result.Data); } else { throw new NotSupportedException(); } } waitResult = buffer.ToArray(); break; case WaitMode.NO_MORE_THAN: { var result = await _pipe.ReadAsync(new PipeReadParameters(count), _cancellation); if (result.Status.IsOneOf(IOBase.ReadStatus.DONE, IOBase.ReadStatus.PATIALLY_DONE)) { waitResult = result.Data.ToArray(); } else { throw new NotSupportedException(); } } break; default: throw new NotSupportedException(); } } return(waitResult); } finally { await Logger.LogResponseAsync(waitResult ?? new byte[0], count); } }
public async Task <byte[]> WaitAsync(int count, WaitMode waitMode, AsyncOperationInfo operationInfo) { var maxCount = _response.Count - _position; switch (waitMode) { case WaitMode.EXACT: if (maxCount < count) { throw new TimeoutException(); } else { var result = _response.GetRange(_position, count).ToArray(); _position += count; return(result); } case WaitMode.NO_MORE_THAN: var msxAvailableBytes = Math.Min(maxCount, _position + count) - _position; var bytesToRead = Math.Min(count, msxAvailableBytes); _position += bytesToRead; return(_response.GetRange(_position, bytesToRead).ToArray()); default: throw new NotSupportedException(); } }
public async Task <byte[]> WaitAsync(int count, WaitMode waitMode, AsyncOperationInfo operationInfo) { var notYetReadBytes = _array.Count - _position; switch (waitMode) { case WaitMode.EXACT: if (notYetReadBytes < count) { throw new TimeoutException(); } else { _position += count; return(await _array.GetRangeAsync(_position - count, count, operationInfo)); } case WaitMode.NO_MORE_THAN: var dataToRead = (int)Math.Min(notYetReadBytes, count); _position += dataToRead; return(await _array.GetRangeAsync(_position - dataToRead, dataToRead, operationInfo)); default: throw new NotSupportedException(); } }
/// <summary> /// block until state is available /// </summary> /// <param name="socket">blocking or non blocking socket</param> /// <param name="mode">blocking state mode</param> public static void SelectSocket(IntPtr socket, WaitMode mode) { var readFDs = new fd_set(); var exceptFDs = new fd_set(); var writeFDs = new fd_set(); switch (mode) { case WaitMode.Read: readFDs.fd_count = 1; readFDs.fd_array = new IntPtr[] { socket }; break; case WaitMode.Write: writeFDs.fd_count = 1; writeFDs.fd_array = new IntPtr[] { socket }; break; } ; int result = select(0, ref readFDs, ref writeFDs, ref exceptFDs, IntPtr.Zero); if (result < 0) { throw new Exception("Invalid select call"); } }
private void EndEnemyTurn() { Enemy.IdleAnimation.StartAnimations(true); InteractableUI.Instance.GetComponent <RectTransform>().localScale = Vector3.one; TheWaitMode = WaitMode.None; InteractableUI.Instance.EnableButtons(); }
private void cbxMaxExecutionTime_SelectionChanged(object sender, SelectionChangedEventArgs e) { var comboBox = sender as ComboBox; m_waitMode = (WaitMode)comboBox.SelectedIndex; Properties.Settings.Default.IdxMaxWaitTime = comboBox.SelectedIndex; Properties.Settings.Default.Save(); }
public override async Task <byte[]> WaitAsync(int count, WaitMode mode, AsyncOperationInfo operationInfo) { var data = await base.WaitAsync(count, mode, operationInfo); Storage.AddRange(data); return(data); }
/// <summary> /// Block until an emulator event occurs. /// </summary> /// <param name="waitMode">What to wait for.</param> /// <param name="timeoutSecs">Optional timeout. This is not destructive if it fails.</param> /// <returns>Success/failure and failure text.</returns> /// <exception cref="InvalidOperationException">Session is not started.</exception> /// <exception cref="X3270ifCommandException"><see cref="ExceptionMode"/> is enabled and the command fails.</exception> /// <remarks> /// <note type="note"> /// If the specified condition has already been met, <see cref="WaitAsync"/> will return immediately. /// See the documentation under each value of <see cref="WaitMode"/> for details on the conditions for waiting. /// </note> /// <note type="caution"> /// The <see cref="WaitMode.Output"/> flavor of <see cref="Wait"/> is integrated with the calls that /// read data from the screen. You must call <see cref="ReadBuffer"/>, <see cref="Ascii()"/> or <see cref="Ebcdic()"/> /// before a Wait(WaitMode.Output) will actually wait for anything. If you /// Wait(WaitMode.Output) immediately after a previous Wait(WaitMode.Output) without any intervening call to /// <see cref="ReadBuffer"/>, <see cref="Ascii()"/> or <see cref="Ebcdic()"/>, <see cref="Wait"/> will return immediately. /// </note> /// </remarks> public IoResult Wait(WaitMode waitMode, int?timeoutSecs = null) { try { return(this.WaitAsync(waitMode, timeoutSecs).Result); } catch (AggregateException e) { throw e.InnerException; } }
public override async Task <byte[]> WaitAsync(int count, WaitMode waitMode, AsyncOperationInfo operationInfo) { var result = await base.WaitAsync(count, waitMode, operationInfo); ReadCount += result.Length; var bytesToStore = Math.Min(Capacity - (ReadCount - result.Length), result.Length).NegativeToZero().ToInt32(); if (bytesToStore != 0) { _storage.Add(result.Take(bytesToStore)); StorageCount += bytesToStore; } return(result); }
public IWorkResult <TResult> Handle(Func <TWorkArgs> args, Action <IWorkResult <TResult> > uiAction, IWorkResult[] preWorkUnitList, WaitMode mode) { this.waitMode = mode; this.uiAction = uiAction; this.preWorkUnitList = preWorkUnitList; this.workResult.IsError = false; this.workResult.IsComplete = false; Task <IWorkResult <TResult> > task = new Task <IWorkResult <TResult> >( o => { TResult result = default(TResult); try { if (this.waitMode == WaitMode.Default || this.waitMode == WaitMode.Bll) { if (!WorkResult.Wait(this.preWorkUnitList)) { this.isSuccessPreWorkUnitList = false; return(this.workResult); } } result = this.work(args()); this.workResult.Result = result; } catch (DevException hsex) { this.workResult.IsError = true; this.workResult.HsufErrorNo = hsex.ErrorNo; this.workResult.ErrorMessage = hsex.Message; } catch (Exception exc) { this.workResult.IsError = true; this.workResult.ErrorMessage = exc.Message; } return(this.workResult); }, args); task.Start(); task.ContinueWith(this.UpdateUI); return(workResult); }
/// <summary> /// Block until an emulator event occurs, asynchronous version. /// </summary> /// <param name="waitMode">What to wait for.</param> /// <param name="timeoutSecs">Optional timeout. This is not destructive if it fails.</param> /// <returns>Success/failure and failure text.</returns> /// <exception cref="InvalidOperationException">Session is not started.</exception> /// <exception cref="X3270ifCommandException"><see cref="ExceptionMode"/> is enabled and the command fails.</exception> /// <remarks> /// <note type="note"> /// If the specified condition has already been met, <see cref="WaitAsync"/> will return immediately. /// See the documentation under each value of <see cref="WaitMode"/> for details on the conditions for waiting. /// </note> /// <note type="caution"> /// The <see cref="WaitMode.Output"/> flavor of <see cref="WaitAsync"/> is integrated with the calls that /// read data from the screen. You must call <see cref="ReadBuffer"/>, <see cref="Ascii()"/> or <see cref="Ebcdic()"/> /// before a WaitAsync(WaitMode.Output) will actually wait for anything. If you /// Wait(WaitMode.Output) immediately after a previous WaitAsync(Output), without any intervening call to <see cref="ReadBuffer"/>, /// <see cref="Ascii()"/> or <see cref="Ebcdic()"/>, <see cref="WaitAsync"/> will return immediately. /// </note> /// </remarks> public async Task <IoResult> WaitAsync(WaitMode waitMode, int?timeoutSecs = null) { string command = "Wait("; if (timeoutSecs != null) { command += timeoutSecs.ToString() + ","; } var modeName = waitMode.ToString(); if (modeName.StartsWith("Wait")) { modeName = modeName.Substring(4); } command += modeName + ")"; return(await this.IoAsync(command, isModify : waitMode == WaitMode.Output).ConfigureAwait(continueOnCapturedContext: false)); }
public void EndPlayerTurn() { if (TheWaitMode == WaitMode.WaitForFinishWithdrawingTool) { PlayerAttack.ToolAnimation.Reverse(); } Player.IdleAnimation.StartAnimations(true); //Enemy do stuff GetEnemyAttack(); if (EnemyAttack != null) { EnemyAttack.Launch(Enemy, Player); TheWaitMode = WaitMode.WaitForEnemyAttack; } else { Enemy.Energy += 5; Game.Enemy.Missed.Show("Waited"); EndEnemyTurn(); } }
public IWorkResult <TResult> Execute(TWorkArgs args, Action <IWorkResult <TResult> > uiAction, IWorkResult[] preWorkUnitList, WaitMode mode) { return(this.work.Handle(args, uiAction, preWorkUnitList, mode)); }
public IWorkResult <TResult> ExecuteSync(Func <TWorkArgs> args, Action <IWorkResult <TResult> > uiAction, IWorkResult[] preWorkUnitList, WaitMode mode) { IWorkResult <TResult> workResult = new WorkResult <TResult>() { IsError = false, Result = default(TResult) }; if (mode == WaitMode.Default || mode == WaitMode.Bll) { this.Wait(preWorkUnitList, workResult); } if (!workResult.IsError) { try { TResult result = this.workSync(args()); workResult.Result = result; } catch (DevException hsex) { workResult.IsError = true; workResult.HsufErrorNo = hsex.ErrorNo; workResult.ErrorMessage = hsex.Message; } catch (Exception exc) { workResult.IsError = true; workResult.ErrorMessage = exc.Message; } } if (!workResult.IsError) { if (mode == WaitMode.UI) { this.Wait(preWorkUnitList, workResult); } } if (uiAction != null) { try { uiAction(workResult); } catch (Exception exc) { Console.WriteLine(exc.Message); } } workResult.IsComplete = true; return(workResult); }
public IWorkResult <TResult> ExecuteSync(TWorkArgs args, Action <IWorkResult <TResult> > uiAction, IWorkResult[] preWorkUnitList, WaitMode mode) { return(this.ExecuteSync(() => { return args; }, uiAction, preWorkUnitList, mode)); }
private void Update() { switch (TheWaitMode) { case WaitMode.None: if (count != Mathf.NegativeInfinity) { count -= Time.deltaTime; if (count <= 0) { if (PlayerPrefs.GetInt("IsBoss", 0) == 0) { SceneManager.LoadScene("Overworld"); } else { if (IsHuman) { SceneManager.LoadScene("TerminatorWin"); } else { SceneManager.LoadScene("RebelWin"); } } } } break; case WaitMode.WaitForFinishTool: if (!PlayerAttack.ToolAnimation.Active) { PlayerAttack.Launch(Player, Enemy); TheWaitMode = WaitMode.WaitForFinishPlayerAttack; } break; case WaitMode.WaitForFinishPlayerAttack: if (!PlayerAttack.AttackAnimation.Active) { PlayerAttack.ToolAnimation.Reverse(); PlayerAttack.ToolAnimation.StartAnimations(); TheWaitMode = WaitMode.WaitForFinishWithdrawingTool; } break; case WaitMode.WaitForFinishWithdrawingTool: if (!PlayerAttack.ToolAnimation.Active) { EndPlayerTurn(); } break; case WaitMode.WaitForEnemyAttack: if ((!IsHuman && !EnemyAttack.AttackAnimation.Active) || (IsHuman && !EnemyAttack.HumanAnimation.Active)) { EndEnemyTurn(); } break; case WaitMode.WaitForFinishScan: if (!Player.ScanAnimation.Active) { foreach (AttackButton item in InteractableUI.Instance.AttackUI.GetComponentsInChildren <AttackButton>()) { Destroy(item.gameObject); } DisplayAttacks.Instance.Display(); EndPlayerTurn(); } break; default: break; } }
public virtual Task <byte[]> WaitAsync(int count, WaitMode waitMode, AsyncOperationInfo operationInfo) { return(_base.WaitAsync(count, waitMode, operationInfo)); }
public JObject GetJson() { var o = new JObject { ["name"] = Name, ["description"] = Description }; if (WaitMode != null) { o["waitMode"] = WaitMode.GetJson(); } else { o["waitMode"] = null; } if (Exclude != null) { var ar = new JArray(); for (int i = 0; i < Exclude.Count; ++i) { var exItem = Exclude[i]; ar.Add(exItem.GetJson()); } o["exclude"] = ar; } else { o["exclude"] = null; } if (Occupation != null) { o["occupation"] = Occupation.GetJson(); } else { o["occupation"] = null; } o["commuting"] = Commuting; var plusNames = new JArray(); foreach (var blk in _sidePlus) { if (blk == null) { continue; } if (!blk.IsValid()) { continue; } plusNames.Add(blk.Name); } o["sidePlus"] = plusNames; var minusNames = new JArray(); foreach (var blk in _sideMinus) { if (blk == null) { continue; } if (!blk.IsValid()) { continue; } minusNames.Add(blk.Name); } o["sideMinus"] = minusNames; o["plusEvents"] = PlusEvents.ToJson(); o["minusEvents"] = MinusEvents.ToJson(); return(o); }
public IWorkResult <TResult> HandleTick(Func <TWorkArgs> args, Action <IWorkResult <TResult> > uiAction, IWorkResult[] preWorkUnitList, WaitMode mode, int interval) { this.workResult.IsComplete = true; DispatcherTimer timer = new DispatcherTimer(); timer.Interval = new TimeSpan(0, 0, 0, 0, interval); timer.Tick += (sender, e) => { if (this.workResult.IsComplete) { this.Handle(args, uiAction, preWorkUnitList, mode); } }; timer.Start(); this.workResult.Timer = timer; return(this.workResult); }
public IWorkResult <TResult> HandleTick(Func <TWorkArgs> args, Action <IWorkResult <TResult> > uiAction, IWorkResult[] preWorkUnitList, WaitMode mode, int interval) { throw new NotImplementedException(); }
static int Main(string[] args) { string exeFileName = null; string waitForProcessName = null; int waitForPid = 0; int waitTimeOut = 10000; string replaceFileName = null; bool noArgs = false; WaitMode waitMode = WaitMode.WaitByProcessName; CommandLineReader reader = new CommandLineReader(args); if (reader.Count == 0) { DisplayUsage(); return(1); } while (reader.Read()) { switch (reader.CurrentArgument.ToLowerInvariant()) { case "-exefilename": if (reader.TryReadNextAsString(out exeFileName) == false) { return(2); } break; case "-timeout": if (reader.TryReadNextAsInt32(out waitTimeOut) == false) { waitTimeOut = 10000; } break; case "-waitforpid": if (reader.TryReadNextAsInt32(out waitForPid) == false) { return(2); } waitMode = WaitMode.WaitByProcessId; break; case "-waitforprocessname": if (reader.TryReadNextAsString(out waitForProcessName) == false) { return(2); } waitMode = WaitMode.WaitByProcessName; break; case "-replacefilename": if (reader.TryReadNextAsString(out replaceFileName) == false) { return(2); } break; case "-noargs": noArgs = true; break; case "-waitforexefile": waitMode = WaitMode.WaitForFile; break; } } if (String.IsNullOrEmpty(exeFileName) == false && File.Exists(exeFileName)) { switch (waitMode) { case WaitMode.WaitByProcessId: { Process process = null; foreach (Process p in Process.GetProcesses()) { if (p.Id == waitForPid) { process = p; break; } } if (process != null) { if (process.WaitForExit(waitTimeOut) == false) { return(3); } } } break; case WaitMode.WaitByProcessName: { if (String.IsNullOrEmpty(waitForProcessName)) { waitForProcessName = Path.GetFileNameWithoutExtension(exeFileName); } int time = Environment.TickCount; while (true) { Process[] processes = Process.GetProcessesByName(waitForProcessName); if (processes.Length > 0) { Process process = processes[0]; if (process.WaitForExit(waitTimeOut) == false) { return(3); } } else { break; } if (Environment.TickCount - time > waitTimeOut) { return(3); } } } break; case WaitMode.WaitForFile: { int time = Environment.TickCount; while (true) { try { using (FileStream fs = File.Open(exeFileName, FileMode.Open, FileAccess.Write, FileShare.Delete)) { // Only Open Check } break; } catch (IOException) { // Ignore } if (Environment.TickCount - time > waitTimeOut) { return(3); } Thread.Sleep(1000); } } break; } Thread.Sleep(100); if (String.IsNullOrEmpty(replaceFileName) == false && File.Exists(replaceFileName)) { try { File.Delete(exeFileName); File.Move(replaceFileName, exeFileName); } catch (Exception e) { Debug.WriteLine(e.ToString()); } } ProcessStartInfo info = new ProcessStartInfo(); try { if (noArgs) { info.WorkingDirectory = Path.GetDirectoryName(exeFileName); info.FileName = exeFileName; Process.Start(info); } else { info.Arguments = String.Format("-delete \"{0}\" -pid {1}", Assembly.GetExecutingAssembly().Location, Process.GetCurrentProcess().Id); info.WorkingDirectory = Path.GetDirectoryName(exeFileName); info.FileName = exeFileName; Process.Start(info); } } catch { // No Error Handling On This One } } return(0); }
public IWorkResult <TResult> HandleTick(TWorkArgs args, Action <IWorkResult <TResult> > uiAction, IWorkResult[] preWorkUnitList, WaitMode mode, int interval) { return(this.HandleTick(() => { return args; }, uiAction, preWorkUnitList, mode, interval)); }
public IWorkResult <TResult> ExecuteTick(Func <TWorkArgs> args, Action <IWorkResult <TResult> > uiAction, IWorkResult[] preWorkUnitList, WaitMode mode, int interval) { return(this.work.HandleTick(args, uiAction, preWorkUnitList, mode, interval)); }
public IWorkResult <TResult> Handle(TWorkArgs args, Action <IWorkResult <TResult> > uiAction, IWorkResult[] preWorkUnitList, WaitMode mode) { throw new NotImplementedException(); }
/// <summary> /// 等待动作完成 /// </summary> /// <param name="nodeList">试教模式下调速的主控轴</param> /// <param name="process">要改变定位信息的工序</param> /// <param name="delayTime">延时查询时间</param> private static void waitForDone(ushort[] nodeList, int processingNo, WaitMode waitMode, DebugAction debugAction, int delayTime = Parameter.delayTime) { short rc = 0; //取得当前的加工主轴 currentMasterNode = nodeList[0]; //如果是试教状态,则启动试教试教监视器 if (RunStatus == RunStatus.TryRunning) { //等待试教进程结束 Monitor.StartDebugMonitor(DebugMode.ModeTwo, nodeList[0], currentStation, processingNo, debugAction).Join(); } //如果是试教状态,或者等待模式为Always则等待至动作完成 else if (waitMode == WaitMode.Always) { //等待每个受控制的从站完成动作 foreach (ushort nodeNo in nodeList) { ushort mDone = 1; uint mStatus = 0; //如果运动没有停止,且没有达到目标位置则继续查询 while ((mDone != 0) || ((mStatus & 0x0400) != 0x0400)) { //等待一定时间再进行查询 Thread.Sleep(delayTime); rc = DMC.CS_DMC_01_motion_done(ControlCard.CardNo, nodeNo, 0, ref mDone); rc = DMC.CS_DMC_01_motion_status(ControlCard.CardNo, nodeNo, 0, ref mStatus); } } } }