예제 #1
0
 public LogViewer(string spacefilter, AssemblaTicketWindow.LoginSucceedDel loginsuccess,string User, string Pw)
 {
     namefilter = spacefilter;
     loginsucceed = loginsuccess;
     user = User;
     pw = Pw;
     if (loginsucceed == null)
         loginsucceed = new AssemblaTicketWindow.LoginSucceedDel(succeed);
     InitializeComponent();
     if (namefilter!=string.Empty)
     {
         Text = PROGRAM + " " + namefilter;
         Invalidate();
     }
     ContextMenu = new ContextMenu();
     ContextMenu.MenuItems.Add("View", new EventHandler(view));
     ContextMenu.MenuItems.Add("Ticket", new EventHandler(aticket));
     ContextMenu.MenuItems.Add("Delete", new EventHandler(del));
     DoubleClick += new EventHandler(LogViewerMain_DoubleClick);
     _logs.DoubleClick += new EventHandler(_logs_DoubleClick);
     _logs.SelectionMode = SelectionMode.MultiExtended;
     _logs.Sorted = true;
     init();
     fsw =  new System.IO.FileSystemWatcher(PATH,WILDEXT);
     fsw.IncludeSubdirectories = false;
     fsw.Changed += new System.IO.FileSystemEventHandler(fsw_Changed);
     fsw.Created += new System.IO.FileSystemEventHandler(fsw_Created);
 }
예제 #2
0
 public OSParser(string directory)
 {
     m_directory = directory;
     var fsWatcher = new System.IO.FileSystemWatcher(directory);
     fsWatcher.EnableRaisingEvents = true;
     fsWatcher.Renamed += fsWatcher_Renamed;
 }
예제 #3
0
 public OEParser(string directory)
 {
     m_Directory = directory;
     System.IO.FileSystemWatcher fsWatcher = new System.IO.FileSystemWatcher(directory);
     fsWatcher.EnableRaisingEvents = true;
     fsWatcher.Renamed += new System.IO.RenamedEventHandler(fsWatcher_Renamed);
 }
 public DialogueRecognitionEngine(Profile profile)
     : base(profile)
 {
     dialogueWatcher = new System.IO.FileSystemWatcher();
     dialogueWatcher.NotifyFilter = System.IO.NotifyFilters.LastWrite;
     dialogueWatcher.Changed += dialogueWatcher_Changed;
     this.dialogueWatcher.Filter = "*.diag";
 }
 public void Dispose()
 {
     if (myWatcher != null)
     {
         myWatcher.Dispose();
         GC.SuppressFinalize(this);
         myWatcher = null;
     }
 }
예제 #6
0
 private System.IO.FileSystemWatcher createWatcher(String path, System.ComponentModel.ISynchronizeInvoke synchroObj)
 {
     var watcher = new System.IO.FileSystemWatcher();
     watcher.Path = path;
     watcher.Filter = "*.txt";
     watcher.NotifyFilter = System.IO.NotifyFilters.FileName;
     watcher.IncludeSubdirectories = false;
     watcher.SynchronizingObject = synchroObj;
     watcher.Created += new System.IO.FileSystemEventHandler(watcher_Changed);
     watcher.EnableRaisingEvents = true;
     return watcher;
 }
예제 #7
0
        public void Startup()
        {
            Tasks.DoLater(() => {
                cswatcher = new System.IO.FileSystemWatcher(Paths.Map(Root));
                cswatcher.Changed += Compile;
                cswatcher.Created += Compile;
                cswatcher.Deleted += Compile;

                Compile(this, EventArgs.Empty);

                cswatcher.EnableRaisingEvents = true;
            });
        }
예제 #8
0
        private static void Main(string[] args)
        {
            System.IO.FileSystemWatcher w = new System.IO.FileSystemWatcher(@"c:\temp", "*.txt");
            w.EnableRaisingEvents = true;
            w.Created            += (o, e) => Console.WriteLine("Created: " + e.FullPath);
            w.Deleted            += (o, e) => Console.WriteLine("Deleted: " + e.FullPath);
            w.Renamed            += (o, e) => Console.WriteLine("Renamed: " + e.FullPath);
            w.Changed            += (o, e) => Console.WriteLine("Changed: " + e.FullPath);

            do
            {
            } while (true);
        }
예제 #9
0
        static void Main(string[] args)
        {
            // New filewatcher
            System.IO.FileSystemWatcher w = new System.IO.FileSystemWatcher(@"c:\temp", "*.txt");
            // Enable watcher
            w.EnableRaisingEvents = true;
            //w.Changed += W_Changed;
            w.Changed += (s, e) => { Console.WriteLine("file changed:" + e.Name); };

            do
            {
            } while (true);
        }
