Example #1
0
 /// <summary>
 /// Sends the value provided by the provided delegate, only if Debug is enabled.
 /// </summary>
 /// <param name="logger">The logger to use.</param>
 /// <param name="function">The function to evaluate if Debug logging is enabled.</param>
 /// <param name="exception">A exception to log about.</param>
 public static void DebugException(this IFullLogger logger, Func <string> function, Exception exception)
 {
     if (logger.IsDebugEnabled)
     {
         logger.Debug(function.Invoke(), exception);
     }
 }
Example #2
0
 /// <summary>
 /// Sends the value provided by the provided delegate, only if Fatal is enabled.
 /// </summary>
 /// <param name="logger">The logger to use.</param>
 /// <param name="function">The function to evaluate if Fatal logging is enabled.</param>
 /// <param name="exception">A exception to log about.</param>
 public static void FatalException(this IFullLogger logger, Func <string> function, Exception exception)
 {
     if (logger.IsFatalEnabled)
     {
         logger.ErrorException(function.Invoke(), exception);
     }
 }
Example #3
0
 /// <summary>
 /// Sends the value provided by the provided delegate, only if Info is enabled.
 /// </summary>
 /// <param name="logger">The logger to use.</param>
 /// <param name="function">The function to evaluate if Info logging is enabled.</param>
 /// <param name="exception">A exception to log about.</param>
 public static void InfoException(this IFullLogger logger, Func <string> function, Exception exception)
 {
     if (logger.IsInfoEnabled)
     {
         logger.Info(function.Invoke(), exception);
     }
 }
Example #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NavigationView"/> class.
        /// </summary>
        /// <param name="mainScheduler">The main scheduler to scheduler UI tasks on.</param>
        /// <param name="backgroundScheduler">The background scheduler.</param>
        /// <param name="viewLocator">The view locator which will find views associated with view models.</param>
        /// <param name="rootPage">The starting root page.</param>
        public NavigationView(IScheduler mainScheduler, IScheduler backgroundScheduler, IViewLocator viewLocator, Page rootPage)
            : base(rootPage)
        {
            _backgroundScheduler = backgroundScheduler;
            MainThreadScheduler  = mainScheduler;
            _viewLocator         = viewLocator;
            _logger = this.Log();

            PagePopped =
                Observable
                .FromEvent <EventHandler <NavigationEventArgs>, IViewModel>(
                    handler =>
            {
                void Handler(object?sender, NavigationEventArgs args)
                {
                    if (args.Page.BindingContext is IViewModel viewModel)
                    {
                        handler(viewModel);
                    }
                }

                return(Handler);
            },
                    x => Popped += x,
                    x => Popped -= x);

            Behaviors.Add(new NavigationPageSystemPopBehavior(_navigationSource.AsObservable()));
        }
 private static void Act(IFullLogger logger, LogLevel thresholdLogLevel, [NotNull] Func <string> valueFunction, [NotNull] Action <string, Exception> logAction, [NotNull] Exception ex)
 {
     if (logger.Level <= thresholdLogLevel)
     {
         logAction.Invoke(valueFunction.Invoke(), ex);
     }
 }
Example #6
0
 /// <summary>
 /// Sends the value provided by the provided delegate, only if Debug 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 Debug logging is enabled.</param>
 public static void Debug <T>(this IFullLogger logger, Func <string> function)
 {
     if (logger.IsDebugEnabled)
     {
         logger.Debug <T>(function.Invoke());
     }
 }
Example #7
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);
            });
        }
Example #8
0
 /// <summary>
 /// Sends the value provided by the provided delegate, only if Debug 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 Debug logging is enabled.</param>
 public static void Info <T>(this IFullLogger logger, Func <string> function)
 {
     if (logger.IsInfoEnabled)
     {
         logger.Info <T>(function.Invoke());
     }
 }
Example #9
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());
     }
 }
Example #10
0
 /// <summary>
 /// Sends the value provided by the provided delegate, only if Fatal 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 Fatal logging is enabled.</param>
 public static void Fatal <T>(this IFullLogger logger, Func <string> function)
 {
     if (logger.IsFatalEnabled)
     {
         logger.Fatal <T>(function.Invoke());
     }
 }
