Exemplo n.º 1
0
        public static IFhirService GetFhirService(Uri baseUri, IStorageBuilder storageBuilder,
                                                  IServiceListener[] listeners = null)
        {
            FhirExtensionsBuilder extensionsBuilder = new FhirExtensionsBuilder(storageBuilder, baseUri);

            return(GetFhirService(baseUri, extensionsBuilder, storageBuilder, listeners));
        }
        /// <summary>
        /// Uses the EntityFramework Core as a storage for saving and loading data.
        /// <para>
        /// Note: It means Parbad can save and load the data in different database providers
        /// such as SQL Server, MySql, Sqlite, PostgreSQL, Oracle, InMemory, etc.
        /// For more information see: https://docs.microsoft.com/en-us/ef/core/providers/.
        /// </para>
        /// <para>Note: This database is only for internal usages such as saving and loading payment information.
        /// You don't need to think about merging and using this database with your own database.
        /// The important payment information such as Tracking Number, Transaction Code, etc. will you get from the result of
        /// all payment requests.</para>
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="configureEfCoreOptions">Configures the EntityFrameworkCore options for Parbad.</param>
        public static IStorageBuilder UseEfCore(this IStorageBuilder builder, Action <EntityFrameworkCoreOptions> configureEfCoreOptions)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }
            if (configureEfCoreOptions == null)
            {
                throw new ArgumentNullException(nameof(configureEfCoreOptions));
            }

            var options = new EntityFrameworkCoreOptions();

            configureEfCoreOptions(options);

            builder.Services.Configure(configureEfCoreOptions);

            builder.Services.AddDbContext <ParbadDataContext>(dbBuilder =>
            {
                options.ConfigureDbContext?.Invoke(dbBuilder);
            });

            builder.AddStorage <EntityFrameworkCoreStorage>(ServiceLifetime.Transient);

            builder.AddStorageManager <EntityFrameworkCoreStorageManager>(ServiceLifetime.Transient);

            return(builder);
        }
        /// <summary>
        /// Uses <see cref="IDistributedCache"/> for saving and loading data.
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="configureOptions"></param>
        public static IStorageBuilder UseDistributedCache(this IStorageBuilder builder, Action <DistributedCacheStorageOptions> configureOptions)
        {
            builder.Services.Configure(configureOptions);
            builder.AddStorage <DistributedCacheStorage>(ServiceLifetime.Transient);

            return(builder);
        }
Exemplo n.º 4
0
        public static IDomainStorageBuilder UseDomainStorage(this IStorageBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            var services = builder.Services;

            // Configure necessary application parts
            services.ConfigureApplicationParts(ConfigureFeatureProviders);

            // TODO: Replace
            //services.AddSingleton(new JsonSerializerSettings
            //{
            //    TypeNameHandling = TypeNameHandling.Auto,
            //    Formatting = Formatting.Indented,
            //    PreserveReferencesHandling = PreserveReferencesHandling.Objects,
            //    ReferenceLoopHandling = ReferenceLoopHandling.Serialize,
            //    ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor
            //});

            services.AddTransient <ISerializerSettingsResolver, SerializerSettingsResolver>();

            AddStreamStore(services);
            AddDomainStorageEngine(services);
            AddProjectionEngine(services);
            AddMessageProcessors(services);

            return(new DomainStorageBuilder(builder));
        }
Exemplo n.º 5
0
 public ScopedFhirServiceBuilder(Uri baseUri, IStorageBuilder <TScope> storageBuilder,
                                 IServiceListener[] listeners = null)
 {
     this.baseUri        = baseUri;
     this.storageBuilder = storageBuilder;
     this.listeners      = listeners;
     this.fhirService    = FhirServiceFactory.GetFhirService(baseUri, storageBuilder, listeners);
 }
