Esempio n. 1
0
 public static LinkCacheItem Factory(IMajorRecordCommonGetter record, bool simple)
 {
     return(new LinkCacheItem(
                simple ? null : record,
                record.FormKey,
                simple ? record.EditorID : null));
 }
Esempio n. 2
0
        public bool TryResolve(FormKey formKey, [MaybeNullWhen(false)] out IMajorRecordCommonGetter majorRec, ResolveTarget target = ResolveTarget.Winner)
        {
            if (formKey.IsNull)
            {
                majorRec = default;
                return(false);
            }

            if (target == ResolveTarget.Origin &&
                formKey.ModKey != _sourceMod.ModKey)
            {
                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);
        }
Esempio n. 3
0
        /// <inheritdoc />
        public bool TryResolve(string editorId, Type type, [MaybeNullWhen(false)] out IMajorRecordCommonGetter majorRec)
        {
            if (editorId.IsNullOrWhitespace())
            {
                majorRec = default;
                return(false);
            }

            // ToDo
            // Upgrade to EnumerateGroups<TMajor>()
            foreach (var major in this._sourceMod.EnumerateMajorRecords(type)
                     // ToDo
                     // Capture and expose errors optionally via TryResolve /w out param
                     .Catch((Exception ex) => { }))
            {
                if (editorId.Equals(major.EditorID))
                {
                    majorRec = major;
                    return(true);
                }
            }

            majorRec = default;
            return(false);
        }
Esempio n. 4
0
        /// <inheritdoc />
        public bool TryResolve(FormKey formKey, Type type, [MaybeNullWhen(false)] out IMajorRecordCommonGetter majorRec, ResolveTarget target = ResolveTarget.Winner)
        {
            if (formKey.IsNull)
            {
                majorRec = default;
                return(false);
            }

            if (target == ResolveTarget.Origin &&
                formKey.ModKey != _sourceMod.ModKey)
            {
                majorRec = default;
                return(false);
            }

            // ToDo
            // Upgrade to EnumerateGroups<TMajor>()
            foreach (var major in this._sourceMod.EnumerateMajorRecords(type)
                     // ToDo
                     // Capture and expose errors optionally via TryResolve /w out param
                     .Catch((Exception ex) => { }))
            {
                if (major.FormKey == formKey)
                {
                    majorRec = major;
                    return(true);
                }
            }

            majorRec = default;
            return(false);
        }
Esempio n. 5
0
 public static string ToString(IMajorRecordCommonGetter majorRec)
 {
     if (majorRec.EditorID.TryGet(out var edid))
     {
         return($"{TypeString} {edid} {majorRec.FormKey}");
     }
     return($"{TypeString} {majorRec.FormKey}");
 }
Esempio n. 6
0
 public bool TryResolveCommon(ILinkCache cache, [MaybeNullWhen(false)] out IMajorRecordCommonGetter formKey)
 {
     if (this.TryResolve(cache, out var rec))
     {
         formKey = rec;
         return(true);
     }
     formKey = default !;
Esempio n. 7
0
 public bool TryResolve(FormKey formKey, [MaybeNullWhen(false)] out IMajorRecordCommonGetter majorRec)
 {
     if (formKey == null)
     {
         majorRec = default;
         return(false);
     }
     return(_untypedMajorRecords.Value.TryGetValue(formKey, out majorRec));
 }
        /// <inheritdoc />
        public bool TryResolve(FormKey formKey, Type type, [MaybeNullWhen(false)] out IMajorRecordCommonGetter majorRec)
        {
            if (!_hasAny || formKey.IsNull)
            {
                majorRec = default;
                return(false);
            }

            DepthCache <IMajorRecordCommonGetter> cache;

            lock (this._winningRecords)
            {
                // Get cache object by type
                if (!this._winningRecords.TryGetValue(type, out cache))
                {
                    cache = new DepthCache <IMajorRecordCommonGetter>();
                    if (type.Equals(typeof(IMajorRecordCommon)) ||
                        type.Equals(typeof(IMajorRecordCommonGetter)))
                    {
                        this._winningRecords[typeof(IMajorRecordCommon)]       = cache;
                        this._winningRecords[typeof(IMajorRecordCommonGetter)] = cache;
                    }
                    else if (LoquiRegistration.TryGetRegister(type, out var registration))
                    {
                        this._winningRecords[registration.ClassType]  = cache;
                        this._winningRecords[registration.GetterType] = cache;
                        this._winningRecords[registration.SetterType] = cache;
                        if (registration.InternalGetterType != null)
                        {
                            this._winningRecords[registration.InternalGetterType] = cache;
                        }
                        if (registration.InternalSetterType != null)
                        {
                            this._winningRecords[registration.InternalSetterType] = cache;
                        }
                    }
                    else
                    {
                        if (!_linkInterfaces.TryGetValue(type, out var objs))
                        {
                            throw new ArgumentException($"A lookup was queried for an unregistered type: {type.Name}");
                        }
                        this._winningRecords[type] = cache;
                    }
                }
            }

            lock (cache)
            {
                // Check for record
                if (cache.TryGetValue(formKey, out majorRec))
                {
                    return(true);
                }
                if (IsPastDepth(cache.Depth))
                {
                    majorRec = default !;
Esempio n. 9
0
 public static RecordException Create(string message, ModKey?modKey, IMajorRecordCommonGetter majorRec, Exception?innerException = null)
 {
     return(new RecordException(
                formKey: majorRec.FormKey,
                modKey: modKey,
                edid: majorRec.EditorID,
                message: message,
                recordType: majorRec.Registration.ClassType,
                innerException: innerException));
 }
Esempio n. 10
0
 /// <inheritdoc />
 public bool TryResolve(FormKey formKey, IEnumerable <Type> types, [MaybeNullWhen(false)] out IMajorRecordCommonGetter majorRec, ResolveTarget target = ResolveTarget.Winner)
 {
     foreach (var type in types)
     {
         if (TryResolve(formKey, type, out majorRec, target))
         {
             return(true);
         }
     }
     majorRec = default;
     return(false);
 }
Esempio n. 11
0
 /// <inheritdoc />
 public bool TryResolve(string editorId, IEnumerable <Type> types, [MaybeNullWhen(false)] out IMajorRecordCommonGetter majorRec)
 {
     foreach (var type in types)
     {
         if (TryResolve(editorId, type, out majorRec))
         {
             return(true);
         }
     }
     majorRec = default;
     return(false);
 }
Esempio n. 12
0
 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));
 }
Esempio n. 13
0
 public bool TryResolve(string editorId, [MaybeNullWhen(false)] out IMajorRecordCommonGetter majorRec)
 {
     if (editorId.IsNullOrWhitespace())
     {
         majorRec = default;
         return(false);
     }
     for (int i = _mutableMods.Count - 1; i >= 0; i--)
     {
         if (_mutableMods[i].TryResolve(editorId, out majorRec))
         {
             return(true);
         }
     }
     return(WrappedImmutableCache.TryResolve(editorId, out majorRec));
 }
Esempio n. 14
0
        /// <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);
            }
        }
