Beispiel #1
0
        public FileWatcher(FrmMain frmMain)
        {
            _frmMain = frmMain;
            
            // list to store all fileWatchers for each upload
            _watcherList = new List<FileWatchers>();

            List<SiteConf.Upload.Object> uploadList = null;

            // checked if orgSite is an Admin
            if (_frmMain._orgSite.HVPAdmin.HasValue)
            {
                if (_frmMain._orgSite.HVPAdmin.Value)
                {
                    // get all the orgsites associated with the admin site
                    List<SiteConf.OrgSite.Object> sites = DataLoader.GetAdminOrgSites(_frmMain._orgSite.ID);

                    // concatenated list of uploads
                    uploadList = new List<SiteConf.Upload.Object>();

                    // get all the uploads for each site
                    foreach (SiteConf.OrgSite.Object site in sites)
                    {
                        List<SiteConf.Upload.Object> uploads = DataLoader.GetUploadList(site.OrgHashCode);

                        uploadList = uploadList.Concat(uploads).ToList();
                    }
                }
            }
            
            // if orgSite is not admin then just get the uploads using the hashcode from it.
            if (uploadList == null)
                uploadList = DataLoader.GetSpreadSheetUploadList(_frmMain._orgSite.OrgHashCode);
            

            foreach (SiteConf.Upload.Object upload in uploadList)
            {
                if (upload.DataSourceName == null || upload.DataSourceName == string.Empty)
                {
                    continue;
                }
                else
                {
                    try
                    {
                        FileWatchers fw = new FileWatchers();
                        fw.FileWatcher = StartWatching(upload.DataSourceName);
                        fw.Upload = upload;

                        _watcherList.Add(fw);
                    }
                    catch
                    {
                        MessageBox.Show("The directory location path for " + upload.Name + " can not be found please check if the path name is correct.",
                        "Spreadsheet directory path error");
                    }
                }
            }
        }
Beispiel #2
0
        public void Watch(string solutionPath, string filter)
        {
            var solutionFolder    = fileSystem.GetDirectoryName(solutionPath);
            var fileSystemWatcher = fileWatcherFactory.Build(new FileSystemWatcherOptions(solutionFolder, filter, ChangeAction, null, ErrorAction, DeletedAction, RenamedAction));

            fileSystemWatcher.EnableRaisingEvents   = true;
            fileSystemWatcher.NotifyFilter          = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.CreationTime | NotifyFilters.FileName | NotifyFilters.DirectoryName;
            fileSystemWatcher.IncludeSubdirectories = true;

            FileWatchers.Add(fileSystemWatcher);
        }
Beispiel #3
0
        public void Watch(string solutionPath, string filter)
        {
            var solutionFolder    = fileSystem.GetDirectoryName(solutionPath);
            var fileSystemWatcher = fileWatcherFactory.Build(solutionFolder, filter, ChangeAction, null,
                                                             ErrorAction);

            fileSystemWatcher.EnableRaisingEvents   = true;
            fileSystemWatcher.NotifyFilter          = NotifyFilters.LastWrite;
            fileSystemWatcher.IncludeSubdirectories = true;

            FileWatchers.Add(fileSystemWatcher);
        }
Beispiel #4
0
 public void Dispose()
 {
     FileWatchers.ToList().ForEach(x => x.Dispose());
 }
Beispiel #5
0
        public void StartWatching(SiteConf.Upload.Object upload)
        {
            // only need to watch if the datasource is a spreadsheet
            if (upload.DataSourceType == DataSourceType.Spreadsheet)
            {
                // try and find an existing watcher
                FileWatchers result = _watcherList.Find(
                    delegate(FileWatchers fw)
                    {
                        return fw.Upload == upload;
                    }
                );

                if (result == null)
                {
                    // start new
                    FileWatchers fw = new FileWatchers();
                    fw.FileWatcher = StartWatching(upload.DataSourceName);
                    fw.Upload = upload;

                    _watcherList.Add(fw);
                }
                else
                {
                    // restart existing
                    result.Upload = upload;
                    result.FileWatcher.Dispose(); // releases any held resources from previous source
                    result.FileWatcher.Path = upload.DataSourceName; // update if user has made changes
                    result.FileWatcher.EnableRaisingEvents = true;
                }
            }
        }