AppResourcesCompiler.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  1. //
  2. // System.Web.Compilation.AppResourceFilesCollection
  3. //
  4. // Authors:
  5. // Marek Habersack ([email protected])
  6. //
  7. // (C) 2006 Marek Habersack
  8. //
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. #if NET_2_0
  30. using System;
  31. using System.CodeDom;
  32. using System.CodeDom.Compiler;
  33. using System.Collections;
  34. using System.Collections.Generic;
  35. using System.Globalization;
  36. using System.IO;
  37. using System.Reflection;
  38. using System.Resources;
  39. using System.Web;
  40. using System.Web.Caching;
  41. using System.Web.Configuration;
  42. using System.Web.Util;
  43. namespace System.Web.Compilation
  44. {
  45. internal class AppResourcesCompiler
  46. {
  47. const string cachePrefix = "@@LocalResourcesAssemblies";
  48. bool isGlobal;
  49. HttpContext context;
  50. AppResourceFilesCollection files;
  51. string tempDirectory;
  52. string TempDirectory {
  53. get {
  54. if (tempDirectory != null)
  55. return tempDirectory;
  56. return (tempDirectory = AppDomain.CurrentDomain.SetupInformation.DynamicBase);
  57. }
  58. }
  59. public AppResourcesCompiler (HttpContext context, bool isGlobal)
  60. {
  61. this.context = context;
  62. this.isGlobal = isGlobal;
  63. this.files = new AppResourceFilesCollection (context, isGlobal);
  64. }
  65. public void Compile ()
  66. {
  67. files.Collect ();
  68. if (!files.HasFiles)
  69. return;
  70. if (isGlobal)
  71. CompileGlobal ();
  72. else
  73. CompileLocal ();
  74. }
  75. void CompileGlobal ()
  76. {
  77. string assemblyPath = FileUtils.CreateTemporaryFile (TempDirectory,
  78. "App_GlobalResources",
  79. "dll",
  80. OnCreateRandomFile) as string;
  81. if (assemblyPath == null)
  82. throw new ApplicationException ("Failed to create global resources assembly");
  83. CompilationSection config = WebConfigurationManager.GetSection ("system.web/compilation") as CompilationSection;
  84. if (config == null || !CodeDomProvider.IsDefinedLanguage (config.DefaultLanguage))
  85. throw new ApplicationException ("Could not get the default compiler.");
  86. CompilerInfo ci = CodeDomProvider.GetCompilerInfo (config.DefaultLanguage);
  87. if (ci == null || !ci.IsCodeDomProviderTypeValid)
  88. throw new ApplicationException ("Failed to obtain the default compiler information.");
  89. CompilerParameters cp = ci.CreateDefaultCompilerParameters ();
  90. cp.OutputAssembly = assemblyPath;
  91. cp.GenerateExecutable = false;
  92. cp.TreatWarningsAsErrors = true;
  93. cp.IncludeDebugInformation = config.Debug;
  94. List <string>[] fileGroups = GroupGlobalFiles (cp);
  95. if (fileGroups == null || fileGroups.Length == 0)
  96. return;
  97. CodeCompileUnit unit = new CodeCompileUnit ();
  98. CodeNamespace ns = new CodeNamespace (null);
  99. ns.Imports.Add (new CodeNamespaceImport ("System"));
  100. ns.Imports.Add (new CodeNamespaceImport ("System.Globalization"));
  101. ns.Imports.Add (new CodeNamespaceImport ("System.Reflection"));
  102. ns.Imports.Add (new CodeNamespaceImport ("System.Resources"));
  103. unit.Namespaces.Add (ns);
  104. CodeDomProvider provider;
  105. provider = ci.CreateProvider ();
  106. if (provider == null)
  107. throw new ApplicationException ("Failed to instantiate the default compiler.");
  108. Dictionary <string,bool> assemblies = new Dictionary<string,bool> ();
  109. foreach (List<string> ls in fileGroups)
  110. DomFromResource (ls [0], unit, assemblies, provider);
  111. foreach (KeyValuePair<string,bool> de in assemblies)
  112. unit.ReferencedAssemblies.Add (de.Key);
  113. AssemblyBuilder abuilder = new AssemblyBuilder (provider);
  114. abuilder.AddCodeCompileUnit (unit);
  115. CompilerResults results = abuilder.BuildAssembly (cp);
  116. if (results.Errors.Count == 0) {
  117. BuildManager.TopLevelAssemblies.Add (results.CompiledAssembly);
  118. HttpContext.AppGlobalResourcesAssembly = results.CompiledAssembly;
  119. } else {
  120. if (context.IsCustomErrorEnabled)
  121. throw new ApplicationException ("An error occurred while compiling global resources.");
  122. throw new CompilationException (null, results.Errors, null);
  123. }
  124. HttpRuntime.WritePreservationFile (results.CompiledAssembly, "App_GlobalResources");
  125. HttpRuntime.EnableAssemblyMapping (true);
  126. }
  127. void CompileLocal ()
  128. {
  129. string path = Path.GetDirectoryName (VirtualPathUtility.ToAbsolute (context.Request.CurrentExecutionFilePath));
  130. if (String.IsNullOrEmpty (path))
  131. throw new ApplicationException ("Unable to determine the request virtual path.");
  132. Assembly cached = GetCachedLocalResourcesAssembly (path);
  133. if (cached != null)
  134. return;
  135. string prefix;
  136. if (path == "/")
  137. prefix = "App_LocalResources.root";
  138. else
  139. prefix = "App_LocalResources" + path.Replace ('/', '.');
  140. string assemblyPath = FileUtils.CreateTemporaryFile (TempDirectory,
  141. prefix,
  142. "dll",
  143. OnCreateRandomFile) as string;
  144. if (assemblyPath == null)
  145. throw new ApplicationException ("Failed to create global resources assembly");
  146. CompilationSection config = WebConfigurationManager.GetSection ("system.web/compilation") as CompilationSection;
  147. if (config == null || !CodeDomProvider.IsDefinedLanguage (config.DefaultLanguage))
  148. throw new ApplicationException ("Could not get the default compiler.");
  149. CompilerInfo ci = CodeDomProvider.GetCompilerInfo (config.DefaultLanguage);
  150. if (ci == null || !ci.IsCodeDomProviderTypeValid)
  151. throw new ApplicationException ("Failed to obtain the default compiler information.");
  152. CompilerParameters cp = ci.CreateDefaultCompilerParameters ();
  153. cp.OutputAssembly = assemblyPath;
  154. cp.GenerateExecutable = false;
  155. cp.TreatWarningsAsErrors = true;
  156. cp.IncludeDebugInformation = config.Debug;
  157. List<AppResourceFileInfo> files = this.files.Files;
  158. foreach (AppResourceFileInfo arfi in files)
  159. GetResourceFile (arfi, cp);
  160. CodeDomProvider provider;
  161. provider = ci.CreateProvider ();
  162. if (provider == null)
  163. throw new ApplicationException ("Failed to instantiate the default compiler.");
  164. AssemblyBuilder abuilder = new AssemblyBuilder (provider);
  165. CompilerResults results = abuilder.BuildAssembly (cp);
  166. if (results.Errors.Count == 0) {
  167. AddAssemblyToCache (path, results.CompiledAssembly);
  168. } else {
  169. if (context.IsCustomErrorEnabled)
  170. throw new ApplicationException ("An error occurred while compiling global resources.");
  171. throw new CompilationException (null, results.Errors, null);
  172. }
  173. }
  174. internal static Assembly GetCachedLocalResourcesAssembly (string path)
  175. {
  176. Dictionary <string, Assembly> cache;
  177. cache = HttpRuntime.Cache[cachePrefix] as Dictionary <string, Assembly>;
  178. if (cache == null || !cache.ContainsKey (path))
  179. return null;
  180. return cache [path];
  181. }
  182. void AddAssemblyToCache (string path, Assembly asm)
  183. {
  184. Cache runtimeCache = HttpRuntime.Cache;
  185. Dictionary <string, Assembly> cache;
  186. cache = runtimeCache[cachePrefix] as Dictionary <string, Assembly>;
  187. if (cache == null)
  188. cache = new Dictionary <string, Assembly> ();
  189. cache [path] = asm;
  190. runtimeCache.Insert (cachePrefix, cache);
  191. }
  192. uint CountChars (char c, string s)
  193. {
  194. uint ret = 0;
  195. foreach (char ch in s) {
  196. if (ch == c)
  197. ret++;
  198. }
  199. return ret;
  200. }
  201. bool IsFileCultureValid (string fileName)
  202. {
  203. string tmp = Path.GetFileNameWithoutExtension (fileName);
  204. tmp = Path.GetExtension (tmp);
  205. if (tmp != null && tmp.Length > 0) {
  206. tmp = tmp.Substring (1);
  207. try {
  208. CultureInfo.GetCultureInfo (tmp);
  209. return true;
  210. } catch {
  211. return false;
  212. }
  213. }
  214. return false;
  215. }
  216. string GetResourceFile (AppResourceFileInfo arfi, CompilerParameters cp)
  217. {
  218. string resfile;
  219. if (arfi.Kind == AppResourceFileKind.ResX)
  220. resfile = CompileResource (arfi);
  221. else
  222. resfile = arfi.Info.FullName;
  223. if (!String.IsNullOrEmpty (resfile))
  224. cp.EmbeddedResources.Add (resfile);
  225. return resfile;
  226. }
  227. List <string>[] GroupGlobalFiles (CompilerParameters cp)
  228. {
  229. List<AppResourceFileInfo> files = this.files.Files;
  230. List<List<string>> groups = new List<List<string>> ();
  231. AppResourcesLengthComparer<List<string>> lcList = new AppResourcesLengthComparer<List<string>> ();
  232. string tmp, s, basename;
  233. uint basedots, filedots;
  234. AppResourceFileInfo defaultFile;
  235. foreach (AppResourceFileInfo arfi in files) {
  236. if (arfi.Kind != AppResourceFileKind.ResX && arfi.Kind != AppResourceFileKind.Resource)
  237. continue;
  238. s = arfi.Info.FullName;
  239. basename = Path.GetFileNameWithoutExtension (s);
  240. basedots = CountChars ('.', basename);
  241. defaultFile = null;
  242. // If there are any files that start with this baseName, we have a default file
  243. foreach (AppResourceFileInfo fi in files) {
  244. if (fi.Seen)
  245. continue;
  246. string s2 = fi.Info.FullName;
  247. if (s2 == null || s == s2)
  248. continue;
  249. tmp = Path.GetFileNameWithoutExtension (s2);
  250. filedots = CountChars ('.', tmp);
  251. if (filedots == basedots + 1 && tmp.StartsWith (basename)) {
  252. if (IsFileCultureValid (s2)) {
  253. // A valid translated file for this name
  254. defaultFile = arfi;
  255. break;
  256. } else {
  257. // This file shares the base name, but the culture is invalid - we must
  258. // ignore it since the name of the generated strongly typed class for this
  259. // resource will clash with the one generated from the default file with
  260. // the given basename.
  261. fi.Seen = true;
  262. }
  263. }
  264. }
  265. if (defaultFile != null) {
  266. List<string> al = new List<string> ();
  267. al.Add (GetResourceFile (arfi, cp));
  268. arfi.Seen = true;
  269. groups.Add (al);
  270. }
  271. }
  272. groups.Sort (lcList);
  273. string tmp2;
  274. // Now find their translated counterparts
  275. foreach (List<string> al in groups) {
  276. s = al [0];
  277. tmp = Path.GetFileNameWithoutExtension (s);
  278. foreach (AppResourceFileInfo arfi in files) {
  279. if (arfi.Seen)
  280. continue;
  281. s = arfi.Info.FullName;
  282. if (s == null)
  283. continue;
  284. tmp2 = arfi.Info.Name;
  285. if (tmp2.StartsWith (tmp)) {
  286. al.Add (GetResourceFile (arfi, cp));
  287. arfi.Seen = true;
  288. }
  289. }
  290. }
  291. // Anything that's left here might be orphans or lone default files.
  292. // For those files we check the part following the last dot
  293. // before the .resx/.resource extensions and test whether it's a registered
  294. // culture or not. If it is not a culture, then we have a
  295. // default file that doesn't have any translations. Otherwise,
  296. // the file is ignored (it's the same thing MS.NET does)
  297. foreach (AppResourceFileInfo arfi in files) {
  298. if (arfi.Seen)
  299. continue;
  300. if (IsFileCultureValid (arfi.Info.FullName))
  301. continue; // Culture found, we reject the file
  302. // A single default file, create a group
  303. List<string> al = new List<string> ();
  304. al.Add (GetResourceFile (arfi, cp));
  305. groups.Add (al);
  306. }
  307. groups.Sort (lcList);
  308. return groups.ToArray ();
  309. }
  310. // CodeDOM generation
  311. void DomFromResource (string resfile, CodeCompileUnit unit, Dictionary <string,bool> assemblies,
  312. CodeDomProvider provider)
  313. {
  314. string fname, nsname, classname;
  315. fname = Path.GetFileNameWithoutExtension (resfile);
  316. nsname = Path.GetFileNameWithoutExtension (fname);
  317. classname = Path.GetExtension (fname);
  318. if (classname == null || classname.Length == 0) {
  319. classname = nsname;
  320. nsname = "Resources";
  321. } else {
  322. if (!nsname.StartsWith ("Resources", StringComparison.InvariantCulture))
  323. nsname = String.Format ("Resources.{0}", nsname);
  324. classname = classname.Substring(1);
  325. }
  326. if (!provider.IsValidIdentifier (nsname) || !provider.IsValidIdentifier (classname))
  327. throw new ApplicationException ("Invalid resource file name.");
  328. CodeNamespace ns = new CodeNamespace (nsname);
  329. CodeTypeDeclaration cls = new CodeTypeDeclaration (classname);
  330. cls.IsClass = true;
  331. cls.TypeAttributes = TypeAttributes.Public | TypeAttributes.Sealed;
  332. CodeMemberField cmf = new CodeMemberField (typeof(CultureInfo), "culture");
  333. cmf.InitExpression = new CodePrimitiveExpression (null);
  334. cmf.Attributes = MemberAttributes.Private | MemberAttributes.Final | MemberAttributes.Static;
  335. cls.Members.Add (cmf);
  336. cmf = new CodeMemberField (typeof(ResourceManager), "resourceManager");
  337. cmf.InitExpression = new CodePrimitiveExpression (null);
  338. cmf.Attributes = MemberAttributes.Private | MemberAttributes.Final | MemberAttributes.Static;
  339. cls.Members.Add (cmf);
  340. // Property: ResourceManager
  341. CodeMemberProperty cmp = new CodeMemberProperty ();
  342. cmp.Attributes = MemberAttributes.Public | MemberAttributes.Final | MemberAttributes.Static;
  343. cmp.Name = "ResourceManager";
  344. cmp.HasGet = true;
  345. cmp.Type = new CodeTypeReference (typeof(ResourceManager));
  346. CodePropertyResourceManagerGet (cmp.GetStatements, resfile, classname);
  347. cls.Members.Add (cmp);
  348. // Property: Culture
  349. cmp = new CodeMemberProperty ();
  350. cmp.Attributes = MemberAttributes.Public | MemberAttributes.Final;
  351. cmp.Attributes = MemberAttributes.Public | MemberAttributes.Final | MemberAttributes.Static;
  352. cmp.Name = "Culture";
  353. cmp.HasGet = true;
  354. cmp.HasSet = true;
  355. cmp.Type = new CodeTypeReference (typeof(CultureInfo));
  356. CodePropertyGenericGet (cmp.GetStatements, "culture", classname);
  357. CodePropertyGenericSet (cmp.SetStatements, "culture", classname);
  358. cls.Members.Add (cmp);
  359. // Add the resource properties
  360. Dictionary<string,bool> imports = new Dictionary<string,bool> ();
  361. try {
  362. ResourceReader res = new ResourceReader (resfile);
  363. foreach (DictionaryEntry de in res) {
  364. Type type = de.Value.GetType ();
  365. if (!imports.ContainsKey (type.Namespace))
  366. imports [type.Namespace] = true;
  367. string asname = new AssemblyName (type.Assembly.FullName).Name;
  368. if (!assemblies.ContainsKey (asname))
  369. assemblies [asname] = true;
  370. cmp = new CodeMemberProperty ();
  371. cmp.Attributes = MemberAttributes.Public | MemberAttributes.Final | MemberAttributes.Static;
  372. cmp.Name = SanitizeResourceName ((string)de.Key);
  373. cmp.HasGet = true;
  374. CodePropertyResourceGet (cmp.GetStatements, (string)de.Key, type, classname);
  375. cmp.Type = new CodeTypeReference (type);
  376. cls.Members.Add (cmp);
  377. }
  378. } catch (Exception ex) {
  379. throw new ApplicationException ("Failed to comipile global resources.", ex);
  380. }
  381. foreach (KeyValuePair<string,bool> de in imports)
  382. ns.Imports.Add (new CodeNamespaceImport(de.Key));
  383. ns.Types.Add (cls);
  384. unit.Namespaces.Add (ns);
  385. }
  386. string SanitizeResourceName (string name)
  387. {
  388. return name.Replace (' ', '_').Replace ('-', '_').Replace ('.', '_');
  389. }
  390. CodeObjectCreateExpression NewResourceManager (string name, string typename)
  391. {
  392. CodeExpression resname = new CodePrimitiveExpression (name);
  393. CodePropertyReferenceExpression asm = new CodePropertyReferenceExpression (
  394. new CodeTypeOfExpression (new CodeTypeReference (typename)),
  395. "Assembly");
  396. return new CodeObjectCreateExpression ("System.Resources.ResourceManager",
  397. new CodeExpression [] {resname, asm});
  398. }
  399. void CodePropertyResourceManagerGet (CodeStatementCollection csc, string resfile, string typename)
  400. {
  401. string name = Path.GetFileNameWithoutExtension (resfile);
  402. CodeStatement st;
  403. CodeExpression exp;
  404. exp = new CodeFieldReferenceExpression (new CodeTypeReferenceExpression (typename), "resourceManager");
  405. st = new CodeConditionStatement (
  406. new CodeBinaryOperatorExpression (
  407. exp,
  408. CodeBinaryOperatorType.IdentityInequality,
  409. new CodePrimitiveExpression (null)),
  410. new CodeStatement [] { new CodeMethodReturnStatement (exp) });
  411. csc.Add (st);
  412. st = new CodeAssignStatement (exp, NewResourceManager (name, typename));
  413. csc.Add (st);
  414. csc.Add (new CodeMethodReturnStatement (exp));
  415. }
  416. void CodePropertyResourceGet (CodeStatementCollection csc, string resname, Type restype, string typename)
  417. {
  418. CodeStatement st = new CodeVariableDeclarationStatement (
  419. typeof (ResourceManager),
  420. "rm",
  421. new CodePropertyReferenceExpression (
  422. new CodeTypeReferenceExpression (typename), "ResourceManager"));
  423. csc.Add (st);
  424. st = new CodeConditionStatement (
  425. new CodeBinaryOperatorExpression (
  426. new CodeVariableReferenceExpression ("rm"),
  427. CodeBinaryOperatorType.IdentityEquality,
  428. new CodePrimitiveExpression (null)),
  429. new CodeStatement [] { new CodeMethodReturnStatement (new CodePrimitiveExpression (null)) });
  430. csc.Add (st);
  431. bool gotstr = (restype == typeof (string));
  432. CodeExpression exp = new CodeMethodInvokeExpression (
  433. new CodeVariableReferenceExpression ("rm"),
  434. gotstr ? "GetString" : "GetObject",
  435. new CodeExpression [] { new CodePrimitiveExpression (resname),
  436. new CodeFieldReferenceExpression (
  437. new CodeTypeReferenceExpression (typename), "culture") });
  438. st = new CodeVariableDeclarationStatement (
  439. restype,
  440. "obj",
  441. gotstr ? exp : new CodeCastExpression (restype, exp));
  442. csc.Add (st);
  443. csc.Add (new CodeMethodReturnStatement (new CodeVariableReferenceExpression ("obj")));
  444. }
  445. void CodePropertyGenericGet (CodeStatementCollection csc, string field, string typename)
  446. {
  447. csc.Add(new CodeMethodReturnStatement (
  448. new CodeFieldReferenceExpression (
  449. new CodeTypeReferenceExpression (typename), field)));
  450. }
  451. void CodePropertyGenericSet (CodeStatementCollection csc, string field, string typename)
  452. {
  453. csc.Add(new CodeAssignStatement (
  454. new CodeFieldReferenceExpression (new CodeTypeReferenceExpression (typename), field),
  455. new CodeVariableReferenceExpression ("value")));
  456. }
  457. string CompileResource (AppResourceFileInfo arfi)
  458. {
  459. string path = arfi.Info.FullName;
  460. string resource = Path.Combine (TempDirectory,
  461. "Resources." + Path.GetFileNameWithoutExtension (path) + ".resources");
  462. FileStream source = null, destination = null;
  463. IResourceReader reader = null;
  464. ResourceWriter writer = null;
  465. try {
  466. source = new FileStream (path, FileMode.Open, FileAccess.Read);
  467. destination = new FileStream (resource, FileMode.Create, FileAccess.Write);
  468. reader = GetReaderForKind (arfi.Kind, source);
  469. writer = new ResourceWriter (destination);
  470. foreach (DictionaryEntry de in reader) {
  471. object val = de.Value;
  472. if (val is string)
  473. writer.AddResource ((string)de.Key, (string)val);
  474. else
  475. writer.AddResource ((string)de.Key, val);
  476. }
  477. } catch (Exception ex) {
  478. throw new HttpException ("Failed to compile resource file", ex);
  479. } finally {
  480. if (reader != null)
  481. reader.Close ();
  482. else if (source != null)
  483. source.Close ();
  484. if (writer != null)
  485. writer.Close ();
  486. else if (destination != null)
  487. destination.Close ();
  488. }
  489. return resource;
  490. }
  491. IResourceReader GetReaderForKind (AppResourceFileKind kind, Stream stream)
  492. {
  493. switch (kind) {
  494. case AppResourceFileKind.ResX:
  495. return new ResXResourceReader (stream);
  496. case AppResourceFileKind.Resource:
  497. return new ResourceReader (stream);
  498. default:
  499. return null;
  500. }
  501. }
  502. object OnCreateRandomFile (string path)
  503. {
  504. FileStream f = new FileStream (path, FileMode.CreateNew);
  505. f.Close ();
  506. return path;
  507. }
  508. };
  509. };
  510. #endif