/// <summary> /// /// </summary> /// <param name="cfg"></param> /// <param name="success"></param> /// <param name="cp"></param> /// <param name="ex"></param> public CommuniPortCreatedEventArgs(ICommuniPortConfig cfg, bool success, ICommuniPort cp, Exception ex) { this._communiPortConfig = cfg; this._success = success; this._communiPort = cp; this._exception = ex; }
/// <summary> /// /// </summary> /// <param name="cpCfg"></param> /// <returns></returns> public ICommuniPort GetOrCreateCommuniPort(ICommuniPortConfig cpCfg) { if (cpCfg == null) { throw new ArgumentNullException("cpCfg"); } ICommuniPort r = null; foreach (ICommuniPort cp in this.CommuniPorts) { if (cpCfg.IsMatch(cp)) { r = cp; break; } } if (r == null) { if (cpCfg.CanCreate) { CommuniPortFactory f = CommuniPortFactory.Default; bool added = f.Add(cpCfg); _log.Info("add " + cpCfg + " to communiport factory: " + added); } } return(r); }
public CreateCommuniPortResult(bool success, ICommuniPortConfig communiPortConfig, string message, Exception exception) { this.Success = success; this.CommuniPortConfig = communiPortConfig; this.Message = message; this.Exception = exception; }
void doit2(ICommuniPortConfig v) { string s = CommuniPortConfigSerializer.Serialize(v); Console.WriteLine(s); ICommuniPortConfig v2 = CommuniPortConfigSerializer.Deserialize(s); Console.WriteLine(v2); }
public bool Add(ICommuniPortConfig cfg) { if (!_cpCfgs.Contains(cfg)) { this._cpCfgs.Add(cfg); return(true); } else { return(false); } }
/// <summary> /// /// </summary> void Target() { while (this._startFlag) { for (int i = _cpCfgs.Count - 1; i >= 0; i--) { ICommuniPortConfig cfg = _cpCfgs[i]; if (cfg.CanCreate) { ICommuniPort cp = null; bool success = false; Exception ex = null; try { cp = cfg.Create(); success = true; CPCreateLog cpclog = new CPCreateLog(DateTime.Now, string.Format("创建 '{0}' 成功", cfg)); this.CPCreateLogs.Add(cpclog); } catch (Exception e) { ex = e; success = false; CPCreateLog cpclog = new CPCreateLog(DateTime.Now, string.Format("创建 '{0}' 失败, {1}", cfg, ex.Message)); this.CPCreateLogs.Add(cpclog); } if (success) { this._cpCfgs.Remove(cfg); } if (CommuniPortCreated != null) { CommuniPortCreated(this, new CommuniPortCreatedEventArgs( cfg, success, cp, ex)); } } } Thread.Sleep(SLEEP_TIME); } }
/// <summary> /// /// </summary> /// <param name="value"></param> public static string Serialize(ICommuniPortConfig value) { if (value == null) { throw new ArgumentNullException("value"); } XmlSerializer er = new XmlSerializer(typeof(Wrapper)); StringWriter sw = new StringWriter(); Wrapper w = new Wrapper(); w.Config = value; er.Serialize(sw, w); return sw.ToString(); }
/// <summary> /// /// </summary> /// <param name="value"></param> static public string Serialize(ICommuniPortConfig value) { if (value == null) { throw new ArgumentNullException("value"); } XmlSerializer er = new XmlSerializer(typeof(Wrapper)); StringWriter sw = new StringWriter(); Wrapper w = new Wrapper(); w.Config = value; er.Serialize(sw, w); return(sw.ToString()); }
/// <summary> /// /// </summary> /// <param name="cpConfig"></param> /// <returns></returns> public static ICommuniPort Create(ICommuniPortConfig cpConfig) { if (cpConfig == null) { throw new ArgumentNullException("cpConfig"); } if (!cpConfig.CanCreate) { string s = string.Format( "cannot create form communiPortConfig: '{0}'", cpConfig.ToString()); throw new InvalidOperationException(s); } ICommuniPort cp = cpConfig.Create(); return cp; }
/// <summary> /// /// </summary> /// <param name="cp"></param> /// <param name="hardware"></param> static public StationCollection Bind(ICommuniPort cp, Hardware hardware) { StationCollection binded = new StationCollection(); foreach (IStation station in hardware.Stations) { ICommuniPortConfig cpConfig = station.CommuniPortConfig; if (cpConfig.IsMatch(cp)) { ICommuniPort old = station.CommuniPort; if (old != cp) { if (old != null) { old.Close(); } station.CommuniPort = cp; binded.Add(station); } } } return(binded); }
public ICommuniPort CreateCommuniPort(ICommuniPortConfig cpConfig) { ICommuniPort cp =null; try { cp = CommuniPortFactory.Create(cpConfig); } catch (Exception ex) { // log ERROR // _log.Fatal(ex); } if (cp != null) { this.Add(cp); } return cp; }
/// <summary> /// /// </summary> /// <param name="value"></param> /// <param name="orderNumber"></param> public CommuniPortConfigParameter(string name, ICommuniPortConfig value, int orderNumber) : base(name, typeof(ICommuniPortConfig), value, orderNumber) { }