public static QueryConstantsBag CreateTestManagementQueries(string invariantName)
        {
            //This is probably the same for all the databases.
            const string DeleteAllDataTemplate =
                @"DELETE OrleansStatisticsTable;
                    DELETE OrleansClientMetricsTable;
                    DELETE OrleansSiloMetricsTable;
                    DELETE OrleansRemindersTable;
                    DELETE OrleansMembershipTable;
                    DELETE OrleansMembershipVersionTable;";

            var queryBag = new QueryConstantsBag();

            queryBag.AddOrModifyQueryConstant(AdoNetInvariants.InvariantNameSqlServer, RelationalTestingConstants.DeleteAllDataKey, DeleteAllDataTemplate);
            switch (invariantName)
            {
            case (AdoNetInvariants.InvariantNameSqlServer):
            {
                return(CreateSqlServerQueries());
            }

            default:
            {
                break;
            }
            }

            return(queryBag);
        }
示例#2
0
        /// <summary>
        /// Initializes Orleans queries from the database. Orleans uses only these queries and the variables therein, nothing more.
        /// </summary>
        /// <param name="storage">The storage to use.</param>
        /// <returns>Orleans queries have been loaded to silo or client memory.</returns>
        /// <remarks>This is public only to be usable to the statistics providers. Not intended for public use otherwise.</remarks>
        public static async Task <QueryConstantsBag> InitializeOrleansQueriesAsync(this IRelationalStorage storage)
        {
            var queryConstants = new QueryConstantsBag();
            var query          = queryConstants.GetConstant(storage.InvariantName, QueryKeys.OrleansQueriesKey);
            var orleansQueries = await storage.ReadAsync(query, _ => { }, (selector, _) =>
            {
                return(Tuple.Create(selector.GetValue <string>("QueryKey"), selector.GetValue <string>("QueryText")));
            }).ConfigureAwait(continueOnCapturedContext: false);

            //The queries need to be added to be used later with a given key.
            foreach (var orleansQuery in orleansQueries)
            {
                queryConstants.AddOrModifyQueryConstant(storage.InvariantName, orleansQuery.Item1, orleansQuery.Item2);
            }

            //Check that all the required keys are loaded and throw an exception giving the keys expected but not loaded.
            var loadedQueriesKeys = queryConstants.GetAllConstants(storage.InvariantName).Keys;
            var missingQueryKeys  = QueryKeys.Keys.Except(loadedQueriesKeys);

            if (missingQueryKeys.Any())
            {
                throw new ArgumentException(string.Format("Not all required queries found when loading from the database. Missing are: {0}", string.Join(",", missingQueryKeys)));
            }

            return(await Task.FromResult(queryConstants));
        }
        /// <summary>
        /// Initializes Orleans queries from the database. Orleans uses only these queries and the variables therein, nothing more.
        /// </summary>
        /// <param name="storage">The storage to use.</param>
        /// <returns>Orleans queries have been loaded to silo or client memory.</returns>
        /// <remarks>This is public only to be usable to the statistics providers. Not intended for public use otherwise.</remarks>
        public static async Task<QueryConstantsBag> InitializeOrleansQueriesAsync(this IRelationalStorage storage)
        {
            var queryConstants = new QueryConstantsBag();            
            var query = queryConstants.GetConstant(storage.InvariantName, QueryKeys.OrleansQueriesKey);
            var orleansQueries = await storage.ReadAsync(query, _ => { }, (selector, _) =>
            {
                return Tuple.Create(selector.GetValue<string>("QueryKey"), selector.GetValue<string>("QueryText"));
            }).ConfigureAwait(continueOnCapturedContext: false);

            //The queries need to be added to be used later with a given key.
            foreach(var orleansQuery in orleansQueries)
            {
                queryConstants.AddOrModifyQueryConstant(storage.InvariantName, orleansQuery.Item1, orleansQuery.Item2);
            }

            //Check that all the required keys are loaded and throw an exception giving the keys expected but not loaded.
            var loadedQueriesKeys = queryConstants.GetAllConstants(storage.InvariantName).Keys;
            var missingQueryKeys = QueryKeys.Keys.Except(loadedQueriesKeys);
            if(missingQueryKeys.Any())
            {
                throw new ArgumentException(string.Format("Not all required queries found when loading from the database. Missing are: {0}", string.Join(",", missingQueryKeys)));
            }

            return await Task.FromResult(queryConstants);
        }
