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); }
private void OnBodyComplete(NativeActivityContext context, ActivityInstance completedInstance) { IElement element = _element.Get(context); if (element != null && element is UIElement ui) { //var window = ((UIElement)element).GetWindow(); var x = X.Get(context); var y = Y.Get(context); var width = Width.Get(context); var height = Height.Get(context); var animatemove = AnimateMove.Get(context); //if(width > 0 && height > 0) //{ // ui.SetWindowSize(width, height); //} //if (x>0 && y>0) //{ // if (animatemove) ui.MoveWindowTo(x, y); if (animatemove) { ui.MoveWindowTo(x, y, width, height); } if (!animatemove) { ui.SetWindowSize(width, height); ui.SetWindowPosition(x, y); } //} } }
protected new void Initialize(CodeActivityContext context) { base.Initialize(context); width = Width.Get(context); buttonText = ButtonText.Get(context); }
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); }
// 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 (Stream.Expression != null) { targetCommand.AddParameter("Stream", Stream.Get(context)); } if (Width.Expression != null) { targetCommand.AddParameter("Width", Width.Get(context)); } if (InputObject.Expression != null) { targetCommand.AddParameter("InputObject", InputObject.Get(context)); } return(new ActivityImplementationContext() { PowerShellInstance = invoker }); }
private void OnBodyComplete(NativeActivityContext context, ActivityInstance completedInstance) { if (breakRequested) { return; } IElement element = _element.Get(context); if (element != null && element is UIElement ui) { var x = X.Get(context); var y = Y.Get(context); var width = Width.Get(context); var height = Height.Get(context); var animatemove = AnimateMove.Get(context); if (animatemove) { ui.MoveWindowTo(x, y, width, height); } if (!animatemove) { ui.SetWindowSize(width, height); ui.SetWindowPosition(x, y); } } }
protected new virtual void Initialize(CodeActivityContext context) { InitializeDelegate(context); width = Width.Get(context); value = Value.Get(context); //value = null; }
// 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 (FilePath.Expression != null) { targetCommand.AddParameter("FilePath", FilePath.Get(context)); } if (LiteralPath.Expression != null) { targetCommand.AddParameter("LiteralPath", LiteralPath.Get(context)); } if (Encoding.Expression != null) { targetCommand.AddParameter("Encoding", Encoding.Get(context)); } if (Append.Expression != null) { targetCommand.AddParameter("Append", Append.Get(context)); } if (Force.Expression != null) { targetCommand.AddParameter("Force", Force.Get(context)); } if (NoClobber.Expression != null) { targetCommand.AddParameter("NoClobber", NoClobber.Get(context)); } if (Width.Expression != null) { targetCommand.AddParameter("Width", Width.Get(context)); } if (NoNewline.Expression != null) { targetCommand.AddParameter("NoNewline", NoNewline.Get(context)); } if (InputObject.Expression != null) { targetCommand.AddParameter("InputObject", InputObject.Get(context)); } return(new ActivityImplementationContext() { PowerShellInstance = invoker }); }
protected override void Execute(CodeActivityContext context) { string message = Message.Get(context); int width = Width.Get(context); int height = Height.Get(context); Image image = QrCodeDrawer.Draw(message, width, height); Result.Set(context, image); }
protected override void Execute(CodeActivityContext context) { string path = Path.Get(context); string message = Message.Get(context); int width = Width.Get(context); int height = Height.Get(context); using (Image image = QrCodeDrawer.Draw(message, width, height)) { image.Save(path); } }
protected override IAsyncResult BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback, object state) { Window currWindow = ActiveWindow.Get(context); try { if (currWindow == null) { PropertyDescriptor property = context.DataContext.GetProperties()[WindowActive.OpenBrowsersPropertyTag]; if (property == null) { property = context.DataContext.GetProperties()[WindowAttach.OpenBrowsersPropertyTag]; } if (property != null) { currWindow = property.GetValue(context.DataContext) as Window; } } Win32Api.Rect rect = new Win32Api.Rect(); Win32Api.GetWindowRect((IntPtr)currWindow.getWindowHwnd(), out rect); int oldWidth = rect.Right - rect.Left; int oldHeight = rect.Bottom - rect.Top; int oldPosX = rect.Left; int oldPosY = rect.Top; int newPosX = PosX.Get(context); int newPosY = PosY.Get(context); int newWidth = Width.Get(context); int newHeight = Height.Get(context); int defPosX = newPosX == 0 ? oldPosX : newPosX; int defPosY = newPosY == 0 ? oldPosY : newPosY; int defWidth = newWidth == 0 ? oldWidth : newWidth; int defHeight = newHeight == 0 ? oldHeight : newHeight; Win32Api.MoveWindow(currWindow.getWindowHwnd(), defPosX, defPosY, defWidth, defHeight, true); } catch (Exception e) { SharedObject.Instance.Output(SharedObject.enOutputType.Error, "关闭窗口错误产生", e.Message); if (ContinueOnError.Get(context)) { } else { throw; } } m_Delegate = new runDelegate(Run); return(m_Delegate.BeginInvoke(callback, state)); }
protected override void StartLoop(NativeActivityContext context) { var selectorstring = Selector.Get(context); selectorstring = OpenRPA.Interfaces.Selector.Selector.ReplaceVariables(selectorstring, context.DataContext); var selector = new Interfaces.Selector.Selector(selectorstring); var checkrunning = CheckRunning.Get(context); checkrunning = true; var pluginname = selector.First().Selector; var Plugin = Plugins.recordPlugins.Where(x => x.Name == pluginname).First(); var timeout = Timeout.Get(context); var element = Plugin.LaunchBySelector(selector, checkrunning, timeout); Result.Set(context, element); _element.Set(context, element); if (element != null && element is UIElement ui && Body == null) { //var window = ((UIElement)element).GetWindow(); var x = X.Get(context); var y = Y.Get(context); var width = Width.Get(context); var height = Height.Get(context); var animatemove = AnimateMove.Get(context); if ((width == 0 && height == 0) || (x == 0 && y == 0)) { } else { if (animatemove) { ui.MoveWindowTo(x, y, width, height); } if (!animatemove) { ui.SetWindowSize(width, height); ui.SetWindowPosition(x, y); } } } if (element != null && Body != null) { IncIndex(context); SetTotal(context, 1); context.ScheduleAction(Body, element, OnBodyComplete); } }
protected override void Execute(NativeActivityContext context) { string expression = null; Expr expr = null; if (Expression.Get(context) is null) { expr = Expr.Get(context); } else { expression = Expression.Get(context); } var w = Width.Get(context); var h = Height.Get(context); var client = (Application)context.Properties.Find(@"Application"); while (client == null || !client.Ready) { Console.WriteLine(Resources.WolframLanguageScope_Execute_Waiting_for_client_to_be_ready___); Thread.Sleep(100); } if (expr is null) { expression = Timeout is null || Timeout.Get(context) <= 0 ? expression : Application.ApplyTimeConstraint(expression, Timeout.Get(context)); } else { expr = Timeout is null || Timeout.Get(context) <= 0 ? expr : Application.ApplyTimeConstraint(expr, Timeout.Get(context)); } Result.Set(context, expr is null ? client.EvaluateToImage(expression, w, h) : client.EvaluateToImage(expr, w, h)); }
protected override void Execute(CodeActivityContext context) { var el = Element.Get(context); if (el == null) { throw new ArgumentException("element cannot be null"); } var screen = Screen.Get(context); var x = X.Get(context); var y = Y.Get(context); var width = Width.Get(context); var height = Height.Get(context); var animatemove = AnimateMove.Get(context); var windowstate = WindowState.Get(context); if (width <= 30 || height <= 10) { } else { var allScreens = System.Windows.Forms.Screen.AllScreens.ToList(); if (screen < 0) { Log.Warning("screen cannot be below 0, using screen 0"); screen = 0; } if (screen >= allScreens.Count) { Log.Warning("screen " + screen + " does not exists, using " + (allScreens.Count - 1) + " instead"); screen = allScreens.Count - 1; } x += allScreens[screen].WorkingArea.X; y += allScreens[screen].WorkingArea.Y; var _window = ((UIElement)el).GetWindow(); var window = new UIElement(_window); if (_window.Properties.NativeWindowHandle.IsSupported) { GenericTools.Restore(_window.Properties.NativeWindowHandle.Value); } if (animatemove) { window.MoveWindowTo(x, y, width, height); } if (!animatemove) { window.SetWindowSize(width, height); window.SetWindowPosition(x, y); } if (!string.IsNullOrEmpty(windowstate) && _window.Properties.NativeWindowHandle.IsSupported) { switch (windowstate) { case "Normal": GenericTools.Restore(_window.Properties.NativeWindowHandle.Value); break; case "Minimized": GenericTools.Minimize(_window.Properties.NativeWindowHandle.Value); break; case "Maximized": GenericTools.Maximized(_window.Properties.NativeWindowHandle.Value); break; } } } }
protected override async Task <Action <AsyncCodeActivityContext> > ExecuteAsync(AsyncCodeActivityContext context, CancellationToken cancellationToken) { // Inputs var timeout = TimeoutMS.Get(context); var inputImage = InputImage.Get(context); var positionX = PositionX.Get(context); var positionY = PositionY.Get(context); var width = Width.Get(context); var height = Height.Get(context); var blur = Blur.Get(context); var blurAmount = BlurAmount.Get(context); // Set a timeout on the execution var task = ExecuteWithTimeout(context, cancellationToken); if (await Task.WhenAny(task, Task.Delay(timeout, cancellationToken)) != task) { throw new TimeoutException(Resources.Timeout_Error); } Image returnImage; // Check if activity should blur or hide part of the image if (blur) { // Convert image to bytestream ImageConverter _imageConverter = new ImageConverter(); byte[] imageByteStream = (byte[])_imageConverter.ConvertTo(inputImage, typeof(byte[])); // Create image from bytestream for MagickImage use var magickimage = new MagickImage(imageByteStream); // Blur part of image magickimage.RegionMask(new MagickGeometry(positionX, positionY, width, height)); magickimage.GaussianBlur(blurAmount, 25); magickimage.RemoveRegionMask(); // Convert MagickInmage to Bytestream var imageBytesOut = magickimage.ToByteArray(); MemoryStream ms = new MemoryStream(imageBytesOut); // Create return image from bytestream returnImage = Image.FromStream(ms); } else { // Create graphics context with returnImage returnImage = inputImage; using (Graphics g = Graphics.FromImage(returnImage)) { // Define brush and rectangle SolidBrush blackBrush = new SolidBrush(Color.Black); Rectangle rect = new Rectangle(positionX, positionY, width, height); // Fill rectangle g.FillRectangle(blackBrush, rect); // Cleanup g.Dispose(); } } // Outputs return((ctx) => { OutputImage.Set(ctx, returnImage); }); }
protected override void StartLoop(NativeActivityContext context) { var selectorstring = Selector.Get(context); selectorstring = OpenRPA.Interfaces.Selector.Selector.ReplaceVariables(selectorstring, context.DataContext); var selector = new Interfaces.Selector.Selector(selectorstring); var checkrunning = CheckRunning.Get(context); checkrunning = true; var pluginname = selector.First().Selector; var Plugin = Plugins.recordPlugins.Where(x => x.Name == pluginname).First(); var timeout = Timeout.Get(context); if (Timeout == null || Timeout.Expression == null) { timeout = TimeSpan.FromSeconds(3); } var element = Plugin.LaunchBySelector(selector, checkrunning, timeout); Result.Set(context, element); _element.Set(context, element); if (element != null && element is UIElement ui && Body == null) { //var window = ((UIElement)element).GetWindow(); var screen = Screen.Get(context); var x = X.Get(context); var y = Y.Get(context); var width = Width.Get(context); var height = Height.Get(context); var animatemove = AnimateMove.Get(context); // if ((width == 0 && height == 0) || (x == 0 && y == 0)) if (width <= 30 || height <= 10) { } else { var allScreens = System.Windows.Forms.Screen.AllScreens.ToList(); if (screen < 0) { Log.Warning("screen cannot be below 0, using screen 0"); screen = 0; } if (screen >= allScreens.Count) { Log.Warning("screen " + screen + " does not exists, using " + (allScreens.Count - 1) + " instead"); screen = allScreens.Count - 1; } x += allScreens[screen].WorkingArea.X; y += allScreens[screen].WorkingArea.Y; if (animatemove) { ui.MoveWindowTo(x, y, width, height); } if (!animatemove) { ui.SetWindowSize(width, height); ui.SetWindowPosition(x, y); } } } if (element != null && Body != null) { IncIndex(context); SetTotal(context, 1); context.ScheduleAction(Body, element, OnBodyComplete); } }
protected override void Execute(NativeActivityContext context) { // получим все параметры var teCode = TeCode.Get(context); // переведем код ТЕ в верхний регистр if (!string.IsNullOrEmpty(teCode)) { teCode = teCode.ToUpper(); } var placeCode = PlaceCode.Get(context); var isPack = IsPack.Get(context); var length = Length.Get(context); var width = Width.Get(context); var height = Height.Get(context); var tareWeight = TareWeight.Get(context); var weight = Weight.Get(context); var mandants = Mandants.Get(context); var teTypeCode = TeTypeCode.Get(context); var autoTeType = AutoTeType.Get(context); var extFilter = Filter.Get(context); _fontSize = FontSize.Get(context); var suspendNotifyCollectionChanged = SuspendNotifyCollectionChanged.Get(context); var teManager = IoC.Instance.Resolve <IBaseManager <TE> >(); try { if (suspendNotifyCollectionChanged) { teManager.SuspendNotifications(); } // если поле тип ТЕ пустое и не стоит признак пытаться определить тип ТЕ автоматически if (string.IsNullOrEmpty(teTypeCode) && !autoTeType) { throw new OperationException("Не указан тип ТЕ"); } // если поле тип ТЕ заполнено и установлен признак получения автоматически if (!string.IsNullOrEmpty(teTypeCode) && autoTeType) { throw new OperationException("Неверные настройки получения типа ТЕ"); } var uw = BeginTransactionActivity.GetUnitOfWork(context); if (uw != null) { throw new OperationException("Действие в транзакции запрещено"); } // проверим существование ТЕ if (!string.IsNullOrEmpty(teCode)) { var bpManager = IoC.Instance.Resolve <IBPProcessManager>(); var existTe = bpManager.CheckInstanceEntity("TE", teCode); if (existTe == 1) { var existTeObj = teManager.Get(teCode); if (existTeObj == null) { throw new OperationException("Нет прав на ТЕ с кодом {0}", teCode); } ExceptionResult.Set(context, null); TeCode.Set(context, teCode); OutTe.Set(context, existTeObj); Exist.Set(context, true); Result.Set(context, true); return; } } // фильтр на тип ТЕ var filter = string.Empty; // фильтр по мандантам if (!string.IsNullOrEmpty(mandants)) { filter = string.Format( "tetypecode in (select tt2m.tetypecode_r from wmstetype2mandant tt2m where tt2m.partnerid_r in ({0}))", mandants); } // фильтр по упаковкам if (isPack) { filter = string.Format( "{0}tetypecode in (select CUSTOMPARAMVAL.cpvkey from wmscustomparamvalue CUSTOMPARAMVAL where CUSTOMPARAMVAL.CPV2ENTITY = 'TETYPE' and CUSTOMPARAMVAL.CUSTOMPARAMCODE_R = 'TETypeIsPackingL2' and CUSTOMPARAMVAL.CPVVALUE is not null and CUSTOMPARAMVAL.CPVVALUE != '0')", string.IsNullOrEmpty(filter) ? string.Empty : filter + " and "); } // дополнительный фильтр по типам ТЕ if (!string.IsNullOrEmpty(extFilter)) { filter = string.Format( "{0}{1}", string.IsNullOrEmpty(filter) ? string.Empty : filter + " and ", extFilter); } // если надо определить тип ТЕ автоматически if (autoTeType) { teTypeCode = BPH.DetermineTeTypeCodeByTeCode(teCode, filter); } var teTypeObj = GetTeType(teTypeCode, filter); // если не выбрали тип ТЕ if (teTypeObj == null) { ExceptionResult.Set(context, null); TeCode.Set(context, teCode); OutTe.Set(context, null); Exist.Set(context, false); Result.Set(context, false); return; } var teObj = new TE(); teObj.SetKey(teCode); teObj.SetProperty(TE.TETypeCodePropertyName, teTypeObj.GetKey()); teObj.SetProperty(TE.CreatePlacePropertyName, placeCode); teObj.SetProperty(TE.CurrentPlacePropertyName, placeCode); teObj.SetProperty(TE.StatusCodePropertyName, TEStates.TE_FREE.ToString()); teObj.SetProperty(TE.TEPackStatusPropertyName, isPack ? TEPackStatus.TE_PKG_CREATED.ToString() : TEPackStatus.TE_PKG_NONE.ToString()); teObj.SetProperty(TE.TELengthPropertyName, length ?? teTypeObj.GetProperty(TEType.LengthPropertyName)); teObj.SetProperty(TE.TEWidthPropertyName, width ?? teTypeObj.GetProperty(TEType.WidthPropertyName)); teObj.SetProperty(TE.TEHeightPropertyName, height ?? teTypeObj.GetProperty(TEType.HeightPropertyName)); teObj.SetProperty(TE.TETareWeightPropertyName, tareWeight ?? teTypeObj.GetProperty(TEType.TareWeightPropertyName)); teObj.SetProperty(TE.TEMaxWeightPropertyName, tareWeight ?? teTypeObj.GetProperty(TEType.MaxWeightPropertyName)); teObj.SetProperty(TE.TEWeightPropertyName, weight ?? teTypeObj.GetProperty(TEType.TareWeightPropertyName)); ((ISecurityAccess)teManager).SuspendRightChecking(); teManager.Insert(ref teObj); ExceptionResult.Set(context, null); TeCode.Set(context, teCode); OutTe.Set(context, teObj); Exist.Set(context, false); Result.Set(context, true); } catch (Exception ex) { TeCode.Set(context, teCode); ExceptionResult.Set(context, ex); OutTe.Set(context, null); Exist.Set(context, false); Result.Set(context, false); } finally { if (suspendNotifyCollectionChanged) { teManager.ResumeNotifications(); } ((ISecurityAccess)teManager).ResumeRightChecking(); } }
protected override void Initialize(CodeActivityContext context) { base.InitializeDelegate(context); width = Width.Get(context); value = Value.Get(context); }