private static XmlReader CreateXmlReader(EFArtifact artifact, XElement xobject)
 {
     var baseReader = xobject.CreateReader();
     var lineNumberService = new XNodeReaderLineNumberService(artifact.XmlModelProvider, baseReader, artifact.Uri);
     var proxyReader = new XmlReaderProxy(baseReader, artifact.Uri, lineNumberService);
     return proxyReader;
 }
        /// <summary>
        ///     Remove the Artifact associated with the Uri from the cache.
        ///     Virtual for testing.
        /// </summary>
        internal virtual void ClearArtifact(Uri uri)
        {
            lock (this)
            {
                EFArtifact artifact = null;
                if (_artifactsByUri.TryGetValue(uri, out artifact))
                {
                    if (artifact != null)
                    {
                        var artifactSet = GetArtifactSet(uri);
                        Debug.Assert(artifactSet != null);

                        // need to dispose the artifact first, as it will try and access it's set
                        artifact.Dispose();

                        // clean up the model manager's collections
                        _artifact2ArtifactSets.Remove(artifact);
                        _artifactsByUri.Remove(uri);

                        // remove this artifact from the set
                        artifactSet.RemoveArtifact(artifact);
                    }
                }
            }
        }
Exemple #3
0
        internal static bool IsSqlFamilyProvider(this EFArtifact thisArtifact)
        {
            Debug.Assert(thisArtifact != null, "thisArtifact != null");

            // This is needed to workaround problems with facet propagation feature.
            // For Sql Server and Sql Server CE facets on properties in S-Space are by default
            // the same as facets on corresponding properties in C-Space and therefore it is possible
            // to blindly (i.e. wihtout asking the provider) propagate facets from S-Space properties
            // to C-Space properties. Providers for other databases may use facets to distinguish among
            // different types in which case the mismatch between facets on C-Space properties and S-Space
            // properties is intentional and facet propagation breaks this. In general we should always ask
            // the provider about the type before we propagate facet values. This is a major change though
            // so for now we will limit the default facet propagation to SqlServer and Sql Server CE only.
            var storageModel = thisArtifact.StorageModel();

            if (storageModel != null &&
                storageModel.Provider != null &&
                storageModel.Provider.Value != null)
            {
                return(storageModel.Provider.Value.Equals("System.Data.SqlClient", StringComparison.Ordinal) ||
                       storageModel.Provider.Value.StartsWith("System.Data.SqlServerCe", StringComparison.Ordinal));
            }

            return(false);
        }
        /// <summary>
        ///     Returns the FeatureState for the 'Get Column Information' functionality for FunctionImports
        /// </summary>
        internal static FeatureState GetFunctionImportColumnInformationFeatureState(EFArtifact artifact)
        {
            Debug.Assert(artifact != null, "artifact != null");

            return IsFeatureSupportedForWorkflowAndRuntime(
                artifact,
                (a, existingFs) => existingFs);
        }
Exemple #5
0
        /// <summary>
        ///     Returns the FeatureState for the 'Get Column Information' functionality for FunctionImports
        /// </summary>
        internal static FeatureState GetFunctionImportColumnInformationFeatureState(EFArtifact artifact)
        {
            Debug.Assert(artifact != null, "artifact != null");

            return(IsFeatureSupportedForWorkflowAndRuntime(
                       artifact,
                       (a, existingFs) => existingFs));
        }
Exemple #6
0
        /// <summary>
        ///     Returns the FeatureState for the EnumTypes feature
        /// </summary>
        internal static FeatureState GetEnumTypeFeatureState(EFArtifact artifact)
        {
            Debug.Assert(artifact != null, "artifact != null");

            return(IsFeatureSupportedForWorkflowAndRuntime(
                       artifact,
                       (a, existingFs) => GetEnumTypeFeatureState(a.SchemaVersion)));
        }
