public async Task Folders_Create_DoesCreate()
        {
            //Arrange

            Random rnd = new Random();

            folders parentFolder = new folders
            {
                Description  = Guid.NewGuid().ToString(),
                Name         = Guid.NewGuid().ToString(),
                MicrotingUid = rnd.Next(1, 255)
            };
            await parentFolder.Create(dbContext).ConfigureAwait(false);

            folders folder = new folders
            {
                Description  = Guid.NewGuid().ToString(),
                Name         = Guid.NewGuid().ToString(),
                MicrotingUid = rnd.Next(1, 255),
                ParentId     = parentFolder.Id
            };

            //Act

            await folder.Create(dbContext).ConfigureAwait(false);

            List <folders>         folders        = dbContext.folders.AsNoTracking().ToList();
            List <folder_versions> folderVersions = dbContext.folder_versions.AsNoTracking().ToList();

            Assert.NotNull(folders);
            Assert.NotNull(folderVersions);

            Assert.AreEqual(2, folders.Count());
            Assert.AreEqual(2, folderVersions.Count());

            Assert.AreEqual(folder.CreatedAt.ToString(), folders[1].CreatedAt.ToString());
            Assert.AreEqual(folder.Version, folders[1].Version);
            Assert.AreEqual(folders[1].WorkflowState, Constants.WorkflowStates.Created);
            Assert.AreEqual(folder.Id, folders[1].Id);
            Assert.AreEqual(folder.Description, folders[1].Description);
            Assert.AreEqual(folder.Name, folders[1].Name);
            Assert.AreEqual(folder.MicrotingUid, folders[1].MicrotingUid);
            Assert.AreEqual(folder.ParentId, parentFolder.Id);

            //Versions

            Assert.AreEqual(folder.CreatedAt.ToString(), folderVersions[1].CreatedAt.ToString());
            Assert.AreEqual(1, folderVersions[1].Version);
            Assert.AreEqual(folderVersions[1].WorkflowState, Constants.WorkflowStates.Created);
            Assert.AreEqual(folder.Id, folderVersions[1].FolderId);
            Assert.AreEqual(folder.Description, folderVersions[1].Description);
            Assert.AreEqual(folder.Name, folderVersions[1].Name);
            Assert.AreEqual(folder.MicrotingUid, folderVersions[1].MicrotingUid);
            Assert.AreEqual(parentFolder.Id, folderVersions[1].ParentId);
        }
Пример #2
0
        public void Rename()
        {
            decimal id   = this.requestData.info.id;
            decimal type = this.requestData.info.type;
            string  name = this.requestData.name;

            NodeData ret = null;

            if (type == 0)   //文件夹类型
            {
                folders folder = (from c in db.folders
                                  where c.id == id
                                  select c).FirstOrDefault();
                folder.name       = name;
                folder.updated_at = DateTime.Now;
                db.SubmitChanges();
                ret = new NodeData
                {
                    id       = folder.id,
                    type     = 0,
                    filename = folder.name.Trim(),
                    time     = folder.updated_at,
                    del      = false,
                    size     = "-"
                };
            }
            else
            {
                files file = (from c in db.files
                              where c.id == id
                              select c
                              ).FirstOrDefault();
                file.name       = name;
                file.updated_at = DateTime.Now;
                db.SubmitChanges();
                ret = new NodeData
                {
                    id       = file.id,
                    type     = file.fil_id == null ? 6 : (decimal)file.fil_id,
                    filename = file.name.Trim(),
                    time     = file.updated_at,
                    del      = file.softdelete,
                    size     = file.size.ToString()
                };
            }

            this.resultData = ret;
        }
Пример #3
0
        static void Main(string[] args)
        {
            const string tTargetName       = "Tenant 2 Test";
            string       tTargetIdentifier = Util.MakeIdentifierRootIdentifier(typeof(tenant).Name, Util.TrimWhitespace(tTargetName));

            const string mTargetName       = "Model 2 Test";
            string       mTargetIdentifier = Util.MakeIdentifierFromParentIdentifier(
                Util.MakeIdentifierRootIdentifier(typeof(tenant).Name, tTargetName),
                typeof(model).Name, Util.TrimWhitespace(mTargetName));

            tenant tTarget = null;
            model  mTarget = null;

            using (var ctxTarget = new ModelMateEFModel9Context())
            {
                ctxTarget.Database.Log = Console.Write;

                tTarget = ModelFinder.FindTenant(ctxTarget, tTargetIdentifier, "");
                ModelDump.DisplayDBPropertyValues("tTarget", ctxTarget.Entry(tTarget).CurrentValues, null);

                folders fs0 = tTarget.folders.ElementAt(0);
                ModelDump.DisplayDBPropertyValues("fs0", ctxTarget.Entry(fs0).CurrentValues, null);
                folder f0 = fs0.folder.ElementAt(0);
                ModelDump.DisplayDBPropertyValues("f0", ctxTarget.Entry(f0).CurrentValues, null);

                mTarget = ModelFinder.FindModel(ctxTarget, tTarget, mTargetIdentifier, null);
                ModelDump.DisplayDBPropertyValues("mTarget", ctxTarget.Entry(mTarget).CurrentValues, null);

                string  modelSchemaFile = @"..\..\..\PSN.ModelMate.Schema\Schema\ModelMateModel9.xsd";
                DataSet dsModel         = new DataSet();
                dsModel.ReadXmlSchema(modelSchemaFile);
                //DataSet ds3 = dsModel.Copy();
                //var mmpModel = new ModelMateProcessor();
                var mmpModel = new ModelProcessor(ModelProcessor.ConvertModel2AMEFFDataSet);
                mmpModel.ProcessModel(dsModel, (DbContext)ctxTarget, new Collection <model> {
                    mTarget
                });
                //dsModel.WriteXml("modelds.xml", XmlWriteMode.IgnoreSchema);
                string filename = "model4archi.xml";
                mmpModel.SaveAMEFFDataSetAsXML(dsModel, filename);

                Console.WriteLine("Press Enter to exit...");
                Console.ReadLine();
            }
        }
        public async Task Core_Folders_DeleteFolder_DoesMarkFolderAsRemoved()
        {
            // Arrange

            string  folderName        = Guid.NewGuid().ToString();
            string  folderDescription = Guid.NewGuid().ToString();
            folders folder            = new folders();

            folder.Name          = folderName;
            folder.Description   = folderDescription;
            folder.WorkflowState = Constants.WorkflowStates.Created;
            folder.MicrotingUid  = 23123;

            await folder.Create(dbContext).ConfigureAwait(false);

            //Act

            await sut.FolderDelete(folder.Id);

            var folderVersions = dbContext.folder_versions.AsNoTracking().ToList();
            var folders        = dbContext.folders.AsNoTracking().ToList();

            //Assert

            Assert.NotNull(folders);
            Assert.NotNull(folderVersions);

            Assert.AreEqual(1, folders.Count);
            Assert.AreEqual(2, folderVersions.Count);

            Assert.AreEqual(folders[0].Name, folderName);
            Assert.AreEqual(folders[0].Description, folderDescription);
            Assert.AreEqual(folders[0].WorkflowState, Constants.WorkflowStates.Removed);


            Assert.AreEqual(folderVersions[0].Name, folders[0].Name);
            Assert.AreEqual(folderVersions[0].Description, folders[0].Description);
            Assert.AreEqual(folderVersions[0].WorkflowState, Constants.WorkflowStates.Created);


            Assert.AreEqual(folderVersions[1].Name, folders[0].Name);
            Assert.AreEqual(folderVersions[1].Description, folders[0].Description);
            Assert.AreEqual(folderVersions[1].WorkflowState, Constants.WorkflowStates.Removed);
        }
Пример #5
0
        private async void Start()
        {
            var parser = new Parser();

            UpdateStatus(string.Empty);
            if (string.IsNullOrWhiteSpace(_basePath))
            {
                UpdateStatus("You MUST set select your beat saber folder first!\n");
                return;
            }
            if (!CheckRequiredFoldersAndFiles())
            {
                UpdateStatus("\nCan not continue until all files and folders required are in place.....");
                return;
            }
            UpdateStatus("\n\nStarting........\nGetting song hash info.....");
            _songHashDisctionary = await parser.GetSongFolderHashesAsync(_basePath);

            UpdateStatus("\nGot hashes. Looking for playlists.....");
            _folders = parser.GetFoldersFromXml(_basePath);
            if (!_folders.folder.Any())
            {
                MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show("Oh no! It looks like you either have an empty folders.xml file OR you have capitalized WIP values. If you have not manually changed the file continue. If you have changed the file, go back and make the WIP values all lower case. Do you want to continue anyways and overwrite the folders.xml file?", "Overwrite Confirmation", MessageBoxButton.YesNo);
                if (messageBoxResult == MessageBoxResult.No)
                {
                    UpdateStatus("\n\nCould not continue!\nIf you have True or False values in your folders.xml file you NEED to change them to be all lower case. Make any \"False\" values false and any \"True\" values true. Then hit start to try again.");
                    return;
                }
                else
                {
                    UpdateStatus("\n\nContinuing. This will overwrite your existing xml file with a valid one.");
                }
            }
            _folders.folder.RemoveAll(x => x.Path.StartsWith("Example")); // We don't want to include examples here
            var playlists = FindPlaylists();

            CreatePlaylistFolders(playlists);
            UpdateStatus("\n\nSaving folders xml file.....");
            parser.SaveFoldersToXml(_basePath, _folders);
            ForceRename();
            UpdateStatus("\n\n\nDone!");
        }