Exemplo n.º 6
0
        /// <summary>
        /// Uses the default implementation of <see cref="IStorageManager"/>.
        /// </summary>
        /// <param name="builder"></param>
        public static IStorageBuilder UseDefaultStorageManager(this IStorageBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            return(builder.AddStorageManager <StorageManager>(ServiceLifetime.Transient));
        }
        public static IStorageBuilder UseInMemoryDatabase(this IStorageBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            builder.UseDatabase <InMemoryDatabase>();

            return(builder);
        }
 public static IStorageBuilder AddSqlServerQueue(this IStorageBuilder builder, string name, Action <SqlServerQueueOptions> configure)
 {
     builder.AddQueueClient <SqlServerQueueClient, SqlServerQueueOptions>(name, configure);
     builder.Services.AddDbContext <QueueDbContext>((serviceProvider, dbContextBuilder) =>
     {
         var optionsMonitor = serviceProvider.GetRequiredService <IOptionsMonitor <SqlServerQueueOptions> >();
         var options        = optionsMonitor.Get(Helpers.GetQualifiedQueueName(name));
         dbContextBuilder.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking);
         dbContextBuilder.UseSqlServer(options.ConnectionString);
     }, ServiceLifetime.Singleton, ServiceLifetime.Singleton);
     return(builder);
 }
Exemplo n.º 9
0
        public FhirExtensionsBuilder(IStorageBuilder fhirStoreBuilder, Uri baseUri)
        {
            this.fhirStoreBuilder = fhirStoreBuilder;
            this.baseUri          = baseUri;
            var extensionBuilders = new Func <IFhirServiceExtension>[]
            {
                GetSearch,
                GetHistory,
                GetConformance,
                GetPaging,
                GetStorage
            };

            extensions = extensionBuilders.Select(builder => builder()).Where(ext => ext != null).ToList();
        }
Exemplo n.º 10
0
        /// <summary>
        /// Adds an implementation of <see cref="IStorageManager"/> which required by Parbad for managing the storage operations.
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="factory"></param>
        /// <param name="lifetime">The lifetime of given StorageManager.</param>
        public static IStorageBuilder AddStorageManager(this IStorageBuilder builder, Func <IServiceProvider, IStorageManager> factory, ServiceLifetime lifetime)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }
            if (factory == null)
            {
                throw new ArgumentNullException(nameof(factory));
            }

            builder.Services.AddOrUpdate(factory, lifetime);

            return(builder);
        }
Exemplo n.º 11
0
        public static IStorageBuilder Configure(this IStorageBuilder builder, Action <StorageOptions> configuration)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            builder.Services.Configure(configuration);

            return(builder);
        }
Exemplo n.º 12
0
        public static IStorageBuilder ExtendStorage(this IStorageBuilder builder,
                                                    IEnumerable <IStorageExtension> extensions)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            if (extensions == null)
            {
                throw new ArgumentNullException(nameof(extensions));
            }


            // TODO
            return(builder); // .Configure(options => options.Extensions.AddRange(hooks));
        }
Exemplo n.º 13
0
        /// <summary>
        /// Adds an implementation of <see cref="IStorageManager"/> which required by Parbad for managing the storage operations.
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="storageManager"></param>
        public static IStorageBuilder AddStorageManager(this IStorageBuilder builder, IStorageManager storageManager)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }
            if (storageManager == null)
            {
                throw new ArgumentNullException(nameof(storageManager));
            }

            builder.Services
            .RemoveAll <IStorageManager>()
            .AddSingleton(storageManager);

            return(builder);
        }
        public static IStorageBuilder UseMongoDB(this IStorageBuilder builder, Action <MongoOptions> configuration, bool useNativeTransactions = false)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            builder.UseMongoDB(useNativeTransactions);

            builder.Services.Configure(configuration);

            return(builder);
        }
        /// <summary>
        /// Uses the Entityframework Core as a storage for saving and loading data.
        /// <para>
        /// Note: It means Parbad can save and load the data in different database providers
        /// such as SQL Server, MySql, Sqlite, PostgreSQL, Oracle, InMemory, etc.
        /// For more information see: https://docs.microsoft.com/en-us/ef/core/providers/.
        /// </para>
        /// <para>Note: This database is only for internal usages such as saving and loading payment information.
        /// You don't need to think about merging and using this database with your own database.
        /// The important payment information such as Tracking Number, Transaction Code, etc. will you get from the result of
        /// all payment requests.</para>
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="configureDatabaseBuilder">Configure what database must be used and how it must be created.</param>
        public static IEntityFrameworkCoreStorageBuilder UseEntityFrameworkCore(this IStorageBuilder builder,
                                                                                Action <DbContextOptionsBuilder> configureDatabaseBuilder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }
            if (configureDatabaseBuilder == null)
            {
                throw new ArgumentNullException(nameof(configureDatabaseBuilder));
            }

            builder.Services.AddDbContext <ParbadDataContext>(configureDatabaseBuilder);

            builder.AddStorage <EntityFrameworkCoreStorage>(ServiceLifetime.Transient);

            return(new EntityFrameworkCoreStorageBuilder(builder.Services));
        }
