Пример #1
0
        private void btnLoadPlan_Click(object sender, EventArgs e)
        {
            try
            {
                OpenFileDialog ofd = new OpenFileDialog();
                ofd.Filter = "Plans (*.plan)|*.plan";
                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    var fi   = new FileInfo(ofd.FileName);
                    var json = File.ReadAllText(fi.FullName);
                    _planManager = (ForwardEngineerANOCataloguePlanManager)
                                   JsonConvertExtensions.DeserializeObject(json, typeof(ForwardEngineerANOCataloguePlanManager), Activator.RepositoryLocator);

                    if (_planManager.StartDate != null)
                    {
                        tbStartDate.Text = _planManager.StartDate.Value.ToString();
                    }

                    cbDateBasedLoad.Checked   = _planManager.DateColumn != null;
                    ddDateColumn.SelectedItem = _planManager.DateColumn;
                }
            }
            catch (Exception exception)
            {
                ExceptionViewer.Show(exception);
            }
        }
Пример #2
0
        public void Test_SerializeObject_ShareAttribute()
        {
            Dictionary <RelationshipAttribute, Guid> d = new Dictionary <RelationshipAttribute, Guid>();

            var json = JsonConvertExtensions.SerializeObject(d, RepositoryLocator);
            var obj  = (Dictionary <RelationshipAttribute, Guid>)JsonConvertExtensions.DeserializeObject(json, typeof(Dictionary <RelationshipAttribute, Guid>), RepositoryLocator);

            Assert.AreEqual(0, obj.Count);

            //now add a key
            d.Add(new RelationshipAttribute(typeof(string), RelationshipType.SharedObject, "fff"), Guid.Empty);

            json = JsonConvertExtensions.SerializeObject(d, RepositoryLocator);
            obj  = (Dictionary <RelationshipAttribute, Guid>)JsonConvertExtensions.DeserializeObject(json, typeof(Dictionary <RelationshipAttribute, Guid>), RepositoryLocator);

            Assert.AreEqual(1, obj.Count);
        }
Пример #3
0
 /// <summary>
 /// Deserializes the json which must be the contents of a .sd file i.e. a ShareDefinitionList
 /// </summary>
 /// <param name="json"></param>
 /// <returns></returns>
 public List <ShareDefinition> GetShareDefinitionList(string json)
 {
     return((List <ShareDefinition>)JsonConvertExtensions.DeserializeObject(json, typeof(List <ShareDefinition>), RepositoryLocator));
 }