예제 #10
0
 static void Main(string[] args)
 {
     System.IO.FileSystemWatcher fsw = new System.IO.FileSystemWatcher(@"c:\temp\", "*.txt");
     fsw.Changed            += Fsw_Changed;
     fsw.Deleted            += (s, e) => { Console.WriteLine("A file {0} is deleted.", e.Name); };
     fsw.EnableRaisingEvents = true;
     fsw.Created            += (s, e) => { Console.WriteLine("A new file {0} is created.", e.Name); };
     fsw.Created            += Fsw_Created1;
     fsw.NotifyFilter        = System.IO.NotifyFilters.FileName | System.IO.NotifyFilters.Size;
     do
     {
     } while (true);
 }
예제 #11
0
        static void Main(string[] args)
        {
            System.IO.FileSystemWatcher fsw = new System.IO.FileSystemWatcher(@"C:\temp", "*.txt");

            fsw.EnableRaisingEvents = true;
            fsw.NotifyFilter        = System.IO.NotifyFilters.FileName | System.IO.NotifyFilters.Size;

            fsw.Changed += Fsw_Changed;

            do
            {
            } while (true);
        }
예제 #12
0
        public SubscribeToChanges(string filePath, Action Callback)
        {
            host = Config.ObjectModelRoot;
            if (host == null)
            {
                throw new ArgumentNullException("ObjectModelRoot not set in config");
            }

            callbackAction = Callback;
            System.IO.FileSystemWatcher watcher = new System.IO.FileSystemWatcher(filePath);
            watcher.Changed            += Watcher_Changed;
            watcher.EnableRaisingEvents = true;
        }
예제 #13
0
        public FileSystemWatcher()
        { 
            var currentDirectory = System.IO.Directory.GetCurrentDirectory();
			
            _actualWatcher = new System.IO.FileSystemWatcher(currentDirectory, "*.js");
			
            _actualWatcher.Changed += _actualWatcher_Changed;
			_actualWatcher.Created += _actualWatcher_Created;
            _actualWatcher.Renamed += _actualWatcher_Renamed;
            _actualWatcher.IncludeSubdirectories = true;
            _actualWatcher.NotifyFilter = System.IO.NotifyFilters.LastWrite|System.IO.NotifyFilters.CreationTime;
            _actualWatcher.EnableRaisingEvents = true;
        }
예제 #14
0
        public SubscribeToChanges(string filePath, Action Callback)
        {
            host = Config.ObjectModelRoot;
            if (host == null)
            {
                throw new ArgumentNullException("ObjectModelRoot not set in config");
            }

            callbackAction = Callback;
            System.IO.FileSystemWatcher watcher = new System.IO.FileSystemWatcher(filePath);
            watcher.Changed += Watcher_Changed;
            watcher.EnableRaisingEvents = true;
        }
예제 #15
0
        /// <summary>
        /// 获取数据连接字符串,默认路径d:\DBConnection
        /// 会自动识是否加密过
        /// </summary>
        /// <param name="connectionName"></param>
        /// <returns></returns>
        public static string GetConnectionString(string connectionName)
        {
            connectionName = (connectionName + ".config").ToUpper();
            //var cache = System.Web.HttpRuntime.Cache;
            //string configKey = "$ConnectionString";
            //var cacheObj = cache.Get(configKey);
            //Dictionary<string, string> keyCache;
            //if (cacheObj != null)
            //{
            //    keyCache = cacheObj as Dictionary<string, string>;
            //}
            if (connectionCaches == null)
            {
                connectionCaches = new Dictionary <string, string>();
                //string folder = "c:\\DBConnection\\";
                string folder = RequestHelper.GetFilePath("DBConnection");
                //优先以网站当前目录下设置
                //if (System.IO.Directory.Exists(folder2))
                //    folder = folder2;

                if (watch2 == null)
                {
                    watch2 = new System.IO.FileSystemWatcher(folder, "*.config");
                    watch2.NotifyFilter = System.IO.NotifyFilters.LastWrite;
                    watch2.Changed     += (s, e) =>
                    {
                        connectionCaches = null;
                    };
                    watch2.EnableRaisingEvents = true;
                }

                string[] files = System.IO.Directory.GetFiles(folder, "*.config");
                foreach (string file in files)
                {
                    string value = System.IO.File.ReadAllText(file);
                    try
                    {
                        value = DesString(value);
                        string fileName = System.IO.Path.GetFileName(file).ToUpper(); //file.Substring(file.LastIndexOf("\\") + 1).ToUpper();
                        connectionCaches.Add(fileName, value);
                    }
                    catch { }
                }
                //cache.Insert(configKey, keyCache, new System.Web.Caching.CacheDependency(folder), DateTime.Now.AddDays(1), System.Web.Caching.Cache.NoSlidingExpiration);
            }
            if (!connectionCaches.ContainsKey(connectionName))
            {
                throw new Exception("数据连接文件不存在,或加密错误:" + connectionName);
            }
            return(connectionCaches[connectionName]);
        }
예제 #16
0
        static void Main(string[] args)
        {
            System.IO.FileSystemWatcher w = new System.IO.FileSystemWatcher(@"c:\temp", "*.txt");
            w.EnableRaisingEvents = true;

            w.Changed += (s, e) => Console.WriteLine(DateTime.Now.ToLongTimeString() + $": Filen {e.Name} er rettet.");
            w.Created += (s, e) => Console.WriteLine(DateTime.Now.ToLongTimeString() + $": Filen {e.Name} er oprettet.");
            w.Deleted += (s, e) => Console.WriteLine(DateTime.Now.ToLongTimeString() + $": Filen {e.Name} er slettet.");
            w.Renamed += (s, e) => Console.WriteLine(DateTime.Now.ToLongTimeString() + $": Filen {e.Name} er omdøbt.");

            do
            {
            } while (true);
        }
예제 #17
0
        static void Main(string[] args)
        {
            System.IO.FileSystemWatcher w =
                new System.IO.FileSystemWatcher(@"c:\temp", "*.txt");
            w.EnableRaisingEvents = true;
            // bind en metode til w.Changed

            w.Changed += W_Changed;
            w.Created += (s, e) => { Console.WriteLine("Oprettet " + e.FullPath, System.Security.Principal.WindowsIdentity.GetCurrent().Name); };
            //string userName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
            do
            {
            } while (true);
        }
예제 #18
0
        /// <summary>
        /// start up.  get globals, load object mappings, init DAL, etc...
        /// </summary>
        public static void Start()
        {
            System.Web.HttpContext context = System.Web.HttpContext.Current;

            // set globals
            NodeTemplateLocation = System.Configuration.ConfigurationSettings.AppSettings["nodeTemplateDirectory"];
            ResourceFileLocation = System.Configuration.ConfigurationSettings.AppSettings["resourceDirectory"];
            VirtualDirectory     = System.Configuration.ConfigurationSettings.AppSettings["virtualDirName"];
            SiteRoot             = "/" + System.Configuration.ConfigurationSettings.AppSettings["virtualDirName"];
            VirutalFileExtention = System.Configuration.ConfigurationSettings.AppSettings["virtualFileExtension"];
            DefaultLanguage      = System.Configuration.ConfigurationSettings.AppSettings["defaultLanguage"];
            ShowLangInUrl        = bool.Parse(System.Configuration.ConfigurationSettings.AppSettings["showLangInUrl"]);
            BaseDirectory        = System.AppDomain.CurrentDomain.BaseDirectory;
            EncryptionKey        = System.Configuration.ConfigurationSettings.AppSettings["encryptionKey"];
            EncryptionMethod     = System.Configuration.ConfigurationSettings.AppSettings["encryptionMethod"];
            EncryptionSalt       = Convert.FromBase64CharArray(EncryptionKey.ToCharArray(), 0, EncryptionKey.Length);
            AdminstratorRoleName = System.Configuration.ConfigurationSettings.AppSettings["AdminstratorRoleName"];
            PublisherRoleName    = System.Configuration.ConfigurationSettings.AppSettings["PublisherRoleName"];
            EditorRoleName       = System.Configuration.ConfigurationSettings.AppSettings["EditorRoleName"];
            ContributorRoleName  = System.Configuration.ConfigurationSettings.AppSettings["ContributorRoleName"];
            ContentMenuDisplay   = System.Configuration.ConfigurationSettings.AppSettings["contentMenuDisplay"];

            appDirectory = AppDomain.CurrentDomain.BaseDirectory.Replace("/bin", "");

            //context.Application.Add("currentUsers",0);
            UserCount = 0;

            // start Object-Relational Mappings
            string connection = System.Configuration.ConfigurationSettings.AppSettings["connectionString"];
            string mappings   = appDirectory + System.Configuration.ConfigurationSettings.AppSettings["objectMappingsFile"];

            ObjectManager       = new Wilson.ORMapper.ObjectSpace(mappings, connection, Wilson.ORMapper.Provider.MsSql);
            mappings            = appDirectory + System.Configuration.ConfigurationSettings.AppSettings["objectMappingsPublicFile"];
            ObjectManagerPublic = new Wilson.ORMapper.ObjectSpace(mappings, connection, Wilson.ORMapper.Provider.MsSql);

            // SQL Data Abstraction Layer
            DAL = new DAL();

            // read templates into memory
            TemplateLoader.Load(System.Configuration.ConfigurationSettings.AppSettings["nodeTemplateDefinitions"]);

            // set FSW on config files
            fsw = new System.IO.FileSystemWatcher(appDirectory, "*.config");
            fsw.EnableRaisingEvents = true;
            fsw.NotifyFilter        = System.IO.NotifyFilters.LastWrite;
            fsw.Changed            += new System.IO.FileSystemEventHandler(fsw_Changed);


            UpdateNodes();
        }
예제 #19
0
        public void Run()
        {
            var watcher = new System.IO.FileSystemWatcher();
            var reader  = new Reader(watcher, basePath);

            reader.StartReading();

            while (running)
            {
                Thread.Sleep(5000);
            }

            reader.StopReading();
        }
예제 #20
0
        static void Main(string[] args)
        {
            System.IO.FileSystemWatcher fw = new System.IO.FileSystemWatcher(@"c:\temp", "*.txt");
            fw.EnableRaisingEvents = true;
            fw.NotifyFilter        = System.IO.NotifyFilters.FileName | System.IO.NotifyFilters.Size;

            // bind en metode til fw.Changed her ------->
            fw.Changed += Fw_Changed;
            fw.Created += Fw_Created;
            fw.Renamed += Fw_Renamed;
            do
            {
            } while (true);
        }
예제 #21
0
        void WatchFile(string strFileName)
        {
            if (m_Watch != null)
            {
                m_Watch.Changed -= M_Watch_Changed;
                m_Watch.Dispose();
            }
            System.IO.FileInfo f = new System.IO.FileInfo(strFileName);

            m_Watch = new System.IO.FileSystemWatcher(f.Directory.FullName, f.Name);

            m_Watch.Changed            += M_Watch_Changed;
            m_Watch.EnableRaisingEvents = true;
        }
예제 #22
0
        static void Main(string[] args)
        {
            System.IO.FileSystemWatcher w = new System.IO.FileSystemWatcher(@"c:\temp", "*.txt");
            w.EnableRaisingEvents = true;
            // bind en metode til w.Changed

            w.Created += (s, e) => Console.WriteLine("Fil oprettet");
            w.Deleted += (s, e) => Console.WriteLine("Fil Deleted");
            w.Changed += (s, e) => Console.WriteLine("Fil Changed");

            do
            {
            } while (true);
        }
예제 #23
0
        public void TestCreateReconciliationFileReaderFile()
        {
            var watcher = new System.IO.FileSystemWatcher();
            string path = @"C:\Reconciliation\CreditCard\In\testfile.txt";
            Reader reader = new Reader(watcher, @"C:\Reconciliation\CreditCard\");
            reader.CreateReconciliationFile(path);

            using (var container = new TransactionModelContainer())
            {
                var reconci = container.ReconciliationFiles.FirstOrDefault(x => x.Id == 1);
                byte[] data = reconci.Contents;
                string s = System.Text.ASCIIEncoding.ASCII.GetString(data);
            }
        }
예제 #24
0
        } // End Function RunWatcher

        static void Main(string[] args)
        {
            string filePath = System.IO.Path.GetDirectoryName(typeof(Program).Assembly.Location);

            filePath = System.IO.Path.Combine(filePath, "..", "..", "..", "myfile.txt");
            filePath = System.IO.Path.GetFullPath(filePath);
            System.Console.WriteLine(filePath);

            using (System.IO.FileSystemWatcher watcher = RunWatcher(filePath))
            {
                System.Console.WriteLine(" --- Press any key to continue --- ");
                System.Console.ReadKey();
            }
        }
예제 #25
0
        internal WebPathManger(HttpServer server)
        {
            _server = server;
            watcher = new System.IO.FileSystemWatcher(_server.Root);
            watcher.IncludeSubdirectories = true;
            watcher.Changed            += Watcher_event;
            watcher.Created            += Watcher_event;
            watcher.Renamed            += Watcher_event;
            watcher.Deleted            += Watcher_event;
            watcher.EnableRaisingEvents = true;

            root = _server.Root;
            findPath(root);
        }
예제 #26
0
        public Geofence()
        {
            Init();

            if (fsw == null)
            {
                fsw = new System.IO.FileSystemWatcher(FileManager.GetExecutingPath(), "*.csv");
                fsw.NotifyFilter = System.IO.NotifyFilters.LastWrite;
                fsw.Changed     += Fsw_Changed;
                // fsw.Created += Fsw_Changed;
                // fsw.Renamed += Fsw_Changed;
                fsw.EnableRaisingEvents = true;
            }
        }
예제 #27
0
        static void Main(string[] args)
        {
            System.IO.FileSystemWatcher w = new System.IO.FileSystemWatcher(@"c:\temp", "*.txt");
            w.EnableRaisingEvents = true;
            // bind en metode til w.Changed
            w.Changed += ShowChanged;
            w.Created += (s, e) => { Console.WriteLine("Oprettet " + e.FullPath); };
            w.Deleted += (s, e) => Console.WriteLine("Slettet " + e.Name);
            w.Renamed += (s, e) => Console.WriteLine("Omdøbt " + e.Name);

            do
            {
            } while (true);
        }
예제 #28
0
        /// <summary>
        /// Конструктор сервиса
        /// </summary>
        public WinService()
        {
            InitializeComponent();

            watcher = new System.IO.FileSystemWatcher()
            {
                Path = @"C:\Users\Student\Documents"
            };
            // Единый обработчик событий файловой системы
            watcher.Changed += watcher_Event;
            watcher.Created += watcher_Event;
            watcher.Deleted += watcher_Event;
            watcher.Renamed += watcher_Event;
        }
예제 #29
0
        } // End FileSystemWatcher_Deleted

        public static void FileSystemWatcher_Disposed(object sender, System.EventArgs e)
        {
            System.IO.FileSystemWatcher fileSystemWatcher = (System.IO.FileSystemWatcher)sender;

            if (fileSystemWatcher != null)
            {
                fileSystemWatcher.Created -= FileSystemWatcher_Created;
                fileSystemWatcher.Renamed -= FileSystemWatcher_Renamed;
                fileSystemWatcher.Changed -= FileSystemWatcher_Changed;
                fileSystemWatcher.Deleted -= FileSystemWatcher_Deleted;
            } // End if (fileSystemWatcher != null)

            System.Console.WriteLine("called on dispose");
        } // End FileSystemWatcher_Disposed