Esempio n. 15
0
        /// <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);
        }
Esempio n. 16
0
 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);
 }
Esempio n. 17
0
        /// <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);
        }
Esempio n. 18
0
        /// <inheritdoc />
        public bool TryResolve(FormKey formKey, Type type, [MaybeNullWhen(false)] out IMajorRecordCommonGetter majorRec, ResolveTarget target = ResolveTarget.Winner)
        {
            if (formKey.IsNull)
            {
                majorRec = default;
                return(false);
            }

            switch (target)
            {
            case ResolveTarget.Origin:
                if (WrappedImmutableCache.TryResolve(formKey, type, out majorRec, target))
                {
                    return(true);
                }
                foreach (var mod in _mutableMods)
                {
                    if (mod.TryResolve(formKey, type, out majorRec, target))
                    {
                        return(true);
                    }
                }

                return(false);

            case ResolveTarget.Winner:
                for (int i = _mutableMods.Count - 1; i >= 0; i--)
                {
                    if (_mutableMods[i].TryResolve(formKey, type, out majorRec, target))
                    {
                        return(true);
                    }
                }
                return(WrappedImmutableCache.TryResolve(formKey, type, out majorRec, target));

            default:
                throw new NotImplementedException();
            }
        }
Esempio n. 19
0
 public bool TryResolve(string editorId, [MaybeNullWhen(false)] out IMajorRecordCommonGetter majorRec)
 {
     if (editorId.IsNullOrWhitespace())
     {
         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 (editorId.Equals(item.EditorID))
         {
             majorRec = item;
             return(true);
         }
     }
     majorRec = default;
     return(false);
 }
Esempio n. 20
0
 public static RecordException Factory(string message, ModKey?modKey, IMajorRecordCommonGetter majorRec, Exception?innerException = null)
 {
     return(Create(message, modKey, majorRec, innerException));
 }
Esempio n. 21
0
 /// <inheritdoc />
 public bool TryResolve(string editorId, [MaybeNullWhen(false)] out IMajorRecordCommonGetter majorRec, params Type[] types)
 {
     return(TryResolve(editorId, (IEnumerable <Type>)types, out majorRec));
 }
Esempio n. 22
0
 /// <inheritdoc />
 public bool TryResolve(FormKey formKey, [MaybeNullWhen(false)] out IMajorRecordCommonGetter majorRec, params Type[] types)
 {
     return(TryResolve(formKey, (IEnumerable <Type>)types, out majorRec));
 }
Esempio n. 23
0
 /// <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)
 {
     return(_untypedMajorRecords.Value.TryGetValue(formKey, out majorRec));
 }
Esempio n. 24
0
 public bool TryResolve(string editorId, [MaybeNullWhen(false)] out IMajorRecordCommonGetter majorRec)
 {
     return(TryResolve(editorId, typeof(IMajorRecordCommonGetter), out majorRec));
 }
 public bool TryResolve(FormKey formKey, [MaybeNullWhen(false)] out IMajorRecordCommonGetter majorRec)
 {
     return(TryResolve <IMajorRecordCommonGetter>(formKey, out majorRec));
 }
Esempio n. 26
0
 public static string GetFileString(IMajorRecordCommonGetter rec, int counter)
 {
     return($"{counter} - {rec.EditorID} - {rec.FormKey.ToString()}");
 }
Esempio n. 27
0
 public static RecordException Factory(Exception ex, ModKey?modKey, IMajorRecordCommonGetter majorRec)
 {
     return(Factory(ex, majorRec.FormKey, majorRec.EditorID, modKey));
 }
Esempio n. 28
0
 public static RecordException Factory(Exception ex, IMajorRecordCommonGetter majorRec)
 {
     return(Enrich(ex, majorRec.FormKey, majorRec.Registration.ClassType, majorRec.EditorID));
 }
Esempio n. 29
0
 public static FormLinkInformation ToFormLinkInformation(this IMajorRecordCommonGetter majorRec)
 {
     return(FormLinkInformation.Factory(majorRec));
 }
Esempio n. 30
0
 public static RecordException Enrich(Exception ex, ModKey?modKey, IMajorRecordCommonGetter majorRec)
 {
     return(Enrich(ex, majorRec.FormKey, majorRec.Registration.ClassType, majorRec.EditorID, modKey));
 }