protected override void Execute(NativeActivityContext context) { UiElement element = null; try { var selStr = Selector.Get(context); element = Common.GetValueOrDefault(context, this.Element, null); if (element == null && selStr != null) { element = UiElement.FromSelector(selStr); } if (Body != null) { context.ScheduleAction(Body, element, OnCompleted, OnFaulted); } } catch (Exception e) { SharedObject.Instance.Output(SharedObject.enOutputType.Error, "元素范围流程失败", e.Message); if (ContinueOnError.Get(context)) { context.ScheduleAction(Body, element, OnCompleted, OnFaulted); } else { throw e; } } }
protected override void Execute(NativeActivityContext context) { try { string _arguments = Arguments.Get(context); string _fileName = ProcessPath.Get(context); string _workingDirectory = WorkingDirectory.Get(context); Int32 _timeout = Timeout.Get(context); Process p = new System.Diagnostics.Process(); if (_arguments != null) { p.StartInfo.Arguments = _arguments; } if (_workingDirectory != null) { p.StartInfo.WorkingDirectory = _workingDirectory; } p.StartInfo.UseShellExecute = false; p.StartInfo.FileName = _fileName; p.Start(); Thread.Sleep(_timeout); context.ScheduleAction(Body, "", OnCompleted, OnFaulted); } catch (Exception e) { if (ContinueOnError.Get(context)) { } else { throw new NotImplementedException(e.Message); } } }
void ScheduleMainActivities(NativeActivityContext context) { if (MainBody != null) { context.ScheduleAction <AuthenticationAgent>(MainBody, authAgent, OnMainActivityComplete); } }
protected override void Execute(NativeActivityContext context) { string serviceAccountEmail = ServiceAccountEmail.Get(context); string keyPath = KeyPath.Get(context); string password = Password.Get(context); var certificate = new X509Certificate2(@keyPath, password, X509KeyStorageFlags.Exportable); ServiceAccountCredential credential = new ServiceAccountCredential( new ServiceAccountCredential.Initializer(serviceAccountEmail) { Scopes = new[] { SheetsService.Scope.Spreadsheets } }.FromCertificate(certificate)); // Create the service. var sheetService = new SheetsService(new BaseClientService.Initializer() { HttpClientInitializer = credential, ApplicationName = "UiPath Robot", }); var googleSheetProperty = new GoogleSheetProperty() { SheetsService = sheetService, SpreadsheetId = SpreadsheetId.Get(context) }; if (Body != null) { context.ScheduleAction <GoogleSheetProperty>(Body, googleSheetProperty, OnCompleted, OnFaulted); } }
protected override void Execute(NativeActivityContext context) { try { Browser getBrowser = currBrowser.Get(context); if (getBrowser != null) { if (getBrowser.getICFBrowser() != null) { if (UiBrowser != null) { UiBrowser.Set(context, getBrowser); } } context.ScheduleAction(Body, getBrowser, OnCompleted, OnFaulted); } } catch (Exception e) { SharedObject.Instance.Output(SharedObject.enOutputType.Error, "附加浏览器出现异常", e.Message); if (!ContinueOnError.Get(context)) { throw; } } }
protected override void StartLoop(NativeActivityContext context) { if (Image == null) { new ArgumentException("Image is null"); } //var timeout = TimeSpan.FromSeconds(3); var timeout = Timeout.Get(context); if (Timeout == null || Timeout.Expression == null) { timeout = TimeSpan.FromSeconds(3); } var maxresults = MaxResults.Get(context); var processname = Processname.Get(context); var comparegray = CompareGray.Get(context); var threshold = Threshold.Get(context); var minresults = MinResults.Get(context); var from = From.Get(context); var limit = Limit.Get(context); if (maxresults < 1) { maxresults = 1; } if (threshold < 0.1) { threshold = 0.1; } if (threshold > 1) { threshold = 1; } ImageElement[] elements = { }; var sw = new Stopwatch(); sw.Start(); do { elements = getBatch(minresults, maxresults, threshold, processname, timeout, comparegray, limit).ToArray(); } while (elements.Count() == 0 && sw.Elapsed < timeout); // Log.Debug(string.Format("OpenRPA.Image::GetElement::found {1} elements in {0:mm\\:ss\\.fff}", sw.Elapsed, elements.Count())); context.SetValue(Elements, elements); IEnumerator <ImageElement> _enum = elements.ToList().GetEnumerator(); context.SetValue(_elements, _enum); bool more = _enum.MoveNext(); if (more) { IncIndex(context); SetTotal(context, elements.Length); context.ScheduleAction(Body, _enum.Current, OnBodyComplete); } else if (elements.Count() < minresults) { throw new Interfaces.ElementNotFoundException("Failed locating item"); } }
protected override void Execute(NativeActivityContext context) { if ((this.Action != null) && (this.Action.Handler != null)) { context.ScheduleAction(this.Action, null, null); } }
/// <summary> /// Respond to the completion callback of the status polling activity. /// </summary> /// <param name="context">The activity context.</param> /// <param name="instance">The current instance of the activity.</param> /// <param name="result">The result of the status inquiry.</param> private void OnGetStatusCompleted(NativeActivityContext context, ActivityInstance instance, string result) { // Check to see if the operation faulted if (this.AzureActivityExceptionCaught.Get(context) == true) { context.ScheduleActivity(this.Failure); return; } // Determine what to do based on the status of the Azure operation. switch (result) { case OperationState.Succeeded: context.ScheduleActivity(this.Success); break; case OperationState.Failed: context.ScheduleActivity(this.Failure); break; case OperationState.InProgress: // Test to see if we are within the timeout if (context.GetValue(this.PollingEndTime).CompareTo(DateTime.UtcNow) <= 0) { context.ScheduleActivity(this.Failure); } // Otherwise delay for the requested interval context.ScheduleAction <int>( this.DelayBody, this.PollingInterval, new CompletionCallback(OnDelayCompleted)); break; } }
protected override void Execute(NativeActivityContext context) { var relativelement = Element.Get(context); Rectangle match = new Rectangle(0, 0, System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width, System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height); if (relativelement != null) { match = relativelement.Rectangle; } match.X += X.Get(context); match.Y += Y.Get(context); var h = Height.Get(context); var w = Width.Get(context); if (h > 10) { match.Height = h; } if (w > 10) { match.Width = w; } var b = Interfaces.Image.Util.Screenshot(match); var v = new ImageElement(match, b); context.SetValue(Result, v); context.ScheduleAction(Body, v, OnBodyComplete); }
protected override void OnExecute(NativeActivityContext context, object objectToValidate, ValidationContext objectToValidateContext) { if (this.Body != null) { context.ScheduleAction <T, ValidationContext>(this.Body, (T)objectToValidate, objectToValidateContext, null, null); } }
protected override void Execute(NativeActivityContext context) { var kernel = Kernel.Get(context); if (kernel != null) { _kernel = new Application(kernel); } else { var kernelPath = KernelPath.Get(context) ?? string.Empty; var kernelArgs = KernelArgs.Get(context) ?? new string[0]; var startupSleep = StartupSleep.Get(context); var enableObjectReferences = EnableObjectReferences.Get(context); var closeOnFinish = CloseKernelOnFinish.Get(context); _kernel = new Application(kernelPath, kernelArgs, enableObjectReferences, closeOnFinish); Task.Run(() => _kernel.Initialization); if (Body == null) { return; } while (!_kernel.Ready) { Console.WriteLine(Resources.WolframLanguageScope_Execute_Waiting_for_client_to_be_ready___); Thread.Sleep(startupSleep); } } Kernel.Set(context, _kernel.KernelLink); context.Properties.Add(@"Application", _kernel); context.ScheduleAction(Body, _kernel, OnCompleted, OnFaulted); }
protected override void Execute(NativeActivityContext context) { if (!string.IsNullOrEmpty(ProxyHost.Get(context))) // Proxy defined { if (!string.IsNullOrEmpty(ProxyUsername.Get(context))) // Proxy authentication { connectionInfo = new PasswordConnectionInfo(Host.Get(context), Port.Get(context), Username.Get(context), Encoding.UTF8.GetBytes(Password.Get(context)), ProxyTypes.Http, ProxyHost.Get(context), ProxyPort.Get(context), ProxyUsername.Get(context), ProxyPassword.Get(context)); } else // No proxy authentication { connectionInfo = new PasswordConnectionInfo(Host.Get(context), Port.Get(context), Username.Get(context), Password.Get(context), ProxyTypes.Http, ProxyHost.Get(context), ProxyPort.Get(context)); } } else // No Proxy defined { connectionInfo = new PasswordConnectionInfo(Host.Get(context), Port.Get(context), Username.Get(context), Password.Get(context)); } sshClient = new SshClient(connectionInfo); sshClient.Connect(); if (Body != null) { //scheduling the execution of the child activities // and passing the value of the delegate argument context.ScheduleAction(Body, sshClient, OnCompleted, OnFaulted); } }
protected override void Execute(NativeActivityContext context) { try { this._context = ContextName.Get(context); Dictionary <string, string> aArguments = new Dictionary <string, string>(); aArguments["Retries"] = "5"; aContext = new ContextServer(contextType.NamedPipe, this._context, aArguments, this.Debug); aContext.CreateServer(); if (Body != null) { //scheduling the execution of the child activities // and passing the value of the delegate argument context.ScheduleAction(Body, aContext, OnCompleted, OnFaulted); } } catch (Exception e) { CleanupContext(); throw; } }
protected override void Execute(NativeActivityContext context) { if ((this.Action != null) && (this.Action.Handler != null)) { context.ScheduleAction <T1, T2, T3, T4, T5, T6, T7, T8, T9>(this.Action, this.Argument1.Get(context), this.Argument2.Get(context), this.Argument3.Get(context), this.Argument4.Get(context), this.Argument5.Get(context), this.Argument6.Get(context), this.Argument7.Get(context), this.Argument8.Get(context), this.Argument9.Get(context), null, null); } }
/// <summary> /// Invoked when the conditional is completed. /// </summary> /// <param name="context"></param> /// <param name="completedInstance"></param> void OnConditionCompleted(NativeActivityContext context, ActivityInstance completedInstance, bool value) { if (value) { context.ScheduleAction(Action, current.Get(context), OnActionCompleted); } }
protected override void Execute(NativeActivityContext context) { try { int hwnd = GetForegroundWindow(); StringBuilder windowText = new StringBuilder(256); GetWindowText(hwnd, windowText, 256); StringBuilder className = new StringBuilder(256); GetClassName(hwnd, className, 256); Window currWindow = new Window(); currWindow.setWindowHwnd(hwnd); currWindow.setWindowText("" + windowText); currWindow.setWindowClass("" + className); context.SetValue(thisWindow, currWindow); if (Body != null) { context.ScheduleAction(Body, currWindow, OnCompleted, OnFaulted); } } catch (Exception e) { SharedObject.Instance.Output(SharedObject.enOutputType.Error, "关闭窗口错误产生", e.Message); if (ContinueOnError.Get(context)) { } else { throw; } } }
protected override void Execute(NativeActivityContext context) { var relativelement = Element.Get(context); var match = relativelement.Rectangle; match.X += OffsetX.Get(context); match.Y += OffsetY.Get(context); match.Width = Width.Get(context); match.Height = Height.Get(context); var processname = relativelement.Processname; if (!string.IsNullOrEmpty(processname)) { var _element = AutomationHelper.GetFromPoint(match.X, match.Y); if (_element.ProcessId < 1) { throw new ElementNotFoundException("Failed locating Image, expected " + processname + " but found nothing"); } var p = System.Diagnostics.Process.GetProcessById(_element.ProcessId); if (p.ProcessName != processname) { throw new ElementNotFoundException("Failed locating Image, expected " + processname + " but found " + p.ProcessName); } } var b = Interfaces.Image.Util.Screenshot(match); //Interfaces.Image.Util.SaveImageStamped(b, "c:\\temp", "GetImage-result"); var v = new ImageElement(match, b); context.SetValue(Result, v); context.ScheduleAction(Body, v, OnBodyComplete); }
protected override void PostExecute(NativeActivityContext context, UnhandledExceptionAction unhandledExceptionAction) { Exception propagatedException = PropagatedException.Get(context); ReceiveRequestSendResponseScopeExecutionProperty executionProperty = context.GetReceiveRequestSendResponseScopeExecutionProperty(); // Due to this activity will handle the fault, the Finally activity in the TryCatch will be executed also, // we have to prevent canceling the operation and the stored previous response in the extension. executionProperty.Faulted = true; switch (unhandledExceptionAction) { default: case UnhandledExceptionAction.Abort: // This will implicitly also call OnUnhandledException. context.Abort(propagatedException); break; case UnhandledExceptionAction.Cancel: // Don't wait for completion, that is critical only for the persistence to happen before the taskCompletionSource of the request is completed. context.ScheduleActivity(cancelWorkflow); break; case UnhandledExceptionAction.Terminate: // Don't wait for completion, that is critical only for the persistence to happen before the taskCompletionSource of the request is completed. context.ScheduleAction(terminateWorkflow, propagatedException); break; } }
protected override void Execute(NativeActivityContext context) { context.CreateBookmark("DownloadDetectorPlugin", new BookmarkCallback(OnBookmarkCallback)); var timeout = Timeout.Get(context); if (timeout.TotalMilliseconds > 0) { wfApp = Plugin.client.WorkflowInstances.Where(x => x.InstanceId == context.WorkflowInstanceId.ToString()).FirstOrDefault(); if (wfApp == null) { throw new Exception("Fail locating current workflow instance, to create timeout activity"); } timer = new System.Timers.Timer(timeout.TotalMilliseconds); timer.Elapsed += (sender, e) => { try { wfApp.ResumeBookmark("DownloadDetectorPlugin", null); } catch (Exception ex) { Log.Error(ex.ToString()); } }; timer.Start(); } context.ScheduleAction(Body, null, null); }
private void ConditionCompletion(NativeActivityContext context, ActivityInstance completedInstance, bool result) { if (completedInstance.State == ActivityInstanceState.Closed && result) { context.ScheduleAction(Body, BodyCompletion, null); } }
protected override void Execute(NativeActivityContext context) { IEnumerable values = this.Values.Get(context); if (values == null) { throw new InvalidOperationException("ParallelForEach requires a non-null Values argument."); } IEnumerator valueEnumerator = values.GetEnumerator(); CompletionCallback onBodyComplete = new CompletionCallback(OnBodyComplete); while (valueEnumerator.MoveNext()) { if (this.Body != null) { context.ScheduleAction(this.Body, valueEnumerator.Current, onBodyComplete); } } IDisposable disposable = valueEnumerator as IDisposable; if (disposable != null) { disposable.Dispose(); } }
protected override void Execute(NativeActivityContext context) { var selector = Selector.Get(context); var sel = new IESelector(selector); var timeout = TimeSpan.FromSeconds(3); var from = From.Get(context); IEElement[] elements = { }; var sw = new Stopwatch(); sw.Start(); do { elements = IESelector.GetElementsWithuiSelector(sel, from); } while (elements.Count() == 0 && sw.Elapsed < timeout); context.SetValue(Elements, elements); IEnumerator <IEElement> _enum = elements.ToList().GetEnumerator(); context.SetValue(_elements, _enum); bool more = _enum.MoveNext(); if (more) { context.ScheduleAction(Body, _enum.Current, OnBodyComplete); } else { throw new Interfaces.ElementNotFoundException("Failed locating item"); } }
protected override void StartLoop(NativeActivityContext context) { // var match = Element.Get(context); var wordlimit = WordLimit.Get(context); var lang = Config.local.ocrlanguage; var casesensitive = CaseSensitive.Get(context); string basepath = Interfaces.Extensions.DataDirectory; string path = System.IO.Path.Combine(basepath, "tessdata"); ocr.TesseractDownloadLangFile(path, Config.local.ocrlanguage); ocr.TesseractDownloadLangFile(path, "osd"); var ele = Element.Get(context); // ele.element.Save(@"c:\temp\dump.png", System.Drawing.Imaging.ImageFormat.Png); // var result = ocr.GetTextcomponents(path, Config.local.ocrlanguage, ele.element); // var result = ocr.GetTextcomponents(path, Config.local.ocrlanguage, @"c:\temp\dump.png"); ImageElement[] result; var _ocr = new Emgu.CV.OCR.Tesseract(path, lang.ToString(), Emgu.CV.OCR.OcrEngineMode.TesseractLstmCombined); _ocr.Init(path, lang.ToString(), Emgu.CV.OCR.OcrEngineMode.TesseractLstmCombined); _ocr.PageSegMode = Emgu.CV.OCR.PageSegMode.SparseText; // OpenRPA.Interfaces.Image.Util.SaveImageStamped(ele.element, "OCR"); Bitmap sourceimg = null; if (ele is ImageElement) { sourceimg = ((ImageElement)ele).element; } else { sourceimg = Interfaces.Image.Util.Screenshot(ele.Rectangle.X, ele.Rectangle.Y, ele.Rectangle.Width, ele.Rectangle.Height); } using (var img = new Emgu.CV.Image <Emgu.CV.Structure.Bgr, byte>(sourceimg)) { result = ocr.OcrImage2(_ocr, img.Mat, wordlimit, casesensitive); } Log.Debug("adding element cords to results: " + ele.Rectangle.ToString()); foreach (var R in result) { var rect = new System.Drawing.Rectangle(R.Rectangle.X + ele.Rectangle.X, R.Rectangle.Y + ele.Rectangle.Y, R.Rectangle.Width, R.Rectangle.Height); R.Rectangle = rect; Log.Debug("Found: '" + R.Text + "' at " + R.Rectangle.ToString()); } context.SetValue(Result, result); IEnumerator <ImageElement> _enum = result.ToList().GetEnumerator(); context.SetValue(_elements, _enum); bool more = _enum.MoveNext(); if (more) { IncIndex(context); SetTotal(context, result.Length); context.ScheduleAction(Body, _enum.Current, OnBodyComplete); } }
private void InternalExecute(NativeActivityContext context, ActivityInstance completedInstance, IEnumerator <T> valueEnumerator) { Fx.Assert(this.Body != null && this.Body.Handler != null, "Body and Body.Handler should not be null"); if (!valueEnumerator.MoveNext()) { if (completedInstance != null) { if (completedInstance.State == ActivityInstanceState.Canceled || (context.IsCancellationRequested && completedInstance.State == ActivityInstanceState.Faulted)) { context.MarkCanceled(); } } valueEnumerator.Dispose(); return; } // After making sure there is another value, let's check for cancelation if (context.IsCancellationRequested) { context.MarkCanceled(); valueEnumerator.Dispose(); return; } context.ScheduleAction(this.Body, valueEnumerator.Current, this.OnChildComplete); }
protected override void Execute(NativeActivityContext context) { if ((this.Action != null) && (this.Action.Handler != null)) { context.ScheduleAction <T1, T2>(this.Action, this.Argument1.Get(context), this.Argument2.Get(context), null, null); } }
protected override void StartLoop(NativeActivityContext context) { System.Data.DataView dv; System.Data.DataTable dt = DataTable.Get(context); if (dt != null) { dv = dt.DefaultView; } else { dv = DataView.Get(context); } if (dv == null) { return; } var elements = (from row in dv.Cast <System.Data.DataRowView>() select row).ToList(); IEnumerator <System.Data.DataRowView> _enum = elements.GetEnumerator(); context.SetValue(_elements, _enum); bool more = _enum.MoveNext(); if (more) { IncIndex(context); SetTotal(context, elements.Count); context.ScheduleAction(Body, _enum.Current, OnBodyComplete); } }
protected override void Execute(NativeActivityContext context) { if ((this.Action != null) && (this.Action.Handler != null)) { context.ScheduleAction(this.Action, null, null); } }
protected override void Execute(NativeActivityContext context) { var SelectorString = Selector.Get(context); SelectorString = OpenRPA.Interfaces.Selector.Selector.ReplaceVariables(SelectorString, context.DataContext); var sel = new JavaSelector(SelectorString); var timeout = TimeSpan.FromSeconds(3); var maxresults = MaxResults.Get(context); var from = From.Get(context); if (maxresults < 1) maxresults = 1; JavaElement[] elements = { }; var sw = new Stopwatch(); sw.Start(); do { var selector = new JavaSelector(SelectorString); elements = JavaSelector.GetElementsWithuiSelector(selector, from, maxresults); } while (elements.Count() == 0 && sw.Elapsed < timeout); Log.Debug(string.Format("OpenRPA.Java::GetElement::found {1} elements in {0:mm\\:ss\\.fff}", sw.Elapsed, elements.Count())); context.SetValue(Elements, elements); IEnumerator<JavaElement> _enum = elements.ToList().GetEnumerator(); context.SetValue(_elements, _enum); bool more = _enum.MoveNext(); if (more) { context.ScheduleAction(Body, _enum.Current, OnBodyComplete); } else { throw new Interfaces.ElementNotFoundException("Failed locating item"); } }
private void OnExtensionProgress(NativeActivityContext context, Bookmark bookmark, Object data) { if (bookmarkProgress.Get(context) != bookmark) { return; } if (data is int && !context.IsCancellationRequested) { Track(context, data); if (this.OnProgress != null) { context.ScheduleAction <int>(this.OnProgress, (int)data); } } else { this.noPersistHandle.Get(context).Exit(context); context.RemoveBookmark(bookmark); if (data is Exception) { throw data as Exception; } } }
protected override void Execute(NativeActivityContext context) { if (Body != null) { context.ScheduleAction(Body, context.GetExtension <ITwilioContext>().GetCallContext()); } }
protected override void Execute(NativeActivityContext context) { if (this.SubscriptionHandle != null) { var subscriptionHandle = this.SubscriptionHandle.Get(context); if (!subscriptionHandle.IsInitialized) { throw new ArgumentException("Subscription", String.Format(Properties.Resources.HandleNotInitialized, this.DisplayName)); } var emptyList = new List <FileChangeEvent>(); this.Result.Set(context, emptyList); var extension = context.GetExtension <Hosting.FolderWatcherExtension>(); // Enter a no persist zone to pin this activity to memory since we are setting up a delegate to receive a callback var handle = this.noPersistHandle.Get(context); handle.Enter(context); Bookmark bookmark = context.CreateBookmark(this.receiveCompleteCallback, BookmarkOptions.MultipleResume); this.receiveCompleteBookmark.Set(context, bookmark); extension.RegisterReceiveNotification(bookmark, subscriptionHandle.Id); if (this.Body != null) { context.ScheduleAction(this.Body, new CompletionCallback(OnBodyCompleted), new FaultCallback(OnBodyFaulted)); } } }
protected override void Execute(NativeActivityContext context) { if (Action == null || Action.Handler == null) { return; } context.ScheduleAction(Action); }
protected override void Execute(NativeActivityContext context) { SendRequestReceiveResponseScopeExecutionProperty executionProperty = context.GetSendRequestReceiveResponseScopeExecutionProperty(); if (executionProperty.UntypedOnOperationTask != null) { // We await the task, but we won't execute the task's Func<Task> or Func<Task<TResponseResult>> return value, that is the ReceiveResponse activity's responsibility. context.ScheduleAction(responseResultWaiter, executionProperty.UntypedOnOperationTask); executionProperty.OnOperationTaskWaiterIsScheduled(); } }
private void ExecuteBody(NativeActivityContext context) { var vars = ComputationContext.GetVariables(context, this); int no; if (!vars.TryGet(IterationNoVarName, out no)) { vars.Set(IterationNoVarName, 1); } context.ScheduleAction(Body, no, OnExecuteBodyCompleted); }
/// <summary> /// Respond to the completion callback of the status polling activity. /// </summary> /// <param name="context">The activity context.</param> /// <param name="instance">The current instance of the activity.</param> /// <param name="result">The result of the status inquiry.</param> private void OnGetStatusCompleted(NativeActivityContext context, ActivityInstance instance, string result) { // Check to see if the operation faulted if (this.AzureActivityExceptionCaught.Get(context)) { context.ScheduleActivity(this.Failure); return; } // Determine what to do based on the status of the Azure operation. switch (result) { case OperationState.Succeeded: context.ScheduleActivity(this.Success); break; case OperationState.Failed: context.ScheduleActivity(this.Failure); break; case OperationState.InProgress: // Test to see if we are within the timeout if (context.GetValue(this.PollingEndTime).CompareTo(DateTime.UtcNow) <= 0) { context.ScheduleActivity(this.Failure); } // Otherwise delay for the requested interval context.ScheduleAction( this.DelayBody, this.PollingInterval, this.OnDelayCompleted); break; } }
private void ConditionTrue(NativeActivityContext context) { context.ScheduleAction(ConditionTrueActivity); }
private void ConditionTrue(NativeActivityContext context) { timesCalled = 0; context.ScheduleAction(ConditionTrueActivity); }
void InternalExecute(NativeActivityContext context, IEnumerator valueEnumerator) { if (!valueEnumerator.MoveNext()) { OnForEachComplete(valueEnumerator); return; } // After making sure there is another value, let's check for cancelation if (context.IsCancellationRequested) { context.MarkCanceled(); OnForEachComplete(valueEnumerator); return; } context.ScheduleAction(this.Body, valueEnumerator.Current, this.OnChildComplete); }
protected override void Execute(NativeActivityContext context) { if (Body != null) context.ScheduleAction(Body, context.GetExtension<ITwilioContext>().GetCallContext()); }
private void OnGetNextVectorsCompleted(NativeActivityContext context, ActivityInstance instance, NeuralVectors[] result) { if (ReinitializationFrequency != null && ReinitializeVectorProvider != null) { var freq = ReinitializationFrequency.Get(context); if (freq > 0) { var vars = ComputationContext.GetVariables(context, this); int iterations = vars.Get<int>(IterationsVarName); if ((++iterations % freq) == 0) { context.ScheduleAction(ReinitializeVectorProvider, OnReinitializeVectorProviderCompleted); } vars.Set(IterationsVarName, iterations); } } GetNextVectorsDone(context, result, TrainingResetSchedule.None); }
private void OnExtensionProgress(NativeActivityContext context, Bookmark bookmark, Object data) { if (bookmarkProgress.Get(context) != bookmark) return; if (data is int && !context.IsCancellationRequested) { Track(context, data); if (this.OnProgress != null) context.ScheduleAction<int>(this.OnProgress, (int)data); } else { this.noPersistHandle.Get(context).Exit(context); context.RemoveBookmark(bookmark); if (data is Exception) throw data as Exception; } }
private void ProcessNextVectors(NativeActivityContext context, NeuralVectors[] result) { bool reinitialize = false; IList<NeuralVectors> finalResult = result; if (IsCached(context)) { var vars = ComputationContext.GetVariables(context, this); var cache = vars.Get<SerializableCache>(CacheVarName).Cache; // Cache results: if (result != null) { foreach (var vectors in result) { string key = vectors.ProviderIndex.ToString(); cache[key] = vectors; } } // Combine cached vectors with result: var vectorsFromCache = cachedVectors.Get(context); cachedVectors.Set(context, null); if (result != null) { if (vectorsFromCache.Count != 0) { finalResult = result.Concat(vectorsFromCache).ToList(); } } else { finalResult = vectorsFromCache.ToList(); } } if (ReinitializationFrequency != null && ReinitializeVectorProvider != null) { var freq = ReinitializationFrequency.Get(context); if (freq > 0) { var vars = ComputationContext.GetVariables(context, this); int iterations = vars.Get<int>(IterationsVarName); if ((++iterations % freq) == 0) { context.ScheduleAction(ReinitializeVectorProvider, OnReinitializeVectorProviderCompleted); reinitialize = true; } vars.Set(IterationsVarName, iterations); } } GetNextVectorsDone(context, finalResult, reinitialize ? TrainingResetSchedule.AfterExecution : TrainingResetSchedule.None); }
protected override void Execute(NativeActivityContext context) { IEnumerable values = this.Values.Get(context); if (values == null) { throw new InvalidOperationException("ParallelForEach requires a non-null Values argument."); } IEnumerator valueEnumerator = values.GetEnumerator(); CompletionCallback onBodyComplete = new CompletionCallback(OnBodyComplete); while (valueEnumerator.MoveNext()) { if (this.Body != null) { context.ScheduleAction(this.Body, valueEnumerator.Current, onBodyComplete); } } IDisposable disposable = valueEnumerator as IDisposable; if (disposable != null) { disposable.Dispose(); } }
private void RunMainActivity(NativeActivityContext context) { context.ScheduleAction(MainActivity, OnMainActivityCompleted); timesCalled++; }