예제 #30
0
        // https://github.com/Tondas/LetsEncrypt
        // https://blogs.akamai.com/2018/10/best-practices-for-ultra-low-latency-streaming-using-chunked-encoded-and-chunk-transferred-cmaf.html
        // https://www.monitis.com/blog/how-to-log-to-postgresql-with-syslog-ng/
        // https://github.com/sshnet/SSH.NET
        // https://labs.rebex.net/syslog
        // https://github.com/moovspace/HotSsl
        // https://github.com/jchristn/WatsonSyslogServer
        // https://github.com/dotnet/aspnetcore/discussions/28238#discussioncomment-142844
        // https://learn.akamai.com/en-us/webhelp/media-services-live/media-services-live-encoder-compatibility-testing-and-qualification-guide-v4.0/GUID-A7D10A31-F4BC-49DD-92B2-8A5BA409BAFE.html#:~:text=The%20transmission%20ends%20when%20a%20zero%2Dlength%20chunk%20is%20received.&text=The%20Content%2DLength%20header%20is,regular%20chunk%20with%20zero%20length.
        // https://www.drunkcode.net/en/posts/2020/6/10/parsing-with-ReadOnlySpan-and-first-try-of-OBJ-reader

        public static void Main(string[] args)
        {
            using (System.IO.FileSystemWatcher watcher = new System.IO.FileSystemWatcher())
            {
                // listenOptions.UseHttps("testCert.pfx", "testPassword");
                watcher.NotifyFilter = System.IO.NotifyFilters.Size
                                       | System.IO.NotifyFilters.LastWrite
                                       | System.IO.NotifyFilters.CreationTime
                                       | System.IO.NotifyFilters.FileName // Needed if text-file is changed with Visual Studio ...
                ;

                CreateHostBuilder(args, watcher).Build().Run();
            } // End Using watcher
        }     // End Sub Main
        public void Start()
        {
            DataBase.Current.AfterInsert += AutomatedTask_AfterInsert;

            //run btsync
            Service.StartService();

            //make sure Directory exists
            var commandDirectory = (from d in DataBase.Current.Set <Directory>() where d.Name == CommandDirectoryName select d).SingleOrDefault <Directory>();

            if (commandDirectory == null)
            {
                commandDirectory      = new Directory();
                commandDirectory.Name = "OKHOSTING.ERP.HR.AutomatedTask";
                DataBase.Current.Set <Directory>().Add(commandDirectory);
            }

            //make sure the current computer is registered
            var currentComputer = Computer.GetCurrentComputer();

            //make sure command's SharedDirectory exist
            var localSharedDirectory = (from sd in DataBase.Current.Set <SharedDirectory>() where sd.Computer == currentComputer && sd.Directory == commandDirectory select sd).SingleOrDefault <SharedDirectory>();

            if (!System.IO.Directory.Exists(CommandDirectoryPath))
            {
                System.IO.Directory.CreateDirectory(CommandDirectoryPath);
            }

            if (localSharedDirectory == null)
            {
                localSharedDirectory           = new SharedDirectory();
                localSharedDirectory.Computer  = currentComputer;
                localSharedDirectory.Directory = commandDirectory;
                localSharedDirectory.Path      = CommandDirectoryPath;
                DataBase.Current.Set <Directory>().Add(commandDirectory);
            }

            DataBase.Current.SaveChanges();

            SharedDirectory.SyncDirectories();

            //listen for commands
            System.IO.FileSystemWatcher watcher = new System.IO.FileSystemWatcher();
            watcher.Path                = CommandDirectoryPath;
            watcher.Filter              = "*.*";
            watcher.Created            += CommandFile_Created;
            watcher.EnableRaisingEvents = true;

            System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);
        }
