public void Start() { Log.Debug("MPExtended.ServiceHosts.WebMediaPortal starting..."); try { // generate IIS Express config file var generator = new IISConfigGenerator(); generator.PhysicalSitePath = Installation.GetFileLayoutType() == FileLayoutType.Source ? Path.Combine(Installation.GetSourceRootDirectory(), "Applications", "MPExtended.Applications.WebMediaPortal") : Path.Combine(Installation.GetInstallDirectory(MPExtendedProduct.WebMediaPortal), "www"); generator.HostAddresses = HostConfiguration.HostAddresses; generator.Port = HostConfiguration.Port; generator.TemplatePath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "IISExpressTemplate.config"); tempConfigFile = Path.GetTempFileName(); generator.GenerateConfigFile(tempConfigFile); Log.Debug("Saved IIS Express configuration file to {0}", tempConfigFile); // log configuration foreach (var addr in generator.HostAddresses) { Log.Debug("- Listening on {0}:{1}", addr, generator.Port); } // start IIS Express string iisExpress = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), "IIS Express", "iisexpress.exe"); string arguments = String.Format("/systray:0 /config:{0} /site:WebMediaPortal", tempConfigFile); string logPath = Path.Combine(Installation.GetLogDirectory(), String.Format("WebMediaPortalIIS-{0:yyyy_MM_dd}.log", DateTime.Now)); hostProcess = new Process(); hostProcess.StartInfo = new ProcessStartInfo() { FileName = iisExpress, Arguments = arguments, RedirectStandardOutput = true, UseShellExecute = false, CreateNoWindow = true }; hostProcess.Start(); Log.Info("Started IIS Express!"); // read output from IIS Express logThread = new Thread(delegate(object param) { using (StreamReader reader = (StreamReader)param) { Stream file = File.Open(logPath, FileMode.Append, FileAccess.Write, FileShare.Read); using (StreamWriter writer = new StreamWriter(file, Encoding.UTF8, 16 * 1024)) { writer.WriteLine("<process started at {0:yyyy-MM-dd HH:mm:ss} with arguments {1}>", DateTime.Now, arguments); string line; long i = 0; while ((line = reader.ReadLine()) != null) { writer.WriteLine("[{0:yyyy-MM-dd HH:mm:ss}] {1}", DateTime.Now, line); if (i++ % 10 == 0) writer.Flush(); } writer.WriteLine("<process exited at {0:yyyy-MM-dd HH:mm:ss}>", DateTime.Now); } } }); logThread.Start(hostProcess.StandardOutput); } catch (Exception ex) { Log.Fatal("Failed to start IIS Express", ex); } }
public void Start() { Log.Debug("MPExtended.ServiceHosts.WebMediaPortal starting..."); try { // remove some old left-overs from 0.4.x var files = Directory.GetFiles(Installation.GetLogDirectory(), "WebMediaPortalIIS-*.log"); if (files.Any()) { Log.Info("Removing {0} old log files (WebMediaPortalIIS-*.log) from WebMediaPortal 0.4.x", files.Count()); foreach (var file in files) { File.Delete(file); } } // generate IIS Express config file var generator = new IISConfigGenerator(); generator.PhysicalSitePath = Installation.GetFileLayoutType() == FileLayoutType.Source ? Path.Combine(Installation.GetSourceRootDirectory(), "Applications", "MPExtended.Applications.WebMediaPortal") : Path.Combine(Installation.GetInstallDirectory(), "www"); generator.TemplatePath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "IISExpressTemplate.config"); tempConfigFile = Path.GetTempFileName(); generator.GenerateConfigFile(tempConfigFile); Log.Debug("Saved IIS Express configuration file to {0}", tempConfigFile); // lookup IIS Express installation path from registry object iisExpressLocation = null; foreach (var version in new string[] { "7.5", "8.0" }) { iisExpressLocation = RegistryReader.ReadKeyAllViews(RegistryHive.LocalMachine, @"SOFTWARE\Microsoft\IISExpress\" + version, "InstallPath"); if (iisExpressLocation != null && !String.IsNullOrEmpty(iisExpressLocation.ToString().Trim())) { break; } } // lookup IIS Express location string iisExpress = null; string iisExpressDefault = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), "IIS Express", "iisexpress.exe"); if (iisExpressLocation != null && File.Exists(Path.Combine(iisExpressLocation.ToString(), "iisexpress.exe"))) { iisExpress = Path.Combine(iisExpressLocation.ToString(), "iisexpress.exe"); Log.Debug("Using IIS Express installed at {0}", iisExpress); } else if (File.Exists(iisExpressDefault)) { Log.Debug("Using IIS Express at default location {0}", iisExpressDefault); } else { Log.Fatal("IIS Express not found"); return; } // rotate IIS Express logfile if it's too big string logPath = Path.Combine(Installation.GetLogDirectory(), String.Format("WebMediaPortalIIS.log", DateTime.Now)); if (File.Exists(logPath) && new FileInfo(logPath).Length > 1024 * 1024) { string backup = Path.ChangeExtension(logPath, ".bak"); if (File.Exists(backup)) { File.Delete(backup); } File.Move(logPath, backup); } // start IIS Express string arguments = String.Format("/systray:0 /config:{0} /site:WebMediaPortal", tempConfigFile); hostProcess = new Process(); hostProcess.StartInfo = new ProcessStartInfo() { FileName = iisExpress, Arguments = arguments, RedirectStandardOutput = true, UseShellExecute = false, CreateNoWindow = true }; hostProcess.Start(); Log.Info("Started IIS Express!"); // read output from IIS Express logThread = new Thread(delegate(object param) { using (StreamReader reader = (StreamReader)param) { Stream file = File.Open(logPath, FileMode.Append, FileAccess.Write, FileShare.Read); using (StreamWriter writer = new StreamWriter(file, Encoding.UTF8, 16 * 1024)) { writer.WriteLine("<process started at {0:yyyy-MM-dd HH:mm:ss} with arguments {1}>", DateTime.Now, arguments); string line; long i = 0; while ((line = reader.ReadLine()) != null) { writer.WriteLine("[{0:yyyy-MM-dd HH:mm:ss}] {1}", DateTime.Now, line); if (i++ % 10 == 0) { writer.Flush(); } } writer.WriteLine("<process exited at {0:yyyy-MM-dd HH:mm:ss}>", DateTime.Now); } } }); logThread.Start(hostProcess.StandardOutput); } catch (Exception ex) { Log.Fatal("Failed to start IIS Express", ex); } }
public void Start() { Log.Debug("MPExtended.ServiceHosts.WebMediaPortal starting..."); try { // remove some old left-overs from 0.4.x var files = Directory.GetFiles(Installation.GetLogDirectory(), "WebMediaPortalIIS-*.log"); if (files.Any()) { Log.Info("Removing {0} old log files (WebMediaPortalIIS-*.log) from WebMediaPortal 0.4.x", files.Count()); foreach (var file in files) { File.Delete(file); } } // generate IIS Express config file var generator = new IISConfigGenerator(); generator.PhysicalSitePath = Installation.GetFileLayoutType() == FileLayoutType.Source ? Path.Combine(Installation.GetSourceRootDirectory(), "Applications", "MPExtended.Applications.WebMediaPortal") : Path.Combine(Installation.GetInstallDirectory(), "www"); generator.TemplatePath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "IISExpressTemplate.config"); generator.TemporaryPath = Path.Combine(Installation.GetCacheDirectory(), "IISExpress"); tempConfigFile = Path.GetTempFileName(); generator.GenerateConfigFile(tempConfigFile); Log.Debug("Saved IIS Express configuration file to {0}, using {1} as www directory", tempConfigFile, generator.PhysicalSitePath); // lookup IIS Express installation path from registry object iisExpressLocation = null; foreach (var version in new string[] { "7.5" }) { iisExpressLocation = RegistryReader.ReadKeyAllViews(RegistryHive.LocalMachine, @"SOFTWARE\Microsoft\IISExpress\" + version, "InstallPath"); if (iisExpressLocation != null && !String.IsNullOrEmpty(iisExpressLocation.ToString().Trim())) break; } // lookup IIS Express location string iisExpress = null; string iisExpressDefault = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), "IIS Express", "iisexpress.exe"); if (iisExpressLocation != null && File.Exists(Path.Combine(iisExpressLocation.ToString(), "iisexpress.exe"))) { iisExpress = Path.Combine(iisExpressLocation.ToString(), "iisexpress.exe"); Log.Debug("Using IIS Express installed at {0}", iisExpress); } else if (File.Exists(iisExpressDefault)) { Log.Debug("Using IIS Express at default location {0}", iisExpressDefault); } else { Log.Fatal("IIS Express not found"); return; } // rotate IIS Express logfile if it's too big string logPath = Path.Combine(Installation.GetLogDirectory(), String.Format("WebMediaPortalIIS.log", DateTime.Now)); if (File.Exists(logPath) && new FileInfo(logPath).Length > 1024 * 1024) { string backup = Path.ChangeExtension(logPath, ".bak"); if (File.Exists(backup)) { File.Delete(backup); } File.Move(logPath, backup); } // start IIS Express string arguments = String.Format("/systray:0 /config:{0} /site:WebMediaPortal", tempConfigFile); hostProcess = new Process(); hostProcess.StartInfo = new ProcessStartInfo() { FileName = iisExpress, Arguments = arguments, RedirectStandardOutput = true, UseShellExecute = false, CreateNoWindow = true }; hostProcess.Start(); Log.Info("Started IIS Express!"); // read output from IIS Express logThread = new Thread(delegate(object param) { using (StreamReader reader = (StreamReader)param) { Stream file = File.Open(logPath, FileMode.Append, FileAccess.Write, FileShare.Read); using (StreamWriter writer = new StreamWriter(file, Encoding.UTF8, 16 * 1024)) { writer.WriteLine("<process started at {0:yyyy-MM-dd HH:mm:ss} with arguments {1}>", DateTime.Now, arguments); string line; long i = 0; while ((line = reader.ReadLine()) != null) { writer.WriteLine("[{0:yyyy-MM-dd HH:mm:ss}] {1}", DateTime.Now, line); if (i++ % 10 == 0) writer.Flush(); } writer.WriteLine("<process exited at {0:yyyy-MM-dd HH:mm:ss}>", DateTime.Now); } } }); logThread.Start(hostProcess.StandardOutput); } catch (Exception ex) { Log.Fatal("Failed to start IIS Express", ex); } }
public void Start() { Log.Debug("MPExtended.ServiceHosts.WebMediaPortal starting..."); try { // generate IIS Express config file var generator = new IISConfigGenerator(); generator.PhysicalSitePath = Installation.GetFileLayoutType() == FileLayoutType.Source ? Path.Combine(Installation.GetSourceRootDirectory(), "Applications", "MPExtended.Applications.WebMediaPortal") : Path.Combine(Installation.GetInstallDirectory(MPExtendedProduct.WebMediaPortal), "www"); generator.HostAddresses = HostConfiguration.HostAddresses; generator.Port = HostConfiguration.Port; generator.TemplatePath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "IISExpressTemplate.config"); tempConfigFile = Path.GetTempFileName(); generator.GenerateConfigFile(tempConfigFile); Log.Debug("Saved IIS Express configuration file to {0}", tempConfigFile); // log configuration foreach (var addr in generator.HostAddresses) { Log.Debug("- Listening on {0}:{1}", addr, generator.Port); } // start IIS Express string iisExpress = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), "IIS Express", "iisexpress.exe"); string arguments = String.Format("/systray:0 /config:{0} /site:WebMediaPortal", tempConfigFile); string logPath = Path.Combine(Installation.GetLogDirectory(), String.Format("WebMediaPortalIIS-{0:yyyy_MM_dd}.log", DateTime.Now)); hostProcess = new Process(); hostProcess.StartInfo = new ProcessStartInfo() { FileName = iisExpress, Arguments = arguments, RedirectStandardOutput = true, UseShellExecute = false, CreateNoWindow = true }; hostProcess.Start(); Log.Info("Started IIS Express!"); // read output from IIS Express logThread = new Thread(delegate(object param) { using (StreamReader reader = (StreamReader)param) { Stream file = File.Open(logPath, FileMode.Append, FileAccess.Write, FileShare.Read); using (StreamWriter writer = new StreamWriter(file, Encoding.UTF8, 16 * 1024)) { writer.WriteLine("<process started at {0:yyyy-MM-dd HH:mm:ss} with arguments {1}>", DateTime.Now, arguments); string line; long i = 0; while ((line = reader.ReadLine()) != null) { writer.WriteLine("[{0:yyyy-MM-dd HH:mm:ss}] {1}", DateTime.Now, line); if (i++ % 10 == 0) { writer.Flush(); } } writer.WriteLine("<process exited at {0:yyyy-MM-dd HH:mm:ss}>", DateTime.Now); } } }); logThread.Start(hostProcess.StandardOutput); } catch (Exception ex) { Log.Fatal("Failed to start IIS Express", ex); } }