示例#4
0
        /// <summary>
        /// Seeks for database provider factory classes from GAC or as indicated by
        /// the configuration file, see at <see href="https://msdn.microsoft.com/en-us/library/dd0w4a2z%28v=vs.110%29.aspx">Obtaining a DbProviderFactory</see>.
        /// </summary>
        /// <returns>Database constants with values from <see cref="DbProviderFactories"/>.</returns>
        /// <remarks>Every call may potentially update data as it is refreshed from <see cref="DbProviderFactories"/>.</remarks>
        public static QueryConstantsBag GetAdoNetFactoryData()
        {
            var queryBag = new QueryConstantsBag();

            //This method seeks for factory classes either from the GAC or as indicated in a config file.
            var factoryData = DbProviderFactories.GetFactoryClasses();

            //The provided default information will be loaded from here to the factory constants
            //which are further augmented with predefined query templates.
            foreach (DataRow row in factoryData.Rows)
            {
                var invariantName = row[AdoNetInvariants.InvariantNameKey].ToString();
                queryBag.AddOrModifyQueryConstant(invariantName, AdoNetInvariants.InvariantNameKey, invariantName);
                queryBag.AddOrModifyQueryConstant(invariantName, AdoNetInvariants.NameKey, row[AdoNetInvariants.NameKey].ToString());
                queryBag.AddOrModifyQueryConstant(invariantName, AdoNetInvariants.DescriptionKey, row[AdoNetInvariants.DescriptionKey].ToString());
                queryBag.AddOrModifyQueryConstant(invariantName, AdoNetInvariants.AssemblyQualifiedNameKey, row[AdoNetInvariants.AssemblyQualifiedNameKey].ToString());
            }

            return(queryBag);
        }
        /// <summary>
        /// Seeks for database provider factory classes from GAC or as indicated by
        /// the configuration file, see at <see href="https://msdn.microsoft.com/en-us/library/dd0w4a2z%28v=vs.110%29.aspx">Obtaining a DbProviderFactory</see>.
        /// </summary>
        /// <returns>Database constants with values from <see cref="DbProviderFactories"/>.</returns>
        /// <remarks>Every call may potentially update data as it is refreshed from <see cref="DbProviderFactories"/>.</remarks>
        public static QueryConstantsBag GetAdoNetFactoryData()
        {
            var queryBag = new QueryConstantsBag();

            //This method seeks for factory classes either from the GAC or as indicated in a config file.            
            var factoryData = DbProviderFactories.GetFactoryClasses();

            //The provided default information will be loaded from here to the factory constants
            //which are further augmented with predefined query templates.
            foreach(DataRow row in factoryData.Rows)
            {
                var invariantName = row[AdoNetInvariants.InvariantNameKey].ToString();
                queryBag.AddOrModifyQueryConstant(invariantName, AdoNetInvariants.InvariantNameKey, invariantName);
                queryBag.AddOrModifyQueryConstant(invariantName, AdoNetInvariants.NameKey, row[AdoNetInvariants.NameKey].ToString());
                queryBag.AddOrModifyQueryConstant(invariantName, AdoNetInvariants.DescriptionKey, row[AdoNetInvariants.DescriptionKey].ToString());
                queryBag.AddOrModifyQueryConstant(invariantName, AdoNetInvariants.AssemblyQualifiedNameKey, row[AdoNetInvariants.AssemblyQualifiedNameKey].ToString());
            }

            return queryBag;
        }
        private static QueryConstantsBag CreateSqlServerQueries()
        {
            var queryBag = new QueryConstantsBag();

            queryBag.AddOrModifyQueryConstant(AdoNetInvariants.InvariantNameSqlServer, RelationalTestingConstants.DefaultConnectionStringKey, @"Data Source=(localdb)\MSSQLLocalDB;Database=Master;Integrated Security=True;Asynchronous Processing=True;Max Pool Size=200; MultipleActiveResultSets=True");
            queryBag.AddOrModifyQueryConstant(AdoNetInvariants.InvariantNameSqlServer, RelationalTestingConstants.ExistsDatabaseKey, "SELECT CAST(COUNT(1) AS BIT) FROM sys.databases WHERE name = @databaseName");
            queryBag.AddOrModifyQueryConstant(AdoNetInvariants.InvariantNameSqlServer, RelationalTestingConstants.CreateDatabaseKey,
                                              @"USE [Master];
                DECLARE @fileName AS NVARCHAR(255) = CONVERT(NVARCHAR(255), SERVERPROPERTY('instancedefaultdatapath')) + N'{0}';
                EXEC('CREATE DATABASE [{0}] ON PRIMARY 
                (
                    NAME = [{0}], 
                    FILENAME =''' + @fileName + ''', 
                    SIZE = 5MB, 
                    MAXSIZE = 100MB, 
                    FILEGROWTH = 5MB
                )')");
            queryBag.AddOrModifyQueryConstant(AdoNetInvariants.InvariantNameSqlServer, RelationalTestingConstants.DropDatabaseKey, @"USE [Master]; ALTER DATABASE [{0}] SET SINGLE_USER WITH ROLLBACK IMMEDIATE; DROP DATABASE [{0}];");

            return(queryBag);
        }