Пример #1
0
        public MongoTables(
            ILoggingService loggingService,
            ITextHelpers textHelpers,
            IConfiguration configuration)
        {
            Ensure.Argument.IsNotNull(loggingService, nameof(loggingService));
            Ensure.Argument.IsNotNull(textHelpers, nameof(textHelpers));
            Ensure.Argument.IsNotNull(configuration, nameof(configuration));

            this.configuration = configuration;

            // Configure the Mongo connection.
            var clientSettings = new MongoClientSettings
            {
                Servers         = configuration.MongoServers.Select(kv => new MongoServerAddress(kv.Key, kv.Value)),
                ApplicationName = "MainApp",
                //WriteConcern = WriteConcern.WMajority,
                //ReadConcern = ReadConcern.Majority,
                ReadPreference     = ReadPreference.Nearest,
                GuidRepresentation = GuidRepresentation.Standard
            };

            // If needed, set up logging.
            if (configuration.MongoDebug)
            {
                clientSettings.ClusterConfigurator = cluster =>
                {
                    cluster.Subscribe <CommandStartedEvent>(e => loggingService.Info("[Mongo] {0} Started - {1}", e.CommandName, e.Command.ToJson()));
                    cluster.Subscribe <CommandSucceededEvent>(e => loggingService.Info("[Mongo] {0} Succeeded - {1}", e.CommandName, e.Reply.ToJson()));
                    cluster.Subscribe <CommandFailedEvent>(e => loggingService.Exception(e.Failure, "[Mongo] {0} Failed", e.CommandName));
                }
            }
            ;

            // Configure serialization.
            var conventionPack = new ConventionPack();

            conventionPack.Add(new SnakeCaseElementNameConvention(textHelpers));
            ConventionRegistry.Register("snakeCase", conventionPack, t => true);

            // Create the client and get a reference to the Db.
            var client = new MongoClient(clientSettings);

            this.database = client.GetDatabase(configuration.MongoDatabaseName);

            // Create the initializer for this component.
            this.initializer = new TaskRunner(this.InitializeOnceAsync);
        }
Пример #2
0
        protected async Task InternalNavigateToAsync(Type viewModelType, object parameter, bool clearStack = false)
        {
            try
            {
                var page = CreatePage(viewModelType, parameter);

                var cp = CurrentApplication.MainPage as NavigationPage;

                if (cp == null || clearStack)
                {
                    cp = new NavigationPage(page);
                    CurrentApplication.MainPage = cp;
                }
                else
                {
                    await cp.PushAsync(page);
                }
            }
            catch (Exception e)
            {
                loggingService.Exception(e);
            }
        }