コード例 #1
0
        public async Task Init(string name, Providers.IProviderRuntime providerRuntime, Providers.IProviderConfiguration config)
        {
            existingCollections = new ConcurrentDictionary <string, bool>();
            createdCollections  = new ConcurrentDictionary <string, bool>();
            Log = providerRuntime.GetLogger("Storage.DocumentDBStorageProvider");
            try
            {
                isFaultTolerant = false; //by default, unless we found otherwise later

                this.jsonSettings = OrleansJsonSerializer.UpdateSerializerSettings(OrleansJsonSerializer.GetDefaultSerializerSettings(), config);
                var url = config.Properties[URL];
                var key = config.Properties[KEY];
                OfferType    = config.Properties[OFFER_TYPE]; //if V1 => S1, S2, S3 else if V2 => RU as integer
                DatabaseName = config.Properties[DATABASE];
                IndexMode    = config.Properties.ContainsKey(INDEXING_MODE) ? config.Properties[INDEXING_MODE] : INDEXING_MODE_CONSISTENT;
                this.Client  = new DocumentClient(new Uri(url), key, new ConnectionPolicy
                {
                    ConnectionMode     = ConnectionMode.Direct,
                    ConnectionProtocol = Protocol.Tcp
                });

                await this.Client.OpenAsync();

                var databases = await this.Client.ReadDatabaseFeedAsync();

                this.Database = databases.Where(d => d.Id == DatabaseName).FirstOrDefault()
                                ?? await this.Client.CreateDatabaseAsync(new Database { Id = DatabaseName });
            }
            catch (Exception ex)
            {
                Log.Error(0, "Error in DocumentDBStorageProvider Init.", ex);
            }
        }
コード例 #2
0
        public CosmosDBGrainStorage(string name, CosmosDBStorageOptions options, SerializationManager serializationManager,
                                    Providers.IProviderRuntime providerRuntime, IPartitionKeyProvider partitionKeyProvider,
                                    IOptions <ClusterOptions> clusterOptions, IGrainFactory grainFactory, ITypeResolver typeResolver, ILoggerFactory loggerFactory)
        {
            this._name = name;
            this._partitionKeyProvider = partitionKeyProvider;
            this._loggerFactory        = loggerFactory;
            var loggerName = $"{typeof(CosmosDBGrainStorage).FullName}.{name}";

            this._logger  = loggerFactory.CreateLogger(loggerName);
            this._options = options;
            this._serializationManager    = serializationManager;
            this._grainFactory            = grainFactory;
            this._typeResolver            = typeResolver;
            this._serviceId               = clusterOptions.Value.ServiceId;
            this._grainReferenceConverter = providerRuntime.ServiceProvider.GetRequiredService <IGrainReferenceConverter>();

            this._sprocFiles = new Dictionary <string, string>
            {
                { LOOKUP_INDEX_SPROC, $"{LOOKUP_INDEX_SPROC}.js" }
            };

            if (this._options.JsonSerializerSettings == null)
            {
                this._options.JsonSerializerSettings = OrleansJsonSerializer.UpdateSerializerSettings(OrleansJsonSerializer.GetDefaultSerializerSettings(this._typeResolver, this._grainFactory),
                                                                                                      this._options.UseFullAssemblyNames,
                                                                                                      this._options.IndentJson,
                                                                                                      this._options.TypeNameHandling);
                this._options.JsonSerializerSettings.DefaultValueHandling       = DefaultValueHandling.Include;
                this._options.JsonSerializerSettings.PreserveReferencesHandling = PreserveReferencesHandling.None;
            }
        }
コード例 #3
0
        public async Task Init(string name, Providers.IProviderRuntime providerRuntime, Providers.IProviderConfiguration config)
        {
            try
            {
                this.Name = name;
                var url = config.Properties["Url"];
                var key = config.Properties["Key"];
                this.databaseName   = config.Properties["Database"];
                this.collectionName = config.Properties["Collection"];

                this.Client = new DocumentClient(new Uri(url), key);

                await this.Client.CreateDatabaseAsync(new Database { Id = this.databaseName });

                var myCollection = new DocumentCollection
                {
                    Id = this.collectionName
                };
                await this.Client.CreateDocumentCollectionAsync(
                    UriFactory.CreateDatabaseUri(this.databaseName),
                    myCollection,
                    new RequestOptions { /*OfferThroughput = 20000 */ });
            }
            catch (Exception ex)
            {
                Log.Error(0, "Error in Init.", ex);
                throw;
            }
        }