コード例 #1
0
 private SimpleFileSystemWatcher GetFileSystemWatcher(string path)
 {
     using (_tracer.Step(String.Format("Creating FileSystemWatcher on path {0}", path)))
     {
         var simpleFileSystemWatcher = new SimpleFileSystemWatcher(path)
         {
             EnableRaisingEvents = true,
             IncludeSubdirectories = false
         };
         simpleFileSystemWatcher.GeneralDirectoryChanged += NotifyGroup;
         EnsureFileSystemWatchersMax();
         return simpleFileSystemWatcher;
     }
 }
コード例 #2
0
ファイル: FileSystemHub.cs プロジェクト: sofianhn/kudu
 private SimpleFileSystemWatcher GetFileSystemWatcher(string path)
 {
     using (_tracer.Step(String.Format("Creating FileSystemWatcher on path {0}", path)))
     {
         var simpleFileSystemWatcher = new SimpleFileSystemWatcher(path)
         {
             EnableRaisingEvents   = true,
             IncludeSubdirectories = false
         };
         simpleFileSystemWatcher.GeneralDirectoryChanged += NotifyGroup;
         EnsureFileSystemWatchersMax();
         return(simpleFileSystemWatcher);
     }
 }
コード例 #3
0
ファイル: TasteCommand.cs プロジェクト: peterchou3788/pretzel
        protected override Task <int> Execute(TasteCommandArguments arguments)
        {
            Tracing.Info("taste - testing a site locally");

            var context = Generator.BuildContext(arguments.Source, arguments.Destination, arguments.Drafts);

            if (arguments.CleanTarget && FileSystem.Directory.Exists(context.OutputFolder))
            {
                FileSystem.Directory.Delete(context.OutputFolder, true);
            }

            if (string.IsNullOrWhiteSpace(arguments.Template))
            {
                arguments.DetectFromDirectory(TemplateEngines.Engines, context);
            }

            engine = TemplateEngines[arguments.Template];

            if (engine == null)
            {
                Tracing.Info("template engine {0} not found - (engines: {1})", arguments.Template,
                             string.Join(", ", TemplateEngines.Engines.Keys));

                return(Task.FromResult(1));
            }

            engine.Initialize();
            engine.Process(context, skipFileOnError: true);
            foreach (var t in Transforms)
            {
                t.Transform(context);
            }

            using (var watcher = new SimpleFileSystemWatcher(arguments.Destination))
            {
                watcher.OnChange(arguments.Source, file => WatcherOnChanged(file, arguments));

                using (var w = new WebHost(arguments.Destination, new FileContentProvider(), Convert.ToInt32(arguments.Port)))
                {
                    try
                    {
                        w.Start();
                    }
                    catch (System.Net.Sockets.SocketException)
                    {
                        Tracing.Info("Port {0} is already in use", arguments.Port);

                        return(Task.FromResult(1));
                    }

                    var url = string.Format("http://localhost:{0}/", arguments.Port);
                    if (arguments.LaunchBrowser)
                    {
                        Tracing.Info("Opening {0} in default browser...", url);
                        try
                        {
                            System.Diagnostics.Process.Start(url);
                        }
                        catch (Exception)
                        {
                            Tracing.Info("Failed to launch {0}.", url);
                        }
                    }
                    else
                    {
                        Tracing.Info("Browse to {0} to view the site.", url);
                    }

                    Tracing.Info("Press 'Q' to stop the web host...");
                    ConsoleKeyInfo key;
                    do
                    {
                        key = Console.ReadKey();
                    }while (key.Key != ConsoleKey.Q);
                    Console.WriteLine();
                }
            }

            return(Task.FromResult(0));
        }
