コード例 #1
0
        public LogViewAdaptor(ILogViewAdaptorHost <TLogView, TLogEntry> host, TLogView initialState, string grainTypeName, ILogConsistencyProtocolServices services, DocumentClient dbClient, DocumentClient spClient, EventStorageOptions options, JsonSerializerSettings serializerSettings) : base(host, initialState, services)
        {
            _grainTypeName      = grainTypeName;
            _client             = dbClient;
            _storedProcClient   = spClient;
            _serializerSettings = serializerSettings;
            _options            = options;

            _databaseUri         = UriFactory.CreateDatabaseUri(options.DatabaseName);
            _collectionUri       = UriFactory.CreateDocumentCollectionUri(options.DatabaseName, options.CollectionName);
            _commitStoredProcUri = UriFactory.CreateStoredProcedureUri(options.DatabaseName, options.CollectionName, ServerSideRegistry.StoredProcedures.Commit);
        }
コード例 #2
0
        public async Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config)
        {
            Name           = name;
            _serviceId     = providerRuntime.ServiceId;
            _options       = providerRuntime.ServiceProvider.GetRequiredService <IOptions <EventStorageOptions> >().Value;
            _loggerFactory = providerRuntime.ServiceProvider.GetRequiredService <ILoggerFactory>();
            _logger        = _loggerFactory.CreateLogger(nameof(LogConsistencyProvider));

            // TODO - use these serializer settings in the client
            _serializerSettings = new JsonSerializerSettings
            {
                ContractResolver = new CamelCasePropertyNamesContractResolver(),
                TypeNameHandling = TypeNameHandling.All
            };

            _dbClient = new DocumentClient(new Uri(_options.AccountEndpoint), _options.AccountKey, _serializerSettings,
                                           new ConnectionPolicy
            {
                ConnectionMode     = _options.ConnectionMode,
                ConnectionProtocol = _options.ConnectionProtocol
            });

            _spClient = new DocumentClient(new Uri(_options.AccountEndpoint), _options.AccountKey,
                                           new ConnectionPolicy
            {
                ConnectionMode     = _options.ConnectionMode,
                ConnectionProtocol = _options.ConnectionProtocol
            });


            await _dbClient.OpenAsync();

            if (_options.CanCreateResources)
            {
                if (_options.DropDatabaseOnInit)
                {
                    await TryDeleteDatabase();
                }

                await TryCreateDatabaseResources();

                if (_options.AutoUpdateStoredProcedures)
                {
                    await UpdateServerSideLogic();
                }
            }
        }