Exemple #7
0
        private static XmlReader CreateXmlReader(EFArtifact artifact, XElement xobject)
        {
            var baseReader        = xobject.CreateReader();
            var lineNumberService = new XNodeReaderLineNumberService(artifact.XmlModelProvider, baseReader, artifact.Uri);
            var proxyReader       = new XmlReaderProxy(baseReader, artifact.Uri, lineNumberService);

            return(proxyReader);
        }
        /// <summary>
        ///     Returns the FeatureState for the EnumTypes feature
        /// </summary>
        internal static FeatureState GetEnumTypeFeatureState(EFArtifact artifact)
        {
            Debug.Assert(artifact != null, "artifact != null");

            return IsFeatureSupportedForWorkflowAndRuntime(
                artifact,
                (a, existingFs) => GetEnumTypeFeatureState(a.SchemaVersion));
        }
 internal static StorageEntityModel StorageModel(this EFArtifact thisArtifact)
 {
     var artifact = GetEntityDesignArtifact(thisArtifact);
     if (artifact != null)
     {
         return artifact.StorageModel;
     }
     return null;
 }
 internal static ConceptualEntityModel ConceptualModel(this EFArtifact thisArtifact)
 {
     var artifact = GetEntityDesignArtifact(thisArtifact);
     if (artifact != null)
     {
         return artifact.ConceptualModel;
     }
     return null;
 }
 internal static EFDesignerInfoRoot DesignerInfo(this EFArtifact thisArtifact)
 {
     var artifact = GetEntityDesignArtifact(thisArtifact);
     if (artifact != null)
     {
         return artifact.DesignerInfo;
     }
     return null;
 }
 internal static MappingModel MappingModel(this EFArtifact thisArtifact)
 {
     var artifact = GetEntityDesignArtifact(thisArtifact);
     if (artifact != null)
     {
         return artifact.MappingModel;
     }
     return null;
 }
        internal static string GetMslAsString(this EFArtifact artifact)
        {
            Debug.Assert(artifact != null, "Artifact is null ");
            if (artifact != null)
            {
                return(GetSchemaFromRuntimeModelRoot(artifact.MappingModel()));
            }

            return(String.Empty);
        }
Exemple #14
0
        private void GetAllErrorsForArtifact(EFArtifact artifact, List <ErrorInfo> allErrors)
        {
            var errorClass2ErrorInfo = _artifacts2Errors[artifact];

            foreach (var errorsForClass in errorClass2ErrorInfo.Values)
            {
                allErrors.AddRange(errorsForClass);
            }

            allErrors.AddRange(artifact.GetAllParseErrorsForArtifact());
        }
Exemple #15
0
 internal void RemoveErrorsForArtifact(EFArtifact artifact, ErrorClass errorClass)
 {
     if (_artifacts2Errors.ContainsKey(artifact))
     {
         var errorClass2ErrorInfo = _artifacts2Errors[artifact];
         foreach (var errorInfos in GetErrorInfosUsingMask(errorClass2ErrorInfo, errorClass))
         {
             errorInfos.Clear();
         }
     }
 }
Exemple #16
0
        /// <summary>
        ///     This will return a collection of errors for the artifact only (without traversing children).
        /// </summary>
        /// <param name="artifact"></param>
        internal ICollection <ErrorInfo> GetArtifactOnlyErrors(EFArtifact artifact)
        {
            var errors = new List <ErrorInfo>();
            var errorClass2ErrorInfo = _artifacts2Errors[artifact];

            foreach (var errorsForClass in errorClass2ErrorInfo.Values)
            {
                errors.AddRange(errorsForClass);
            }
            return(errors);
        }
 internal EFDesignerInfoRoot(EFArtifact parent, XElement element)
     : base(parent, element)
 {
     // Allow the Diagrams node comes from DiagramArtifact.
     var artifact = Artifact as EntityDesignArtifact;
     if (artifact != null
         && artifact.DiagramArtifact != null)
     {
         _diagramArtifact = artifact.DiagramArtifact;
     }
 }
Exemple #18
0
 /// <summary>
 ///     Get the EFArtifact for a particular Uri from the cache or null if it hasn't been loaded.
 ///     Virtual to allow mocking.
 /// </summary>
 internal virtual EFArtifact GetArtifact(Uri uri)
 {
     lock (this)
     {
         EFArtifact result = null;
         if (_artifactsByUri.TryGetValue(uri, out result))
         {
             return(result);
         }
         return(null);
     }
 }
        internal EFDesignerInfoRoot(EFArtifact parent, XElement element)
            : base(parent, element)
        {
            // Allow the Diagrams node comes from DiagramArtifact.
            var artifact = Artifact as EntityDesignArtifact;

            if (artifact != null &&
                artifact.DiagramArtifact != null)
            {
                _diagramArtifact = artifact.DiagramArtifact;
            }
        }
