public Task(IDevice device, IOpera opera, Strategy strategy, int retryTimes) { this.Device = device; this.Opera = opera; this.Strategy = strategy; this.Retry = new Retry(retryTimes); }
/// <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()); }
/// <summary> /// /// </summary> /// <param name="deviceType"></param> /// <param name="operaNode"></param> /// <returns></returns> private static IOpera CreateComplexOpera(string deviceType, XmlNode operaNode) { OperaCollection operas = new OperaCollection(); foreach (XmlNode childOperaNode in operaNode.ChildNodes) { switch (childOperaNode.Name) { case DeviceDefineNodeNames.Opera: string childOperaName = GetAttribute((XmlElement)childOperaNode, DeviceDefineNodeNames.OperaName); IOpera childOpera = Create(deviceType, childOperaName, operaNode.ParentNode); if (childOpera == null) { string msg = string.Format("cannot create opera '{0}.{1}' from '{2}'", deviceType, childOperaName, operaNode.ParentNode.InnerXml); throw new ConfigException(msg); } operas.Add(childOpera); break; default: throw new ConfigException( string.Format("unexpectd node '{0}' in '{1}'", childOperaNode.Name, operaNode.InnerXml)); } } string operaName = GetAttribute((XmlElement)operaNode, DeviceDefineNodeNames.Name); return(new ComplexOpera(deviceType, operaName, operas)); }
/// <summary> /// /// </summary> /// <returns></returns> public TaskCollection Create(IDevice device) { TaskCollection tasks = new TaskCollection(); // TODO: not find // foreach (TaskDefine td in TaskDefines) { bool b = StringHelper.Equal(td.DeviceType, device.GetType().Name); if (!b) { continue; } IOpera opera = this.OperaFactory.Create(td.DeviceType, td.OperaName); Strategy strategy = td.StrategyDefine.Create(); //TimeSpan timeout = TimeSpan.FromMilliseconds(device.Station.CommuniPortConfig.TimeoutMilliSecond); Task t = new Task(device, opera, strategy, td.RetryTimes); device.TaskManager.Tasks.Enqueue(t); tasks.Add(t); } _log.Info("create '{0}' task count '{1}'", device.GetType().Name, tasks.Count); return(tasks); }
/// <summary> /// /// </summary> /// <param name="parseResult"></param> private void ProcessXGUploadRecordResult(XGDevice xgdevice, IParseResult pr) { ProcessXGDeviceRecordHelp(xgdevice, pr, false); IOperaFactory operaFactory = xgdevice.Dpu.OperaFactory; IOpera op = operaFactory.Create(xgdevice.GetType().Name, XGOperaNames.RemoveUpload); //ITaskFactory taskFactory = xgdevice.Dpu.TaskFactory; Task task = new Task(xgdevice, op, new ImmediateStrategy(), 1); xgdevice.TaskManager.Tasks.Enqueue(task); }
/// <summary> /// /// </summary> /// <param name="operaName"></param> /// <returns></returns> public IOpera Create(string deviceType, string operaName) { OperaDefine dd = FindDeviceDefine(deviceType); if (dd == null) { string s = string.Format("not find device type '{0}' from opera define collection", deviceType); throw new InvalidOperationException(s); } IOpera opera = dd.CreateOpera(operaName); return(opera); }
/// <summary> /// /// </summary> /// <param name="device"></param> /// <param name="bs"></param> /// <returns></returns> //public override IUploadParseResult OnProcessUpload(IDevice device, byte[] bs) public override void OnProcessUpload(IDevice device, IParseResult pr) { XGDevice xg = (XGDevice)device; DateTime dt = (DateTime)pr.Results["DT"]; string cardSN = pr.Results["cardSN"].ToString(); //xg.DeviceDataManager.Last = new XGData(dt, cardSN); SaveToDBAndUpdateLast(xg, dt, cardSN); IOpera op = device.Dpu.OperaFactory.Create(device.GetType().Name, XGOperaNames.RemoveUpload); Task task = new Task(device, op, Strategy.CreateImmediateStrategy(), 1); device.TaskManager.Tasks.Enqueue(task); }
/// <summary> /// /// </summary> /// <returns></returns> public IOpera CreateOpera(string operaName) { IOpera opera = MyOperaFactory.Create( this.DeviceType, operaName, this.OperaDefineNode ); if (opera == null) { string s = string.Format( "can not create opera with '{0} {1}'", this.DeviceType, operaName); throw new InvalidOperationException(s); } return(opera); }
public Task(IDevice device, IOpera opera, Strategy strategy) : this(device, opera, strategy, 1) { }
/// <summary> /// /// </summary> /// <param name="operaName"></param> /// <returns></returns> public IOpera Create(string deviceType, string operaName) { IOpera op = this.OperaDefines.Create(deviceType, operaName); return(op); }