/// <summary>
 /// Gets the culture from the language string (or the current culture).
 /// </summary>
 /// <param name="context">The current context.</param>
 /// <param name="language">The ISO culture name.</param>
 /// <returns>
 /// The culture info representing the language or the current culture.
 /// </returns>
 public static CultureInfo GetCultureFrom(this IBrowsingContext context, String language)
 {
     try
     {
         return(new CultureInfo(language));
     }
     catch (CultureNotFoundException ex)
     {
         context.TrackError(ex);
         return(context.GetCulture());
     }
 }
Exemple #2
0
        public async Task RunAsync(CancellationToken cancel)
        {
            var download = Download;

            if (download != null)
            {
                try
                {
                    _response = await download.Task.ConfigureAwait(false);
                }
                catch
                {
                    await _document.QueueTaskAsync(FireErrorEvent).ConfigureAwait(false);
                }
            }

            if (_response != null)
            {
                var cancelled = await _document.QueueTaskAsync(FireBeforeScriptExecuteEvent).ConfigureAwait(false);

                if (!cancelled)
                {
                    var options = CreateOptions();
                    var insert  = _document.Source.Index;

                    try
                    {
                        await _engine.EvaluateScriptAsync(_response, options, cancel).ConfigureAwait(false);
                    }
                    catch (Exception ex)
                    {
                        /* We omit failed 3rd party services */
                        _context.TrackError(ex);
                    }

                    _document.Source.Index = insert;
                    await _document.QueueTaskAsync(FireAfterScriptExecuteEvent).ConfigureAwait(false);

                    await _document.QueueTaskAsync(FireLoadEvent).ConfigureAwait(false);

                    _response.Dispose();
                    _response = null;
                }
            }
        }