Exemplo n.º 1
0
        ///--------------------------------------------------------------------------------
        /// <summary>This method applies solution deletes.</summary>
        ///--------------------------------------------------------------------------------
        public void ProcessDeleteSolutionPerformed(SolutionEventArgs data)
        {
            try
            {
                bool isItemMatch = false;
                if (data != null && data.Solution != null)
                {
                    foreach (SolutionViewModel item in Solutions.ToList <SolutionViewModel>())
                    {
                        if (item.Solution.SolutionID == data.Solution.SolutionID)
                        {
                            // remove item from tabs, if present
                            WorkspaceEventArgs message = new WorkspaceEventArgs();
                            message.ItemID = item.Solution.SolutionID;
                            Mediator.NotifyColleagues <WorkspaceEventArgs>(MediatorMessages.Command_CloseItemRequested, message);

                            // delete children
                            for (int i = item.Items.Count - 1; i >= 0; i--)
                            {
                                if (item.Items[i] is ViewViewModel)
                                {
                                    ViewViewModel child        = item.Items[i] as ViewViewModel;
                                    ViewEventArgs childMessage = new ViewEventArgs();
                                    childMessage.View        = child.View;
                                    childMessage.SolutionID  = item.Solution.SolutionID;
                                    childMessage.Solution    = Solution;
                                    childMessage.WorkspaceID = child.WorkspaceID;
                                    item.ViewsFolder.ProcessDeleteViewPerformed(childMessage);
                                }
                                if (item.Items[i] is DatabaseSourceViewModel)
                                {
                                    DatabaseSourceViewModel child        = item.Items[i] as DatabaseSourceViewModel;
                                    DatabaseSourceEventArgs childMessage = new DatabaseSourceEventArgs();
                                    childMessage.DatabaseSource = child.DatabaseSource;
                                    childMessage.SolutionID     = item.Solution.SolutionID;
                                    childMessage.Solution       = Solution;
                                    childMessage.WorkspaceID    = child.WorkspaceID;
                                    item.SpecificationSourcesFolder.ProcessDeleteDatabaseSourcePerformed(childMessage);
                                }
                                if (item.Items[i] is XmlSourceViewModel)
                                {
                                    XmlSourceViewModel child        = item.Items[i] as XmlSourceViewModel;
                                    XmlSourceEventArgs childMessage = new XmlSourceEventArgs();
                                    childMessage.XmlSource   = child.XmlSource;
                                    childMessage.SolutionID  = item.Solution.SolutionID;
                                    childMessage.Solution    = Solution;
                                    childMessage.WorkspaceID = child.WorkspaceID;
                                    item.SpecificationSourcesFolder.ProcessDeleteXmlSourcePerformed(childMessage);
                                }
                                if (item.Items[i] is ProjectViewModel)
                                {
                                    ProjectViewModel child        = item.Items[i] as ProjectViewModel;
                                    ProjectEventArgs childMessage = new ProjectEventArgs();
                                    childMessage.Project     = child.Project;
                                    childMessage.SolutionID  = item.Solution.SolutionID;
                                    childMessage.Solution    = Solution;
                                    childMessage.WorkspaceID = child.WorkspaceID;
                                    item.ProjectsFolder.ProcessDeleteProjectPerformed(childMessage);
                                }
                                if (item.Items[i] is FeatureViewModel)
                                {
                                    FeatureViewModel child        = item.Items[i] as FeatureViewModel;
                                    FeatureEventArgs childMessage = new FeatureEventArgs();
                                    childMessage.Feature     = child.Feature;
                                    childMessage.SolutionID  = item.Solution.SolutionID;
                                    childMessage.Solution    = Solution;
                                    childMessage.WorkspaceID = child.WorkspaceID;
                                    item.FeaturesFolder.ProcessDeleteFeaturePerformed(childMessage);
                                }
                                if (item.Items[i] is WorkflowViewModel)
                                {
                                    WorkflowViewModel child        = item.Items[i] as WorkflowViewModel;
                                    WorkflowEventArgs childMessage = new WorkflowEventArgs();
                                    childMessage.Workflow    = child.Workflow;
                                    childMessage.SolutionID  = item.Solution.SolutionID;
                                    childMessage.Solution    = Solution;
                                    childMessage.WorkspaceID = child.WorkspaceID;
                                    item.WorkflowsFolder.ProcessDeleteWorkflowPerformed(childMessage);
                                }
                                if (item.Items[i] is ModelViewModel)
                                {
                                    ModelViewModel child        = item.Items[i] as ModelViewModel;
                                    ModelEventArgs childMessage = new ModelEventArgs();
                                    childMessage.Model       = child.Model;
                                    childMessage.SolutionID  = item.Solution.SolutionID;
                                    childMessage.Solution    = Solution;
                                    childMessage.WorkspaceID = child.WorkspaceID;
                                    item.ModelsFolder.ProcessDeleteModelPerformed(childMessage);
                                }
                                if (item.Items[i] is DiagramViewModel)
                                {
                                    DiagramViewModel child        = item.Items[i] as DiagramViewModel;
                                    DiagramEventArgs childMessage = new DiagramEventArgs();
                                    childMessage.Diagram     = child.Diagram;
                                    childMessage.SolutionID  = item.Solution.SolutionID;
                                    childMessage.Solution    = Solution;
                                    childMessage.WorkspaceID = child.WorkspaceID;
                                    item.DiagramsFolder.ProcessDeleteDiagramPerformed(childMessage);
                                }
                                if (item.Items[i] is AuditPropertyViewModel)
                                {
                                    AuditPropertyViewModel child        = item.Items[i] as AuditPropertyViewModel;
                                    AuditPropertyEventArgs childMessage = new AuditPropertyEventArgs();
                                    childMessage.AuditProperty = child.AuditProperty;
                                    childMessage.SolutionID    = item.Solution.SolutionID;
                                    childMessage.Solution      = Solution;
                                    childMessage.WorkspaceID   = child.WorkspaceID;
                                    item.AuditPropertiesFolder.ProcessDeleteAuditPropertyPerformed(childMessage);
                                }
                                if (item.Items[i] is SpecTemplateViewModel)
                                {
                                    SpecTemplateViewModel child        = item.Items[i] as SpecTemplateViewModel;
                                    SpecTemplateEventArgs childMessage = new SpecTemplateEventArgs();
                                    childMessage.SpecTemplate = child.SpecTemplate;
                                    childMessage.SolutionID   = item.Solution.SolutionID;
                                    childMessage.Solution     = Solution;
                                    childMessage.WorkspaceID  = child.WorkspaceID;
                                    item.SpecTemplatesFolder.ProcessDeleteSpecTemplatePerformed(childMessage);
                                }
                                if (item.Items[i] is CodeTemplateViewModel)
                                {
                                    CodeTemplateViewModel child        = item.Items[i] as CodeTemplateViewModel;
                                    CodeTemplateEventArgs childMessage = new CodeTemplateEventArgs();
                                    childMessage.CodeTemplate = child.CodeTemplate;
                                    childMessage.SolutionID   = item.Solution.SolutionID;
                                    childMessage.Solution     = Solution;
                                    childMessage.WorkspaceID  = child.WorkspaceID;
                                    item.CodeTemplatesFolder.ProcessDeleteCodeTemplatePerformed(childMessage);
                                }
                            }

                            // delete item
                            isItemMatch = true;
                            Solutions.Remove(item);
                            Items.Remove(item);
                            OnUpdated(this, null);
                            break;
                        }
                    }
                    if (isItemMatch == false)
                    {
                        ShowIssue(DisplayValues.Issue_DeleteItemNotFound);
                    }
                }
            }
            catch (Exception ex)
            {
                ShowIssue(ex.Message + ex.StackTrace);
            }
        }