예제 #32
0
        private static void InitializeFileWatch()
        {
            string globalContent = FlatRedBall.IO.FileManager.RelativeDirectory + "content/globalcontent/";

            if (System.IO.Directory.Exists(globalContent))
            {
                watcher                     = new System.IO.FileSystemWatcher();
                watcher.Path                = globalContent;
                watcher.NotifyFilter        = System.IO.NotifyFilters.LastWrite;
                watcher.Filter              = "*.*";
                watcher.Changed            += HandleFileChanged;
                watcher.EnableRaisingEvents = true;
            }
        }
예제 #33
0
 internal void CheckWatcher()
 {
     if (watcher==null) watcher = new System.IO.FileSystemWatcher();
       watcher.EnableRaisingEvents = false;
       System.Windows.MessageBox.Show(
     string.Format(Info==null?"wtf?":Info.FullName,Info==null ? "wtf":Info.Directory.Name)
        );
       watcher.Path=Info.Directory.FullName;
       watcher.Filter = Info.Name;
       watcher.NotifyFilter = System.IO.NotifyFilters.LastWrite;
       watcher.Changed -= watcher_Changed;
       watcher.Changed += watcher_Changed;
       watcher.EnableRaisingEvents = true;
 }
예제 #34
0
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.label1 = new System.Windows.Forms.Label();
			this.newItemListBox = new System.Windows.Forms.ListBox();
			this.chunkFileSystemWatcher = new System.IO.FileSystemWatcher();
			this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
			((System.ComponentModel.ISupportInitialize)(this.chunkFileSystemWatcher)).BeginInit();
			this.SuspendLayout();
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(24, 24);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(624, 23);
			this.label1.TabIndex = 0;
			this.label1.Text = "Watching: ";
			// 
			// newItemListBox
			// 
			this.newItemListBox.Location = new System.Drawing.Point(24, 64);
			this.newItemListBox.Name = "newItemListBox";
			this.newItemListBox.ScrollAlwaysVisible = true;
			this.newItemListBox.Size = new System.Drawing.Size(616, 186);
			this.newItemListBox.TabIndex = 1;
			// 
			// chunkFileSystemWatcher
			// 
			this.chunkFileSystemWatcher.EnableRaisingEvents = true;
			this.chunkFileSystemWatcher.Filter = "*.xml";
			this.chunkFileSystemWatcher.Path = "C:\\Documents and Settings\\Administrator\\My Documents\\test hot";
			this.chunkFileSystemWatcher.SynchronizingObject = this;
			this.chunkFileSystemWatcher.Created += new System.IO.FileSystemEventHandler(this.NewChunkEvent);
			// 
			// sqlConnection1
			// 
			this.sqlConnection1.ConnectionString = "workstation id=\"SONY-PDS1L39IGJ\";packet size=4096;integrated security=SSPI;data s" +
				"ource=\"(local)\\NetSDK\";persist security info=False;initial catalog=MediaWatch";
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(664, 273);
			this.Controls.Add(this.newItemListBox);
			this.Controls.Add(this.label1);
			this.Name = "Form1";
			this.Text = "This hot folder watcher will be a service!";
			((System.ComponentModel.ISupportInitialize)(this.chunkFileSystemWatcher)).EndInit();
			this.ResumeLayout(false);

		}
예제 #35
0
파일: Program.cs 프로젝트: SylviH/KursusOpg
        static void Main(string[] args)
        {
            System.IO.FileSystemWatcher fileSystemWatcher = new System.IO.FileSystemWatcher(@"C:\temp", "*.txt");
            fileSystemWatcher.EnableRaisingEvents = true;
            fileSystemWatcher.Changed            += FileSystemWatcher_Changed;
            fileSystemWatcher.Created            += FileSystemWatcher_Created;
            //Denne er lavet på hurtigere måde
            fileSystemWatcher.Deleted += (s, e) => { Console.WriteLine("Slettet " + "" + e.FullPath); };


            do
            {
            } while (true);
        }
