示例#1
0
 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;
         }
     }
 }
示例#2
0
        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;
                }
            }
        }
示例#3
0
 protected override void Execute(CodeActivityContext context)
 {
     try
     {
         Int32  _timeout = Timeout.Get(context);
         string data     = "";
         Thread.Sleep(_timeout);
         latch = new CountdownEvent(1);
         Thread td = new Thread(() =>
         {
             System.Windows.Forms.IDataObject clipBoardBefore = System.Windows.Forms.Clipboard.GetDataObject();
             if (clipBoardBefore.GetDataPresent(System.Windows.DataFormats.Text))
             {
                 data = (string)clipBoardBefore.GetData(System.Windows.DataFormats.Text);
             }
             refreshData(latch);
         });
         td.TrySetApartmentState(ApartmentState.STA);
         td.IsBackground = true;
         td.Start();
         latch.Wait();
         Result.Set(context, data);
     }
     catch (Exception e)
     {
         SharedObject.Instance.Output(SharedObject.enOutputType.Error, "有一个错误产生", e.Message);
         if (ContinueOnError.Get(context))
         {
         }
         else
         {
             throw;
         }
     }
 }
示例#4
0
        protected override void Execute(CodeActivityContext context)
        {
            try
            {
                string _ProcessName = ProcessName.Get(context);
                if (_ProcessName.ToUpper().EndsWith(".EXE"))
                {
                    _ProcessName = _ProcessName.Substring(0, _ProcessName.Length - 4);
                }

                Process[] ps = Process.GetProcessesByName(_ProcessName);
                foreach (Process item in ps)
                {
                    item.Kill();
                }
                Thread.Sleep(1000);
            }
            catch (Exception e)
            {
                SharedObject.Instance.Output(SharedObject.enOutputType.Error, "有一个错误产生", e.Message);
                if (ContinueOnError.Get(context))
                {
                }
                else
                {
                    throw;
                }
            }
        }
示例#5
0
        protected override IAsyncResult BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback, object state)
        {
            try
            {
                m_Delegate = new runDelegate(Run);

                UiElement element = null;
                var       selStr  = Selector.Get(context);

                element = Common.GetValueOrDefault(context, this.Element, null);
                if (element == null && selStr != null)
                {
                    element = UiElement.FromSelector(selStr);
                }
                else
                {
                    PropertyDescriptor property = context.DataContext.GetProperties()[EleScope.GetEleScope];
                    element = property.GetValue(context.DataContext) as UiElement;
                }

                AutomationElement autoEle = element.NativeObject as AutomationElement;
                while (true)
                {
                    if (WaitNotActivity && WaitNotVisible)
                    {
                        //不可见 不活动 逻辑
                    }
                    else if (WaitNotActivity)
                    {
                        //不活动逻辑
                    }
                    else if (WaitNotVisible)
                    {
                        //不可见逻辑
                    }
                    else
                    {
                        if (!autoEle.IsEnabled)
                        {
                            break;
                        }
                    }
                    Thread.Sleep(500);
                }

                return(m_Delegate.BeginInvoke(callback, state));
            }
            catch (Exception e)
            {
                SharedObject.Instance.Output(SharedObject.enOutputType.Error, "等待元素消失出错", e.Message);
                if (ContinueOnError.Get(context))
                {
                    return(m_Delegate.BeginInvoke(callback, state));
                }
                else
                {
                    throw e;
                }
            }
        }
        protected override void Execute(CodeActivityContext context)
        {
            string _arguments        = Arguments.Get(context);
            string _fileName         = FileName.Get(context);
            string _workingDirectory = WorkingDirectory.Get(context);

            try
            {
                Process p = new System.Diagnostics.Process();
                if (_arguments != null)
                {
                    p.StartInfo.Arguments = _arguments;
                }
                if (_workingDirectory != null)
                {
                    p.StartInfo.WorkingDirectory = _workingDirectory;
                }
                p.StartInfo.UseShellExecute = Default;
                p.StartInfo.Verb            = "Open";
                p.StartInfo.FileName        = _fileName;
                p.Start();
            }
            catch (Exception e)
            {
                SharedObject.Instance.Output(SharedObject.enOutputType.Error, "有一个错误产生", e.Message);
                if (!ContinueOnError.Get(context))
                {
                    throw new NotImplementedException(e.Message);
                }
            }
        }
