Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: visual_studio/NativeClientVSAddIn/NativeClientVSAddIn/WebServer.cs

Issue 10836143: Refactored the VS add-in (Closed) Base URL: https://nativeclient-sdk.googlecode.com/svn/trunk/src
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 namespace NativeClientVSAddIn
6 {
7 using System;
8
9 using EnvDTE;
10 using Microsoft.VisualStudio.VCProjectEngine;
11
12 /// <summary>
13 /// This class contains the functionality related to the web server which host s the web page
14 /// during debugging.
15 /// </summary>
16 public class WebServer : IDisposable
17 {
18 /// <summary>
19 /// The web server port to default to if the user does not specify one.
20 /// </summary>
21 private const int DefaultWebServerPort = 5103;
22
23 /// <summary>
24 /// Holds the main web server process.
25 /// </summary>
26 private System.Diagnostics.Process webServer_;
27
28 /// <summary>
29 /// Captures output from the web server.
30 /// </summary>
31 private OutputWindowPane webServerOutputPane_;
32
33 /// <summary>
34 /// Keeps track of if dispose has been called.
35 /// </summary>
36 private bool disposed_ = false;
37
38 /// <summary>
39 /// Constructs the WebServer, starts the web server process.
40 /// </summary>
41 /// <param name="outputWindowPane">Existing output pane to send web server o utput to.</param>
42 /// <param name="properties">PropertyManager that is set to a valid project/ platform.</param>
43 public WebServer(OutputWindowPane outputWindowPane, PropertyManager properti es)
44 {
45 if (outputWindowPane == null)
46 {
47 throw new ArgumentNullException("outputWindowPane");
48 }
49
50 if (properties == null)
51 {
52 throw new ArgumentNullException("properties");
53 }
54
55 webServerOutputPane_ = outputWindowPane;
56
57 int webServerPort;
58 if (!int.TryParse(properties.WebServerPort, out webServerPort))
59 {
60 webServerPort = DefaultWebServerPort;
61 }
62
63 string webServerExecutable = "python.exe";
64 string webServerArguments = string.Format(
65 "{0}\\examples\\httpd.py --no_dir_check {1}", properties.SDKRootDirect ory, webServerPort);
66
67 try
68 {
69 webServer_ = new System.Diagnostics.Process();
70 webServer_.StartInfo.CreateNoWindow = true;
71 webServer_.StartInfo.UseShellExecute = false;
72 webServer_.StartInfo.RedirectStandardOutput = true;
73 webServer_.StartInfo.RedirectStandardError = true;
74 webServer_.StartInfo.FileName = webServerExecutable;
75 webServer_.StartInfo.Arguments = webServerArguments;
76 webServer_.StartInfo.WorkingDirectory = properties.ProjectDirectory;
77 webServer_.OutputDataReceived += WebServerMessageReceive;
78 webServer_.ErrorDataReceived += WebServerMessageReceive;
79 webServer_.Start();
80 webServer_.BeginOutputReadLine();
81 webServer_.BeginErrorReadLine();
82 }
83 catch (Exception e)
84 {
85 webServerOutputPane_.OutputString(Strings.WebServerStartFail + "\n");
86 webServerOutputPane_.OutputString("Exception: " + e.Message + "\n");
87 webServerOutputPane_.Activate();
88 }
89
90 webServerOutputPane_.Clear();
91 webServerOutputPane_.OutputString(Strings.WebServerStartMessage + "\n");
92 webServerOutputPane_.Activate();
93 }
94
95 /// <summary>
96 /// Finalizer. Should clean up unmanaged resources. Should not be overriden in derived classes.
97 /// </summary>
98 ~WebServer()
99 {
100 Dispose(false);
101 }
102
103 /// <summary>
104 /// Disposes the object when called by user code (not directly by garbage co llector).
105 /// </summary>
106 public void Dispose()
107 {
108 Dispose(true);
109 GC.SuppressFinalize(this);
110 }
111
112 /// <summary>
113 /// Disposes the object. If disposing is false then this has been called by garbage collection,
114 /// and we shouldn't reference managed objects.
115 /// </summary>
116 /// <param name="disposing">True if user called Dispose, false if garbage co llection.</param>
117 protected virtual void Dispose(bool disposing)
118 {
119 if (!disposed_ && disposing)
120 {
121 // Managed resource clean up.
122 Utility.EnsureProcessKill(ref webServer_);
123 webServerOutputPane_.OutputString(Strings.WebServerStopMessage);
124 webServerOutputPane_.Activate();
125 }
126
127 disposed_ = true;
128 }
129
130 /// <summary>
131 /// Receives output from the web server process to display in the Visual Stu dio UI.
132 /// </summary>
133 /// <param name="sender">The parameter is not used.</param>
134 /// <param name="e">Contains the data to display.</param>
135 private void WebServerMessageReceive(object sender, System.Diagnostics.DataR eceivedEventArgs e)
136 {
137 webServerOutputPane_.OutputString(e.Data + "\n");
138 }
139 }
140 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698