Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        int IVsSolutionEvents.OnAfterCloseSolution(object pUnkReserved)
        {
            // Clear and remove all error lists when the solution is closed
            ErrorListHelper.RemoveAll();

            IsAfterErrorListClearedOnSolutionClose = true;

            return(VSConstants.S_OK);
        }
Ejemplo n.º 3
0
        internal static bool LoadAndValidateAllFilesInProject(
            IVsHierarchy pHierProj, bool doEscherValidation, Func <EFArtifact, bool> shouldValidateArtifact)
        {
            // clear all errors for this project
            ErrorListHelper.ClearHierarchyErrors(pHierProj);

            var fileFinder = new VSFileFinder(EntityDesignArtifact.ExtensionEdmx);

            fileFinder.FindInProject(pHierProj);

            var edmxFilesToValidate = new List <VSFileFinder.VSFileInfo>(fileFinder.MatchingFiles);

            return(LoadAndValidateFiles(edmxFilesToValidate, doEscherValidation, shouldValidateArtifact));
        }
Ejemplo n.º 4
0
        private static bool LoadAndValidateFiles(
            IEnumerable <VSFileFinder.VSFileInfo> edmxFilesToValidate, bool doEscherValidation, Func <EFArtifact, bool> shouldValidateArtifact)
        {
            var validationSuccessful = true;

            // load all the artifacts, and clear out the error list for them.
            using (var modelManager = new EntityDesignModelManager(new VSArtifactFactory(), new VSArtifactSetFactory()))
            {
                foreach (var vsFileInfo in edmxFilesToValidate)
                {
                    var uri = Utils.FileName2Uri(vsFileInfo.Path);
                    try
                    {
                        var artifact = GetArtifactForValidation(uri, vsFileInfo.Hierarchy, modelManager);
                        if (artifact != null &&
                            shouldValidateArtifact(artifact))
                        {
                            // we need to continue validating even if validation for an artifact failed so just
                            // set the flag and continue validating.
                            if (!ValidateArtifactAndWriteErrors(artifact, vsFileInfo, doEscherValidation))
                            {
                                validationSuccessful = false;
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        // an exception occurred loading the document, so add an error for it into the error pane.
                        var errorList = ErrorListHelper.GetSingleDocErrorList(vsFileInfo.Hierarchy, vsFileInfo.ItemId);

                        Debug.Assert(errorList != null, "errorList is null!");

                        errorList.AddItem(
                            EFModelErrorTaskFactory
                            .CreateErrorTask(uri.LocalPath, e, vsFileInfo.Hierarchy, vsFileInfo.ItemId));

                        validationSuccessful = false;
                    }
                }
            }

            return(validationSuccessful);
        }
Ejemplo n.º 5
0
 public void AddErrorInfosToErrorList(ICollection <ErrorInfo> errors, IVsHierarchy vsHierarchy, uint itemID, bool bringErrorListToFront = false)
 {
     ErrorListHelper.AddErrorInfosToErrorList(errors, vsHierarchy, itemID, bringErrorListToFront);
 }