示例#7
0
 protected override void Execute(CodeActivityContext context)
 {
     try
     {
         string sPath = Path.Get(context);
         if (!Directory.Exists(sPath))
         {
             Directory.CreateDirectory(sPath);
         }
         else
         {
             SharedObject.Instance.Output(SharedObject.enOutputType.Warning, "有一个警告产生", "文件夹已存在!");
         }
     }
     catch
     {
         SharedObject.Instance.Output(SharedObject.enOutputType.Error, "有一个错误产生", "创建文件夹失败!");
         if (ContinueOnError.Get(context))
         {
         }
         else
         {
             throw;
         }
     }
 }
示例#8
0
        protected override void EndExecute(AsyncCodeActivityContext context, System.IAsyncResult result)
        {
            DatabaseConnection existingConnection = DBConnection.Get(context);

            try
            {
                Func <DBExecuteCommandResult> action        = (Func <DBExecuteCommandResult>)context.UserState;
                DBExecuteCommandResult        commandResult = action.EndInvoke(result);
                this.AffectedRecords.Set(context, commandResult.Result);
                foreach (var param in commandResult.ParametersBind)
                {
                    var currentParam = Parameters[param.Key];
                    if (currentParam.Direction == ArgumentDirection.Out || currentParam.Direction == ArgumentDirection.InOut)
                    {
                        currentParam.Set(context, param.Value.Item1);
                    }
                }
            }
            catch (Exception ex)
            {
                HandleException(ex, ContinueOnError.Get(context));
            }
            finally
            {
                if (existingConnection == null)
                {
                    DBConn.Dispose();
                }
            }
        }
示例#9
0
        protected async override Task <Action <AsyncCodeActivityContext> > ExecuteAsync(AsyncCodeActivityContext context, CancellationToken cancellationToken)
        {
            var          connString       = ConnectionString.Get(context);
            SecureString connSecureString = null;
            var          provName         = ProviderName.Get(context);

            connSecureString = ConnectionSecureString.Get(context);
            DatabaseConnection existingConnection = null;

            existingConnection = ExistingDbConnection.Get(context);
            DatabaseConnection dbConnection = null;
            var continueOnError             = ContinueOnError.Get(context);

            try
            {
                ConnectionHelper.ConnectionValidation(existingConnection, connSecureString, connString, provName);
                dbConnection = await Task.Run(() => existingConnection ?? new DatabaseConnection().Initialize(connString ?? new NetworkCredential("", connSecureString).Password, provName));

                if (UseTransaction)
                {
                    dbConnection.BeginTransaction();
                }
            }
            catch (Exception e)
            {
                Trace.TraceError($"{e}");
                HandleException(e, continueOnError);
            }
            return(asyncCodeActivityContext =>
            {
                DatabaseConnection.Set(asyncCodeActivityContext, dbConnection);
            });
        }
示例#10
0
 protected override void Execute(CodeActivityContext context)
 {
     try
     {
         string srcPath = Path.Get(context);
         if (File.Exists(srcPath))
         {
             File.Delete(srcPath);
         }
         else
         {
             Directory.Delete(srcPath, true);
         }
     }
     catch
     {
         SharedObject.Instance.Output(SharedObject.enOutputType.Error, "有一个错误产生", "删除文件或文件夹失败!");
         if (ContinueOnError.Get(context))
         {
         }
         else
         {
             throw;
         }
     }
 }
