public override void Write(LoadException le) { m_xmlWriter.WriteStartElement("Error"); switch (le.ErrorType) { case LoadException.LoadErrorType.INVALID_ENTRY_SHAPE: var entryShape = le.Data["shape"] as string; var entryId = le.Data["entry"] as string; LexEntry entry = le.Loader.CurrentMorpher.Lexicon.GetEntry(entryId); m_xmlWriter.WriteString(string.Format(ParserCoreStrings.ksHCInvalidEntryShape, entryShape, entry.Description)); break; case LoadException.LoadErrorType.INVALID_RULE_SHAPE: var ruleShape = le.Data["shape"] as string; var ruleId = le.Data["rule"] as string; MorphologicalRule rule = le.Loader.CurrentMorpher.GetMorphologicalRule(ruleId); m_xmlWriter.WriteString(string.Format(ParserCoreStrings.ksHCInvalidRuleShape, ruleShape, rule.Description)); break; default: m_xmlWriter.WriteString(string.Format(ParserCoreStrings.ksHCDefaultErrorMsg, le.Message)); break; } m_xmlWriter.WriteEndElement(); }
public void LoadAll() { BeforeLoad(); // Plugins are stored in format {PluginDir}/{PluginName}/AthamePlugin.*.dll var subDirs = Directory.GetDirectories(PluginDirectory); isLoading = true; foreach (var dir in subDirs) { var name = Path.GetFileName(dir); try { // Attempt to load a .pdb if one exists var basePath = Path.Combine(dir, PluginDllPrefix + name); var dllFilename = basePath + ".dll"; var pdbFilename = basePath + ".pdb"; var theAssembly = File.Exists(pdbFilename) ? Assembly.Load(File.ReadAllBytes(dllFilename), File.ReadAllBytes(pdbFilename)) : Assembly.Load(File.ReadAllBytes(dllFilename)); // Set basic information about the assembly var plugin = new PluginInstance { Assembly = theAssembly, AssemblyDirectory = dir, Name = name }; Plugins.Add(plugin); Activate(plugin); AreAnyLoaded = true; } catch (Exception ex) { Log.WriteException(Level.Error, Tag, ex, $"While loading plugin {name}"); var eventArgs = new PluginLoadExceptionEventArgs { PluginName = name, Exception = ex, Continue = true }; LoadException?.Invoke(this, eventArgs); if (!eventArgs.Continue) { return; } } } isLoading = false; }
public void LoadAll() { if (Plugins != null) { throw new InvalidOperationException("Plugins can only be loaded once"); } Plugins = new List <PluginInstance>(); // Cache current AppDomain loaded assemblies loadedAssemblies = AppDomain.CurrentDomain.GetAssemblies(); // Plugins are stored in format {PluginDir}/{PluginName}/AthamePlugin.*.dll var subDirs = Directory.GetDirectories(PluginDirectory); var pluginDlls = new List <string>(); foreach (var subDir in subDirs) { pluginDlls.AddRange(Directory.GetFiles(subDir, $"{PluginDllPrefix}*.dll")); } isLoading = true; // Load and activate all plugins var assemblies = from dllPath in pluginDlls select Assembly.LoadFile(dllPath); foreach (var assembly in assemblies) { try { Load(assembly); } catch (Exception ex) { Log.WriteException(Level.Error, Tag, ex, $"While loading assembly {assembly}"); #if DEBUG Debugger.Break(); #endif var eventArgs = new PluginLoadExceptionEventArgs { Exception = ex, Continue = true }; LoadException?.Invoke(this, eventArgs); if (!eventArgs.Continue) { return; } } } isLoading = false; }
public static object DeserializeSafely( this IDeserializer d, Type t, string pathToFile, bool list) { try { using (var reader = new StreamReader(pathToFile)) { if (list) { t = typeof(List <>).MakeGenericType(t); } return(d.Deserialize(reader, t)); } } catch (YamlException ex) { throw LoadException.DeserializationError(pathToFile, ex); } }
private static void ShowProblemLoadingError(LoadException e) { MessageBox.Show( $"There has been a problem loading the XAML at line: {e.LineNumber} pos: {e.LinePosition}. Detailed exception: \n\nException:\n{e.ToString().GetFirstNChars(500)}", "Load problem"); }
protected virtual void OnViewLoadError(LoadException error) { }
/// <summary> /// Note: This method is re-entrant safe but not thread safe. /// </summary> /// <param name="adDocument">The ad document to execute.</param> /// <param name="adSource">The original ad source that the ad document came from.</param> /// <param name="startTimeout">The timeout for the ad</param> /// <param name="cancellationToken">A cancellation token to cancel the ad.</param> /// <param name="progress">Reports progress of the ad.</param> /// <returns>Two tasks that indicate when the ad is finished and another for when the ad is done with its linear portion</returns> PlayAdAsyncResult PlayAdAsync(AdDocumentPayload adDocument, IAdSource adSource, TimeSpan?startTimeout, CancellationToken cancellationToken, IProgress <AdStatus> progress) { // primary task wll hold a task that finishes when the ad document finishes or a non-linear ad starts. var primaryTask = new TaskCompletionSource <object>(); // secondary task will hold a task that finishes when the entire ad document finishes. var secondaryTask = TaskHelpers.Create <Task>(async() => { LoadException loadException = null; // keep around to re-throw in case we can't recover using (var timeoutTokenSource = new CancellationTokenSource()) { if (startTimeout.HasValue) { timeoutTokenSource.CancelAfter(startTimeout.Value); } var timeoutToken = timeoutTokenSource.Token; using (var mainCancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, timeoutToken)) { var mainCancellationToken = mainCancellationTokenSource.Token; // NOTE: mainCancellationToken is reset to just the initial token once we have successfully started an ad. progress.Report(AdStatus.Opening); try { try { bool podPlayed = false; // throw an exception if no ad ever played // a task to hold the currently playing ad Task activeAdTask = null; foreach (var adPod in adDocument.AdPods) { try { bool adPlayed = false; // throw an exception if no ad ever played // model expects ads to be in the correct order. foreach (var defaultAd in adPod.Ads) { try { var adCandidates = new List <Ad>(); adCandidates.Add(defaultAd); adCandidates.AddRange(defaultAd.FallbackAds); foreach (var ad in adCandidates) { try // **** try ad **** { // group the creatives by sequence number. Always put the group without sequence number at the back of the piority list in compliance with VAST spec. foreach (var creativeSet in ad.Creatives.GroupBy(c => c.Sequence).OrderBy(cs => cs.Key.GetValueOrDefault(int.MaxValue)).Select(cs => cs.ToList())) { var newAdUnit = await LoadAdUnitAsync(creativeSet, ad, adSource, mainCancellationToken); // if there is an ad playing, wait for it to finish before proceeding. if (activeAdTask.IsRunning()) { await activeAdTask; mainCancellationToken.ThrowIfCancellationRequested(); // we can safely assume this is not a timeout and only check the token passed as a param } if (!newAdUnit.Player.AdLinear) { // if the next ad is nonlinear, we've successfully finished the primary task. primaryTask.TrySetResult(null); } LoadAdUnit(newAdUnit, creativeSet); adPlayed = true; loadException = null; // if there was a load error, we recovered, reset. progress.Report(AdStatus.Loaded); activeAd = newAdUnit; VpaidController.AddAd(activeAd); try { await StartAdUnitAsync(newAdUnit, ad, mainCancellationToken); // we successfully started an ad, create a new cancellation token that is not linked to timeout mainCancellationToken = cancellationToken; progress.Report(AdStatus.Playing); // returns when task is over or approaching end activeAdTask = await PlayAdUnitAsync(newAdUnit, mainCancellationToken); if (activeAdTask != null) { activeAdTask = activeAdTask.ContinueWith((Task t) => { progress.Report(AdStatus.Complete); activeAd = null; }, TaskScheduler.FromCurrentSynchronizationContext()); } else { progress.Report(AdStatus.Complete); activeAd = null; } } catch { CleanupAd(activeAd); progress.Report(AdStatus.Complete); activeAd = null; throw; } } break; // we successfully played an ad, break out of loop. } // **** end try ad **** catch (LoadException) { if (ad == adCandidates.Last()) { throw; // ignore if it's not the last ad in order to go to next fallback ad } } } } catch (LoadException) { if (defaultAd == adPod.Ads.Last()) { throw; // ignore if it's not the last ad in the pod } } } if (!adPlayed) { throw new LoadException(new Exception("No ads found.")); } podPlayed = true; break; // we should only play one adPod per the VAST spec } catch (LoadException ex) { // keep around to re-throw in case we can't successfully load an ad loadException = ex; // move to the next adpod, ignore for now. We'll log this later if it's relevant } } // always wait for the playing ad to complete before returning if (activeAdTask.IsRunning()) { await activeAdTask; } if (!podPlayed) { VpaidController.TrackErrorUrl(adDocument.Error, Microsoft.Media.Advertising.VpaidController.Error_NoAd); throw new LoadException(new Exception("No ads found.")); } } catch (OperationCanceledException) { if (timeoutToken.IsCancellationRequested) { throw new TimeoutException(); } else { throw; } } catch (Exception ex) { throw new PlayException(ex); } if (loadException != null) { throw loadException; } } catch (Exception ex) { LogError(adSource, ex); primaryTask.TrySetException(ex); throw; } finally { progress.Report(AdStatus.Unloaded); } primaryTask.TrySetResult(null); } } }); return(new PlayAdAsyncResult(primaryTask.Task, secondaryTask)); }