public static void DisplayIpaddress() { try { const string linkDescription = @"您可以通过以下链接访问:"; Log4Log.Info(linkDescription); ContentLog.WriteLine(linkDescription); var hostName = Dns.GetHostName(); var ipHostEntry = Dns.GetHostEntry(hostName); ipHostEntry .AddressList .Where(item => item.AddressFamily == AddressFamily.InterNetwork) .ToList() .ForEach(item => { var url = string.Format(@"http://{0}", item.ToString()); Log4Log.Info(url); ContentLog.WriteLine(url); }); } catch (Exception ex) { var exceptionMessage = @"获取本机IP出错:" + ex.Message; Log4Log.Info(exceptionMessage); ContentLog.WriteLine(exceptionMessage); } }
public HttpResponseMessage Open(string path) { Log4Log.Info(Request.ToString()); ContentLog.WriteLine(Request.ToString()); var httpResponseMessage = Request.Response(path); Log4Log.Info(httpResponseMessage.ToString()); ContentLog.WriteLine(httpResponseMessage.ToString()); return(httpResponseMessage); }
public HttpResponseMessage Index() { var path = Application.StartupPath; Log4Log.Info(Request.ToString()); ContentLog.WriteLine(Request.ToString()); var httpResponseMessage = Request.Response(path); Log4Log.Info(httpResponseMessage.ToString()); ContentLog.WriteLine(httpResponseMessage.ToString()); return(httpResponseMessage); }
protected override void OnLoad(EventArgs e) { ContentLog.Initialize(richTextBoxContent); var autoRunEnable = AutoRun.GetRunEnable(); AutoRunToolStripMenuItem.Checked = autoRunEnable; var thread = new Thread(() => { var config = new HttpSelfHostConfiguration(DomainName.Value); config.Routes.MapHttpRoute( "Default", "{controller}/{action}", new { controller = "Home", action = "Index" } ); using (var httpSelfHostServer = new HttpSelfHostServer(config)) { try { httpSelfHostServer.OpenAsync().Wait(); IpaddressHelper.DisplayIpaddress(); Log4Log.Info(@"Started"); ContentLog.WriteLine(@"Started"); } catch (Exception ex) { MessageBox.Show(ex.ToString()); Log4Log.Info(ex.ToString()); ContentLog.WriteLine(ex.ToString()); } while (true) { Thread.Sleep(10); } } // ReSharper disable once FunctionNeverReturns }) { IsBackground = true }; thread.Start(); }
public HttpResponseMessage Download(string filePath) { Log4Log.Info(Request.ToString()); ContentLog.WriteLine(Request.ToString()); var fileName = Path.GetFileName(filePath); if (File.Exists(filePath) == false) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "文件未找到")); } var response = new HttpResponseMessage(HttpStatusCode.OK); try { var fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read); { response.Content = new StreamContent(fileStream); response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = fileName }; } Log4Log.Info(response.ToString()); ContentLog.WriteLine(response.ToString()); return(response); } catch (Exception exception) { var httpResponseMessage = Request.CreateErrorResponse(HttpStatusCode.NotFound, exception.Message); Log4Log.Info(httpResponseMessage.ToString()); ContentLog.WriteLine(httpResponseMessage.ToString()); return(httpResponseMessage); } }