示例#11
0
 protected override void Execute(CodeActivityContext context)
 {
     try
     {
         Int32     _HighlightTime = GetValueOrDefault(context, HighlightTime, 1);
         Color     _Value         = GetValueOrDefault(context, Value, Color.Red);
         var       selStr         = Selector.Get(context);
         UiElement element        = GetValueOrDefault(context, this.Element, null);
         if (element == null && selStr != null)
         {
             element = UiElement.FromSelector(selStr);
         }
         if (element != null)
         {
             element.DrawHighlight(_Value, TimeSpan.FromSeconds(_HighlightTime), true);
             Thread.Sleep(_HighlightTime * 1);
         }
         else
         {
             UIAutomationCommon.HandleContinueOnError(context, ContinueOnError, Localize.LocalizedResources.GetString("msgNoElementFound"));
         }
     }
     catch (Exception e)
     {
         SharedObject.Instance.Output(SharedObject.enOutputType.Error, "UI元素设置高亮失败", e.Message);
         if (ContinueOnError.Get(context))
         {
         }
         else
         {
             throw;
         }
     }
 }
示例#12
0
        protected override void EndExecute(AsyncCodeActivityContext context, IAsyncResult result)
        {
            DatabaseConnection existingConnection = DBConnection.Get(context);

            try
            {
                Func <DataTable> action = (Func <DataTable>)context.UserState;
                DataTable        dt     = action.EndInvoke(result);
                if (dt == null)
                {
                    return;
                }

                DataTable.Set(context, dt);
            }
            catch (Exception ex)
            {
                HandleException(ex, ContinueOnError.Get(context));
            }
            finally
            {
                if (existingConnection == null)
                {
                    DBConn.Dispose();
                }
            }
        }
示例#13
0
        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;
                }
            }
        }
示例#14
0
 protected override void Execute(CodeActivityContext context)
 {
     try
     {
         string   filePath        = Path.Get(context);
         FileInfo file            = new FileInfo(filePath);
         string   DestinationPath = Destination.Get(context) + file.Name;
         if (file.Exists)
         {
             System.IO.File.Copy(filePath, DestinationPath, Overwrite);
         }
         else
         {
             SharedObject.Instance.Output(SharedObject.enOutputType.Error, "有一个错误产生", "文件复制失败");
         }
     }
     catch
     {
         SharedObject.Instance.Output(SharedObject.enOutputType.Error, "有一个错误产生", "文件复制失败");
         if (ContinueOnError.Get(context))
         {
         }
         else
         {
             throw;
         }
     }
 }
示例#15
0
        protected override IAsyncResult BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback, object state)
        {
            DataTable dataTable  = null;
            string    connString = null;
            string    provName   = null;
            string    tableName  = null;

            try
            {
                DbConnection = ExistingDbConnection.Get(context);
                connString   = ConnectionString.Get(context);
                provName     = ProviderName.Get(context);
                tableName    = TableName.Get(context);
                dataTable    = DataTable.Get(context);
            }
            catch (Exception ex)
            {
                HandleException(ex, ContinueOnError.Get(context));
            }
            // create the action for doing the actual work
            Func <int> action = () =>
            {
                DbConnection = DbConnection ?? new DatabaseConnection().Initialize(connString, provName);
                if (DbConnection == null)
                {
                    return(0);
                }
                return(DbConnection.InsertDataTable(tableName, dataTable));
            };

            context.UserState = action;
            return(action.BeginInvoke(callback, state));
        }
示例#16
0
 protected override void Execute(CodeActivityContext context)
 {
     try
     {
         var       selStr  = Selector.Get(context);
         UiElement element = Common.GetValueOrDefault(context, this.Element, null);
         if (element == null && selStr != null)
         {
             element = UiElement.FromSelector(selStr);
         }
         Rectangle rec = element.BoundingRectangle;
         Rectangle.Set(context, element.BoundingRectangle);
     }
     catch (Exception e)
     {
         SharedObject.Instance.Output(SharedObject.enOutputType.Error, "获取元素区域坐标失败", e.Message);
         if (ContinueOnError.Get(context))
         {
         }
         else
         {
             throw e;
         }
     }
 }
