Exemple #1
0
        /// <summary> Initialization function for this storage provider. </summary>
        /// <see cref="IProvider#Init"/>
        public async Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config)
        {
            serviceId = providerRuntime.ServiceId.ToString();
            Log       = providerRuntime.GetLogger("StorageProvider.SimpleSQLServerStorage." + serviceId);

            try
            {
                Name = name;

                _serializationManager = providerRuntime.ServiceProvider.GetRequiredService <SerializationManager>();
                this.jsonSettings     = OrleansJsonSerializer.UpdateSerializerSettings(OrleansJsonSerializer.GetDefaultSerializerSettings(_serializationManager, providerRuntime.GrainFactory), config);

                if (!config.Properties.ContainsKey(CONNECTION_STRING) || string.IsNullOrWhiteSpace(config.Properties[CONNECTION_STRING]))
                {
                    throw new BadProviderConfigException($"Specify a value for: {CONNECTION_STRING}");
                }
                var connectionString = config.Properties[CONNECTION_STRING];
                sqlconnBuilder = new SqlConnectionStringBuilder(connectionString);

                //a validation of the connection would be wise to perform here
                var sqlCon = new SqlConnection(sqlconnBuilder.ConnectionString);
                await sqlCon.OpenAsync();

                sqlCon.Close();

                //initialize to use the default of JSON storage (this is to provide backwards compatiblity with previous version
                useJsonOrBinaryFormat = StorageFormatEnum.Binary;

                if (config.Properties.ContainsKey(USE_JSON_FORMAT_PROPERTY))
                {
                    if ("true".Equals(config.Properties[USE_JSON_FORMAT_PROPERTY], StringComparison.OrdinalIgnoreCase))
                    {
                        useJsonOrBinaryFormat = StorageFormatEnum.Json;
                    }

                    if ("both".Equals(config.Properties[USE_JSON_FORMAT_PROPERTY], StringComparison.OrdinalIgnoreCase))
                    {
                        useJsonOrBinaryFormat = StorageFormatEnum.Both;
                    }
                }

                if (config.Properties.ContainsKey(THROW_ON_DESERIALIZE_ERROR))
                {
                    if ("false".Equals(config.Properties[THROW_ON_DESERIALIZE_ERROR], StringComparison.OrdinalIgnoreCase))
                    {
                        throwOnDeserializeError = false;
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error((int)SimpleSQLServerProviderErrorCodes.SimpleSQLServerProvider_InitProvider, ex.ToString(), ex);
                throw;
            }
        }
Exemple #2
0
        /// <summary> Initialization function for this storage provider. </summary>
        /// <see cref="IProvider#Init"/>
        public async Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config)
        {
            Name      = name;
            serviceId = providerRuntime.ServiceId.ToString();

            if (!config.Properties.ContainsKey(CONNECTION_STRING) ||
                string.IsNullOrWhiteSpace(config.Properties[CONNECTION_STRING]))
            {
                throw new ArgumentException("Specify a value for:", CONNECTION_STRING);
            }
            var connectionString = config.Properties[CONNECTION_STRING];

            sqlconnBuilder = new SqlConnectionStringBuilder(connectionString);

            //a validation of the connection would be wise to perform here
            //await new SqlConnection(sqlconnBuilder.ConnectionString).OpenAsync();

            //initialize to use the default of JSON storage (this is to provide backwards compatiblity with previous version
            useJsonOrBinaryFormat = StorageFormatEnum.Binary;

            if (config.Properties.ContainsKey(USE_JSON_FORMAT_PROPERTY))
            {
                if ("true".Equals(config.Properties[USE_JSON_FORMAT_PROPERTY], StringComparison.OrdinalIgnoreCase))
                {
                    useJsonOrBinaryFormat = StorageFormatEnum.Json;
                }

                if ("both".Equals(config.Properties[USE_JSON_FORMAT_PROPERTY], StringComparison.OrdinalIgnoreCase))
                {
                    useJsonOrBinaryFormat = StorageFormatEnum.Both;
                }
            }

            jsonSettings = new Newtonsoft.Json.JsonSerializerSettings()
            {
                TypeNameHandling           = TypeNameHandling.All,
                PreserveReferencesHandling = PreserveReferencesHandling.Objects,
                DateFormatHandling         = DateFormatHandling.IsoDateFormat,
                DefaultValueHandling       = DefaultValueHandling.Ignore,
                MissingMemberHandling      = MissingMemberHandling.Ignore,
                NullValueHandling          = NullValueHandling.Ignore,
                ConstructorHandling        = ConstructorHandling.AllowNonPublicDefaultConstructor
            };

            Log = providerRuntime.GetLogger("StorageProvider.SimpleSQLServerStorage." + serviceId);
        }
        /// <summary> Initialization function for this storage provider. </summary>
        /// <see cref="IProvider#Init"/>
        public async Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config)
        {
            serviceId = providerRuntime.ServiceId.ToString();
            Log = providerRuntime.GetLogger("StorageProvider.SimpleSQLServerStorage." + serviceId);

            try
            {
                Name = name;
                this.jsonSettings = OrleansJsonSerializer.UpdateSerializerSettings(OrleansJsonSerializer.GetDefaultSerializerSettings(), config);

                if (!config.Properties.ContainsKey(CONNECTION_STRING) || string.IsNullOrWhiteSpace(config.Properties[CONNECTION_STRING]))
                {
                    throw new BadProviderConfigException($"Specify a value for: {CONNECTION_STRING}");
                }
                var connectionString = config.Properties[CONNECTION_STRING];
                sqlconnBuilder = new SqlConnectionStringBuilder(connectionString);

                //a validation of the connection would be wise to perform here
                var sqlCon = new SqlConnection(sqlconnBuilder.ConnectionString);
                await sqlCon.OpenAsync();
                sqlCon.Close();

                //initialize to use the default of JSON storage (this is to provide backwards compatiblity with previous version
                useJsonOrBinaryFormat = StorageFormatEnum.Binary;

                if (config.Properties.ContainsKey(USE_JSON_FORMAT_PROPERTY))
                {
                    if ("true".Equals(config.Properties[USE_JSON_FORMAT_PROPERTY], StringComparison.OrdinalIgnoreCase))
                        useJsonOrBinaryFormat = StorageFormatEnum.Json;

                    if ("both".Equals(config.Properties[USE_JSON_FORMAT_PROPERTY], StringComparison.OrdinalIgnoreCase))
                        useJsonOrBinaryFormat = StorageFormatEnum.Both;
                }
            }
            catch (Exception ex)
            {
                Log.Error((int) SimpleSQLServerProviderErrorCodes.SimpleSQLServerProvider_InitProvider, ex.ToString(), ex);
                throw;
            }
        }