Ejemplo n.º 1
0
        // フォームクローズの処理
        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            // ウォッチャの取得
            Watcher = this.Watcher;

            // 監視中か否か
            bool isRunning = Watcher.EnableRaisingEvents;

            // 監視中なら監視終了
            if (isRunning)
            {
                Watcher.EnableRaisingEvents = false;
            }

            // ウォッチャの破棄
            Watcher.Dispose();
            Watcher = null;

            // 設定の保存
            Properties.Settings.Default.watchPath  = this.txtPath.Text;
            Properties.Settings.Default.suppress   = this.chkSuppressBalloon.Checked;
            Properties.Settings.Default.autostart  = this.chkAutostart.Checked;
            Properties.Settings.Default.showcreate = this.chkShowCreated.Checked;

            Properties.Settings.Default.Save();
        }
        private void MISettings_Click(object sender, EventArgs e)
        {
            _SettingsWindow = new ApplicationSettings();

            _SettingsWindow.Icon = this.AppIcon;

            // IF WE ARE ALREADY SHOWING THE WINDOW SET FOCUS TO IT
            if (_SettingsWindow.Visible)
            {
                _SettingsWindow.Focus();
            }
            else
            {
                _SettingsWindow.ShowDialog();
            }

            // IF A CHANGE HAS BEEN MADE IN THE SETTING RESTART THE SERVICE
            if (_SettingsWindow.HasChanged)
            {
                this.StopMonitoring();
                _DirectoryMonitor.Dispose();
                this.InitiateDirectoryMonitor();
                this.StartMonitoring();
            }

            _SettingsWindow.Dispose();
        }
Ejemplo n.º 3
0
 //Button2のClickイベントハンドラ
 private void stop()
 {
     //監視を終了
     watcher_.EnableRaisingEvents = false;
     watcher_.Dispose();
     watcher_ = null;
     Console.WriteLine("監視を終了しました。");
 }
 public void Dispose()
 {
     if (myWatcher != null)
     {
         myWatcher.Dispose();
         GC.SuppressFinalize(this);
         myWatcher = null;
     }
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Releases unmanaged and - optionally - managed resources.
 /// </summary>
 /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
 private void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (watcher != null)
         {
             watcher.Dispose();
             watcher = null;
         }
     }
 }
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (_watcher != null)
                {
                    _watcher.Dispose();
                }
            }

            base.Dispose(disposing);
        }
Ejemplo n.º 7
0
        /// <summary>
        ///   Releases the unmanaged resources used by the <see cref="T:Rothko.FileSystemWatcher"/> and
        ///   optionally releases the managed resources.
        /// </summary>
        /// <param name="disposing">
        ///   true to release both managed and unmanaged resources; false to release only unmanaged resources.
        /// </param>
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (inner != null)
                {
                    UnhookEvents();
                    inner.Dispose();
                }

                var handler = Disposed;
                if (handler != null)
                {
                    handler(this, new EventArgs());
                }
            }
        }
Ejemplo n.º 8
0
 private void LoadFile(string Filename, int Page, bool NewSumatraInstance)
 {
     if (fw != null)
     {
         fw.EnableRaisingEvents = false;
         fw.Dispose();
     }
     SumatraPDFControl.LoadFile(Filename, Page, NewSumatraInstance);
     fw = new System.IO.FileSystemWatcher(System.IO.Path.GetDirectoryName(Filename))
     {
         NotifyFilter          = System.IO.NotifyFilters.LastWrite,
         Filter                = System.IO.Path.GetFileName(Filename),
         IncludeSubdirectories = true
     };
     fw.Changed            += Fw_Changed;
     fw.EnableRaisingEvents = true;
 }
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                _cancellationTokenSource?.Cancel();
                _containedFSW?.Dispose();

                //_onExistedHandler = null;
                //_onAllChangesHandler = null;
                //_onCreatedHandler = null;
                //_onChangedHandler = null;
                //_onDeletedHandler = null;
                //_onRenamedHandler = null;
                //_onErrorHandler = null;
            }
            base.Dispose(disposing);
        }
