///-------------------------------------------------------------------------------- /// <summary>Create the instance with the designer view and other data.</summary> /// /// <param name="solutionDiagram">The solution diagram to load.</param> /// <param name="entities">The solution entities that could be added to the diagram.</param> /// <param name="solution">The associated solution.</param> /// <param name="loadChildren">Flag indicating if child information should be loaded.</param> ///-------------------------------------------------------------------------------- public DiagramViewModel(Diagram solutionDiagram, EnterpriseDataObjectList <EntityViewModel> entities, Solution solution, bool loadChildren = true) { Entities = new EnterpriseDataObjectList <EntityViewModel>(); if (entities != null) { foreach (EntityViewModel entity in entities) { if (loadChildren == true) { Entities.Add(new EntityViewModel(entity.Entity, solution, loadChildren)); } else { Entities.Add(entity); } } } else { foreach (Entity entity in solution.EntityList) { Entities.Add(new EntityViewModel(entity, solution, loadChildren)); } } WorkspaceID = Guid.NewGuid(); Solution = solution; DiagramEntities = new EnterpriseDataObjectList <DiagramEntityViewModel>(); DiagramRelationships = new EnterpriseDataObjectList <DiagramRelationshipViewModel>(); LoadDiagram(solutionDiagram); DiagramEntities.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(DiagramEntities_CollectionChanged); DiagramRelationships.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(DiagramRelationships_CollectionChanged); }
///-------------------------------------------------------------------------------- /// <summary>This method loads an item of ModelData into the view model.</summary> /// /// <param name="model">The Model to load.</param> /// <param name="solution">The Solution to load.</param> /// <param name="loadChildren">Flag indicating whether to perform a deeper load.</param> ///-------------------------------------------------------------------------------- public void LoadModelData(Model model, Solution solution, bool loadChildren = true) { // attach the model data Model = model; Solution = solution; ItemID = Model.ModelID; Items.Clear(); if (loadChildren == true) { // attach ModelObjectDataItems if (ModelObjectDataItems == null) { ModelObjectDataItems = new EnterpriseDataObjectList <ModelObjectDataViewModel>(); foreach (ModelObject loopObject in model.ModelObjectList) { if (loopObject.ParentModelObjectID == null) { ModelObjectDataViewModel modelObjectDataViewModel = new ModelObjectDataViewModel(model, loopObject, null, solution, loadChildren); modelObjectDataViewModel.Updated += new EventHandler(Children_Updated); ModelObjectDataItems.Add(modelObjectDataViewModel); Items.Add(modelObjectDataViewModel); } } } #region protected #endregion protected Refresh(false); } }
///-------------------------------------------------------------------------------- /// <summary>This method loads an item of ModelObjectData into the view model.</summary> /// /// <param name="model">The Model to load.</param> /// <param name="modelObject">The ModelObject to load.</param> /// <param name="modelProperty">The ModelProperty to load.</param> /// <param name="objectInstance">The ObjectInstance to load.</param> /// <param name="solution">The Solution to load.</param> /// <param name="loadChildren">Flag indicating whether to perform a deeper load.</param> ///-------------------------------------------------------------------------------- public void LoadModelPropertyData(Model model, ModelObject modelObject, ModelProperty modelProperty, ObjectInstance objectInstance, Solution solution, bool loadChildren = true) { // attach the ModelObject Model = model; ModelObject = modelObject; ModelProperty = modelProperty; ObjectInstance = objectInstance; Solution = solution; ItemID = ModelProperty.ModelPropertyID; Items.Clear(); if (loadChildren == true) { // attach PropertyInstances if (PropertyInstances == null) { PropertyInstances = new EnterpriseDataObjectList <PropertyInstanceViewModel>(); foreach (PropertyInstance item in objectInstance.PropertyInstanceList) { if (item.Solution == null) { // TODO: this is a hack item.Solution = solution; } if (objectInstance == null || item.ModelPropertyID == modelProperty.ModelPropertyID) { PropertyInstanceViewModel itemView = new PropertyInstanceViewModel(item, solution); itemView.Updated += new EventHandler(Children_Updated); PropertyInstances.Add(itemView); Items.Add(itemView); } } } #region protected #endregion protected Refresh(false); } }
///-------------------------------------------------------------------------------- /// <summary>This method gets the collection context associated with this node.</summary> /// /// <param name="solutionContext">The associated solution.</param> /// <param name="templateContext">The associated template.</param> /// <param name="modelContext">The associated model context.</param> /// <param name="collectionType">The type of collection to get.</param> /// <param name="interpreterType">The type of interpretation to perform.</param> ///-------------------------------------------------------------------------------- public IEnterpriseEnumerable GetCollection(Solution solutionContext, ITemplate templateContext, IDomainEnterpriseObject modelContext, ModelContextNode collectionType, InterpreterTypeCode interpreterType) { IDomainEnterpriseObject collectionContext = modelContext; if (ModelContext != null) { bool isValidContext; collectionContext = ModelContext.GetModelContext(solutionContext, templateContext, modelContext, out isValidContext); } else if (CurrentItem != null) { collectionContext = CurrentItem.GetModelContext(solutionContext, templateContext, modelContext); } else if (SpecCurrentItem != null) { collectionContext = SpecCurrentItem.GetModelContext(solutionContext, templateContext, modelContext); } if (MethodName == LanguageTerms.FindAllMethod && ModelProperty != null) { IEnterpriseEnumerable collection = collectionType.GetCollection(solutionContext, templateContext, collectionContext); if (collection != null) { return(collection.FindItems(ModelProperty.ModelPropertyName, Parameter.GetObjectValue(solutionContext, templateContext, modelContext, interpreterType))); } } else if (MethodName == LanguageTerms.GetEntityAndBasesCollection) { // TODO: condense ability to get extended collections if (collectionType.ModelContextName == "Entity" && collectionContext is Entity) { EnterpriseDataObjectList <Entity> entities = new EnterpriseDataObjectList <Entity>(); Entity currentEntity = collectionContext as Entity; while (currentEntity != null) { entities.Add(currentEntity); currentEntity = currentEntity.BaseEntity; } return(entities); } else if (collectionType.ModelContextName == "Property") { EnterpriseDataObjectList <Property> items = new EnterpriseDataObjectList <Property>(); bool isValidContext; Entity currentEntity = Entity.GetModelContext(solutionContext, collectionContext, out isValidContext) as Entity; while (currentEntity != null) { foreach (Property loopItem in currentEntity.PropertyList) { items.Add(loopItem); } currentEntity = currentEntity.BaseEntity; } return(items); } else if (collectionType.ModelContextName == "PropertyReference") { EnterpriseDataObjectList <PropertyReference> items = new EnterpriseDataObjectList <PropertyReference>(); bool isValidContext; Entity currentEntity = Entity.GetModelContext(solutionContext, collectionContext, out isValidContext) as Entity; while (currentEntity != null) { foreach (PropertyReference loopItem in currentEntity.PropertyReferenceList) { items.Add(loopItem); } currentEntity = currentEntity.BaseEntity; } return(items); } else if (collectionType.ModelContextName == "EntityReference") { EnterpriseDataObjectList <EntityReference> items = new EnterpriseDataObjectList <EntityReference>(); bool isValidContext; Entity currentEntity = Entity.GetModelContext(solutionContext, collectionContext, out isValidContext) as Entity; while (currentEntity != null) { foreach (EntityReference loopItem in currentEntity.EntityReferenceList) { items.Add(loopItem); } currentEntity = currentEntity.BaseEntity; } return(items); } else if (collectionType.ModelContextName == "Collection") { EnterpriseDataObjectList <Collection> items = new EnterpriseDataObjectList <Collection>(); bool isValidContext; Entity currentEntity = Entity.GetModelContext(solutionContext, collectionContext, out isValidContext) as Entity; while (currentEntity != null) { foreach (Collection loopItem in currentEntity.CollectionList) { items.Add(loopItem); } currentEntity = currentEntity.BaseEntity; } return(items); } else if (collectionType.ModelContextName == "Relationship") { EnterpriseDataObjectList <Relationship> items = new EnterpriseDataObjectList <Relationship>(); bool isValidContext; Entity currentEntity = Entity.GetModelContext(solutionContext, collectionContext, out isValidContext) as Entity; while (currentEntity != null) { foreach (Relationship loopItem in currentEntity.RelationshipList) { items.Add(loopItem); } currentEntity = currentEntity.BaseEntity; } return(items); } else if (collectionType.ModelContextName == "Index") { EnterpriseDataObjectList <Index> items = new EnterpriseDataObjectList <Index>(); bool isValidContext; Entity currentEntity = Entity.GetModelContext(solutionContext, collectionContext, out isValidContext) as Entity; while (currentEntity != null) { foreach (Index loopItem in currentEntity.IndexList) { items.Add(loopItem); } currentEntity = currentEntity.BaseEntity; } return(items); } else if (collectionType.ModelContextName == "Method") { EnterpriseDataObjectList <Method> items = new EnterpriseDataObjectList <Method>(); bool isValidContext; Entity currentEntity = Entity.GetModelContext(solutionContext, collectionContext, out isValidContext) as Entity; while (currentEntity != null) { foreach (Method loopItem in currentEntity.MethodList) { items.Add(loopItem); } currentEntity = currentEntity.BaseEntity; } return(items); } } else if (MethodName == LanguageTerms.GetBaseAndEntitiesCollection) { // TODO: condense ability to get extended collections if (collectionType.ModelContextName == "Entity" && collectionContext is Entity) { EnterpriseDataObjectList <Entity> items = new EnterpriseDataObjectList <Entity>(); Entity currentEntity = collectionContext as Entity; while (currentEntity != null) { items.Insert(0, currentEntity); currentEntity = currentEntity.BaseEntity; } return(items); } else if (collectionType.ModelContextName == "Property") { EnterpriseDataObjectList <Property> items = new EnterpriseDataObjectList <Property>(); bool isValidContext; Entity currentEntity = Entity.GetModelContext(solutionContext, collectionContext, out isValidContext) as Entity; while (currentEntity != null) { foreach (Property loopItem in currentEntity.PropertyList) { items.Add(loopItem); } currentEntity = currentEntity.BaseEntity; } return(items); } else if (collectionType.ModelContextName == "PropertyReference") { EnterpriseDataObjectList <PropertyReference> items = new EnterpriseDataObjectList <PropertyReference>(); bool isValidContext; Entity currentEntity = Entity.GetModelContext(solutionContext, collectionContext, out isValidContext) as Entity; while (currentEntity != null) { foreach (PropertyReference loopItem in currentEntity.PropertyReferenceList) { items.Add(loopItem); } currentEntity = currentEntity.BaseEntity; } return(items); } else if (collectionType.ModelContextName == "EntityReference") { EnterpriseDataObjectList <EntityReference> items = new EnterpriseDataObjectList <EntityReference>(); bool isValidContext; Entity currentEntity = Entity.GetModelContext(solutionContext, collectionContext, out isValidContext) as Entity; while (currentEntity != null) { foreach (EntityReference loopItem in currentEntity.EntityReferenceList) { items.Add(loopItem); } currentEntity = currentEntity.BaseEntity; } return(items); } else if (collectionType.ModelContextName == "Collection") { EnterpriseDataObjectList <Collection> items = new EnterpriseDataObjectList <Collection>(); bool isValidContext; Entity currentEntity = Entity.GetModelContext(solutionContext, collectionContext, out isValidContext) as Entity; while (currentEntity != null) { foreach (Collection loopItem in currentEntity.CollectionList) { items.Add(loopItem); } currentEntity = currentEntity.BaseEntity; } return(items); } else if (collectionType.ModelContextName == "Relationship") { EnterpriseDataObjectList <Relationship> items = new EnterpriseDataObjectList <Relationship>(); bool isValidContext; Entity currentEntity = Entity.GetModelContext(solutionContext, collectionContext, out isValidContext) as Entity; while (currentEntity != null) { foreach (Relationship loopItem in currentEntity.RelationshipList) { items.Add(loopItem); } currentEntity = currentEntity.BaseEntity; } return(items); } else if (collectionType.ModelContextName == "Index") { EnterpriseDataObjectList <Index> items = new EnterpriseDataObjectList <Index>(); bool isValidContext; Entity currentEntity = Entity.GetModelContext(solutionContext, collectionContext, out isValidContext) as Entity; while (currentEntity != null) { foreach (Index loopItem in currentEntity.IndexList) { items.Add(loopItem); } currentEntity = currentEntity.BaseEntity; } return(items); } else if (collectionType.ModelContextName == "Method") { EnterpriseDataObjectList <Method> items = new EnterpriseDataObjectList <Method>(); bool isValidContext; Entity currentEntity = Entity.GetModelContext(solutionContext, collectionContext, out isValidContext) as Entity; while (currentEntity != null) { foreach (Method loopItem in currentEntity.MethodList) { items.Add(loopItem); } currentEntity = currentEntity.BaseEntity; } return(items); } } else if (MethodName == LanguageTerms.ExtendingEntitiesCollection) { if (collectionType.ModelContextName == "Entity" && collectionContext is Entity) { return((collectionContext as Entity).ExtendingEntites); } else if (collectionType.ModelContextName == "Property") { EnterpriseDataObjectList <Property> items = new EnterpriseDataObjectList <Property>(); bool isValidContext; Entity currentEntity = Entity.GetModelContext(solutionContext, collectionContext, out isValidContext) as Entity; if (currentEntity != null) { foreach (Entity loopEntity in currentEntity.ExtendingEntites) { foreach (Property loopItem in loopEntity.PropertyList) { items.Add(loopItem); } } } return(items); } else if (collectionType.ModelContextName == "PropertyReference") { EnterpriseDataObjectList <PropertyReference> items = new EnterpriseDataObjectList <PropertyReference>(); bool isValidContext; Entity currentEntity = Entity.GetModelContext(solutionContext, collectionContext, out isValidContext) as Entity; if (currentEntity != null) { foreach (Entity loopEntity in currentEntity.ExtendingEntites) { foreach (PropertyReference loopItem in loopEntity.PropertyReferenceList) { items.Add(loopItem); } } } return(items); } else if (collectionType.ModelContextName == "EntityReference") { EnterpriseDataObjectList <EntityReference> items = new EnterpriseDataObjectList <EntityReference>(); bool isValidContext; Entity currentEntity = Entity.GetModelContext(solutionContext, collectionContext, out isValidContext) as Entity; if (currentEntity != null) { foreach (Entity loopEntity in currentEntity.ExtendingEntites) { foreach (EntityReference loopItem in loopEntity.EntityReferenceList) { items.Add(loopItem); } } } return(items); } else if (collectionType.ModelContextName == "Collection") { EnterpriseDataObjectList <Collection> items = new EnterpriseDataObjectList <Collection>(); bool isValidContext; Entity currentEntity = Entity.GetModelContext(solutionContext, collectionContext, out isValidContext) as Entity; if (currentEntity != null) { foreach (Entity loopEntity in currentEntity.ExtendingEntites) { foreach (Collection loopItem in loopEntity.CollectionList) { items.Add(loopItem); } } } return(items); } else if (collectionType.ModelContextName == "Relationship") { EnterpriseDataObjectList <Relationship> items = new EnterpriseDataObjectList <Relationship>(); bool isValidContext; Entity currentEntity = Entity.GetModelContext(solutionContext, collectionContext, out isValidContext) as Entity; if (currentEntity != null) { foreach (Entity loopEntity in currentEntity.ExtendingEntites) { foreach (Relationship loopItem in loopEntity.RelationshipList) { items.Add(loopItem); } } } return(items); } else if (collectionType.ModelContextName == "Index") { EnterpriseDataObjectList <Index> items = new EnterpriseDataObjectList <Index>(); bool isValidContext; Entity currentEntity = Entity.GetModelContext(solutionContext, collectionContext, out isValidContext) as Entity; if (currentEntity != null) { foreach (Entity loopEntity in currentEntity.ExtendingEntites) { foreach (Index loopItem in loopEntity.IndexList) { items.Add(loopItem); } } } return(items); } else if (collectionType.ModelContextName == "Method") { EnterpriseDataObjectList <Method> items = new EnterpriseDataObjectList <Method>(); bool isValidContext; Entity currentEntity = Entity.GetModelContext(solutionContext, collectionContext, out isValidContext) as Entity; if (currentEntity != null) { foreach (Entity loopEntity in currentEntity.ExtendingEntites) { foreach (Method loopItem in loopEntity.MethodList) { items.Add(loopItem); } } } return(items); } } else if (MethodName == LanguageTerms.PathRelationships) { if (collectionType.ModelContextName == "Relationship" && collectionContext is Entity) { return((collectionContext as Entity).PathRelationships); } } return(null); }
///-------------------------------------------------------------------------------- /// <summary>This method gets the collection context associated with this item.</summary> /// /// <param name="solutionContext">The associated solution.</param> /// <param name="modelContext">The associated model context.</param> ///-------------------------------------------------------------------------------- public static IEnterpriseEnumerable GetCollectionContext(Solution solutionContext, IDomainEnterpriseObject modelContext, bool getChildItems = false) { IDomainEnterpriseObject nodeContext = modelContext; while (nodeContext != null) { if (nodeContext is XmlNode) { if (getChildItems == true) { EnterpriseDataObjectList <XmlNode> nodes = new EnterpriseDataObjectList <XmlNode>(); foreach (XmlNode node in (nodeContext as XmlNode).XmlNodeList) { foreach (IDomainEnterpriseObject childNode in GetCollectionContext(solutionContext, node, getChildItems)) { if (childNode is XmlNode) { nodes.Add(childNode as XmlNode); } } } return(nodes); } return((nodeContext as XmlNode).XmlNodeList); } else if (nodeContext is XmlDocument) { if (getChildItems == true) { EnterpriseDataObjectList <XmlNode> nodes = new EnterpriseDataObjectList <XmlNode>(); foreach (XmlNode node in (nodeContext as XmlDocument).XmlNodeList) { nodes.Add(node); foreach (IDomainEnterpriseObject childNode in GetCollectionContext(solutionContext, node, getChildItems)) { if (childNode is XmlNode) { nodes.Add(childNode as XmlNode); } } } return(nodes); } return((nodeContext as XmlDocument).XmlNodeList); } else if (nodeContext is XmlSource) { EnterpriseDataObjectList <XmlNode> nodes = new EnterpriseDataObjectList <XmlNode>(); if ((nodeContext as XmlSource).SpecDocument != null) { foreach (XmlNode node in (nodeContext as XmlSource).SpecDocument.XmlNodeList) { nodes.Add(node); foreach (IDomainEnterpriseObject childNode in GetCollectionContext(solutionContext, node, true)) { if (childNode is XmlNode) { nodes.Add(childNode as XmlNode); } } } } return(nodes); } else if (nodeContext is Solution) { EnterpriseDataObjectList <XmlNode> nodes = new EnterpriseDataObjectList <XmlNode>(); foreach (XmlSource source in (nodeContext as Solution).XmlSourceList) { if (source.SpecDocument != null) { foreach (XmlNode node in source.SpecDocument.XmlNodeList) { nodes.Add(node); foreach (IDomainEnterpriseObject childNode in GetCollectionContext(solutionContext, node, true)) { if (childNode is XmlNode) { nodes.Add(childNode as XmlNode); } } } } } return(nodes); } nodeContext = nodeContext.GetParentItem(); } return(null); }
///-------------------------------------------------------------------------------- /// <summary>This method gets the collection context associated with this item.</summary> /// /// <param name="solutionContext">The associated solution.</param> /// <param name="modelContext">The associated model context.</param> ///-------------------------------------------------------------------------------- public static IEnterpriseEnumerable GetCollectionContext(Solution solutionContext, IDomainEnterpriseObject modelContext) { IDomainEnterpriseObject nodeContext = modelContext; while (nodeContext != null) { if (nodeContext is SqlView) { return((nodeContext as SqlView).SqlViewPropertyList); } #region protected else if (nodeContext is SqlDatabase) { EnterpriseDataObjectList <SqlViewProperty> properties = new EnterpriseDataObjectList <SqlViewProperty>(); foreach (SqlView view in (nodeContext as SqlDatabase).SqlViewList) { foreach (SqlViewProperty property in view.SqlViewPropertyList) { properties.Add(property); } } return(properties); } else if (nodeContext is DatabaseSource) { if ((nodeContext as DatabaseSource).SpecDatabase != null) { EnterpriseDataObjectList <SqlViewProperty> properties = new EnterpriseDataObjectList <SqlViewProperty>(); foreach (SqlView view in (nodeContext as DatabaseSource).SpecDatabase.SqlViewList) { foreach (SqlViewProperty property in view.SqlViewPropertyList) { properties.Add(property); } } return(properties); } } else if (nodeContext is Project) { if ((nodeContext as Project).OutputDatabase != null) { EnterpriseDataObjectList <SqlViewProperty> properties = new EnterpriseDataObjectList <SqlViewProperty>(); foreach (SqlView view in (nodeContext as Project).OutputDatabase.SqlViewList) { foreach (SqlViewProperty property in view.SqlViewPropertyList) { properties.Add(property); } } return(properties); } } else if (nodeContext is Solution) { EnterpriseDataObjectList <SqlViewProperty> properties = new EnterpriseDataObjectList <SqlViewProperty>(); foreach (DatabaseSource source in (nodeContext as Solution).DatabaseSourceList) { if (source.SpecDatabase != null) { foreach (SqlView view in source.SpecDatabase.SqlViewList) { foreach (SqlViewProperty property in view.SqlViewPropertyList) { properties.Add(property); } } } } return(properties); } #endregion protected nodeContext = nodeContext.GetParentItem(); } return(null); }