void DisposeWatcher()
 {
     if (m_watcher != null && m_watcher.Watching)
     {
         m_watcher.Dispose();
     }
 }
Ejemplo n.º 2
0
        // The bulk of the clean-up code is implemented in Dispose(bool)
        protected virtual void Dispose(bool disposing)
        {
            if (_isDisposed)
            {
                return;
            }

            if (disposing)
            {
                // free managed resources
                // Managed resources are those that are pure .NET code and managed by the runtime and are under its direct control.
                DirectoryInfo = null;
                if (Watcher != null)
                {
                    Watcher?.EndInit();
                    Watcher?.Dispose();
                }
            }

            //// free native resources if there are any.
            //if (nativeResource != IntPtr.Zero)
            //{
            //	// Unmanaged resources are those that are not. File handles, pinned memory, COM objects, database connections etc
            //	Marshal.FreeHGlobal(nativeResource);
            //	nativeResource = IntPtr.Zero;
            //}

            _isDisposed = true;
        }
Ejemplo n.º 3
0
 public void Dispose()
 {
     if (_watcher != null && _watcher.Watching)
     {
         _watcher.Dispose();
     }
 }
Ejemplo n.º 4
0
 private void StopWatching()
 {
     Watcher?.Dispose();
     synth.SpeakAsyncCancelAll();
     LastConversation = null;
     Watcher          = null;
 }
Ejemplo n.º 5
0
        protected override void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    if (_currentRecord != null)
                    {
                        LogJobEnd();
                    }

                    _cmdSelectFolder = null;
                    _cmdSaveList     = null;
                    _cmdCopyFiles    = null;
                    _cmdLaunchEditor = null;
                    _currentRecord   = null;

                    if (watcher != null)
                    {
                        watcher.Dispose();
                    }
                    if (fileHelper != null)
                    {
                        fileHelper.Dispose();
                    }
                }

                _changedFiles  = null;
                _customFilters = null;
                _scanModes     = null;
                _subFolders    = null;

                base.Dispose(disposing);
            }
        }
Ejemplo n.º 6
0
        private Watcher StartNewWatcher()
        {
            var newWatcher = new Watcher();

            try
            {
                newWatcher.DirectoryPath = DirectoryPath;
                newWatcher.Filter        = "*.log";
                newWatcher.LineWriter    = CreateWriter();
                newWatcher.FileFound    += WatcherFileFound;
                newWatcher.Start();
            }
            catch
            {
                try
                {
                    newWatcher.Dispose();
                }
                catch
                {
                }
                throw;
            }
            return(newWatcher);
        }
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();

                // If the process has started, all three disposable objects will be valid
                // I would just call OnStop, but the code analysis tool doesn't look inside
                // it and thinks the members aren't being Disposed.
                if (Processors.Count > 0)
                {
                    // Clean up the directory watcher and crash processor threads
                    foreach (var Processor in Processors)
                    {
                        Processor.Dispose();
                    }
                    Processors.Clear();

                    Watcher.Dispose();
                    Watcher = null;

                    StatusReporter.Dispose();
                    StatusReporter = null;

                    Slack.Dispose();
                    Slack = null;

                    // Flush the log to disk
                    Log.Dispose();
                    Log = null;
                }
            }
            base.Dispose(disposing);
        }
Ejemplo n.º 8
0
        public Task StopAsync(CancellationToken cancellationToken)
        {
            _logger.LogInformation("Stopping Foo monitoring!");

            _watcher.Dispose();

            return(Task.CompletedTask);
        }
Ejemplo n.º 9
0
 public void Dispose()
 {
     if (null != Watcher)
     {
         Watcher.EnableRaisingEvents = false;
         Watcher.Dispose();
     }
 }
Ejemplo n.º 10
0
        private void DestroyWatcher()
        {
#if HRVC_DEBUG
            Logger.log.Critical($"Destroying FileSystemWatcher for {ContentDirectory}");
#endif
            Watcher.Dispose();
            Watcher = null;
        }
Ejemplo n.º 11
0
 public void Dispose()
 {
     if (Watcher != null)
     {
         Watchers.Remove(Watcher);
         Watcher.EnableRaisingEvents = false;
         Watcher.Dispose();
     }
 }
Ejemplo n.º 12
0
 protected void DisposeInternal()
 {
     if (Disposed)
     {
         return;
     }
     Watcher?.Dispose();
     Disposed = true;
 }
Ejemplo n.º 13
0
 public void StopWatching()
 {
     if (Watcher != null)
     {
         Watcher.EnableRaisingEvents = false;
         Watcher.Dispose();
         Watcher = null;
     }
 }
