public void addHandler(handler_type handler)
        {
            var _handler = new System.IO.FileSystemEventHandler((o, a) => handler());

            myWatcher.Changed += _handler;
            myWatcher.Created += _handler;
        }
Пример #2
0
 public void UnloadWatch()
 {
     Changed -= new System.IO.FileSystemEventHandler(OnChanged);
     Created -= new System.IO.FileSystemEventHandler(OnChanged);
     Deleted -= new System.IO.FileSystemEventHandler(OnChanged);
     Renamed -= new System.IO.RenamedEventHandler(OnRenamed);
     this.EnableRaisingEvents = false;
 }
Пример #3
0
 private void InitWatch()
 {
     this.NotifyFilter =
         System.IO.NotifyFilters.FileName |
         System.IO.NotifyFilters.DirectoryName;
     this.Filter = "*.*";
     Changed    += new System.IO.FileSystemEventHandler(OnChanged);
     Created    += new System.IO.FileSystemEventHandler(OnChanged);
     Deleted    += new System.IO.FileSystemEventHandler(OnChanged);
     Renamed    += new System.IO.RenamedEventHandler(OnRenamed);
     this.EnableRaisingEvents   = true;
     this.IncludeSubdirectories = true;
 }
 //Automatically raise event in calling thread when _fsw.SynchronizingObject is set. Ex: When used as a component in Win Forms.
 //TODO: remove redundancy. I don't understand how to cast the specific *EventHandler to a generic Delegate, EventHandler, Action or whatever.
 private void InvokeHandler(FileSystemEventHandler eventHandler, FileSystemEventArgs e)
 {
     if (eventHandler != null)
     {
         if (_containedFSW.SynchronizingObject != null && this._containedFSW.SynchronizingObject.InvokeRequired)
         {
             _containedFSW.SynchronizingObject.BeginInvoke(eventHandler, new object[] { this, e });
         }
         else
         {
             eventHandler(this, e);
         }
     }
 }
Пример #5
0
        } // End Function ServerCertificateSelector

        public static void ListenAnyIP(
            Microsoft.AspNetCore.Server.Kestrel.Core.ListenOptions listenOptions
            , System.IO.FileSystemWatcher watcher
            )
        {
            System.Collections.Concurrent.ConcurrentDictionary <string, System.Security.Cryptography.X509Certificates.X509Certificate2> certs =
                new System.Collections.Concurrent.ConcurrentDictionary <string, System.Security.Cryptography.X509Certificates.X509Certificate2>(
                    System.StringComparer.OrdinalIgnoreCase
                    );

            watcher.Filters.Add("localhost.yml");
            watcher.Filters.Add("example.com.yaml");
            watcher.Filters.Add("sub.example.com.yaml");

            System.IO.FileSystemEventHandler onChange = delegate(object sender, System.IO.FileSystemEventArgs e)
            {
                CertificateFileChanged(certs, sender, e);
            };


            watcher.Changed += new System.IO.FileSystemEventHandler(onChange);
            watcher.Created += new System.IO.FileSystemEventHandler(onChange);
            watcher.Deleted += new System.IO.FileSystemEventHandler(onChange);
            // watcher.Renamed += new System.IO.RenamedEventHandler(OnRenamed);

            watcher.EnableRaisingEvents = true;


            listenOptions.UseHttps(
                delegate(Microsoft.AspNetCore.Server.Kestrel.Https.HttpsConnectionAdapterOptions httpsOptions)
            {
                UseHttps(certs, httpsOptions);

                httpsOptions.ServerCertificateSelector =
                    delegate(Microsoft.AspNetCore.Connections.ConnectionContext connectionContext, string name)
                {
                    return(ServerCertificateSelector(certs, connectionContext, name));
                };
            }
                ); // End ListenOptions.UseHttps
        } // End Sub ListenAnyIP
 public void addHandler(handler_type handler)
 {
     var _handler = new System.IO.FileSystemEventHandler((o, a) => handler());
     myWatcher.Changed += _handler;
     myWatcher.Created += _handler;
 }
        } // End Sub ConfigureEndpointDefaults

        public static void HttpsDefaults(
            Microsoft.AspNetCore.Server.Kestrel.Https.HttpsConnectionAdapterOptions listenOptions
            , System.IO.FileSystemWatcher watcher
            )
        {
            bool isNotWindows = !System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Windows);

            System.Collections.Concurrent.ConcurrentDictionary <string, CertHackStore> certs =
                new System.Collections.Concurrent.ConcurrentDictionary <string, CertHackStore>(
                    System.StringComparer.OrdinalIgnoreCase
                    );

            string cert = SecretManager.GetSecret <string>("ssl_cert");
            string key  = SecretManager.GetSecret <string>("ssl_key");

            certs["localhost"] = CertHackStore.FromPem(cert, key);


            // watcher.Filters.Add("localhost.yml");
            // watcher.Filters.Add("example.com.yaml");
            // watcher.Filters.Add("sub.example.com.yaml");

            System.IO.FileSystemEventHandler onChange = delegate(object sender, System.IO.FileSystemEventArgs e)
            {
                CertificateFileChanged(certs, sender, e);
            };


            watcher.Changed += new System.IO.FileSystemEventHandler(onChange);
            watcher.Created += new System.IO.FileSystemEventHandler(onChange);
            watcher.Deleted += new System.IO.FileSystemEventHandler(onChange);
            // watcher.Renamed += new System.IO.RenamedEventHandler(OnRenamed);

            if (!System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Windows))
            {
                watcher.EnableRaisingEvents = true;
            }



            listenOptions.ServerCertificateSelector =
                delegate(Microsoft.AspNetCore.Connections.ConnectionContext connectionContext, string name)
            {
                return(ServerCertificateSelector(certs, connectionContext, name));
            };



#if NO_NGINX_FUCKUP
            listenOptions.OnAuthenticate =
                delegate(Microsoft.AspNetCore.Connections.ConnectionContext connectionContext, System.Net.Security.SslServerAuthenticationOptions sslOptions)
            {
                // not supported on Windoze
                if (isNotWindows)
                {
                    sslOptions.CipherSuitesPolicy = new System.Net.Security.CipherSuitesPolicy(
                        new System.Net.Security.TlsCipherSuite[]
                    {
                        System.Net.Security.TlsCipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
                        System.Net.Security.TlsCipherSuite.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
                        System.Net.Security.TlsCipherSuite.TLS_CHACHA20_POLY1305_SHA256,
                        // ...
                    });
                } // End if (!isWindows)
            }     // End Delegate
            ;     // End OnAuthenticate
#endif
        } // End Sub HttpsDefaults