示例#1
0
        private void BuildFilters(Config config, Solution solution)
        {
            //remove existing filters
            try
            {
                using (SqlConnection conn = new SqlConnection(solution.ConnectionString))
                {
                    conn.Open();
                    SqlCommand cmd = new SqlCommand("[admin].RemoveFilters", conn);
                    cmd.CommandType = System.Data.CommandType.StoredProcedure;
                    SqlCommandBuilder.DeriveParameters(cmd);
                    cmd.ExecuteNonQuery();
                }
            }
            catch
            {
            }

            //create new ones
            String solutionFolder = solution.SolutionFolder;

            if (deleteTempFiles)
            {
                solutionFolder = System.IO.Path.Combine(System.IO.Path.GetTempPath(), Guid.NewGuid().ToString());
                Directory.CreateDirectory(solutionFolder);
                Directory.CreateDirectory(System.IO.Path.Combine(solutionFolder, @"Database"));
                Directory.CreateDirectory(System.IO.Path.Combine(solutionFolder, @"configuration"));
                Directory.CreateDirectory(System.IO.Path.Combine(solutionFolder, @"sqlite"));
            }

            solution.Log("Start updating solution");

            Dictionary<String, String> tempFiles = GetTempFiles(solutionFolder);

            DatabaseFactory.DatabaseFactory dbf = new DatabaseFactory.DatabaseFactory(solution.ConnectionString);

            //filters
            String filtersScript;
            if (solution.IsAsured)
                filtersScript = new FiltersAzure(config).TransformText();
            else
                filtersScript = new Filters(config).TransformText();
            System.IO.File.WriteAllText(tempFiles["filters"], filtersScript);
            dbf.RunScript(filtersScript);

            solution.Log("Filters ok");

            //sync patch
            String syncPatchScript = new SyncPatch2(config).TransformText();
            System.IO.File.WriteAllText(tempFiles["syncpatch"], syncPatchScript);
            dbf.RunScript(syncPatchScript);

            solution.Log("Sync patch ok");

            solution.Log("Solution has been successfully updated");
        }