コード例 #4
0
#pragma warning restore 649

        public void Execute(IEnumerable <string> arguments)
        {
            Tracing.Info("taste - testing a site locally");

            parameters.Parse(arguments);

            var context = Generator.BuildContext(parameters.Path, parameters.IncludeDrafts);

            if (string.IsNullOrWhiteSpace(parameters.Template))
            {
                parameters.DetectFromDirectory(templateEngines.Engines, context);
            }

            engine = templateEngines[parameters.Template];

            if (engine == null)
            {
                Tracing.Info(string.Format("template engine {0} not found - (engines: {1})", parameters.Template,
                                           string.Join(", ", templateEngines.Engines.Keys)));

                return;
            }

            engine.Initialize();
            engine.Process(context, skipFileOnError: true);
            foreach (var t in transforms)
            {
                t.Transform(context);
            }
            var watcher = new SimpleFileSystemWatcher();

            watcher.OnChange(parameters.Path, WatcherOnChanged);

            var w = new WebHost(engine.GetOutputDirectory(parameters.Path), new FileContentProvider(), Convert.ToInt32(parameters.Port));

            w.Start();

            var url = string.Format("http://localhost:{0}/", parameters.Port);

            if (parameters.LaunchBrowser)
            {
                Tracing.Info(string.Format("Opening {0} in default browser...", url));
                try
                {
                    Process.Start(url);
                }
                catch (Exception)
                {
                    Tracing.Info(string.Format("Failed to launch {0}.", url));
                }
            }
            else
            {
                Tracing.Info(string.Format("Browse to {0} to view the site.", url));
            }

            Tracing.Info("Press 'Q' to stop the web host...");
            ConsoleKeyInfo key;

            do
            {
                key = Console.ReadKey();
            }while (key.Key != ConsoleKey.Q);
            Console.WriteLine();
        }
コード例 #5
0
        protected async override Task <int> Execute(TasteCommandArguments arguments)
        {
            Tracing.Info("taste - testing a site locally");

            var context = Generator.BuildContext(arguments.Source, arguments.Destination, arguments.Drafts);

            if (arguments.CleanTarget && FileSystem.Directory.Exists(context.OutputFolder))
            {
                FileSystem.Directory.Delete(context.OutputFolder, true);
            }

            if (string.IsNullOrWhiteSpace(arguments.Template))
            {
                arguments.DetectFromDirectory(TemplateEngines.Engines, context);
            }

            engine = TemplateEngines[arguments.Template];

            if (engine == null)
            {
                Tracing.Info("template engine {0} not found - (engines: {1})", arguments.Template,
                             string.Join(", ", TemplateEngines.Engines.Keys));

                return(1);
            }

            engine.Initialize();
            engine.Process(context, skipFileOnError: true);
            foreach (var t in Transforms)
            {
                t.Transform(context);
            }

            using (var watcher = new SimpleFileSystemWatcher(arguments.Destination))
            {
                watcher.OnChange(arguments.Source, file => WatcherOnChanged(file, arguments));

                using (var w = new AspNetCoreWebHost(arguments.Destination, Convert.ToInt32(arguments.Port), arguments.Debug))
                {
                    try
                    {
                        await w.Start();
                    }
                    catch (IOException ex) when(ex.InnerException is AddressInUseException)
                    {
                        Tracing.Info("Port {0} is already in use", arguments.Port);

                        return(1);
                    }

                    var url = string.Format("http://localhost:{0}/", arguments.Port);
                    if (arguments.LaunchBrowser)
                    {
                        Tracing.Info("Opening {0} in default browser...", url);
                        try
                        {
                            // How to launch browser on netcore
                            // https://github.com/dotnet/corefx/issues/10361
                            var psi = new System.Diagnostics.ProcessStartInfo
                            {
                                FileName        = url,
                                UseShellExecute = true
                            };
                            System.Diagnostics.Process.Start(psi);
                        }
                        catch (Exception)
                        {
                            Tracing.Info("Failed to launch {0}.", url);
                        }
                    }
                    else
                    {
                        Tracing.Info("Browse to {0} to view the site.", url);
                    }

                    Tracing.Info("Press 'Q' to stop the web host...");
                    ConsoleKeyInfo key;
                    do
                    {
                        key = Console.ReadKey();
                    }while (key.Key != ConsoleKey.Q);
                    Console.WriteLine();
                }
            }

            return(0);
        }