Exemplo n.º 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);
        }
Exemplo n.º 2
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);
        }
        /// <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);
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
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);
        }
        /// <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;
            }
        }
        /// <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();
            }
        }
Exemplo n.º 10
0
        /// <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();
            }
        }