public bool EnqueList(string key, object element) { if (!dictListElementTypes.ContainsKey(key)) { return(false); } lock (dictLists[key]) { if (null == element) { (dictLists[key] as IList).Add(element); return(true); } if (dictListElementTypes[key].IsAssignableFrom(element.GetType())) { (dictLists[key] as IList).Add(element); return(true); } if (JFTypeExt.IsExplicitFrom(dictItemTypes[key], element.GetType())) { (dictLists[key] as IList).Add(JFConvertExt.ChangeType(element, dictListElementTypes[key])); return(true); } return(false); } }
/// <summary> /// 设置一个项的值 /// </summary> /// <param name="key"></param> /// <param name="value"></param> public bool SetItemValue(string key, object value) { if (!dictItemTypes.ContainsKey(key)) { return(false); } lock (dictItemTypes[key]) { if (null == value) { //if (dictItemTypes[key].IsValueType) // return false; dictItems[key] = value; return(true); } if (dictItemTypes[key].IsAssignableFrom(value.GetType()))//value的类型是ItemType的子类 { dictItems[key] = value; return(true); } if (JFTypeExt.IsExplicitFrom(dictItemTypes[key], value.GetType())) { dictItems[key] = JFConvertExt.ChangeType(value, dictItemTypes[key]); return(true); } return(false); } }
internal void Init() { JFXmlSortedDictionary <string, List <object> > devInitParams = JFHubCenter.Instance.SystemCfg.GetItemValue(JFHubCenter.CK_InitDevParams) as JFXmlSortedDictionary <string, List <object> >; foreach (KeyValuePair <string, List <object> > kv in devInitParams) { IJFInitializable dev = JFHubCenter.Instance.InitorHelp.CreateInstance(kv.Value[0] as string); // as IJFDevice; dictInitors.Add(kv.Key, dev); try //尝试初始化 { string[] paramNames = dev.InitParamNames; if (null != paramNames && paramNames.Length > 0) { for (int i = 0; i < paramNames.Length; i++) { object pr = i < kv.Value.Count - 1 ? kv.Value[i + 1] : null; object relParamVal = null; Type paramType = dev.GetInitParamDescribe(paramNames[i]).ParamType; SerializableAttribute[] sas = paramType.GetCustomAttributes(typeof(SerializableAttribute), false) as SerializableAttribute[]; if (sas != null && sas.Length > 0) //如果是可序列化的类型,直接保存序列化后的文本 { relParamVal = JFFunctions.FromXTString(pr as string, paramType); } else { if (paramType.IsValueType || paramType == typeof(string)) //单值对象和字符串对象直接添加 { relParamVal = pr; } else //目前支持Array 和 List { if (paramType.IsArray) //参数类型是数组 { if (null == pr || string.Empty == pr as string) { relParamVal = null; } else { string[] elmts = (pr as string).Split(new char[] { '$' }); relParamVal = GenArrayObject(paramType, elmts.Length); if (elmts.Length != 0) { for (int j = 0; j < elmts.Length; j++) { (relParamVal as Array).SetValue(JFConvertExt.ChangeType(elmts[j], paramType.GetElementType()), j); } } } } else if (typeof(IList).IsAssignableFrom(paramType)) //队列类型 { if (null == pr || string.Empty == pr as string) { relParamVal = null; } else { string[] elmts = (pr as string).Split(new char[] { '$' }); relParamVal = GenListObject(paramType); if (elmts.Length != 0) { for (int j = 0; j < elmts.Length; j++) { (relParamVal as IList).Add(JFConvertExt.ChangeType(elmts[j], paramType.GetElementType())); } } } } } } dev.SetInitParamValue(paramNames[i], relParamVal); } } dev.Initialize(); if (dev is IJFDevice) { (dev as IJFDevice).OpenDevice(); Thread.Sleep(100); } } catch { //初始化发生异常 } //dictInitors.Add(kv.Key, dev); //if (dev is IJFStation) //{ // (dev as IJFStation).WorkStatusChanged += JFHubCenter.Instance.StationMgr.StationWorkStatusChanged; // (dev as IJFStation).CustomStatusChanged += JFHubCenter.Instance.StationMgr.StationCustomStatusChanged; // if (dev is JFCmdWorkBase) // (dev as JFCmdWorkBase).WorkMsg2Outter += JFHubCenter.Instance.StationMgr.StationWorkMsg; //} } }