示例#17
0
 protected override void Execute(CodeActivityContext context)
 {
     try
     {
         var       selStr  = Selector.Get(context);
         UiElement element = Common.GetValueOrDefault(context, this.Element, null);
         if (element == null && selStr != null)
         {
             element = UiElement.FromSelector(selStr);
         }
         Bitmap bit = element.CaptureInformativeScreenshot();
         Image.Set(context, bit);
     }
     catch (Exception e)
     {
         SharedObject.Instance.Output(SharedObject.enOutputType.Error, "屏幕截图失败", e.Message);
         if (ContinueOnError.Get(context))
         {
         }
         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);
         }
     }
 }
示例#19
0
        private void OnFaultedCallback(NativeActivityFaultContext faultContext, Exception exception, ActivityInstance source)
        {
            faultContext.CancelChildren();
            DatabaseConnection conn = DBConnection.Get(faultContext);

            if (conn != null)
            {
                try
                {
                    if (UseTransaction)
                    {
                        conn.Rollback();
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    conn.Dispose();
                }
            }

            HandleException(exception, ContinueOnError.Get(faultContext));
            faultContext.HandleFault();
        }
示例#20
0
        protected override void Execute(CodeActivityContext context)
        {
            string buff = "";

            try
            {
                var       selStr  = Selector.Get(context);
                UiElement element = GetValueOrDefault(context, this.Element, null);
                if (element == null && selStr != null)
                {
                    element = UiElement.FromSelector(selStr);
                }

                if (element != null)
                {
                    if (element.IsNativeObjectAutomationElement)
                    {
                        var nativieObject = element.NativeObject as AutomationElement;
                        var comboBox      = nativieObject.AsTextBox();
                        buff = comboBox.Text;
                        if (Value != null)
                        {
                            Value.Set(context, buff);
                        }
                    }
                }
                else
                {
                    UIAutomationCommon.HandleContinueOnError(context, ContinueOnError, Localize.LocalizedResources.GetString("msgNoElementFound"));
                }
            }
            //catch(Exception)
            //{
            //    SharedObject.Instance.Output(SharedObject.enOutputType.Error, "PatternNotSupportedException");
            //}
            //catch (FlaUI.Core.Exceptions.MethodNotSupportedException)
            //{
            //    DataGridView gridView = element.AsDataGridView();
            //    AutomationElement[] child = gridView.FindAllChildren();
            //    for (int i = 0; i < child.Length; i++)
            //    {
            //        string nameStr = child[i].Name;
            //        buff += nameStr;
            //    }
            //    if (Value != null)
            //        Value.Set(context, buff);
            //}
            catch (Exception e)
            {
                SharedObject.Instance.Output(SharedObject.enOutputType.Error, "获取UI元素文本失败", e.Message);
                if (ContinueOnError.Get(context))
                {
                }
                else
                {
                    throw;
                }
            }
        }
示例#21
0
        protected override void Execute(CodeActivityContext context)
        {
            Int32 _delayAfter  = GetValueOrDefault(context, this.DelayAfter, 3000);
            Int32 _delayBefore = GetValueOrDefault(context, this.DelayBefore, 3000);

            try
            {
                Thread.Sleep(_delayBefore);
                var       selStr  = Selector.Get(context);
                UiElement element = GetValueOrDefault(context, this.Element, null);
                if (element == null && selStr != null)
                {
                    element = UiElement.FromSelector(selStr);
                }
                if (element != null)
                {
                    if (element.IsNativeObjectAutomationElement)
                    {
                        var nativieObject = element.NativeObject as AutomationElement;
                        var checkBox      = nativieObject.AsCheckBox();
                        checkBox.Click();
                    }
                    else
                    {
                        SharedObject.Instance.Output(SharedObject.enOutputType.Error, "有一个错误产生", "非Window元素");
                        if (ContinueOnError.Get(context))
                        {
                        }
                        else
                        {
                            throw new NotImplementedException("非Window元素");
                        }
                    }
                }
                else
                {
                    SharedObject.Instance.Output(SharedObject.enOutputType.Error, "有一个错误产生", "查找不到元素");
                    if (ContinueOnError.Get(context))
                    {
                    }
                    else
                    {
                        throw new NotImplementedException("查找不到元素");
                    }
                }
                Thread.Sleep(_delayAfter);
            }
            catch (Exception e)
            {
                SharedObject.Instance.Output(SharedObject.enOutputType.Error, "校验单选按钮或复选框失败", e.Message);
                if (ContinueOnError.Get(context))
                {
                }
                else
                {
                    throw;
                }
            }
        }
示例#22
0
        protected async override Task <Action <AsyncCodeActivityContext> > ExecuteAsync(AsyncCodeActivityContext context, CancellationToken cancellationToken)
        {
            DataTable    dataTable        = null;
            string       connString       = null;
            SecureString connSecureString = null;
            string       provName         = null;
            string       tableName        = null;

            string[]           columnNames        = null;
            DatabaseConnection existingConnection = null;
            long             affectedRecords      = 0;
            IExecutorRuntime executorRuntime      = null;
            var continueOnError = ContinueOnError.Get(context);

            try
            {
                existingConnection = DbConnection = ExistingDbConnection.Get(context);
                connString         = ConnectionString.Get(context);
                provName           = ProviderName.Get(context);
                tableName          = TableName.Get(context);
                dataTable          = DataTable.Get(context);
                columnNames        = ColumnNames.Get(context);
                executorRuntime    = context.GetExtension <IExecutorRuntime>();
                connSecureString   = ConnectionSecureString.Get(context);
                ConnectionHelper.ConnectionValidation(existingConnection, connSecureString, connString, provName);
                affectedRecords = await Task.Run(() =>
                {
                    DbConnection = DbConnection ?? new DatabaseConnection().Initialize(connString != null ? connString : new NetworkCredential("", connSecureString).Password, provName);
                    if (DbConnection == null)
                    {
                        return(0);
                    }
                    if (executorRuntime != null && executorRuntime.HasFeature(ExecutorFeatureKeys.LogMessage))
                    {
                        return(DbConnection.BulkUpdateDataTable(BulkUpdateFlag, tableName, dataTable, columnNames, executorRuntime));
                    }
                    else
                    {
                        return(DbConnection.BulkUpdateDataTable(BulkUpdateFlag, tableName, dataTable, columnNames));
                    }
                });
            }
            catch (Exception ex)
            {
                HandleException(ex, continueOnError);
            }
            finally
            {
                if (existingConnection == null)
                {
                    DbConnection?.Dispose();
                }
            }

            return(asyncCodeActivityContext =>
            {
                AffectedRecords.Set(asyncCodeActivityContext, affectedRecords);
            });
        }
示例#23
0
        protected override void Execute(CodeActivityContext context)
        {
            Int32 _delayAfter  = Common.GetValueOrDefault(context, this.DelayAfter, 300);
            Int32 _delayBefore = Common.GetValueOrDefault(context, this.DelayBefore, 300);

            try
            {
                Thread.Sleep(_delayBefore);
                var       selStr  = Selector.Get(context);
                UiElement element = Common.GetValueOrDefault(context, this.Element, null);
                if (element == null && selStr != null)
                {
                    element = UiElement.FromSelector(selStr);
                }

                Int32 pointX = 0;
                Int32 pointY = 0;
                if (usePoint)
                {
                    pointX = offsetX.Get(context);
                    pointY = offsetY.Get(context);
                }
                else
                {
                    if (element != null)
                    {
                        pointX = element.GetClickablePoint().X;
                        pointY = element.GetClickablePoint().Y;
                        element.SetForeground();
                    }
                    else
                    {
                        SharedObject.Instance.Output(SharedObject.enOutputType.Error, "有一个错误产生", "查找不到元素");
                        if (ContinueOnError.Get(context))
                        {
                            return;
                        }
                        else
                        {
                            throw new NotImplementedException("查找不到元素");
                        }
                    }
                }
                UiElement.MouseMoveTo(pointX, pointY);
                Thread.Sleep(_delayAfter);
            }
            catch (Exception e)
            {
                SharedObject.Instance.Output(SharedObject.enOutputType.Error, "有一个错误产生", e.Message);
                if (ContinueOnError.Get(context))
                {
                }
                else
                {
                    throw new NotImplementedException("查找不到元素");
                }
            }
        }
示例#24
0
        protected override async void Execute(NativeActivityContext context)
        {
            bool in_continueonerror = ContinueOnError.Get(context);

            try
            {
                CancellationToken cancellationToken = default;
                var timeout = Timeout.Get(context);

                int    tableNumber = TableNumber.Get(context);
                var    task        = GetHtmlMailBody(context);
                string htmlstring  = task.Result;

                var out_NumberOfTables = NumberOfMailTables(htmlstring);

                int NumberOfTables = out_NumberOfTables.Result;

                if (NumberOfTables == 0)
                {
                    throw new NullReferenceException("No table in mail Body");
                }
                ;

                if (tableNumber - 1 > NumberOfTables)
                {
                    throw new Exception("Total Number of tables in mail body is " + NumberOfTables.ToString() + " please enter the TableNumber equal or less then " + NumberOfTables.ToString());
                }
                else
                {
                    var result_datatables = GetDatatable(htmlstring);

                    DataTable[] out_dataTables = result_datatables.Result;


                    if (await Task.WhenAny(task, Task.Delay(timeout, cancellationToken)) != task)
                    {
                        throw new TimeoutException();
                    }
                    ;

                    if (tableNumber == 0)
                    {
                        Datatable.Set(context, out_dataTables[tableNumber]);
                    }
                    else
                    {
                        Datatable.Set(context, out_dataTables[tableNumber - 1]);
                    }
                }
            }


            catch { if (in_continueonerror == false)
                    {
                    }
            }
        }
示例#25
0
        protected override void Execute(CodeActivityContext context)
        {
            Int32 _delayAfter  = Common.GetValueOrDefault(context, this.DelayAfter, 300);
            Int32 _delayBefore = Common.GetValueOrDefault(context, this.DelayBefore, 300);

            try
            {
                Thread.Sleep(_delayBefore);
                var       selStr  = Selector.Get(context);
                UiElement element = Common.GetValueOrDefault(context, this.Element, null);
                if (element == null && selStr != null)
                {
                    element = UiElement.FromSelector(selStr);
                }

                Int32 pointX = 0;
                Int32 pointY = 0;
                if (usePoint)
                {
                    pointX = offsetX.Get(context);
                    pointY = offsetY.Get(context);
                }
                else
                {
                    if (element != null)
                    {
                        pointX = element.GetClickablePoint().X;
                        pointY = element.GetClickablePoint().Y;
                        element.SetForeground();
                    }
                }
                if (isRunClick)
                {
                    UiElement.MouseMoveTo(pointX, pointY);
                    UiElement.MouseAction((Plugins.Shared.Library.UiAutomation.ClickType)ClickType, (Plugins.Shared.Library.UiAutomation.MouseButton)MouseButton);
                }
                DealBaseKeyBordPress();
                if (Common.DealVirtualKeyPress(SelectedKey.ToUpper()))
                {
                    Common.DealVirtualKeyRelease(SelectedKey.ToUpper());
                }
                DealBaseKeyBordRelease();
                Thread.Sleep(_delayAfter);
            }
            catch (Exception e)
            {
                SharedObject.Instance.Output(SharedObject.enOutputType.Error, "有一个错误产生", e.Message);
                if (ContinueOnError.Get(context))
                {
                    return;
                }
                else
                {
                    throw new NotImplementedException(e.Message);
                }
            }
        }
示例#26
0
        protected override void Execute(CodeActivityContext context)
        {
            string text         = Text.Get(context);
            Int32  _delayAfter  = GetValueOrDefault(context, this.DelayAfter, 300);
            Int32  _delayBefore = GetValueOrDefault(context, this.DelayBefore, 300);

            try
            {
                Thread.Sleep(_delayBefore);
                var       selStr  = Selector.Get(context);
                UiElement element = GetValueOrDefault(context, this.Element, null);
                if (element == null && selStr != null)
                {
                    element = UiElement.FromSelector(selStr);
                }
                if (element != null)
                {
                    if (element.IsNativeObjectAutomationElement)
                    {
                        if (element.IsNativeObjectAutomationElement)
                        {
                            var nativieObject = element.NativeObject as AutomationElement;
                            var textbox       = nativieObject.AsTextBox();
                            if (!textbox.IsReadOnly)
                            {
                                textbox.Text = text;
                            }
                            else
                            {
                                SharedObject.Instance.Output(SharedObject.enOutputType.Error, Localize.LocalizedResources.GetString("msgErrorOccurred"), "该编辑框无法设置值");
                            }
                        }
                    }
                    else
                    {
                        UIAutomationCommon.HandleContinueOnError(context, ContinueOnError, "非Window元素");
                    }
                }
                else
                {
                    UIAutomationCommon.HandleContinueOnError(context, ContinueOnError, Localize.LocalizedResources.GetString("msgNoElementFound"));
                }
                Thread.Sleep(_delayAfter);
            }
            catch (Exception e)
            {
                SharedObject.Instance.Output(SharedObject.enOutputType.Error, "设置UI元素文本失败", e.Message);
                if (ContinueOnError.Get(context))
                {
                }
                else
                {
                    throw;
                }
            }
        }
示例#27
0
        protected override void Execute(CodeActivityContext context)
        {
            string itemName     = Item.Get(context);
            Int32  _delayAfter  = GetValueOrDefault(context, this.DelayAfter, 300);
            Int32  _delayBefore = GetValueOrDefault(context, this.DelayBefore, 300);

            try
            {
                Thread.Sleep(_delayBefore);
                var       selStr  = Selector.Get(context);
                UiElement element = GetValueOrDefault(context, this.Element, null);
                if (element == null && selStr != null)
                {
                    element = UiElement.FromSelector(selStr);
                }
                if (element != null)
                {
                    if (element.IsNativeObjectAutomationElement)
                    {
                        var nativieObject = element.NativeObject as AutomationElement;
                        var comboBox      = nativieObject.AsComboBox();
                        var comboItem     = comboBox.Select(itemName);
                        if (comboItem.Text != itemName)
                        {
                            var lbox     = nativieObject.AsListBox();
                            var listItem = lbox.Select(itemName);
                            if (listItem.Text != itemName)
                            {
                                SharedObject.Instance.Output(SharedObject.enOutputType.Error, "SelectItem失败,请检查UI元素!");
                            }
                        }
                    }
                    else
                    {
                        UIAutomationCommon.HandleContinueOnError(context, ContinueOnError, "非Window元素");
                    }
                }
                else
                {
                    UIAutomationCommon.HandleContinueOnError(context, ContinueOnError, Localize.LocalizedResources.GetString("msgNoElementFound"));
                }
                Thread.Sleep(_delayAfter);
            }
            catch (Exception e)
            {
                SharedObject.Instance.Output(SharedObject.enOutputType.Error, "选取组合框或列表框项目失败", e.Message);
                if (ContinueOnError.Get(context))
                {
                }
                else
                {
                    throw;
                }
            }
        }
示例#28
0
        protected override IAsyncResult BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback, object state)
        {
            try
            {
                m_Delegate = new runDelegate(Run);
                string    filterText = FilterText.Get(context);
                TreeScope treeScope;
                if (Scope == ScopeOption.Children)
                {
                    treeScope = TreeScope.Children;
                }
                else if (Scope == ScopeOption.Descendants)
                {
                    treeScope = TreeScope.Descendants;
                }
                else
                {
                    treeScope = TreeScope.Subtree;
                }
                UiElement element = null;
                var       selStr  = Selector.Get(context);


                element = Common.GetValueOrDefault(context, this.Element, null);
                if (element == null && selStr != null)
                {
                    element = UiElement.FromSelector(selStr);
                }
                else
                {
                    PropertyDescriptor property = context.DataContext.GetProperties()[EleScope.GetEleScope];
                    element = property.GetValue(context.DataContext) as UiElement;
                }

                List <UiElement> uiList = new List <UiElement>();
                uiList = element.FindAllByFilter(treeScope, TrueCondition.Default, filterText);
                UiList.Set(context, uiList);

                return(m_Delegate.BeginInvoke(callback, state));
            }
            catch (Exception e)
            {
                SharedObject.Instance.Output(SharedObject.enOutputType.Error, "获取子节点元素失败", e.Message);
                if (ContinueOnError.Get(context))
                {
                    return(m_Delegate.BeginInvoke(callback, state));
                }
                else
                {
                    throw e;
                }
            }
        }