Ejemplo n.º 14
0
 public void Close()
 {
     if (!Completed)
     {
         return;
     }
     Watcher?.Dispose();
     Client?.Exit();
 }
Ejemplo n.º 15
0
        public void Dispose_ForInvoked_DisposesWrapper(
            Watcher sut,
            [Freeze] IWrapper wrapper)
        {
            sut.Dispose();

            wrapper.Received()
            .Dispose();
        }
Ejemplo n.º 16
0
        private void OnTimerExpired(object sender, ElapsedEventArgs e)
        {
            Watcher.EnableRaisingEvents = false;
            Watcher.Dispose();
            _timer.Enabled = false;
            _timer.Dispose();

            Finished?.Invoke(this, new FileMonitorFinishedArgs(this));
        }
Ejemplo n.º 17
0
 /// <summary>
 ///     Dispose this scheduler.
 /// </summary>
 /// <param name="disposing">The boolean whether to dispose.</param>
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         Watcher.Changed -= OnChanged;
         Watcher.Created -= OnChanged;
         Watcher.Renamed -= OnChanged;
         Watcher.Dispose();
     }
 }
Ejemplo n.º 18
0
        public void Dispose()
        {
            Watcher.Dispose();

            if (null != Reader)
            {
                Reader.Close();
                Reader.Dispose();
            }
        }
Ejemplo n.º 19
0
        private void OnChanged(object s, FileSystemEventArgs e)
        {
            if (e.FullPath != TempPath)
            {
                return;
            }

            if (e.ChangeType != WatcherChangeTypes.Changed)
            {
                return;
            }

            try
            {
                var newFiles     = File.ReadAllLines(TempPath);
                var filesChanged = 0;

                for (var i = 0; i < FileList.Length; i++)
                {
                    var oldFileName = FileList[i];
                    var newFileName = newFiles[i];

                    if (oldFileName == newFileName)
                    {
                        continue;
                    }

                    File.Move(oldFileName, newFileName);
                    filesChanged++;
                }

                Renamed?.Invoke(this, new RenamedEventArgs(filesChanged));
            }
            catch (Exception ex)
            {
                using var dialog = new TaskDialog()
                      {
                          Caption = "Renamer",
                          Icon    = TaskDialogStandardIcon.Error,
                          Text    = "An error has occured while renaming files.",
                          DetailsCollapsedLabel = "Show exception details",
                          DetailsExpandedLabel  = "Hide exception details",
                          DetailsExpandedText   = ex.ToString(),
                          StandardButtons       = TaskDialogStandardButtons.Ok
                      };

                dialog.Show();
            }
            finally
            {
                File.Delete(TempPath);
            }

            Watcher.Dispose();
        }
Ejemplo n.º 20
0
        private void MenuRemove_Click(object sender, RoutedEventArgs e)
        {
            Watcher watcher = WatcherList.SelectedItem as Watcher;

            if (watcher == null)
            {
                return;
            }

            manager.Watchers.Remove(watcher);
            watcher.Dispose();
        }
Ejemplo n.º 21
0
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (Watcher != null)
         {
             Watcher.Changed -= OnChanged;
             Watcher.Dispose();
             Watcher = null;
         }
     }
 }
Ejemplo n.º 22
0
        public override TaskStatus Run()
        {
            InfoFormat("Watching the folder {0} ...", FolderToWatch);

            try
            {
                if (!string.IsNullOrEmpty(SmbComputerName) && !string.IsNullOrEmpty(SmbUsername) && !string.IsNullOrEmpty(SmbPassword))
                {
                    using (NetworkShareAccesser.Access(SmbComputerName, SmbDomain, SmbUsername, SmbPassword))
                    {
                        if (!Directory.Exists(FolderToWatch))
                        {
                            ErrorFormat("The folder {0} does not exist.", FolderToWatch);
                            return(new TaskStatus(Status.Error));
                        }

                        InitFileSystemWatcher();
                    }
                }
                else
                {
                    if (!Directory.Exists(FolderToWatch))
                    {
                        ErrorFormat("The folder {0} does not exist.", FolderToWatch);
                        return(new TaskStatus(Status.Error));
                    }

                    InitFileSystemWatcher();
                }
            }
            catch (ThreadAbortException)
            {
                if (Watcher != null)
                {
                    Watcher.EnableRaisingEvents = false;
                    Watcher.Dispose();
                }
                throw;
            }
            catch (Exception e)
            {
                if (Watcher != null)
                {
                    Watcher.EnableRaisingEvents = false;
                    Watcher.Dispose();
                }
                ErrorFormat("An error occured while initializing FileSystemWatcher.", e);
            }

            Info("Task finished");
            return(new TaskStatus(Status.Success));
        }