예제 #36
0
        }     // End Sub Main

        // https://github.com/dotnet/aspnetcore/discussions/28238
        // https://github.com/aspnet/KestrelHttpServer/issues/2103
        // https://ayende.com/blog/181281-A/building-a-lets-encrypt-acme-v2-client
        // https://weblog.west-wind.com/posts/2016/feb/22/using-lets-encrypt-with-iis-on-windows
        // https://medium.com/@MaartenSikkema/automatically-request-and-use-lets-encrypt-certificates-in-dotnet-core-9d0d152a59b5
        // https://github.com/dotnet/aspnetcore/issues/1190
        // https://docs.microsoft.com/en-us/aspnet/core/fundamentals/servers/kestrel?view=aspnetcore-5.0#code-try-30
        public static IHostBuilder CreateHostBuilder(string[] args, System.IO.FileSystemWatcher watcher)
        {
            // Microsoft.AspNetCore.Server.IIS

            return(Host
                   .CreateDefaultBuilder(args)
                   .ConfigureWebHostDefaults(
                       delegate(IWebHostBuilder webBuilder)
            {
#if false
                // https://docs.microsoft.com/en-us/aspnet/core/fundamentals/servers/kestrel?view=aspnetcore-5.0#code-try-30
                webBuilder.ConfigureKestrel(
                    delegate(
                        WebHostBuilderContext builderContext
                        , Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerOptions serverOptions)
                {
                    // https://github.com/dotnet/aspnetcore/pull/24286
                    // From config-file with reload on change
                    // serverOptions.Configure(builderContext.Configuration.GetSection("Kestrel"), reloadOnChange: false);

                    // On Linux, CipherSuitesPolicy can be used to filter TLS handshakes on a per-connection basis:
                    serverOptions.ConfigureHttpsDefaults(Configuration.Kestrel.Https.HttpsDefaults);             // End ConfigureHttpsDefaults

                    // serverOptions.Listen(System.Net.IPAddress.Loopback, 5001,
                    serverOptions.ListenAnyIP(5005,
                                              delegate(Microsoft.AspNetCore.Server.Kestrel.Core.ListenOptions listenOptions)
                    {
                        Configuration.Kestrel.Https.ListenAnyIP(listenOptions, watcher);
                    }
                                              ); // End ListenAnyIp
                }
                    );                           // End ConfigureKestrel
#endif

                // https://developers.redhat.com/blog/2018/07/24/improv-net-core-kestrel-performance-linux/
                webBuilder.UseLinuxTransport();

                /*
                 * if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Windows))
                 * {
                 *  webBuilder.UseIISIntegration();
                 * }
                 * else webBuilder.UseKestrel();
                 */

                webBuilder.UseStartup <Startup>()
                // .UseApplicationInsights()
                ;
            })); // End ConfigureWebHostDefaults
        } // End Function CreateHostBuilder
예제 #37
0
파일: Program.cs 프로젝트: Larsrd/Opgaver
        static void Main(string[] args)
        {
            System.IO.FileSystemWatcher watcher = new System.IO.FileSystemWatcher(@"C:\temp", "*.txt");
            watcher.EnableRaisingEvents = true;

            //inkluder evt en af to nedenstående, som sørger for at eventen kun registreres
            watcher.NotifyFilter = System.IO.NotifyFilters.FileName | System.IO.NotifyFilters.Size; // fyrer kun hvis størrelsen har ændret sig
            //watcher.NotifyFilter = System.IO.NotifyFilters.FileName | System.IO.NotifyFilters.LastWrite; //fyrer hvis der gemmes, men desværre to gange!

            watcher.Changed += Watcher_Changed;
            while (true)
            {
            }
        }
예제 #38
0
        public Tab()
        {
            title                                = new WrapPanel();
            titleText                            = new Label();
            titleText.Content                    = "New File";
            titleText.Width                      = 110;
            titleText.Height                     = 34;
            titleText.VerticalAlignment          = VerticalAlignment.Top;
            titleText.VerticalContentAlignment   = VerticalAlignment.Center;
            titleText.HorizontalContentAlignment = HorizontalAlignment.Center;
            titleText.FontFamily                 = Tab.fontFamilySegoeUI;
            titleText.IsTabStop                  = true;
            Microsoft.Windows.Shell.WindowChrome.SetIsHitTestVisibleInChrome(titleText, /*isHitTestable*/ true);
            title.Children.Add(titleText);

            Separator seperator = new Separator();

            seperator.Width      = 5;
            seperator.Visibility = Visibility.Hidden;
            title.Children.Add(seperator);

            closeButton        = new Image();
            closeButton.Width  = 8;
            closeButton.Height = 8;
            BitmapImage closeImage = new BitmapImage();

            closeImage.BeginInit();
            closeImage.UriSource = new Uri("pack://application:,,,/Bend;component/Images/Close-dot.png");
            closeImage.EndInit();
            closeButton.Source = closeImage;
            closeButton.Margin = new Thickness(0, 6, 0, 0);
            Microsoft.Windows.Shell.WindowChrome.SetIsHitTestVisibleInChrome(closeButton, /*isHitTestable*/ true);
            title.Children.Add(closeButton);

            Microsoft.Windows.Shell.WindowChrome.SetIsHitTestVisibleInChrome(title, /*isHitTestable*/ true);

            textEditor = new TextEditor();
            textEditor.HorizontalAlignment = HorizontalAlignment.Stretch;
            textEditor.Margin             = new Thickness(0);
            textEditor.VerticalAlignment  = VerticalAlignment.Stretch;
            textEditor.ShowLineNumbers    = true;
            textEditor.FontFamily         = Tab.fontFamilyConsolas;
            textEditor.FontSize           = 14;
            textEditor.PreviewMouseWheel += Tab.EditorPreviewMouseWheel;
            textEditor.PreviewKeyDown    += Tab.EditorPreviewKeyDown;

            this.fileChangedWatcher = null;
            this.lastFileChangeTime = 1;
            this.LoadOptions();
        }
예제 #39
0
 public FileSystem(string root)
 {
     RootFolder = new Folder(root);
     RootFolder.Read();
     watcher = new System.IO.FileSystemWatcher(RootFolder.Path)
     {
         NotifyFilter = System.IO.NotifyFilters.LastWrite | System.IO.NotifyFilters.FileName | System.IO.NotifyFilters.DirectoryName | System.IO.NotifyFilters.Size | System.IO.NotifyFilters.CreationTime
     };
     watcher.IncludeSubdirectories = true;
     watcher.EnableRaisingEvents   = true;
     watcher.Changed += ChangedFile;
     watcher.Deleted += ChangedFile;
     watcher.Created += ChangedFile;
     watcher.Renamed += ChangedFile;
 }
예제 #40
0
        public VolumeMonitor( string path )
        {
            mWatcher = new System.IO.FileSystemWatcher( path );

            mWatcher.NotifyFilter = System.IO.NotifyFilters.FileName | System.IO.NotifyFilters.LastWrite | System.IO.NotifyFilters.DirectoryName;

            mWatcher.Changed += new System.IO.FileSystemEventHandler( mWatcher_Changed );
            mWatcher.Created += new System.IO.FileSystemEventHandler( mWatcher_Created );
            mWatcher.Deleted += new System.IO.FileSystemEventHandler( mWatcher_Deleted );
            mWatcher.Renamed += new System.IO.RenamedEventHandler( mWatcher_Renamed );
            mWatcher.Error += new System.IO.ErrorEventHandler( mWatcher_Error );

            mWatcher.IncludeSubdirectories = true;
            mWatcher.EnableRaisingEvents = true;
        }
