public void CreateFunctionImport(Function sproc) { var root = ViewModel.EDMRootNode(); if (null == root) { Debug.Fail("There is no root node in the EDM Explorer"); return; } if (null == root.ConceptualModel) { Debug.Fail("There is no conceptual entity model representation in the EDM Explorer"); return; } var cModel = root.ConceptualModel.ModelItem as ConceptualEntityModel; if (null == cModel) { Debug.Fail("There is no corresponding model item for the EDM Explorer's conceptual entity model representation"); return; } var cContainer = cModel.FirstEntityContainer as ConceptualEntityContainer; if (null == cContainer) { Debug.Fail("There is no conceptual entity container in the conceptual entity model"); return; } if (null == root.StorageModel) { Debug.Fail("The EDM Explorer must have a storage entity model"); return; } var sModel = root.StorageModel.ModelItem as StorageEntityModel; if (null == sModel) { Debug.Fail("There is no corresponding model item for the EDM Explorer's storage entity model representation"); return; } var artifact = ViewModel.EditingContext.GetEFArtifactService().Artifact; if (null == artifact) { Debug.Fail("There is no artifact for the EDM Explorer's view model representation"); return; } EntityDesignViewModelHelper.CreateFunctionImport( ViewModel.EditingContext, artifact, sproc, sModel, cModel, cContainer, null, EfiTransactionOriginator.ExplorerWindowOriginatorId); }
// <summary> // Launch edit function import dialog box. // </summary> public void EditFunctionImport(FunctionImport functionImport) { Debug.Assert(functionImport != null, "The functionImport passed in to EditFunctionImport is null."); if (null == functionImport) { return; } var artifact = functionImport.Artifact; Debug.Assert(artifact != null, "There is no artifact in the passed in functionImport."); if (null == artifact) { return; } var cModel = artifact.ConceptualModel(); Debug.Assert( cModel != null, "There is no corresponding model item for the EDM Explorer's conceptual entity model representation."); if (null == cModel) { return; } var sModel = artifact.StorageModel(); Debug.Assert(sModel != null, "There is no corresponding model item for the EDM Explorer's storage entity model representation"); if (null == sModel) { return; } var cContainer = cModel.FirstEntityContainer as ConceptualEntityContainer; Debug.Assert(cContainer != null, "There is no conceptual entity container in the conceptual entity model"); if (null == cContainer) { return; } EntityDesignViewModelHelper.EditFunctionImport( ViewModel.EditingContext, functionImport, sModel, cModel, cContainer, GetFunctionImportReturnType(cModel, functionImport), EfiTransactionOriginator.ExplorerWindowOriginatorId); }
public void ExecuteActivate() { var viewModelHelper = ExplorerViewModelHelper as EntityDesignExplorerViewModelHelper; Debug.Assert(viewModelHelper != null, "ExplorerViewModelHelper is null or is not type of EntityDesignExplorerViewModelHelper"); // Function-Import/Function double-click behavior. var selectedExplorerEFElement = GetSelectedExplorerEFElement(); var explorerFunctionImport = selectedExplorerEFElement as ExplorerFunctionImport; var explorerFunction = selectedExplorerEFElement as ExplorerFunction; var explorerDiagram = selectedExplorerEFElement as ExplorerDiagram; var explorerConceptualProperty = selectedExplorerEFElement as ExplorerConceptualProperty; var explorerEnumType = selectedExplorerEFElement as ExplorerEnumType; var diagramManagercontextItem = EditingContext.Items.GetValue <DiagramManagerContextItem>(); Debug.Assert(diagramManagercontextItem != null, "Could not find instance of: DiagramManagerContextItem in editing context."); if (viewModelHelper != null && explorerFunctionImport != null) { viewModelHelper.EditFunctionImport(explorerFunctionImport.ModelItem as FunctionImport); } // if the user double-clicks on the function in the model browser. else if (viewModelHelper != null && explorerFunction != null) { var function = explorerFunction.ModelItem as Function; Debug.Assert(function != null, "ExplorerFunction.ModelItem value is expected to be typeof Function and not null."); if (function != null) { var schemaVersion = (function.Artifact == null ? null : function.Artifact.SchemaVersion); if (function.IsComposable != null && function.IsComposable.Value && !EdmFeatureManager.GetComposableFunctionImportFeatureState(schemaVersion).IsEnabled()) { // Composable Function Import for Version <= V2 - give warning message VsUtils.ShowMessageBox( PackageManager.Package, string.Format( CultureInfo.CurrentCulture, Design.Resources.FunctionImport_CannotCreateFromComposableFunction, EntityFrameworkVersion.Version2), OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST, OLEMSGICON.OLEMSGICON_WARNING); } else { // first we detect whether there are existing FunctionImport(s) with the underlying function. var itemBindings = function.GetDependentBindings(); var matchFunctionImportList = new List <FunctionImport>(); foreach (var itemBinding in itemBindings) { var functionImportMapping = itemBinding.GetParentOfType(typeof(FunctionImportMapping)) as FunctionImportMapping; if (functionImportMapping != null && functionImportMapping.FunctionImportName != null && functionImportMapping.FunctionImportName.Target != null) { matchFunctionImportList.Add(functionImportMapping.FunctionImportName.Target); } } // if we found function imports for the underlying function, navigate to the first function import in alphabetical sorted list if (matchFunctionImportList.Count > 0) { matchFunctionImportList.Sort(EFElement.EFElementDisplayNameComparison); ExplorerNavigationHelper.NavigateTo(matchFunctionImportList[0]); } else { // We could not find any function import for the underlying function, show new function import dialog viewModelHelper.CreateFunctionImport(explorerFunction.ModelItem as Function); } } } } else if (explorerEnumType != null) { var enumType = explorerEnumType.ModelItem as EnumType; Debug.Assert(enumType != null, "ExplorerEnumType's model item is null or is not type of EnumType."); EntityDesignViewModelHelper.EditEnumType( Context, EfiTransactionOriginator.ExplorerWindowOriginatorId, new EnumTypeViewModel(enumType)); } // if the selected Explorer is type of ExplorerDiagram. else if (explorerDiagram != null && diagramManagercontextItem != null) { diagramManagercontextItem.DiagramManager.OpenDiagram(explorerDiagram.DiagramMoniker, true); } else if (explorerConceptualProperty != null) { Debug.Assert( explorerConceptualProperty.Parent is ExplorerConceptualEntityType, "Only properties that belong to Entity type are supported."); if (explorerConceptualProperty.Parent is ExplorerConceptualEntityType) { diagramManagercontextItem.DiagramManager.ActiveDiagram.AddOrShowEFElementInDiagram(explorerConceptualProperty.ModelItem); } } // if the selected Explorer is type of ExplorerConceptualEntityType, ExplorerConceptualAssociation, ExplorerNavigationProperty, ExplorerAssociationSet or ExplorerEntitySet else if (diagramManagercontextItem != null && diagramManagercontextItem.DiagramManager != null && diagramManagercontextItem.DiagramManager.ActiveDiagram != null) { Debug.Assert( selectedExplorerEFElement is ExplorerConceptualEntityType || selectedExplorerEFElement is ExplorerConceptualAssociation || selectedExplorerEFElement is ExplorerNavigationProperty || selectedExplorerEFElement is ExplorerAssociationSet || selectedExplorerEFElement is ExplorerEntitySet || selectedExplorerEFElement is ExplorerEntityTypeShape, "The selected explorer type:" + selectedExplorerEFElement.GetType().Name + " is not supported."); if (selectedExplorerEFElement is ExplorerConceptualEntityType || selectedExplorerEFElement is ExplorerConceptualAssociation || selectedExplorerEFElement is ExplorerNavigationProperty || selectedExplorerEFElement is ExplorerAssociationSet || selectedExplorerEFElement is ExplorerEntitySet) { diagramManagercontextItem.DiagramManager.ActiveDiagram.AddOrShowEFElementInDiagram(selectedExplorerEFElement.ModelItem); } else if (selectedExplorerEFElement is ExplorerEntityTypeShape) { var entityTypeShape = selectedExplorerEFElement.ModelItem as EntityTypeShape; Debug.Assert(entityTypeShape != null, "ExplorerEntityTypeShape does not contain instance of EntityTypeShape"); if (entityTypeShape != null) { diagramManagercontextItem.DiagramManager.OpenDiagram(entityTypeShape.Diagram.Id, true); diagramManagercontextItem.DiagramManager.ActiveDiagram.AddOrShowEFElementInDiagram( entityTypeShape.EntityType.Target); } } } }
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { if (null == context) { Debug.Fail("context object must not be null"); // returning value means "no change" return(value); } if (null == context.Instance) { Debug.Fail("context Instance object should not be null"); // returning value means "no change" return(value); } if (null == provider) { Debug.Fail("provider object must not be null"); // returning value means "no change" return(value); } var funcImpDesc = context.Instance as EFFunctionImportDescriptor; if (null == funcImpDesc) { Debug.Fail( "Context Instance object should be EFFunctionImportDescriptor, instead received object of type " + context.Instance.GetType().FullName); // returning value means "no change" return(value); } var funcImp = funcImpDesc.TypedEFElement; if (null == funcImp) { Debug.Fail("TypedEFElement is null for EFFunctionImportDescriptor object: " + funcImpDesc); // returning value means "no change" return(value); } var artifact = funcImp.Artifact; if (null == artifact) { Debug.Fail("Null artifact in FunctionImportReturnTypeTypeEditor"); // returning value means "no change" return(value); } if (null == artifact.Uri) { Debug.Fail("Null artifact.Uri in FunctionImportReturnTypeTypeEditor"); // returning value means "no change" return(value); } if (null == artifact.Uri.LocalPath) { Debug.Fail("Null artifact.Uri.LocalPath in FunctionImportReturnTypeTypeEditor"); // returning value means "no change" return(value); } // get SchemaVersion for current edmx file if (null == artifact.SchemaVersion) { Debug.Fail("Could not determine Version for path " + artifact.Uri.LocalPath); // returning value means "no change" return(value); } var cModel = artifact.ConceptualModel(); if (null == cModel) { Debug.Fail("Null Conceptual Model in FunctionImportReturnTypeTypeEditor"); // returning value means "no change" return(value); } var sModel = artifact.StorageModel(); var cContainer = cModel.FirstEntityContainer as ConceptualEntityContainer; // Since "value" parameter does not contain namespace information, so we could not differentiate between a complex type named "Decimal" and "Decimal" primitive type, // we need to get the normalized-return-type-string from function import and use it instead. var selectedElement = ModelHelper.FindComplexTypeEntityTypeOrPrimitiveTypeForFunctionImportReturnType( cModel, funcImp.ReturnTypeToNormalizedString); EntityDesignViewModelHelper.EditFunctionImport( funcImpDesc.EditingContext, funcImp, sModel, cModel, cContainer, selectedElement, EfiTransactionOriginator.ExplorerWindowOriginatorId); return(value); }