Exemple #20
0
 internal void RenameArtifact(Uri oldUri, Uri newUri)
 {
     lock (this)
     {
         EFArtifact result = null;
         if (_artifactsByUri.TryGetValue(oldUri, out result))
         {
             _artifactsByUri.Remove(oldUri);
             _artifactsByUri.Add(newUri, result);
             result.RenameArtifact(newUri);
         }
     }
 }
        internal static string GetProviderManifestToken(this EFArtifact artifact)
        {
            var storageModel = artifact.StorageModel();

            if (storageModel != null &&
                storageModel.ProviderManifestToken != null)
            {
                return(storageModel.ProviderManifestToken.Value);
            }

            Debug.Fail("Unable to determine the provider manifest token for the SSDL");

            return(String.Empty);
        }
Exemple #22
0
        internal void GetErrorsForArtifact(EFArtifact artifact, List <ErrorInfo> errors, ErrorClass errorClass)
        {
            Dictionary <ErrorClass, ICollection <ErrorInfo> > errorClass2ErrorInfo = null;

            _artifacts2Errors.TryGetValue(artifact, out errorClass2ErrorInfo);

            if (errorClass2ErrorInfo != null)
            {
                foreach (var e in GetErrorInfosUsingMask(errorClass2ErrorInfo, errorClass))
                {
                    errors.AddRange(e);
                }
            }
        }
Exemple #23
0
        /// <summary>
        ///     Captures the common pattern:
        ///     1. Check if the workflow supports the feature
        ///     2. If the workflow allows the feature to be enabled, we may want to disable it based on the runtime.
        /// </summary>
        private static FeatureState IsFeatureSupportedForWorkflowAndRuntime(
            EFArtifact artifact,
            Func <EFArtifact, FeatureState, FeatureState> featureManagerFunction)
        {
            const FeatureState featureState = FeatureState.VisibleAndEnabled;

            Debug.Assert(artifact != null, "Not a valid EFArtifact");
            Debug.Assert(featureManagerFunction != null, "Not a valid featureManager function");

            // If a feature is deemed invisible within the workflow, there's nothing more we can do within the runtime.
            // NOTE: There are no scenarios yet for the case where a feature is disabled (but visible) and the runtime wants to set it to invisible.
            if (featureState.IsEnabled())
            {
                return(featureManagerFunction(artifact, featureState));
            }

            return(featureState);
        }
 private static EntityDesignArtifact GetEntityDesignArtifact(EFArtifact baseArtifact)
 {
     // Assumption: DiagramArtifact's ArtifactSet will only contains 2 artifacts: DiagramArtifact and EntityDesignArtifact.
     if (baseArtifact is DiagramArtifact)
     {
         return baseArtifact.ArtifactSet.GetEntityDesignArtifact();
     }
     else if (baseArtifact is EntityDesignArtifact)
     {
         return baseArtifact as EntityDesignArtifact;
     }
     else
     {
         Debug.Fail(
             "The artifact must be an EntityDesignArtifact or DiagramArtifact to be used with the EFExtensions extension methods.");
     }
     return null;
 }
Exemple #25
0
        /// <summary>
        ///     Get the EFArtifactSet for a particular Uri from the cache or null if it hasn't been loaded.
        ///     Virtual to allow mocking.
        /// </summary>
        internal virtual EFArtifactSet GetArtifactSet(Uri uri)
        {
            lock (this)
            {
                EFArtifact artifact = null;
                _artifactsByUri.TryGetValue(uri, out artifact);
                if (artifact != null)
                {
                    List <EFArtifactSet> result = null;
                    if (_artifact2ArtifactSets.TryGetValue(artifact, out result))
                    {
                        Debug.Assert(result.Count == 1, "Support for an artifact spanning multiple sets is not yet implemented");
                        return(result[0]);
                    }
                }

                return(null);
            }
        }
        public IList<EdmSchemaError> GenerateCode(EFArtifact artifact, string defaultNamespace, TextWriter outputWriter)
        {
            Debug.Assert(outputWriter != null, "OutputWriter parameter is null");
            Debug.Assert(artifact != null, "artifact parameter is null");

            // create a specialized xml reader that piggybacks off of XNodeReader and keeps track 
            // of line numbers using the Xml Model
            using (var xmlModelReader = CreateXmlReader(artifact, artifact.ConceptualModel().XElement))
            {
                var codeGenerator = CreateCodeGenerator(_language, _targetEntityFrameworkVersion);

                Debug.Assert(artifact.ConceptualModel() != null, "Artifact ConceptuaModel is null");

                if (defaultNamespace != null && artifact.ConceptualModel() != null)
                {
                    codeGenerator.AddNamespaceMapping(artifact.ConceptualModel().Namespace.Value, defaultNamespace);
                }

                return codeGenerator.GenerateCode(xmlModelReader, outputWriter);
            }
        }
