Пример #1
0
 private void OnChanged(object sender, FileSystemEventArgs e)
 {
     if (!_isClosed)
     {
         if (ChkRealTimeAnalysis.IsChecked)
         {
             try
             {
                 Application.Current.Dispatcher?.BeginInvoke(new Action(async() =>
                 {
                     if (_idle)
                     {
                         _silently = true;
                         await BtnFindMutantsClick(_selectedMutators);
                         if (!_testsAreFailing)
                         {
                             await BtnApplyMutantsClick();
                         }
                     }
                 }), DispatcherPriority.ApplicationIdle);
             }
             catch (Exception exception)
             {
                 Trace.TraceError("Closing Real Time Mutation {0}", exception);
                 _watcher?.Dispose();
             }
         }
     }
     else
     {
         _watcher?.Dispose();
     }
 }
Пример #2
0
        protected override void _Load()
        {
            _luaEnv?.Dispose();
            _watcher?.Dispose();
            _luaEnv = new LuaEnv();
            _luaEnv.Global.Set("Game", Game);
            _luaEnv.Global.Set("Logger", LogSystem);
            _luaEnv.Global.Set("Plugin", this);
            _luaEnv.Global.Set("DataPath", Path.Combine(Descriptor.Directory, "Data"));
            _luaEnv.DoString(_luaSandbox);

            _sandbox = _luaEnv.Global.Get <LuaTable>("sandbox_env");

            var entryScript = File.ReadAllText(EntryFilePath);

            _luaEnv.DoString(entryScript, "chunk", _sandbox);

            if (Convert.ToBoolean(Func("load")))
            {
                _watcher        = new FileSystemWatcher();
                _watcher.Path   = Path.GetDirectoryName(EntryFilePath);
                _watcher.Filter = Path.GetFileName(EntryFilePath);
                _watcher.EnableRaisingEvents = true;
                _watcher.Changed            += (sender, e) =>
                {
                    _refresh = true;
                };
            }

            Loaded = true;
        }
Пример #3
0
 private void MakerExiting(object sender, EventArgs e)
 {
     _textureChanged?.Dispose();
     _texChangeWatcher?.Dispose();
     _bytesToLoad = null;
     _lastError   = null;
     _loadToggle  = null;
 }
        private void MakerExiting(object sender, EventArgs e)
        {
            _textureChanged?.Dispose();
            _texChangeWatcher?.Dispose();
            _bytesToLoad = null;
            _lastError   = null;

            GetControllerRegistration().MaintainState = false;
        }
Пример #5
0
 /// <summary>
 /// Stop the filewatcher.
 /// </summary>
 public virtual void Stop()
 {
     _fileSystemWatcher?.Dispose();
     lock (_filesProcessed)
     {
         _filesProcessed.Clear();
     }
     IsStarted = false;
 }
Пример #6
0
        protected override void PostStop()
        {
            ValidateFolderAndSettings?.Cancel(false);
            _watcher?.Dispose();
            var self = Self;

            Context.ActorSelection("/user/DatabaseWatcher").Tell(new UnSubscribeToObjectChanges(self));
            LogToEverything(Context, $"FileSystemWatcher has stopped monitoring {_folderPath.FullName.ToString()}");

            _watcher = null;
            base.PostStop();
        }
Пример #7
0
        private void OnFileAccept(string[] strings, string type, bool hideMain)
        {
            _hideMainToLoad = hideMain;
            if (strings == null || strings.Length == 0)
            {
                return;
            }

            var texPath = strings[0];

            if (string.IsNullOrEmpty(texPath))
            {
                return;
            }

            _typeToLoad = type;

            void ReadTex(string texturePath)
            {
                try
                {
                    _bytesToLoad = File.ReadAllBytes(texturePath);
                }
                catch (Exception ex)
                {
                    _bytesToLoad = null;
                    _lastError   = ex;
                }
            }

            ReadTex(texPath);

            _texChangeWatcher?.Dispose();
            if (KoiSkinOverlayGui.WatchLoadedTexForChanges?.Value ?? true)
            {
                var directory = Path.GetDirectoryName(texPath);
                if (directory != null)
                {
                    _texChangeWatcher          = new FileSystemWatcher(directory, Path.GetFileName(texPath));
                    _texChangeWatcher.Changed += (sender, args) =>
                    {
                        if (File.Exists(texPath))
                        {
                            ReadTex(texPath);
                        }
                    };
                    _texChangeWatcher.Deleted            += (sender, args) => _texChangeWatcher?.Dispose();
                    _texChangeWatcher.Error              += (sender, args) => _texChangeWatcher?.Dispose();
                    _texChangeWatcher.EnableRaisingEvents = true;
                }
            }
        }
 protected void Dispose(bool disposing)
 {
     if (disposing)
     {
         _workspaceService.OnActiveWorkspaceChanged -= OnActiveWorkspaceChanged;
         if (_workspaceSettingsMgr != null)
         {
             _workspaceSettingsMgr.OnWorkspaceSettingsChanged -= OnSettingsChanged;
         }
         _folderWatcher?.Dispose();
         _folderWatcherTimer?.Dispose();
     }
 }