Пример #6
0
        static void Main(string[] args)
        {
            int id = (Int32)DateTime.Now.Ticks;
            Console.WriteLine("id: " + id.ToString());

            var tenant1 = new tenant();
            tenant1.tenant_Id = id++;
            var tname = new name();
            tname.name_Id = id++;
            tname.lang = "en-us";
            tname.name_text = "tenant " + DateTime.Now.ToString();
            tenant1.name.Add(tname);

            var folders = new folders();
            folders.folders_Id = id++;
            var fname = new name();
            fname.lang = "en-us";
            fname.name_Id = id++;
            fname.name_text = "folders " + DateTime.Now.ToString();

            tenant1.folders.Add(folders);

            using (var ctx = new PSN.ModelMate.EDM.ModelMateEFModel9Context())
            {
                ctx.Database.Log = Console.Write;
                ctx.tenant.Add(tenant1);
                ctx.SaveChanges();
            }

            using (var ctx = new PSN.ModelMate.EDM.ModelMateEFModel9Context())
            {
                ctx.Database.Log = Console.Write;
                var tenant2 = ctx.tenant.Find(new object[] { tenant1.tenant_Id });
                Console.WriteLine("tenant.name.count: " + tenant2.name.Count);
                Console.WriteLine("tenant.folders.count: " + tenant2.folders.Count);
                ctx.SaveChanges();
            }

            Console.WriteLine("Press enter to continue...");
            Console.ReadLine();

        }
Пример #7
0
        public void SaveFoldersToXml(string path, folders folders)
        {
            // removes version
            XmlWriterSettings settings = new XmlWriterSettings();

            settings.OmitXmlDeclaration = true;

            XmlSerializer xsSubmit = new XmlSerializer(typeof(folders));

            using (StringWriter sw = new StringWriter())
                using (XmlWriter writer = XmlWriter.Create(sw, settings))
                {
                    // removes namespace
                    var xmlns = new XmlSerializerNamespaces();
                    xmlns.Add(string.Empty, string.Empty);

                    xsSubmit.Serialize(writer, folders, xmlns);
                    var content       = sw.ToString();
                    var xml_formatted = XDocument.Parse(content).ToString();
                    File.WriteAllText($@"{path}\UserData\SongCore\folders.xml", xml_formatted);
                }
        }
Пример #8
0
        public void AddFolder()
        {
            folders folder = new folders
            {
                fol_id     = this.requestData.currentFolder,
                use_id     = this.uid,
                name       = this.requestData.name,
                created_at = DateTime.Now,
                updated_at = DateTime.Now
            };

            db.folders.InsertOnSubmit(folder);
            db.SubmitChanges();
            this.resultData = new NodeData
            {
                id       = folder.id,
                type     = 0,
                filename = folder.name.Trim(),
                time     = folder.updated_at,
                del      = false,
                size     = "-"
            };
        }
Пример #9
0
        public folders GetFoldersFromXml(string path)
        {
            var result   = new folders();
            var filePath = $@"{path}\UserData\SongCore\folders.xml";

            XmlSerializer ser = new XmlSerializer(typeof(folders));

            try
            {
                using (XmlReader reader = XmlReader.Create(filePath))
                {
                    result = (folders)ser.Deserialize(reader);
                }
            }
            catch (Exception e)
            {
                result = new folders
                {
                    folder = new List <foldersFolder>()
                };
            }

            return(result);
        }
Пример #10
0
        static void Main(string[] args)
        {
            var models1 = new models
            {
                models_Id = Util.MakeIdInt32()
            };

            for (int iTimes = 0; iTimes < 10; iTimes++)
            {
                var model = new model
                {
                    identifier = Util.MakeIdentifierTimestamped(ModelConst.MODEL_PREFIX, DateTime.Now),
                    version    = ModelConst.MODEL_VERSION,
                    model_Id   = Util.MakeIdInt32()
                };
                models1.model.Add(model);
            }

            var models2 = new models
            {
                models_Id = Util.MakeIdInt32()
            };

            for (int iTimes = 0; iTimes < 10; iTimes++)
            {
                var model = new model
                {
                    identifier = Util.MakeIdentifierTimestamped(ModelConst.MODEL_PREFIX, DateTime.Now),
                    version    = ModelConst.MODEL_VERSION,
                    model_Id   = Util.MakeIdInt32()
                };
                models2.model.Add(model);
            }

            folder[] folderArray = new folder[2];
            folderArray[0] = new folder
            {
                identifier = Util.MakeIdentifierTimestamped(ModelConst.MODEL_PREFIX, DateTime.Now),
                folder_Id  = Util.MakeIdInt32()
            };
            folderArray[0].models.Add(models1); // NOTE: Models

            folderArray[1] = new folder
            {
                identifier = Util.MakeIdentifierTimestamped(ModelConst.MODEL_PREFIX, DateTime.Now),
                folder_Id  = Util.MakeIdInt32()
            };
            folderArray[1].models.Add(models2); // NOTE: Model Templates

            var folders = new folders
            {
                folders_Id = Util.MakeIdInt32()
            };

            for (int iTimes = 0; iTimes < 2; iTimes++)
            {
                var folder = folderArray[iTimes];
                folders.folder.Add(folder);
            }

            var tenant = new tenant
            {
                identifier = Util.MakeIdentifierTimestamped(ModelConst.TENANT_PREFIX, DateTime.Now),
                version    = ModelConst.TENANT_VERSION,
                tenant_Id  = Util.MakeIdInt32()
            };

            name name;

            name           = new name();
            name.name_Id   = Util.MakeIdInt32();
            name.lang      = "en";
            name.name_text = Util.MakeIdentifierTimestamped(ModelConst.TENANT_PREFIX);
            tenant.name.Add(name);

            name           = new name();
            name.name_Id   = Util.MakeIdInt32();
            name.lang      = "en";
            name.name_text = Util.MakeIdentifierTimestamped(ModelConst.TENANT_PREFIX);
            tenant.name.Add(name);

            tenant.folders.Add(folders);

            using (var context = new ModelMateEFModel9Context())
            {
                context.tenant.Add(tenant);
                context.SaveChanges();

                tenant.version = ModelConst.TENANT_TESTVERSION;

                context.SaveChanges();

                object[] keys         = { 1724588879 };
                tenant   tenantDelete = context.tenant.Find(keys);
                context.tenant.Remove(tenantDelete);
                context.SaveChanges();
            }

            Console.WriteLine("Press Enter to continue...");
            Console.ReadLine();
        }
