protected override void ExecuteCrmWorkFlowActivity(CodeActivityContext context, LocalWorkflowContext localContext) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (localContext == null) { throw new ArgumentNullException(nameof(localContext)); } string stringToSearch = StringToSearch.Get(context); string searchFor = SearchFor.Get(context); bool caseSensitive = CaseSensitive.Get(context); if (!caseSensitive) { stringToSearch = stringToSearch.ToUpper(); searchFor = searchFor.ToUpper(); } bool containsString = stringToSearch.Contains(searchFor); ContainsString.Set(context, containsString); }
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); } }
protected override void Execute(CodeActivityContext executionContext) { var text = Text.Get <string>(executionContext); var old = Old.Get <string>(executionContext); var @new = New.Get <string>(executionContext); if (@new == null) { @new = String.Empty; } var result = string.Empty; if (!CaseSensitive.Get <bool>(executionContext)) { if (!String.IsNullOrEmpty(text) && !String.IsNullOrEmpty(old)) { result = text.Replace(old, @new); } } else { result = CompareAndReplace(text, old, @new, StringComparison.CurrentCultureIgnoreCase); } Result.Set(executionContext, result); }
protected override void Execute(CodeActivityContext executionContext) { ITracingService tracer = executionContext.GetExtension <ITracingService>(); try { string stringToSearch = StringToSearch.Get(executionContext); string searchFor = SearchFor.Get(executionContext); bool caseSensitive = CaseSensitive.Get(executionContext); if (!caseSensitive) { stringToSearch = stringToSearch.ToUpper(); searchFor = searchFor.ToUpper(); } bool containsString = stringToSearch.Contains(searchFor); ContainsString.Set(executionContext, containsString); } catch (Exception ex) { tracer.Trace("Exception: {0}", ex.ToString()); } }
/// <inheritdoc /> protected override void Execute(Context context) { var settings = new StringComparisonSettings { CaseSensitive = CaseSensitive.Get(context), AccentSensitive = AccentSensitive.Get(context) }; var result = StringComparisons.JaroWinklerDistance(String1.Get(context), String2.Get(context), settings); Result.Set(context, (int)Math.Round(result * 100)); }
protected override void Execute(CodeActivityContext executionContext) { try { string stringToSearch = StringToSearch.Get(executionContext); string searchFor = SearchFor.Get(executionContext); bool caseSensitive = CaseSensitive.Get(executionContext); bool startsWithString = stringToSearch.StartsWith(searchFor, (caseSensitive) ? StringComparison.CurrentCulture : StringComparison.CurrentCultureIgnoreCase); StartsWithString.Set(executionContext, startsWithString); } catch (Exception e) { throw new InvalidPluginExecutionException(e.Message); } }
protected override void Execute(CodeActivityContext executionContext) { ITracingService tracer = executionContext.GetExtension <ITracingService>(); try { string stringToSearch = StringToSearch.Get(executionContext); string searchFor = SearchFor.Get(executionContext); bool caseSensitive = CaseSensitive.Get(executionContext); bool endsWithString = stringToSearch.EndsWith(searchFor, (caseSensitive) ? StringComparison.CurrentCulture : StringComparison.CurrentCultureIgnoreCase); EndsWithString.Set(executionContext, endsWithString); } catch (Exception ex) { tracer.Trace("Exception: {0}", ex.ToString()); } }
protected override void ExecuteCrmWorkFlowActivity(CodeActivityContext context, LocalWorkflowContext localContext) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (localContext == null) { throw new ArgumentNullException(nameof(localContext)); } string stringToSearch = StringToSearch.Get(context); string searchFor = SearchFor.Get(context); bool caseSensitive = CaseSensitive.Get(context); bool endsWithString = stringToSearch.EndsWith(searchFor, (caseSensitive) ? StringComparison.CurrentCulture : StringComparison.CurrentCultureIgnoreCase); EndsWithString.Set(context, endsWithString); }
// Module defining this command // Optional custom code for this activity /// <summary> /// Returns a configured instance of System.Management.Automation.PowerShell, pre-populated with the command to run. /// </summary> /// <param name="context">The NativeActivityContext for the currently running activity.</param> /// <returns>A populated instance of System.Management.Automation.PowerShell</returns> /// <remarks>The infrastructure takes responsibility for closing and disposing the PowerShell instance returned.</remarks> protected override ActivityImplementationContext GetPowerShell(NativeActivityContext context) { System.Management.Automation.PowerShell invoker = global::System.Management.Automation.PowerShell.Create(); System.Management.Automation.PowerShell targetCommand = invoker.AddCommand(PSCommandName); // Initialize the arguments if (InputObject.Expression != null) { targetCommand.AddParameter("InputObject", InputObject.Get(context)); } if (Pattern.Expression != null) { targetCommand.AddParameter("Pattern", Pattern.Get(context)); } if (Path.Expression != null) { targetCommand.AddParameter("Path", Path.Get(context)); } if (LiteralPath.Expression != null) { targetCommand.AddParameter("LiteralPath", LiteralPath.Get(context)); } if (SimpleMatch.Expression != null) { targetCommand.AddParameter("SimpleMatch", SimpleMatch.Get(context)); } if (CaseSensitive.Expression != null) { targetCommand.AddParameter("CaseSensitive", CaseSensitive.Get(context)); } if (Quiet.Expression != null) { targetCommand.AddParameter("Quiet", Quiet.Get(context)); } if (List.Expression != null) { targetCommand.AddParameter("List", List.Get(context)); } if (Include.Expression != null) { targetCommand.AddParameter("Include", Include.Get(context)); } if (Exclude.Expression != null) { targetCommand.AddParameter("Exclude", Exclude.Get(context)); } if (NotMatch.Expression != null) { targetCommand.AddParameter("NotMatch", NotMatch.Get(context)); } if (AllMatches.Expression != null) { targetCommand.AddParameter("AllMatches", AllMatches.Get(context)); } if (Encoding.Expression != null) { targetCommand.AddParameter("Encoding", Encoding.Get(context)); } if (Context.Expression != null) { targetCommand.AddParameter("Context", Context.Get(context)); } return(new ActivityImplementationContext() { PowerShellInstance = invoker }); }
protected override void Execute(CodeActivityContext executionContext) { #region "Load CRM Service from context" Common objCommon = new Common(executionContext); objCommon.tracingService.Trace("Load CRM Service from context --- OK"); #endregion #region "Read Parameters" String inputText = this.InputText.Get(executionContext); bool capitalizeAllWords = this.CapitalizeAllWords.Get(executionContext); string padCharacter = this.PadCharacter.Get(executionContext); bool padontheLeft = this.PadontheLeft.Get(executionContext); int finalLengthwithPadding = this.FinalLengthwithPadding.Get(executionContext); string replaceOldValue = this.ReplaceOldValue.Get(executionContext); string replaceNewValue = this.ReplaceNewValue.Get(executionContext); if (replaceNewValue == null) { replaceNewValue = ""; } bool caseSensitive = this.CaseSensitive.Get(executionContext); bool fromLefttoRight = this.FromLefttoRight.Get(executionContext); int startIndex = this.StartIndex.Get(executionContext); int subStringLength = this.SubStringLength.Get(executionContext); string regularExpression = this.RegularExpression.Get(executionContext); #endregion string capitalizedText = ""; if (capitalizeAllWords) { // All words capitalizedText = System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(inputText); } else { // First Letter only capitalizedText = inputText.Substring(0, 1).ToUpper() + inputText.Substring(1); } //padding string paddedText = ""; if (padCharacter == "") { padCharacter = " "; } if (padontheLeft) { paddedText = inputText.PadLeft(finalLengthwithPadding, padCharacter.ToCharArray()[0]); } else { paddedText = inputText.PadRight(finalLengthwithPadding, padCharacter.ToCharArray()[0]); } //replace string string replacedText = ""; if (!CaseSensitive.Get <bool>(executionContext)) { if (!String.IsNullOrEmpty(inputText) && !String.IsNullOrEmpty(replaceOldValue)) { replacedText = inputText.Replace(replaceOldValue, replaceNewValue); } } else { replacedText = CompareAndReplace(inputText, replaceOldValue, replaceNewValue, StringComparison.CurrentCultureIgnoreCase); } //substring string subStringText = ""; if (subStringLength <= 0 || startIndex < 0) { subStringText = String.Empty; } else { if (!fromLefttoRight) { startIndex = inputText.Length - subStringLength - startIndex; } subStringText = inputText.Substring(startIndex, subStringLength); } //regex string regexText = ""; bool regexSuccess = false; if (regularExpression != "") { Regex regex = new Regex(regularExpression); Match match = regex.Match(inputText); if (match.Success) { regexSuccess = true; regexText = match.Value; } } this.CapitalizedText.Set(executionContext, capitalizedText); this.TextLength.Set(executionContext, capitalizedText.Length); this.PaddedText.Set(executionContext, paddedText); this.ReplacedText.Set(executionContext, replacedText); this.SubstringText.Set(executionContext, subStringText); this.TrimmedText.Set(executionContext, inputText.Trim()); this.RegexSuccess.Set(executionContext, regexSuccess); this.RegexText.Set(executionContext, regexText); }
protected override void Execute(NativeActivityContext context) { // var match = Element.Get(context); var wordlimit = WordLimit.Get(context); var lang = Config.local.ocrlanguage; var casesensitive = CaseSensitive.Get(context); var isfrontside = IsFrontSide.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.GetIdTextcomponents(path, Config.local.ocrlanguage, ele.element); // var result = ocr.GetIdTextcomponents(path, Config.local.ocrlanguage, @"c:\temp\dump.png"); ImageElement[] result; // 百度OCR var _ocr = new Baidu.Aip.Ocr.Ocr(ocr.API_KEY, ocr.SECRET_KEY); _ocr.Timeout = 60000;//设置超时时间 //_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); } String idCardSide; if (isfrontside) { idCardSide = "front"; } else { idCardSide = "back"; } MemoryStream ms = new MemoryStream(); sourceimg.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp); byte[] imageBytes = ms.GetBuffer(); ms.Close(); var word_results = _ocr.Idcard(imageBytes, idCardSide); context.SetValue(Result, word_results["words_result"]); var image_status = word_results["image_status"].ToString(); context.SetValue(OcrStatus, image_status); //IEnumerator<ImageElement> _enum = result.ToList().GetEnumerator(); //context.SetValue(_elements, _enum); //bool more = _enum.MoveNext(); //if (more) //{ // context.ScheduleAction(Body, _enum.Current, OnBodyComplete); //} }