Ejemplo n.º 10
0
 private void AutoChange()
 {
     if (this.IsAutoUpdate)
     {
         fsw = new System.IO.FileSystemWatcher(System.IO.Path.GetDirectoryName(path), System.IO.Path.GetFileName(path));
         fsw.IncludeSubdirectories = false;
         fsw.Changed            += new System.IO.FileSystemEventHandler(fsw_Changed);
         fsw.Created            += new System.IO.FileSystemEventHandler(fsw_Changed);
         fsw.EnableRaisingEvents = true;
     }
     else
     {
         if (fsw != null)
         {
             fsw.Dispose();
             fsw = null;
         }
     }
 }
Ejemplo n.º 11
0
        public void Dispose()
        {
            if (m_filewatcher != null)
            {
                m_filewatcher.EnableRaisingEvents = false;
                m_filewatcher.Created            -= new System.IO.FileSystemEventHandler(m_filewatcher_Created);
                m_filewatcher.Dispose();
                m_filewatcher = null;
            }

            if (m_file != null)
            {
                m_file.Dispose();

                try { System.IO.File.Delete(m_lockfilename); }
                catch { }

                m_file = null;
            }
        }
Ejemplo n.º 12
0
        public override void Stop()
        {
            Ready = false;

            if (m_Watcher != null)
            {
                m_Watcher.EnableRaisingEvents = false;
                //m_Watcher.Created -= FileCreated;
                m_Watcher.Dispose();
                m_Watcher = null;
            }

            if (m_RtpClient != null)
            {
                m_RtpClient.Disconnect();
                m_RtpClient = null;
            }

            m_Frames.Clear();

            SessionDescription = null;

            base.Stop();
        }
Ejemplo n.º 13
0
        private void ErrorPulse(object sender, System.IO.ErrorEventArgs e)
        {
            System.IO.FileSystemWatcher watcher = ((System.IO.FileSystemWatcher)sender);

            KeyValuePair <int, System.IO.FileSystemWatcher> watch = runners.Where(q => q.Value == watcher).FirstOrDefault();

            foreach (FolderItemConfiguration item in Configuration.Folders)
            {
                if (watch.Key == item.GetHashCode())
                {
                    int iMaxAttempts = 120;
                    int iTimeOut     = 30000;
                    int i            = 0;
                    while ((!System.IO.Directory.Exists(watcher.Path) || watcher.EnableRaisingEvents == false) && i < iMaxAttempts)
                    {
                        i += 1;
                        try
                        {
                            watcher.EnableRaisingEvents = false;
                            if (!System.IO.Directory.Exists(watcher.Path))
                            {
                                Log(sender, "Directory Inaccesible " + watcher.Path + " at " + DateTime.Now.ToString("HH:mm:ss"));
                                System.Threading.Thread.Sleep(iTimeOut);
                            }
                            else
                            {
                                // ReInitialize the Component
                                watcher.Dispose();
                                watcher = null;
                                watcher = new System.IO.FileSystemWatcher();
                                ((System.ComponentModel.ISupportInitialize)(watcher)).BeginInit();
                                watcher.Path   = item.Path;
                                watcher.Filter = item.Filter;
                                watcher.IncludeSubdirectories = item.Recursive;
                                watcher.Created            += WatcherPulse;
                                watcher.Deleted            += WatcherPulse;
                                watcher.Changed            += WatcherPulse;
                                watcher.Renamed            += WatcherPulse;
                                watcher.Error              += ErrorPulse;
                                watcher.EnableRaisingEvents = true;
                                ((System.ComponentModel.ISupportInitialize)(watcher)).EndInit();
                                Log(sender, "Try to Restart RaisingEvents Watcher at " + DateTime.Now.ToString("HH:mm:ss"));
                                runners[item.GetHashCode()] = watcher;
                            }
                        }
                        catch (Exception error)
                        {
                            if (sender != null)
                            {
                                Log(sender, "Error trying Restart Service " + error.StackTrace + " at " + DateTime.Now.ToString("HH:mm:ss"));
                            }
                            else
                            {
                                Log(watcher, "Error trying Restart Service " + error.StackTrace + " at " + DateTime.Now.ToString("HH:mm:ss"));
                            }

                            watcher.EnableRaisingEvents = false;
                            System.Threading.Thread.Sleep(iTimeOut);
                        }
                    }
                }
            }
        }
