예제 #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);
        }
    }