Beispiel #1
0
 /// <summary>
 /// Initializes the singleton application object.  This is the first line of authored code
 /// executed, and as such is the logical equivalent of main() or WinMain().
 /// </summary>
 public App()
 {
     DataCache.JsonSerializerSettings = new JsonSerializerSettings
     {
         TypeNameHandling = TypeNameHandling.All
     };
     AppInitializationRoutines.InitializeDependencyInjection(DependenciesRegistration);
     this.InitializeComponent();
     this.Suspending += OnSuspending;
 }
Beispiel #2
0
 public override void OnCreate()
 {
     Log.Debug(nameof(App), "Starting application.");
     Log.Debug(nameof(App), "Starting dependencies registration.");
     AppInitializationRoutines.Init(AdaptersRegistration);
     Log.Debug(nameof(App), "Finished registering dependencies.");
     ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
     Log.Debug(nameof(App), "Finished application start. Commencing Activity launch.");
     base.OnCreate();
 }
Beispiel #3
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            this.ApplyTheme();

            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            AppCenter.Start("c0a878f9-4b3b-4c60-b56d-41e237fbf515", typeof(Analytics), typeof(Crashes));
            SetContentView(Resource.Layout.activity_main);

            if (!_initialized)
            {
                App.NavigationManager = new NavigationManager <PageIndex>(
                    SupportFragmentManager,
                    RootView,
                    new DependencyResolver());
                App.DialogManager = new CustomDialogsManager <DialogIndex>(
                    SupportFragmentManager,
                    new Dictionary <DialogIndex, ICustomDialogProvider>
                {
                    { DialogIndex.ChangelogDialog, new OneshotCustomDialogProvider <ChangelogDialog>() }
                },
                    new DependencyResolver());

                AppInitializationRoutines.InitializeDependencies();


                using (var scope = ResourceLocator.ObtainScope())
                {
                    ViewModel = scope.Resolve <MainViewModel>();
                    _logger   = scope.Resolve <ILogger <MainActivity> >();
                }
                SetSupportActionBar(Toolbar);
                InitDrawer();
                ViewModel.Initialize();

                _initialized = true;
            }
            else
            {
                App.NavigationManager.RestoreState(SupportFragmentManager, RootView);
                App.DialogManager.ChangeFragmentManager(SupportFragmentManager);
                if (App.NavigationManager.CurrentPage == PageIndex.Feed)
                {
                    App.NavigationManager.PageDefinitions[PageIndex.Feed].Page.NavigatedTo();
                }
                SetSupportActionBar(Toolbar);
                InitDrawer();
            }
        }
Beispiel #4
0
 public override void OnCreate()
 {
     DataCache.JsonSerializerSettings = new JsonSerializerSettings()
     {
         TypeNameHandling = TypeNameHandling.All
     };
     ImageService.Instance.Config.HttpClient = new HttpClient(new NativeMessageHandler(
                                                                  throwOnCaptiveNetwork: false,
                                                                  new TLSConfig
     {
         DangerousAcceptAnyServerCertificateValidator = true,
         DangerousAllowInsecureHTTPLoads = true
     })
     {
         AllowAutoRedirect = true
     });
     AppInitializationRoutines.InitializeDependencyInjection(DependenciesRegistration);
 }
Beispiel #5
0
        /// <summary>
        /// Invoked when the application is launched normally by the end user.  Other entry points
        /// will be used such as when the application is launched to open a specific file.
        /// </summary>
        /// <param name="e">Details about the launch request and process.</param>
        protected override void OnLaunched(LaunchActivatedEventArgs e)
        {
            Frame rootFrame = Window.Current.Content as Frame;

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active
            if (rootFrame == null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();

                rootFrame.NavigationFailed += OnNavigationFailed;

                if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
                {
                    //TODO: Load state from previously suspended application
                }

                // Place the frame in the current Window
                Window.Current.Content = rootFrame;
            }

            if (e.PrelaunchActivated == false)
            {
                if (rootFrame.Content == null)
                {
                    // When the navigation stack isn't restored navigate to the first page,
                    // configuring the new page by passing required information as a navigation
                    // parameter
                    rootFrame.Navigate(typeof(MainPage), e.Arguments);
                    AppInitializationRoutines.InitializeDependencies();
                }
                // Ensure the current window is active
                Window.Current.Activate();
            }
        }
Beispiel #6
0
        public override bool OnStartJob(JobParameters jobParameters)
        {
            Log.Info(nameof(FeedUpdateService), "Starting feed update job service.");
            Task.Run(async() =>
            {
                try
                {
                    AppInitializationRoutines.InitializeDependenciesForBackground(DependenciesRegistration);
                    using (var scope = ResourceLocator.ObtainScope())
                    {
                        var userDataProvider = scope.Resolve <IUserDataProvider>();
                        await userDataProvider.Initialize();

                        if (!userDataProvider.CrawlingSets.Any())
                        {
                            return;
                        }

                        var feedProvider        = scope.Resolve <IFeedProvider>();
                        var feedHistoryProvider = scope.Resolve <IFeedHistoryProvider>();
                        var cts             = new CancellationTokenSource();
                        var tcs             = new TaskCompletionSource <bool>();
                        var finishSemaphore = new SemaphoreSlim(1);

                        feedProvider.NewCrawlerBatch += async(sender, batch) =>
                        {
                            try
                            {
                                await finishSemaphore.WaitAsync(cts.Token);

                                if (batch.CrawlerResult.Success)
                                {
                                    if (await feedHistoryProvider.HasAnyChanged(
                                            batch.SetOfOrigin,
                                            batch.CrawlerResult.Results))
                                    {
                                        cts.Cancel();
                                        Log.Info(nameof(FeedUpdateService), "Found new feed content.");
                                        tcs.SetResult(true);
                                    }
                                }
                            }
                            catch (TaskCanceledException)
                            {
                            }
                            finally
                            {
                                finishSemaphore.Release();
                            }
                        };

                        feedProvider.Finished += async(sender, args) =>
                        {
                            if (tcs.Task.IsCompleted)
                            {
                                return;
                            }
                            try
                            {
                                await finishSemaphore.WaitAsync(cts.Token);
                                if (tcs.Task.IsCompleted)
                                {
                                    return;
                                }
                                tcs.SetResult(false);
                            }
                            catch
                            {
                                //not important at this point
                            }
                        };

                        feedProvider.StartAggregating(
                            userDataProvider.CrawlingSets.ToList(),
                            cts.Token,
                            true);

                        var result = await tcs.Task;

                        if (result)
                        {
                            var builder = new NotificationCompat.Builder(this, FeedUpdateChannel)
                                          .SetSmallIcon(Resource.Drawable.icon_logo_small)
                                          .SetContentTitle(AppResources.Notification_FeedUpdate)
                                          .SetContentText(AppResources.Notification_FeedUpdate_Description)
                                          .SetPriority(NotificationCompat.PriorityDefault);
                            CreateNotificationChannel();

                            var manager = NotificationManager.FromContext(this);
                            manager.Notify(NotificationId, builder.Build());
                        }

                        Log.Info(nameof(FeedUpdateService), "Finishing feed update job service.");
                        JobFinished(jobParameters, true);
                    }
                }
                catch (Exception e)
                {
                    Log.Error(nameof(FeedUpdateService), $"Failed to process feed update notification. {e}");
                }
            });

            return(true);
        }
Beispiel #7
0
 public override void OnCreate()
 {
     AppInitializationRoutines.Initialize(AdaptersRegistration);
     ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
     base.OnCreate();
 }