Example #1
0
        public void RoundTripComparisonTest()
        {
            var sw = new Stopwatch();
            Debug.WriteLine("Starting Test:");
            sw.Start();
            var importFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "FolderDTC");
            var importDts = new FolderDataTableSet(importFolder)
            {
                Id = "Import DataSet",
                TableList = TableList
            };

            var connStr = DataSerTestHelper.DataDiffConnectionString;

            Debug.WriteLine(string.Format("Starting import...  elpased: {0}", sw.Elapsed));
            var importResult = importDts.ImportTables(connStr);
            Debug.WriteLine(string.Format("Import complete: {0}", sw.Elapsed));
            DataSerTestHelper.AssertResult(importResult);
            Debug.WriteLine(string.Format("Starting export...  elpased: {0}", sw.Elapsed));
            var exportFolder = TestHelper.ResetFolder("Export");
            var exportDts = new DatabaseDataTableSet(connStr)
            {
                Id = "Export DataSet",
                TableList = TableList
            };

            var exportResult = exportDts.ExportTables(exportFolder);
            Debug.WriteLine(string.Format("export complete: {0}", sw.Elapsed));
            DataSerTestHelper.AssertResult(exportResult);

            Debug.WriteLine("Asserting exported files are the same as the originals...");
            AssertFolderContentsAreEqual(importFolder, exportFolder);
            Debug.WriteLine(string.Format("Total time: {0}", sw.Elapsed));

        }
 public void PreserveSpaceTest()
 {
     var dts = new FolderDataTableSet("FolderDTC")
     {
         Id = "Preserve space test.",
         TableList = new List<string>() {"Production.Culture"}
     };
     var loadResult = dts.Load();
     Assert.IsTrue(loadResult.Success);
     var dt = dts["Production.Culture"];
     var row = dt.Rows[0];
     Assert.AreEqual("      ",row["CultureId"]);
 }
 private void cmdExecuteMigration_Click(object sender, System.EventArgs e)
 {
     UiWrap(() =>
     {
         var source = GetSource().AbortOnFail();
         string workingFolder = ExportToWorkingFolder(source).AbortOnFail();
         string msg = "Importing tables...";
         ShowStatus(msg);
         var importSource = new FolderDataTableSet(workingFolder)
         {
             Id = "Source Import Folder",
             TableList = source.TableList
         };
         var importResult = importSource.ImportTables(txtTargetDb.Text);
         if (!importResult.Success)
         {
             ShowStatus(importResult, "Importing tables");
             return;
         }
         var successMsg = string.Format("Migration to database target '{0}' complete. The following tables were imported:\r\n{1}",
            txtTargetDb.Text, string.Join("\r\n", importResult.Value.Select(t => "\t" + t)));
         ShowStatus(successMsg);
         File.WriteAllText(Path.Combine(workingFolder, "TableMigrationReport.txt"), successMsg);
         MessageBox.Show(string.Format("Migration complete. {0} tables migrated.", importResult.Value.Count())); ;
     }, "Migrating tables");
 }
Example #4
0
        public static ReturnValue<DataTableSet> FromConfigFile(string fileName, bool loadOnOpen = true)
        {
            try
            {
                var config = XDocument.Load(fileName);
                string type = config.Root.Element("Type").Value;
                DataTableSet dtSet;
                if (type == "Database")
                {
                    string connStr = config.Root.Element("ConnectionString").Value;
                    dtSet = new DatabaseDataTableSet(connStr);
                    dtSet.Id = connStr;
                }
                else if (type == "Folder")
                {
                    string folderPath = config.Root.Element("FolderPath").Value;
                    dtSet = new FolderDataTableSet(folderPath);
                    dtSet.Id = folderPath;
                }
                else
                {

                    return ReturnValue<DataTableSet>.FailResult(string.Format("Invalid Type in configration file: {0}", type));
                }
                var dataTablesElement = config.Root.Element("Tables");
                if (dataTablesElement != null)
                {
                    dtSet.TableList = dataTablesElement.Elements("Table").Select(e => e.Value).ToList();

                }

                if (loadOnOpen)
                {
                    var loadResult = dtSet.Load();
                    if (!loadResult.Success)
                        return ReturnValue<DataTableSet>.Cascade(loadResult, "Failed to load tables.");
                }

                return ReturnValue<DataTableSet>.SuccessResult(dtSet);

            }
            catch (Exception ex)
            {
                return ReturnValue<DataTableSet>.FailResult(string.Format("Error trying to create DataTableSet from file: {0}", fileName), ex);
            }
        }