示例#29
0
        protected override System.IAsyncResult BeginExecute(AsyncCodeActivityContext context, System.AsyncCallback callback, object state)
        {
            string connString     = null;
            string provName       = null;
            string sql            = string.Empty;
            int    commandTimeout = OverTime.Get(context);

            if (commandTimeout < 0)
            {
                throw new ArgumentException("TimeoutMS");
            }
            Dictionary <string, Tuple <object, ArgumentDirection> > parameters = null;

            try
            {
                sql        = SQLString.Get(context);
                DBConn     = DBConnection.Get(context);
                connString = ConnectionString.Get(context);
                provName   = ProviderName.Get(context);
                if (Parameters != null)
                {
                    parameters = new Dictionary <string, Tuple <object, ArgumentDirection> >();
                    foreach (var param in Parameters)
                    {
                        parameters.Add(param.Key, new Tuple <object, ArgumentDirection>(param.Value.Get(context), param.Value.Direction));
                    }
                }
            }
            catch (Exception ex)
            {
                HandleException(ex, ContinueOnError.Get(context));
            }

            // create the action for doing the actual work
            Func <DBExecuteCommandResult> action = () =>
            {
                DBExecuteCommandResult executeResult = new DBExecuteCommandResult();
                if (DBConn == null)
                {
                    DBConn = new DatabaseConnection().Initialize(connString, provName);
                }
                if (DBConn == null)
                {
                    return(executeResult);
                }
                executeResult = new DBExecuteCommandResult(DBConn.Execute(sql, parameters, commandTimeout, CommandType), parameters);
                return(executeResult);
            };

            context.UserState = action;

            return(action.BeginInvoke(callback, state));
        }