Exemple #27
0
        public IList <EdmSchemaError> GenerateCode(EFArtifact artifact, string defaultNamespace, TextWriter outputWriter)
        {
            Debug.Assert(outputWriter != null, "OutputWriter parameter is null");
            Debug.Assert(artifact != null, "artifact parameter is null");

            // create a specialized xml reader that piggybacks off of XNodeReader and keeps track
            // of line numbers using the Xml Model
            using (var xmlModelReader = CreateXmlReader(artifact, artifact.ConceptualModel().XElement))
            {
                var codeGenerator = CreateCodeGenerator(_language, _targetEntityFrameworkVersion);

                Debug.Assert(artifact.ConceptualModel() != null, "Artifact ConceptuaModel is null");

                if (defaultNamespace != null && artifact.ConceptualModel() != null)
                {
                    codeGenerator.AddNamespaceMapping(artifact.ConceptualModel().Namespace.Value, defaultNamespace);
                }

                return(codeGenerator.GenerateCode(xmlModelReader, outputWriter));
            }
        }
Exemple #28
0
        /// <summary>
        ///     This method will do the following.
        ///     - Add EFArtifact reference to the EFArtifactSet.
        ///     - Update artifactsByUri and artifact2ArtifactSet dictionaries.
        ///     - Initialize the EFArtifact.
        /// </summary>
        /// <param name="efArtifact"></param>
        /// <param name="efArtifactSet"></param>
        internal void RegisterArtifact(EFArtifact efArtifact, EFArtifactSet efArtifactSet)
        {
            Debug.Assert(
                _artifactsByUri.ContainsKey(efArtifact.Uri) == false && _artifact2ArtifactSets.ContainsKey(efArtifact) == false,
                "This artifact has been registered in model manager.");

            if (_artifactsByUri.ContainsKey(efArtifact.Uri) == false &&
                _artifact2ArtifactSets.ContainsKey(efArtifact) == false)
            {
                if (efArtifactSet.Artifacts.Contains(efArtifact) == false)
                {
                    efArtifactSet.Add(efArtifact);
                }

                _artifactsByUri[efArtifact.Uri] = efArtifact;

                var artifactSetList = new List <EFArtifactSet>(1);
                artifactSetList.Add(efArtifactSet);
                _artifact2ArtifactSets[efArtifact] = artifactSetList;
                efArtifact.Init();
            }
        }
        internal static EdmItemCollection GetEdmItemCollectionFromArtifact(this EFArtifact artifact, out IList <EdmSchemaError> schemaErrors)
        {
            Debug.Assert(artifact != null, "Artifact is null ");

            var conceptualModel = artifact.ConceptualModel();

            EdmItemCollection edmItemCollection = null;

            schemaErrors = new List <EdmSchemaError>();

            Debug.Assert(
                conceptualModel != null && conceptualModel.XElement != null,
                "Could not find the conceptual model or its XElement in GetEdmItemCollectionFromArtifact");
            if (conceptualModel != null &&
                conceptualModel.XElement != null)
            {
                using (var xmlReader = conceptualModel.XElement.CreateReader())
                {
                    edmItemCollection = EdmItemCollection.Create(new[] { xmlReader }, null, out schemaErrors);
                }
            }

            return(edmItemCollection);
        }
 public int OnBeforeValidateModel(Project project, EFArtifact artifact, bool isCurrentlyBuilding)
 {
     var args = new ModelChangeEventArgs();
     args.ProjectObj = project;
     args.Artifact = artifact;
     args.IsCurrentlyBuilding = isCurrentlyBuilding;
     if (BeforeValidateModel != null)
     {
         return BeforeValidateModel(this, args);
     }
     else
     {
         return 0;
     }
 }
 protected EFRuntimeModelRoot(EFArtifact parent, XElement element)
     : base(parent, element)
 {
 }
        // internal for testing
        internal static bool ShouldValidateArtifactDuringBuild(EFArtifact artifact)
        {
            Debug.Assert(artifact != null, "artifact != null");

            if (artifact.DesignerInfo() != null)
            {
                DesignerInfo designerInfo;
                if (artifact.DesignerInfo().TryGetDesignerInfo(OptionsDesignerInfo.ElementName, out designerInfo))
                {
                    var optionsDesignerInfo = (OptionsDesignerInfo)designerInfo;

                    if (optionsDesignerInfo.ValidateOnBuild != null
                        && optionsDesignerInfo.ValidateOnBuild.ValueAttr != null)
                    {
                        bool validateOnBuild;
                        if (bool.TryParse(optionsDesignerInfo.ValidateOnBuild.ValueAttr.Value, out validateOnBuild))
                        {
                            return validateOnBuild;
                        }
                    }
                }
            }

            return true;
        }
 public int OnBeforeGenerateDDL(Project project, EFArtifact artifact)
 {
     var args = new ModelChangeEventArgs();
     args.ProjectObj = project;
     args.Artifact = artifact;
     if (BeforeGenerateDDL != null)
     {
         return BeforeGenerateDDL(this, args);
     }
     else
     {
         return 0;
     }
 }
        internal static DesignerProperty GetMetadataPropertyFromArtifact(EFArtifact artifact)
        {
            var designerRoot = artifact.DesignerInfo();
            DesignerProperty mapProperty = null;
            if (designerRoot != null)
            {
                DesignerInfo designerInfo;
                if (designerRoot.TryGetDesignerInfo(ConnectionDesignerInfo.ElementName, out designerInfo))
                {
                    var connectionDesignerInfo = designerInfo as ConnectionDesignerInfo;
                    Debug.Assert(
                        connectionDesignerInfo != null,
                        "We should have associated the ConnectionDesignerInfo with " + ConnectionDesignerInfo.ElementName);

                    if (connectionDesignerInfo != null)
                    {
                        mapProperty = connectionDesignerInfo.MetadataArtifactProcessingProperty;
                    }
                }
            }
            return mapProperty;
        }
