示例#1
0
        /// <summary>
        /// DynamicStats request.
        /// </summary>
        /// <param name="TenantName">Name of the tenant.</param>
        /// <param name="ObjectID">The object ID.</param>
        /// <param name="statObjectType">Type of the stat object.</param>
        /// <param name="statTypeName">Name of the stat type.</param>
        /// <param name="Seconds">The seconds.</param>
        /// <param name="filter">The filter.</param>
        /// <param name="insensitivity">The insensitivity.</param>
        /// <param name="refID">The reference ID.</param>
        /// <returns></returns>
        public IMessage StatRequest(RequestOpenStatisticEx requestStat)
        {
            IMessage message = null;

            try
            {
                logger.Info("Request : StatRequest Method :Entry");

                if (StatisticsSetting.GetInstance().statServerProtocol != null)
                {
                    if (StatSettings.statServerProtocol.State == ChannelState.Opened)
                    {
                        logger.Info("Request : StatRequest Method :" + requestStat.ToString());
                        message = StatSettings.statServerProtocol.Request(requestStat);
                        logger.Info("Request : StatRequest Method :" + message.ToString());
                    }
                }
            }
            catch (ProtocolException Protocolexception)
            {
                logger.Error("Request : StatRequest Method : " + Protocolexception.Message);
            }
            catch (Exception GeneralException)
            {
                logger.Error("Request : StatRequest Method : " + GeneralException.Message);
            }
            finally
            {
                logger.Debug("Request : StatRequest Method : Exit");
                GC.SuppressFinalize(message);
                GC.Collect();
            }
            return(message);
        }
示例#2
0
        public void TestNotifyAvgTimeSent()
        {
            // Arrange.
            var repo             = new MockRepository(MockBehavior.Default);
            var statSettingsMock = repo.Create <IStatisticsSettings>();
            var saveServiceMock  = repo.Create <IStatisticsSaveService>();
            var timerServiceMock = repo.Create <IStatisticsTimeService>();
            var loggerMock       = repo.Create <ILogger>();

            var client       = new Client();
            var subscription = new Subscription();
            var messageType  = new MessageType();

            var settings = new StatisticsSetting()
            {
                Subscription = subscription
            };

            statSettingsMock
            .Setup(ds => ds.GetSetting(It.IsAny <Subscription>()))
            .Returns <Subscription>(sub => settings);

            statSettingsMock
            .Setup(ds => ds.GetSubscriptionSB())
            .Returns(Guid.NewGuid());

            saveServiceMock
            .Setup(ds => ds.Save(It.IsAny <IEnumerable <StatisticsRecord> >()))
            .Callback <IEnumerable <StatisticsRecord> >(
                srs =>
            {
                Assert.Equal(2, srs.Count());
                var firstSrs = srs.First();
                Assert.Equal(subscription, firstSrs.StatisticsSetting.Subscription);
                Assert.Equal(0, firstSrs.ReceivedCount);
                Assert.Equal(0, firstSrs.SentCount);
                Assert.Equal(0, firstSrs.ErrorsCount);
                Assert.Equal(0, firstSrs.UniqueErrorsCount);
                Assert.Equal(80, firstSrs.SentAvgTime);
            });

            timerServiceMock.Setup(ts => ts.Now).Returns(() => DateTime.Now);

            var service = new DefaultStatisticsService(statSettingsMock.Object, saveServiceMock.Object, timerServiceMock.Object, loggerMock.Object);

            // Act.
            RunSBComponentAfterStart(
                service,
                c =>
            {
                c.NotifyAvgTimeSent(subscription, 100);
                c.NotifyAvgTimeSent(subscription, 60);
            });

            // Assert.
            saveServiceMock.Verify(ds => ds.Save(It.IsAny <IEnumerable <StatisticsRecord> >()), Times.Once);
            loggerMock.Verify(l => l.LogError(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <Message>()), Times.Never);
            repo.Verify();
        }
示例#3
0
        public void TestUpdatingExistedInterval()
        {
            var repo            = new MockRepository(MockBehavior.Default);
            var dataServiceMock = repo.Create <IDataService>();
            var loggerMock      = repo.Create <ILogger>();

            var called  = false;
            var setting = new StatisticsSetting()
            {
                Subscription = new Subscription()
                {
                    MessageType = new MessageType(),
                    Client      = new Client(),
                }
            };

            DataObject[] dObjs = It.IsAny <DataObject[]>();

            dataServiceMock
            .Setup(ds => ds.UpdateObjects(ref dObjs))
            .RefCallback((ref DataObject[] objects) =>
            {
                called = true;

                // Existed record is updated.
                Assert.Equal(24, (objects[0] as StatisticsRecord).SentCount);
                Assert.Equal(16, (objects[0] as StatisticsRecord).ReceivedCount);
            }).IgnoreRefMatching();
            dataServiceMock.Setup(ds => ds.LoadObjects(It.IsAny <LoadingCustomizationStruct>()))
            .Returns(new DataObject[] { new StatisticsRecord()
                                        {
                                            SentCount = 20, ReceivedCount = 10, StatisticsSetting = setting
                                        } });

            var service = new DefaultStatisticsSaveService(dataServiceMock.Object, loggerMock.Object);

            service.SetStatisticsService(GetMockStatisticsService());

            // Act && Assert.
            service.Save(new[]
            {
                // Wrong order for testing sorting records.
                new StatisticsRecord()
                {
                    Since = new DateTime(2016, 01, 01, 00, 01, 00), SentCount = 7, ReceivedCount = 5, StatisticsSetting = setting
                },                                                                                                                                        // the second
                new StatisticsRecord()
                {
                    Since = new DateTime(2016, 01, 01, 00, 00, 00), SentCount = 4, ReceivedCount = 6, StatisticsSetting = setting
                }                                                                                                                                        // the first
            });
            loggerMock.Verify(l => l.LogError(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <Message>()), Times.Never);
            Assert.True(called);
            repo.Verify();
        }
示例#4
0
        //Team Communicator Request
        public IMessage StatRequest(RequestOpenStatisticEx requestStat, string serverName)
        {
            IMessage message = null;

            try
            {
                logger.Info("Request : StatRequest Method :Entry");
                if (string.IsNullOrEmpty(serverName.Trim()))
                {
                    if (StatisticsSetting.GetInstance().statProtocols.Count > 0)
                    {
                        if (StatisticsSetting.GetInstance().statProtocols[0] != null)
                        {
                            if (StatisticsSetting.GetInstance().statProtocols[0].State == ChannelState.Opened || StatisticsSetting.GetInstance().statProtocols[0].State == ChannelState.Opening)
                            {
                                logger.Info("Request : StatRequest Method :" + requestStat.ToString());
                                message = StatisticsSetting.GetInstance().statProtocols[0].Request(requestStat);
                                logger.Info("Request : StatRequest Method :" + message.ToString());
                            }
                        }
                    }
                }
                else
                {
                    if (StatisticsSetting.GetInstance().rptProtocolManager[serverName] != null)
                    {
                        if (StatisticsSetting.GetInstance().rptProtocolManager[serverName].State == ChannelState.Opened || StatisticsSetting.GetInstance().rptProtocolManager[serverName].State == ChannelState.Opening)
                        {
                            logger.Info("Request : StatRequest Method :" + requestStat.ToString());
                            message = StatisticsSetting.GetInstance().rptProtocolManager[serverName].Request(requestStat);
                            logger.Info("Request : StatRequest Method :" + message.ToString());
                        }
                    }
                }
            }

            catch (ProtocolException Protocolexception)
            {
                logger.Error("Request : StatRequest Method : " + Protocolexception.Message);
            }
            catch (Exception GeneralException)
            {
                logger.Error("Request : StatRequest Method : " + GeneralException.Message);
            }
            finally
            {
                logger.Debug("Request : StatRequest Method : Exit");
                GC.SuppressFinalize(message);
                GC.Collect();
            }
            return(message);
        }
