/// <summary>
        /// Gets the plugin values.
        /// </summary>
        /// <param name="AppName">Name of the app.</param>
        /// <param name="ConfObject">The conf object.</param>
        /// <returns></returns>
        public OutputValues GetPluginValues(string AppName, ConfService ConfObject)
        {
            ReadApplication read   = new ReadApplication();
            OutputValues    output = OutputValues.GetInstance();

            try
            {
                logger.Debug("ConfigConnectionManager : GetPluginValues Method: Entry");
                StatisticsSetting.GetInstance().confObject = ConfObject;

                read.ReadLoggerDetails(AppName);
                output.MessageCode = "200";
                output.Message     = "Config Server Protocol Opened";
            }
            catch (Exception connectionException)
            {
                logger.Error("ConfigConnectionManager :GetPluginValues Method: " + connectionException.Message.ToString());
            }
            finally
            {
                logger.Debug("ConfigConnectionManager : GetPluginValues Method: Exit");
                GC.Collect();
            }

            return(output);
        }
        public void CloseStatServer()
        {
            try
            {
                logger.Info("ReportingServer : CloseStatServer Method - Entry");
                if ((StatisticsSetting.GetInstance().serverNames != null) && (StatisticsSetting.GetInstance().serverNames.Count > 0))
                {
                    foreach (string name in StatisticsSetting.GetInstance().serverNames.Keys)
                    {
                        if (Settings.rptProtocolManager[name] != null)
                        {
                            if (Settings.rptProtocolManager[name].State == ChannelState.Opened)
                            {
                                logger.Info("ReportingServer : CloseStatServer Method Stat server protocol state : " + Settings.rptProtocolManager[name].State.ToString());
                                Settings.rptProtocolManager[name].Close();
                                logger.Info("ReportingServer : CloseStatServer Method Stat server protocol has been closed.");
                            }
                            else
                            {
                                logger.Info("ReportingServer : CloseStatServer Method Stat server protocol is in " + Settings.rptProtocolManager[name].State + " state.");
                            }
                        }
                    }
                }
                Settings.rptProtocolManager = null;
                StatisticsSetting.GetInstance().serverNames = null;
            }

            catch (Exception ex)
            {
                logger.Error("Error occurred while closing the " + "Stat server protocol : " + ex.Message);
            }
            logger.Info("ReportingServer : CloseStatServer Method - Exit");
        }
 /// <summary>
 /// Gets the instance.
 /// </summary>
 /// <returns></returns>
 public static StatisticsSetting GetInstance()
 {
     if (singletonInstance == null)
     {
         singletonInstance = new StatisticsSetting();
         return(singletonInstance);
     }
     else
     {
         return(singletonInstance);
     }
 }
        public void CloseConfigServer()
        {
            try
            {
                if (StatisticsSetting.GetInstance().protocolManager != null && StatisticsSetting.GetInstance().protocolManager[StatisticsSetting.ConfServer].State == ChannelState.Opened)
                {
                    logger.Info("ConfigConnectionManager : Config server protocol state : " + StatisticsSetting.GetInstance().protocolManager[StatisticsSetting.ConfServer].State.ToString());
                    StatisticsSetting.GetInstance().protocolManager[StatisticsSetting.ConfServer].Close();
                    logger.Info("ConfigConnectionManager : Config server protocol has been closed.");
                }
            }

            catch (Exception ex)
            {
                logger.Error("Error occurred while closing the " + "Config server protocol : " + ex.Message);
            }
        }
        //#region Create StatserverConnection

        ///// <summary>
        ///// Creates the connection.
        ///// </summary>
        ///// <param name="host">The host.</param>
        ///// <param name="port">The port.</param>
        ///// <param name="backupHost">The backup host.</param>
        ///// <param name="backupPort">The backup port.</param>
        ///// <param name="addpServerTimeOut">The addp server time out.</param>
        ///// <param name="addpClientTimeOut">The addp client time out.</param>
        ///// <param name="agentIdentifier">The agent identifier.</param>
        ///// <param name="timeOut">The time out.</param>
        ///// <param name="attempts">The attempts.</param>
        ///// <returns></returns>
        //public StatServerProtocol CreateConnection(string host, string port, string backupHost,
        //    string backupPort, int addpServerTimeOut, int addpClientTimeOut, string agentIdentifier,
        //    int timeOut, short attempts)
        //{
        //    StatServerProtocol protocol = null;
        //    try
        //    {
        //        logger.Debug("ReportingServer : CreateConnection Method: Entry");
        //        logger.Info("Reporting Server AddpServerTimeOut : " + addpServerTimeOut);
        //        logger.Info("Reporting Server AddpClientTimeOut : " + addpClientTimeOut);
        //        Settings.statisticsProperties.Uri = new Uri("tcp://" + host + ":" + port);
        //        Settings.statisticsProperties.ClientName = "StatTicker_" + agentIdentifier;

        //        Settings.statisticsProperties.FaultTolerance = FaultToleranceMode.WarmStandby;
        //        Settings.statisticsProperties.WarmStandbyTimeout = timeOut;
        //        Settings.statisticsProperties.WarmStandbyAttempts = attempts;
        //        Settings.statisticsProperties.WarmStandbyUri = new Uri("tcp://" + backupHost +
        //            ":" + backupPort);

        //        Settings.statisticsProperties.UseAddp = true;
        //        Settings.statisticsProperties.AddpServerTimeout = addpServerTimeOut;
        //        Settings.statisticsProperties.AddpClientTimeout = addpClientTimeOut;
        //        Settings.statisticsProperties.AddpTrace = "both";


        //        Settings.rptProtocolManager.Register(Settings.statisticsProperties);

        //        protocol = (StatServerProtocol)Settings.rptProtocolManager[StatisticsSetting.StatServer];

        //        protocol.Received += StatisticsBase.GetInstance().ReportingSuccessMessage;

        //        //Settings.reportingBroker = new EventBrokerService(Settings.rptProtocolManager.Receiver);

        //        //Settings.reportingBroker.Activate();

        //        //Settings.reportingBroker.Register(StatisticsBase.GetInstance().ReportingSuccessMessage);

        //        Settings.rptProtocolManager[StatisticsSetting.StatServer].Open();


        //        if (Settings.rptProtocolManager[StatisticsSetting.StatServer].State == ChannelState.Opened)
        //        {
        //            logger.Trace("ReportingServer : CreateConnection Method : StatServer Connection Opened : " + Settings.statisticsProperties.ClientName);
        //        }
        //        else
        //        {
        //            logger.Warn("ReportingServer : CreateConnection Method: StatServer Connection Closed");
        //        }
        //    }
        //    catch (ProtocolException protocolException)
        //    {
        //        if (protocolException.Message == "Exception occured during channel opening")
        //        {
        //            logger.Error("ReportingServer : CreateConnection Method: " + protocolException.Message);
        //        }
        //    }
        //    catch (Exception generalException)
        //    {
        //        logger.Error("ReportingServer : CreateConnection Method: " + generalException.Message);
        //    }
        //    finally
        //    {
        //        logger.Debug("ReportingServer : CreateConnection Method: Exit");
        //        Settings.statisticsProperties = null;
        //        GC.Collect();
        //    }
        //    return protocol;
        //}

        //public void CloseStatServer()
        //{
        //    try
        //    {
        //        if (Settings.rptProtocolManager[StatisticsSetting.StatServer].State == ChannelState.Opened)
        //        {
        //            logger.Info("ReportingServer : Stat server protocol state : " + Settings.rptProtocolManager[StatisticsSetting.StatServer].State.ToString());
        //            Settings.rptProtocolManager[StatisticsSetting.StatServer].Close();
        //            logger.Info("ReportingServer : Stat server protocol has been closed.");
        //        }
        //        else
        //            logger.Info("ReportingServer : Stat server protocol is in " + Settings.rptProtocolManager[StatisticsSetting.StatServer].State + " state.");
        //    }

        //    catch (Exception ex)
        //    {
        //        logger.Error("Error occurred while closing the " + "Stat server protocol : " + ex.Message);
        //    }
        //}

        //#endregion

        #region Create StatserverConnection

        /// <summary>
        /// Creates the connection.
        /// </summary>
        /// <param name="host">The host.</param>
        /// <param name="port">The port.</param>
        /// <param name="backupHost">The backup host.</param>
        /// <param name="backupPort">The backup port.</param>
        /// <param name="addpServerTimeOut">The addp server time out.</param>
        /// <param name="addpClientTimeOut">The addp client time out.</param>
        /// <param name="agentIdentifier">The agent identifier.</param>
        /// <param name="timeOut">The time out.</param>
        /// <param name="attempts">The attempts.</param>
        /// <returns></returns>
        public void CreateConnection(Uri primaryUri, Uri backupUri, int addpServerTimeOut, int addpClientTimeOut, string agentIdentifier, int timeout, short attempts, string protocolName)
        {
            if (Settings.statProtocols == null)
            {
                Settings.statProtocols = new List <StatServerProtocol>();
            }
            try
            {
                logger.Debug("ReportingServer : CreateConnection Method: Entry");
                logger.Info("Reporting Server : CreateConnection Method AddpServerTimeOut : " + addpServerTimeOut);
                logger.Info("Reporting Server : CreateConnection Method AddpClientTimeOut : " + addpClientTimeOut);
                logger.Info("Reporting Server : CreateConnection Method primaryUri : " + primaryUri);
                logger.Info("Reporting Server : CreateConnection Method StatProtocol Name : " + protocolName);
                Settings.statisticsProperties            = new StatServerConfiguration(protocolName);
                Settings.statisticsProperties.Uri        = primaryUri;
                Settings.statisticsProperties.ClientName = "StatTicker_" + agentIdentifier;

                Settings.statisticsProperties.FaultTolerance      = FaultToleranceMode.WarmStandby;
                Settings.statisticsProperties.WarmStandbyTimeout  = timeout;
                Settings.statisticsProperties.WarmStandbyAttempts = attempts;
                Settings.statisticsProperties.WarmStandbyUri      = backupUri;
                Settings.statisticsProperties.UseAddp             = true;
                Settings.statisticsProperties.AddpServerTimeout   = addpServerTimeOut;
                Settings.statisticsProperties.AddpClientTimeout   = addpClientTimeOut;
                Settings.statisticsProperties.AddpTrace           = "both";


                Settings.rptProtocolManager.Register(Settings.statisticsProperties);
                if (Settings.statProtocols != null)
                {
                    Settings.statProtocols.Add((StatServerProtocol)Settings.rptProtocolManager[protocolName]);
                }
                Settings.rptProtocolManager[protocolName].Received += StatisticsBase.GetInstance().ReportingSuccessMessage;

                //Settings.reportingBroker = new EventBrokerService(Settings.rptProtocolManager.Receiver);

                //Settings.reportingBroker.Activate();

                //Settings.reportingBroker.Register(StatisticsBase.GetInstance().ReportingSuccessMessage);

                Settings.rptProtocolManager[protocolName].Open();


                if (Settings.rptProtocolManager[protocolName].State == ChannelState.Opened)
                {
                    if (StatisticsSetting.GetInstance().serverNames == null)
                    {
                        StatisticsSetting.GetInstance().serverNames = new Dictionary <string, bool>();
                    }
                    if (!StatisticsSetting.GetInstance().serverNames.ContainsKey(protocolName))
                    {
                        StatisticsSetting.GetInstance().serverNames.Add(protocolName, true);
                    }
                    logger.Trace("ReportingServer : CreateConnection Method : StatServer Connection Opened");
                    logger.Info("Reporting Server : CreateConnection Method Stat Server Protocol : " + protocolName + "opened");
                }
                else
                {
                    logger.Warn("ReportingServer : CreateConnection Method: StatServer Connection Closed");
                    logger.Warn("Reporting Server : CreateConnection Method Stat Server Protocol : " + protocolName + "closed");
                }
            }
            catch (ProtocolException protocolException)
            {
                if (protocolException.Message == "Exception occured during channel opening")
                {
                    logger.Error("ReportingServer : CreateConnection Method: " + protocolException.Message);
                }
            }
            catch (Exception generalException)
            {
                logger.Error("ReportingServer : CreateConnection Method: " + generalException.Message);
            }
            finally
            {
                logger.Debug("ReportingServer : CreateConnection Method: Exit");
                Settings.statisticsProperties = null;
                GC.Collect();
            }
        }
        /// <summary>
        /// Checks the user privilege.
        /// </summary>
        /// <param name="username">The username.</param>
        /// <returns></returns>
        public string CheckUserPrivilege(string username, IStatisticsCollection statCollection)
        {
            bool   isAuthenticated = false;
            bool   isAdmin         = false;
            string AdminUsers      = string.Empty;

            try
            {
                logger.Debug("ConfigConnectionManager : CheckUserPrivilege Method: Entry");

                CfgAccessGroupQuery queryAccessGroup = null;
                CfgAccessGroup      accessGroup      = null;
                CfgPersonQuery      queryPerson      = null;
                CfgPerson           Person           = null;

                if (statCollection.ApplicationContainer.UserGroupName != null && !isAdmin)
                {
                    queryAccessGroup      = new CfgAccessGroupQuery();
                    queryAccessGroup.Name = statCollection.ApplicationContainer.UserGroupName;
                    accessGroup           = StatisticsSetting.GetInstance().confObject.RetrieveObject <CfgAccessGroup>(queryAccessGroup);

                    queryPerson          = new CfgPersonQuery();
                    queryPerson.UserName = username;
                    Person = StatisticsSetting.GetInstance().confObject.RetrieveObject <CfgPerson>(queryPerson);

                    if (accessGroup != null)
                    {
                        foreach (CfgID memberID in accessGroup.MemberIDs)
                        {
                            int id = memberID.DBID;
                            if (memberID.Type == CfgObjectType.CFGPerson)
                            {
                                if (id == Person.DBID)
                                {
                                    isAuthenticated = true;
                                    StatisticsSetting.GetInstance().isAdmin = false;
                                }
                            }
                        }
                    }

                    queryPerson = new CfgPersonQuery();
                    ICollection <CfgPerson> Persons = StatisticsSetting.GetInstance().confObject.RetrieveMultipleObjects <CfgPerson>(queryPerson);

                    if (Persons != null)
                    {
                        foreach (CfgPerson agent in Persons)
                        {
                            if (accessGroup != null)
                            {
                                foreach (CfgID memberID in accessGroup.MemberIDs)
                                {
                                    int id = memberID.DBID;
                                    if (memberID.Type == CfgObjectType.CFGPerson)
                                    {
                                        if (id == agent.DBID)
                                        {
                                            StatisticsSetting.GetInstance().LstAgentUNames.Add(agent.UserName);
                                            StatisticsSetting.GetInstance().LstPersons.Add(agent);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                if (statCollection.AdminValues.AdminUsers.Count != 0)
                {
                    if (statCollection.AdminValues.AdminUsers.Contains(username))
                    {
                        isAdmin = true;
                        StatisticsSetting.GetInstance().isAdmin = true;
                    }
                }
            }
            catch (Exception generalException)
            {
                logger.Error("ConfigConnectionManager : CheckUserPrivilege Method: " + generalException.Message.ToString());
            }
            finally
            {
                logger.Debug("ConfigConnectionManager : CheckUserPrevilege Method: Exit");
                GC.Collect();
            }
            return(isAuthenticated.ToString() + "," + isAdmin.ToString());
        }
        /// <summary>
        /// Connects the config server.
        /// </summary>
        /// <param name="ConfigServerHost">The config server host.</param>
        /// <param name="ConfigServerPort">The config server port.</param>
        /// <param name="userName">Name of the user.</param>
        /// <param name="password">The password.</param>
        /// <returns></returns>
        public OutputValues ConnectConfigServer(string ConfigServerHost, string ConfigServerPort,
                                                string userName, string password, string clientName, string logUserName)
        {
            EventBrokerService comEventBrokerService;
            OutputValues       output = OutputValues.GetInstance();
            ReadApplication    read   = new ReadApplication();

            try
            {
                StatisticsSetting.GetInstance().logUserName = logUserName;
                logger.Debug("ConfigConnectionManager : ConnectConfigServer Method: Entry");
                if (StatisticsSetting.GetInstance().protocolManager == null)
                {
                    StatisticsSetting.GetInstance().configurationProperties = new ConfServerConfiguration("config");
                    StatisticsSetting.GetInstance().protocolManager         = new ProtocolManagementService();

                    //Primary Server settings
                    StatisticsSetting.GetInstance().configurationProperties.Uri = new Uri("tcp://" + ConfigServerHost + ":"
                                                                                          + ConfigServerPort);
                    StatisticsSetting.GetInstance().configurationProperties.ClientApplicationType = CfgAppType.CFGAgentDesktop;
                    StatisticsSetting.GetInstance().configurationProperties.ClientName = clientName;
                    StatisticsSetting.GetInstance().configurationProperties.UserName = userName;
                    StatisticsSetting.GetInstance().configurationProperties.UserPassword = password;

                    //Set ADDP
                    StatisticsSetting.GetInstance().configurationProperties.UseAddp = true;
                    StatisticsSetting.GetInstance().configurationProperties.AddpServerTimeout = 30;
                    StatisticsSetting.GetInstance().configurationProperties.AddpClientTimeout = 60;

                    //Open the connection
                    try
                    {
                        StatisticsSetting.GetInstance().protocolManager.Register(StatisticsSetting.GetInstance().configurationProperties);
                    }
                    catch (Exception generalException)
                    {
                        output.MessageCode = "2001";
                        output.Message     = (generalException.InnerException == null ? generalException.Message : generalException.InnerException.Message);
                        logger.Error("ConfigConnectionManager : ConnectConfigServer Method: " + generalException.Message.ToString());
                        return(output);
                    }

                    StatisticsSetting.GetInstance().protocolManager[StatisticsSetting.ConfServer].Open();

                    comEventBrokerService = new EventBrokerService(StatisticsSetting.GetInstance().protocolManager.Receiver);
                    comEventBrokerService.Activate();

                    //comEventBrokerService.Register(OnConfEventError);
                    //comEventBrokerService.Register(OnConfEventObjectsRead);
                    //comEventBrokerService.Register(OnConfEventObjectsSent);

                    //KeyValueCollection filterKey = new KeyValueCollection();
                    //filterKey.Add("switch_dbid", 102);
                    //filterKey.Add("dn_type", (int)CfgDNType.CFGExtension);
                    //RequestReadObjects requestReadObjects = RequestReadObjects.Create((int)CfgObjectType.CFGDN, filterKey);
                    //StatisticsSetting.GetInstance().protocolManager[StatisticsSetting.ConfServer].Send(requestReadObjects);

                    if (StatisticsSetting.GetInstance().confObject == null)
                    {
                        StatisticsSetting.GetInstance().confObject = (ConfService)ConfServiceFactory.CreateConfService(
                            StatisticsSetting.GetInstance().protocolManager[StatisticsSetting.ConfServer] as ConfServerProtocol,
                            comEventBrokerService, true);
                    }

                    //NotificationQuery NQuery=new NotificationQuery();
                    //NQuery.ObjectType=CfgObjectType.CFGPerson;

                    //StatisticsSetting.GetInstance().confObject.Subscribe(NQuery);

                    if (StatisticsSetting.GetInstance().protocolManager[StatisticsSetting.ConfServer].State == ChannelState.Opened)
                    {
                        StatisticsSetting.GetInstance().confProtocol = (ConfServerProtocol)StatisticsSetting.GetInstance().protocolManager[StatisticsSetting.ConfServer];

                        read.ReadLoggerDetails(StatisticsSetting.GetInstance().AppName);
                        output.MessageCode = "2000";
                        output.Message     = "Config Server Protocol Opened";
                        logger.Trace("ConfigConnectionManager : ConnectConfigServer Method: Config Server Protocol Opened");
                    }
                    else
                    {
                        output.MessageCode = "2001";
                        output.Message     = "Config Server Protocol Closed";
                        logger.Warn("ConfigConnectionManager : ConnectConfigServer Method: Config Server Protocol Closed");
                    }
                }
            }
            catch (Exception connectionException)
            {
                logger.Error("ConfigConnectionManager : ConnectConfigServer Method: " + connectionException.Message.ToString());
                output.MessageCode = "2001";
                output.Message     = (connectionException.InnerException == null ? connectionException.Message : connectionException.InnerException.Message);
            }
            finally
            {
                logger.Debug("ConfigConnectionManager : ConnectConfigServer Method: Exit");
                //StatisticsSetting.GetInstance().protocolManager = null;
                GC.Collect();
            }
            return(output);
        }