Пример #11
0
        static void Main(string[] args)
        {
            string modelName = "Model 2 Test";

            ModelFactory.ModelName = modelName;

            //model modelArchisurance = ObjectFactory.NewModel("Archisurance");
            //DataSet dsArchisurance = new DataSet();
            //string xmlArchiSurance = @"..\..\..\PSN.ModelMate.Schema\Samples\Archisurance\Archisurance-psn.xml";
            //dsArchisurance.ReadXml(xmlArchiSurance);
            ////dsArchisurance.WriteXmlSchema("xmlArchiSurance.xsd");
            ////dsArchisurance.WriteXml("xmlArchiSurance.xml");
            //var mmpArchisurance = new ModelMateProcessor(ModelMateProcessor.ConvertAMEFFDataSet2Model);
            //// TODO TODO mmpArchisurance.ProcessModel(dsArchisurance, (DbContext)null, new Collection<model> { modelArchisurance });

            string tenantName = "Tenant 0 " + DateTime.Now.ToString();

            ModelFactory.TenantName = tenantName;

            var tenant0 = ModelFactory.NewTenantWithRootFolder(tenantName);

            tenantName = "Tenant 1 " + DateTime.Now.ToString();
            ModelFactory.TenantName = tenantName;

            var tenant1 = ModelFactory.NewTenant(tenantName,
                                                 ModelFactory.NewFolder("/",
                                                                        new folder[] { ModelFactory.NewFolder("Model Templates"), ModelFactory.NewFolder("Production Models") }
                                                                        )
                                                 );

            ModelConst.PropertyDataType dtStringType = ModelConst.PropertyDataType.stringType;
            propertydef  pdefString = ModelFactory.NewPropertyDef("String Propertydef " + DateTime.Now.ToString(), dtStringType);
            propertydefs pdefs      = ModelFactory.NewPropertyDefs(pdefString);

            ModelConst.ElementType etAC = ModelConst.ElementType.ApplicationComponent;
            element[] elementArray      = new element[10];
            for (int iElement = 0; iElement < 10; iElement++)
            {
                property p = ModelFactory.NewProperty(ModelFactory.NewValue("Element Property Value " + DateTime.Now.ToString()),
                                                      pdefString);
                elementArray[iElement] = ModelFactory.NewElement("Element " + iElement.ToString() + " " + DateTime.Now.ToString(), etAC, p);
            }
            elements elements = ModelFactory.NewElements(elementArray);

            tenantName = "Tenant 2 Test";
            ModelFactory.TenantName = tenantName;

            model model2;
            //var tenant2 = ModelFactory.NewTenant(tenantName,
            //                ModelFactory.NewFolder("/",
            //                    ModelFactory.NewFolder("Production Models",
            //                        ModelFactory.NewFolder("HQ Models Folder " + DateTime.Now.ToString(),
            //                            model2 = ModelFactory.NewModel(modelName, ModelConst.LANG_EN,
            //                                                            elements, pdefs
            //                            )
            //                        )
            //                    )
            //                )
            //              );

            var tenant2 = ModelFactory.NewTenant(tenantName,
                                                 ModelFactory.NewFolder("/",
                                                                        model2 = ModelFactory.NewModel(modelName, ModelConst.LANG_EN,
                                                                                                       elements, pdefs
                                                                                                       )
                                                                        )
                                                 );

            Console.WriteLine("Tenant.tenant_Id " + tenant2.tenant_Id.ToString());
            foreach (folders fs in tenant2.folders)
            {
                Console.WriteLine("Folders.tenant_Id " + fs.tenant_Id.ToString());
                Console.WriteLine("Folders.folders_Id " + fs.folders_Id.ToString());

                foreach (folder f in fs.folder)
                {
                    Console.WriteLine("Folder " + f.folders_Id.ToString());
                    Console.WriteLine("Folder " + f.folder_Id.ToString());
                }
            }

            var name = ModelFactory.NewName("Model 2 Name " + DateTime.Now.ToString());

            model2.name.Add(name);
            var documentation = ModelFactory.NewDocumentation("Model 2 Documentation " + DateTime.Now.ToString());

            model2.documentation.Add(documentation);
            var metadata = ModelFactory.NewMetadata(
                ModelFactory.NewProperty(ModelFactory.NewValue("Model 2 Metadata Value " + DateTime.Now.ToString()), pdefString)
                );

            model2.metadata.Add(metadata);

            var properties = ModelFactory.NewProperties(
                ModelFactory.NewProperty(ModelFactory.NewValue("Model 2 Property Value " + DateTime.Now.ToString()), pdefString)
                );

            model2.properties.Add(properties);

            var relationship1 = ModelFactory.NewRelationship("Association Relationship " + DateTime.Now.ToString(),
                                                             ModelConst.RelationshipType.AssociationRelationship,
                                                             elementArray[0], elementArray[1]
                                                             );
            var relationships = ModelFactory.NewRelationships(relationship1);

            model2.relationships.Add(relationships);

            var organization = ModelFactory.NewOrganization(
                ModelFactory.NewItem(elementArray[0],
                                     ModelFactory.NewItem(null,
                                                          ModelFactory.NewItem(elementArray[1]
                                                                               )
                                                          )
                                     )
                );

            model2.organization.Add(organization);

            var style1 = ModelFactory.NewStyle(
                ModelFactory.NewFillColor(255, 0, 0),
                ModelFactory.NewLineColor(0, 255, 0),
                ModelFactory.NewFont("Times Roman", (float)10.5, "bold", ModelFactory.NewColor(0, 0, 255)), 3
                );
            var style2 = ModelFactory.NewStyle(
                ModelFactory.NewFillColor(255, 0, 0),
                ModelFactory.NewLineColor(0, 255, 0),
                ModelFactory.NewFont("Times Roman", (float)12.5, "bold", ModelFactory.NewColor(0, 0, 255)), 3
                );

            var node0 = ModelFactory.NewNode("Node 0 " + DateTime.Now.ToString(),
                                             0, 0, 0, 50, 50, 50,
                                             elementArray[0], null, null, style1,
                                             new node[] { ModelFactory.NewNode("Sub Node " + DateTime.Now.ToString(),
                                                                               10, 10, 10, 25, 25, 25,
                                                                               elementArray[3]) }
                                             );
            var node1 = ModelFactory.NewNode("Node 1 " + DateTime.Now.ToString(),
                                             100, 100, 100, 50, 50, 50,
                                             elementArray[1], null, null, style2,
                                             null
                                             );

            var bendpoint1  = ModelFactory.NewBendPoint(25, 25, 25);
            var connection1 = ModelFactory.NewConnection("Connection 1 " + DateTime.Now.ToString(),
                                                         node0, node1, relationship1
                                                         );

            connection1.bendpoint.Add(bendpoint1);

            view view2;
            var  views = ModelFactory.NewViews(
                view2 = ModelFactory.NewView("View 2 " + DateTime.Now.ToString(), ModelConst.ViewType.Layered,
                                             new node[] {
                node0, node1
            },
                                             new connection[] { connection1 }
                                             )
                );

            model2.views.Add(views);

            tenant2.processinghistory.Add(
                ModelFactory.NewProcessinghistory(
                    ModelFactory.NewTimesnap(DateTime.Now, "Timesnap Processinghistory " + DateTime.Now.ToString(),
                                             ModelConst.TimesnapCategory.processinghistory, "Subcategory " + DateTime.Now.ToString(),
                                             null, null,
                                             ModelFactory.NewProperty(ModelFactory.NewValue("Value " + DateTime.Now.ToString()), pdefString
                                                                      )
                                             )
                    )
                );
            tenant2.usage.Add(
                ModelFactory.NewUsage(
                    ModelFactory.NewTimesnap(DateTime.Now, "Timesnap Performance " + DateTime.Now.ToString(),
                                             ModelConst.TimesnapCategory.usage, "Subcategory " + DateTime.Now.ToString(),
                                             null, null,
                                             ModelFactory.NewProperty(ModelFactory.NewValue("Value " + DateTime.Now.ToString()), pdefString
                                                                      )
                                             )
                    )
                );
            tenant2.performance.Add(
                ModelFactory.NewPerformance(
                    ModelFactory.NewTimesnap(DateTime.Now, "Timesnap Performance " + DateTime.Now.ToString(),
                                             ModelConst.TimesnapCategory.performance, "Subcategory " + DateTime.Now.ToString(),
                                             null, null,
                                             ModelFactory.NewProperty(ModelFactory.NewValue("Value " + DateTime.Now.ToString()), pdefString
                                                                      )
                                             )
                    )
                );
            tenant2.management.Add(
                ModelFactory.NewManagement(
                    ModelFactory.NewTimesnap(DateTime.Now, "Timesnap Management " + DateTime.Now.ToString(),
                                             ModelConst.TimesnapCategory.management, "Subcategory " + DateTime.Now.ToString(),
                                             null, null,
                                             ModelFactory.NewProperty(ModelFactory.NewValue("Value " + DateTime.Now.ToString()), pdefString
                                                                      )
                                             )
                    )
                );

            model2.processinghistory.Add(
                ModelFactory.NewProcessinghistory(
                    ModelFactory.NewTimesnap(DateTime.Now, "Timesnap Processinghistory " + DateTime.Now.ToString(),
                                             ModelConst.TimesnapCategory.processinghistory, "Subcategory " + DateTime.Now.ToString(),
                                             null, null,
                                             ModelFactory.NewProperty(ModelFactory.NewValue("Value " + DateTime.Now.ToString()), pdefString
                                                                      )
                                             )
                    )
                );
            model2.usage.Add(
                ModelFactory.NewUsage(
                    ModelFactory.NewTimesnap(DateTime.Now, "Timesnap Performance " + DateTime.Now.ToString(),
                                             ModelConst.TimesnapCategory.usage, "Subcategory " + DateTime.Now.ToString(),
                                             null, null,
                                             ModelFactory.NewProperty(ModelFactory.NewValue("Value " + DateTime.Now.ToString()), pdefString
                                                                      )
                                             )
                    )
                );
            model2.performance.Add(
                ModelFactory.NewPerformance(
                    ModelFactory.NewTimesnap(DateTime.Now, "Timesnap Performance " + DateTime.Now.ToString(),
                                             ModelConst.TimesnapCategory.performance, "Subcategory " + DateTime.Now.ToString(),
                                             null, null,
                                             ModelFactory.NewProperty(ModelFactory.NewValue("Value " + DateTime.Now.ToString()), pdefString
                                                                      )
                                             )
                    )
                );
            model2.management.Add(
                ModelFactory.NewManagement(
                    ModelFactory.NewTimesnap(DateTime.Now, "Timesnap Management " + DateTime.Now.ToString(),
                                             ModelConst.TimesnapCategory.management, "Subcategory " + DateTime.Now.ToString(),
                                             null, null,
                                             ModelFactory.NewProperty(ModelFactory.NewValue("Value " + DateTime.Now.ToString()), pdefString
                                                                      )
                                             )
                    )
                );

            elementArray[0].processinghistory.Add(
                ModelFactory.NewProcessinghistory(
                    ModelFactory.NewTimesnap(DateTime.Now, "Timesnap Processinghistory " + DateTime.Now.ToString(),
                                             ModelConst.TimesnapCategory.processinghistory, "Subcategory " + DateTime.Now.ToString(),
                                             null, null,
                                             ModelFactory.NewProperty(ModelFactory.NewValue("Value " + DateTime.Now.ToString()), pdefString
                                                                      )
                                             )
                    )
                );
            elementArray[0].usage.Add(
                ModelFactory.NewUsage(
                    ModelFactory.NewTimesnap(DateTime.Now, "Timesnap Performance " + DateTime.Now.ToString(),
                                             ModelConst.TimesnapCategory.usage, "Subcategory " + DateTime.Now.ToString(),
                                             null, null,
                                             ModelFactory.NewProperty(ModelFactory.NewValue("Value " + DateTime.Now.ToString()), pdefString
                                                                      )
                                             )
                    )
                );
            elementArray[0].performance.Add(
                ModelFactory.NewPerformance(
                    ModelFactory.NewTimesnap(DateTime.Now, "Timesnap Performance " + DateTime.Now.ToString(),
                                             ModelConst.TimesnapCategory.performance, "Subcategory " + DateTime.Now.ToString(),
                                             null, null,
                                             ModelFactory.NewProperty(ModelFactory.NewValue("Value " + DateTime.Now.ToString()), pdefString
                                                                      )
                                             )
                    )
                );
            elementArray[0].management.Add(
                ModelFactory.NewManagement(
                    ModelFactory.NewTimesnap(DateTime.Now, "Timesnap Management " + DateTime.Now.ToString(),
                                             ModelConst.TimesnapCategory.management, "Subcategory " + DateTime.Now.ToString(),
                                             null, null,
                                             ModelFactory.NewProperty(ModelFactory.NewValue("Value " + DateTime.Now.ToString()), pdefString
                                                                      )
                                             )
                    )
                );

            view2.processinghistory.Add(
                ModelFactory.NewProcessinghistory(
                    ModelFactory.NewTimesnap(DateTime.Now, "Timesnap Processinghistory " + DateTime.Now.ToString(),
                                             ModelConst.TimesnapCategory.processinghistory, "Subcategory " + DateTime.Now.ToString(),
                                             null, null,
                                             ModelFactory.NewProperty(ModelFactory.NewValue("Value " + DateTime.Now.ToString()), pdefString
                                                                      )
                                             )
                    )
                );
            view2.usage.Add(
                ModelFactory.NewUsage(
                    ModelFactory.NewTimesnap(DateTime.Now, "Timesnap Performance " + DateTime.Now.ToString(),
                                             ModelConst.TimesnapCategory.usage, "Subcategory " + DateTime.Now.ToString(),
                                             null, null,
                                             ModelFactory.NewProperty(ModelFactory.NewValue("Value " + DateTime.Now.ToString()), pdefString
                                                                      )
                                             )
                    )
                );
            view2.performance.Add(
                ModelFactory.NewPerformance(
                    ModelFactory.NewTimesnap(DateTime.Now, "Timesnap Performance " + DateTime.Now.ToString(),
                                             ModelConst.TimesnapCategory.performance, "Subcategory " + DateTime.Now.ToString(),
                                             null, null,
                                             ModelFactory.NewProperty(ModelFactory.NewValue("Value " + DateTime.Now.ToString()), pdefString
                                                                      )
                                             )
                    )
                );
            view2.management.Add(
                ModelFactory.NewManagement(
                    ModelFactory.NewTimesnap(DateTime.Now, "Timesnap Management " + DateTime.Now.ToString(),
                                             ModelConst.TimesnapCategory.management, "Subcategory " + DateTime.Now.ToString(),
                                             null, null,
                                             ModelFactory.NewProperty(ModelFactory.NewValue("Value " + DateTime.Now.ToString()), pdefString
                                                                      )
                                             )
                    )
                );

            //using (XmlWriter writer = XmlWriter.Create("model2.xml"))
            //{
            //    //XmlSerializer serializer = new XmlSerializer(typeof(model));
            //    DataContractSerializerSettings settings = new DataContractSerializerSettings();
            //    DataContractSerializer serializer = new DataContractSerializer(typeof(model));
            //    serializer.WriteObject(writer, model2);
            //    writer.Close();
            //}

            string xmlSchemaFile = @"..\..\..\PSN.ModelMate.Schema\Schema\Reference ModelGood9.xsd";

            // DataSet ds = new DataSet();
            // ds.ReadXmlSchema(xmlSchemaFile);
            // BUG DataSet ds2 = new DataSet();
            // BUG ds2.ReadXmlSchema(xmlSchemaFile);

            //DataTable dttenant = ds.Tables["tenant"];
            //DataRow drtentant1 = dttenant.NewRow();
            //DataRow drtentant2 = ds.Tables["tenant"].NewRow();

            //DataTable dtfolders = ds.Tables["folders"];
            //DataTable dtfolder = ds.Tables["folder"];
            //DataTable dtmodels = ds.Tables["models"];
            //DataTable dtmodel = ds.Tables["model"];

            //DataTable dtprocessinghistory = ds.Tables["processinghistory"];
            //DataTable dtusage = ds.Tables["usage"];
            //DataTable dtperformance = ds.Tables["performance"];
            //DataTable dtmanagement = ds.Tables["management"];
            //DataTable dttimesnap = ds.Tables["timesnap"];

            //DataTable dtproperties = ds.Tables["properties"];
            //DataTable dtproperty = ds.Tables["property"];

            //DataTable dtpropertydefs = ds.Tables["propertydefs"];
            //DataTable dtpropertydef = ds.Tables["propertydef"];

            //DataTable dtelements = ds.Tables["elements"];
            //DataTable dtelement = ds.Tables["element"];

            //DataTable dtrelationships = ds.Tables["relationships"];
            //DataTable dtrelationship = ds.Tables["relationship"];

            //DataTable dtviews = ds.Tables["views"];
            //DataTable dtview = ds.Tables["view"];
            //DataTable dtconnection = ds.Tables["connection"];
            //DataTable dtnode = ds.Tables["node"];

            //DataTable dtstyle = ds.Tables["style"];
            //DataTable dtfont = ds.Tables["font"];
            //DataTable dtfillColor = ds.Tables["fillColor"];
            //DataTable dtlineColor = ds.Tables["lineColor"];
            //DataTable dtcolor = ds.Tables["color"];
            //DataTable dtbendpoint = ds.Tables["bendpoint"];

            //DataTable dtmetadata = ds.Tables["metadata"];

            //DataTable dtorganization = ds.Tables["organization"];
            //DataTable dtitem = ds.Tables["item"];

            //DataTable dtname = ds.Tables["name"];
            //DataTable dtvalue = ds.Tables["value"];
            //DataTable dtdocumentation = ds.Tables["documentation"];
            //DataTable dtlabel = ds.Tables["label"];

            using (var ctx = new ModelMateEFModel9Context())
            {
                ctx.Database.Log = Console.Write;

                ctx.tenant.Add(tenant0);
                ModelDump.DisplayTrackedEntities("Add tenant0", ctx.ChangeTracker);
                ctx.SaveChanges();
                ModelDump.DisplayTrackedEntities("Save tenant0", ctx.ChangeTracker);

                ctx.tenant.Add(tenant1);
                ctx.SaveChanges();

                ctx.tenant.Add(tenant2);
                ModelDump.DisplayTrackedEntities("Add tenant2", ctx.ChangeTracker);
                ctx.SaveChanges();
                ModelDump.DisplayTrackedEntities("Save tenant2", ctx.ChangeTracker);
                ModelDump.DisplayDBPropertyValues("tenant2", ctx.Entry(tenant2).CurrentValues, null);
                ModelDump.DisplayDBPropertyValues("model2", ctx.Entry(model2).CurrentValues, null);
                Console.WriteLine("Tenant.tenant_Id " + tenant2.tenant_Id.ToString());
                foreach (folders fs in tenant2.folders)
                {
                    Console.WriteLine("Folders.tenant_Id " + fs.tenant_Id.ToString());
                    Console.WriteLine("Folders.folders_Id " + fs.folders_Id.ToString());

                    foreach (folder f in fs.folder)
                    {
                        Console.WriteLine("Folder " + f.folders_Id.ToString());
                        Console.WriteLine("Folder " + f.folder_Id.ToString());
                    }
                }

                folders fs0 = tenant2.folders.ElementAt(0);
                ModelDump.DisplayDBPropertyValues("fs0", ctx.Entry(fs0).CurrentValues, null);

                folder f0 = fs0.folder.ElementAt(0);
                ModelDump.DisplayDBPropertyValues("f0", ctx.Entry(f0).CurrentValues, null);

                Console.WriteLine("RECURSION ==================================================");
                //DataSet dsTenant = new DataSet();
                //dsTenant.ReadXmlSchema(xmlSchemaFile);
                ////dsTenant.Tables["tenant"].Namespace = "http://www.w3.org/XML/1998/namespace";
                ////dsTenant.Tables["tenant"].Prefix = "xml";
                //var tenant = ctx.tenant.Find(new object[] { tenant2.tenant_Id });
                //var mmp = new ModelMateProcessor(ModelMateProcessor.ProcessObjectPopulateXMLDataSet);
                //mmp.ProcessTenant(dsTenant, (DbContext)ctx, new Collection<tenant> { tenant });
                //dsTenant.WriteXml("tentantds.xml");

                string  modelSchemaFile = @"..\..\..\PSN.ModelMate.Schema\Schema\ModelMateModel9.xsd";
                DataSet dsModel         = new DataSet();
                dsModel.ReadXmlSchema(modelSchemaFile);
                //DataSet ds3 = dsModel.Copy();
                //var mmpModel = new ModelMateProcessor();
                var mmpModel = new ModelProcessor(ModelProcessor.ConvertModel2AMEFFDataSet);
                mmpModel.ProcessModel(dsModel, (DbContext)ctx, new Collection <model> {
                    model2
                });
                dsModel.WriteXml("modelds.xml", XmlWriteMode.IgnoreSchema);
                string filename = "modelds2.xml";
                mmpModel.SaveAMEFFDataSetAsXML(dsModel, filename);

                tenant2.version = ModelConst.TENANT_TESTVERSION;
                var name2 = ModelFactory.NewName("Model Name FR " + DateTime.Now.ToString(), ModelConst.LANG_FR);
                model2.name.Add(name2);
                var name3 = ModelFactory.NewName("Model Name EN " + DateTime.Now.ToString());
                model2.name.Add(name3);
                ModelDump.DisplayTrackedEntities("Change tenant2", ctx.ChangeTracker);
                ctx.SaveChanges();
                ModelDump.DisplayTrackedEntities("Save tenant2", ctx.ChangeTracker);

                object[] keys    = { -1702823521 };
                tenant   tenant9 = ctx.tenant.Find(keys);
                //ctx.tenant.Remove(tenantDelete);
                //ctx.SaveChanges();
            }

            Console.WriteLine("Press enter to exist...");
            Console.ReadLine();
        }
