/// <summary>
        /// To validate the DirectorySettings
        /// </summary>
        /// <param name="downloadSettings">Download settings</param>
        /// <param name="ftpDirSettings">Directory settings</param>
        /// <returns></returns>
        private static bool HasInvalidFtpSettings(DownloadServiceSettings downloadSettings, FtpDirectorySettings ftpDirSettings)
        {
            Logger.Log.Info("Inside Method");
            foreach (FtpSetting ftpSetting in downloadSettings.FtpSettings)
            {
                if (string.IsNullOrEmpty(ftpSetting.FtpDirectorySetting))
                {
                    Logger.Log.Error("Ftp directory setting name missing in some download settings");
                    return(true);
                }

                if (ftpDirSettings.DirectorySettings[ftpSetting.FtpDirectorySetting] == null)
                {
                    Logger.Log.ErrorFormat("Ftp directory setting missing, the direcotry setting name is {0}", ftpSetting.FtpDirectorySetting);
                    return(true);
                }

                if (string.IsNullOrEmpty(ftpSetting.LoggerName))
                {
                    Logger.Log.Error("Logger name missing in some ftp configuration settings");
                    return(true);
                }
            }

            int countDirectoryMapping = downloadSettings.FtpSettings.OfType <FtpSetting>().Count();
            int distinctCount         = downloadSettings.FtpSettings.OfType <FtpSetting>().Select(eachsetting => eachsetting.FtpDirectorySetting).Distinct().Count();

            if (countDirectoryMapping != distinctCount)
            {
                Logger.Log.Error("The VXML server mapping to the FTP servers is repeated... ");
                return(true);
            }

            return(false);
        }
Exemplo n.º 2
0
        /// <summary>
        /// To span the threads to start the data download process based on the configuration settings
        /// </summary>
        private void StartSimultaneousDownloadProcess()
        {
            Logger.Log.Info("Inside Method");
            int threadCount = 0;
            DownloadServiceSettings downloadSettings = ConfigurationManager.GetSection("DownloadServiceSettings") as DownloadServiceSettings;
            FtpDirectorySettings    ftpDirSettings   = ConfigurationManager.GetSection("FtpDirectorySettings") as FtpDirectorySettings;

            foreach (FtpSetting setting in downloadSettings.FtpSettings)
            {
                if (setting.IsActive)
                {
                    DataDownload             downloadUtility = new DataDownload();
                    ParameterizedThreadStart paramThread     = new ParameterizedThreadStart(downloadUtility.StartDownload);
                    Thread threadInstance = new Thread(paramThread);
                    threadInstance.Name = string.Format("{0}-{1}", setting.Name, setting.VxmlServer);
                    threadInstance.Start(new object[] { setting, ftpDirSettings.DirectorySettings[setting.FtpDirectorySetting] });
                    threadCount++;
                    Interlocked.Increment(ref StaticInfo.ThreadCount);
                }
            }
            Logger.Log.InfoFormat("Total No of Thread Started : {0}", threadCount);
        }
 /// <summary>
 /// To the check the active download settings
 /// </summary>
 /// <param name="downloadSettings"></param>
 /// <returns></returns>
 private static bool HasActiveFtpSetttings(DownloadServiceSettings downloadSettings)
 {
     Logger.Log.Info("Inside Method");
     return(downloadSettings.FtpSettings.OfType <FtpSetting>().Where(F => F.IsActive).Count() > 0);
 }
        /// <summary>
        /// To validate the configuration settings (i.e DownloadServiceSettings, FtpDirectorySettings, etc...)
        /// </summary>
        /// <returns>returns true if it is valid configuration settings; otherwise false</returns>
        public static bool ValidateConfiguration()
        {
            try
            {
                Logger.Log.Info("Inside Method");
                DownloadServiceSettings downloadSettings     = ConfigurationManager.GetSection("DownloadServiceSettings") as DownloadServiceSettings;
                FtpDirectorySettings    ftpDirectorySettings = ConfigurationManager.GetSection("FtpDirectorySettings") as FtpDirectorySettings;


                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

                ConfigurationSection section = config.GetSection("FtpDirectorySettings");

                if (section != null && !section.SectionInformation.IsProtected)
                {
                    section.SectionInformation.ProtectSection("DataProtectionConfigurationProvider");
                    config.Save();
                }

                if (downloadSettings == null)
                {
                    Logger.Log.Error("Download service setting congfiguration is missing");
                    return(false);
                }

                if (ftpDirectorySettings == null)
                {
                    Logger.Log.Error("Ftp directory setting congfiguration is missing");
                    return(false);
                }

                if (downloadSettings.FtpSettings.Count == 0)
                {
                    Logger.Log.Error("There is no ftp setting congfigured");
                    return(false);
                }

                if (ftpDirectorySettings.DirectorySettings.Count == 0)
                {
                    Logger.Log.Error("There is no ftp directory setting congfigured");
                    return(false);
                }

                if (!HasActiveFtpSetttings(downloadSettings))
                {
                    Logger.Log.Error("There is no active ftp setting configured");
                    return(false);
                }

                if (HasInvalidFtpSettings(downloadSettings, ftpDirectorySettings))
                {
                    Logger.Log.Error("Some invalid ftp settings configured");
                    return(false);
                }

                if (HasInvalidFtpDirectorySettings(ftpDirectorySettings))
                {
                    Logger.Log.Error("Some invalid ftp directory settings configured");
                    return(false);
                }

                if (HasDublicateFtpPath(ftpDirectorySettings))
                {
                    Logger.Log.Error("Duplicate ftp path appears in the ftp directory settings");
                    return(false);
                }

                return(true);
            }
            catch (Exception ex)
            {
                Logger.Log.Error("Error Occured While Validating Configuration Settings", ex);
                return(false);
            }
        }