예제 #41
0
        public VolumeMonitor(string path)
        {
            mWatcher = new System.IO.FileSystemWatcher(path);

            mWatcher.NotifyFilter = System.IO.NotifyFilters.FileName | System.IO.NotifyFilters.LastWrite | System.IO.NotifyFilters.DirectoryName;

            mWatcher.Changed += new System.IO.FileSystemEventHandler(mWatcher_Changed);
            mWatcher.Created += new System.IO.FileSystemEventHandler(mWatcher_Created);
            mWatcher.Deleted += new System.IO.FileSystemEventHandler(mWatcher_Deleted);
            mWatcher.Renamed += new System.IO.RenamedEventHandler(mWatcher_Renamed);
            mWatcher.Error   += new System.IO.ErrorEventHandler(mWatcher_Error);

            mWatcher.IncludeSubdirectories = true;
            mWatcher.EnableRaisingEvents   = true;
        }
예제 #42
0
        static RenderPass()
        {
            m_Watcher = new System.IO.FileSystemWatcher
            {
                Path = "../../shaders/"/*, Filter = "*.glsl"*/,
                NotifyFilter = System.IO.NotifyFilters.LastWrite | System.IO.NotifyFilters.LastAccess | System.IO.NotifyFilters.FileName
            };

            m_Watcher.EnableRaisingEvents = true;
            System.IO.FileSystemEventHandler hnd = (sender, e) => m_FileManipulated(e.Name);
            m_Watcher.Renamed += (sender, e) => m_FileManipulated(e.Name);
            m_Watcher.Changed += hnd;
            m_Watcher.Created += hnd;
            m_Watcher.Deleted += hnd;
        }
예제 #43
0
        static void Main(string[] args)
        {
            Console.WriteLine();
            System.IO.FileSystemWatcher w = new System.IO.FileSystemWatcher(@"c:\temp", "*.txt");
            w.EnableRaisingEvents = true;
            w.NotifyFilter        = System.IO.NotifyFilters.FileName | System.IO.NotifyFilters.Size;
            w.Created            += (s, e) => Console.WriteLine("Filen {0} oprettes", e.Name);
            w.Deleted            += (s, e) => Console.WriteLine("Filen {0} slettes", e.Name);
            w.Changed            += (s, e) => Console.WriteLine("Filen {0} ændres", e.Name);


            do
            {
            } while (true);
        }
 public void app_closed(object sender, System.EventArgs e)
 {
     if (!readOnly)
     {
         monitor.Changed -= docChanged;
         monitor.EnableRaisingEvents = false;
         monitor.Dispose();
         monitor = null;
         readOnly = true;
         long time = System.IO.File.GetLastWriteTime(file_path).Ticks;
         if (time > last_change)
             saveFile();
     }
     DocumentOpener.RemoveDirectory(DocumentOpener.app_path + "/" + this.storage_id);
     closed = true;
 }
예제 #45
0
        public CsvProvider(string fileName)
        {
            _fullPath = fileName;
            _cache = new Dictionary<int, CheckListItem>();
            _isStorageChanged = true;

            string path = System.IO.Path.GetDirectoryName(fileName);
            _name = System.IO.Path.GetFileName(fileName);

            // create FS watcher
            _watcher = new System.IO.FileSystemWatcher(path, "*" + System.IO.Path.GetExtension(fileName));
            _watcher.NotifyFilter = System.IO.NotifyFilters.LastWrite;
            _watcher.IncludeSubdirectories = false;
            _watcher.Changed += watcher_Changed;
            _watcher.EnableRaisingEvents = true;
        }
        /// <summary>
        /// 设置Config监控
        /// </summary>
        /// <param name="sectionName"></param>
        /// <param name="path"></param>
        public void SetupWacher()
        {
            if (_watcher == null)
            {
                lock (_lockObj)
                {
                    if (_watcher == null)
                    {
                        _watcher = new System.IO.FileSystemWatcher(System.IO.Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, folder));
                        _watcher.Filter = "*.*";
                        _watcher.NotifyFilter = System.IO.NotifyFilters.LastWrite;

                        _watcher.EnableRaisingEvents = true;
                        _watcher.Changed += new System.IO.FileSystemEventHandler(_watcher_Changed);
                    }
                }
            }
        }
예제 #47
0
		public void CreateWatcher()
		{
			watcher = new System.IO.FileSystemWatcher();
			watcher.Path = @"c:\temp\";
			watcher.NotifyFilter =
					System.IO.NotifyFilters.Size |
					System.IO.NotifyFilters.FileName |
					System.IO.NotifyFilters.DirectoryName |
					System.IO.NotifyFilters.CreationTime |
					System.IO.NotifyFilters.LastAccess |
					System.IO.NotifyFilters.LastWrite;

			watcher.Filter = "*.*";
			watcher.Changed += watcher_Changed;
			watcher.Created += watcher_Changed;
			watcher.Deleted += watcher_Changed;
			watcher.Renamed += new System.IO.RenamedEventHandler(watcher_Renamed);
		}
예제 #48
0
        public MainWindow()
        {
            InitializeComponent();

              Thumbnails = new List<HudWindows.ThumbnailViewWindow>();
              Backdrops = new List<HudWindows.BackdropWindow>();
              Backdrops.Add(new HudWindows.BackdropWindow());
              Backdrops.ForEach((b) => b.Show());

              Topmost = true;

              fsMessages.Items.Add(String.Format("Watching: {0}\n", Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)));
              fsMessages.SelectedIndex = 0;

              Watcher = new System.IO.FileSystemWatcher(System.Environment.GetFolderPath(Environment.SpecialFolder.UserProfile));
              Watcher.IncludeSubdirectories = true;
              Watcher.Created += (sender, e) => this.Dispatcher.Invoke(new Action<object, System.IO.FileSystemEventArgs>(FileChangedEvent), sender, e);
              Watcher.Deleted += (sender, e) => this.Dispatcher.Invoke(new Action<object, System.IO.FileSystemEventArgs>(FileChangedEvent), sender, e);
              Watcher.Changed += (sender, e) => this.Dispatcher.Invoke(new Action<object, System.IO.FileSystemEventArgs>(FileChangedEvent), sender, e);
              Watcher.Renamed += (sender, e) => this.Dispatcher.Invoke(new Action<object, System.IO.RenamedEventArgs>(FileRenamedEvent), sender, e);
              Watcher.EnableRaisingEvents = true;
        }
        public DiffUpdateBackgroundParser(ITextBuffer textBuffer, ITextBuffer documentBuffer, TaskScheduler taskScheduler, ITextDocumentFactoryService textDocumentFactoryService, IGitCommands commands)
            : base(textBuffer, taskScheduler, textDocumentFactoryService)
        {
            _documentBuffer = documentBuffer;
            _commands = commands;
            ReparseDelay = TimeSpan.FromMilliseconds(500);

            ITextDocument textDocument;
            if (TextDocumentFactoryService.TryGetTextDocument(TextBuffer, out textDocument))
            {
                GitFileStatusTracker tracker = new GitFileStatusTracker(Path.GetDirectoryName(textDocument.FilePath));
                if (tracker.HasGitRepository && tracker.Repository.Resolve(Constants.HEAD) != null)
                {
                    _watcher = new FileSystemWatcher(tracker.Repository.Directory.GetAbsolutePath());
                    _watcher.IncludeSubdirectories = true;
                    _watcher.Changed += HandleFileSystemChanged;
                    _watcher.Created += HandleFileSystemChanged;
                    _watcher.Deleted += HandleFileSystemChanged;
                    _watcher.Renamed += HandleFileSystemChanged;
                    _watcher.EnableRaisingEvents = true;
                }
            }
        }
