示例#1
0
        private static void Main(string[] args)
        {
            SafetyCheck(args);

            var fileLocation = args[0];
            var filePattern  = args[1];

            WatchedFiles.Files = new ConcurrentDictionary <string, (long LineCount, DateTime LastModified)>();

            _actorSystem = ActorSystem.Create("FileWatcherActorSystem");
            var dbCoordinatorPool =
                _actorSystem.ActorOf(
                    Props.Create(() => new DatabaseCoordinatorActor())
                    .WithRouter(new RoundRobinPool(5, new DefaultResizer(1, 10))),
                    fileLocation.ToActorName() + "dbPool");

            NonBlockingConsole.WriteLine(
                $"FileWatcher is watching {fileLocation} for changes, using the following pattern: {filePattern}" +
                $"{_pressEsc}");

            var fileWatcherActor = _actorSystem.ActorOf <FolderWatcherActor>();
            var watchFiles       = new WatchFolder(fileLocation, filePattern, dbCoordinatorPool);

            fileWatcherActor.Tell(watchFiles);

            while (Console.ReadKey().Key != ConsoleKey.Escape)
            {
                Console.ReadKey();
            }

            QuitProgram(false);
        }
        public FolderProperties(WatchFolder folder = null)
        {
            InitializeComponent();
            Title = folder == null ? "New Folder" : "Edit Folder";

            if (folder == null)
                NewFolder = new WatchFolder();
            else
                NewFolder = (WatchFolder) folder.Clone();

            DataContext = NewFolder;
        }
示例#3
0
 /// <summary>
 /// Inserts a library Watch Folder entry into the database from the fields of a WatchFolder model object
 /// </summary>
 /// <param name="watchFolder">The given WatchFolder object</param>
 /// <returns>DbOperationResult - Showing success or fail, with messages and stats</returns>
 public async Task <DbOperationResult> Insert(WatchFolder watchFolder)
 {
     try
     {
         return(await Insert_R(watchFolder));
     }
     catch
     {
         ThreadHelper.SafeSleep(50);
         return(await Insert_R(watchFolder));
     }
 }
        protected override void OnStart(string[] args)
        {
            try
            {
                string assemblyVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
                Log.Info("Starting version " + assemblyVersion);

                watchFolder             = new WatchFolder();
                watchFolder.KeepRunning = true;
                watchFolder.Start();
            }
            catch (Exception ex)
            {
                Log.Error("Exception starting service ", ex);
            }
        }
示例#5
0
        private void StartWatching(WatchFolder watchMessage)
        {
            _fileCoordinator = Context.ActorOf(Props.Create(() => new FileCoordinatorActor(watchMessage.DbCoordinator))
                                               .WithRouter(new RoundRobinPool(5, new DefaultResizer(1, 10))),
                                               watchMessage.FileLocation.ToActorName() + "filePool");

            var isFirstPass = true;

            var stopwatch    = new Stopwatch();
            var lastScanTime = DateTime.Now.ToUniversalTime();

            while (true)
            {
                var scanStarted = DateTime.Now.ToUniversalTime();
                stopwatch.Restart();
                var dirInfo      = new DirectoryInfo(watchMessage.FileLocation);
                var currentFiles = dirInfo
                                   .EnumerateFiles(watchMessage.MatchingPattern)
                                   .AsParallel()
                                   .Select(file =>
                {
                    if (_fileList.Count == 0 ||
                        fileModifiedSinceLastScan(file.LastWriteTime.ToUniversalTime(), lastScanTime)
                        // Sometimes a file will be modified > 10 seconds ago, and the system will miss it because of lag
                        // This  happens the most when there are lots of big files
                        || fileModifiedSinceLastRecordedWriteTime(file))
                    {
                        _fileCoordinator.Tell(new FileToProcess(file, !isFirstPass));
                    }
                    return(file);
                })
                                   .ToList();

                handleDeletedFiles(currentFiles);

                lastScanTime = scanStarted;
                stopwatch.Stop();
                var timeToSleep = TimeSpan.FromSeconds(10) - stopwatch.Elapsed;
                if (timeToSleep > TimeSpan.Zero)
                {
                    Thread.Sleep(timeToSleep);
                }

                isFirstPass = false;
            }
        }