Пример #12
0
        static void Main(string[] args)
        {
            using (var ctx = new ModelMateEFModel9Context())
            {
                ctx.Database.Log = Console.Write;
                Console.WriteLine("LazyLoadingEnabled: " + ctx.Configuration.LazyLoadingEnabled.ToString());

                foreach (tenant t in ctx.tenant)
                {
                    ModelDump.DisplayDBPropertyValues("t", ctx.Entry(t).CurrentValues, null);
                }

                //var query = from t in ctx.tenant
                //            where t.identifier == tident1
                //            select t;
                //tenant tq = query.Single();

                //object[] keysq = { tid };
                //tenant tq = ctx.tenant.Find(keysq);

                //ctx.Entry(tq).Collection(fs => fs.folders).Load(); // Works
                //folders fsq = tq.folders.ElementAt(0);
                //ModelMateLib.DisplayDBPropertyValues("fsq", ctx.Entry(fsq).CurrentValues, null);

                //ctx.Entry(fsq).Collection(f => f.folder).Load(); // Works
                //folder fq = fsq.folder.ElementAt(0);
                //ModelMateLib.DisplayDBPropertyValues("fq", ctx.Entry(fq).CurrentValues, null);

                //ctx.tenant.Load();
                object[] keys    = { tid };
                tenant   tenant9 = ctx.tenant.Find(keys);
                folders  fs0     = tenant9.folders.ElementAt(0);
                ModelDump.DisplayDBPropertyValues("fs0", ctx.Entry(fs0).CurrentValues, null);
                folder f0 = fs0.folder.ElementAt(0);
                ModelDump.DisplayDBPropertyValues("f0", ctx.Entry(f0).CurrentValues, null);



                //folders fs0 = t0.folders.ElementAt(0);
                //ModelMateLib.DisplayDBPropertyValues("fs0", ctx.Entry(fs0).CurrentValues, null);
                //folder f0 = fs0.folder.ElementAt(0);
                //ModelMateLib.DisplayDBPropertyValues("f0", ctx.Entry(f0).CurrentValues, null);

                tenant[] ts2 = new tenant[] { };
                ts2 = ModelFinder.FindTenants(ctx, tident2, "");
                ModelDump.DisplayDBPropertyValues("ts2", ctx.Entry(ts2[0]).CurrentValues, null);

                ts2 = ModelFinder.FindTenants(ctx, "", tname2);
                ModelDump.DisplayDBPropertyValues("ts2", ctx.Entry(ts2[0]).CurrentValues, null);

                tenant t2 = null;
                try
                {
                    t2 = ModelFinder.FindTenant(ctx, "", tname1);
                    ModelDump.DisplayDBPropertyValues("t1", ctx.Entry(t2).CurrentValues, null);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("EXCEPTION: " + ex.ToString());
                }

                //tenant t2 = null;
                try
                {
                    t2 = ModelFinder.FindTenant(ctx, tident1, "");
                    ModelDump.DisplayDBPropertyValues("t1", ctx.Entry(t2).CurrentValues, null);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("EXCEPTION: " + ex.ToString());
                }

                model m2 = ModelFinder.FindModel(ctx, t2, mident0, null);
                ModelDump.DisplayDBPropertyValues("m2", ctx.Entry(m2).CurrentValues, null);

                element[] es0 = ModelFinder.FindElements(ctx, t2, m2, ModelConst.ElementType.ApplicationComponent);
                Console.WriteLine("es0.Count: " + es0.Count <element>().ToString());
                ModelDump.DisplayDBPropertyValues("es0", ctx.Entry(es0[0]).CurrentValues, null);

                es0 = ModelFinder.FindElements(ctx, t2, m2, ModelConst.ElementType.AllElementTypes);
                Console.WriteLine("es0.Count: " + es0.Count <element>().ToString());
                ModelDump.DisplayDBPropertyValues("es0", ctx.Entry(es0[0]).CurrentValues, null);

                relationship[] rs0 = ModelFinder.FindRelationships(ctx, t2, m2, ModelConst.RelationshipType.AllRelationshipTypes);
                Console.WriteLine("es0.Count: " + es0.Count <element>().ToString());
                ModelDump.DisplayDBPropertyValues("es0", ctx.Entry(es0[0]).CurrentValues, null);

                foreach (relationship r in rs0)
                {
                    element eSource = ModelFinder.FindElement(ctx, t2, m2, r.source, null);
                    element eTarget = ModelFinder.FindElement(ctx, t2, m2, r.target, null);
                    ModelDump.DisplayDBPropertyValues("eSource", ctx.Entry(eSource).CurrentValues, null);
                    ModelDump.DisplayDBPropertyValues("r", ctx.Entry(r).CurrentValues, null);
                    ModelDump.DisplayDBPropertyValues("eTarget", ctx.Entry(eTarget).CurrentValues, null);
                }

                Console.WriteLine("Press enter to exit...");
                Console.ReadLine();
            }
        }