Example #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="QueueApiClient"/> class.
 /// </summary>
 /// <param name="apiContract">The api contract.</param>
 /// <param name="hubClient">The hub client.</param>
 /// <param name="blobCache">The cache.</param>
 /// <param name="logger">The logger.</param>
 public QueueApiClient(IQueueApiContract apiContract, IHubClient <QueuedStoreDto> hubClient, IBlobCache blobCache, ILogManager logger)
 {
     _apiContract = apiContract;
     _hubClient   = hubClient;
     BlobCache    = blobCache;
     _logger      = logger.GetLogger(GetType());
 }
Example #12
0
 /// <summary>
 /// Sends the value provided by the provided delegate, only if Warn is enabled.
 /// </summary>
 /// <param name="logger">The logger to use.</param>
 /// <param name="function">The function to evaluate if Warn logging is enabled.</param>
 public static void Warn(this IFullLogger logger, Func <string> function)
 {
     if (logger.IsWarnEnabled)
     {
         logger.Warn(function.Invoke());
     }
 }
Example #13
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NavigationView"/> class.
        /// </summary>
        /// <param name="mainScheduler">The main scheduler to scheduler UI tasks on.</param>
        /// <param name="backgroundScheduler">The background scheduler.</param>
        /// <param name="viewLocator">The view locator which will find views associated with view models.</param>
        public NavigationView(IScheduler mainScheduler, IScheduler backgroundScheduler, IViewLocator viewLocator)
        {
            _backgroundScheduler = backgroundScheduler;
            MainThreadScheduler  = mainScheduler;
            _viewLocator         = viewLocator;
            _logger = this.Log();

            PagePopped =
                Observable
                .FromEvent <EventHandler <NavigationEventArgs>, IViewModel>(
                    handler =>
            {
                void Handler(object?sender, NavigationEventArgs args)
                {
                    if (args.Page.BindingContext is IViewModel viewModel)
                    {
                        handler(viewModel);
                    }
                }

                return(Handler);
            },
                    x => Popped += x,
                    x => Popped -= x);
        }