Пример #9
0
        private async Task ChangeAssetFolderAsync(string path)
        {
            if (_assetFolder != path)
            {
                _assetFolderWatcher?.Dispose();
                _assetFolderWatcher = null;
                Sprites             = null;

                _assetFolder = path;
                UpdateSetFolderButtonTooltip();
                await StartShowAssetFolderContent();
            }
        }
 protected void Dispose(bool disposing)
 {
     if (disposing)
     {
         _workspaceContextProvider.WorkspaceOpening -= OnWorkspaceOpening;
         _workspaceContextProvider.WorkspaceClosed  -= OnWorkspaceClosed;
         if (_workspace != null)
         {
             _workspace.InterpreterSettingChanged -= OnInterpreterSettingChanged;
         }
         _folderWatcher?.Dispose();
         _folderWatcherTimer?.Dispose();
     }
 }
Пример #11
0
 /// <inheritdoc />
 public void Stop()
 {
     // FileSystemWatcher sometimes raises multiple events when a file changes - https://github.com/dotnet/runtime/issues/24079.
     // This can cause multiple uncesssary NodeJS process restarts (see OutOfProcessNodeJSService).
     //
     // To avoid such restarts, we need to stop/ignore events once one is raised.
     // Setting FileSystemWatcher.EnableRaisingEvents to false is insufficient - once set to true, previously buffered events may be raised (observed on macos).
     //
     // Disposing works since it removes all handlers from the instance - https://github.com/dotnet/runtime/blob/a27884006dc5515e072adb4fa7c6f97cca08abd8/src/libraries/System.IO.FileSystem.Watcher/src/System/IO/FileSystemWatcher.cs#L343-L370.
     // Microsoft.AspNetCore.NodeServices took this approach as well.
     //
     // If stop is called before start, _fileSystemWatcher may be null.
     _fileSystemWatcher?.Dispose();
 }
Пример #12
0
        public void TryCreateTeleporterWatcher(DalamudPluginInterface pi, bool useTeleport)
        {
            const string teleporterPluginConfigFile = "TeleporterPlugin.json";

            _teleporterLanguage = _language;
            if (!useTeleport || _teleporterWatcher != null)
            {
                _teleporterWatcher?.Dispose();
                _teleporterWatcher = null;
                return;
            }

            var dir = new DirectoryInfo(pi.GetPluginConfigDirectory());

            if (!dir.Exists || (dir.Parent?.Exists ?? false))
            {
                return;
            }

            dir = dir.Parent;

            var file = new FileInfo(Path.Combine(dir !.FullName, teleporterPluginConfigFile));

            if (file.Exists)
            {
                ParseTeleporterFile(file.FullName);
            }

            void OnTeleporterConfigChange(object source, FileSystemEventArgs args)
            {
                PluginLog.Verbose("Reloading Teleporter Config.");
                if (args.ChangeType != WatcherChangeTypes.Changed && args.ChangeType != WatcherChangeTypes.Created)
                {
                    return;
                }

                ParseTeleporterFile(args.FullPath);
            }

            _teleporterWatcher = new FileSystemWatcher
            {
                Path         = dir.FullName,
                NotifyFilter = NotifyFilters.LastWrite,
                Filter       = teleporterPluginConfigFile,
            };
            _teleporterWatcher.Changed += OnTeleporterConfigChange;
            _teleporterWatcher !.EnableRaisingEvents = true;
        }
