/// <summary> /// Start the progress using the given IAsync operation /// </summary> /// <param name="asyncOperation"></param> public void Start(LoadModelAsync asyncOperation) { _waitable = asyncOperation; if (_waitable == null) { return; } _waitable.ProgressUpdated += (float value) => { UpdateProgress(value); }; _waitable.Completed += WaitableCompleted; }
private async void ScaleLoad(LoadModelFromSASParams loadModelParams, ModelProgressStatus progressTask) { var machine = AppServices.RemoteRendering?.PrimaryMachine; // Remember the current connection, so we can cancel the load on a new connection uint connectionId = _connectionId; LoadModelAsync loadOperation = null; _progress.Add(progressTask); while (true) { if (machine == null) { var msg = $"Unable to load model: there is no remote rendering session. (url = {loadModelParams.ModelUrl})"; Debug.LogFormat(LogType.Error, LogOption.NoStacktrace, null, msg); AppServices.AppNotificationService.RaiseNotification(msg, AppNotificationType.Error); break; } lock (_loadingTasks) { if (_loadingTasks.Count == 0 || _loadingTasks.Count < _remoteObjectFactoryServiceProfile.ConcurrentModelLoads) { loadOperation = machine.Actions.LoadModelAsyncAsOperation(loadModelParams); break; } } await Task.WhenAll(_loadingTasks); lock (_loadingTasks) { _loadingTasks.Clear(); } } if (loadOperation != null) { if (_connectionId != connectionId) { progressTask.Start(null); } else { progressTask.Start(loadOperation); _loadingTasks.Add(IgnoreFailure(progressTask.Result)); } } }
/// <summary> /// Handle the waitable completion event. /// </summary> private void WaitableCompleted(LoadModelAsync async) { if (_waitable == null || _taskSource.Task.IsCompleted) { return; } _waitable.Completed -= WaitableCompleted; if (_waitable.IsRanToCompletion) { _taskSource.TrySetResult(_waitable.Result); } else { _taskSource.TrySetException(new Exception($"Load model failed with status '{_waitable.Status}'")); } // Force progress to complete on success or failure UpdateProgress(1.0f); }
public GenericRecogizer(LoadModelAsync modelLoader) { _modelLoader = modelLoader; }
public SpectacledPorpoiseRecognizer(LoadModelAsync modelLoader) { _modelLoader = modelLoader; }