예제 #50
0
        internal static ConfigReader Create()
        {
            if (_DbConfigReader != null)
                return _DbConfigReader;

            if (watcher == null)
            {
                watcher = new System.IO.FileSystemWatcher();
                watcher.Path = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Config");
                watcher.Filter = "*.config";
                watcher.Changed += new System.IO.FileSystemEventHandler(watcher_Changed);
                watcher.IncludeSubdirectories = true;
                watcher.EnableRaisingEvents = true;
            }

            _Mutex.WaitOne();
            if (_DbConfigReader == null)
                _DbConfigReader = new ConfigReader();
            _Mutex.ReleaseMutex();

            return _DbConfigReader;
        }
 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;
 }
예제 #52
0
 /// <summary>
 ///   Initializes a new instance of the <see cref="T:Rothko.FileSystemWatcher"/> class.
 /// </summary>
 public FileSystemWatcher()
 {
     inner = new System.IO.FileSystemWatcher();
     HookEvents();
 }
예제 #53
0
        void CreateWatcher(string folder_path)
        {
            if ( folder_path.Contains (".app/") || folder_path.EndsWith(".app"))
                return;
            Console.WriteLine (DateTime.Now.ToUniversalTime ()+" - Creating a watcher to "+folder_path+"\n");
            System.IO.DirectoryInfo d = new System.IO.DirectoryInfo (folder_path);

            System.IO.FileSystemWatcher f = new System.IO.FileSystemWatcher(d.FullName, "*.*");
            f.NotifyFilter = System.IO.NotifyFilters.DirectoryName | System.IO.NotifyFilters.FileName | System.IO.NotifyFilters.LastWrite;
            f.Changed += HandleChanges;
            f.Deleted += HandleChanges;
            f.Created += HandleChanges;
            f.EnableRaisingEvents = true;

            foreach (System.IO.DirectoryInfo dir in d.GetDirectories())
                CreateWatcher (dir.FullName);

            watchers.Add (f);
        }
예제 #54
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;
            }
        }
예제 #55
0
 /// <summary>
 ///   Initializes a new instance of the <see cref="T:Rothko.FileSystemWatcher"/> class, given the
 ///   specified directory to monitor.
 /// </summary>
 /// <param name="path">
 ///   The directory to monitor, in standard or Universal Naming Convention (UNC) notation.
 /// </param>
 /// <exception cref="T:System.ArgumentNullException">
 ///   The <paramref name="path"/> parameter is null.
 /// </exception>
 /// <exception cref="T:System.ArgumentException">
 ///   The <paramref name="path"/> parameter is an empty string ("").
 ///   -or- The path specified through the <paramref name="path"/> parameter does not exist.
 /// </exception>
 /// <exception cref="T:System.IO.PathTooLongException"><paramref name="path"/> is too long.</exception>
 public FileSystemWatcher(string path)
 {
     inner = new System.IO.FileSystemWatcher(path);
     HookEvents();
 }
예제 #56
0
        /// <summary>
        /// Constructs a new SingleInstance object
        /// </summary>
        /// <param name="appname">The application name</param>
        /// <param name="basefolder">The folder in which the control file structure is placed</param>
        public SingleInstance(string appname, string basefolder)
        {
            if (!System.IO.Directory.Exists(basefolder))
                System.IO.Directory.CreateDirectory(basefolder);

            m_controldir = System.IO.Path.Combine(basefolder, CONTROL_DIR);
            if (!System.IO.Directory.Exists(m_controldir))
                System.IO.Directory.CreateDirectory(m_controldir);

            m_lockfilename = System.IO.Path.Combine(m_controldir, CONTROL_FILE);
            m_file = null;
			
			System.IO.Stream temp_fs = null;

			try
            {
				if (Library.Utility.Utility.IsClientLinux)
					temp_fs = UnixSupport.File.OpenExclusive(m_lockfilename, System.IO.FileAccess.Write);
				else
					temp_fs = System.IO.File.Open(m_lockfilename, System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.None);
				
				if (temp_fs != null)
				{
					System.IO.StreamWriter sw = new System.IO.StreamWriter(temp_fs);
					sw.WriteLine(System.Diagnostics.Process.GetCurrentProcess().Id);
					sw.Flush();
					//Do not dispose sw as that would dispose the stream
					m_file = temp_fs;
				}
            }
            catch
            {
				if (temp_fs != null)
					try { temp_fs.Dispose(); }
					catch {}
            }

            //If we have write access
            if (m_file != null)
            {
                m_filewatcher = new System.IO.FileSystemWatcher(m_controldir);
                m_filewatcher.Created += new System.IO.FileSystemEventHandler(m_filewatcher_Created);
                m_filewatcher.EnableRaisingEvents = true;

                DateTime startup = System.IO.File.GetLastWriteTime(m_lockfilename);

                //Clean up any files that were created before the app launched
                foreach(string s in System.IO.Directory.GetFiles(m_controldir))
                    if (s != m_lockfilename && System.IO.File.GetCreationTime(s) < startup)
                        try { System.IO.File.Delete(s); }
                        catch { }
            }
            else
            {
                //Wait for the initial process to signal that the filewatcher is activated
                int retrycount = 5;
                while (retrycount > 0 && new System.IO.FileInfo(m_lockfilename).Length == 0)
                {
                    System.Threading.Thread.Sleep(500);
                    retrycount--;
                }

                //HACK: the unix file lock does not allow us to read the file length when the file is locked
                if (new System.IO.FileInfo(m_lockfilename).Length == 0)
                    if (!Library.Utility.Utility.IsClientLinux)
                        throw new Exception("The file was locked, but had no data");

                //Notify the other process that we have started
                string filename = System.IO.Path.Combine(m_controldir, COMM_FILE_PREFIX + Guid.NewGuid().ToString());

                //Write out the commandline arguments
                string[] cmdargs = System.Environment.GetCommandLineArgs();
                using (System.IO.StreamWriter sw = new System.IO.StreamWriter(Library.Utility.Utility.IsClientLinux ? UnixSupport.File.OpenExclusive(filename, System.IO.FileAccess.Write) : new System.IO.FileStream(filename, System.IO.FileMode.CreateNew, System.IO.FileAccess.Write, System.IO.FileShare.None)))
                    for (int i = 1; i < cmdargs.Length; i++) //Skip the first, as that is the filename
                        sw.WriteLine(cmdargs[i]);

                //Wait for the other process to delete the file, indicating that it is processed
                retrycount = 5;
                while (retrycount > 0 && System.IO.File.Exists(filename))
                {
                    System.Threading.Thread.Sleep(500);
                    retrycount--;
                }

                //This may happen if the other process is closing as we write the command
                if (System.IO.File.Exists(filename))
                {
                    //Try to clean up, so the other process does not spuriously show this
                    try { System.IO.File.Delete(filename); }
                    catch { }

                    throw new Exception("The lock file was locked, but the locking process did not respond to the start command");
                }
            }
        }
