J2EEUtils.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. //
  2. // (C) 2005 Mainsoft Corporation (http://www.mainsoft.com)
  3. //
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining
  6. // a copy of this software and associated documentation files (the
  7. // "Software"), to deal in the Software without restriction, including
  8. // without limitation the rights to use, copy, modify, merge, publish,
  9. // distribute, sublicense, and/or sell copies of the Software, and to
  10. // permit persons to whom the Software is furnished to do so, subject to
  11. // the following conditions:
  12. //
  13. // The above copyright notice and this permission notice shall be
  14. // included in all copies or substantial portions of the Software.
  15. //
  16. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  17. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  18. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  19. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  20. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  21. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  22. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  23. //
  24. using System;
  25. using System.Web.Util;
  26. using System.IO;
  27. using [email protected];
  28. using vmw.common;
  29. using System.ComponentModel;
  30. using System.Threading;
  31. namespace System.Web.J2EE
  32. {
  33. internal static class J2EEUtils
  34. {
  35. public static int RunProc(string[] cmd)
  36. {
  37. java.lang.Runtime rt = java.lang.Runtime.getRuntime();
  38. java.lang.Process proc = rt.exec(cmd);
  39. StreamGobbler errorGobbler = new
  40. StreamGobbler(proc.getErrorStream(), "ERROR");
  41. StreamGobbler outputGobbler = new
  42. StreamGobbler(proc.getInputStream(), "OUTPUT");
  43. errorGobbler.start();
  44. outputGobbler.start();
  45. int exitVal = proc.waitFor();
  46. return exitVal;
  47. }
  48. }
  49. public class StreamGobbler : java.lang.Thread
  50. {
  51. java.io.InputStream _is;
  52. String _type;
  53. public StreamGobbler(java.io.InputStream ins, String type)
  54. {
  55. this._is = ins;
  56. this._type = type;
  57. }
  58. public override void run()
  59. {
  60. try
  61. {
  62. java.io.InputStreamReader isr = new java.io.InputStreamReader(_is);
  63. java.io.BufferedReader br = new java.io.BufferedReader(isr);
  64. String line=null;
  65. while ( (line = br.readLine()) != null)
  66. {
  67. #if DEBUG
  68. Console.WriteLine(_type + ">" + line);
  69. #endif
  70. }
  71. }
  72. catch (Exception ex)
  73. {
  74. #if DEBUG
  75. Console.WriteLine(ex);
  76. #endif
  77. }
  78. }
  79. }
  80. }
  81. #region FileSystemWatcher Stub
  82. namespace System.IO
  83. {
  84. [DefaultEvent ("Changed")]
  85. #if NET_2_0
  86. [IODescription ("")]
  87. #endif
  88. public class FileSystemWatcher : Component, ISupportInitialize
  89. {
  90. public FileSystemWatcher ()
  91. : this (String.Empty) {
  92. }
  93. public FileSystemWatcher (string path)
  94. : this (path, "*.*") {
  95. }
  96. public FileSystemWatcher (string path, string filter) {
  97. }
  98. #region Properties
  99. [DefaultValue (false)]
  100. [IODescription ("Flag to indicate if this instance is active")]
  101. public bool EnableRaisingEvents {
  102. get { return false; }
  103. set { }
  104. }
  105. [DefaultValue ("*.*")]
  106. [IODescription ("File name filter pattern")]
  107. [RecommendedAsConfigurable (true)]
  108. [TypeConverter ("System.Diagnostics.Design.StringValueConverter, " + Consts.AssemblySystem_Design)]
  109. public string Filter {
  110. get { return "*.*"; }
  111. set { }
  112. }
  113. [DefaultValue (false)]
  114. [IODescription ("Flag to indicate we want to watch subdirectories")]
  115. public bool IncludeSubdirectories {
  116. get { return false; }
  117. set { }
  118. }
  119. [Browsable (false)]
  120. [DefaultValue (8192)]
  121. public int InternalBufferSize {
  122. get { return 8192; }
  123. set { }
  124. }
  125. [DefaultValue (NotifyFilters.FileName | NotifyFilters.DirectoryName | NotifyFilters.LastWrite)]
  126. [IODescription ("Flag to indicate which change event we want to monitor")]
  127. public NotifyFilters NotifyFilter {
  128. get { return NotifyFilters.FileName | NotifyFilters.DirectoryName | NotifyFilters.LastWrite; }
  129. set { }
  130. }
  131. [DefaultValue ("")]
  132. [IODescription ("The directory to monitor")]
  133. [RecommendedAsConfigurable (true)]
  134. [TypeConverter ("System.Diagnostics.Design.StringValueConverter, " + Consts.AssemblySystem_Design)]
  135. [Editor ("System.Diagnostics.Design.FSWPathEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
  136. public string Path {
  137. get { return String.Empty; }
  138. set { }
  139. }
  140. [DefaultValue (null)]
  141. [IODescription ("The object used to marshal the event handler calls resulting from a directory change")]
  142. #if NET_2_0
  143. [Browsable (false)]
  144. #endif
  145. public ISynchronizeInvoke SynchronizingObject {
  146. get { return null; }
  147. set { }
  148. }
  149. #endregion // Properties
  150. #region Methods
  151. protected override void Dispose (bool disposing) {
  152. base.Dispose (disposing);
  153. }
  154. enum EventType
  155. {
  156. FileSystemEvent,
  157. ErrorEvent,
  158. RenameEvent
  159. }
  160. private void RaiseEvent (Delegate ev, EventArgs arg, EventType evtype) {
  161. if (ev == null)
  162. return;
  163. if (SynchronizingObject == null) {
  164. Delegate [] delegates = ev.GetInvocationList ();
  165. if (evtype == EventType.RenameEvent) {
  166. foreach (RenamedEventHandler d in delegates) {
  167. d.BeginInvoke (this, (RenamedEventArgs) arg, null, null);
  168. }
  169. }
  170. else if (evtype == EventType.ErrorEvent) {
  171. foreach (ErrorEventHandler d in delegates) {
  172. d.BeginInvoke (this, (ErrorEventArgs) arg, null, null);
  173. }
  174. }
  175. else {
  176. foreach (FileSystemEventHandler d in delegates) {
  177. d.BeginInvoke (this, (FileSystemEventArgs) arg, null, null);
  178. }
  179. }
  180. return;
  181. }
  182. SynchronizingObject.BeginInvoke (ev, new object [] { this, arg });
  183. }
  184. protected void OnChanged (FileSystemEventArgs e) {
  185. RaiseEvent (Changed, e, EventType.FileSystemEvent);
  186. }
  187. protected void OnCreated (FileSystemEventArgs e) {
  188. RaiseEvent (Created, e, EventType.FileSystemEvent);
  189. }
  190. protected void OnDeleted (FileSystemEventArgs e) {
  191. RaiseEvent (Deleted, e, EventType.FileSystemEvent);
  192. }
  193. protected void OnError (ErrorEventArgs e) {
  194. RaiseEvent (Error, e, EventType.ErrorEvent);
  195. }
  196. protected void OnRenamed (RenamedEventArgs e) {
  197. RaiseEvent (Renamed, e, EventType.RenameEvent);
  198. }
  199. public WaitForChangedResult WaitForChanged (WatcherChangeTypes changeType) {
  200. return WaitForChanged (changeType, Timeout.Infinite);
  201. }
  202. public WaitForChangedResult WaitForChanged (WatcherChangeTypes changeType, int timeout) {
  203. return new WaitForChangedResult ();
  204. }
  205. #endregion
  206. #region Events and Delegates
  207. [IODescription ("Occurs when a file/directory change matches the filter")]
  208. public event FileSystemEventHandler Changed;
  209. [IODescription ("Occurs when a file/directory creation matches the filter")]
  210. public event FileSystemEventHandler Created;
  211. [IODescription ("Occurs when a file/directory deletion matches the filter")]
  212. public event FileSystemEventHandler Deleted;
  213. [Browsable (false)]
  214. public event ErrorEventHandler Error;
  215. [IODescription ("Occurs when a file/directory rename matches the filter")]
  216. public event RenamedEventHandler Renamed;
  217. #endregion // Events and Delegates
  218. #region ISupportInitialize Members
  219. public void BeginInit () {
  220. }
  221. public void EndInit () {
  222. }
  223. #endregion
  224. }
  225. }
  226. #endregion