示例#1
0
文件: TaskExecutor.cs 项目: wpmyj/c3
        /// <summary>
        ///
        /// </summary>
        /// <param name="device"></param>
        /// <param name="operaName"></param>
        /// <param name="keyValues"></param>
        public ExecuteResult Execute(IDevice device, string operaName, KeyValueCollection keyValues)
        {
            if (device == null)
            {
                throw new ArgumentNullException("device");
            }

            if (keyValues == null)
            {
                keyValues = new KeyValueCollection();
            }

            if (!(device.Station.CommuniPort != null &&
                  device.Station.CommuniPort.IsOpened))
            {
                return(ExecuteResult.CreateFailExecuteResult("not connected"));
            }

            IOpera opera = device.Dpu.OperaFactory.Create(device.GetType().Name,
                                                          operaName);

            foreach (KeyValue kv in keyValues)
            {
                opera.SendPart[kv.Key] = kv.Value;
            }

            this.Task = new Task(device, opera, Strategy.CreateImmediateStrategy(), 1);

            device.TaskManager.Tasks.Enqueue(this.Task);

            return(ExecuteResult.CreateSuccessExecuteResult());
        }
示例#2
0
        public ExecuteResult Doit(ExecuteArgs args)
        {
            if (args == null)
            {
                throw new ArgumentNullException("args");
            }

            this._executeArgs = args;
            int     deviceID = args.DeviceID;
            IDevice device   = SoftManager.GetSoft().Hardware.FindDevice(deviceID);

            ExecuteResult r = null;

            if (StringHelper.Equal(args.ExecuteName, DefineExecuteNames.IsReady))
            {
                if (device == null)
                {
                    string s = string.Format(RemoteStrings.NotFindDeviceByID, deviceID);
                    r = ExecuteResult.CreateFailExecuteResult(s);
                }
                else
                {
                    if (device.Station.CommuniPort != null &&
                        device.Station.CommuniPort.IsOpened)
                    {
                        r = ExecuteResult.CreateSuccessExecuteResult();
                    }
                    else
                    {
                        r = ExecuteResult.CreateFailExecuteResult(RemoteStrings.NotConnection);
                    }
                }
            }
            else
            {
                Debug.Assert(device != null);
                TaskExecutor te = new TaskExecutor();
                te.Ended += new EventHandler(te_Ended);
                r         = te.Execute(device, args.ExecuteName, args.KeyValues);
            }
            return(r);
        }
示例#3
0
文件: RemoteServer.cs 项目: wpmyj/c3
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void RemoteObject_Executeing(object sender, ExecuteEventArgs e)
        {
            ExecuteResult r      = null;
            int           id     = e.ExecuteArgs.DeviceID;
            IDevice       device = SoftManager.GetSoft().Hardware.FindDevice(id);

            if (StringHelper.Equal(e.ExecuteArgs.ExecuteName, DefineExecuteNames.IsReady))
            {
                if (device == null)
                {
                    string s = string.Format(RemoteStrings.NotFindDeviceByID, id);
                    r = ExecuteResult.CreateFailExecuteResult(s);
                }
                else
                {
                    if (device.Station.CommuniPort != null &&
                        device.Station.CommuniPort.IsOpened)
                    {
                        r = ExecuteResult.CreateSuccessExecuteResult();
                    }
                    else
                    {
                        r = ExecuteResult.CreateFailExecuteResult(RemoteStrings.NotConnection);
                    }
                }
            }
            else
            {
                TaskExecutor te = new TaskExecutor();
                r = te.Execute(device, e.ExecuteArgs.ExecuteName, e.ExecuteArgs.KeyValues);
                log.Info("task execute : {0}, {1}", r.IsSuccess, r.FailMessage);
                if (r.IsSuccess)
                {
                    this.Add(e, te);
                }
            }
            e.Result = r;
        }