Пример #13
0
        private void UpdateAutosplitter()
        {
            var previousLatestSavePath = latestSavePath;

            latestSavePath = FindLatestSavePath();
            if (latestSavePath != previousLatestSavePath)
            {
                if (timer.CurrentState.CurrentPhase == TimerPhase.Running)
                {
                    ResetWools();
                    timer.Reset(true);
                }
                watcher?.Dispose();
                watcher = new FileSystemWatcher
                {
                    Path = latestSavePath, NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
                                                          | NotifyFilters.FileName |
                                                          NotifyFilters.DirectoryName |
                                                          NotifyFilters.Size |
                                                          NotifyFilters.Attributes,
                    Filter = "*.*"
                };
                watcher.Renamed            += NewLevelDat;
                watcher.Created            += SessionLock;
                watcher.Changed            += SessionLock;
                watcher.EnableRaisingEvents = true;

                CheckExistingSessionLock();
            }

            if (timer.CurrentState.CurrentPhase == TimerPhase.NotRunning)
            {
                ResetWools();
            }
        }
Пример #14
0
        protected override void UnloadContent()
        {
            Batch?.Dispose();
            Watcher?.Dispose();

            base.Dispose();
        }
Пример #15
0
 public void Disconnect()
 {
     _fileWatcher.Created            -= OnCreated;
     _fileWatcher.EnableRaisingEvents = false;
     _fileWatcher?.Dispose();
     _rabbitMqHelper?.Dispose();
 }
Пример #16
0
        public void Dispose()
        {
            UnloadPlugin();

            _watcher?.Dispose();
            _watcher = null;
        }
Пример #17
0
 public void Dispose()
 {
     m_watcher?.Dispose();
     m_watcher = null;
     m_client?.Dispose();
     m_client = null;
 }
        private void InitializeWorkspace(IPythonWorkspaceContext workspace)
        {
            lock (_factories) {
                // Cleanup state associated with the previous workspace, if any
                if (_workspace != null)
                {
                    _workspace.InterpreterSettingChanged -= OnInterpreterSettingChanged;
                    _workspace = null;
                }

                _folderWatcher?.Dispose();
                _folderWatcher = null;
                _folderWatcherTimer?.Dispose();
                _folderWatcherTimer = null;

                // Setup new workspace
                _workspace = workspace;
                if (_workspace != null)
                {
                    _workspace.InterpreterSettingChanged += OnInterpreterSettingChanged;
                    try {
                        _folderWatcher                       = new FileSystemWatcher(_workspace.Location, "*.*");
                        _folderWatcher.Created              += OnFileCreatedDeletedRenamed;
                        _folderWatcher.Deleted              += OnFileCreatedDeletedRenamed;
                        _folderWatcher.Renamed              += OnFileCreatedDeletedRenamed;
                        _folderWatcher.EnableRaisingEvents   = true;
                        _folderWatcher.IncludeSubdirectories = true;
                    } catch (ArgumentException) {
                    } catch (IOException) {
                    }
                    _folderWatcherTimer = new Timer(OnFileChangesTimerElapsed);
                }
            }
        }
Пример #19
0
        public static void WaitForZipCreation(string path, string fileName)
        {
            if (string.IsNullOrWhiteSpace(path))
            {
                throw new ArgumentNullException(nameof(path));
            }
            if (string.IsNullOrWhiteSpace(fileName))
            {
                throw new ArgumentNullException(nameof(fileName));
            }

            FileSystemWatcher fsw = null;

            try
            {
                fsw = new FileSystemWatcher();
                string[] data = new string[] { path, fileName };

                fsw.Path   = path;
                fsw.Filter = fileName;

                fsw.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
                                   | NotifyFilters.FileName | NotifyFilters.DirectoryName;

                Task work = Task.Run(() =>
                {
                    try
                    {
                        Thread.Sleep(1000);

                        if (data.Length == 2)
                        {
                            string dataPath = data[0];
                            string dataFile = path + data[1];
                            Console.WriteLine($"Creating {dataFile} in task...");

                            FileStream fileStream = File.Create(dataFile);
                            fileStream.Close();
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                    }
                });

                WaitForChangedResult result =
                    fsw.WaitForChanged(WatcherChangeTypes.Created, 3000);
                Console.WriteLine($"{result.Name} created at {path}.");
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            finally
            {
                File.Delete(fileName);
                fsw?.Dispose();
            }
        }
Пример #20
0
        public void Dispose()
        {
            _fileSystemWatcher?.Dispose();
            _timer?.Dispose();

            Console.WriteLine($"Stopped watching {_watchFolder} for {_watchFilter} files");
        }
            public void Dispose()
            {
                View = null;

                m_DataWatcher?.Dispose();
                m_DataWatcher = null;
            }
Пример #22
0
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         _fw?.Dispose();
     }
 }
