Ejemplo n.º 1
0
        protected override IAsyncResult BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback,
                                                     object state)
        {
            base.Target  = "Win32_TerminalServiceSetting";
            base.Where   = base.WhereCondition.Get(context);
            base.Service = "cimv2";
            _useRdp      = context.GetValue(this.UseRemoteDesktop);
            _setFw       = context.GetValue(this.SetFirewallRule);
            _laterVista  = context.GetValue(this.IsVistaLater);

            return(base.BeginExecute(context, callback, state));
        }
Ejemplo n.º 2
0
        protected override IAsyncResult BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback, object state)
        {
            var hc   = new HttpClient();
            var task = hc
                       .PostAsync(context.GetValue(网址), context.GetValue(Http内容))
                       .ToApm(callback, state);

            task.ContinueWith(q =>
                              hc.Dispose()
                              );
            return(task);
        }
Ejemplo n.º 3
0
        protected override IAsyncResult BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback, object state)
        {
            // Obtain the runtime value of the Text input argument
            FileInfo image   = context.GetValue(this.InputFile);
            Options  options = context.GetValue(this.Options);

            Func <FileInfo, Options, AsyncCodeActivityContext, FileInfo> resizeDelegate = new Func <FileInfo, Options, AsyncCodeActivityContext, FileInfo>(ResizeImageFile);

            context.UserState = resizeDelegate;
            IAsyncResult result = resizeDelegate.BeginInvoke(image, options, context, callback, state);

            return(result);
        }
        /// <summary>
        ///     Asynchronously execute the activity
        /// </summary>
        /// <param name="context">The execution context for an asynchronous activity.</param>
        /// <param name="cancellationToken">Propagates notification that operations should be canceled.</param>
        /// <returns>Represents an asynchronous operation that returns DataTable.</returns>
        protected override Task <DataTable> ExecuteAsyncWithResult(AsyncCodeActivityContext context,
                                                                   CancellationToken cancellationToken)
        {
            string query = context.GetValue(Query);

            // Connection string from the Composer's Environment Settings.
            string connectionString = GetConnectionString(context);

            return(Task.Factory.StartNew(
                       () =>
            {
                DataTable dataTable = new DataTable();

                // Create a SQL connection to the Server
                using (SqlConnection connection = new SqlConnection(connectionString))
                {
                    // Execute SQL Query
                    using (SqlCommand sqlCommand = new SqlCommand(query, connection))
                    {
                        connection.Open();

                        // Fill the Datable with the request data
                        using (SqlDataAdapter dataAdapter = new SqlDataAdapter(sqlCommand))
                        {
                            dataAdapter.Fill(dataTable);
                            connection.Close();
                        }
                    }
                }

                // After a successful execution return the DataTable
                return dataTable;
            },
                       cancellationToken));
        }
Ejemplo n.º 5
0
        protected override IAsyncResult BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback,
                                                     object state)
        {
            base.Target = "Win32_NTLogEvent";
            var logtype          = context.GetValue(this.LogType) ?? "System";
            var conditionStrings = context.GetValue(base.WhereCondition);

            if (conditionStrings == null)
            {
                conditionStrings = "LogFile='" + logtype + "'";
            }
            else
            {
                conditionStrings = "LogFile='" + logtype + "' and " + conditionStrings;
            }

            base.Where   = conditionStrings;
            base.Service = "cimv2";
            return(base.BeginExecute(context, callback, state));
        }
Ejemplo n.º 6
0
        protected override IAsyncResult BeginExecute(AsyncCodeActivityContext context,
                                                     AsyncCallback callback, object state)
        {
            var currentScope = context.GetValue(Scope);

            var asyncExecute = new AsyncExecuteWMIDelegate(ExecuteWMI);

            context.UserState = asyncExecute;

            _selectFields = SelectFields.Get(context);
            HideExc       = HideException.Get(context);

            return(asyncExecute.BeginInvoke(Target, Where, currentScope, callback, state));
        }
Ejemplo n.º 7
0
        protected override IAsyncResult BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback,
                                                     object state)
        {
            base.Target  = "Win32_Service";
            base.Where   = base.WhereCondition.Get(context);
            base.Service = "cimv2";
            if (base.Where != "")
            {
                base.Where += " and ";
            }
            base.Where += "Name='" + context.GetValue(this.ServiceName) + "' ";

            switch (context.GetValue(this.Status))
            {
            case 1:
                _methodName = "StartService";
                //Start
                break;

            case 2:
                _methodName = "StopService";
                //Stop
                break;

            case 3:
                _methodName = "PauseService";
                //Pause
                break;

            case 4:
                _methodName = "ResumeService";
                //Resume
                break;
            }

            return(base.BeginExecute(context, callback, state));
        }
        protected override IAsyncResult BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback,
                                                     object state)
        {
            base.Target  = "AntiSpywareProduct";
            base.Where   = base.WhereCondition.Get(context);
            base.Service = "SecurityCenter";
            var lateVista = context.GetValue(this.IsVistaLater);

            if (lateVista)
            {
                base.Service += "2";
            }

            return(base.BeginExecute(context, callback, state));
        }
 protected override IAsyncResult BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback, object state)
 {
     return(context.GetValue(响应消息).Content.ReadAsStringAsync().ToApm(callback, state));
 }
