Beispiel #1
0
        /// <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);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Converts Monitor entity message to Freeform entity message
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>Freeform entity message.</returns>
        public FFMsg_H2G CreateEntity(MonMsg_H2G request)
        {
            using (ILogMethod method = Log.LogMethod(this.DYN_MODULE_NAME, "CreateEntity"))
            {
                FFMsg_H2G result = null;
                try
                {
                    if (request == null || request.Targets.Count == 0)
                    {
                        Log.Info("Unable to create the freeform message (Invalid targets found).");
                        return(null);
                    }

                    string key = request.FaultSourceTypeKey;

                    foreach (var monTgt in request.Targets)
                    {
                        IMonTgtParser parser = null;
                        MonTgtParserMappingH2GAttribute mappingAttribute = null;

                        //if (_tgtParserMappingsH2G.ContainsKey(key))
                        //{
                        //    parser = _tgtParserMappingsH2G[key];
                        //    mappingAttribute = parser.MappingAttributeH2G;
                        //}

                        //if (parser == null)
                        //{
                        key = monTgt.GetType().FullName;
                        if (_tgtParserMappingsByTypeH2G.ContainsKey(key))
                        {
                            parser           = _tgtParserMappingsByTypeH2G[key];
                            mappingAttribute = parser.MappingAttributeH2G;
                        }
                        //}

                        if (parser != null)
                        {
                            IFreeformEntity_MsgTgt ffTgt = parser.CreateEntity(request, monTgt) as IFreeformEntity_MsgTgt;
                            if (ffTgt != null)
                            {
                                if (result == null)
                                {
                                    result = FreeformEntityFactory.CreateEntity <FFMsg_H2G>(FF_FlowDirection.H2G,
                                                                                            new FFCreateEntityRequest_H2G()
                                    {
                                        PollCode  = mappingAttribute.PollCode,
                                        SessionID = mappingAttribute.SessionID,
                                        IPAddress = request.IpAddress,
                                    });
                                    result.InstallationNo = request.InstallationNo;
                                }
                                result.Targets.Add(ffTgt);
                            }
                        }
                    }

                    if (result == null)
                    {
                        Log.Info("Unable to create the freeform message");
                        return(null);
                    }
                }
                catch (Exception ex)
                {
                    method.Exception(ex);
                }

                return(result);
            }
        }
Beispiel #3
0
        private void InitializeTgtParserMappingsH2G()
        {
            using (ILogMethod method = Log.LogMethod(this.DYN_MODULE_NAME, "InitializeMappings"))
            {
                IDictionary <string, IMonTgtParser> parserInstances = null;

                try
                {
                    _tgtParserMappingsH2G       = new StringDictionary <IMonTgtParser>();
                    _tgtParserMappingsByTypeH2G = new StringDictionary <IMonTgtParser>();
                    _monitorTypeAttributesH2G   = new StringDictionary <MonTgtParserMappingAttribute>();
                    parserInstances             = new StringDictionary <IMonTgtParser>();

                    foreach (var mappingType in _tgtParserMappingTypesH2G.AsParallel())
                    {
                        IMonTgtParser      parser            = null;
                        MappingTypeH2GInfo typeInfo          = mappingType.Value;
                        MonTgtParserMappingH2GAttribute 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.MappingAttributeH2G = typeInfo.MappingAttribute;
                                parserInstances.Add(mappingTypeKey, parser);
                            }
                        }

                        if (parser == null)
                        {
                            continue;
                        }
                        if (!_tgtParserMappingsH2G.ContainsKey(attr.FaultSourceTypeKey))
                        {
                            _tgtParserMappingsH2G.Add(attr.FaultSourceTypeKey, parser);
                        }
                        if (attr.MonitorTargetType != null)
                        {
                            if (!_tgtParserMappingsByTypeH2G.ContainsKey(attr.MonitorTargetType.FullName))
                            {
                                _tgtParserMappingsByTypeH2G.Add(attr.MonitorTargetType.FullName, parser);
                            }

                            string monitorKey = attr.MonitorTargetType.Name;
                            if (!_monitorTypeAttributesH2G.ContainsKey(monitorKey))
                            {
                                _monitorTypeAttributesH2G.Add(monitorKey, attr);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    method.Exception(ex);
                }
                finally
                {
                    if (parserInstances != null)
                    {
                        parserInstances.Clear();
                        parserInstances = null;
                    }
                }
            }
        }