Пример #23
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         librariesWatcher?.Dispose();
     }
 }
Пример #24
0
 /// <summary>
 /// Protected implementation of Dispose pattern.
 /// </summary>
 /// <param name="isDisposing">Called from Dispose().</param>
 void Dispose(bool isDisposing)
 {
     if (isDisposing)
     {
         _watcher?.Dispose();
     }
 }
Пример #25
0
        /// <summary>
        ///     Ends the watch on the log directory
        /// </summary>
        public void EndWatch()
        {
            //stop the file monitors
            if (_timerFileChecker != null && _timerFileChecker.Enabled)
            {
                _timerFileChecker?.Stop();
            }

            if (_fsw != null)
            {
                _fsw.EnableRaisingEvents = false;
                _fsw?.Dispose();
                _fsw = null;
            }

            //end all monitors
            var lstRemove = new List <string>();

            foreach (var mon in _dicMonitors)
            {
                lstRemove.Add(mon.Key);
            }

            foreach (var monKey in lstRemove)
            {
                AuctionMonitor monOut;
                if (_dicMonitors.TryRemove(monKey, out monOut))
                {
                    this.OnAuctionMonitorEnded(monOut);
                }
            }

            _watching = false;
        }
Пример #26
0
        public virtual Task UnloadAsync()
        {
            fileSystemWatcher?.Dispose();
            folderSystemWatcher?.Dispose();

            return(Task.CompletedTask);
        }
Пример #27
0
        public void Stop()
        {
            // We're relying on callers to synchronize start/stops so we don't need to ensure one happens before the other.

            _watcher?.Dispose();
            _watcher = null;
        }
Пример #28
0
 private void DisposeResources()
 {
     _repo?.Dispose();
     _repo = null;
     _fsw?.Dispose();
     _fsw = null;
 }
Пример #29
0
        public void Watch(string templateFolder)
        {
            if (currentFolder == templateFolder)
            {
                return;
            }

            lock (this)
            {
                if (currentFolder == templateFolder)
                {
                    return;
                }

                currentFolder = templateFolder;

                currentWatcher?.Dispose();
                currentWatcher = new FileSystemWatcher(templateFolder)
                {
                    EnableRaisingEvents   = true,
                    IncludeSubdirectories = true
                };
                currentWatcher.Changed += Handler;
                currentWatcher.Renamed += Handler;
            }
        }
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         _fileWatcher?.Dispose();
     }
 }
 public void WatcherShouldBeDisposedOnDispose()
 {
     FileSystemWatcher tested = new FileSystemWatcher();
       bool wasDisposed = false;
       tested.watcher.Disposed += (s,e) => wasDisposed = true;
       tested.Dispose();
       Assert.IsTrue(wasDisposed);
 }
Пример #32
0
    public static void FileSystemWatcher_Disposed()
    {
        FileSystemWatcher watcher = new FileSystemWatcher();
        watcher.Dispose();
        watcher.Dispose(); // shouldn't throw

        Assert.Throws<ObjectDisposedException>(() => watcher.EnableRaisingEvents = true);
    }
Пример #33
0
    public static void FileSystemWatcher_StopCalledOnBackgroundThreadDoesNotDeadlock()
    {
        // Check the case where Stop or Dispose (they do the same thing) is called from 
        // a FSW event callback and make sure we don't Thread.Join to deadlock
        using (var dir = Utility.CreateTestDirectory())
        {
            FileSystemWatcher watcher = new FileSystemWatcher();
            AutoResetEvent are = new AutoResetEvent(false);

            FileSystemEventHandler callback = (sender, arg) => {
                watcher.Dispose();
                are.Set();
            };

            // Attach the FSW to the existing structure
            watcher.Path = Path.GetFullPath(dir.Path);
            watcher.Filter = "*";
            watcher.NotifyFilter = NotifyFilters.FileName | NotifyFilters.Size;
            watcher.Changed += callback;

            using (var file = File.Create(Path.Combine(dir.Path, "testfile.txt")))
            {
                watcher.EnableRaisingEvents = true;

                // Change the nested file and verify we get the changed event
                byte[] bt = new byte[4096];
                file.Write(bt, 0, bt.Length);
                file.Flush();
            }

            are.WaitOne(Utility.WaitForExpectedEventTimeout);
        }
    }