|
1 | 1 | using System; |
| 2 | +using System.IO; |
| 3 | +using System.Reflection; |
| 4 | +using System.Text; |
2 | 5 |
|
3 | 6 | using OriginalJsEngine = MsieJavaScriptEngine.MsieJsEngine; |
4 | 7 | using OriginalJsEngineLoadException = MsieJavaScriptEngine.JsEngineLoadException; |
@@ -334,6 +337,102 @@ protected override void InnerCollectGarbage() |
334 | 337 | _jsEngine.CollectGarbage(); |
335 | 338 | } |
336 | 339 |
|
| 340 | + public override void ExecuteFile(string path, Encoding encoding = null) |
| 341 | + { |
| 342 | + VerifyNotDisposed(); |
| 343 | + |
| 344 | + if (path == null) |
| 345 | + { |
| 346 | + throw new ArgumentNullException( |
| 347 | + "path", string.Format(CoreStrings.Common_ArgumentIsNull, "path")); |
| 348 | + } |
| 349 | + |
| 350 | + if (string.IsNullOrWhiteSpace(path)) |
| 351 | + { |
| 352 | + throw new ArgumentException( |
| 353 | + string.Format(CoreStrings.Common_ArgumentIsEmpty, "path"), "path"); |
| 354 | + } |
| 355 | + |
| 356 | + if (!File.Exists(path)) |
| 357 | + { |
| 358 | + throw new FileNotFoundException( |
| 359 | + string.Format(CoreStrings.Common_FileNotExist, path), path); |
| 360 | + } |
| 361 | + |
| 362 | + try |
| 363 | + { |
| 364 | + _jsEngine.ExecuteFile(path, encoding); |
| 365 | + } |
| 366 | + catch (OriginalJsRuntimeException e) |
| 367 | + { |
| 368 | + throw ConvertMsieJsRuntimeExceptionToJsRuntimeException(e); |
| 369 | + } |
| 370 | + } |
| 371 | + |
| 372 | + public override void ExecuteResource(string resourceName, Type type) |
| 373 | + { |
| 374 | + VerifyNotDisposed(); |
| 375 | + |
| 376 | + if (resourceName == null) |
| 377 | + { |
| 378 | + throw new ArgumentNullException( |
| 379 | + "resourceName", string.Format(CoreStrings.Common_ArgumentIsNull, "resourceName")); |
| 380 | + } |
| 381 | + |
| 382 | + if (type == null) |
| 383 | + { |
| 384 | + throw new ArgumentNullException( |
| 385 | + "type", string.Format(CoreStrings.Common_ArgumentIsNull, "type")); |
| 386 | + } |
| 387 | + |
| 388 | + if (string.IsNullOrWhiteSpace(resourceName)) |
| 389 | + { |
| 390 | + throw new ArgumentException( |
| 391 | + string.Format(CoreStrings.Common_ArgumentIsEmpty, "resourceName"), "resourceName"); |
| 392 | + } |
| 393 | + |
| 394 | + try |
| 395 | + { |
| 396 | + _jsEngine.ExecuteResource(resourceName, type); |
| 397 | + } |
| 398 | + catch (OriginalJsRuntimeException e) |
| 399 | + { |
| 400 | + throw ConvertMsieJsRuntimeExceptionToJsRuntimeException(e); |
| 401 | + } |
| 402 | + } |
| 403 | + |
| 404 | + public override void ExecuteResource(string resourceName, Assembly assembly) |
| 405 | + { |
| 406 | + VerifyNotDisposed(); |
| 407 | + |
| 408 | + if (resourceName == null) |
| 409 | + { |
| 410 | + throw new ArgumentNullException( |
| 411 | + "resourceName", string.Format(CoreStrings.Common_ArgumentIsNull, "resourceName")); |
| 412 | + } |
| 413 | + |
| 414 | + if (assembly == null) |
| 415 | + { |
| 416 | + throw new ArgumentNullException( |
| 417 | + "assembly", string.Format(CoreStrings.Common_ArgumentIsNull, "assembly")); |
| 418 | + } |
| 419 | + |
| 420 | + if (string.IsNullOrWhiteSpace(resourceName)) |
| 421 | + { |
| 422 | + throw new ArgumentException( |
| 423 | + string.Format(CoreStrings.Common_ArgumentIsEmpty, "resourceName"), "resourceName"); |
| 424 | + } |
| 425 | + |
| 426 | + try |
| 427 | + { |
| 428 | + _jsEngine.ExecuteResource(resourceName, assembly); |
| 429 | + } |
| 430 | + catch (OriginalJsRuntimeException e) |
| 431 | + { |
| 432 | + throw ConvertMsieJsRuntimeExceptionToJsRuntimeException(e); |
| 433 | + } |
| 434 | + } |
| 435 | + |
337 | 436 | #endregion |
338 | 437 |
|
339 | 438 | #region IDisposable implementation |
|
0 commit comments