/// <summary> /// Checks if a Keyworded record contains a specific Keyword, by FormKey. /// Also looks up that keyword in the given cache. <br /> /// <br /> /// Note that this function only succeeds if the record contains the keyword, /// and the cache found it as well. <br /> /// <br /> /// It is possible that the record contains the keyword, but it could not be found /// by the cache. /// <br /> /// Aspects: IKeywordedGetter<IKeywordCommonGetter> /// </summary> /// <param name="keyworded">Keyworded record to check</param> /// <param name="keywordKey">FormKey of the Keyword record to look for</param> /// <param name="cache">LinkCache to resolve against</param> /// <param name="keyword">Keyword record retrieved, if keyworded record does contain</param> /// <returns>True if the Keyworded record contains a Keyword link /w the given FormKey</returns> public static bool TryResolveKeyword <TKeyword>( this IKeywordedGetter <TKeyword> keyworded, FormKey keywordKey, ILinkCache cache, [MaybeNullWhen(false)] out TKeyword keyword) where TKeyword : class, IKeywordCommonGetter { if (!keyworded.Keywords?.Any(x => x.FormKey == keywordKey) ?? true) { keyword = default; return(false); } return(cache.TryResolve(keywordKey, out keyword)); }
public IEnumerable <IMajorRecordCommonGetter> ResolveAll(FormKey formKey) { for (int i = _mutableMods.Count - 1; i >= 0; i--) { if (_mutableMods[i].TryResolve(formKey, out var majorRec)) { yield return(majorRec); } } foreach (var rec in WrappedImmutableCache.ResolveAll(formKey)) { yield return(rec); } }
private bool ShouldStopQuery <T>(FormKey targetKey, DepthCache <T> cache) { if (cache.Depth >= this._listedOrder.Count) { return(true); } // If we're going deeper than the originating mod of the target FormKey, we can stop if (cache.PassedMods.Contains(targetKey.ModKey)) { return(true); } return(false); }
public bool TryResolve(FormKey formKey, [MaybeNullWhen(false)] out IMajorRecordCommonGetter majorRec) { if (formKey.IsNull) { majorRec = default; return(false); } for (int i = _mutableMods.Count - 1; i >= 0; i--) { if (_mutableMods[i].TryResolve(formKey, out majorRec)) { return(true); } } return(WrappedImmutableCache.TryResolve(formKey, out majorRec)); }
/// <inheritdoc /> public bool TryResolveIdentifier(FormKey formKey, Type type, [MaybeNullWhen(false)] out string?editorId) { if (formKey.IsNull) { editorId = default; return(false); } for (int i = _mutableMods.Count - 1; i >= 0; i--) { if (_mutableMods[i].TryResolveIdentifier(formKey, type, out editorId)) { return(true); } } return(WrappedImmutableCache.TryResolveIdentifier(formKey, type, out editorId)); }
/// <inheritdoc /> public bool TryResolveContext(FormKey formKey, Type type, [MaybeNullWhen(false)] out IModContext <TMod, IMajorRecordCommon, IMajorRecordCommonGetter> majorRec) { if (formKey == null) { majorRec = default; return(false); } for (int i = _mutableMods.Count - 1; i >= 0; i--) { if (_mutableMods[i].TryResolveContext(formKey, type, out majorRec)) { return(true); } } return(WrappedImmutableCache.TryResolveContext(formKey, type, out majorRec)); }
/// <inheritdoc /> public bool TryResolveIdentifier(string editorId, Type type, [MaybeNullWhen(false)] out FormKey formKey) { if (editorId.IsNullOrWhitespace()) { formKey = default; return(false); } for (int i = _mutableMods.Count - 1; i >= 0; i--) { if (_mutableMods[i].TryResolveIdentifier(editorId, type, out formKey)) { return(true); } } return(WrappedImmutableCache.TryResolveIdentifier(editorId, type, out formKey)); }
/// <summary> /// Looks up a given FormKey to try to locate the target record. /// /// This call is not as optimized as its generic typed counterpart. /// It does not know what type the record is limited to, and so much load and process /// all record types in order to do a proper search. /// </summary> /// <param name="formKey">FormKey to search for</param> /// <param name="majorRec">MajorRecord if found</param> /// <returns>True if record was found</returns> public bool TryLookup(FormKey formKey, [MaybeNullWhen(false)] out IMajorRecordCommonGetter majorRec) { if (!_hasAny) { majorRec = default; return(false); } lock (this._loadOrderUntypedMajorRecords) { if (this._loadOrderUntypedMajorRecords.TryGetValue(formKey, out majorRec)) { return(true); } if (this._processedUntypedDepth >= this._loadOrder.Count) { return(false); } while (this._processedUntypedDepth < this._loadOrder.Count) { // Get next unprocessed mod var targetIndex = this._loadOrder.Count - _processedUntypedDepth - 1; var targetMod = this._loadOrder[targetIndex]; this._processedUntypedDepth++; if (targetMod.Mod == null) { continue; } // Add records from that mod that aren't already cached foreach (var record in targetMod.Mod.EnumerateMajorRecords()) { if (!_loadOrderUntypedMajorRecords.ContainsKey(record.FormKey)) { _loadOrderUntypedMajorRecords.Set(record); } } // Check again if (this._loadOrderUntypedMajorRecords.TryGetValue(formKey, out majorRec)) { return(true); } } // Record doesn't exist return(false); } }
public override string ToString() { if (Types.Length == 0) { if (Type != null) { return($"{nameof(MissingRecordException)} {FormKey?.ToString() ?? EditorID}<{Type}>: {this.Message} {this.InnerException}{this.StackTrace}"); } else { return($"{nameof(MissingRecordException)} {FormKey?.ToString() ?? EditorID}: {this.Message} {this.InnerException}{this.StackTrace}"); } } else { return($"{nameof(MissingRecordException)} {FormKey?.ToString() ?? EditorID}<{Type} (+{Types.Length - 1})>: {this.Message} {this.InnerException}{this.StackTrace}"); } }
/// <inheritdoc /> public bool TryResolveContext <TMajor, TMajorGetter>(FormKey formKey, [MaybeNullWhen(false)] out IModContext <TMod, TModGetter, TMajor, TMajorGetter> majorRec) where TMajor : class, IMajorRecordCommon, TMajorGetter where TMajorGetter : class, IMajorRecordCommonGetter { if (formKey.IsNull) { majorRec = default; return(false); } for (int i = _mutableMods.Count - 1; i >= 0; i--) { if (_mutableMods[i].TryResolveContext <TMajor, TMajorGetter>(formKey, out majorRec)) { return(true); } } return(WrappedImmutableCache.TryResolveContext <TMajor, TMajorGetter>(formKey, out majorRec)); }
public bool TryResolve(FormKey formKey, [MaybeNullWhen(false)] out IMajorRecordCommonGetter majorRec) { if (formKey == null) { majorRec = default; return(false); } // ToDo // Upgrade to call EnumerateGroups(), which will perform much better foreach (var item in this._sourceMod.EnumerateMajorRecords()) { if (item.FormKey == formKey) { majorRec = item; return(true); } } majorRec = default; return(false); }
/// <inheritdoc /> public bool TryResolve(FormKey formKey, Type type, [MaybeNullWhen(false)] out IMajorRecordCommonGetter majorRec) { if (formKey == null) { majorRec = default; return(false); } IReadOnlyCache <IMajorRecordCommonGetter, FormKey> cache; lock (_majorRecords) { cache = GetCache(type); } if (!cache.TryGetValue(formKey, out majorRec)) { majorRec = default; return(false); } return(true); }
/// <inheritdoc /> public bool TryResolve(FormKey formKey, Type type, [MaybeNullWhen(false)] out IMajorRecordCommonGetter majorRec) { if (formKey == null) { majorRec = default; return(false); } // ToDo // Upgrade to EnumerateGroups<TMajor>() foreach (var major in this._sourceMod.EnumerateMajorRecords(type)) { if (major.FormKey == formKey) { majorRec = major; return(true); } } majorRec = default; return(false); }
/// <inheritdoc /> public bool TryResolve <TMajor>(FormKey formKey, [MaybeNullWhen(false)] out TMajor majorRec) where TMajor : class, IMajorRecordCommonGetter { if (formKey == null) { majorRec = default; return(false); } IReadOnlyCache <IMajorRecordCommonGetter, FormKey> cache; lock (_majorRecords) { cache = GetCache(typeof(TMajor)); } if (!cache.TryGetValue(formKey, out var majorRecObj)) { majorRec = default; return(false); } majorRec = (majorRecObj as TMajor) !; return(majorRec != null); }
public bool TryResolve(FormKey formKey, [MaybeNullWhen(false)] out IMajorRecordCommonGetter majorRec) { if (formKey.IsNull) { majorRec = default; return(false); } // ToDo // Upgrade to call EnumerateGroups(), which will perform much better foreach (var item in this._sourceMod.EnumerateMajorRecords() // ToDo // Capture and expose errors optionally via TryResolve /w out param .Catch((Exception ex) => { })) { if (item.FormKey == formKey) { majorRec = item; return(true); } } majorRec = default; return(false); }
/// <inheritdoc /> public bool TryResolveContext <TMajorSetter, TMajorGetter>(FormKey formKey, [MaybeNullWhen(false)] out IModContext <TMod, TMajorSetter, TMajorGetter> majorRec) where TMajorSetter : class, IMajorRecordCommon, TMajorGetter where TMajorGetter : class, IMajorRecordCommonGetter { if (formKey == null) { majorRec = default; return(false); } // ToDo // Upgrade to EnumerateGroups<TMajor>() foreach (var major in this._sourceMod.EnumerateMajorRecordContexts <TMajorSetter, TMajorGetter>(this)) { if (major.Record.FormKey == formKey) { majorRec = major; return(true); } } majorRec = default; return(false); }
/// <inheritdoc /> public bool TryResolveContext(FormKey formKey, Type type, [MaybeNullWhen(false)] out IModContext <TMod, TModGetter, IMajorRecordCommon, IMajorRecordCommonGetter> majorRec) { if (formKey.IsNull) { majorRec = default; return(false); } // ToDo // Upgrade to EnumerateGroups<TMajor>() foreach (var major in this._sourceMod.EnumerateMajorRecordContexts(this, type) // ToDo // Capture and expose errors optionally via TryResolve /w out param .Catch((Exception ex) => { })) { if (major.Record.FormKey == formKey) { majorRec = major; return(true); } } majorRec = default; return(false); }
/// <inheritdoc /> public bool TryResolveContext <TMajorSetter, TMajorGetter>(FormKey formKey, [MaybeNullWhen(false)] out IModContext <TMod, TMajorSetter, TMajorGetter> majorRec) where TMajorSetter : class, IMajorRecordCommon, TMajorGetter where TMajorGetter : class, IMajorRecordCommonGetter { if (formKey == null) { majorRec = default; return(false); } IReadOnlyCache <IModContext <TMod, IMajorRecordCommon, IMajorRecordCommonGetter>, FormKey> cache; lock (_contexts) { cache = GetContextCache(typeof(TMajorGetter)); } if (!cache.TryGetValue(formKey, out var majorRecObj) || !(majorRecObj.Record is TMajorGetter)) { majorRec = default; return(false); } majorRec = majorRecObj.AsType <TMod, IMajorRecordCommon, IMajorRecordCommonGetter, TMajorSetter, TMajorGetter>(); return(true); }
/// <inheritdoc /> public bool TryResolve(FormKey formKey, [MaybeNullWhen(false)] out IMajorRecordCommonGetter majorRec, params Type[] types) { return(TryResolve(formKey, (IEnumerable <Type>)types, out majorRec)); }
public IEnumerable <IModContext <TMod, TModGetter, IMajorRecordCommon, IMajorRecordCommonGetter> > ResolveAllContexts(FormKey formKey) { if (TryResolveContext(formKey, out var rec)) { yield return(rec); } }
/// <inheritdoc /> public IEnumerable <IModContext <TMod, TModGetter, TMajor, TMajorGetter> > ResolveAllContexts <TMajor, TMajorGetter>(FormKey formKey) where TMajor : class, IMajorRecordCommon, TMajorGetter where TMajorGetter : class, IMajorRecordCommonGetter { if (TryResolveContext <TMajor, TMajorGetter>(formKey, out var rec)) { yield return(rec); } }
/// <inheritdoc /> public bool ContainsKey(FormKey key) => InternalCache.ContainsKey(key);
public static bool Contains <TMajor>(this IReadOnlyList <IFormLinkGetter <TMajor> > list, FormKey formKey) where TMajor : class, IMajorRecordCommonGetter { return(list.Any(f => f.FormKey == formKey)); }
/// <inheritdoc /> public IMajorRecordCommonGetter Resolve(FormKey formKey, params Type[] types) { return(Resolve(formKey, (IEnumerable <Type>)types)); }
public static void Remove <TMajor>(this IList <IFormLinkGetter <TMajor> > list, FormKey formKey) where TMajor : class, IMajorRecordCommonGetter { list.Remove(new FormLink <TMajor>(formKey)); }
public IModContext <TMod, TModGetter, IMajorRecordCommon, IMajorRecordCommonGetter> ResolveContext(FormKey formKey) { if (TryResolveContext <IMajorRecordCommon, IMajorRecordCommonGetter>(formKey, out var majorRec)) { return(majorRec); } throw new MissingRecordException(formKey, typeof(IMajorRecordCommonGetter)); }
/// <inheritdoc /> public bool Remove(FormKey key) => InternalCache.Remove(key);
/// <inheritdoc /> public IModContext <TMod, TModGetter, IMajorRecordCommon, IMajorRecordCommonGetter> ResolveContext(FormKey formKey, Type type) { if (TryResolveContext(formKey, type, out var commonRec)) { return(commonRec); } throw new MissingRecordException(formKey, type); }
/// <inheritdoc /> public TMajor this[FormKey key] => InternalCache[key];
/// <inheritdoc /> public IModContext <TMod, TModGetter, TMajor, TMajorGetter> ResolveContext <TMajor, TMajorGetter>(FormKey formKey) where TMajor : class, IMajorRecordCommon, TMajorGetter where TMajorGetter : class, IMajorRecordCommonGetter { if (TryResolveContext <TMajor, TMajorGetter>(formKey, out var commonRec)) { return(commonRec); } throw new MissingRecordException(formKey, typeof(TMajorGetter)); }