示例#5
0
 /// <summary>
 /// Creates new statistics setting and returns it.
 /// </summary>
 /// <param name="subscription">Subscription for statistics setting.</param>
 /// <returns>New statistics setting.</returns>
 public StatisticsSetting CreateSetting(Subscription subscription)
 {
     if (subscription == null)
     {
         var statSetting = new StatisticsSetting();
         return(_statSettings[new Guid(statSetting.__PrimaryKey.ToString())] = statSetting);
     }
     else
     {
         var subscriptionId = new Guid(subscription.__PrimaryKey.ToString());
         return(_statSettings[subscriptionId] = new StatisticsSetting()
         {
             Subscription = subscription,
         });
     }
 }
        /// <summary>
        /// Gets the color.
        /// </summary>
        /// <param name="statName">Name of the stat.</param>
        /// <param name="thresholdType">Type of the threshold.</param>
        /// <returns></returns>
        Color GetColor(string refid, int thresholdType)
        {
            Color result = new Color();

            try
            {
                logger.Debug("ThresholdSettings : GetColor Method : Entry");
                if (StatisticsSetting.GetInstance().ThresholdColors.ContainsKey(refid))
                {
                    List <Color> colorCollection = (List <Color>)StatisticsSetting.GetInstance().ThresholdColors[refid];
                    try
                    {
                        result = colorCollection[thresholdType];
                    }
                    catch (Exception colorException)
                    {
                        result = Color.Black;
                        logger.Error("ThresholdSettings : GetColor Method : " + colorException.Message);
                    }
                }
                else
                {
                    result = Color.Black;
                }
            }
            catch (Exception generalException)
            {
                logger.Error("ThresholdSettings : GetColor Method : " + generalException.Message);
            }
            finally
            {
                logger.Debug("ThresholdSettings : GetColor Method : Exit");
                GC.Collect();
            }
            return(result);
        }
        /// <summary>
        /// Called when [next].
        /// </summary>
        /// <param name="value">The value.</param>
        public void OnNext(IStatisticsCollection value)
        {
            Request       statreq = new Request();
            List <string> tempThresholdValues;
            List <Color>  tempThresholdColors;

            try
            {
                logger.Debug("AgentStatisticsSubscriber : OnNext Method : Entry");
                if (value != null)
                {
                    if (value.AgentStatistics != null && value.AgentStatistics.Count != 0)
                    {
                        try
                        {
                            foreach (IAgentStatistics agentstat in value.AgentStatistics)
                            {
                                string[] configuredstat = value.StatisticsCommon.AgentStatistics.Split(',');
                                {
                                    foreach (string configstat in configuredstat)
                                    {
                                        if (configstat == agentstat.TempStatName)
                                        {
                                            string statName   = agentstat.StatisticsName.ToString();
                                            string filter     = agentstat.FilterName.ToString();
                                            string serverName = agentstat.ServerName.ToString();
                                            string format     = agentstat.StatisticsFormat.ToString();

                                            logger.Info("AgentStatisticsSubscriber : OnNext Method : Request : ReferenceId - " + agentstat.ReferenceID);
                                            logger.Info("AgentStatisticsSubscriber : OnNext Method : Request : StatName - " + statName);
                                            logger.Info("AgentStatisticsSubscriber : OnNext Method : Request : ServerName - " + serverName);

                                            IMessage response;
                                            if (!StatisticsSetting.GetInstance().isAdmin)
                                            {
                                                if (agentstat.ReferenceID < StatisticsSetting.GetInstance().BAttributeReferenceId)
                                                {
                                                    logger.Info("AgentStatisticsSubscriber : OnNext Method : Request : AgentEmpId - " + StatisticsSetting.GetInstance().AgentEmpId);
                                                    response = statreq.StatRequest(value.StatisticsCommon.TenantName, StatisticsSetting.GetInstance().AgentEmpId,
                                                                                   StatisticObjectType.Agent, statName, value.StatisticsCommon.NotifySeconds,
                                                                                   filter, value.StatisticsCommon.Insensitivity, agentstat.ReferenceID, serverName);
                                                }
                                                else
                                                {
                                                    //logger.Info("AgentStatisticsSubscriber : OnNext Method : Request : AgentEmpId - " + StatisticsSetting.GetInstance().AgentEmpId);
                                                    response = statreq.StatRequest(value.StatisticsCommon.TenantName, StatisticsSetting.GetInstance().AgentEmpId,
                                                                                   StatisticObjectType.Agent, value.StatisticsCommon.NotifySeconds,
                                                                                   filter, configstat, agentstat.ReferenceID, serverName);
                                                }
                                            }
                                            else
                                            {
                                                if (!StatisticsSetting.GetInstance().RequestIds.Contains(agentstat.ReferenceID))
                                                {
                                                    StatisticsSetting.GetInstance().RequestIds.Add(agentstat.ReferenceID);
                                                }
                                                response = statreq.StatRequest(value.StatisticsCommon.TenantName, StatisticsSetting.GetInstance().IndividualAgent,
                                                                               StatisticObjectType.Agent, statName, value.StatisticsCommon.NotifySeconds,
                                                                               filter, value.StatisticsCommon.Insensitivity, agentstat.ReferenceID, serverName);
                                            }

                                            if (response != null)
                                            {
                                                statVariables = new StatVariables();
                                                switch (response.Id)
                                                {
                                                case EventStatisticOpened.MessageId:
                                                    EventStatisticOpened info;
                                                    info = (EventStatisticOpened)response;
                                                    statVariables.Statfilter  = filter;
                                                    statVariables.StatType    = StatisticObjectType.Agent.ToString();
                                                    statVariables.DisplayName = agentstat.DisplayName;
                                                    statVariables.Tooltip     = agentstat.ToolTipName;
                                                    statVariables.Statformat  = format;
                                                    statVariables.ObjectType  = agentstat.TempStatName;
                                                    statVariables.ObjectID    = StatisticsSetting.GetInstance().AgentEmpId;
                                                    statVariables.ReferenceId = info.ReferenceId.ToString();

                                                    tempThresholdValues = new List <string>();
                                                    tempThresholdValues.Add(agentstat.ThresholdLevelOne);
                                                    tempThresholdValues.Add(agentstat.ThresholdLevelTwo);

                                                    tempThresholdColors = new List <Color>();
                                                    tempThresholdColors.Add(agentstat.StatColor);
                                                    tempThresholdColors.Add(agentstat.ThresholdColorOne);
                                                    tempThresholdColors.Add(agentstat.ThresholdColorTwo);

                                                    StatisticsBase.GetInstance().IsMyStats = true;

                                                    if (!StatisticsSetting.GetInstance().ListRequestIds.Contains(agentstat.ReferenceID))
                                                    {
                                                        StatisticsSetting.GetInstance().ListRequestIds.Add(agentstat.ReferenceID);
                                                    }

                                                    if (!StatisticsSetting.GetInstance().ThresholdValues.ContainsKey(agentstat.ReferenceID.ToString()))
                                                    {
                                                        StatisticsSetting.GetInstance().ThresholdValues.Add(agentstat.ReferenceID.ToString(), tempThresholdValues);
                                                    }

                                                    if (!StatisticsSetting.GetInstance().ThresholdColors.ContainsKey(agentstat.ReferenceID.ToString()))
                                                    {
                                                        StatisticsSetting.GetInstance().ThresholdColors.Add(agentstat.ReferenceID.ToString(), tempThresholdColors);
                                                    }

                                                    if (!StatisticsSetting.GetInstance().DictAllStats.ContainsKey(info.ReferenceId.ToString()))
                                                    {
                                                        StatisticsSetting.GetInstance().DictAllStats.Add(info.ReferenceId.ToString(), agentstat.TempStatName);
                                                    }

                                                    if (!StatisticsSetting.GetInstance().agentStatisticsPluginHolder.ContainsKey(info.ReferenceId))
                                                    {
                                                        StatisticsSetting.GetInstance().agentStatisticsPluginHolder.Add(info.ReferenceId, statVariables);
                                                    }

                                                    StatisticsSetting.GetInstance().FinalAgentPackageID.Add(agentstat.ReferenceID);
                                                    break;

                                                case EventError.MessageId:
                                                    EventError eventError = (EventError)response;
                                                    logger.Error("AgentStatisticsSubscriber : OnNext Method : " + eventError.StringValue);
                                                    break;
                                                }
                                                statVariables = null;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        catch (Exception generalException)
                        {
                            logger.Error("AgentStatisticsSubscriber : OnNext Method : " + generalException.Message);
                        }
                        finally
                        {
                            GC.Collect();
                        }
                    }
                }
            }
            catch (Exception GeneralException)
            {
                logger.Error("AgentStatisticsSubscriber : OnNext Method : " + GeneralException.Message);
            }
            finally
            {
                logger.Debug("AgentStatisticsSubscriber : OnNext Method : Exit");
                statreq = null;
            }
        }
        /// <summary>
        /// Gets the color of the agent.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="objectid">The name.</param>
        /// <param name="statDisplayName">Display name of the stat.</param>
        /// <param name="statName">Name of the stat.</param>
        /// <returns></returns>
        public Color ThresholdColor(string value, string objectid, string refid, string statformat)
        {
            Color agentColor = Color.Black;

            try
            {
                logger.Debug("ThresholdSettings : ThresholdColor Method : Entry");
                if (StatisticsSetting.GetInstance().ThresholdValues.ContainsKey(refid))
                {
                    List <string> localValues = (List <string>)StatisticsSetting.GetInstance().ThresholdValues[refid];
                    if (localValues != null)
                    {
                        if (string.Compare(statformat, "t", true) == 0)
                        {
                            DateTime thresholdDate1 = Convert.ToDateTime(localValues[0]);
                            DateTime thresholdDate2 = Convert.ToDateTime(localValues[1]);
                            DateTime realValue      = Convert.ToDateTime(value);

                            if (Convert.ToInt32(realValue.TimeOfDay.TotalSeconds) <= Convert.ToInt32(thresholdDate1.TimeOfDay.TotalSeconds))
                            {
                                agentColor = GetColor(refid, 0);
                                StatisticsSetting.GetInstance().isLevelTwo        = false;
                                StatisticsSetting.GetInstance().isThresholdBreach = false;
                            }
                            else if (Convert.ToInt32(realValue.TimeOfDay.TotalSeconds) > Convert.ToInt32(thresholdDate1.TimeOfDay.TotalSeconds) &&
                                     Convert.ToInt32(realValue.TimeOfDay.TotalSeconds) <= Convert.ToInt32(thresholdDate2.TimeOfDay.TotalSeconds))
                            {
                                agentColor = GetColor(refid, 1);
                                StatisticsSetting.GetInstance().isLevelTwo        = false;
                                StatisticsSetting.GetInstance().isThresholdBreach = true;
                            }
                            else if (Convert.ToInt32(realValue.TimeOfDay.TotalSeconds) > Convert.ToInt32(thresholdDate2.TimeOfDay.TotalSeconds))
                            {
                                agentColor = GetColor(refid, 2);
                                StatisticsSetting.GetInstance().isLevelTwo        = true;
                                StatisticsSetting.GetInstance().isThresholdBreach = true;
                            }
                        }
                        else if (string.Compare(statformat, "d", true) == 0)
                        {
                            int thresValue1 = Convert.ToInt32(localValues[0]);
                            int thresValue2 = Convert.ToInt32(localValues[1]);
                            if (Convert.ToInt32(value) <= thresValue1)
                            {
                                agentColor = GetColor(refid, 0);
                                StatisticsSetting.GetInstance().isLevelTwo        = false;
                                StatisticsSetting.GetInstance().isThresholdBreach = false;
                            }
                            else if (Convert.ToInt32(value) > thresValue1 && Convert.ToInt32(value) <= thresValue2)
                            {
                                agentColor = GetColor(refid, 1);
                                StatisticsSetting.GetInstance().isLevelTwo        = false;
                                StatisticsSetting.GetInstance().isThresholdBreach = true;
                            }
                            else if (Convert.ToInt32(value) > thresValue2)
                            {
                                agentColor = GetColor(refid, 2);
                                StatisticsSetting.GetInstance().isLevelTwo        = true;
                                StatisticsSetting.GetInstance().isThresholdBreach = true;
                            }
                        }
                    }
                }
            }
            catch (Exception generalException)
            {
                logger.Error("ThresholdSettings : ThresholdColor Method : " + generalException.Message);
            }
            finally
            {
                logger.Debug("ThresholdSettings : ThresholdColor Method : Exit");
                GC.Collect();
            }
            return(agentColor);
        }
示例#9
0
        /// <summary>
        /// Stats the request.
        /// </summary>
        /// <param name="TenantName">Name of the tenant.</param>
        /// <param name="ObjectID">The object ID.</param>
        /// <param name="statObjectType">Type of the stat object.</param>
        /// <param name="statTypeName">Name of the stat type.</param>
        /// <param name="Seconds">The seconds.</param>
        /// <param name="filter">The filter.</param>
        /// <param name="insensitivity">The insensitivity.</param>
        /// <param name="refID">The reference ID.</param>
        /// <returns></returns>
        public IMessage StatRequest(string TenantName, string ObjectID, StatisticObjectType statObjectType, string statTypeName,
                                    int Seconds, string filter, int insensitivity, int refID, string serverName)
        {
            IMessage message  = null;
            string   response = string.Empty;

            try
            {
                logger.Debug("Request : StatRequest Method : Entry");
                statObject        = StatisticObject.Create(ObjectID, statObjectType, TenantName);
                statMetric        = StatisticMetric.Create(statTypeName);
                statMetric.Filter = filter;
                notification      = Notification.Create();
                notification.Mode = NotificationMode.Periodical;
                //notification.Mode = NotificationMode.Immediate ;
                notification.Frequency = Seconds;
                insValue.Add("Insens", insensitivity);
                RequestOpenStatistic requestStat;
                requestStat             = RequestOpenStatistic.Create(statObject, statMetric, notification, insValue, refID);
                requestStat.ReferenceId = refID;
                if (string.IsNullOrEmpty(serverName))
                {
                    if (StatisticsSetting.GetInstance().statProtocols.Count > 0)
                    {
                        if (StatisticsSetting.GetInstance().statProtocols[0] != null)
                        {
                            if (StatisticsSetting.GetInstance().statProtocols[0].State == ChannelState.Opened || StatisticsSetting.GetInstance().statProtocols[0].State == ChannelState.Opening)
                            {
                                logger.Info("Request : StatRequest Method :" + requestStat.ToString());
                                message = StatisticsSetting.GetInstance().statProtocols[0].Request(requestStat);
                                logger.Info("Request : StatRequest Method :" + message.ToString());
                            }
                        }
                    }
                }
                else
                {
                    if (StatisticsSetting.GetInstance().rptProtocolManager[serverName] != null)
                    {
                        if (StatisticsSetting.GetInstance().rptProtocolManager[serverName].State == ChannelState.Opened || StatisticsSetting.GetInstance().rptProtocolManager[serverName].State == ChannelState.Opening)
                        {
                            logger.Info("Request : StatRequest Method :" + requestStat.ToString());
                            message = StatisticsSetting.GetInstance().rptProtocolManager[serverName].Request(requestStat);
                            logger.Info("Request : StatRequest Method :" + message.ToString());
                        }
                    }
                }
            }
            catch (ProtocolException Protocolexception)
            {
                logger.Error("Request : StatRequest Method : " + Protocolexception.Message);
            }
            catch (Exception GeneralException)
            {
                logger.Error("Request : StatRequest Method : " + GeneralException.Message);
            }
            finally
            {
                logger.Debug("Request : StatRequest Method : Exit");
                GC.SuppressFinalize(message);
                GC.Collect();
            }
            return(message);
        }
示例#10
0
        /// <summary>
        /// DynamicStats request.
        /// </summary>
        /// <param name="TenantName">Name of the tenant.</param>
        /// <param name="ObjectID">The object ID.</param>
        /// <param name="statObjectType">Type of the stat object.</param>
        /// <param name="statTypeName">Name of the stat type.</param>
        /// <param name="Seconds">The seconds.</param>
        /// <param name="filter">The filter.</param>
        /// <param name="insensitivity">The insensitivity.</param>
        /// <param name="refID">The reference ID.</param>
        /// <returns></returns>
        public IMessage StatRequest(string TenantName, string ObjectID, StatisticObjectType statObjectType,
                                    int Seconds, string filter, string sectionName, int RefId, string serverName)
        {
            IMessage message = null;

            try
            {
                logger.Info("Request : StatRequest Method :Entry");

                var requestStat = RequestOpenStatisticEx.Create();

                requestStat.StatisticObject            = StatisticObject.Create();
                requestStat.StatisticObject.ObjectId   = ObjectID;
                requestStat.StatisticObject.ObjectType = statObjectType;
                requestStat.StatisticObject.TenantName = TenantName;

                requestStat.Notification           = Notification.Create();
                requestStat.Notification.Mode      = NotificationMode.Periodical;
                requestStat.Notification.Frequency = Seconds;

                DnActionMask mainMask = null;
                DnActionMask relMask  = null;

                requestStat.StatisticMetricEx = StatisticMetricEx.Create();

                if (StatisticsSetting.GetInstance().DictStatisticsMetrics.ContainsKey(sectionName))
                {
                    Dictionary <string, string> statMetricDetail = new Dictionary <string, string>();
                    statMetricDetail = StatisticsSetting.GetInstance().DictStatisticsMetrics[sectionName];

                    if (statMetricDetail.Count != 0)
                    {
                        foreach (string key in statMetricDetail.Keys)
                        {
                            if (string.Compare(key, "Category", true) == 0)
                            {
                                if (statMetricDetail[key] != null)
                                {
                                    var values = Enum.GetValues(typeof(StatisticCategory));
                                    foreach (StatisticCategory categoryItem in values)
                                    {
                                        if (string.Compare(categoryItem.ToString(), statMetricDetail[key], true) == 0)
                                        {
                                            requestStat.StatisticMetricEx.Category = categoryItem;
                                        }
                                    }
                                }
                            }
                            else if (string.Compare(key, "MainMask", true) == 0)
                            {
                                mainMask = ActionsMask.CreateDnActionMask();

                                string[] actions = statMetricDetail[key].ToString().Split(',');

                                foreach (string customAction in actions)
                                {
                                    string myAction = string.Empty;
                                    if (customAction.Contains('~'))
                                    {
                                        myAction = customAction.Substring(1, customAction.Length - 1);
                                        var values = Enum.GetValues(typeof(DnActions));
                                        foreach (DnActions action in values)
                                        {
                                            if (string.Compare(action.ToString(), myAction, true) == 0)
                                            {
                                                mainMask.ClearBit(action);
                                            }
                                        }
                                    }
                                    else if (customAction.Contains('*'))
                                    {
                                        var values = Enum.GetValues(typeof(DnActions));
                                        foreach (DnActions action in values)
                                        {
                                            mainMask.SetBit(action);
                                        }
                                    }
                                    else
                                    {
                                        var values = Enum.GetValues(typeof(DnActions));
                                        foreach (DnActions action in values)
                                        {
                                            if (string.Compare(action.ToString(), customAction.Trim().ToString(), true) == 0)
                                            {
                                                mainMask.SetBit(action);
                                            }
                                        }
                                    }
                                }
                            }
                            else if (string.Compare(key, "RelMask", true) == 0)
                            {
                                relMask = ActionsMask.CreateDnActionMask();

                                if (statMetricDetail[key] != null)
                                {
                                    string[] actions = statMetricDetail[key].ToString().Split(',');

                                    foreach (string customAction in actions)
                                    {
                                        string myAction = string.Empty;
                                        if (customAction.Contains('~'))
                                        {
                                            myAction = customAction.Substring(1, customAction.Length - 1);
                                            var values = Enum.GetValues(typeof(DnActions));
                                            foreach (DnActions action in values)
                                            {
                                                if (string.Compare(action.ToString(), myAction, true) == 0)
                                                {
                                                    mainMask.ClearBit(action);
                                                }
                                            }
                                        }
                                        else
                                        {
                                            var values = Enum.GetValues(typeof(DnActions));
                                            foreach (DnActions action in values)
                                            {
                                                if (string.Compare(action.ToString(), customAction.Trim().ToString(), true) == 0)
                                                {
                                                    relMask.SetBit(action);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            else if (string.Compare(key, "Subject", true) == 0)
                            {
                                if (statMetricDetail[key] != null)
                                {
                                    var values = Enum.GetValues(typeof(StatisticSubject));
                                    foreach (StatisticSubject subjectItem in values)
                                    {
                                        if (string.Compare(subjectItem.ToString(), statMetricDetail[key], true) == 0)
                                        {
                                            requestStat.StatisticMetricEx.Subject = subjectItem;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                requestStat.StatisticMetricEx.IntervalType   = StatisticInterval.GrowingWindow;
                requestStat.StatisticMetricEx.IntervalLength = 0;
                requestStat.StatisticMetricEx.MainMask       = mainMask;
                requestStat.StatisticMetricEx.RelativeMask   = relMask;
                requestStat.StatisticMetricEx.Filter         = filter;
                requestStat.ReferenceId = RefId;
                if (string.IsNullOrEmpty(serverName))
                {
                    if (StatisticsSetting.GetInstance().statProtocols.Count > 0)
                    {
                        if (StatisticsSetting.GetInstance().statProtocols[0] != null)
                        {
                            if (StatisticsSetting.GetInstance().statProtocols[0].State == ChannelState.Opened || StatisticsSetting.GetInstance().statProtocols[0].State == ChannelState.Opening)
                            {
                                logger.Info("Request : StatRequest Method :" + requestStat.ToString());
                                message = StatisticsSetting.GetInstance().statProtocols[0].Request(requestStat);
                                logger.Info("Request : StatRequest Method :" + message.ToString());
                            }
                        }
                    }
                }
                else
                {
                    if (StatisticsSetting.GetInstance().rptProtocolManager[serverName] != null)
                    {
                        if (StatisticsSetting.GetInstance().rptProtocolManager[serverName].State == ChannelState.Opened)
                        {
                            logger.Info("Request : StatRequest Method :" + requestStat.ToString());
                            message = StatisticsSetting.GetInstance().rptProtocolManager[serverName].Request(requestStat);
                            logger.Info("Request : StatRequest Method :" + message.ToString());
                        }
                    }
                }
            }
            catch (ProtocolException Protocolexception)
            {
                logger.Error("Request : StatRequest Method : " + Protocolexception.Message);
            }
            catch (Exception GeneralException)
            {
                logger.Error("Request : StatRequest Method : " + GeneralException.Message);
            }
            finally
            {
                logger.Debug("Request : StatRequest Method : Exit");
                GC.SuppressFinalize(message);
                GC.Collect();
            }
            return(message);
        }
示例#11
0
        private bool SaveSetting(Sys_Statistics_Item statistics)
        {
            var statisticsID      = statistics.ID;
            var selectionModuleID = GetSelectionModuleID();

            if (statisticsID == Guid.Empty || selectionModuleID == Guid.Empty)
            {
                return(false);
            }

            var statisticsSettings = new List <StatisticsSetting>();

            try
            {
                var settting = JsonConvert.DeserializeObject <List <StatisticsSetting> >(CurrentStatistics.Columns);
                if (settting != null)
                {
                    statisticsSettings = settting;
                }
            }
            catch (Exception)
            {
                var m = JsonConvert.DeserializeObject <Dictionary <string, string> >(CurrentStatistics.Columns);
                foreach (var key in m.Keys)
                {
                    statisticsSettings.Add(new StatisticsSetting()
                    {
                        ItemName  = key,
                        BindField = m[key],
                    });
                }
            }
            StatisticsModuleSetting model = null;
            StatisticsSetting       item  = null;
            var settings = new List <StatisticsModuleSetting>();

            for (var i = 0; i < this.TableStatistics.ActiveSheet.Rows.Count; i++)
            {
                model = new StatisticsModuleSetting();
                item  = new StatisticsSetting();
                var itemName  = TableStatistics.ActiveSheet.Cells[i, 0].Value;
                var itemType  = TableStatistics.ActiveSheet.Cells[i, 1].Value;
                var sheetName = TableStatistics.ActiveSheet.Cells[i, 2].Value;
                var sheetID   = TableStatistics.ActiveSheet.Cells[i, 2].Tag;
                var cellName  = TableStatistics.ActiveSheet.Cells[i, 3].Value;
                if (itemName == null || itemType == null)
                {
                    continue;
                }

                var itn = Convert.ToString(itemName);
                var it  = Map[Convert.ToString(itemType)];
                var sn  = Convert.ToString(sheetName);
                var si  = new Guid(Convert.ToString(sheetID));
                var cn  = Convert.ToString(cellName);

                model.BindField          = it;
                model.StatisticsItemName = itn;
                model.CellName           = cn;
                model.SheetName          = sn;
                model.SheetID            = si;

                item = statisticsSettings.Find(m => m.BindField == it);
                if (item == null)
                {
                    item = new StatisticsSetting();
                    statisticsSettings.Add(item);
                }

                item.BindField = it;
                item.ItemName  = itn;
                settings.Add(model);
            }

            var map    = JsonConvert.SerializeObject(settings);
            var result = StatisticsHelperClient.UpdateStatisticsMapOnModule(selectionModuleID, map);

            if (string.IsNullOrEmpty(result) == false)
            {
                MessageBox.Show(result, "保存失败", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return(false);
            }

            statistics.Columns = JsonConvert.SerializeObject(statisticsSettings);
            result             = StatisticsHelperClient.ModifyStatistics(statistics);
            if (string.IsNullOrEmpty(result) == false)
            {
                MessageBox.Show(result, "保存失败", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return(false);
            }

            if (NeedSynchronous)
            {
                result = StatisticsHelperClient.SynchronousStatistics(statistics.ID, statisticsSettings);
            }

            result = StatisticsHelperClient.NewStatisticsReference(statistics.ID, selectionModuleID);
            if (string.IsNullOrEmpty(result) == false)
            {
                MessageBox.Show(result, "保存失败", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return(false);
            }

            return(true);
        }
        /// <summary>
        /// Called when [next].
        /// </summary>
        /// <param name="value">The value.</param>
        public void OnNext(IStatisticsCollection value)
        {
            Request       statreq = new Request();
            List <string> tempThresholdValues;
            List <Color>  tempThresholdColors;
            int           tempRefid = StatisticsSetting.GetInstance().ReferenceId + 150;

            try
            {
                logger.Debug("VQStatisticsSubscriber : OnNext Method : Entry");
                if (value != null)
                {
                    if (value.VirtualQueueStatistics != null && value.VirtualQueueStatistics.Count != 0)
                    {
                        try
                        {
                            string[] VQueues = value.StatisticsCommon.VQueueObjects.Split(',');
                            foreach (string vqueue in VQueues)
                            {
                                StatisticsSetting.GetInstance().VQueueListCollections.Add(vqueue);
                            }

                            foreach (IVirtualQueueStatistics vqstat in value.VirtualQueueStatistics)
                            {
                                string[] configuredstat = value.StatisticsCommon.VQueueStatistics.Split(',');
                                {
                                    foreach (string configstat in configuredstat)
                                    {
                                        if (configstat == vqstat.TempStatName)
                                        {
                                            for (int VQIndex = 0; VQIndex < StatisticsSetting.GetInstance().VQueueListCollections.Count; VQIndex++)
                                            {
                                                string   Dilimitor = "_@";
                                                string[] vq_Switch = StatisticsSetting.GetInstance().VQueueListCollections[VQIndex].Split(new[] { Dilimitor }, StringSplitOptions.None);

                                                string statName   = vqstat.StatisticsName.ToString();
                                                string filter     = vqstat.FilterName.ToString();
                                                string serverName = vqstat.ServerName.ToString();
                                                string format     = vqstat.StatisticsFormat.ToString();

                                                //if (string.Compare(vqstat.TempStatName, vq_Switch[2].ToString(), true) == 0)
                                                {
                                                    logger.Info("VQStatisticsSubscriber : OnNext Method : Request : ReferenceId - " + tempRefid);
                                                    logger.Info("VQStatisticsSubscriber : OnNext Method : Request : StatName - " + statName);
                                                    logger.Info("VQStatisticsSubscriber : OnNext Method : Request : VQueueName - " + vq_Switch[0] + "@" + vq_Switch[1]);
                                                    logger.Info("VQStatisticsSubscriber : OnNext Method : Request : serverName - " + serverName);
                                                    IMessage response;
                                                    if (tempRefid < StatisticsSetting.GetInstance().BAttributeReferenceId)
                                                    {
                                                        response = statreq.StatRequest(value.StatisticsCommon.TenantName, vq_Switch[0] + "@" + vq_Switch[1],
                                                                                       StatisticObjectType.Queue, statName, value.StatisticsCommon.NotifySeconds,
                                                                                       filter, value.StatisticsCommon.Insensitivity, tempRefid, serverName);
                                                    }
                                                    else
                                                    {
                                                        response = statreq.StatRequest(value.StatisticsCommon.TenantName, vq_Switch[0] + "@" + vq_Switch[1],
                                                                                       StatisticObjectType.Queue, value.StatisticsCommon.NotifySeconds,
                                                                                       filter, configstat, tempRefid, serverName);
                                                    }


                                                    logger.Info("VQStatisticsSubscriber : OnNext Method : Request : " + response.ToString());

                                                    if (response != null)
                                                    {
                                                        statVariables = new StatVariables();
                                                        switch (response.Id)
                                                        {
                                                        case EventStatisticOpened.MessageId:
                                                            EventStatisticOpened info;
                                                            info = (EventStatisticOpened)response;
                                                            statVariables.Statfilter = filter;
                                                            statVariables.StatType   = StatisticObjectType.Queue.ToString();
                                                            //statVariables.DisplayName = vqstat.DisplayName;
                                                            statVariables.Tooltip     = vqstat.ToolTipName;
                                                            statVariables.Statformat  = format;
                                                            statVariables.ObjectType  = vqstat.TempStatName;
                                                            statVariables.ReferenceId = info.ReferenceId.ToString();

                                                            string[] tempQueueName = StatisticsSetting.GetInstance().VQueueListCollections[VQIndex].Split(new[] { Dilimitor }, StringSplitOptions.None);
                                                            statVariables.DisplayName = vqstat.DisplayName;
                                                            if (StatisticsBase.GetInstance().QueueDisplayName == StatisticsEnum.ACDDisplayName.Queue.ToString() || StatisticsBase.GetInstance().QueueDisplayName == StatisticsEnum.ACDDisplayName.RoutingPoint.ToString())
                                                            {
                                                                statVariables.ObjectID = tempQueueName[0].ToString();
                                                                statVariables.CCStat   = vqstat.DisplayName + " " + tempQueueName[0].ToString();
                                                            }
                                                            else if (StatisticsBase.GetInstance().QueueDisplayName == StatisticsEnum.ACDDisplayName.Skill.ToString())
                                                            {
                                                                statVariables.ObjectID = tempQueueName[1].ToString();
                                                                statVariables.CCStat   = vqstat.DisplayName + " " + tempQueueName[1].ToString();
                                                            }
                                                            else
                                                            {
                                                                statVariables.ObjectID = tempQueueName[0].ToString();
                                                                statVariables.CCStat   = vqstat.DisplayName + " " + tempQueueName[0].ToString();
                                                            }

                                                            tempThresholdValues = new List <string>();
                                                            tempThresholdValues.Add(vqstat.ThresholdLevelOne);
                                                            tempThresholdValues.Add(vqstat.ThresholdLevelTwo);

                                                            tempThresholdColors = new List <Color>();
                                                            tempThresholdColors.Add(vqstat.StatColor);
                                                            tempThresholdColors.Add(vqstat.ThresholdColorOne);
                                                            tempThresholdColors.Add(vqstat.ThresholdColorTwo);

                                                            StatisticsBase.GetInstance().IsCCStats = true;

                                                            if (!StatisticsSetting.GetInstance().ThresholdValues.ContainsKey(info.ReferenceId.ToString()))
                                                            {
                                                                StatisticsSetting.GetInstance().ThresholdValues.Add(info.ReferenceId.ToString(), tempThresholdValues);
                                                            }

                                                            if (!StatisticsSetting.GetInstance().ThresholdColors.ContainsKey(info.ReferenceId.ToString()))
                                                            {
                                                                StatisticsSetting.GetInstance().ThresholdColors.Add(info.ReferenceId.ToString(), tempThresholdColors);
                                                            }

                                                            if (!StatisticsSetting.GetInstance().DictAllStats.ContainsKey(info.ReferenceId.ToString()))
                                                            {
                                                                StatisticsSetting.GetInstance().DictAllStats.Add(info.ReferenceId.ToString(), vqstat.TempStatName);
                                                            }

                                                            if (!StatisticsSetting.GetInstance().VQStatisticsValueHolder.ContainsKey(info.ReferenceId))
                                                            {
                                                                StatisticsSetting.GetInstance().VQStatisticsValueHolder.Add(info.ReferenceId, statVariables);
                                                            }

                                                            StatisticsSetting.GetInstance().FinalVQPackageID.Add(info.ReferenceId);
                                                            break;

                                                        case EventError.MessageId:
                                                            EventError eventError = (EventError)response;
                                                            logger.Error("VQStatisticsSubscriber : OnNext Method: " + eventError.StringValue);
                                                            break;
                                                        }
                                                        statVariables = null;
                                                    }
                                                    tempRefid++;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        catch (Exception generalException)
                        {
                            logger.Error("VQStatisticsSubscriber : OnNext Method : " + generalException.Message);
                        }
                        finally
                        {
                            GC.Collect();
                        }
                    }
                }
            }
            catch (Exception GeneralException)
            {
                logger.Error("VQStatisticsSubscriber : OnNext Method : " + GeneralException.Message);
            }
            finally
            {
                logger.Debug("VQStatisticsSubscriber : OnNext Method : Exit");
                statreq = null;
            }
        }
        public void TestPartCompression()
        {
            foreach (var dataService in DataServices)
            {
                // Arrange.
                var statSetting        = new StatisticsSetting();
                var compressionSetting = new StatisticsCompressionSetting()
                {
                    StatisticsSetting  = statSetting,
                    CompressTo         = StatisticsInterval.Hour,
                    StatisticsAgeCount = 1,
                    StatisticsAgeUnits = TimeUnit.Minute,
                    NextCompressTime   = DateTime.Now,
                };
                var dataObjects = new DataObject[100];
                var date        = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour - 1, 0, 0, 0);
                for (int i = 0; i < 100; i++)
                {
                    dataObjects[i] = new StatisticsRecord()
                    {
                        Since = date.AddMinutes(i),
                        To    = date.AddMinutes(i + 1),
                        StatisticsInterval = StatisticsInterval.OneMinute,
                        SentCount          = 1,
                        StatisticsSetting  = statSetting,
                    };
                }

                var counter         = 0;
                var mockTimeService = new Mock <IStatisticsTimeService>();
                mockTimeService
                .Setup(ts => ts.Now)
                .Callback(() =>
                {
                    counter++;
                    if (counter == 5)
                    {
                        throw new Exception("As if something went wrong.");
                    }
                }).Returns(DateTime.Now);

                dataService.UpdateObject(statSetting);
                dataService.UpdateObject(compressionSetting);
                dataService.UpdateObjects(ref dataObjects);

                var component = new DefaultStatisticsCompressorService(
                    dataService,
                    mockTimeService.Object,
                    GetMockLogger(),
                    GetMockStatisticsService())
                {
                    CompressionPeriod           = 1000,
                    MaxRecordsForOneCompression = 50,
                };

                // Act.
                Act(component);

                // Assert.
                var statRecords = dataService.Query <StatisticsRecord>(StatisticsRecord.Views.CompressView)
                                  .OrderBy(r => r.Since)
                                  .ToArray();
                var compressedRecord   = statRecords.First();
                var unCompressedRecord = statRecords.Skip(1).First();

                Assert.Equal(41, statRecords.Count());
                Assert.Equal(60, compressedRecord.SentCount);
                Assert.Equal(StatisticsInterval.Hour, compressedRecord.StatisticsInterval);
                Assert.Equal(StatisticsInterval.OneMinute, unCompressedRecord.StatisticsInterval);
            }
        }
        /// <summary>
        /// Databases the connection.
        /// </summary>
        public void DBConnection()
        {
            try
            {
                if (string.Compare(StatisticsSetting.GetInstance().DBType, StatisticsEnum.DBType.SQLServer.ToString(), true) == 0)
                {
                    logger.Info("DBSubscriber : DBConnection :  Establishing connection with the Database");

                    #region SQL Connection

                    StatisticsSetting.GetInstance().sqlConnection.ConnectionString = "Data Source=" + StatisticsSetting.GetInstance().DBDataSource + ";Initial Catalog=" + StatisticsSetting.GetInstance().DBName + ";Persist Security Info=True;User ID=" + StatisticsSetting.GetInstance().DBUserName + ";Password="******"DBSubscriber : DBConnection :  Establishing connection with the Database");

                    #region SQLite Connection

                    StatisticsSetting.GetInstance().sqliteCon.ConnectionString = "Data Source=" + StatisticsSetting.GetInstance().DBDataSource;
                    StatisticsSetting.GetInstance().sqliteCon.Open();

                    StatisticsSetting.GetInstance().isDBConnectionOpened = true;

                    #endregion
                }
                else if (string.Compare(StatisticsSetting.GetInstance().DBType, StatisticsEnum.DBType.ORACLE.ToString(), true) == 0)
                {
                    logger.Info("DBSubscriber : DBConnection :  Establishing connection with the Database");

                    #region ORACLE Connection

                    if (StatisticsSetting.GetInstance().DBSID == "" || StatisticsSetting.GetInstance().DBSID == null)
                    {
                        StatisticsSetting.GetInstance().DBDataSource = "(Description=(Address_list=(Address=(Protocol=TCP)(HOST=" + StatisticsSetting.GetInstance().DBHost + ")(PORT=" + StatisticsSetting.GetInstance().DBPort + ")))(CONNECT_DATA=(SERVICE_NAME=" + StatisticsSetting.GetInstance().DBSName + ")));User Id = " + StatisticsSetting.GetInstance().DBUserName + ";Password="******";";
                    }
                    else
                    {
                        StatisticsSetting.GetInstance().DBDataSource = "(Description=(Address_list=(Address=(Protocol=TCP)(HOST=" + StatisticsSetting.GetInstance().DBHost + ")(PORT=" + StatisticsSetting.GetInstance().DBPort + ")))(CONNECT_DATA=(SID=" + StatisticsSetting.GetInstance().DBSID + ")));User Id = " + StatisticsSetting.GetInstance().DBUserName + ";Password="******";";
                    }

                    StatisticsSetting.GetInstance().oracleConn.ConnectionString = "Data Source=" + StatisticsSetting.GetInstance().DBDataSource;
                    StatisticsSetting.GetInstance().oracleConn.Open();

                    StatisticsSetting.GetInstance().isDBConnectionOpened = true;

                    #endregion
                }
            }
            catch (SQLiteException sqliteException)
            {
                logger.Error("DBSubscriber : DBConnection : " + (sqliteException.InnerException == null ? sqliteException.Message : sqliteException.InnerException.Message));
                statBase.DisplayDBError(sqliteException.InnerException == null ? sqliteException.Message : sqliteException.InnerException.Message);
                DBTimer.Start();
            }
            catch (SqlException sqlException)
            {
                logger.Error("DBSubscriber : DBConnection : " + (sqlException.InnerException == null ? sqlException.Message : sqlException.InnerException.Message));
                statBase.DisplayDBError(sqlException.InnerException == null ? sqlException.Message : sqlException.InnerException.Message);
                DBTimer.Start();
            }
            catch (OracleException oracleException)
            {
                logger.Error("DBSubscriber : DBConnection : " + (oracleException.InnerException == null ? oracleException.Message : oracleException.InnerException.Message));
                statBase.DisplayDBError(oracleException.InnerException == null ? oracleException.Message : oracleException.InnerException.Message);
                DBTimer.Start();
            }
        }
        /// <summary>
        /// Called when [next].
        /// </summary>
        /// <param name="value">The value.</param>
        public void OnNext(IStatisticsCollection value)
        {
            List <string> tempThresholdValues;
            List <Color>  tempThresholdColors;
            DataTable     dataTable = null;

            try
            {
                foreach (IDBValules dbStat in value.DBValues)
                {
                    DBTimer.Stop();

                    tempStatCollection = value;

                    string connectionString = string.Empty;

                    if (string.Compare(StatisticsSetting.GetInstance().DBType, StatisticsEnum.DBType.SQLServer.ToString(), true) == 0)
                    {
                        #region SQL Server Connection

                        if (!StatisticsSetting.GetInstance().isDBConnectionOpened)
                        {
                            logger.Info("DBSubscriber : OnNext :  Establishing connection with the Database");

                            DBConnection();
                        }
                        if (StatisticsSetting.GetInstance().sqlConnection.State == ConnectionState.Open)
                        {
                            logger.Info("DBSubscriber : OnNext :  Connection to the Database established");

                            dataTable = new DataTable();
                            StatisticsSetting.GetInstance().sqlCommand = new SqlCommand(dbStat.Query, StatisticsSetting.GetInstance().sqlConnection);
                            StatisticsSetting.GetInstance().sqlAdapter = new SqlDataAdapter(StatisticsSetting.GetInstance().sqlCommand);
                            StatisticsSetting.GetInstance().sqlAdapter.Fill(dataTable);
                            StatisticsSetting.GetInstance().sqlCommand.Notification = null;

                            //SqlDependency sqlDependency = new SqlDependency(StatisticsSetting.GetInstance().sqlCommand);
                            //sqlDependency.OnChange += new OnChangeEventHandler(sqlDependency_OnChange);
                        }
                        else
                        {
                            logger.Error("DBSubscriber : OnNext :  Connection to the Database lost, Trying to Re-Establish the connection with the Database");

                            DBConnection();
                        }

                        #endregion
                    }
                    else if (string.Compare(StatisticsSetting.GetInstance().DBType, StatisticsEnum.DBType.SQLite.ToString(), true) == 0)
                    {
                        #region SQLite Connection

                        if (!StatisticsSetting.GetInstance().isDBConnectionOpened)
                        {
                            logger.Info("DBSubscriber : OnNext :  Establishing connection with the Database");

                            DBConnection();
                        }
                        if (StatisticsSetting.GetInstance().sqliteCon.State == ConnectionState.Open)
                        {
                            logger.Info("DBSubscriber : OnNext :  Connection to the Database established");

                            dataTable = new DataTable();
                            StatisticsSetting.GetInstance().sqliteCmd = StatisticsSetting.GetInstance().sqliteCon.CreateCommand();
                            StatisticsSetting.GetInstance().sqliteCmd.CommandText = dbStat.Query;
                            StatisticsSetting.GetInstance().sqliteDA = new SQLiteDataAdapter(StatisticsSetting.GetInstance().sqliteCmd);
                            StatisticsSetting.GetInstance().sqliteDA.Fill(dataTable);
                        }
                        else
                        {
                            logger.Error("DBSubscriber : OnNext :  Connection to the Database lost, Trying to Re-Establish the connection with the Database");

                            DBConnection();
                        }

                        #endregion
                    }
                    else if (string.Compare(StatisticsSetting.GetInstance().DBType, StatisticsEnum.DBType.ORACLE.ToString(), true) == 0)
                    {
                        #region ORACLE Connection

                        if (!StatisticsSetting.GetInstance().isDBConnectionOpened)
                        {
                            logger.Info("DBSubscriber : OnNext :  Establishing connection with the Database");

                            DBConnection();
                        }
                        if (StatisticsSetting.GetInstance().oracleConn.State == ConnectionState.Open)
                        {
                            logger.Info("DBSubscriber : OnNext :  Connection to the Database established");

                            dataTable = new DataTable();
                            StatisticsSetting.GetInstance().oracleCmd = StatisticsSetting.GetInstance().oracleConn.CreateCommand();
                            StatisticsSetting.GetInstance().oracleCmd.CommandText = dbStat.Query;
                            StatisticsSetting.GetInstance().oracleDA = new OracleDataAdapter(StatisticsSetting.GetInstance().oracleCmd);
                            StatisticsSetting.GetInstance().oracleDA.Fill(dataTable);
                        }
                        else
                        {
                            logger.Error("DBSubscriber : OnNext :  Connection to the Database lost, Trying to Re-Establish the connection with the Database");

                            DBConnection();
                        }

                        #endregion
                    }


                    if (dataTable.Rows.Count != 0)
                    {
                        tempThresholdValues = new List <string>();
                        tempThresholdValues.Add(dbStat.Threshold1);
                        tempThresholdValues.Add(dbStat.Threshold2);

                        tempThresholdColors = new List <Color>();
                        tempThresholdColors.Add(dbStat.Color1);
                        tempThresholdColors.Add(dbStat.Color2);
                        tempThresholdColors.Add(dbStat.Color3);

                        if (!StatisticsSetting.GetInstance().ThresholdValues.ContainsKey(dbStat.ReferenceID.ToString()))
                        {
                            StatisticsSetting.GetInstance().ThresholdValues.Add(dbStat.ReferenceID.ToString(), tempThresholdValues);
                        }

                        if (!StatisticsSetting.GetInstance().ThresholdColors.ContainsKey(dbStat.ReferenceID.ToString()))
                        {
                            StatisticsSetting.GetInstance().ThresholdColors.Add(dbStat.ReferenceID.ToString(), tempThresholdColors);
                        }

                        if (!StatisticsSetting.GetInstance().DictAllStats.ContainsKey(dbStat.ReferenceID.ToString()))
                        {
                            StatisticsSetting.GetInstance().DictAllStats.Add(dbStat.ReferenceID.ToString(), dbStat.TempStat);
                        }

                        if (!StatisticsSetting.GetInstance().DictDBStatValuesHolder.ContainsKey(dbStat.ReferenceID.ToString()))
                        {
                            StatisticsSetting.GetInstance().DictDBStatValuesHolder.Add(dbStat.ReferenceID.ToString(), dataTable.Rows[0][0].ToString());
                        }
                        else
                        {
                            StatisticsSetting.GetInstance().DictDBStatValuesHolder[dbStat.ReferenceID.ToString()] = dataTable.Rows[0][0].ToString();
                        }
                    }

                    statBase.NotifyDBStatistics(dbStat.ReferenceID.ToString());
                }

                DBTimer.Start();
            }
            catch (SQLiteException sqliteException)
            {
                logger.Error("DBSubscriber : OnNext : " + (sqliteException.InnerException == null ? sqliteException.Message : sqliteException.InnerException.Message));
                statBase.DisplayDBError(sqliteException.InnerException == null ? sqliteException.Message : sqliteException.InnerException.Message);
                DBConnection();
            }
            catch (SqlException sqlException)
            {
                logger.Error("DBSubscriber : OnNext : " + (sqlException.InnerException == null ? sqlException.Message : sqlException.InnerException.Message));
                statBase.DisplayDBError(sqlException.InnerException == null ? sqlException.Message : sqlException.InnerException.Message);
                DBConnection();
            }
            catch (OracleException oracleException)
            {
                logger.Error("DBSubscriber : OnNext : " + (oracleException.InnerException == null ? oracleException.Message : oracleException.InnerException.Message));
                statBase.DisplayDBError(oracleException.InnerException == null ? oracleException.Message : oracleException.InnerException.Message);
                DBConnection();
            }
            catch (Exception GeneralException)
            {
                logger.Error("DBSubscriber : OnNext : " + (GeneralException.InnerException == null ? GeneralException.Message : GeneralException.InnerException.Message));
            }
            finally
            {
                //sqlConnection.Close();
            }
        }