public void Build(Solution solution, bool onlyResources, bool checkTabularSectionKey = false, bool filtersOnly = false) { String configurationFile = System.IO.Path.Combine(solution.SolutionFolder, @"configuration\configuration.xml"); Factory factory = new Factory(); Dictionary<String, Parameter> globalParameters = factory.GetGlobalParameters(configurationFile); List<Entity> entities = new List<Entity>(); entities.AddRange(factory.GetEntities(configurationFile, checkTabularSectionKey)); entities.AddRange(factory.GetResources(solution.DeviceResourceFolder)); entities.AddRange(factory.GetAdmin()); Dictionary<String, List<Constant>> constants = factory.GetConstants(configurationFile); ConfigVersion configVersion = factory.GetVersion(configurationFile); Config config = new Config(configVersion, solution.DatabaseName, entities, globalParameters, constants); if (onlyResources) BuildResources(config, solution); else { if (filtersOnly) BuildFilters(config, solution); else { BuildAll(config, solution); InsertConstants(solution); } } }
private void checkRange(ref Solution curr) { for (int i = 0; i < argCnt; i++) { curr.point[i] = (curr.point[i] > rangeMax[i] ? rangeMax[i] : curr.point[i]); curr.point[i] = (curr.point[i] < rangeMin[i] ? rangeMin[i] : curr.point[i]); } }
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"); }
private Solution chooseNext(Solution curr) { Solution tmp = new Solution(argCnt); for (int i = 0; i < argCnt; i++) { tmp.point[i] = curr.point[i] + getRandSign() * (rangeMax[i] - rangeMin[i]) * T / TInit * rand.NextDouble(); // tmp.point[i] = curr.point[i] + getRandSign() * (rangeMax[i] - rangeMin[i]) * rand.NextDouble(); } checkRange(ref tmp); tmp.profit = getProfit(tmp.point); return tmp; }
public static Solution CreateFromContext(string scope) { Solution info = new Solution(); info.Name = scope; return info; }
public CatalogFileFiltered(Solution solution, Guid userId) { this.solution = solution; this.userId = userId; }
private Solution getRandSolution() { Solution tmp = new Solution(argCnt); for (int i = 0; i < argCnt; i++) { tmp.point[i] = rand.NextDouble() * (rangeMax[i] - rangeMin[i]) + rangeMin[i]; } tmp.profit = getProfit(tmp.point); return tmp; }
private void CheckMetaVersion(Config config, Solution solution) { Common.Logon.CheckSupportedMetaVersion(solution.Name, config.ConfigVersion.Version); }
private void BuildResources(Config config, Solution solution) { if (solution.ResourcesExists) { //check if settings.xml exists if (!System.IO.File.Exists(solution.SettingsFile)) throw new Exception("File settings.xml not found in resource folder"); CheckMetaVersion(config, solution); PopulateResources(solution.ConnectionString, solution.DeviceResourceFolder); } }
private void InsertConstants(Solution solution) { XmlDocument doc = new XmlDocument(); doc.Load(solution.ConfigurationFile); SqlConnection conn = new SqlConnection(solution.ConnectionString); conn.Open(); using (conn) { SqlTransaction tran = conn.BeginTransaction(); try { XmlNodeList entityNodes = doc.DocumentElement.SelectNodes("//Configuration/Constants/Entity"); foreach (XmlNode entityNode in entityNodes) { String entityName = entityNode.Attributes["Name"].Value; String[] arr = entityName.Split('.'); //entityName = String.Format("[{0}].[{1}]", arr[0], arr[1]); SqlCommand cmd = new SqlCommand(); cmd = new SqlCommand(String.Format("[{0}].[{1}_adm_insert]", arr[0], arr[1]), conn, tran); cmd.CommandType = System.Data.CommandType.StoredProcedure; SqlCommandBuilder.DeriveParameters(cmd); System.Xml.XmlNodeList rows = entityNode.SelectNodes("Row"); foreach (System.Xml.XmlNode row in rows) { FillParameters(cmd, row); cmd.ExecuteNonQuery(); } } tran.Commit(); } catch (Exception) { tran.Rollback(); throw; } } }
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"); }