public void Update_FROM_2015_01_05() { var filePath = Path.Combine(TestTempPath, "TestUpdate.cruise"); try { using (var setup = new SQLiteDatastore(filePath)) { setup.Execute(CruiseDAL.Tests.SQL.CRUISECREATE_2015_01_05); } using (var datastore = new CruiseDatastore(filePath)) { var updater = new Updater_V2(); updater.Invoking(x => x.Update(datastore)) .Should().NotThrow(); var semVerActual = new Version(datastore.DatabaseVersion); var semVerExpected = new Version("2.7.0"); semVerActual.Major.Should().Be(semVerExpected.Major); semVerActual.Minor.Should().Be(semVerExpected.Minor); ValidateUpdate(datastore); } } finally { if (File.Exists(filePath)) { File.Delete(filePath); } } }
public void update_from_2_5_to_2_7() { var fileName = "v2_5_0.cruise";; var path = InitializeTestFile(fileName); Output.WriteLine(path); using (var db = new CruiseDatastore(path)) { var updater = new Updater_V2(); updater.Update(db); db.CurrentTransaction.Should().BeNull(); // insert multiple trees with the same guid to make sure that the tree guid uniqe constraint is removed //for (var i = 0; i < 2; i++) //{ // db.Insert(new V2.Models.Tree() // { // Tree_GUID = "something", // CuttingUnit_CN = 1, // Stratum_CN = 1, // SampleGroup_CN = 1, // TreeDefaultValue_CN = 1, // }); //} db.DatabaseVersion.Should().StartWith("2.7."); } }
public void Update_FROM_05_30_2013() { var filePath = Path.Combine(TestTempPath, "TestUpdate.cruise"); try { using (var setup = new SQLiteDatastore(filePath)) { setup.Execute(CruiseDAL.Tests.SQL.CRUISECREATE_05_30_2013); } using (var database = new CruiseDatastore(filePath)) { var dataStore = new CruiseDatastore(filePath); var updater = new Updater_V2(); updater.Invoking(x => x.Update(dataStore)).Should().Throw <IncompatibleSchemaException>(); database.CurrentTransaction.Should().BeNull(); } } finally { if (File.Exists(filePath)) { File.Delete(filePath); } } }
public void FixVersion_2_5_0(string fileName) { var targetPath = InitializeTestFile(fileName); using (var db = new CruiseDatastore(targetPath)) { //var trees = db.From<TreeDO>().Query().ToArray(); db.From <TreeDOold>().Invoking(x => x.Query().ToArray()).Should().NotThrow(); var errorTrees = db.QueryGeneric("SELECT * FROM Tree WHERE typeof(Tree_GUID) = 'text' AND Tree_GUID NOT LIKE '________-____-____-____-____________';") .ToArray(); errorTrees.Should().NotBeEmpty(); var updater = new Updater_V2(); updater.Update(db); //db.DatabaseVersion.Should().Be("2.5.1.1"); var errorTreesAgain = db.QueryGeneric("SELECT * FROM Tree WHERE typeof(Tree_GUID) = 'text' AND Tree_GUID NOT LIKE '________-____-____-____-____________';") .ToArray(); errorTreesAgain.Should().BeEmpty(); db.From <TreeDOold>().Invoking(x => x.Query()).Should().NotThrow(); } }
} // end onEquations private void onFile(object sender, EventArgs e) { // clear filename in case user wants to change files fileName = ""; // Create an instance of the open file dialog OpenFileDialog browseDialog = new OpenFileDialog(); // Set filter options and filter index browseDialog.Filter = "Cruise Files - V2 |*.cruise|Cruise Files - V3|*.crz3|All Files|*.*"; browseDialog.FilterIndex = 1; browseDialog.Multiselect = false; // February 2017 -- nowhave the option to edit volume equations and selected reports // on template files. Need a flag indicating it is a template file so some // tasks are skipped that would apply to just cruise files. templateFlag = 0; // capture filename selected while (fileName == "" || fileName == null) { DialogResult dResult = browseDialog.ShowDialog(); if (dResult == DialogResult.Cancel) { return; } if (dResult == DialogResult.OK) { fileName = browseDialog.FileName; if (fileName.EndsWith(".cut") || fileName.EndsWith(".CUT")) { // disable all buttons except equations and reports menuButton2.BackgroundImage = Properties.Resources.button_image; menuButton3.BackgroundImage = Properties.Resources.button_image; processBtn.BackgroundImage = Properties.Resources.disabled_button; menuButton5.BackgroundImage = Properties.Resources.disabled_button; menuButton2.Enabled = true; menuButton3.Enabled = true; processBtn.Enabled = false; menuButton5.Enabled = false; // Have user enter a different file to preserve the regional tempalte file DialogResult dr = MessageBox.Show("Do you want to use a different filename for any changes made?", "QUESTION", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dr == DialogResult.Yes) { // show dialog to captue new filanem EnterNewFilename enf = new EnterNewFilename(); enf.ShowDialog(); // copy original file to new filename string pathName = Path.GetDirectoryName(fileName); pathName += "\\"; newTemplateFile = enf.templateFilename; newTemplateFile = newTemplateFile.Insert(0, pathName); File.Copy(fileName, newTemplateFile, true); fileName = newTemplateFile; DAL = new DAL(newTemplateFile); templateFlag = 1; } else if (dr == DialogResult.No) { //fileName = fileName; DAL = new DAL(fileName); if (fileName.EndsWith(".CUT") || fileName.EndsWith(".cut")) { newTemplateFile = fileName; templateFlag = 1; } else { templateFlag = 0; } } // endif } else if (!fileName.EndsWith(".cruise") && !fileName.EndsWith(".CRUISE")) { if (!fileName.EndsWith(".crz3") && !fileName.EndsWith(".CRZ3")) { // is it a cruise file? MessageBox.Show("File selected is not a cruise file.", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else { DAL_V3 = new CruiseDatastore_V3(fileName); string V2FileName = fileName.Replace(".crz3", "").Replace(".CRZ3", ""); //V2FileName = V2FileName + "WBTest.cruise"; V2FileName = V2FileName + ".process"; try { var cruiseIDs = DAL_V3.QueryScalar <string>("SELECT CruiseID FROM Cruise;").ToArray(); if (cruiseIDs.Length > 1) { MessageBox.Show("File contains multiple cruises. \r\nOpening files with multiple cruises is not supported yet", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } var cruiseID = cruiseIDs.First(); string cruiseV2Path = V2FileName; CruiseDatastoreBuilder_V2 V2Builder = new CruiseDatastoreBuilder_V2(); Updater_V2 v2Updater = new Updater_V2(); CruiseDatastore myV2DAL = new DAL(cruiseV2Path, true); //CruiseDatastore v2DB = new CruiseDatastore(cruiseV2Path, true, V2Builder, v2Updater); DownMigrator myMyigrator = new DownMigrator(); string error_message = ""; if (myMyigrator.EnsureCanMigrate(cruiseID, DAL_V3, out error_message)) { //CONVERT LOGIC NEEDED HERE. myMyigrator.MigrateFromV3ToV2(cruiseID, DAL_V3, myV2DAL); fileName = V2FileName; }//end if else { MessageBox.Show("This version 3 file has issues. \r\nError: " + error_message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); return; }//end else } catch (Exception ex) { MessageBox.Show("This version 3 file has issues. \r\n", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } } // endif } } ; // end while if (templateFlag == 0) { // check for fatal errors before doing anything else -- October 20145 //fileName = fileName; DAL = new DAL(fileName); //open connection forces the connection to remain open not to close and open. Might be good to re-work the process button click? DAL.OpenConnection(); string[] errors; // bool ithResult = bslyr.DAL.HasCruiseErrors(out errors); bool ithResult = false; if (ithResult) { MessageBox.Show("This file has errors which affect processing.\nCannot continue until these are fixed in CruiseManager.", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); menuButton2.BackgroundImage = Properties.Resources.disabled_button; menuButton3.BackgroundImage = Properties.Resources.disabled_button; processBtn.BackgroundImage = Properties.Resources.disabled_button; menuButton5.BackgroundImage = Properties.Resources.disabled_button; menuButton2.Enabled = false; menuButton3.Enabled = false; processBtn.Enabled = false; menuButton5.Enabled = false; return; } // end check for fatal errors // if filename is not blank, enable remaining menu buttons if (fileName.Contains(".cruise") || fileName.Contains(".CRUISE") || fileName.Contains(".process") || fileName.Contains(".PROCESS")) { menuButton2.BackgroundImage = Properties.Resources.button_image; menuButton3.BackgroundImage = Properties.Resources.button_image; processBtn.BackgroundImage = Properties.Resources.button_image; menuButton5.BackgroundImage = Properties.Resources.button_image; menuButton2.Enabled = true; menuButton3.Enabled = true; processBtn.Enabled = true; menuButton5.Enabled = true; // need region number in order to hide volume button as well as region 9 button List <SaleDO> saleList = new List <SaleDO>(); saleList = DAL.From <SaleDO>().Read().ToList(); currentRegion = saleList[0].Region; } // endif } // endif tempalteFlag // add file name to title line at top if (fileName.Length > 35) { string tempName = "..." + fileName.Substring(fileName.Length - 35, 35); Text = tempName; } // endif fileName } // end onFile