Exemplo n.º 1
0
        public static SreFileSystemWatcher Get(this Dictionary <int, SreFileSystemWatcher> sreFileSystemWatchers, int dataSourceId)
        {
            SreFileSystemWatcher sreFileSystemWatcher = null;

            sreFileSystemWatchers.TryGetValue(dataSourceId, out sreFileSystemWatcher);
            return(sreFileSystemWatcher);
        }
Exemplo n.º 2
0
        public void Start()
        {
            SqlWatchers = new Dictionary <int, SqlWatcher>();
            try
            {
                if (!Directory.Exists(IdpeConfigurationSection.CurrentConfig.LocalFileWatcher.DirectoryPull))
                {
                    Directory.CreateDirectory(IdpeConfigurationSection.CurrentConfig.LocalFileWatcher.DirectoryPull);
                }
                WindowsUtility.SetFolderPermission(IdpeConfigurationSection.CurrentConfig.LocalFileWatcher.DirectoryPull);
            }
            catch (Exception ex)
            {
                Trace.TraceInformation(ex.Message);
                Trace.Flush();
            }

            DateTime stTm = DateTime.Now;

            if (EyediaCoreConfigurationSection.CurrentConfig.TempDirectory.Length > Constants.MaxTempFolderPath)
            {
                throw new ConfigurationErrorsException(string.Format("'{0}' can not have more than '{1}' length", EyediaCoreConfigurationSection.CurrentConfig.TempDirectory, Constants.MaxTempFolderPath));
            }

            _Manager = new Manager();
            List <int> allDataSourceIds = _Manager.GetAllDataSourceIds(false);

            foreach (int dataSourceId in allDataSourceIds)
            {
                string dir = Path.Combine(IdpeConfigurationSection.CurrentConfig.LocalFileWatcher.DirectoryPull, dataSourceId.ToString());
                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }
            }

            string sysDir = Path.Combine(IdpeConfigurationSection.CurrentConfig.LocalFileWatcher.DirectoryPull, "100");

            if (!Directory.Exists(sysDir))
            {
                Directory.CreateDirectory(sysDir);
            }

            StartLocalFileSystemWatcher();
            List <IdpeDataSource> dataSources = _Manager.GetDataSources();

            foreach (IdpeDataSource dataSource in dataSources)
            {
                List <IdpeKey> keys = Cache.Instance.Bag[dataSource.Id + ".keys"] as List <IdpeKey>;
                if (keys == null)
                {
                    keys = DataSource.LoadKeys(dataSource.Id);
                }

                if ((dataSource.DataFeederType != null) &&
                    ((DataFeederTypes)dataSource.DataFeederType == DataFeederTypes.PullFtp))
                {
                    #region Initializing FtpPullers
                    string ftpRemoteLocation         = FindSREKeyUsingType(keys, IdpeKeyTypes.FtpRemoteLocation);
                    string ftpUserName               = FindSREKeyUsingType(keys, IdpeKeyTypes.FtpUserName);
                    string ftpPassword               = FindSREKeyUsingType(keys, IdpeKeyTypes.FtpPassword);
                    string strinterval               = FindSREKeyUsingType(keys, IdpeKeyTypes.FtpWatchInterval);
                    int    ftpWatchIntervalInMinutes = 0;
                    int.TryParse(strinterval, out ftpWatchIntervalInMinutes);
                    if (ftpWatchIntervalInMinutes == 0)
                    {
                        ftpWatchIntervalInMinutes = 1;
                    }

                    string ftpLocalLocation = Path.Combine(IdpeConfigurationSection.CurrentConfig.LocalFileWatcher.DirectoryPull, dataSource.Id.ToString());
                    string appOutputFolder  = Path.Combine(IdpeConfigurationSection.CurrentConfig.LocalFileWatcher.DirectoryOutput, dataSource.Id.ToString(), DateTime.Now.ToString("yyyyMMdd"));


                    Dictionary <string, object> datasourceParameters = new Dictionary <string, object>();
                    lock (_lock)
                    {
                        datasourceParameters.Add("DataSourceId", dataSource.Id);
                        datasourceParameters.Add("OutputFolder", appOutputFolder);
                        datasourceParameters.Add("ProcessingBy", dataSource.ProcessingBy);
                    }

                    FtpFileSystemWatcher ftpWatcher =
                        new FtpFileSystemWatcher(datasourceParameters, ftpRemoteLocation, ftpLocalLocation,
                                                 ftpWatchIntervalInMinutes, ftpUserName, ftpPassword, false, true);

                    ExtensionMethods.TraceInformation("Pullers - Initialized 'PullFtp'; '{0}' [ftpRemoteLocation = {1}, ftpLocalLocation = {2}, ftpUserName = {3},ftpPassword = {4}, interval = {5}]",
                                                      dataSource.Name, ftpRemoteLocation, ftpLocalLocation, ftpUserName, ftpPassword, ftpWatchIntervalInMinutes);
                    Registry.Instance.FtpWatchers.Add(ftpWatcher);

                    #endregion Initializing FtpPullers
                }
                else if ((dataSource.DataFeederType != null) &&
                         ((DataFeederTypes)dataSource.DataFeederType == DataFeederTypes.PullLocalFileSystem))
                {
                    if (IsLocalFileSystemFoldersOverriden(keys))
                    {
                        SreFileSystemWatcher sreFileSystemWatcher      = new SreFileSystemWatcher(dataSource.Id, keys);
                        Watchers.FileSystemWatcherEventHandler handler = new Watchers.FileSystemWatcherEventHandler(FileDownloaded);
                        sreFileSystemWatcher.FileDownloaded -= handler;
                        sreFileSystemWatcher.FileDownloaded += handler;
                        sreFileSystemWatcher.StartWatching();
                        Registry.Instance.DataSourceFileWatcher.Add(dataSource.Id, sreFileSystemWatcher);
                    }

                    //we dont have to do anything if it is generic
                }
                else if ((dataSource.DataFeederType != null) &&
                         ((DataFeederTypes)dataSource.DataFeederType == DataFeederTypes.PullSql))
                {
                    #region Initializing SQL Pullers

                    SqlWatcher sqlWatcher = new SqlWatcher(dataSource);
                    sqlWatcher.StartDownloading();
                    SqlWatchers.Add(dataSource.Id, sqlWatcher);

                    #endregion Initializing SQL Pullers
                }

                Trace.Flush();
            }

            ExtensionMethods.TraceInformation("Pullers - Initialization finished.{0}", DateTime.Now - stTm);
        }