Exemplo n.º 16
0
        public static IDomainStorageBuilder UseDomainStorage(this IStorageBuilder builder,
                                                             Action <DomainStorageOptions> configuration)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            var result = UseDomainStorage(builder);

            result.Services.Configure(configuration);
            return(result);
        }
Exemplo n.º 17
0
        public static IFhirService GetFhirService(Uri baseUri, IFhirExtensionsBuilder extensionsBuilder,
                                                  IStorageBuilder storageBuilder, //we won't need this anymore if we can remove the Transfer dependency for IFhirService
                                                  IServiceListener[] listeners = null)
        {
            IGenerator generator = storageBuilder.GetStore <IGenerator>();

            IFhirServiceExtension[] extensions        = extensionsBuilder.GetExtensions().ToArray();
            IServiceListener[]      computedListeners = (listeners ?? Enumerable.Empty <IServiceListener>())
                                                        .Union(extensions.OfType <IServiceListener>())
                                                        .ToArray();
            ICompositeServiceListener serviceListener = new ServiceListener(new Localhost(baseUri), computedListeners);
            Transfer transfer = new Transfer(generator, new Localhost(baseUri));

            return(new FhirService(extensions,
                                   GetFhirResponseFactory(baseUri),
                                   transfer,
                                   serviceListener));
        }
Exemplo n.º 18
0
        public static IStorageBuilder UseDatabase <TDatabase>(this IStorageBuilder builder)
            where TDatabase : class, IDatabase
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            var services = builder.Services;

            services.AddSingleton <IDatabase, TDatabase>();
            services.AddSingleton(p => p.GetRequiredService <IDatabase>() as IFilterableDatabase);
            services.AddSingleton(p => p.GetRequiredService <IDatabase>() as IQueryableDatabase);

            services.UseTransactionSubsystem();

            return(builder);
        }
        public static IStorageBuilder UseMongoDB(this IStorageBuilder builder, string database, bool useNativeTransactions = false)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            if (database == null)
            {
                throw new ArgumentNullException(nameof(database));
            }

            builder.UseMongoDB(useNativeTransactions);

            builder.Services.Configure <MongoOptions>(options =>
            {
                options.Database = database;
            });

            return(builder);
        }
Exemplo n.º 20
0
        /// <summary>
        /// Create default session channels and return IEnumerable list of them.
        /// In the case when checkPendingAsimovEvents == true call method on Vortex channel
        /// to check whether pending telemetry is exists and in case existing Start this channel
        /// immediately.
        /// </summary>
        /// <param name="telemetrySession"></param>
        /// <param name="checkPendingAsimovEvents"></param>
        /// <returns></returns>
        public IEnumerable <ISessionChannel> CreateSessionChannels(TelemetrySession telemetrySession, bool checkPendingAsimovEvents)
        {
            IStorageBuilder     storageBuilder     = GetStorageBuilder();
            IProcessLockFactory processLockFactory = GetProcessLock();

            if (AppInsightsInstrumentationKey != null)
            {
                yield return(new DefaultAppInsightsSessionChannel(AppInsightsInstrumentationKey, telemetrySession.UserId.ToString(), storageBuilder, processLockFactory));
            }
            if (AsimovInstrumentationKey != null)
            {
                AsimovAppInsightsSessionChannel asimovAppInsightsSessionChannel = new AsimovAppInsightsSessionChannel("aivortex", false, AsimovInstrumentationKey, telemetrySession.UserId.ToString(), ChannelProperties.Default | ChannelProperties.NotForUnitTest, telemetrySession, storageBuilder, processLockFactory);
                if (checkPendingAsimovEvents)
                {
                    asimovAppInsightsSessionChannel.CheckPendingEventsAndStartChannel(telemetrySession.SessionId);
                }
                yield return(asimovAppInsightsSessionChannel);

                yield return(new AsimovAppInsightsSessionChannel("aiasimov", Platform.IsWindows, AsimovInstrumentationKey, telemetrySession.UserId.ToString(), ChannelProperties.NotForUnitTest, telemetrySession, storageBuilder, processLockFactory));
            }
            yield return(new TelemetryLogToFileChannel());
        }
        public static IStorageBuilder UseMongoDB(this IStorageBuilder builder, bool useNativeTransactions = false)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            builder.Services.AddOptions();
            builder.Services.AddSingleton(BuildMongoClient);
            builder.Services.AddSingleton(BuildMongoDatabase);

            if (useNativeTransactions)
            {
                builder.UseTransactionalDatabase <MongoDatabase>();
            }
            else
            {
                builder.UseDatabase <MongoDatabase>();
            }

            return(builder);
        }