Ejemplo n.º 10
0
        protected override IAsyncResult BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback, object state)
        {
            Int32 delayAfter  = GetValueOrDefault(context, this.DelayAfter, 300);
            Int32 delayBefore = GetValueOrDefault(context, this.DelayBefore, 300);
            Int32 timeoutMS   = GetValueOrDefault(context, this.TimeoutMS, 10000);

            object[] args;
            Thread.Sleep(delayBefore);

            if (Parameters.Count == 0)
            {
                args = new object[0];
            }
            else
            {
                args = new object[Parameters.Count];
                int i = 0;
                foreach (InArgument para in Parameters)
                {
                    args[i++] = context.GetValue(para);
                }
            }


            //var selStr = Selector.Get(context);
            string jsCode = JSCode.Get(context);

            if (File.Exists(jsCode))
            {
                string jsContent = File.ReadAllText(jsCode);
                jsCode = jsContent;
            }

            m_Delegate = new runDelegate(Run);
            //流程运行 只允许一个输入参数
            //chrome运行JS与IE不同,首先命名函数,而后执行。IE命名后可直接执行
            //返回值必须调用return func(),参数传递必须使用func(arguments[i])
            try
            {
                /******流程运行******/
                //根据OpenBrowser标志获取其抽象化属性
                PropertyDescriptor property = context.DataContext.GetProperties()[OpenBrowser.OpenBrowsersPropertyTag];
                if (property == null)
                {
                    //根据AttachBrowser标志获取其抽象化属性
                    property = context.DataContext.GetProperties()[AttachBrowser.OpenBrowsersPropertyTag];
                }
                if (property == null)
                {
                    return(m_Delegate.BeginInvoke(callback, state));
                }
                //抽象化属性转换为可用Browser属性
                Browser getBrowser = property.GetValue(context.DataContext) as Browser;

                ChromeDriver           chromeDriver = getBrowser.getICFBrowser() as ChromeDriver;
                InternetExplorerDriver ieDriver     = getBrowser.getICFBrowser() as InternetExplorerDriver;
                FirefoxDriver          fxDriver     = getBrowser.getICFBrowser() as FirefoxDriver;

                //流程运行
                object returnVaue  = null;
                Int32  circleTimes = timeoutMS / 1000;

                CallWithTimeout(new Action(() => {
                    if (isCircle)
                    {
                        for (int i = 0; i <= circleTimes; i++)
                        {
                            try
                            {
                                if (chromeDriver != null)
                                {
                                    returnVaue = chromeDriver.ExecuteScript(jsCode, args);
                                }
                                else if (fxDriver != null)
                                {
                                    returnVaue = fxDriver.ExecuteScript(jsCode, args);
                                }
                                else if (ieDriver != null)
                                {
                                    returnVaue = ieDriver.ExecuteScript(jsCode, args);
                                }
                                break;
                            }
                            catch
                            {
                                Thread.Sleep(500);
                                continue;
                            }
                        }
                    }
                    else
                    {
                        if (chromeDriver != null)
                        {
                            returnVaue = chromeDriver.ExecuteScript(jsCode, args);
                        }
                        else if (fxDriver != null)
                        {
                            returnVaue = fxDriver.ExecuteScript(jsCode, args);
                        }
                        else if (ieDriver != null)
                        {
                            returnVaue = ieDriver.ExecuteScript(jsCode, args);
                        }
                    }
                }), timeoutMS);

                if (returnVaue != null && JSOut != null)
                {
                    JSOut.Set(context, returnVaue);
                }
            }
            catch (Exception e)
            {
                SharedObject.Instance.Output(SharedObject.enOutputType.Error, "运行JS出错", e + "    JS: " + jsCode);
                if (ContinueOnError.Get(context))
                {
                    return(m_Delegate.BeginInvoke(callback, state));
                }
                else
                {
                    throw new NotImplementedException("执行JS过程出错!");
                }
            }

            if (isErrorFlag == true && !ContinueOnError.Get(context))
            {
                throw new NotImplementedException("执行JS过程出错!");
            }
            else
            {
                Thread.Sleep(delayAfter);
                return(m_Delegate.BeginInvoke(callback, state));
            }
        }
Ejemplo n.º 11
0
        protected override Task ExecuteAsync(AsyncCodeActivityContext context, CancellationToken cancellationToken, Application client)
        {
            var columnNames = context.GetValue <string>(ColumnNames);

            return(Task.Run(() => client.SelectColumns(columnNames.Split(','))));
        }
Ejemplo n.º 12
0
        protected override Task ExecuteAsync(AsyncCodeActivityContext context, CancellationToken cancellationToken, Application client)
        {
            string filePath = context.GetValue <string>(FilePath);

            return(Task.Run(() => client.SaveToTextFile(filePath)));
        }