示例#30
0
        protected override void Execute(CodeActivityContext context)
        {
            string attribute_str   = Attribute.Get(context);
            string attribute_value = Value.Get(context);

            try
            {
                Int32 _timeout = TimeoutMS.Get(context);
                Thread.Sleep(_timeout);
                latch = new CountdownEvent(1);
                Thread td = new Thread(() =>
                {
                    if (Selector.Expression == null)
                    {
                        //ActiveElement处理
                    }
                    else
                    {
                        var selStr        = Selector.Get(context);
                        UiElement element = GetValueOrDefault(context, this.Element, null);
                        if (element == null && selStr != null)
                        {
                            element = UiElement.FromSelector(selStr);
                        }
                        if (element != null)
                        {
                            element.SetForeground();
                            mshtml.IHTMLDocument2 currDoc      = null;
                            SHDocVw.InternetExplorer ieBrowser = GetIEFromHWndClass.GetIEFromHWnd((int)element.WindowHandle, out currDoc);
                            mshtml.IHTMLElement currEle        = GetIEFromHWndClass.GetEleFromDoc(
                                element.GetClickablePoint(), (int)element.WindowHandle, currDoc);
                            currEle.setAttribute(attribute_str, attribute_value);
                        }
                        else
                        {
                            UIAutomationCommon.HandleContinueOnError(context, ContinueOnError, Localize.LocalizedResources.GetString("msgNoElementFound"));
                        }
                    }
                    refreshData(latch);
                });
                td.TrySetApartmentState(ApartmentState.STA);
                td.IsBackground = true;
                td.Start();
                latch.Wait();
            }
            catch (Exception e)
            {
                SharedObject.Instance.Output(SharedObject.enOutputType.Error, "出现异常", e.Message);
                if (ContinueOnError.Get(context))
                {
                }
            }
        }