示例#2
0
        private void BuildAll(Config config, Solution solution)
        {
            String solutionFolder = solution.SolutionFolder;
            CreateSolutionFolders(solutionFolder);

            if (deleteTempFiles)
            {
                solutionFolder = System.IO.Path.Combine(System.IO.Path.GetTempPath(), Guid.NewGuid().ToString());
                Directory.CreateDirectory(solutionFolder);
                Directory.CreateDirectory(System.IO.Path.Combine(solutionFolder, @"Database"));
                Directory.CreateDirectory(System.IO.Path.Combine(solutionFolder, @"configuration"));
                Directory.CreateDirectory(System.IO.Path.Combine(solutionFolder, @"sqlite"));
            }

            solution.Log("Start building solution");

            Dictionary<String, String> tempFiles = GetTempFiles(solutionFolder);

            DatabaseFactory.DatabaseFactory dbf = null;

            //init database
            dbf = new DatabaseFactory.DatabaseFactory(solution.DatabaseServer);

            String dropDatabaseScript;
            if (solution.IsAsured)
                dropDatabaseScript = new DropDatabaseAzure(config).TransformText();
            else
                dropDatabaseScript = new DropDatabase(config).TransformText();
            System.IO.File.WriteAllText(tempFiles["dropdatabase"], dropDatabaseScript);
            try
            {
                dbf.RunScript(dropDatabaseScript);
            }
            catch (Exception)
            {
            }

            String createDatabaseScript;
            if(solution.IsAsured)
                createDatabaseScript = new CreateDatabaseAzure(config).TransformText();
            else
                createDatabaseScript = new CreateDatabase(config).TransformText();

            System.IO.File.WriteAllText(tempFiles["createdatabase"], createDatabaseScript);
            dbf.RunScript(createDatabaseScript);

            solution.Log("DB scripts ok");

            //create database
            dbf = new DatabaseFactory.DatabaseFactory(solution.ConnectionString);
            String dbScript = new Database(config).TransformText();
            System.IO.File.WriteAllText(tempFiles["database"], dbScript);
            dbf.RunScript(dbScript);

            solution.Log("Database ok");

            System.Data.SqlClient.SqlConnection.ClearAllPools();

            //sort tables
            SyncOrder.Initialize(solution.ConnectionString);
            SyncOrder.Sort(config.Entities);
            
            //provisioning
            String syncConfig = tempFiles["syncconfig"];
            System.IO.File.WriteAllText(syncConfig, new SyncConfig(config, solution.ConnectionString).TransformText());
            dbf.Provision(new String[] { "/mode:provision", String.Format("/scopeconfig:{0}", syncConfig) });

            solution.Log("Provision ok");

            //filters
            String filtersScript;
            if (solution.IsAsured)
                filtersScript = new FiltersAzure(config).TransformText();
            else
                filtersScript = new Filters(config).TransformText();
            System.IO.File.WriteAllText(tempFiles["filters"], filtersScript);
            dbf.RunScript(filtersScript);

            solution.Log("Filters ok");

            //sync patch
            String syncPatchScript = new SyncPatch2(config).TransformText();
            System.IO.File.WriteAllText(tempFiles["syncpatch"], syncPatchScript);
            dbf.RunScript(syncPatchScript);

            solution.Log("Sync patch ok");

            //admin
            dbScript = new DatabaseAdmin(config).TransformText();
            System.IO.File.WriteAllText(tempFiles["admin"], dbScript);
            dbf.RunScript(dbScript);

            solution.Log("Admin ok");

            //clustered primary keys patch
            config.BuildClusteredPrimaryKeys(solution.ConnectionString);
            String keysPatchScript = new KeysPatch(config).TransformText();
            System.IO.File.WriteAllText(tempFiles["keyspatch"], keysPatchScript);
            dbf.RunScript(keysPatchScript);

            solution.Log("Clustered keys patch ok");

            if (solution.IsAsured)
            {
                //clustered primary keys patch
                config.BuildNonClusteredPrimaryKeys(solution.ConnectionString);
                String azureKeysPatchScript = new AzureKeysPatch(config).TransformText();
                System.IO.File.WriteAllText(tempFiles["azurekeyspatch"], azureKeysPatchScript);
                dbf.RunScript(azureKeysPatchScript);

                solution.Log("Non clustered keys patch ok");
                solution.Log("Default NEWID values on tabular sections ok");
            }
            else
            {
                String nonAzureKeysPatchScript = new NonAzureKeysPatch(config).TransformText();
                System.IO.File.WriteAllText(tempFiles["azurekeyspatch"], nonAzureKeysPatchScript);
                dbf.RunScript(nonAzureKeysPatchScript);
                solution.Log("Default NEWSEQUENTIALID values on tabular sections ok");
            }
    
            //initial load
            String dataLoadScript = new DataLoad(config).TransformText();
            System.IO.File.WriteAllText(tempFiles["dataload"], dataLoadScript);
            dbf.RunScript(dataLoadScript);
            
            solution.Log("initial data load ok");

            //sqlite
            String sqlieScript = new SQLiteDatabase(config).TransformText();
            System.IO.File.WriteAllText(tempFiles["sqlite"], sqlieScript);
            if(!System.IO.Directory.Exists(System.IO.Path.Combine(solution.SolutionFolder,"sqlite")))
                System.IO.Directory.CreateDirectory(System.IO.Path.Combine(solution.SolutionFolder,"sqlite"));
            String sqlitedb = System.IO.Path.Combine(solution.SolutionFolder, @"sqlite\sqlite.db");
            if (System.IO.File.Exists(sqlitedb))
                System.IO.File.Delete(sqlitedb);

            //SQLiteDatabaseFactory dbflite = new SQLiteDatabaseFactory(sqlitedb);
            //dbflite.CreateDatabase();
            //dbflite.RunScript(sqlieScript);
            //dbflite.InsertMetadata(solution.ConfigurationFile);

            solution.Log("sqlite ok");

            System.IO.File.WriteAllText(System.IO.Path.Combine(solution.SolutionFolder, @"Code\Server.cs"), new Server(config).TransformText());

            System.IO.File.WriteAllText(System.IO.Path.Combine(solution.SolutionFolder, @"Code\Client.cs"), new Client(config).TransformText());

            System.IO.File.WriteAllText(System.IO.Path.Combine(solution.SolutionFolder, @"Code\ClientMetadata.cs"), new ClientMetadata(config).TransformText());

            System.IO.File.WriteAllText(System.IO.Path.Combine(solution.SolutionFolder, @"Code\ClientConstants.cs"), new ClientConstants(config).TransformText());

            System.IO.File.WriteAllText(System.IO.Path.Combine(solution.SolutionFolder, @"Code\Fake.cs"), new Fake().TransformText());

            System.IO.File.WriteAllText(System.IO.Path.Combine(solution.SolutionFolder, @"Code\DbFake.cs"), new DbFake().TransformText());

            solution.Log("Code generation ok");

            BuildClientDll(solution.SolutionFolder);
            solution.Log("Client dll ok");

            BuildServerDll(solution.SolutionFolder);
            solution.Log("Server dll ok");

            BuildResources(config, solution);
            solution.Log("Resources ok");

            if (deleteTempFiles)
            {
                foreach (var entry in tempFiles)
                    System.IO.File.Delete(entry.Value);
            }

            solution.Log("Solution has been successfully built");
        }