Ejemplo n.º 23
0
 public void Stop()
 {
     if (watcher == null)
     {
         throw new InvalidOperationException("Watcher is not started");
     }
     if (watcher.IsStarted)
     {
         watcher.Stop();
     }
     watcher.Dispose();
     watcher = null;
 }
Ejemplo n.º 24
0
        public void Dispose()
        {
            IsDisposed  = true;
            _isChanging = false;

            Watcher.Changed -= OnChanged;
            Watcher.Created -= OnCreated;
            Watcher.Deleted -= OnDeleted;
            Watcher.Renamed -= OnRenamed;

            Watcher.Dispose();
            Watcher = null;
        }
Ejemplo n.º 25
0
        static void Main(string[] args)
        {
            IWatcher watcher = new Watcher();

            watcher.MessageHandlerEvent += ConsoleMessagePrinter.WriteMessageInConsole;
            ITaskManager taskManager = new TaskManager(watcher);

            watcher.Watch();
            Console.WriteLine("Console Client working");
            Console.ReadLine();
            watcher.MessageHandlerEvent -= ConsoleMessagePrinter.WriteMessageInConsole;
            watcher.StopWatch();
            watcher.Dispose();
        }
        public Task StopAsync(CancellationToken cancellationToken)
        {
            if (_leaderCheckTimer != null)
            {
                _leaderCheckTimer.Dispose();
            }

            if (_watcher != null)
            {
                _watcher.Dispose();
            }

            return(Task.CompletedTask);
        }
Ejemplo n.º 27
0
        private void Init()
        {
            watcher?.Dispose();
            Items.Clear();
            watcher = State.Client?.ListNamespaceWithHttpMessagesAsync(watch: true)
                      .Watch <V1Namespace, V1NamespaceList>((type, item) =>
            {
                switch (type)
                {
                case WatchEventType.Added:
                    if (!Items.Any(x => x.Metadata.Uid == item.Metadata.Uid))
                    {
                        Items.Add(item);
                    }
                    else
                    {
                        Items[Items.FindIndex(x => x.Metadata.Uid == item.Metadata.Uid)] = item;
                    }
                    break;

                case WatchEventType.Modified:
                    Items[Items.FindIndex(x => x.Metadata.Uid == item.Metadata.Uid)] = item;
                    break;

                case WatchEventType.Deleted:
                    Items.RemoveAt(Items.FindIndex(x => x.Metadata.Uid == item.Metadata.Uid));
                    break;

                case WatchEventType.Error:
                    break;

                default:
                    break;
                }
                StateHasChanged();
            });
        }
Ejemplo n.º 28
0
 public void Dispose()
 {
     if (Disposed)
     {
         return;
     }
     Watcher.EnableRaisingEvents = false;
     Watcher.Changed            -= this.WatcherOnChanged;
     Watcher.Deleted            -= this.WatcherOnDeleted;
     Watcher.Renamed            -= this.WatcherOnRenamed;
     Disposed = true;
     Watcher.Dispose();
     Object = null;
     Path   = null;
 }
Ejemplo n.º 29
0
        static void Main(string[] args)
        {
            using (var watcher = new FileSystemWatcher(@"C:\temp")
            {
                EnableRaisingEvents = true
            })
            {
                watcher.Created += new FileSystemEventHandler(watcher_Created);

                Console.WriteLine("Press a key to release the watcher reference.");
                Console.ReadKey(true);

                watcher = null;
            }
            Watcher.Dispose();
            Console.WriteLine("Press a key to exit the application.");
            Console.ReadKey(true);
        }
        private async Task StartWatcher(CancellationToken token)
        {
            var response = await _client.ListClusterCustomObjectWithHttpMessagesAsync(
                group : Constants.Group,
                version : Constants.Version,
                plural : Constants.Plural,
                watch : true,
                timeoutSeconds : ((int)TimeSpan.FromMinutes(60).TotalSeconds),
                cancellationToken : token
                );

            _watcher = response.Watch <HealthCheckResource, object>(
                onEvent: async(type, item) => await OnEventHandlerAsync(type, item, token)
                ,
                onClosed: () =>
            {
                _watcher.Dispose();
                _ = StartWatcher(token);
            },
                onError: e => _logger.LogError(e.Message)
                );
        }