Esempio n. 1
0
        public static RuntimeBuilder AddSqlServerRuntime(this RuntimeBuilder builder,
                                                         string connectionString,
                                                         ConnectionScope scope = ConnectionScope.ByRequest,
                                                         Action <SqlServerOptions> configureDatabase = null)
        {
            void ConfigureDatabase(SqlServerOptions o)
            {
                configureDatabase?.Invoke(o);
            }

            builder.Services.Configure <SqlServerOptions>(ConfigureDatabase);

            var serviceProvider = builder.Services.BuildServiceProvider();

            var options = serviceProvider.GetService <IOptions <SqlServerOptions> >()?.Value ?? new SqlServerOptions();

            configureDatabase?.Invoke(options);

            var dialect = new SqlServerDialect();

            SqlBuilder.Dialect = dialect;

            builder.AddSqlRuntimeStores <SqlServerConnectionFactory>(connectionString, scope, OnCommand(), OnConnection);

            builder.Services.AddMetrics();
            builder.Services.TryAddSingleton <ISqlDialect>(dialect);
            builder.Services.TryAddSingleton(dialect);
            builder.Services.TryAddSingleton <IDataBatchOperation <SqlServerPreBatchStatus>, SqlServerBatchDataOperation>();

            var runtimeOptions = serviceProvider.GetRequiredService <IOptions <RuntimeOptions> >().Value;

            MigrateToLatest(connectionString, runtimeOptions);

            return(builder);
        }
Esempio n. 2
0
#pragma warning disable CA2000 // Dispose objects before losing scope
        private ClrRuntime ConstructRuntime(string dac)
        {
            if (IntPtr.Size != DataTarget.DataReader.PointerSize)
            {
                throw new InvalidOperationException("Mismatched architecture between this process and the dac.");
            }

            DacLibrary dacLibrary = new DacLibrary(DataTarget, dac);

            DacInterface.SOSDac?sos = dacLibrary.SOSDacInterface;
            if (sos is null)
            {
                throw new InvalidOperationException($"Could not create a ISOSDac pointer from this dac library: {dac}");
            }

            var factory = new RuntimeBuilder(this, dacLibrary, sos);

            if (Flavor == ClrFlavor.Core)
            {
                return(factory.GetOrCreateRuntime());
            }

            if (Version.Major < 4 || (Version.Major == 4 && Version.Minor == 5 && Version.Patch < 10000))
            {
                throw new NotSupportedException($"CLR version '{Version}' is not supported by ClrMD.  For Desktop CLR, only CLR 4.6 and beyond are supported.");
            }

            return(factory.GetOrCreateRuntime());
        }
Esempio n. 3
0
File: Add.cs Progetto: qiqi545/HQ
        private static RuntimeBuilder AddDocumentDbRuntimeStores(this RuntimeBuilder builder, string connectionString,
                                                                 ConnectionScope scope, Action <DocumentDbOptions> configureDatabase)
        {
            var slot = Constants.ConnectionSlots.Runtime;

            if (configureDatabase != null)
            {
                builder.Services.Configure(slot, configureDatabase);
            }

            var serviceProvider = builder.Services.BuildServiceProvider();

            var dbOptions = serviceProvider.GetService <IOptions <DocumentDbOptions> >()?.Value ?? new DocumentDbOptions();

            configureDatabase?.Invoke(dbOptions);

            var dialect = new DocumentDbDialect();

            SqlBuilder.Dialect = dialect;

            builder.AddSqlRuntimeStores <DocumentDbConnectionFactory>(connectionString, scope, OnCommand(),
                                                                      OnConnection);

            builder.Services.AddMetrics();
            builder.Services.TryAddSingleton <ISqlDialect>(dialect);
            builder.Services.TryAddSingleton(dialect);
            builder.Services
            .TryAddSingleton <IDataBatchOperation <DocumentDbBatchOptions>, DocumentDbBatchDataOperation>();

            var runtimeOptions = serviceProvider.GetRequiredService <IOptions <RuntimeOptions> >().Value;

            MigrateToLatest(runtimeOptions, dbOptions);

            return(builder);
        }
Esempio n. 4
0
File: Add.cs Progetto: qiqi545/HQ
 public static RuntimeBuilder AddDocumentDbRuntimeStores(this RuntimeBuilder builder, string connectionString,
                                                         ConnectionScope scope, IConfiguration dbConfig)
 {
     return(dbConfig == null
                         ? AddDocumentDbRuntimeStores(builder, connectionString, scope)
                         : AddDocumentDbRuntimeStores(builder, connectionString, scope, dbConfig.FastBind));
 }
Esempio n. 5
0
        public static RuntimeBuilder AddSqlServerRuntime(
            this RuntimeBuilder builder,
            string connectionString, ConnectionScope scope = ConnectionScope.ByRequest,
            IConfiguration databaseConfig = null)
        {
            var configureDatabase = databaseConfig != null ? databaseConfig.FastBind : (Action <SqlServerOptions>)null;

            return(AddSqlServerRuntime(builder, connectionString, scope, configureDatabase));
        }
        public IAuthority Build()
        {
            var builder = new RuntimeBuilder(_loggerFactory);

            foreach (var rule in _rules)
            {
                rule.Apply(builder);
            }

            return(new SupremeAuthority(builder.Build(), _loggerFactory));
        }
Esempio n. 7
0
File: Add.cs Progetto: qiqi545/HQ
        public static RuntimeBuilder AddSqlRuntimeStores <TDatabase>
        (
            this RuntimeBuilder builder,
            string connectionString,
            ConnectionScope scope,
            Action <IDbCommand, Type, IServiceProvider> onCommand = null,
            Action <IDbConnection, IServiceProvider> onConnection = null
        )
            where TDatabase : class, IConnectionFactory, new()
        {
            if (scope == ConnectionScope.ByRequest)
            {
                builder.Services.AddHttpContextAccessor();
            }

            builder.Services.AddDatabaseConnection <RuntimeBuilder, TDatabase>(connectionString, scope, onConnection, onCommand);
            builder.Services.AddScoped <IObjectGetRepository <long>, SqlObjectGetRepository>();

            return(builder);
        }
Esempio n. 8
0
        public Sample()
        {
            InitializeComponent();

            _RuntimeBuilder = new RuntimeBuilder(
                Path.Combine(Application.StartupPath, "working"),           // working directory
                Path.Combine(Application.StartupPath, "working", "obj"),    // intermediate directory
                Path.Combine(Application.StartupPath, "Content"),           // output directory
                TargetPlatform.Windows,                                     // target platform
                GraphicsProfile.Reach,                                      // graphics profile
                true)                                                       // compress the content
            {
                Logger = new StringBuilderLogger()                          // logger
            };

            // When the StringBuilderLogger logs a message, we write it to a RichTextBox and scroll to the end of it.
            ((StringBuilderLogger)_RuntimeBuilder.Logger).OnMessageLogged += (log) =>
            {
                richTextBoxLog.Text           = log;
                richTextBoxLog.SelectionStart = richTextBoxLog.Text.Length;
                richTextBoxLog.ScrollToCaret();
            };
        }
Esempio n. 9
0
File: Add.cs Progetto: qiqi545/HQ
 public static RuntimeBuilder AddDocumentDbRuntimeStores(this RuntimeBuilder builder, string connectionString,
                                                         ConnectionScope scope = ConnectionScope.ByRequest)
 {
     return(AddDocumentDbRuntimeStores(builder, connectionString, scope,
                                       o => { DefaultDbOptions(connectionString, o); }));
 }