Пример #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(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);
        }
        public static void RequestTeamCommunicatorStatistics(string businessAttributeName, string dynamicStatName, string[] objectIds, StatisticObjectType statObjectType,
                                                             int seconds, int insensitivity)
        {
            _logger.Info("Request Statistics Entry");
            try
            {
                if (objectIds == null || objectIds.Length <= 0)
                {
                    _logger.Warn("object ids for requesting statistics is null or empty");
                    return;
                }

                System.Collections.Generic.Dictionary <string, string> dictionary = new System.Collections.Generic.Dictionary <string, string>();
                dictionary = GetDynamicStatsConfiguration(businessAttributeName, dynamicStatName);
                if (dictionary == null || dictionary.Count <= 0)
                {
                    _logger.Warn("Dynamic teamcommunicator statistics configuration throws null or empty collection");
                    return;
                }
                string tenantName = string.Empty;
                if (ConfigContainer.Instance().AllKeys.Contains("tenant-name"))
                {
                    tenantName = (string)ConfigContainer.Instance().GetValue("tenant-name");
                }

                int refID = 5000;
                for (int index = 0; index < objectIds.Length; index++)
                {
                    if (string.IsNullOrEmpty(objectIds[index]))
                    {
                        continue;
                    }

                    var requestStat = RequestOpenStatisticEx.Create();

                    requestStat.StatisticObject            = StatisticObject.Create();
                    requestStat.StatisticObject.ObjectId   = objectIds[index];
                    requestStat.StatisticObject.ObjectType = statObjectType;
                    if (!string.IsNullOrEmpty(tenantName))
                    {
                        requestStat.StatisticObject.TenantName = tenantName;
                    }

                    requestStat.Notification           = Notification.Create();
                    requestStat.Notification.Mode      = NotificationMode.Immediate;
                    requestStat.Notification.Frequency = seconds;

                    DnActionMask mainMask = null;
                    DnActionMask relMask  = null;

                    requestStat.StatisticMetricEx = StatisticMetricEx.Create();

                    if (dictionary.ContainsKey("Category"))
                    {
                        var values = Enum.GetValues(typeof(StatisticCategory));
                        foreach (StatisticCategory categoryItem in values)
                        {
                            if (string.Compare(categoryItem.ToString(), dictionary["Category"], true) == 0)
                            {
                                requestStat.StatisticMetricEx.Category = categoryItem;
                            }
                        }
                    }
                    if (dictionary.ContainsKey("MainMask"))
                    {
                        mainMask = ActionsMask.CreateDnActionMask();

                        string[] actions = dictionary["MainMask"].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);
                                    }
                                }
                            }
                        }
                    }

                    if (dictionary.ContainsKey("RelMask"))
                    {
                        relMask = ActionsMask.CreateDnActionMask();

                        string[] actions = dictionary["RelMask"].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);
                                    }
                                }
                            }
                        }
                    }
                    if (dictionary.ContainsKey("Subject"))
                    {
                        if (dictionary["Subject"] != null)
                        {
                            var values = Enum.GetValues(typeof(StatisticSubject));
                            foreach (StatisticSubject subjectItem in values)
                            {
                                if (string.Compare(subjectItem.ToString(), dictionary["Subject"], true) == 0)
                                {
                                    requestStat.StatisticMetricEx.Subject = subjectItem;
                                }
                            }
                        }
                    }
                    if (dictionary.ContainsKey("Filter"))
                    {
                        if (dictionary["Filter"] != null)
                        {
                            requestStat.StatisticMetricEx.Filter = dictionary["Filter"].ToString();
                        }
                        else
                        {
                            requestStat.StatisticMetricEx.Filter = string.Empty;
                        }
                    }

                    requestStat.StatisticMetricEx.IntervalType   = StatisticInterval.GrowingWindow;
                    requestStat.StatisticMetricEx.IntervalLength = 0;
                    requestStat.StatisticMetricEx.MainMask       = mainMask;
                    requestStat.StatisticMetricEx.RelativeMask   = relMask;
                    requestStat.ReferenceId = refID;
                    _logger.Info("Request Team Communicator statistics : " + requestStat.ToString());
                    IMessage response = ((StatServerProtocol)ProtocolManagers.Instance().ProtocolManager[ServerType.Statisticsserver.ToString()]).Request(requestStat);
                    if (response != null)
                    {
                        switch (response.Id)
                        {
                        case EventStatisticOpened.MessageId:
                            EventStatisticOpened info;
                            info = (EventStatisticOpened)response;
                            _logger.Trace("RequestStatistics Method : EventStatisticsOpened : " + info.Name);
                            break;

                        case EventError.MessageId:
                            EventError eventError = (EventError)response;
                            _logger.Trace("RequestStatistics Method : EventError : " + eventError.StringValue);
                            break;
                        }
                    }
                    refID++;
                }
            }
            catch (Exception generalException)
            {
                _logger.Error("Error while requesting statistics : " + ((generalException.InnerException == null) ? generalException.Message : generalException.InnerException.ToString()));
            }
        }