Пример #13
0
        static void Main(string[] args)
        {
            const string tTargetName = "Test6 Tenant";
            const string mTargetName = "Test6 Model";

            string tSourceName = tTargetName;
            string mSourceName = mTargetName;

            //DirectoryInfo di = new DirectoryInfo(@"..\..\MyUsers4ModelMate");
            DirectoryInfo di = new DirectoryInfo(@"..\..\Test Assemblies");
            //DirectoryInfo di = new DirectoryInfo(@"..\..\Web Assemblies");

            string test1 = "Microsoft.CSharp, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";

            //"System.Xml.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

            //"System.Collections.Generic.IDictionary`2<System.String,System.Data.Entity.Infrastructure.Annotations.AnnotationValues> System.Data.Entity.Migrations.Model.AlterTableOperation::_annotations";

            //"System.Collections.Generic.IDictionary`2<System.String,System.Data.Entity.Infrastructure.Annotations.AnnotationValues> System.Data.Entity.Migrations.Model.AlterTableOperation::_annotations";

            //"System.Data.Entity.DbSet`1<VetContext1.DataModel1.AnimalType>";

            string test1Namespace  = Cecil2ModelMate.GetNamespaceFromFQName(test1);
            string test1Name       = Cecil2ModelMate.GetNameFromFQName(test1);
            string test1ObjectType = Cecil2ModelMate.DetermineArchiMateObjectType(test1).ToString();

            Console.WriteLine("test1: " + test1);
            Console.WriteLine("test1Namespace: " + test1Namespace);
            Console.WriteLine("test1Name: " + test1Name);
            Console.WriteLine("test1ObjectType: " + test1ObjectType);
            test1ObjectType = Cecil2ModelMate.DetermineArchiMateObjectType(test1Name).ToString();
            Console.WriteLine("test1ObjectType: " + test1ObjectType);
            test1ObjectType = Cecil2ModelMate.DetermineArchiMateObjectType(test1Namespace).ToString();
            Console.WriteLine("test1ObjectType: " + test1ObjectType);

            //test1 = "a.b.c.d";
            //test1Name = Cecil2ModelMate.GetNameFromFQName(test1);
            //test1Namespace = Cecil2ModelMate.GetNamespaceFromFQName(test1);
            //Console.WriteLine("test1: " + test1);
            //Console.WriteLine("test1Namespace: " + test1Namespace);
            //Console.WriteLine("test1Name: " + test1Name);

            //string test2 = "System.Data.Entity.DbSet`1<VetContext1.DataModel1.AnimalType>";
            //string test2Name = Cecil2ModelMate.DetermineArchiMateObjectType(test2).ToString();
            //Console.WriteLine("test2: " + test2);
            //Console.WriteLine("test2Name: " + test2Name);

            //test2 = "System.Data.Entity.DbSet`1";
            //test2Name = Cecil2ModelMate.DetermineArchiMateObjectType(test2).ToString();
            //Console.WriteLine("test2: " + test2);
            //Console.WriteLine("test2Name: " + test2Name);

            //string test3 = "System.Data.Entity.Infrastructure.Interception.MutableInterceptionContext`1<TResult>";
            //string test3Namespace = Cecil2ModelMate.GetNamespaceFromFQName(test3);
            //string test3Name = Cecil2ModelMate.DetermineArchiMateInterfaceType(test3).ToString();
            //Console.WriteLine("test3: " + test3);
            //Console.WriteLine("test3Namespace: " + test3Namespace);
            //Console.WriteLine("test3Name: " + test3Name);

            //test3 = "System.Data";
            //test3Namespace = Cecil2ModelMate.GetNamespaceFromFQName(test3);
            //test3Name = Cecil2ModelMate.DetermineArchiMateInterfaceType(test3).ToString();
            //Console.WriteLine("test3: " + test3);
            //Console.WriteLine("test3Namespace: " + test3Namespace);
            //Console.WriteLine("test3Name: " + test3Name);

            //test3 = "System";
            //test3Namespace = Cecil2ModelMate.GetNamespaceFromFQName(test3);
            //test3Name = Cecil2ModelMate.DetermineArchiMateInterfaceType(test3).ToString();
            //Console.WriteLine("test3: " + test3);
            //Console.WriteLine("test3Namespace: " + test3Namespace);
            //Console.WriteLine("test3Name: " + test3Name);

            //test3 = "S";
            //test3Namespace = Cecil2ModelMate.GetNamespaceFromFQName(test3);
            //test3Name = Cecil2ModelMate.DetermineArchiMateInterfaceType(test3).ToString();
            //Console.WriteLine("test3: " + test3);
            //Console.WriteLine("test3Namespace: " + test3Namespace);
            //Console.WriteLine("test3Name: " + test3Name);

            //test3 = "";
            //test3Namespace = Cecil2ModelMate.GetNamespaceFromFQName(test3);
            //test3Name = Cecil2ModelMate.DetermineArchiMateInterfaceType(test3).ToString();
            //Console.WriteLine("test3: " + test3);
            //Console.WriteLine("test3Namespace: " + test3Namespace);
            //Console.WriteLine("test3Name: " + test3Name);

            model mSource = Cecil2ModelMate.Migrate2ModelMate(tSourceName, mSourceName, di);

            Console.WriteLine("Press enter to exit...");
            Console.ReadLine();

            using (var ctxTarget = new ModelMateEFModel9Context())
            {
                //var oldLog = ctxTarget.Database.Log;
                //ctxTarget.Database.Log = Console.Write;

                Console.WriteLine("propertydefs.Count: " + ctxTarget.propertydefs.Local.Count().ToString());

                ModelMigrator.PreloadAllTables(ctxTarget);

                var tTarget = ModelFinder.FindTenant(ctxTarget, null, tTargetName);
                //var tenants = ModelFinder.FindTenants(ctxTarget, null, tnameTest);
                //var tenant = tenants.ElementAt<tenant>(0);
                Console.WriteLine("tenant.identifier: " + tTarget.identifier);

                folders fs0 = tTarget.folders.ElementAt(0);
                ModelDump.DisplayDBPropertyValues("fs0", ctxTarget.Entry(fs0).CurrentValues, null);
                folder f0 = fs0.folder.ElementAt(0);
                ModelDump.DisplayDBPropertyValues("f0", ctxTarget.Entry(f0).CurrentValues, null);

                var models  = ModelFinder.FindModels(ctxTarget, tTarget, null, mTargetName);
                var mTarget = models.ElementAt <model>(0);
                Console.WriteLine("model.identifier: " + mTarget.identifier);
                var model0 = ModelFinder.FindModel(ctxTarget, tTarget, null, mTargetName);
                Console.WriteLine("model0.identifier: " + model0.identifier);

                ModelMigrator.MigrateModel(ctxTarget, tTarget, f0,
                                           mSource, PCOOperation.merge, PCOOperation.merge, true);

                string  modelSchemaFile = @"..\..\..\PSN.ModelMate.Schema\Schema\ModelMateModel9.xsd";
                DataSet dsModel         = new DataSet();
                dsModel.ReadXmlSchema(modelSchemaFile);
                var mmpModel = new ModelProcessor(ModelProcessor.ConvertModel2AMEFFDataSet);
                mmpModel.ProcessModel(dsModel, (DbContext)ctxTarget, new Collection <model> {
                    model0
                });
                //dsModel.WriteXml("model0ds.xml", XmlWriteMode.IgnoreSchema);
                string filename = "model8archi.xml";
                mmpModel.SaveAMEFFDataSetAsXML(dsModel, filename);

                //ctxTarget.Database.Log = oldLog;
                ctxTarget.SaveChanges();
            }

            Console.WriteLine("Press enter to exit...");
            Console.ReadLine();
        }