Пример #4
0
        public void CreateANOVersion_TestSkippingTables(bool tableInfoAlreadyExistsForSkippedTable, bool putPlanThroughSerialization)
        {
            var dbFrom = DiscoveredServerICanCreateRandomDatabasesAndTablesOn.ExpectDatabase(TestDatabaseNames.GetConsistentName("CreateANOVersion_TestSkippingTables_From"));
            var dbTo   = DiscoveredServerICanCreateRandomDatabasesAndTablesOn.ExpectDatabase(TestDatabaseNames.GetConsistentName("CreateANOVersion_TestSkippingTables_To"));

            dbFrom.Create(true);
            dbTo.Create(true);

            try
            {
                var tblFromHeads = dbFrom.CreateTable("Heads", new[]
                {
                    new DatabaseColumnRequest("SkullColor", "varchar(10)"),
                    new DatabaseColumnRequest("Vertebrae", "varchar(25)")
                });

                var cols = new[]
                {
                    new DatabaseColumnRequest("SpineColor", "varchar(10)"),
                    new DatabaseColumnRequest("Vertebrae", "varchar(25)")
                };

                var tblFromNeck = dbFrom.CreateTable("Necks", cols);

                //Necks table already exists in the destination so will be skipped for migration but still needs to be imported
                var tblToNeck = dbTo.CreateTable("Necks", cols);


                TableInfo    fromHeadsTableInfo;
                ColumnInfo[] fromHeadsColumnInfo;
                TableInfo    fromNeckTableInfo;
                ColumnInfo[] fromNeckColumnInfo;
                TableInfo    toNecksTableInfo  = null;
                ColumnInfo[] toNecksColumnInfo = null;

                TableInfoImporter i1 = new TableInfoImporter(CatalogueRepository, tblFromHeads);
                i1.DoImport(out fromHeadsTableInfo, out fromHeadsColumnInfo);

                TableInfoImporter i2 = new TableInfoImporter(CatalogueRepository, tblFromNeck);
                i2.DoImport(out fromNeckTableInfo, out fromNeckColumnInfo);

                //Table already exists but does the in Catalogue reference exist?
                if (tableInfoAlreadyExistsForSkippedTable)
                {
                    TableInfoImporter i3 = new TableInfoImporter(CatalogueRepository, tblToNeck);
                    i3.DoImport(out toNecksTableInfo, out toNecksColumnInfo);
                }

                //Create a JoinInfo so the query builder knows how to connect the tables
                new JoinInfo(CatalogueRepository,
                             fromHeadsColumnInfo.Single(c => c.GetRuntimeName().Equals("Vertebrae")),
                             fromNeckColumnInfo.Single(c => c.GetRuntimeName().Equals("Vertebrae")), ExtractionJoinType.Inner, null
                             );

                var                     cataEngineer = new ForwardEngineerCatalogue(fromHeadsTableInfo, fromHeadsColumnInfo, true);
                Catalogue               cata;
                CatalogueItem[]         cataItems;
                ExtractionInformation[] extractionInformations;
                cataEngineer.ExecuteForwardEngineering(out cata, out cataItems, out extractionInformations);

                var cataEngineer2 = new ForwardEngineerCatalogue(fromNeckTableInfo, fromNeckColumnInfo, true);
                cataEngineer2.ExecuteForwardEngineering(cata);

                //4 extraction informations in from Catalogue (2 from Heads and 2 from Necks)
                Assert.AreEqual(cata.GetAllExtractionInformation(ExtractionCategory.Any).Count(), 4);

                //setup ANOTable on head
                var anoTable = new ANOTable(CatalogueRepository, ANOStore_ExternalDatabaseServer, "ANOSkullColor", "C");
                anoTable.NumberOfCharactersToUseInAnonymousRepresentation = 10;
                anoTable.SaveToDatabase();
                anoTable.PushToANOServerAsNewTable("varchar(10)", new ThrowImmediatelyCheckNotifier());

                //////////////////The actual test!/////////////////
                var planManager = new ForwardEngineerANOCataloguePlanManager(RepositoryLocator, cata);

                //ano the table SkullColor
                var scPlan = planManager.GetPlanForColumnInfo(fromHeadsColumnInfo.Single(col => col.GetRuntimeName().Equals("SkullColor")));
                scPlan.ANOTable = anoTable;
                scPlan.Plan     = Plan.ANO;

                if (putPlanThroughSerialization)
                {
                    var asString = JsonConvertExtensions.SerializeObject(planManager, RepositoryLocator);

                    planManager = (ForwardEngineerANOCataloguePlanManager)JsonConvertExtensions.DeserializeObject(asString, typeof(ForwardEngineerANOCataloguePlanManager), RepositoryLocator);
                }

                //not part of serialization
                planManager.TargetDatabase = dbTo;
                planManager.SkippedTables.Add(fromNeckTableInfo);//skip the necks table because it already exists (ColumnInfos may or may not exist but physical table definetly does)

                var engine = new ForwardEngineerANOCatalogueEngine(RepositoryLocator, planManager);

                if (!tableInfoAlreadyExistsForSkippedTable)
                {
                    var ex = Assert.Throws <Exception>(engine.Execute);
                    Assert.IsTrue(Regex.IsMatch(ex.InnerException.Message, "Found '0' ColumnInfos called"));
                    Assert.IsTrue(Regex.IsMatch(ex.InnerException.Message, "[Necks].[SpineColor]"));

                    return;
                }
                else
                {
                    engine.Execute();
                }

                var newCata = CatalogueRepository.GetAllObjects <Catalogue>().Single(c => c.Name.Equals("ANOHeads"));
                Assert.IsTrue(newCata.Exists());

                var newCataItems = newCata.CatalogueItems;
                Assert.AreEqual(newCataItems.Count(), 4);

                //should be extraction informations
                //all extraction informations should point to the new table location
                Assert.IsTrue(newCataItems.All(ci => ci.ExtractionInformation.SelectSQL.Contains(dbTo.GetRuntimeName())));

                //these columns should all exist
                Assert.IsTrue(newCataItems.Any(ci => ci.ExtractionInformation.SelectSQL.Contains("SkullColor")));
                Assert.IsTrue(newCataItems.Any(ci => ci.ExtractionInformation.SelectSQL.Contains("SpineColor")));
                Assert.IsTrue(newCataItems.Any(ci => ci.ExtractionInformation.SelectSQL.Contains("Vertebrae"))); //actually there will be 2 copies of this one from Necks one from Heads

                //new ColumnInfo should have a reference to the anotable
                Assert.IsTrue(newCataItems.Single(ci => ci.Name.Equals("ANOSkullColor")).ColumnInfo.ANOTable_ID == anoTable.ID);


                var newSpineColorColumnInfo = newCataItems.Single(ci => ci.Name.Equals("ANOSkullColor")).ColumnInfo;

                //table info already existed, make sure the new CatalogueItems point to the same columninfos / table infos
                Assert.IsTrue(newCataItems.Select(ci => ci.ColumnInfo).Contains(newSpineColorColumnInfo));
            }
            finally
            {
                dbFrom.Drop();
                dbTo.Drop();
            }
        }
