Beispiel #1
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 */
                        Debug.WriteLine(ex);
                    }

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

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

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