public void Update() { if (!IsEnabled) { return; } if (Input.GetKeyDown(_key)) { Begin?.Invoke(this, _lastPosition = Input.mousePosition); } else if (Input.GetKey(_key)) { Vector3 currentMousePosition = Input.mousePosition; if (_lastPosition != currentMousePosition) { Moved?.Invoke(this, currentMousePosition); _lastPosition = currentMousePosition; } Pressed?.Invoke(this, currentMousePosition); } else if (Input.GetKeyUp(_key)) { Ended?.Invoke(this, Input.mousePosition); _lastPosition = Vector3.zero; } }
/// <summary> /// 获取是否存在指定远程文件 /// </summary> /// <param name="edi"></param> /// <returns></returns> public bool ExistFile(ExistDataItem edi) { edi.Exist = false; try { string filename = edi.Target.Replace(CurrentRemotePath + Path.AltDirectorySeparatorChar, ""); string[] s = List(filename); if (s.Length == 0) { throw new IOException("not found " + filename); } edi.Success = true; edi.Exist = true; if (edi.Replied) { Ended?.Invoke(edi); } } catch (IOException ex) { edi.Message = ex.Message; edi.Success = false; edi.Exist = false; } return(edi.Exist); }
protected void OnEnded() { if (Ended != null) { Ended.Invoke(this); } }
public DataboundDatagridItemCreatorForm(ISomeService someService) { _view = new DataboundDatagridItemCreatorFormView(); var someText = LocalValueFieldBuilder.Build(_view.SomeText, Validator.IsNotNullRef); var someNumber = LocalValueFieldBuilder.BuildNullableInt(_view.SomeNumber, Validator.IsNotNull, Validator.MustBePositive <int>()); var someBool = LocalValueFieldBuilder.Build(_view.SomeBool); _view.SomeTrait.PermittedValues = EnumExtensions.GetEnumValues <SomeTraitType>().Select(x => (SomeTraitType?)x); var someTrait = LocalValueFieldBuilder.Build(_view.SomeTrait, Validator.IsNotNull); var createProduct = RemoteActionBuilder.Build(_view.CreateAction, () => someService.Create( new SomeDto { SomeNumber = someNumber.Value.GetValueOrDefault(), SomeText = someText.Value, SomeBool = someBool.Value, SomeTrait = someTrait.Value.Value }), x => { CreatedItem = x; Ended?.Invoke(this, Outcome.Created); }); var isFormValid = new AggregatedErrorsValue <bool>(false, self => !self.Errors.Any(), x => { x.Observes(someText); x.Observes(someNumber); x.Observes(someBool); x.Observes(someTrait); }); createProduct.BindEnableAndInitialize(isFormValid); }
public SomeChoicesForm() { _view = new SomeChoicesFormView(); LocalActionBuilder.Build(_view.First, () => Ended?.Invoke(this, Outcome.FirstChoice)); LocalActionBuilder.Build(_view.Second, () => Ended?.Invoke(this, Outcome.SecondChoice)); }
public async Task RunAsync(CancellationToken ct) { this._CurrentCount = Seconds; Started?.Invoke(this, Seconds); timer.Start(); int Counter = Seconds; await Task.Run(async() => { while (!ct.IsCancellationRequested && timer.Enabled && Counter > 0) { try { await Task.Delay(1000, ct); } catch (Exception ex) { timer.Stop(); } Counter--; Tick?.Invoke(this, Counter); } }); Ended?.Invoke(this, new EventArgs()); }
private async Task Combatant_Death(IEntity deadCombatant) { deadCombatant.Died -= Combatant_Death; Dead.Add(deadCombatant); Debug.WriteLine("Combatant Died " + deadCombatant.Name); // figure out how many are alive per faction foreach (var faction in Factions.Keys.ToList()) { // if a faction has no members alive then we are ending var aliveCount = Factions[faction].Count(e => !Dead.Contains(e)); if (aliveCount == 0) { _ended = true; foreach (var combatant in Combatants.Keys.ToList()) { combatant.Died -= Combatant_Death; } if (Ended != null) { await Ended.Invoke(this, EncounterEndings.Death); } //break; return; } } }
public VerticalMenuForm( string title, IEnumerable <T> menuItems, Func <T, string> menuItemLabel, Func <string, IActionView <HTMLElement> > actionBuilder, bool isCancellable = true) { _title = title; _isCancellable = isCancellable; _view = new VerticalMenuFormView( (act, lbl) => { var res = actionBuilder(lbl); res.Triggered += () => act.Invoke(); return(res); }); _view.MenuItems = menuItems.Select(x => { var xCpy = x; return(Tuple.Create <Action, string>(() => { Chosen = xCpy; Ended?.Invoke(this, CompletedOrCanceled.Completed); }, menuItemLabel(x))); }); }
/// <summary> /// Triggers the optimization job end event /// </summary> protected virtual void TriggerOnEndEvent() { if (_disposed) { return; } SetOptimizationStatus(OptimizationStatus.Completed); var result = Strategy.Solution; if (result != null) { var constraint = NodePacket.Constraints != null ? $"Constraints: ({string.Join(",", NodePacket.Constraints)})" : string.Empty; Log.Trace($"LeanOptimizer.TriggerOnEndEvent({GetLogDetails()}): Optimization has ended. " + $"Result for {OptimizationTarget}: was reached using ParameterSet: ({result.ParameterSet}) backtestId '{result.BacktestId}'. " + $"{constraint}"); } else { Log.Trace($"LeanOptimizer.TriggerOnEndEvent({GetLogDetails()}): Optimization has ended. Result was not reached"); } // we clean up before we send an update so that the runtime stats are updated CleanUpRunningInstance(); ProcessUpdate(forceSend: true); Ended?.Invoke(this, result); }
public PhotoTakerForm(PhotoTakerFormView view) { _view = view; LocalActionBuilder.Build(_view.TakePhoto, () => _view.InputFile.Click()); LocalActionBuilder.Build(_view.AcceptPhoto, () => { _view.ResetPreviewStyle(true); Ended?.Invoke(this, CompletedOrCanceled.Completed); }); LocalActionBuilder.Build(_view.RetryPhoto, () => { _view.ClearImage(); _view.InputFile.Click(); }); _view.InputFile.OnChange += _ => { var files = _view.InputFile.Files; if (files == null || files.Length <= 0) { Logger.Debug(GetType(), "got no files"); return; } Logger.Debug(GetType(), "got files {0}", files.Length); var fr = new FileReader(); fr.OnLoad += ev => { _view.SetImageFromDataUrl((string)fr.Result); }; fr.ReadAsDataURL(files[0]); }; }
/// <summary> /// Invoked when the post process script exits. /// </summary> private void OnPostProcessDlProcessExited(object sender, EventArgs e) { // Invoke the ended callback when the process exits. var exitCode = ((postProcess?.ExitCode ?? 1) == 0) ? 0 : (int)ExitCodes.Error; Ended?.Invoke(this, postProcess?.ExitCode ?? 1); }
public UploaderDemoForm(IHttpRequester httpRequester) { _view = new UploaderDemoFormView(); _view.Attachments.SetImplementation(new ISomeService_OrderAttachment(httpRequester, () => 124, () => true)); _attachments = LocalValueFieldBuilder.Build(new List <RemoteFileDescr>(), _view.Attachments, (newValue, errors) => { errors.IfTrueAdd(newValue.Count > 10, "Maximum 10 files allowed"); }); //TODO this is experimental feature. It should be added by the above statement (if BeforeChange is supported in IView) _view.Attachments.BeforeChange += (newValue, isUser, preventProp) => { if (newValue.Count > 10) { preventProp(new HashSet <string> { "Maximum 10 files allowed" }); } }; var mayConfirm = new AggregatedErrorsValue <bool>( false, self => !self.Errors.Any(), x => x.Observes(_attachments)); var confirm = LocalActionBuilder.Build(_view.Confirm, () => Ended?.Invoke(this, Unit.Instance)); confirm.BindEnableAndInitialize(mayConfirm); }
public async void Execute(object parameter) { IsExecuting = true; Started?.Invoke(this, EventArgs.Empty); await Task.Run(() => { _execute(_cancelCommand.Token); }, _cancelCommand.Token) .ContinueWith(t => { var error = t.Exception?.InnerException; if (_postAction != null) { _postAction.Invoke(new RunWorkerCompletedEventArgs(null, error, t.IsCanceled)); error = null; } IsExecuting = false; Ended?.Invoke(this, EventArgs.Empty); if (_postAction == null && error != null) { throw error; } }, TaskScheduler.FromCurrentSynchronizationContext()); }
public void Start() { if (_real.IsRunning) { return; } _real.Start(); _updateTimer.Start(); Task.Run(() => { while (_real.IsRunning) { if (Time - _real.Elapsed <= new TimeSpan(0, 0, 0, 0)) { break; } Thread.Sleep(150); } if (Time - _real.Elapsed <= new TimeSpan(0, 0, 0, 0)) { Stop(); Reset(); Ended?.Invoke(this, null); } }); }
public void Restart() { ElapsedTime = 0; if (!Repetitive) { Ended.Invoke(this, new AnimationEndedEventArgs()); } }
/// <summary> /// 结束构造(触发Ended事件。) /// </summary> protected virtual void OnEnd() { if (!_ended) { _ended = true; Ended?.Invoke(this, System.EventArgs.Empty); } }
private void MediaPlayer_MediaEnded(object sender, RoutedEventArgs e) { Ended?.Invoke(this, EventArgs.Empty); if (_active && IsLooped) { ResetAndPlay(); } }
public IoTSoundPlayer(Context context) { this.context = context; player = new MediaPlayer(); player.Completion += (sender, e) => { Ended?.Invoke(this, EventArgs.Empty); }; }
public void End() { OnEnd(); if (Ended != null) { Ended.Invoke(this); } }
private IEnumerator CooldownCoroutine() { Started?.Invoke(); IsRunning = true; yield return(new WaitForSeconds(duration)); Ended?.Invoke(); IsRunning = false; }
public Task NotifyEnded() { if (Ended != null) { return(Ended.Invoke()); } return(Task.CompletedTask); }
/// <inheritdoc /> public void Dispose() { Ended?.Invoke(this, null); Database?.Dispose(); Replicator?.Stop(); // Uncomment after DB019 (https://github.com/couchbase/couchbase-lite-net/issues/908) //_replicator?.Dispose(); HttpClient.Dispose(); }
private void OnMediaEnded(object sender, EventArgs eventArgs) { if (Ended == null) { return; } Task.Factory.StartNew(() => Ended?.Invoke(this, EventArgs.Empty)); }
public DataboundDatagridForm() { _view = new DataboundDatagridFormView(); Func <string, BaseUnboundColumnBuilder <SomeDto> > build = x => UnboundDataGridColumnBuilder.For <SomeDto>(x); Items = DataGridModel <SomeDto> .CreateAndBindReloadable( _view.Items, () => Ended?.Invoke(this, Outcome.ReloadData), (el, theaderHeight, _) => //most of the time you would use Toolkit.DefaultTableBodyHeightProvider() el.GetAvailableHeightForFormElement(0, 2) - theaderHeight - _view.Help.Widget.OffsetHeight, new List <IDataGridColumn <SomeDto> > { build("#") .WithValueLocalized(x => Items.Items.IndexOf(x) + 1) .NonTransformable() .Build(), build("SomeNumber") .WithValueLocalized(x => x.SomeNumber) .TransformableDefault() .Observes(x => nameof(x.SomeNumber)) .Build(), build("SomeText") .WithValue(x => x.SomeText) .TransformableDefault() .Observes(x => nameof(x.SomeText)) .Build(), build("SomeBool") .WithValueLocalized(x => x.SomeBool) .TransformableDefault() .Observes(x => nameof(x.SomeBool)) .Build(), build("SomeTrait") .WithValueAsText(x => x.SomeTrait, x => x.ToString()) .TransformableAsText() .Observes(x => nameof(x.SomeTrait)) .Build(), }).model; Items.Activated.Changed += (sender, oldValue, newValue, errors, isUserChange) => { if (newValue == null) { return; } ChoosenItem = Items.Activated.Value; Ended?.Invoke(this, Outcome.EditItemDemanded); }; LocalActionBuilder.Build(_view.Creator, () => Ended?.Invoke(this, Outcome.CreateItemDemanded)); //button that is activated only if exactly one record is selected in the datagarid var activateEditor = LocalActionBuilder.Build(_view.Editor, () => { ChoosenItem = Items.Selected[0]; Ended?.Invoke(this, Outcome.EditItemDemanded); }); activateEditor.BindSelectionIntoEnabled(Items, SelectionNeeded.ExactlyOneSelected); }
private void Timer_Elapsed(object sender, ElapsedEventArgs e) { _CurrentCount--; Tick?.Invoke(this, _CurrentCount); if (_CurrentCount <= 0) { timer.Stop(); Ended?.Invoke(this, new EventArgs()); } }
public void End(ActionStatus status) { if (_status != ActionStatus.Running) { return; } _status = status; OnEnd(); Ended?.Invoke(this); }
public ConfirmMessageForm(ConfirmMessageFormView view, string messageOrNull = null, string titleOrNull = null) { Title = titleOrNull ?? I18n.Translate("Confirmation"); View = view; _message = new LocalValue <string>(messageOrNull ?? I18n.Translate("Without message")); view.Message.BindReadOnlyAndInitialize(_message); LocalActionBuilder.Build(view.Confirm, () => Ended?.Invoke(this, CompletedOrCanceled.Completed)); LocalActionBuilder.Build(view.Cancel, () => Ended?.Invoke(this, CompletedOrCanceled.Canceled)); }
public InformationalMessageForm(InformationalMessageFormView view, string messageOrNull = null, string titleOrNull = null, bool cancellable = true) { _cancellable = cancellable; Title = titleOrNull ?? I18n.Translate("Confirmation"); View = view; _message = new LocalValue <string>(messageOrNull ?? I18n.Translate("Without message")); view.Message.BindReadOnlyAndInitialize(_message); LocalActionBuilder.Build(view.Confirm, () => Ended?.Invoke(this, Unit.Instance)); }
private async Task EndGame(PlayerColor winner) { moveTimeOut.Cancel(); Game.PlayState = Game.State.Ended; Logger.LogInformation($"The winner is ${winner}"); var newScore = SaveWinner(winner); await SendWinner(winner, newScore); Ended?.Invoke(this, EventArgs.Empty); }
void ExecuteProcess(string filename, string arguments) { using (var proc = new Process()) { proc.EnableRaisingEvents = false; proc.StartInfo.FileName = filename; proc.StartInfo.Arguments = arguments; proc.Start(); proc.WaitForExit(); }; Ended?.Invoke(this, EventArgs.Empty); }