Esempio n. 1
0
 /// <summary>
 /// Sends the value provided by the provided delegate, only if Error is enabled.
 /// </summary>
 /// <typeparam name="T">The type of object we are logging about.</typeparam>
 /// <param name="logger">The logger to use.</param>
 /// <param name="function">The function to evaluate if Error logging is enabled.</param>
 public static void Error <T>(this IFullLogger logger, Func <string> function)
 {
     if (logger.IsErrorEnabled)
     {
         logger.Error <T>(function.Invoke());
     }
 }
Esempio n. 2
0
        public static IObservable <IChangeSet <TSource, TKey> > CacheChangeSet <TSource, TKey>(
            this IObservable <IChangeSet <TSource, TKey> > source,
            string cacheKey,
            IBlobCache?blobCache = null,
            IFullLogger?log      = default)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            if (cacheKey == null)
            {
                throw new ArgumentNullException(nameof(cacheKey));
            }

            blobCache ??= BlobCache.LocalMachine;

            return(Observable
                   .Create <IChangeSet <TSource, TKey> >(observer =>
                                                         source
                                                         .ToCollection()
                                                         .Concat(
                                                             blobCache
                                                             .GetObject <List <TSource> >(cacheKey)
                                                             .Catch(Observable.Return(new List <TSource>())))
                                                         .Subscribe(items =>
            {
                log?.Debug("CACHE: Writing {Count} items to cache with key: {CacheKey}", items.Count, cacheKey);

                blobCache
                .InsertObject(cacheKey, items.ToList())
                .Catch(Observable.Return(Unit.Default).Do(unit => log?.Error("Failed to add items to cache")));
            })));
        }
Esempio n. 3
0
        public ModsViewModel(IScreen screen, DowModLoader?dowModService = null) : base(screen, "mods")
        {
            this.logger        = this.Log();
            this.dowModService = dowModService ?? Locator.Current.GetService <DowModLoader>();

            var whenNotLoading = this.WhenAnyValue(x => x.Loading).Select(loading => !loading).DistinctUntilChanged();

            var whenItemSelected = this.WhenAnyValue(x => x.SelectedBaseItem, x => x.SelectedModItem,
                                                     (baseItem, modItem) => baseItem != null || modItem != null).DistinctUntilChanged();

            var canLoadSpecific = whenNotLoading.CombineLatest(whenItemSelected, (notLoading, itemSelected) => notLoading && itemSelected).DistinctUntilChanged();

            ReloadMods = ReactiveCommand.CreateFromTask(LoadAllMods, whenNotLoading);

            RefreshMods = ReactiveCommand.CreateFromTask(GetModsAsync);
            RefreshMods.ThrownExceptions.Subscribe(exception => logger.Error(exception));
            RefreshMods.Execute().Subscribe();

            RefreshMods.Select(mods => mods.Where(x => !x.Module.File.IsVanilla))
            .Subscribe(mods =>
            {
                ModItems.Clear();
                ModItems.AddRange(mods);
            });

            RefreshMods.Select(mods => mods.Where(x => x.Module.File.IsVanilla))
            .Subscribe(mods =>
            {
                BaseGameItems.Clear();
                BaseGameItems.AddRange(mods);
            });
        }
Esempio n. 4
0
        /// <summary>
        /// Sends the value provided by the provided delegate, only if Error is enabled.
        /// </summary>
        /// <typeparam name="T">The type of object we are logging about.</typeparam>
        /// <param name="logger">The logger to use.</param>
        /// <param name="function">The function to evaluate if Error logging is enabled.</param>
        public static void Error <T>(this IFullLogger logger, Func <string> function)
        {
            if (logger is null)
            {
                throw new ArgumentNullException(nameof(logger));
            }

            if (function is null)
            {
                throw new ArgumentNullException(nameof(function));
            }

            if (logger.IsErrorEnabled)
            {
                logger.Error <T>(function.Invoke());
            }
        }
Esempio n. 5
0
        public static void LogForType(this IFullLogger logger, NotificationType notificationType, string message)
        {
            switch (notificationType)
            {
            case NotificationType.Info:
                logger.Info(message);
                break;

            case NotificationType.Warning:
                logger.Warn(message);
                break;

            case NotificationType.Error:
                logger.Error(message);
                break;
            }
        }