Ejemplo n.º 14
0
        public void run()
        {
            if (System.IO.Directory.Exists(DocumentOpener.app_path + "/" + this.storage_id))
            {
                MessageBox.Show("The file " + this.filename + " is already open.", "File already open", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
                return;
            }
            DocumentOpener.op_mutex.WaitOne();
            DocumentOpener.op_win.Invoke((MethodInvoker) delegate
            {
                DocumentOpener.op_win.text.Text           = "";
                DocumentOpener.op_win.progressBar.Visible = false;
                DocumentOpener.op_win.TopLevel            = true;
                DocumentOpener.op_win.Show();
            });
            if (!readOnly)
            {
                DocumentOpener.op_win.Invoke((MethodInvoker) delegate
                {
                    DocumentOpener.op_win.text.Text = "Asking to edit " + filename;
                });
                doc_lock = new DocumentLock(this);
                if (doc_lock.error != null)
                {
                    DocumentOpener.op_win.Invoke((MethodInvoker) delegate
                    {
                        DocumentOpener.op_win.Hide();
                    });
                    DocumentOpener.op_mutex.ReleaseMutex();
                    MessageBox.Show(doc_lock.error, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
                    return;
                }
            }
            DocumentDownload download = new DocumentDownload(this);

            last_change = System.IO.File.GetLastWriteTime(file_path).Ticks;
            DocumentOpener.op_win.Invoke((MethodInvoker) delegate
            {
                DocumentOpener.op_win.Hide();
            });
            DocumentOpener.op_mutex.ReleaseMutex();
            if (download.error != null)
            {
                MessageBox.Show(download.error, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
                download = null;
                return;
            }
            download = null;
            if (!readOnly)
            {
                monitor              = new System.IO.FileSystemWatcher();
                monitor.Path         = DocumentOpener.app_path + "/" + this.storage_id;
                monitor.NotifyFilter = System.IO.NotifyFilters.CreationTime | System.IO.NotifyFilters.LastAccess | System.IO.NotifyFilters.LastWrite | System.IO.NotifyFilters.Size | System.IO.NotifyFilters.FileName;
                //monitor.NotifyFilter = System.IO.NotifyFilters.LastWrite;
                //monitor.Filter = this.filename;
                monitor.Changed            += docChanged;
                monitor.Renamed            += docChanged;
                monitor.Created            += docChanged;
                monitor.Deleted            += docChanged;
                monitor.EnableRaisingEvents = true;
            }
            if (process != null)
            {
                if (process.HasExited)
                {
                    app_closed(null, null);
                }
                else
                {
                    process.Exited += app_closed;
                }
            }
            while (!closed)
            {
                Thread.Sleep(1000);
                if (!closed)
                {
                    try
                    {
                        System.IO.File.Open(file_path, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.None).Close();
                        app_closed(null, null);
                        break;
                    }
                    catch (Exception) {
                        if (doc_lock != null && doc_lock.updater.error != null)
                        {
                            readOnly                    = true;
                            monitor.Changed            -= docChanged;
                            monitor.EnableRaisingEvents = false;
                            monitor.Dispose();
                            monitor = null;
                            if (process != null && !process.HasExited)
                            {
                                for (int i = 0; i < 10 && !process.HasExited; i++)
                                {
                                    try { process.Kill(); }
                                    catch (Exception) { }
                                    Thread.Sleep(500);
                                }
                            }
                            app_closed(null, null);
                            break;
                        }
                    }
                }
            }
            while (!closed)
            {
                Thread.Sleep(100);
            }
            if (doc_lock != null)
            {
                doc_lock.unlock();
            }
            doc_lock = null;
            monitor  = null;
            thread   = null;
            process  = null;
        }