Exemple #35
0
 /// <summary>
 ///     Gets the AttributeContentValidator used for validating xml attribute values for this ModelManager.
 /// </summary>
 internal abstract AttributeContentValidator GetAttributeContentValidator(EFArtifact artifact);
 /// <summary>
 ///     This will return a collection of errors for all errors in the artifact.  This includes parse errors on the artifact,
 ///     as well as resolve and validation errors that occurred on this artifact in this artifact set.
 /// </summary>
 /// <param name="artifact"></param>
 internal ICollection<ErrorInfo> GetAllErrorsForArtifact(EFArtifact artifact)
 {
     var allErrors = new List<ErrorInfo>();
     GetAllErrorsForArtifact(artifact, allErrors);
     return allErrors;
 }
        public void EnsureDiagramIsCreated(EFArtifact artifact)
        {
            if (RootElement != null)
            {
                var modelRoot = RootElement as EntityDesignerViewModel;
                if (modelRoot != null)
                {
                    var diagram = modelRoot.GetDiagram();
                    Debug.Assert(diagram != null, "DSL Diagram should have been created by now");

                    if (diagram != null)
                    {
                        Debug.Assert(artifact.DesignerInfo() != null, "artifact.DesignerInfo should not be null");
                        Debug.Assert(artifact.DesignerInfo().Diagrams != null, "artifact.DesignerInfo.Diagrams should not be null");

                        if (artifact.DesignerInfo() != null
                            && artifact.DesignerInfo().Diagrams != null)
                        {
                            var saveDiagramDocument = false;

                            if (artifact.DesignerInfo().Diagrams.FirstDiagram == null)
                            {
                                // layout is very slow.  Only auto-layout if less than a max number of types
                                if (diagram.ModelElement.EntityTypes.Count < EntityDesignerDiagram.IMPLICIT_AUTO_LAYOUT_CEILING)
                                {
                                    diagram.AutoLayoutDiagram();
                                }

                                try
                                {
                                    EntityDesignerViewModel.RespondToModelChanges = false;
                                    EntityModelToDslModelTranslatorStrategy.CreateDefaultDiagram(modelRoot.EditingContext, diagram);

                                    // Ensure that DSL Diagram and Model Diagram are in sync:
                                    // - Update xref between 2 diagrams
                                    // - Propagetes model diagram info to DSL Diagram.
                                    var modelDiagram = artifact.DesignerInfo().Diagrams.FirstDiagram;
                                    Debug.Assert(modelDiagram != null, "modelDiagram should not be null");
                                    if (modelDiagram != null)
                                    {
                                        ModelTranslatorContextItem.GetEntityModelTranslator(EditingContext)
                                            .SynchronizeSingleDslModelElement(modelRoot, modelDiagram);
                                    }
                                }
                                finally
                                {
                                    EntityDesignerViewModel.RespondToModelChanges = true;
                                }

                                // save the file after adding Diagram element so it won't open as a dirty document
                                saveDiagramDocument = true;
                            }

                            if (saveDiagramDocument)
                            {
                                var rdt = new RunningDocumentTable(ServiceProvider);
                                rdt.SaveFileIfDirty(FileName);
                            }

                            _isDiagramLoaded = true;
                        }
                    }
                }
            }
        }
 internal void RemoveErrorsForArtifact(EFArtifact artifact, ErrorClass errorClass)
 {
     if (_artifacts2Errors.ContainsKey(artifact))
     {
         var errorClass2ErrorInfo = _artifacts2Errors[artifact];
         foreach (var errorInfos in GetErrorInfosUsingMask(errorClass2ErrorInfo, errorClass))
         {
             errorInfos.Clear();
         }
     }
 }
 internal EFArtifactSet(EFArtifact artifact)
 {
     Add(artifact);
 }
        /// <summary>
        ///     This will remove all errors that are tied to a specified artifact.
        ///     This is necessary for cases such as rename, where we don't want validation post-rename to contain
        ///     the errors for the old artifact (resulting in duplicate errors)
        /// </summary>
        /// <param name="artifact"></param>
        internal void RemoveErrorsForArtifact(EFArtifact artifact)
        {
            if (_artifacts2Errors.ContainsKey(artifact))
            {
                var errorClass2ErrorInfo = _artifacts2Errors[artifact];
                foreach (var errorsForClass in errorClass2ErrorInfo.Values)
                {
                    // store these off because we can't remove while iterating
                    var errorsToRemove = new List<ErrorInfo>();

                    // find any errors that reference the passed in item
                    foreach (var errorInfo in errorsForClass)
                    {
                        if (errorInfo.Item.Artifact == artifact)
                        {
                            errorsToRemove.Add(errorInfo);
                        }
                    }

                    // go remove the ones we found
                    foreach (var removeMe in errorsToRemove)
                    {
                        errorsForClass.Remove(removeMe);
                    }
                }
            }
        }
        /// <summary>
        ///     Remove an artifact from this artifact set, and clear all symbols defined by the artifact
        /// </summary>
        /// <param name="artifact"></param>
        internal void RemoveArtifact(EFArtifact artifact)
        {
            // need to also remove the symbols for this artifact
            var keysToRemove = new List<Symbol>();

            foreach (var key in _symbolTable.Keys)
            {
                var symbolValues = _symbolTable[key];
                for (var i = symbolValues.Count - 1; i >= 0; i--)
                {
                    var item = symbolValues[i];
                    if (item.Artifact == artifact)
                    {
                        symbolValues.RemoveAt(i);
                    }
                }

                if (symbolValues.Count == 0)
                {
                    keysToRemove.Add(key);
                }
            }

            foreach (var keyToRemove in keysToRemove)
            {
                _symbolTable.Remove(keyToRemove);
            }

            _artifacts2Errors.Remove(artifact);
        }
 internal EntityDesignArtifactSet(EFArtifact artifact)
     : base(artifact)
 {
 }