Пример #5
0
        public void GatherAndShare_ANOTable_Test(bool goViaJson)
        {
            var anoserver = new ExternalDatabaseServer(CatalogueRepository, "MyGatherAndShareTestANOServer", new ANOStorePatcher());
            var anoTable  = new ANOTable(CatalogueRepository, anoserver, "ANOMagad", "N");

            Assert.AreEqual(anoTable.Server_ID, anoserver.ID);

            Gatherer g = new Gatherer(RepositoryLocator);

            Assert.IsTrue(g.CanGatherDependencies(anoTable));

            var gObj = g.GatherDependencies(anoTable);

            //root should be the server
            Assert.AreEqual(gObj.Object, anoserver);
            Assert.AreEqual(gObj.Children.Single().Object, anoTable);

            //get the sharing definitions
            var             shareManager = new ShareManager(RepositoryLocator);
            ShareDefinition defParent    = gObj.ToShareDefinition(shareManager, new List <ShareDefinition>());
            ShareDefinition defChild     = gObj.Children.Single().ToShareDefinition(shareManager, new List <ShareDefinition>(new [] { defParent }));

            //make it look like we never had it in the first place
            shareManager.GetNewOrExistingExportFor(anoserver).DeleteInDatabase();
            shareManager.GetNewOrExistingExportFor(anoTable).DeleteInDatabase();
            anoTable.DeleteInDatabase();
            anoserver.DeleteInDatabase();

            if (goViaJson)
            {
                var sParent = JsonConvertExtensions.SerializeObject(defParent, RepositoryLocator);
                var sChild  = JsonConvertExtensions.SerializeObject(defChild, RepositoryLocator);

                defParent = (ShareDefinition)JsonConvertExtensions.DeserializeObject(sParent, typeof(ShareDefinition), RepositoryLocator);
                defChild  = (ShareDefinition)JsonConvertExtensions.DeserializeObject(sChild, typeof(ShareDefinition), RepositoryLocator);
            }

            var anoserverAfter = new ExternalDatabaseServer(shareManager, defParent);

            Assert.IsTrue(anoserverAfter.Exists());

            //new instance
            Assert.AreNotEqual(anoserverAfter.ID, anoserver.ID);

            //same properties
            Assert.AreEqual(anoserverAfter.Name, anoserver.Name);
            Assert.AreEqual(anoserverAfter.CreatedByAssembly, anoserver.CreatedByAssembly);
            Assert.AreEqual(anoserverAfter.Database, anoserver.Database);
            Assert.AreEqual(anoserverAfter.DatabaseType, anoserver.DatabaseType);
            Assert.AreEqual(anoserverAfter.Username, anoserver.Username);
            Assert.AreEqual(anoserverAfter.Password, anoserver.Password);

            var anoTableAfter = new ANOTable(shareManager, defChild);

            //new instance
            Assert.AreNotEqual(anoTableAfter.ID, anoTable.ID);
            Assert.AreNotEqual(anoTableAfter.Server_ID, anoTable.Server_ID);

            //same properties
            Assert.AreEqual(anoTableAfter.NumberOfCharactersToUseInAnonymousRepresentation, anoTable.NumberOfCharactersToUseInAnonymousRepresentation);
            Assert.AreEqual(anoTableAfter.Suffix, anoTable.Suffix);

            //change a property and save it
            anoTableAfter.Suffix = "CAMMELS!";
            CatalogueRepository.SaveToDatabase(anoTableAfter);
            //anoTableAfter.SaveToDatabase(); <- this decides to go check the ANOTable exists on the server refernced which is immaginary btw >< thats why we have the above line instead

            //reimport (this time it should be an update, we import the share definitions and it overrdies our database copy (sharing is UPSERT)
            var anoTableAfter2 = new ANOTable(shareManager, defChild);

            Assert.AreEqual(anoTableAfter.ID, anoTableAfter2.ID);
            Assert.AreEqual("N", anoTableAfter2.Suffix);
            Assert.AreEqual(ChangeDescription.DatabaseCopyDifferent, anoTableAfter.HasLocalChanges().Evaluation);

            anoTableAfter.DeleteInDatabase();
            anoserverAfter.DeleteInDatabase();

            foreach (ObjectImport o in RepositoryLocator.CatalogueRepository.GetAllObjects <ObjectImport>())
            {
                o.DeleteInDatabase();
            }
        }