Exemplo n.º 22
0
        public static IStorageBuilder UseTransactionalDatabase <TDatabase>(this IStorageBuilder builder, Func <IServiceProvider, TDatabase> factory)
            where TDatabase : class, IDatabase, ITransactionalDatabase
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            if (factory == null)
            {
                throw new ArgumentNullException(nameof(factory));
            }

            var services = builder.Services;

            services.AddSingleton <IDatabase, TDatabase>(factory);
            services.AddSingleton(p => p.GetRequiredService <IDatabase>() as IFilterableDatabase);
            services.AddSingleton(p => p.GetRequiredService <IDatabase>() as IQueryableDatabase);

            services.AddSingleton <ITransactionalDatabase, TDatabase>(p => p.GetRequiredService <IDatabase>() as TDatabase);
            services.AddSingleton(p => p.GetRequiredService <ITransactionalDatabase>() as IQueryableTransactionalDatabase);

            return(builder);
        }
Exemplo n.º 23
0
 public static IStorageBuilder AddAzureBlob(this IStorageBuilder storageBuilder, ServiceLifetime serviceLifetime, Action <AzureBlobConfiguration> configure)
 {
     return(storageBuilder.AddAzureBlob(Options.Options.DefaultName, serviceLifetime, configure));
 }
Exemplo n.º 24
0
        /// <summary>
        /// Adds an implementation of <see cref="IStorageManager"/> which required by Parbad for managing the storage operations.
        /// </summary>
        /// <typeparam name="TManager"></typeparam>
        /// <param name="builder"></param>
        /// <param name="lifetime">The lifetime of given StorageManager.</param>
        public static IStorageBuilder AddStorageManager <TManager>(this IStorageBuilder builder, ServiceLifetime lifetime) where TManager : class, IStorageManager
        {
            builder.Services.AddOrUpdate <IStorageManager, TManager>(lifetime);

            return(builder);
        }
Exemplo n.º 25
0
 /// <summary>
 /// Uses the default implementation of <see cref="IStorageManager"/>.
 /// </summary>
 /// <param name="builder"></param>
 public static IStorageBuilder UseDefaultStorageManager(this IStorageBuilder builder)
 {
     return(AddStorageManager <StorageManager>(builder, ServiceLifetime.Transient));
 }
Exemplo n.º 26
0
 public DomainStorageBuilder(IStorageBuilder storageBuilder)
 {
     Assert(storageBuilder != null);
     _storageBuilder = storageBuilder;
 }
Exemplo n.º 27
0
 public static IStorageBuilder AddAzureTable(this IStorageBuilder storageBuilder, string name, ServiceLifetime serviceLifetime, Action <AzureTableConfiguration> configure)
 {
     return(storageBuilder.AddAzureTable <TableItemAssembler>(name, serviceLifetime, configure));
 }
Exemplo n.º 28
0
 public static IStorageBuilder AddAzureTable <TTableItemAssembler>(this IStorageBuilder storageBuilder, string name, ServiceLifetime serviceLifetime, Action <AzureTableConfiguration> configure) where TTableItemAssembler : class, ITableItemAssembler
 {
     storageBuilder.AddTableClient <AzureTableClient>(name, serviceLifetime).Configure(configure);
     storageBuilder.Services.AddSingleton <ITableItemAssembler, TTableItemAssembler>();
     return(storageBuilder);
 }
Exemplo n.º 29
0
 public static IStorageBuilder AddAzureQueue(this IStorageBuilder storageBuilder, string name, ServiceLifetime serviceLifetime, Action <AzureQueueConfiguration> configure)
 {
     storageBuilder.AddQueueClient <AzureQueueClient>(name, serviceLifetime).Configure(configure);
     return(storageBuilder);
 }
 /// <summary>
 /// Uses <see cref="IDistributedCache"/> for saving and loading data.
 /// </summary>
 /// <param name="builder"></param>
 public static IStorageBuilder UseDistributedCache(this IStorageBuilder builder)
 => UseDistributedCache(builder, options => { });