Exemple #43
0
 internal EFArtifactSet(EFArtifact artifact)
 {
     Add(artifact);
 }
 private static bool IsArtifactDesignerSafe(EFArtifact artifact)
 {
     // if the artifact needs to be reloaded, treat it as designer-unsafe for our purposes.
     // this should only be the case when editing in the xml editor, and our selection container
     // gets invoked.
     if (artifact.RequireDelayedReload)
     {
         return false;
     }
     return artifact.IsDesignerSafe;
 }
Exemple #45
0
 internal void Add(EFArtifact artifact)
 {
     _artifacts2Errors.Add(artifact, new Dictionary <ErrorClass, ICollection <ErrorInfo> >());
 }
 /// <summary>
 ///     Gets the AttributeContentValidator used for validating xml attribute values for this ModelManager.
 /// </summary>
 internal abstract AttributeContentValidator GetAttributeContentValidator(EFArtifact artifact);
Exemple #47
0
 protected EFRuntimeModelRoot(EFArtifact parent, XElement element)
     : base(parent, element)
 {
 }
        internal static void ProcessStoredProcedureReturnTypeInformation(
            EFArtifact artifact,
            Dictionary<EntityStoreSchemaFilterEntry, IDataSchemaProcedure> newFunctionSchemaProceduresMap, IList<Command> commands,
            bool shouldCreateComposableFunctionImports)
        {
            if (null == artifact)
            {
                Debug.Fail("null artifact");
                return;
            }

            if (null == newFunctionSchemaProceduresMap)
            {
                Debug.Fail("Null newFunctionSchemaProceduresMap for artifact " + artifact.Uri);
                return;
            }

            var sem = artifact.StorageModel();
            if (null == sem)
            {
                Debug.Fail("Null StorageEntityModel for artifact " + artifact.Uri);
                return;
            }

            var storageEntityContainerName = sem.FirstEntityContainer.LocalName.Value;
            if (string.IsNullOrWhiteSpace(storageEntityContainerName))
            {
                Debug.Fail("Null or whitespace StorageEntityContainerName for artifact " + artifact.Uri);
                return;
            }

            foreach (var entry in newFunctionSchemaProceduresMap.Keys)
            {
                var schemaProcedure = newFunctionSchemaProceduresMap[entry];
                Command cmd = null;
                if (null == schemaProcedure)
                {
                    // schemaProcedure information was not collected - so delete the Function
                    var dbObj = DatabaseObject.CreateFromEntityStoreSchemaFilterEntry(entry, storageEntityContainerName);
                    var func = ModelHelper.FindFunction(sem, dbObj);
                    Debug.Assert(func != null, "Could not find Function to delete matching Database Object " + dbObj.ToString());
                    if (null != func)
                    {
                        cmd = func.GetDeleteCommand();
                    }
                }
                else
                {
                    cmd = new CreateMatchingFunctionImportCommand(schemaProcedure, shouldCreateComposableFunctionImports);
                }

                if (null != cmd)
                {
                    commands.Add(cmd);
                }
            }
        }
 /// <summary>
 ///     This will return a collection of errors for the artifact only (without traversing children).
 /// </summary>
 /// <param name="artifact"></param>
 internal ICollection<ErrorInfo> GetArtifactOnlyErrors(EFArtifact artifact)
 {
     var errors = new List<ErrorInfo>();
     var errorClass2ErrorInfo = _artifacts2Errors[artifact];
     foreach (var errorsForClass in errorClass2ErrorInfo.Values)
     {
         errors.AddRange(errorsForClass);
     }
     return errors;
 }
 internal static string GetDatabaseSchemaNameFromArtifact(EFArtifact artifact)
 {
     var databaseSchemaName = ModelHelper.GetDesignerPropertyValueFromArtifact(
         OptionsDesignerInfo.ElementName, OptionsDesignerInfo.AttributeDatabaseSchemaName, artifact);
     if (String.IsNullOrEmpty(databaseSchemaName))
     {
         // There is probably not a DesignerProperty under the DesignerInfoPropertySet or there may not even
         // be a DesignerInfoPropertySet under the DesignerInfo. In this case, we will just use the default value
         // of the database schema name
         databaseSchemaName = DefaultDatabaseSchemaName;
     }
     return databaseSchemaName;
 }
        /// <summary>
        ///     This method will do the following.
        ///     - Add EFArtifact reference to the EFArtifactSet.
        ///     - Update artifactsByUri and artifact2ArtifactSet dictionaries.
        ///     - Initialize the EFArtifact.
        /// </summary>
        /// <param name="efArtifact"></param>
        /// <param name="efArtifactSet"></param>
        internal void RegisterArtifact(EFArtifact efArtifact, EFArtifactSet efArtifactSet)
        {
            Debug.Assert(
                _artifactsByUri.ContainsKey(efArtifact.Uri) == false && _artifact2ArtifactSets.ContainsKey(efArtifact) == false,
                "This artifact has been registered in model manager.");

            if (_artifactsByUri.ContainsKey(efArtifact.Uri) == false
                && _artifact2ArtifactSets.ContainsKey(efArtifact) == false)
            {
                if (efArtifactSet.Artifacts.Contains(efArtifact) == false)
                {
                    efArtifactSet.Add(efArtifact);
                }

                _artifactsByUri[efArtifact.Uri] = efArtifact;

                var artifactSetList = new List<EFArtifactSet>(1);
                artifactSetList.Add(efArtifactSet);
                _artifact2ArtifactSets[efArtifact] = artifactSetList;
                efArtifact.Init();
            }
        }
 internal void Add(EFArtifact artifact)
 {
     _artifacts2Errors.Add(artifact, new Dictionary<ErrorClass, ICollection<ErrorInfo>>());
 }
 internal EntityDesignArtifactSet(EFArtifact artifact)
     : base(artifact)
 {
 }
        private void GetAllErrorsForArtifact(EFArtifact artifact, List<ErrorInfo> allErrors)
        {
            var errorClass2ErrorInfo = _artifacts2Errors[artifact];
            foreach (var errorsForClass in errorClass2ErrorInfo.Values)
            {
                allErrors.AddRange(errorsForClass);
            }

            allErrors.AddRange(artifact.GetAllParseErrorsForArtifact());
        }