Exemplo n.º 2
0
        /* This tests creates a simple solution containing 1 feature and 1 entity (forward-engineered). There's 1
         * solution template, which iterates the entities and outputs a simple text file containing - featurename-entityname
         */
        protected override void DoExecute(string playground)
        {
            var solutionDesigner = new DesignerViewModel();
            var builder          = new BuilderViewModel();

            builder.ProcessNewCommand(builder.SolutionsFolder);
            var solutionVM = solutionDesigner.SelectedItem as SolutionViewModel;

            if (solutionVM == null)
            {
                throw new InvalidOperationException("Couldn't find SolutionViewModel");
            }
            solutionVM.SolutionName           = "TestSolution";
            solutionVM.Namespace              = "TestNamespace";
            solutionVM.OutputSolutionFileName = "TestSolution.sln";
            solutionVM.CompanyName            = "TestCompany";
            solutionVM.ProductName            = "TestProduct";
            solutionVM.ProductVersion         = "0.1";
            solutionVM.SolutionPath           = Path.Combine(playground, "TestSolution.xml");
            solutionVM.TemplatePath           = Path.Combine(playground, "SolutionFile.mpt");
            solutionVM.Update();
            var solution = solutionVM.Solution;

            if (solution == null)
            {
                throw new InvalidOperationException("Couldn't find Solution!");
            }
            solutionVM.UpdateCommand.Execute(null);
            solutionVM.SaveSolution();
            solutionVM.LoadSolution(solution, true);
            //solutionVM.Refresh(true, 3);
            if (solutionVM.CodeTemplatesFolder == null)
            {
                throw new InvalidOperationException("Couldn't find CodeTemplatesFolder");
            }
            solutionVM.CodeTemplatesFolder.ProcessNewCodeTemplateCommand();
            var newSolTpl        = new CodeTemplateViewModel();
            var solutionTemplate = solutionDesigner.SelectedItem as CodeTemplateViewModel ?? newSolTpl;

            Assert.AreNotSame(solutionTemplate, newSolTpl, "Couldn't find template!");

            solutionTemplate.TemplateName       = "SolutionFile";
            solutionTemplate.IsTopLevelTemplate = true;
            solutionTemplate.TemplateOutput     = "<%%=Solution.SolutionDirectory%%><%%-\\%%><%%=Solution.OutputSolutionFileName%%>\r\n" +
                                                  "<%%:\r\n" +
                                                  "    update(Path)\r\n" +
                                                  "%%>";
            solutionTemplate.TemplateContent = "<%%-Entities:\r\n" +
                                               "%%><%%:\r\n" +
                                               "foreach(Entity)\r\n" +
                                               "{\r\n" +
                                               "    <%%- - %%><%%=Feature.FeatureName%%><%%--%%><%%=Entity.EntityName%%><%%-\r\n" +
                                               "%%>\r\n" +
                                               "}%%>";
            solutionTemplate.Update();

            solutionVM.FeaturesFolder.ProcessNewFeatureCommand();

            var newFeature = new FeatureViewModel();
            var feature    = solutionDesigner.SelectedItem as FeatureViewModel ?? newFeature;

            Assert.AreNotSame(feature, newFeature, "Couldn't find feature!");

            feature.Solution    = solution;
            feature.FeatureName = "TestFeature";
            feature.UpdateCommand.Execute(null);
            solutionDesigner.ShowItemInTreeView(feature);


            feature.ProcessNewEntityCommand();

            var newEntity = new EntityViewModel();
            var entity    = solutionDesigner.SelectedItem as EntityViewModel ?? newEntity;

            Assert.AreNotSame(entity, newEntity, "Couldn't find entity!");

            entity.EntityName         = "TestEntity";
            entity.EntityTypeCode     = 3; // primary
            entity.IdentifierTypeCode = 1; // generated
            entity.Update();
            entity.LoadEntity(entity.Entity);

            entity.PropertiesFolder.ProcessNewPropertyCommand();

            var newProperty = new PropertyViewModel();
            var property    = solutionDesigner.SelectedItem as PropertyViewModel ?? newProperty;

            Assert.AreNotSame(property, newProperty, "Couldn't find Property!");

            solutionVM.UpdateCommand.Execute(null);
            solutionVM.SaveSolution();
            using (var resetEvent = new AutoResetEvent(false))
            {
                var updated = new EventHandler((sender, args) =>
                {
                    Console.WriteLine("Solution updated!");
                    resetEvent.Set();
                });
                solutionVM.Updated += updated;
                solutionVM.UpdateOutputSolution();
                Assert.IsTrue(resetEvent.WaitOne(EventWaitTimeout), "Timeout waiting for solution update!");
                solutionVM.Updated -= updated;
            }
            var expectedOutput = "Entities:\r\n" +
                                 " - TestFeature-TestEntity\r\n";
            var output = File.ReadAllText(Path.Combine(playground, "TestSolution.sln"));

            Assert.AreEqual(expectedOutput, output);
        }
        protected override void DoExecute(string playground)
        {
            TestLocaldb.Execute("sqllocaldb.exe", "stop v11.0");
            TestLocaldb.Execute("sqllocaldb.exe", "start v11.0");

            var dbName = "Northwind-" + Guid.NewGuid();

            mDatabaseFileName    = Path.Combine(playground, dbName + ".mdf");
            mDatabaseLogFileName = Path.Combine(playground, dbName + "_log.ldf");
            mTemplatesPath       = Path.Combine(playground, "Templates");

            // setup database
            NorthwindUtility.Create(dbName, mDatabaseFileName, mDatabaseLogFileName);
            var gettingStartedPath = Path.Combine(playground, "GettingStartedPack");

            Directory.CreateDirectory(gettingStartedPath);

            // unpack sapmle pack to <Playground>\GettingStartedPack
            SamplePacksUtility.ExtractGettingStartedTo(gettingStartedPath);

            var solutionDesigner = new DesignerViewModel();
            var builder          = new BuilderViewModel();
            var solutionVM       = NewSolution(builder,
                                               solutionDesigner,
                                               "TestSolution",
                                               "TestNamespace",
                                               "TestSolution.sln",
                                               "TestCompany",
                                               "TestProduct",
                                               "0.1",
                                               Path.Combine(playground, "TestSolution.xml"),
                                               Path.Combine(playground, Path.Combine(playground, "NorthwindSolutionFile.mpt")));

            solutionVM.Solution.OutputRequested += SolutionOnOutputRequested;

            #region create solution template
            if (solutionVM.CodeTemplatesFolder == null)
            {
                throw new InvalidOperationException("Couldn't find CodeTemplatesFolder");
            }

            solutionVM.CodeTemplatesFolder.ProcessNewCodeTemplateCommand();
            var newSolTpl        = new CodeTemplateViewModel();
            var solutionTemplate = solutionDesigner.SelectedItem as CodeTemplateViewModel ?? newSolTpl;
            Assert.AreNotSame(solutionTemplate, newSolTpl, "Couldn't find template!");

            solutionTemplate.TemplateName       = "NorthwindSolutionFile";
            solutionTemplate.IsTopLevelTemplate = true;
            solutionTemplate.TemplateOutput     = "<%%=Solution.SolutionDirectory%%><%%-\\%%><%%=Solution.OutputSolutionFileName%%>\r\n" +
                                                  "<%%:\r\n" +
                                                  "    update(Path)\r\n" +
                                                  "%%>";
            solutionTemplate.TemplateContent = "<%%-Entities:\r\n" +
                                               "%%><%%:\r\n" +
                                               "foreach(Entity)\r\n" +
                                               "{\r\n" +
                                               "    <%%- - %%><%%=Feature.FeatureName%%><%%--%%><%%=Entity.EntityName%%><%%-\r\n" +
                                               "%%>\r\n" +
                                               "}%%>";
            solutionTemplate.Update();
            solutionVM.TemplatePath = Path.Combine(playground, Path.Combine(playground, "NorthwindSolutionFile.mpt"));
            SaveSolution(solutionVM);
            solutionVM.CodeTemplatesFolder.LoadTemplates(solutionVM.Solution);

            #endregion create solution template

            NewDatabaseSource(builder,
                              solutionDesigner,
                              solutionVM,
                              @"(localdb)\v11.0",
                              mDatabaseFileName,
                              Path.Combine(gettingStartedPath, @"GettingStarted\Specifications\SQLServer\MDLSqlModel.mps"));

            BuildSolution(solutionVM);

            UpdateOutputSolution(solutionVM);

            var expectedOutput = "Entities:\r\n" +
                                 " - Domain-Category\r\n" +
                                 " - Domain-CustomerCustomerDemo\r\n" +
                                 " - Domain-CustomerDemographic\r\n" +
                                 " - Domain-Customer\r\n" +
                                 " - Domain-Employee\r\n" +
                                 " - Domain-EmployeeTerritory\r\n" +
                                 " - Domain-OrderDetail\r\n" +
                                 " - Domain-Order\r\n" +
                                 " - Domain-Product\r\n" +
                                 " - Domain-Region\r\n" +
                                 " - Domain-Shipper\r\n" +
                                 " - Domain-Supplier\r\n" +
                                 " - Domain-Territory\r\n";
            var output = File.ReadAllText(Path.Combine(playground, "TestSolution.sln"));
            Assert.AreEqual(expectedOutput, output);
        }