예제 #57
0
 /// <summary>
 ///   Initializes a new instance of the <see cref="T:Rothko.FileSystemWatcher"/> class, given the
 ///   specified directory and type of files to monitor.
 /// </summary>
 /// <param name="path">
 ///   The directory to monitor, in standard or Universal Naming Convention (UNC) notation.
 /// </param>
 /// <param name="filter">
 ///   The type of files to watch. For example, "*.txt" watches for changes to all text files.
 /// </param>
 /// <exception cref="T:System.ArgumentNullException">
 ///   The <paramref name="path"/> parameter is null.
 ///   -or- The <paramref name="filter"/> parameter is null.
 /// </exception>
 /// <exception cref="T:System.ArgumentException">
 ///   The <paramref name="path"/> parameter is an empty string ("").
 ///   -or- The path specified through the <paramref name="path"/> parameter does not exist.
 /// </exception>
 /// <exception cref="T:System.IO.PathTooLongException"><paramref name="path"/> is too long.</exception>
 public FileSystemWatcher(string path, string filter)
 {
     inner = new System.IO.FileSystemWatcher(path, filter);
     HookEvents();
 }
        /// <summary>
        /// Loads the contents of the named StringTemplate.
        /// </summary>
        /// <param name="templateName">Name of the StringTemplate to load</param>
        /// <returns>
        /// The contexts of the named StringTemplate or null if the template wasn't found
        /// </returns>
        /// <exception cref="TemplateLoadException">Thrown if error prevents successful template load</exception>
        protected override string InternalLoadTemplateContents(string templateName)
        {
            string templateText = null;
            string templateLocation = null;

            try
            {
                //templateLocation = Path.Combine(LocationRoot, GetLocationFromTemplateName(templateName));
                templateLocation = string.Format("{0}/{1}", LocationRoot, GetLocationFromTemplateName(templateName)).Replace('\\', '/');
                StreamReader br;
                try
                {
                    br = new StreamReader(templateLocation, encoding);
                }
                catch(FileNotFoundException)
                {
                    return null;
                }
                catch(DirectoryNotFoundException)
                {
                    return null;
                }
                catch(Exception ex)
                {
                    throw new TemplateLoadException("Cannot open template file: " + templateLocation, ex);
                }

                try
                {
                    templateText = br.ReadToEnd();
                    if ((templateText != null) && (templateText.Length > 0))
                    {
                        //templateText = templateText.Trim();

                        if (filesWatcher == null)
                        {
                            filesWatcher = new FileSystemWatcher(LocationRoot, "*.st");
                            //filesWatcher.InternalBufferSize *= 2;
                            filesWatcher.NotifyFilter =
                                NotifyFilters.LastWrite
                                | NotifyFilters.Attributes
                                | NotifyFilters.Security
                                | NotifyFilters.Size
                                | NotifyFilters.CreationTime
                                | NotifyFilters.DirectoryName
                                | NotifyFilters.FileName;
                            filesWatcher.IncludeSubdirectories = true;
                            filesWatcher.Changed += new FileSystemEventHandler(OnChanged);
                            filesWatcher.Deleted += new FileSystemEventHandler(OnChanged);
                            filesWatcher.Created += new FileSystemEventHandler(OnChanged);
                            filesWatcher.Renamed += new RenamedEventHandler(OnRenamed);
                            filesWatcher.EnableRaisingEvents = true;
                        }
                    }
                    fileSet.Remove(templateLocation);
                }
                finally
                {
                    if (br != null) ((IDisposable)br).Dispose();
                    br = null;
                }
            }
            catch (ArgumentException ex)
            {
                string message;
                if (templateText == null)
                    message = string.Format("Invalid file character encoding: {0}", encoding);
                else
                    message = string.Format("The location root '{0}' and/or the template name '{1}' is invalid.", LocationRoot, templateName);

                throw new TemplateLoadException(message, ex);
            }
            catch (IOException ex)
            {
                throw new TemplateLoadException("Cannot close template file: " + templateLocation, ex);
            }
            return templateText;
        }
예제 #59
0
        private void Main_Load(object sender, EventArgs e)
        {
            siL = SmallListForFATX;
            liL = LargeListForFATX;

            #region TreeView Shit
            treeView1.ImageList = siL;
            treeView1.MouseDown += new MouseEventHandler(treeView1_MouseDown);
            treeView1.ContextMenu = treeview_ContextMenu;
            treeview_ContextMenu.Popup += new EventHandler(treeview_ContextMenu_Popup);
            treeView1.BeforeLabelEdit += new NodeLabelEditEventHandler(treeView1_BeforeLabelEdit);
            treeView1.AfterLabelEdit += new NodeLabelEditEventHandler(treeView1_AfterLabelEdit);
            #endregion

            #region ListView Shit
            listView1.SmallImageList = siL;
            listView1.LargeImageList = liL;
            listView1.ContextMenu = listview_ContextMenu;
            listView1.DoubleClick += new EventHandler(listView1_DoubleClick);
            listView1.ColumnClick += new ColumnClickEventHandler(listView1_ColumnClick);
            listView1.KeyDown += new KeyEventHandler(listView1_KeyDown);
            listView1.ListViewItemSorter = lvwColumnSorter;
            listView1.BeforeLabelEdit += new LabelEditEventHandler(listView1_BeforeLabelEdit);
            listView1.AfterLabelEdit += new LabelEditEventHandler(listView1_AfterLabelEdit);
            listView1.DragDrop += new DragEventHandler(listView1_DragDrop);
            listView1.DragOver += new DragEventHandler(listView1_DragOver);
            listView1.MouseDown += new MouseEventHandler(listView1_MouseDown);
            listView1.MouseUp += new MouseEventHandler(listView1_MouseUp);
            listView1.KeyUp += new KeyEventHandler(listView1_KeyUp);
            listView1.KeyPress += new KeyPressEventHandler(listView1_KeyPress);
            listview_ContextMenu.Popup += new EventHandler(listview_ContextMenu_Popup);
            listView1.ItemDrag += new ItemDragEventHandler(listView1_ItemDrag);
            listView1.DragEnter += new DragEventHandler(listView1_DragEnter);
            #endregion

            this.Resize += new EventHandler(Main_Resize);
            this.Shown += new EventHandler(Main_Shown);
            this.FormClosing += new FormClosingEventHandler(Main_FormClosing);

            // Initialize our drive watchers
            List<System.IO.FileSystemWatcher> fsL = new List<System.IO.FileSystemWatcher>();
            foreach (string s in Environment.GetLogicalDrives())
            {
                try
                {
                    System.IO.FileSystemWatcher Watcher = new System.IO.FileSystemWatcher(s);
                    // Set the file created event
                    Watcher.Created += new System.IO.FileSystemEventHandler(Watcher_Created);
                    fsL.Add(Watcher);
                }
                catch { continue; }
            }
            Watchers = fsL.ToArray();

            DoStartup();
        }
 public FileWatcher(string directory, string file_glob)
 {
     myWatcher = new System.IO.FileSystemWatcher(directory, file_glob);
 }