Exemple #55
0
 internal override AttributeContentValidator GetAttributeContentValidator(EFArtifact artifact)
 {
     return(EscherAttributeContentValidator.GetInstance(artifact.SchemaVersion));
 }
        internal void GetErrorsForArtifact(EFArtifact artifact, List<ErrorInfo> errors, ErrorClass errorClass)
        {
            Dictionary<ErrorClass, ICollection<ErrorInfo>> errorClass2ErrorInfo = null;

            _artifacts2Errors.TryGetValue(artifact, out errorClass2ErrorInfo);

            if (errorClass2ErrorInfo != null)
            {
                foreach (var e in GetErrorInfosUsingMask(errorClass2ErrorInfo, errorClass))
                {
                    errors.AddRange(e);
                }
            }
        }
 internal static string GetTemplatePathFromArtifact(EFArtifact artifact)
 {
     var templatePath = ModelHelper.GetDesignerPropertyValueFromArtifact(
         OptionsDesignerInfo.ElementName, OptionsDesignerInfo.AttributeDDLGenerationTemplate, artifact);
     if (String.IsNullOrEmpty(templatePath))
     {
         // There is probably not a DesignerProperty under the DesignerInfoPropertySet or there may not even
         // be a DesignerInfoPropertySet under the DesignerInfo. In this case, we will just use the default value
         // of the workflow path.
         templatePath = DefaultTemplatePath;
     }
     return templatePath;
 }
 private static bool ValidateArtifactAndWriteErrors(EFArtifact artifact, VSFileFinder.VSFileInfo vsFileInfo, bool doEscherValidation)
 {
     return ValidateArtifactAndWriteErrors(artifact, vsFileInfo.Hierarchy, vsFileInfo.ItemId, doEscherValidation);
 }