示例#6
0
        public void Run()
        {
            System.Console.Clear();

            //string version = Assembly.GetEntryAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion;


            try
            {
                string assemblyVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString();



                //System.Console.WriteLine("Starting version "+ version);
                watchFolder = new WatchFolder();
                watchFolder.DoneWatching += WatchFolder_DoneWatching;

                Log.Info("Starting version " + assemblyVersion);

                System.Console.CancelKeyPress += (s, e) =>
                {
                    Log.Info("Cancel pressed - stopping");
                    e.Cancel = true;
                    watchFolder.Stop();
                    running = false;
                    stopEvent.Set();
                };

                watchFolder.Start();

                while (running)
                {
                    System.Console.WriteLine("Press CTRL+C to stop:");

                    stopEvent.WaitOne();

                    Log.Info("Stopped");
                }
            }
            catch (Exception ex)
            {
                Log.Error("Exception", ex);
            }
        }
示例#7
0
        private async Task <DbOperationResult> Insert_R(WatchFolder watchFolder)
        {
            var stopWatch = new Stopwatch();

            stopWatch.Start();

            try
            {
                int existingMusicFileId = GetWatchFolderIdFromPath(watchFolder.Path).Result;
                if (existingMusicFileId == -1)
                {
                    using (var conn = DbConnection())
                    {
                        conn.Open();
                        watchFolder.Id = (int)conn.Query <long>(
                            @"INSERT 
                                INTO WatchFolders (
                                        Path) 
                                VALUES (@Path);
                              SELECT last_insert_rowid()",
                            watchFolder).First();
                        conn.Close();
                    }
                }
                else
                {
                    stopWatch.Stop();
                    return(await Task.FromResult(DbOperationResult.Success(existingMusicFileId, stopWatch.Elapsed)));
                }

                stopWatch.Stop();
                return(await Task.FromResult(DbOperationResult.Success(watchFolder.Id, stopWatch.Elapsed)));
            }
            catch (Exception e)
            {
                stopWatch.Stop();
                return(await Task.FromResult(DbOperationResult.Fail(e.Message, stopWatch.Elapsed)));
            }
        }
示例#8
0
        public void AddWatchFolder(WatchFolderSettings watchFolderSetting, TaskSettings taskSettings)
        {
            if (!IsExist(watchFolderSetting))
            {
                if (!taskSettings.WatchFolderList.Contains(watchFolderSetting))
                {
                    taskSettings.WatchFolderList.Add(watchFolderSetting);
                }

                WatchFolder watchFolder = new WatchFolder { Settings = watchFolderSetting, TaskSettings = taskSettings };
                watchFolder.FileWatcherTrigger += path =>
                {
                    TaskSettings taskSettingsCopy = TaskSettings.GetSafeTaskSettings(taskSettings);
                    UploadManager.UploadFile(path, taskSettingsCopy);
                };
                WatchFolders.Add(watchFolder);

                if (taskSettings.WatchFolderEnabled)
                {
                    watchFolder.Enable();
                }
            }
        }
 /// <summary>
 /// Deletes a library Watch Folder entry from the database of a given WatchFolder model object
 /// </summary>
 /// <param name="watchFolder">The given WatchFolder object</param>
 /// <returns>DbOperationResult - Showing success or fail, with messages and stats</returns>
 public async Task <DbOperationResult> Delete(WatchFolder watchFolder)
 {
     return(await Delete(watchFolder.Id));
 }
示例#10
0
 public Unwatch(IFileWatcher watcher, IDisposable subscription, WatchFolder watchFolder)
 {
     _subscription = subscription;
     WatchFolder   = watchFolder;
     _watcher      = watcher;
 }
 private void btnCancel_Click(object sender, RoutedEventArgs e)
 {
     NewFolder = null;
     DialogResult = true;
 }
示例#12
0
 public void Start()
 {
     Console.WriteLine("Started service");
     watchFolder = new WatchFolder();
     watchFolder.Start();
 }
示例#13
0
 private bool IsWatchfolderAlreadyAddedAndUnchanged( WatchFolder currentFolder )
 {
     return WatchFolders.Values.Any( watchFolder => currentFolder.ID                     == watchFolder.ID && 
                                                    currentFolder.WorkflowXML.ToString() == watchFolder.WorkflowXML.ToString() &&
                                                    currentFolder.DestinationID          == watchFolder.DestinationID &&
                                                    currentFolder.Filter                 == watchFolder.Filter &&
                                                    currentFolder.IsEnabled              == watchFolder.IsEnabled );
 }
示例#14
0
 private async Task <DbOperationResult> Delete_R(WatchFolder watchFolder)
 {
     return(await Delete(watchFolder.Id));
 }