public void NewDatabaseSource(BuilderViewModel builder, DesignerViewModel designer, SolutionViewModel solutionVM, string serverName, string databaseName, string templatePath)
        {
            solutionVM.SpecificationSourcesFolder.ProcessNewDatabaseSourceCommand();

            var newDBSource = new DatabaseSourceViewModel();
            var dbSource    = designer.SelectedItem as DatabaseSourceViewModel ?? newDBSource;

            Assert.AreNotSame(dbSource, newDBSource, "Couldn't find database source");
            dbSource.DatabaseTypeCode   = (int)DatabaseTypeCode.SqlServer;
            dbSource.SourceDbServerName = serverName;
            dbSource.SourceDbName       = databaseName;
            dbSource.TemplatePath       = templatePath;
            Assert.IsTrue(File.Exists(dbSource.TemplatePath), "Solution template not found!");
            dbSource.Order = 1;

            dbSource.Update();
            solutionVM.Update();
            solutionVM.SpecTemplatesFolder.LoadSpecTemplates(solutionVM.Solution);
            SaveSolution(solutionVM);
        }
Пример #2
0
        ///--------------------------------------------------------------------------------
        /// <summary>This method handles dropping items onto the treeview.</summary>
        ///
        /// <param name="data">The data as a viewmodel.</param>
        ///--------------------------------------------------------------------------------
        protected void Paste(IWorkspaceViewModel data)
        {
            SolutionViewModel             solution;
            ProjectViewModel              assembly;
            DatabaseSourceViewModel       databaseSource;
            AuditPropertyViewModel        auditProperty;
            FeatureViewModel              feature;
            EntityViewModel               entity;
            CollectionViewModel           collectionProperty;
            PropertyReferenceViewModel    derivedProperty;
            PropertyViewModel             property;
            EntityReferenceViewModel      referenceProperty;
            MethodViewModel               method;
            ParameterViewModel            parameter;
            IndexViewModel                index;
            IndexPropertyViewModel        indexProperty;
            RelationshipViewModel         relationship;
            RelationshipPropertyViewModel relationshipProperty;

            if (data is ProjectViewModel)
            {
                // process assembly drop
                assembly = data as ProjectViewModel;
                solution = DataContext as SolutionViewModel;
                if (solution == null)
                {
                    // get parent solution
                    solution = ViewModelHelper.FindParentView <SolutionViewModel>(this);
                }
                if (solution == null)
                {
                    // invalid drop location
                    HandleInvalidDrop(assembly);
                }
                else if (solution.ProjectsFolder.Projects.Find("Name", assembly.Name) != null)
                {
                    // duplicate item found, cannot drop
                    if (assembly != DataContext as ProjectViewModel)
                    {
                        HandleDuplicateDrop(assembly);
                    }
                }
                else
                {
                    // do the drop
                    ProjectViewModel view = solution.ProjectsFolder.PasteProject(assembly, true);
                    view.ShowInTreeView();
                }
            }
            else if (data is DatabaseSourceViewModel)
            {
                // process databaseSource drop
                databaseSource = data as DatabaseSourceViewModel;
                solution       = DataContext as SolutionViewModel;
                if (solution == null)
                {
                    // get parent solution
                    solution = ViewModelHelper.FindParentView <SolutionViewModel>(this);
                }
                if (solution == null)
                {
                    // invalid drop location
                    HandleInvalidDrop(databaseSource);
                }
                else if (solution.SpecificationSourcesFolder.DatabaseSources.Find("Name", databaseSource.Name) != null)
                {
                    // duplicate item found, cannot drop
                    if (databaseSource != DataContext as DatabaseSourceViewModel)
                    {
                        HandleDuplicateDrop(databaseSource);
                    }
                }
                else
                {
                    // do the drop
                    DatabaseSourceViewModel view = solution.SpecificationSourcesFolder.PasteDatabaseSource(databaseSource, true);
                    view.ShowInTreeView();
                }
            }
            else if (data is AuditPropertyViewModel)
            {
                // process auditProperty drop
                auditProperty = data as AuditPropertyViewModel;
                solution      = DataContext as SolutionViewModel;
                if (solution == null)
                {
                    // get parent solution
                    solution = ViewModelHelper.FindParentView <SolutionViewModel>(this);
                }
                if (solution == null)
                {
                    // invalid drop location
                    HandleInvalidDrop(auditProperty);
                }
                else if (solution.AuditPropertiesFolder.AuditProperties.Find("Name", auditProperty.Name) != null)
                {
                    // duplicate item found, cannot drop
                    if (auditProperty != DataContext as AuditPropertyViewModel)
                    {
                        HandleDuplicateDrop(auditProperty);
                    }
                }
                else
                {
                    // do the drop
                    AuditPropertyViewModel view = solution.AuditPropertiesFolder.PasteAuditProperty(auditProperty, true);
                    view.ShowInTreeView();
                }
            }
            else if (data is FeatureViewModel)
            {
                // process feature drop
                feature  = data as FeatureViewModel;
                solution = DataContext as SolutionViewModel;
                if (solution == null)
                {
                    // get parent solution
                    solution = ViewModelHelper.FindParentView <SolutionViewModel>(this);
                }
                if (solution == null)
                {
                    // invalid drop location
                    HandleInvalidDrop(feature);
                }
                else if (solution.FeaturesFolder.Features.Find("Name", feature.Name) != null)
                {
                    // duplicate item found, cannot drop
                    if (feature != DataContext as FeatureViewModel)
                    {
                        HandleDuplicateDrop(feature);
                    }
                }
                else
                {
                    // do the drop
                    Mouse.OverrideCursor = Cursors.Wait;
                    FeatureViewModel view = solution.FeaturesFolder.PasteFeature(feature, true);
                    view.ShowInTreeView();
                    solution.Refresh(true);
                    Mouse.OverrideCursor = null;
                }
            }
            else if (data is EntityViewModel)
            {
                // process entity drop
                entity  = data as EntityViewModel;
                feature = DataContext as FeatureViewModel;
                if (feature == null)
                {
                    // get parent feature
                    feature = ViewModelHelper.FindParentView <FeatureViewModel>(this);
                }
                if (feature == null)
                {
                    // invalid drop location
                    HandleInvalidDrop(entity);
                }
                else if (feature.Entities.Find("Name", entity.Name) != null)
                {
                    // duplicate item found, cannot drop
                    if (entity != DataContext as EntityViewModel)
                    {
                        HandleDuplicateDrop(entity);
                    }
                }
                else
                {
                    // do the drop
                    Mouse.OverrideCursor = Cursors.Wait;
                    EntityViewModel view = feature.PasteEntity(entity, true);
                    view.ShowInTreeView();
                    solution = ViewModelHelper.FindParentView <SolutionViewModel>(this);
                    if (solution != null)
                    {
                        solution.Refresh(true);
                    }
                    Mouse.OverrideCursor = null;
                }
            }
            else if (data is CollectionViewModel)
            {
                // process collectionProperty drop
                collectionProperty = data as CollectionViewModel;
                entity             = DataContext as EntityViewModel;
                if (entity == null)
                {
                    // get parent entity
                    entity = ViewModelHelper.FindParentView <EntityViewModel>(this);
                }
                if (entity == null)
                {
                    // invalid drop location
                    HandleInvalidDrop(collectionProperty);
                }
                else if (entity.CollectionsFolder.Collections.Find("Name", collectionProperty.Name) != null)
                {
                    // duplicate item found, cannot drop
                    if (collectionProperty != DataContext as CollectionViewModel)
                    {
                        HandleDuplicateDrop(collectionProperty);
                    }
                }
                else
                {
                    // do the drop
                    CollectionViewModel view = entity.CollectionsFolder.PasteCollection(collectionProperty, true);
                    view.ShowInTreeView();
                }
            }
            else if (data is PropertyReferenceViewModel)
            {
                // process derivedProperty drop
                derivedProperty = data as PropertyReferenceViewModel;
                entity          = DataContext as EntityViewModel;
                if (entity == null)
                {
                    // get parent entity
                    entity = ViewModelHelper.FindParentView <EntityViewModel>(this);
                }
                if (entity == null)
                {
                    // invalid drop location
                    HandleInvalidDrop(derivedProperty);
                }
                else if (entity.PropertyReferencesFolder.PropertyReferences.Find("Name", derivedProperty.Name) != null)
                {
                    // duplicate item found, cannot drop
                    if (derivedProperty != DataContext as PropertyReferenceViewModel)
                    {
                        HandleDuplicateDrop(derivedProperty);
                    }
                }
                else
                {
                    // do the drop
                    PropertyReferenceViewModel view = entity.PropertyReferencesFolder.PastePropertyReference(derivedProperty, true);
                    view.ShowInTreeView();
                }
            }
            else if (data is PropertyViewModel)
            {
                // process property drop
                property = data as PropertyViewModel;
                entity   = DataContext as EntityViewModel;
                if (entity == null)
                {
                    // get parent entity
                    entity = ViewModelHelper.FindParentView <EntityViewModel>(this);
                }
                if (entity == null)
                {
                    // invalid drop location
                    HandleInvalidDrop(property);
                }
                else if (entity.PropertiesFolder.Properties.Find("Name", property.Name) != null)
                {
                    // duplicate item found, cannot drop
                    if (property != DataContext as PropertyViewModel)
                    {
                        HandleDuplicateDrop(property);
                    }
                }
                else
                {
                    // do the drop
                    PropertyViewModel view = entity.PropertiesFolder.PasteProperty(property, true);
                    solution = ViewModelHelper.FindParentView <SolutionViewModel>(this);
                    if (solution != null)
                    {
                        solution.Refresh(true);
                    }
                    view.ShowInTreeView();
                }
            }
            else if (data is EntityReferenceViewModel)
            {
                // process referenceProperty drop
                referenceProperty = data as EntityReferenceViewModel;
                entity            = DataContext as EntityViewModel;
                if (entity == null)
                {
                    // get parent entity
                    entity = ViewModelHelper.FindParentView <EntityViewModel>(this);
                }
                if (entity == null)
                {
                    // invalid drop location
                    HandleInvalidDrop(referenceProperty);
                }
                else if (entity.EntityReferencesFolder.EntityReferences.Find("Name", referenceProperty.Name) != null)
                {
                    // duplicate item found, cannot drop
                    if (referenceProperty != DataContext as EntityReferenceViewModel)
                    {
                        HandleDuplicateDrop(referenceProperty);
                    }
                }
                else
                {
                    // do the drop
                    EntityReferenceViewModel view = entity.EntityReferencesFolder.PasteEntityReference(referenceProperty, true);
                    view.ShowInTreeView();
                }
            }
            else if (data is MethodViewModel)
            {
                // process method drop
                method = data as MethodViewModel;
                entity = DataContext as EntityViewModel;
                if (entity == null)
                {
                    // get parent entity
                    entity = ViewModelHelper.FindParentView <EntityViewModel>(this);
                }
                if (entity == null)
                {
                    // invalid drop location
                    HandleInvalidDrop(method);
                }
                else if (entity.MethodsFolder.Methods.Find("Name", method.Name) != null)
                {
                    // duplicate item found, cannot drop
                    if (method != DataContext as MethodViewModel)
                    {
                        HandleDuplicateDrop(method);
                    }
                }
                else
                {
                    // do the drop
                    MethodViewModel view = entity.MethodsFolder.PasteMethod(method, true);
                    view.ShowInTreeView();
                }
            }
            else if (data is ParameterViewModel)
            {
                // process parameter drop
                parameter = data as ParameterViewModel;
                method    = DataContext as MethodViewModel;
                if (method == null)
                {
                    // get parent method
                    method = ViewModelHelper.FindParentView <MethodViewModel>(this);
                }
                if (method == null)
                {
                    // invalid drop location
                    HandleInvalidDrop(parameter);
                }
                else if (method.Parameters.Find("Name", parameter.Name) != null)
                {
                    // duplicate item found, cannot drop
                    if (parameter != DataContext as ParameterViewModel)
                    {
                        HandleDuplicateDrop(parameter);
                    }
                }
                else
                {
                    // do the drop
                    ParameterViewModel view = method.PasteParameter(parameter, true);
                    view.ShowInTreeView();
                }
            }
            else if (data is IndexViewModel)
            {
                // process index drop
                index  = data as IndexViewModel;
                entity = DataContext as EntityViewModel;
                if (entity == null)
                {
                    // get parent entity
                    entity = ViewModelHelper.FindParentView <EntityViewModel>(this);
                }
                if (entity == null)
                {
                    // invalid drop location
                    HandleInvalidDrop(index);
                }
                else if (entity.IndexesFolder.Indexes.Find("Name", index.Name) != null)
                {
                    // duplicate item found, cannot drop
                    if (index != DataContext as IndexViewModel)
                    {
                        HandleDuplicateDrop(index);
                    }
                }
                else
                {
                    // do the drop
                    IndexViewModel view = entity.IndexesFolder.PasteIndex(index, true);
                    view.ShowInTreeView();
                }
            }
            else if (data is IndexPropertyViewModel)
            {
                // process index drop
                indexProperty = data as IndexPropertyViewModel;
                index         = DataContext as IndexViewModel;
                if (index == null)
                {
                    // get parent index
                    index = ViewModelHelper.FindParentView <IndexViewModel>(this);
                }
                if (index == null)
                {
                    // invalid drop location
                    HandleInvalidDrop(indexProperty);
                }
                else if (index.IndexProperties.Find("Name", indexProperty.Name) != null)
                {
                    // duplicate item found, cannot drop
                    if (indexProperty != DataContext as IndexPropertyViewModel)
                    {
                        HandleDuplicateDrop(indexProperty);
                    }
                }
                else
                {
                    // do the drop
                    IndexPropertyViewModel view = index.PasteIndexProperty(indexProperty, true);
                    view.ShowInTreeView();
                }
            }
            else if (data is RelationshipViewModel)
            {
                // process relationship drop
                relationship = data as RelationshipViewModel;
                entity       = DataContext as EntityViewModel;
                if (entity == null)
                {
                    // get parent entity
                    entity = ViewModelHelper.FindParentView <EntityViewModel>(this);
                }
                if (entity == null)
                {
                    // invalid drop location
                    HandleInvalidDrop(relationship);
                }
                else if (entity.RelationshipsFolder.Relationships.Find("Name", relationship.Name) != null)
                {
                    // duplicate item found, cannot drop
                    if (relationship != DataContext as RelationshipViewModel)
                    {
                        HandleDuplicateDrop(relationship);
                    }
                }
                else
                {
                    // do the drop
                    RelationshipViewModel view = entity.RelationshipsFolder.PasteRelationship(relationship, true);
                    view.ShowInTreeView();
                }
            }
            else if (data is RelationshipPropertyViewModel)
            {
                // process relationshipProperty drop
                relationshipProperty = data as RelationshipPropertyViewModel;
                relationship         = DataContext as RelationshipViewModel;
                if (relationship == null)
                {
                    // get parent relationship
                    relationship = ViewModelHelper.FindParentView <RelationshipViewModel>(this);
                }
                if (relationship == null)
                {
                    // invalid drop location
                    HandleInvalidDrop(relationshipProperty);
                }
                else if (relationship.RelationshipProperties.Find("Name", relationshipProperty.Name) != null)
                {
                    // duplicate item found, cannot drop
                    if (relationshipProperty != DataContext as RelationshipPropertyViewModel)
                    {
                        HandleDuplicateDrop(relationshipProperty);
                    }
                }
                else
                {
                    // do the drop
                    RelationshipPropertyViewModel view = relationship.PasteRelationshipProperty(relationshipProperty, true);
                    view.ShowInTreeView();
                }
            }
        }