Exemple #59
0
        // <summary>
        //     Enable/Disable code generation for an edmx project item.
        // </summary>
        internal static Command SetCodeGenStrategyToNoneCommand(EFArtifact artifact)
        {
            Debug.Assert(artifact != null, "Artifact should not be null");
            var existingCodeGenStrategy = ModelHelper.GetDesignerPropertyValueFromArtifact(
                OptionsDesignerInfo.ElementName, OptionsDesignerInfo.AttributeCodeGenerationStrategy, artifact);
            if (string.IsNullOrWhiteSpace(existingCodeGenStrategy))
            {
                existingCodeGenStrategy = Resources.Default; // which is the default value of CodeGenerationStrategy attribute
            }

            if (!string.Equals(existingCodeGenStrategy, Resources.None))
            {
                return ModelHelper.CreateSetDesignerPropertyValueCommandFromArtifact(
                    artifact, OptionsDesignerInfo.ElementName,
                    OptionsDesignerInfo.AttributeCodeGenerationStrategy,
                    Resources.None);
            }

            return null;
        }
        private static bool ValidateArtifactAndWriteErrors(
            EFArtifact artifact, IVsHierarchy hierarchy, uint itemId, bool doEscherValidation)
        {
            Debug.Assert(artifact != null, "artifact != null!");
            Debug.Assert(hierarchy != null, "project hierarchy is null!");
            Debug.Assert(itemId != VSConstants.VSITEMID_NIL, "itemid is nil");

            var errorList = ErrorListHelper.GetSingleDocErrorList(hierarchy, itemId);
            Debug.Assert(errorList != null, "Couldn't get error list for artifact " + artifact.Uri);

            errorList.Clear();

            var artifactSet = (EntityDesignArtifactSet)artifact.ArtifactSet;
            Debug.Assert(
                artifactSet.Artifacts.OfType<EntityDesignArtifact>().Count() == 1,
                "Expected there is 1 instance of EntityDesignArtifact; Actual:" +
                artifactSet.Artifacts.OfType<EntityDesignArtifact>().Count());

            VsUtils.EnsureProvider(artifact);
            ((EntityDesignModelManager)artifact.ModelManager)
                .ValidateAndCompileMappings(artifactSet, doEscherValidation);

            var errors = artifactSet.GetArtifactOnlyErrors(artifact);

            if (errors.Count > 0)
            {
                ErrorListHelper.AddErrorInfosToErrorList(errors, hierarchy, itemId, errorList);
                return false;
            }

            return true;
        }