/// <summary> /// Converts Freeform entity message to Moitor entity message /// </summary> /// <param name="request"></param> /// <returns></returns> public MonitorEntity_MsgTgt CreateTargetEntity(IMonitorEntity parent, IFreeformEntity_MsgTgt request) { using (ILogMethod method = Log.LogMethod(this.DYN_MODULE_NAME, "CreateTargetEntity")) { MonitorEntity_MsgTgt result = null; try { IFreeformEntity child = request; if (child.IsLeafNode) { return(null); } string key = child.GetType().FullName; if (!child.EntityKey.IsEmpty()) { key += "_" + child.EntityKey; } if (_tgtParserMappingsByTypeG2H.ContainsKey(key)) { IMonTgtParser parser = _tgtParserMappingsByTypeG2H[key]; MonTgtParserMappingG2HAttribute mappingAttribute = parser.MappingAttributeG2H; result = parser.CreateEntity(parent, child) as MonitorEntity_MsgTgt; if (result != null) { result.FaultSource = mappingAttribute.FaultSource; if (mappingAttribute.FaultType != -1) { result.FaultType = mappingAttribute.FaultType; } result.ExtraAttribute = mappingAttribute; } } } catch (Exception ex) { method.Exception(ex); } return(result); } }
private void InitializeTgtParserMappingsG2H() { using (ILogMethod method = Log.LogMethod(this.DYN_MODULE_NAME, "InitializeMappings")) { IDictionary <string, IMonTgtParser> parserInstances = null; try { _tgtParserMappingsG2H = new StringDictionary <IMonTgtParser>(); _tgtParserMappingsByTypeG2H = new StringDictionary <IMonTgtParser>(); _monitorTypeAttributesG2H = new StringDictionary <MonTgtParserMappingAttribute>(); parserInstances = new StringDictionary <IMonTgtParser>(); foreach (var mappingType in _tgtParserMappingTypesG2H.AsParallel()) { IMonTgtParser parser = null; MappingTypeG2HInfo typeInfo = mappingType.Value; MonTgtParserMappingG2HAttribute attr = typeInfo.MappingAttribute; string mappingTypeKey = typeInfo.MappingType.FullName; if (parserInstances.ContainsKey(mappingTypeKey)) { parser = parserInstances[mappingTypeKey] as IMonTgtParser; } else { parser = Activator.CreateInstance(typeInfo.MappingType) as IMonTgtParser; if (parser != null) { parser.MappingAttributeG2H = typeInfo.MappingAttribute; parserInstances.Add(mappingTypeKey, parser); } } if (parser == null) { continue; } if (!_tgtParserMappingsG2H.ContainsKey(attr.FaultSourceTypeKey)) { _tgtParserMappingsG2H.Add(attr.FaultSourceTypeKey, parser); } if (attr.FreeformTargetType != null) { string key = attr.FreeformTargetType.FullName; if (!attr.ChildKey.IsEmpty()) { key += "_" + attr.ChildKey; } if (!_tgtParserMappingsByTypeG2H.ContainsKey(key)) { _tgtParserMappingsByTypeG2H.Add(key, parser); } if (attr.MonitorTargetType != null) { string monitorKey = attr.MonitorTargetType.Name; if (!_monitorTypeAttributesG2H.ContainsKey(monitorKey)) { _monitorTypeAttributesG2H.Add(monitorKey, attr); } } } } } catch (Exception ex) { method.Exception(ex); } finally { if (parserInstances != null) { parserInstances.Clear(); parserInstances = null; } } } }