Example #1
0
        public static void Web(Config config, Action action)
        {
            Directory.CreateDirectory(config.WebRoot);
            var zippath = PathTools.Combine(config.WebRoot, "Daemon.StaticWebServer.zip");

            if (File.Exists(zippath))
            {
                File.Delete(zippath);
            }
            Logger.Trace("Zipping to {0}", zippath);
            ZipTools.ZipFromFiles(zippath, ExecutableTools.Directory()
                                  , "Daemon.StaticWebServer.exe"
                                  , "SharpDaemon.dll"
                                  );
            var process = new DaemonProcess(new DaemonProcess.Args
            {
                Executable = ExecutableTools.Relative("Daemon.StaticWebServer.exe"),
                Arguments  = $"EndPoint={config.WebEP} Root=\"{config.WebRoot}\"",
            });

            Logger.Trace("Web process {0} {1} {2} {3}", process.Id, process.Name, process.Info.FileName, process.Info.Arguments);
            var reader = new Runner(new Runner.Args {
                ThreadName = "WEB"
            });

            reader.Run(() =>
            {
                var line = process.ReadLine();
                while (line != null)
                {
                    Logger.Trace("<w {0}", line);
                    line = process.ReadLine();
                }
            });
            using (reader)
            {
                using (process)
                {
                    action();
                }
            }
        }