Пример #14
0
        static void Main(string[] args)
        {
            const string tTargetName       = "Tenant 2 Test";
            string       tTargetIdentifier = Util.MakeIdentifierRootIdentifier(typeof(tenant).Name, Util.TrimWhitespace(tTargetName));

            const string mTargetName       = "Model 2 Test";
            string       mTargetIdentifier = Util.MakeIdentifierFromParentIdentifier(
                Util.MakeIdentifierRootIdentifier(typeof(tenant).Name, tTargetName),
                typeof(model).Name, Util.TrimWhitespace(mTargetName));

            tenant tTarget = null;
            model  mTarget = null;

            using (var ctxTarget = new ModelMateEFModel9Context())
            {
                ctxTarget.Database.Log = Console.Write;
                Console.WriteLine("LazyLoadingEnabled: " + ctxTarget.Configuration.LazyLoadingEnabled.ToString());

                tTarget = ModelFinder.FindTenant(ctxTarget, tTargetIdentifier, "");
                ModelDump.DisplayDBPropertyValues("tTarget", ctxTarget.Entry(tTarget).CurrentValues, null);

                mTarget = ModelFinder.FindModel(ctxTarget, tTarget, mTargetIdentifier, null);
                ModelDump.DisplayDBPropertyValues("mTarget", ctxTarget.Entry(mTarget).CurrentValues, null);

                element[] es0 = ModelFinder.FindElements(ctxTarget, tTarget, mTarget, ModelConst.ElementType.ApplicationComponent);
                Console.WriteLine("es0.Count: " + es0.Count <element>().ToString());
                ModelDump.DisplayDBPropertyValues("es0", ctxTarget.Entry(es0[0]).CurrentValues, null);

                es0 = ModelFinder.FindElements(ctxTarget, tTarget, mTarget, ModelConst.ElementType.AllElementTypes);
                Console.WriteLine("es0.Count: " + es0.Count <element>().ToString());
                ModelDump.DisplayDBPropertyValues("es0", ctxTarget.Entry(es0[0]).CurrentValues, null);

                relationship[] rs0 = ModelFinder.FindRelationships(ctxTarget, tTarget, mTarget, ModelConst.RelationshipType.AllRelationshipTypes);
                Console.WriteLine("es0.Count: " + es0.Count <element>().ToString());
                ModelDump.DisplayDBPropertyValues("es0", ctxTarget.Entry(es0[0]).CurrentValues, null);

                foreach (relationship r in rs0)
                {
                    element eSource = ModelFinder.FindElement(ctxTarget, tTarget, mTarget, r.source, null);
                    element eTarget = ModelFinder.FindElement(ctxTarget, tTarget, mTarget, r.target, null);
                    ModelDump.DisplayDBPropertyValues("eSource", ctxTarget.Entry(eSource).CurrentValues, null);
                    ModelDump.DisplayDBPropertyValues("r", ctxTarget.Entry(r).CurrentValues, null);
                    ModelDump.DisplayDBPropertyValues("eTarget", ctxTarget.Entry(eTarget).CurrentValues, null);
                }
            }

            Console.WriteLine("Press enter to exit...");
            Console.ReadLine();

            string tSourceName = "Tenant 2";

            ModelFactory.TenantName = tSourceName;

            string mSourceIdentifier = mTargetIdentifier;
            string mSourceName       = mTargetName; // "Model 2 " + DateTime.Now.ToString();

            ModelFactory.ModelName = mSourceName;

            tenant tSource = null;
            model  mSource = null;

            propertydef pdef1 = ModelFactory.NewPropertyDef("String Propertydef 1", ModelConst.PropertyDataType.stringType);
            propertydef pdef2 = ModelFactory.NewPropertyDef("Boolean Propertydef 2", ModelConst.PropertyDataType.booleanType);
            propertydef pdef3 = ModelFactory.NewPropertyDef("Number Propertydef 3", ModelConst.PropertyDataType.numberType);

            propertydef[] pdfArray = new propertydef[] { pdef1, pdef2, pdef3 };
            propertydefs  pdefs    = ModelFactory.NewPropertyDefs(pdfArray);

            ModelConst.ElementType etAC = ModelConst.ElementType.ApplicationComponent;
            element[] elementArray      = new element[10];
            for (int iElement = 0; iElement < 10; iElement++)
            {
                property p1 = ModelFactory.NewProperty(ModelFactory.NewValue("Element Property Value " + DateTime.Now.ToString()),
                                                       pdfArray[iElement % 3]);
                property p2 = ModelFactory.NewProperty(ModelFactory.NewValue("Element Property Value " + DateTime.Now.ToString()),
                                                       pdfArray[(iElement + 1) % 3]);
                properties ps = ModelFactory.NewProperties(new property[] { p1, p2 });
                elementArray[iElement] = ModelFactory.NewElement("Element " + iElement.ToString(), etAC, ps);
            }
            elements elements = ModelFactory.NewElements(elementArray);

            tSource = ModelFactory.NewTenant(tSourceName,
                                             ModelFactory.NewFolder("/",
                                                                    mSource = ModelFactory.NewModel(mSourceName, ModelConst.LANG_EN,
                                                                                                    elements, pdefs
                                                                                                    )
                                                                    )
                                             );

            mSource.version = "9.0";

            var properties = ModelFactory.NewProperties(ModelFactory.NewProperty(ModelFactory.NewValue("Model 2 Value 1"), pdef1));

            mSource.properties.Add(properties);

            //var name = ModelFactory.NewName("Model 2 Name " + DateTime.Now.ToString());
            //model3.name.Add(name);

            var relationship1 = ModelFactory.NewRelationship("Association Relationship 1",
                                                             ModelConst.RelationshipType.AssociationRelationship,
                                                             elementArray[0], elementArray[1]
                                                             );
            var relationship2 = ModelFactory.NewRelationship("Association Relationship 2",
                                                             ModelConst.RelationshipType.AssociationRelationship,
                                                             elementArray[2], elementArray[3]
                                                             );
            var relationships = ModelFactory.NewRelationships(new relationship[] { relationship1, relationship2 });

            mSource.relationships.Add(relationships);

            Console.WriteLine("Press enter to exit...");
            Console.ReadLine();

            //var organization = ModelFactory.NewOrganization(
            //            ModelFactory.NewItem(elementArray[0],
            //                ModelFactory.NewItem(null,
            //                    ModelFactory.NewItem(elementArray[1]
            //                    )
            //                )
            //            )
            //       );
            //model3.organization.Add(organization);

            //var documentation = ModelFactory.NewDocumentation("Model 2 Documentation " + DateTime.Now.ToString());
            //model3.documentation.Add(documentation);

            //var metadata = ModelFactory.NewMetadata(
            //            ModelFactory.NewProperty(ModelFactory.NewValue("Model 2 Metadata Value " + DateTime.Now.ToString()), pdefString)
            //        );
            //model3.metadata.Add(metadata);

            //var style1 = ModelFactory.NewStyle(
            //                ModelFactory.NewFillColor(255, 0, 0),
            //                ModelFactory.NewLineColor(0, 255, 0),
            //                ModelFactory.NewFont("Times Roman", (float)10.5, "bold", ModelFactory.NewColor(0, 0, 255)), 3
            //            );
            //var style2 = ModelFactory.NewStyle(
            //    ModelFactory.NewFillColor(255, 0, 0),
            //    ModelFactory.NewLineColor(0, 255, 0),
            //    ModelFactory.NewFont("Times Roman", (float)12.5, "bold", ModelFactory.NewColor(0, 0, 255)), 3
            //);

            //var node0 = ModelFactory.NewNode("Node 0 " + DateTime.Now.ToString(),
            //                            0, 0, 0, 50, 50, 50,
            //                            elementArray[0], null, null, style1,
            //                            new node[] { ModelFactory.NewNode("Sub Node " + DateTime.Now.ToString(),
            //                                            10, 10, 10, 25, 25, 25,
            //                                            elementArray[3])
            //                            }
            //            );
            //var node1 = ModelFactory.NewNode("Node 1 " + DateTime.Now.ToString(),
            //                            100, 100, 100, 50, 50, 50,
            //                            elementArray[1], null, null, style2,
            //                            null
            //            );

            //var bendpoint1 = ModelFactory.NewBendPoint(25, 25, 25);
            //var connection1 = ModelFactory.NewConnection("Connection 1 " + DateTime.Now.ToString(),
            //                    node0, node1, relationship1
            //                  );
            //connection1.bendpoint.Add(bendpoint1);

            //view view2;
            //var views = ModelFactory.NewViews(
            //                view2 = ModelFactory.NewView("View 2 " + DateTime.Now.ToString(), ModelConst.ViewType.Layered,
            //                    new node[] {
            //                        node0, node1
            //                    },
            //                    new connection[] { connection1 }
            //                )
            //            );
            //model2.views.Add(views);

            //tenant2.processinghistory.Add(
            //ModelFactory.NewProcessinghistory(
            //    ModelFactory.NewTimesnap(DateTime.Now, "Timesnap Processinghistory " + DateTime.Now.ToString(),
            //        ModelConst.TimesnapCategory.processinghistory, "Subcategory " + DateTime.Now.ToString(),
            //        null, null,
            //        ModelFactory.NewProperty(ModelFactory.NewValue("Value " + DateTime.Now.ToString()), pdefString
            //        )
            //    )
            //)
            //);
            //tenant2.usage.Add(
            //            ModelFactory.NewUsage(
            //                ModelFactory.NewTimesnap(DateTime.Now, "Timesnap Performance " + DateTime.Now.ToString(),
            //                    ModelConst.TimesnapCategory.usage, "Subcategory " + DateTime.Now.ToString(),
            //                    null, null,
            //                    ModelFactory.NewProperty(ModelFactory.NewValue("Value " + DateTime.Now.ToString()), pdefString
            //                    )
            //                )
            //            )
            //            );
            //tenant2.performance.Add(
            //            ModelFactory.NewPerformance(
            //                ModelFactory.NewTimesnap(DateTime.Now, "Timesnap Performance " + DateTime.Now.ToString(),
            //                    ModelConst.TimesnapCategory.performance, "Subcategory " + DateTime.Now.ToString(),
            //                    null, null,
            //                    ModelFactory.NewProperty(ModelFactory.NewValue("Value " + DateTime.Now.ToString()), pdefString
            //                    )
            //                )
            //            )
            //            );
            //tenant2.management.Add(
            //            ModelFactory.NewManagement(
            //                ModelFactory.NewTimesnap(DateTime.Now, "Timesnap Management " + DateTime.Now.ToString(),
            //                    ModelConst.TimesnapCategory.management, "Subcategory " + DateTime.Now.ToString(),
            //                    null, null,
            //                    ModelFactory.NewProperty(ModelFactory.NewValue("Value " + DateTime.Now.ToString()), pdefString
            //                    )
            //                )
            //            )
            //            );

            //model2.processinghistory.Add(
            //            ModelFactory.NewProcessinghistory(
            //                ModelFactory.NewTimesnap(DateTime.Now, "Timesnap Processinghistory " + DateTime.Now.ToString(),
            //                    ModelConst.TimesnapCategory.processinghistory, "Subcategory " + DateTime.Now.ToString(),
            //                    null, null,
            //                    ModelFactory.NewProperty(ModelFactory.NewValue("Value " + DateTime.Now.ToString()), pdefString
            //                    )
            //                )
            //            )
            //            );
            //model2.usage.Add(
            //            ModelFactory.NewUsage(
            //                ModelFactory.NewTimesnap(DateTime.Now, "Timesnap Performance " + DateTime.Now.ToString(),
            //                    ModelConst.TimesnapCategory.usage, "Subcategory " + DateTime.Now.ToString(),
            //                    null, null,
            //                    ModelFactory.NewProperty(ModelFactory.NewValue("Value " + DateTime.Now.ToString()), pdefString
            //                    )
            //                )
            //            )
            //            );
            //model2.performance.Add(
            //            ModelFactory.NewPerformance(
            //                ModelFactory.NewTimesnap(DateTime.Now, "Timesnap Performance " + DateTime.Now.ToString(),
            //                    ModelConst.TimesnapCategory.performance, "Subcategory " + DateTime.Now.ToString(),
            //                    null, null,
            //                    ModelFactory.NewProperty(ModelFactory.NewValue("Value " + DateTime.Now.ToString()), pdefString
            //                    )
            //                )
            //            )
            //            );
            //model2.management.Add(
            //            ModelFactory.NewManagement(
            //                ModelFactory.NewTimesnap(DateTime.Now, "Timesnap Management " + DateTime.Now.ToString(),
            //                    ModelConst.TimesnapCategory.management, "Subcategory " + DateTime.Now.ToString(),
            //                    null, null,
            //                    ModelFactory.NewProperty(ModelFactory.NewValue("Value " + DateTime.Now.ToString()), pdefString
            //                    )
            //                )
            //            )
            //            );

            //elementArray[0].processinghistory.Add(
            //ModelFactory.NewProcessinghistory(
            //    ModelFactory.NewTimesnap(DateTime.Now, "Timesnap Processinghistory " + DateTime.Now.ToString(),
            //        ModelConst.TimesnapCategory.processinghistory, "Subcategory " + DateTime.Now.ToString(),
            //        null, null,
            //        ModelFactory.NewProperty(ModelFactory.NewValue("Value " + DateTime.Now.ToString()), pdefString
            //        )
            //    )
            //)
            //);
            //elementArray[0].usage.Add(
            //            ModelFactory.NewUsage(
            //                ModelFactory.NewTimesnap(DateTime.Now, "Timesnap Performance " + DateTime.Now.ToString(),
            //                    ModelConst.TimesnapCategory.usage, "Subcategory " + DateTime.Now.ToString(),
            //                    null, null,
            //                    ModelFactory.NewProperty(ModelFactory.NewValue("Value " + DateTime.Now.ToString()), pdefString
            //                    )
            //                )
            //            )
            //            );
            //elementArray[0].performance.Add(
            //            ModelFactory.NewPerformance(
            //                ModelFactory.NewTimesnap(DateTime.Now, "Timesnap Performance " + DateTime.Now.ToString(),
            //                    ModelConst.TimesnapCategory.performance, "Subcategory " + DateTime.Now.ToString(),
            //                    null, null,
            //                    ModelFactory.NewProperty(ModelFactory.NewValue("Value " + DateTime.Now.ToString()), pdefString
            //                    )
            //                )
            //            )
            //            );
            //elementArray[0].management.Add(
            //            ModelFactory.NewManagement(
            //                ModelFactory.NewTimesnap(DateTime.Now, "Timesnap Management " + DateTime.Now.ToString(),
            //                    ModelConst.TimesnapCategory.management, "Subcategory " + DateTime.Now.ToString(),
            //                    null, null,
            //                    ModelFactory.NewProperty(ModelFactory.NewValue("Value " + DateTime.Now.ToString()), pdefString
            //                    )
            //                )
            //            )
            //            );

            //view2.processinghistory.Add(
            //            ModelFactory.NewProcessinghistory(
            //                ModelFactory.NewTimesnap(DateTime.Now, "Timesnap Processinghistory " + DateTime.Now.ToString(),
            //                    ModelConst.TimesnapCategory.processinghistory, "Subcategory " + DateTime.Now.ToString(),
            //                    null, null,
            //                    ModelFactory.NewProperty(ModelFactory.NewValue("Value " + DateTime.Now.ToString()), pdefString
            //                    )
            //                )
            //            )
            //            );
            //view2.usage.Add(
            //            ModelFactory.NewUsage(
            //                ModelFactory.NewTimesnap(DateTime.Now, "Timesnap Performance " + DateTime.Now.ToString(),
            //                    ModelConst.TimesnapCategory.usage, "Subcategory " + DateTime.Now.ToString(),
            //                    null, null,
            //                    ModelFactory.NewProperty(ModelFactory.NewValue("Value " + DateTime.Now.ToString()), pdefString
            //                    )
            //                )
            //            )
            //            );
            //view2.performance.Add(
            //            ModelFactory.NewPerformance(
            //                ModelFactory.NewTimesnap(DateTime.Now, "Timesnap Performance " + DateTime.Now.ToString(),
            //                    ModelConst.TimesnapCategory.performance, "Subcategory " + DateTime.Now.ToString(),
            //                    null, null,
            //                    ModelFactory.NewProperty(ModelFactory.NewValue("Value " + DateTime.Now.ToString()), pdefString
            //                    )
            //                )
            //            )
            //            );
            //view2.management.Add(
            //            ModelFactory.NewManagement(
            //                ModelFactory.NewTimesnap(DateTime.Now, "Timesnap Management " + DateTime.Now.ToString(),
            //                    ModelConst.TimesnapCategory.management, "Subcategory " + DateTime.Now.ToString(),
            //                    null, null,
            //                    ModelFactory.NewProperty(ModelFactory.NewValue("Value " + DateTime.Now.ToString()), pdefString
            //                    )
            //                )
            //            )
            //            );

            using (var ctxTarget = new ModelMateEFModel9Context())
            {
                ctxTarget.Database.Log = Console.Write;

                tTarget = ModelFinder.FindTenant(ctxTarget, tTargetIdentifier, "");
                ModelDump.DisplayDBPropertyValues("tTarget", ctxTarget.Entry(tTarget).CurrentValues, null);

                folders fs0 = tTarget.folders.ElementAt(0);
                ModelDump.DisplayDBPropertyValues("fs0", ctxTarget.Entry(fs0).CurrentValues, null);
                folder f0 = fs0.folder.ElementAt(0);
                ModelDump.DisplayDBPropertyValues("f0", ctxTarget.Entry(f0).CurrentValues, null);

                mTarget = ModelFinder.FindModel(ctxTarget, tTarget, mTargetIdentifier, null);
                ModelDump.DisplayDBPropertyValues("mTarget", ctxTarget.Entry(mTarget).CurrentValues, null);

                ModelMigrator.MigrateModel(ctxTarget, tTarget, f0,
                                           mSource, PCOOperation.merge, PCOOperation.merge, true);
            }

            Console.WriteLine("Press enter to exist...");
            Console.ReadLine();
        }