Пример #6
0
        public void GatherAndShare_Catalogue_Test(bool goViaJson)
        {
            //Setup some objects under Catalogue that we can share
            var cata = new Catalogue(CatalogueRepository, "Cata");

            cata.Periodicity = Catalogue.CataloguePeriodicity.BiMonthly;
            cata.SaveToDatabase();

            var catalogueItem1 = new CatalogueItem(CatalogueRepository, cata, "Ci1");
            var catalogueItem2 = new CatalogueItem(CatalogueRepository, cata, "Ci2");

            var tableInfo = new TableInfo(CatalogueRepository, "Myt");
            var colInfo   = new ColumnInfo(CatalogueRepository, "[Mt].[C1]", "varchar(10)", tableInfo);

            catalogueItem1.ColumnInfo_ID = colInfo.ID;
            catalogueItem1.SaveToDatabase();

            var ei = new ExtractionInformation(CatalogueRepository, catalogueItem1, colInfo, "UPPER(C1) as Fish");

            //the logging server has a system default so should have been populated
            Assert.IsNotNull(cata.LiveLoggingServer_ID);

            //Catalogue sharing should be allowed
            Gatherer g = new Gatherer(RepositoryLocator);

            Assert.IsTrue(g.CanGatherDependencies(cata));

            //gather the objects depending on Catalogue as a tree
            var gObj = g.GatherDependencies(cata);

            Assert.AreEqual(2, gObj.Children.Count); //both cata items

            var lmd = new LoadMetadata(CatalogueRepository);

            cata.LoadMetadata_ID = lmd.ID;
            cata.SaveToDatabase();

            //get the share definition
            var shareManager    = new ShareManager(RepositoryLocator);
            var shareDefinition = gObj.ToShareDefinitionWithChildren(shareManager);


            if (goViaJson)
            {
                var json =
                    shareDefinition.Select(s => JsonConvertExtensions.SerializeObject(s, RepositoryLocator)).ToList();
                shareDefinition =
                    json.Select(
                        j => JsonConvertExtensions.DeserializeObject(j, typeof(ShareDefinition), RepositoryLocator))
                    .Cast <ShareDefinition>()
                    .ToList();
            }

            //make a local change
            cata.Name            = "fishfish";
            cata.SubjectNumbers  = "123";
            cata.LoadMetadata_ID = null;
            cata.Periodicity     = Catalogue.CataloguePeriodicity.Unknown;
            cata.SaveToDatabase();

            lmd.DeleteInDatabase();

            //import the saved copy
            shareManager.ImportSharedObject(shareDefinition);

            //revert the memory copy and check it got overwritten with the original saved values
            cata.RevertToDatabaseState();
            Assert.AreEqual("Cata", cata.Name);

            var exports = CatalogueRepository.GetAllObjects <ObjectExport>();

            Assert.IsTrue(exports.Any());

            //now delete and report
            foreach (var d in exports)
            {
                d.DeleteInDatabase();
            }

            //make a local change including Name
            cata.Name = "fishfish";
            cata.SaveToDatabase();

            //test importing the Catalogue properties only
            shareManager.ImportPropertiesOnly(cata, shareDefinition[0]);

            //import the defined properties but not name
            Assert.AreEqual("fishfish", cata.Name);
            Assert.AreEqual(Catalogue.CataloguePeriodicity.BiMonthly, cata.Periodicity); //reset this though
            Assert.IsNull(cata.LoadMetadata_ID);
            cata.SaveToDatabase();

            cata.DeleteInDatabase();

            //none of these should now exist thanks to cascade deletes
            Assert.IsFalse(cata.Exists());
            Assert.IsFalse(catalogueItem1.Exists());
            Assert.IsFalse(catalogueItem2.Exists());

            //import the saved copy
            var newObjects = shareManager.ImportSharedObject(shareDefinition).ToArray();

            Assert.AreEqual("Cata", ((Catalogue)newObjects[0]).Name);
            Assert.AreEqual("Ci1", ((CatalogueItem)newObjects[1]).Name);
            Assert.AreEqual("Ci2", ((CatalogueItem)newObjects[2]).Name);
        }