Example #14
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NavigationView"/> class.
        /// </summary>
        /// <param name="mainScheduler">The main scheduler to scheduler UI tasks on.</param>
        /// <param name="backgroundScheduler">The background scheduler.</param>
        /// <param name="viewLocator">The view locator which will find views associated with view models.</param>
        public NavigationView(IScheduler mainScheduler, IScheduler backgroundScheduler, IViewLocator viewLocator)
        {
            InitializeComponent();

            _logger = this.Log();

            BackgroundScheduler = backgroundScheduler;
            MainThreadScheduler = mainScheduler;
            _viewLocator        = viewLocator;

            _mirroredPageStack  = new Stack <IViewModel?>();
            _mirroredModalStack = new Stack <IViewModel?>();

            backButton.Visibility = Visibility.Collapsed;

            PagePopped = Observable
                         .FromEvent <NavigatedEventHandler, NavigationEventArgs>(
                handler => (_, e) => handler(e),
                x => mainFrame.Navigated += x,
                x => mainFrame.Navigated -= x)
                         .Do(_ => IsBackButtonVisible = mainFrame.CanGoBack)
                         .Where(ep => ep.NavigationMode == NavigationMode.Back)
                         .Select(ep =>
            {
                if (!(ep.Content is IViewFor view))
                {
                    _logger.Debug($"The view ({ep.Content.GetType()}) does not implement IViewFor<>.  Cannot set ViewModel from a back navigation.");
                }
Example #15
0
        internal static Type[] GetTypesFromAssembly(
            Assembly assembly,
            IFullLogger log)
        {
            try
            {
                return(assembly.GetTypes());
            }
            catch (ReflectionTypeLoadException e)
            {
                // The array returned by the Types property of this exception contains a Type
                // object for each type that was loaded and null for each type that could not
                // be loaded, while the LoaderExceptions property contains an exception for
                // each type that could not be loaded.
                if (log != null)
                {
                    log.Warn(e, "Exception while detecting drawing types.");

                    foreach (var loaderException in e.LoaderExceptions)
                    {
                        log.Warn(loaderException, "Inner Exception for detecting drawing types.");
                    }
                }

                // null check here because mono doesn't appear to follow the MSDN documentation
                // as of July 2019.
                return(e.Types != null
                    ? e.Types.Where(x => x != null).ToArray()
                    : Array.Empty <Type>());
            }
        }
Example #16
0
        public static void LogIfThrows(this IFullLogger This, LogLevel level, string message, Action block)
        {
            try {
                block();
            } catch (Exception ex) {
                switch (level)
                {
                case LogLevel.Debug:
                    This.DebugException(message ?? "", ex);
                    break;

                case LogLevel.Info:
                    This.InfoException(message ?? "", ex);
                    break;

                case LogLevel.Warn:
                    This.WarnException(message ?? "", ex);
                    break;

                case LogLevel.Error:
                    This.ErrorException(message ?? "", ex);
                    break;
                }

                throw;
            }
        }
Example #17
0
        public static async Task <T> LogIfThrows <T>(this IFullLogger This, LogLevel level, string message, Func <Task <T> > block)
        {
            try {
                return(await block());
            } catch (Exception ex) {
                switch (level)
                {
                case LogLevel.Debug:
                    This.DebugException(message ?? "", ex);
                    break;

                case LogLevel.Info:
                    This.InfoException(message ?? "", ex);
                    break;

                case LogLevel.Warn:
                    This.WarnException(message ?? "", ex);
                    break;

                case LogLevel.Error:
                    This.ErrorException(message ?? "", ex);
                    break;
                }
                throw;
            }
        }
Example #18
0
        /// <summary>
        /// Sends the value provided by the provided delegate, only if Info is enabled.
        /// </summary>
        /// <param name="logger">The logger to use.</param>
        /// <param name="function">The function to evaluate if Info logging is enabled.</param>
        /// <param name="exception">A exception to log about.</param>
        public static void InfoException(this IFullLogger logger, Func <string> function, Exception exception)
        {
            if (logger.IsInfoEnabled)
            {
#pragma warning disable CS0618 // Type or member is obsolete
                logger.InfoException(function.Invoke(), exception);
#pragma warning restore CS0618 // Type or member is obsolete
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="FunctionalFullLogger"/> class.
        /// </summary>
        /// <param name="fullLogger">The splat full logger that will be used</param>
        /// <exception cref="ArgumentNullException">No splat logger was passed</exception>
        public FunctionalFullLogger([NotNull]IFullLogger fullLogger)
        {
            if (fullLogger == null)
            {
                throw new ArgumentNullException(nameof(fullLogger));
            }

            this._fullLogger = fullLogger;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="NavigationView"/> class.
        /// </summary>
        /// <param name="mainScheduler">The main scheduler to scheduler UI tasks on.</param>
        /// <param name="backgroundScheduler">The background scheduler.</param>
        /// <param name="viewLocator">The view locator which will find views associated with view models.</param>
        public NavigationView(IScheduler mainScheduler, IScheduler backgroundScheduler, IViewLocator viewLocator)
        {
            InitializeComponent();

            _logger = this.Log();

            _backgroundScheduler = backgroundScheduler;
            _mainScheduler       = mainScheduler;
            _viewLocator         = viewLocator;

            _mirroredPageStack  = new Stack <IViewModel?>();
            _mirroredModalStack = new Stack <IViewModel?>();

            backButton.Visibility = Visibility.Collapsed;

            PagePopped = Observable
                         .FromEvent <NavigatedEventHandler, NavigationEventArgs>(
                handler =>
            {
                return((sender, e) => handler(e));
            },
                x => mainFrame.Navigated += x,
                x => mainFrame.Navigated -= x)
                         .Do(args =>
            {
                if (mainFrame.CanGoBack)
                {
                    IsBackButtonVisible = true;
                }
                else
                {
                    IsBackButtonVisible = false;
                }
            })
                         .Where(ep => ep.NavigationMode == NavigationMode.Back)
                         .Select(ep =>
            {
                var view = ep.Content as IViewFor;
                if (view == null)
                {
                    _logger.Debug($"The view ({ep.Content.GetType()}) does not implement IViewFor<>.  Cannot set ViewModel from a back navigation.");
                }
                else
                {
                    view.ViewModel = _mirroredPageStack.Peek();
                }

                // Since view stack doesn't contain instances (only types), we have to store the latest viewmodel and return it on a back nav.
                // ep.Content contains an instance of the new view, but it may have just been created and its ViewModel property will be null.
                // But we want the view that was just removed.  We need to send the old view's viewmodel to IViewStackService so that the ViewModel can be removed from the stack.
                return(_lastPoppedViewModel);
            })
                         .WhereNotNull();

            BackRequested.Subscribe();
        }
Example #21
0
        public static IDisposable Measure(this IFullLogger log, string message, Action <string> logLevel = null)
        {
            var start = DateTime.Now;

            return(Disposable.Create(() =>
            {
                var elapsed = DateTime.Now - start;
                (logLevel ?? log.Info)(message + " took " + elapsed.Humanize(2));
            }));
        }
Example #22
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NavigationView"/> class.
        /// </summary>
        /// <param name="mainScheduler">The main scheduler to scheduler UI tasks on.</param>
        /// <param name="backgroundScheduler">The background scheduler.</param>
        /// <param name="viewLocator">The view locator which will find views associated with view models.</param>
        /// <param name="rootPage">The starting root page.</param>
        public NavigationView(IScheduler mainScheduler, IScheduler backgroundScheduler, IViewLocator viewLocator, Page rootPage)
            : base(rootPage)
        {
            _backgroundScheduler = backgroundScheduler;
            _mainScheduler       = mainScheduler;
            _viewLocator         = viewLocator;
            _logger = this.Log();

            PagePopped = Observable
                         .FromEventPattern <NavigationEventArgs>(x => Popped += x, x => Popped -= x)
                         .Select(ep => ep.EventArgs.Page.BindingContext as IViewModel)
                         .WhereNotNull();
        }
Example #23
0
        internal static Dictionary <string, int> GetDrawableList(
            IFullLogger log,
            Assembly[] assemblies)
        {
            // VS2019 onward
            var drawableTypes = assemblies
                                .AsParallel()
                                .SelectMany(a => GetTypesFromAssembly(a, log))
                                .Where(x => x.Name.Equals("Resource", StringComparison.Ordinal) && x.GetNestedType("Drawable") != null)
                                .Select(x => x.GetNestedType("Drawable"))
                                .ToArray();

            if (log?.IsDebugEnabled == true)
            {
                var output = new StringBuilder();
                output.Append("DrawableList. Got ").Append(drawableTypes.Length).AppendLine(" types.");

                foreach (var drawableType in drawableTypes)
                {
                    output.Append("DrawableList Type: ").AppendLine(drawableType.Name);
                }

                log.Debug(output.ToString());
            }

            var result = drawableTypes
                         .AsParallel()
                         .SelectMany(x => x.GetFields())
                         .Where(x => x.FieldType == typeof(int) && x.IsLiteral)
                         .ToDictionary(k => k.Name, v => (int)v.GetRawConstantValue());

            if (log?.IsDebugEnabled == true)
            {
                var output = new StringBuilder();
                output.Append("DrawableList. Got ").Append(result.Count).AppendLine(" items.");

                foreach (var keyValuePair in result)
                {
                    output.Append("DrawableList Item: ").AppendLine(keyValuePair.Key);
                }

                log.Debug(output.ToString());
            }

            return(result);
        }
Example #24
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;
            }
        }
        /// <summary>
        /// Sends the value provided by the provided delegate, only if Debug is enabled.
        /// </summary>
        /// <param name="logger">The logger to use.</param>
        /// <param name="function">The function to evaluate if Debug logging is enabled.</param>
        public static void Info(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.IsInfoEnabled)
            {
                logger.Info(function.Invoke());
            }
        }
Example #26
0
        internal void ProcessChatCommand(object sender, CommandEventArgs e)
        {
            Window1.< > c__DisplayClass16_0 CS$ < > 8__locals1 = new Window1.< > c__DisplayClass16_0();
            CS$ < > 8__locals1.e           = e;
            CS$ < > 8__locals1.< > 4__this = this;
            IFullLogger      @default = LogHost.Default;
            string           str      = "[ProcessChatCommand] New command: ";
            CommandEventArgs e2       = CS$ < > 8__locals1.e;

            @default.Info(str + ((e2 != null) ? e2.ToString() : null));
            CS$ < > 8__locals1.mem = ((sender is FFXIVMemory) ? (sender as FFXIVMemory) : Program.mem);
            if (CS$ < > 8__locals1.mem == null)
            {
                return;
            }
            if (CS$ < > 8__locals1.e.Command == Command.Hunt && this.hunts != null)
            {
                Window1.< > c__DisplayClass16_1 CS$ < > 8__locals2 = new Window1.< > c__DisplayClass16_1();
                CS$ < > 8__locals2.CS$ < > 8__locals1 = CS$ < > 8__locals1;
                Tuple <ushort, ushort, float, float> hi;
                if (GameResources.TryGetDailyHuntInfo(CS$ < > 8__locals2.CS$ < > 8__locals1.e.Parameter, out hi))
                {
                    CS$ < > 8__locals2.CS$ < > 8__locals1.mem.WriteChatMessage(ChatMessage.MakePosChatMessage(string.Format(CultureInfo.CurrentCulture, FFXIV_GameSense.Properties.Resources.LKICanBeFoundAt, GameResources.GetEnemyName((uint)hi.Item1, true)), hi.Item2, hi.Item3, hi.Item4, "", 0));
                    return;
                }
                if (FFXIVHunts.Worlds.First <KeyValuePair <ushort, World> >().Value.Hunts.Exists((Hunt x) => x.Name.Equals(CS$ < > 8__locals2.CS$ < > 8__locals1.e.Parameter, StringComparison.OrdinalIgnoreCase)))
                {
                    this.hunts.QueryHunt(FFXIVHunts.Worlds.First <KeyValuePair <ushort, World> >().Value.Hunts.First((Hunt x) => x.Name.Equals(CS$ < > 8__locals2.CS$ < > 8__locals1.e.Parameter, StringComparison.OrdinalIgnoreCase)).Id);
                    return;
                }
                ushort bnpcid;
                if (GameResources.GetEnemyId(CS$ < > 8__locals2.CS$ < > 8__locals1.e.Parameter, out bnpcid))
                {
                    this.hunts.RandomPositionForBNpc(bnpcid);
                    return;
                }
                CS$ < > 8__locals2.fid = GameResources.GetFateId(CS$ < > 8__locals2.CS$ < > 8__locals1.e.Parameter, true);
                if (CS$ < > 8__locals2.fid > 0)
                {
                    this.hunts.LastKnownInfoForFATE(CS$ < > 8__locals2.fid);
                    if (Settings.Default.TrackFATEAfterQuery)
                    {
                        this.vm.FATEEntries.SingleOrDefault((FATEListViewItem x) => x.ID == CS$ < > 8__locals2.fid).Announce = true;
                        return;
                    }
                }
Example #27
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ViewStackService"/> class.
        /// </summary>
        /// <param name="view">The view.</param>
        public ViewStackService(IView view)
        {
            _logger     = this.Log();
            _view       = view;
            _modalStack = new BehaviorSubject <IImmutableList <IPageViewModel> >(ImmutableList <IPageViewModel> .Empty);
            _pageStack  = new BehaviorSubject <IImmutableList <IPageViewModel> >(ImmutableList <IPageViewModel> .Empty);

            // TODO: Make this SubscribeSafe();
            _view.PagePopped.Do(poppedPage =>
            {
                var currentPageStack = _pageStack.Value;
                if (currentPageStack.Count > 0 && poppedPage == currentPageStack[currentPageStack.Count - 1])
                {
                    var removedPage = PopStackAndTick(_pageStack);
                    _logger.Debug("Removed page '{0}' from stack.", removedPage.Id);
                }
            }).SubscribeSafe();
        }
        /// <summary>
        /// Sends the value provided by the provided delegate, only if Debug is enabled.
        /// </summary>
        /// <param name="logger">The logger to use.</param>
        /// <param name="function">The function to evaluate if Debug logging is enabled.</param>
        /// <param name="exception">A exception to log about.</param>
        public static void DebugException(this IFullLogger logger, Func <string> function, Exception exception)
        {
            if (logger is null)
            {
                throw new ArgumentNullException(nameof(logger));
            }

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

            if (logger.IsDebugEnabled)
            {
#pragma warning disable CS0618 // Type or member is obsolete
                logger.DebugException(function.Invoke(), exception);
#pragma warning restore CS0618 // Type or member is obsolete
            }
        }
Example #29
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NavigationView"/> class.
        /// </summary>
        /// <param name="mainScheduler">The main scheduler to scheduler UI tasks on.</param>
        /// <param name="backgroundScheduler">The background scheduler.</param>
        /// <param name="viewLocator">The view locator which will find views associated with view models.</param>
        public NavigationView(IScheduler mainScheduler, IScheduler backgroundScheduler, IViewLocator viewLocator)
        {
            _backgroundScheduler = backgroundScheduler;
            _mainScheduler       = mainScheduler;
            _viewLocator         = viewLocator;
            _logger = this.Log();

            PagePopped =
                Observable
                .FromEvent <EventHandler <NavigationEventArgs>, object>(
                    handler =>
            {
                void Handler(object sender, NavigationEventArgs args) => handler(args.Page.BindingContext);
                return(Handler);
            },
                    x => Popped += x,
                    x => Popped -= x)
                .Cast <IViewModel>();
        }
Example #30
0
        internal static Dictionary <string, int> GetDrawableList(
            IFullLogger log,
            Assembly[] assemblies)
        {
            // VS2019 onward
            var drawableTypes = assemblies
                                .SelectMany(a => GetTypesFromAssembly(a, log))
                                .Where(x => x.Name == "Resource" && x.GetNestedType("Drawable") != null)
                                .Select(x => x.GetNestedType("Drawable"))
                                .ToArray();

            if (log != null)
            {
                log.Debug(() => "DrawableList. Got " + drawableTypes.Length + " types.");
                foreach (var drawableType in drawableTypes)
                {
                    log.Debug(() => "DrawableList Type: " + drawableType.Name);
                }
            }

            var result = drawableTypes
                         .SelectMany(x => x.GetFields())
                         .Where(x => x.FieldType == typeof(int) && x.IsLiteral)
                         .ToDictionary(k => k.Name, v => (int)v.GetRawConstantValue());

            if (log != null)
            {
                log.Debug(() => "DrawableList. Got " + result.Count + " items.");
                foreach (var keyValuePair in result)
                {
                    log.Debug(() => "DrawableList Item: " + keyValuePair.Key);
                }
            }

            return(result);
        }
Example #31
0
 static IFullLogger Log()
 {
     return(logger ??
            (logger = Locator.CurrentMutable.GetService <ILogManager>().GetLogger(typeof(Utility))));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="DefaultExceptionHandler"/> class.
 /// </summary>
 public DefaultExceptionHandler()
 {
     this.logger = this.Log();
 }
Example #33
0
 static Template()
 {
     var service = (ILogManager)Locator.Current.GetService(typeof(ILogManager));
     existingLogger = service.GetLogger(typeof(Template));
 }
 static ClassWithExistingField()
 {
     existingLogger = Locator.Current.GetService<ILogManager>()
         .GetLogger(typeof (ClassWithExistingField));
 }
 private static void Act(IFullLogger logger, LogLevel thresholdLogLevel, [NotNull]Func<string> valueFunction, [NotNull]Action<string, Exception> logAction, [NotNull]Exception ex)
 {
     if (logger.Level <= thresholdLogLevel)
     {
         logAction.Invoke(valueFunction.Invoke(), ex);
     }
 }