internal static void AddErrorInfosToErrorList( ICollection <ErrorInfo> errors, IVsHierarchy vsHierarchy, uint itemID, DesignerErrorList errorList, bool bringErrorListToFront = false) { errorList.Clear(); var errorCount = 0; foreach (var error in errors) { if (errorCount++ > 99) { break; } var errorTask = EFModelErrorTaskFactory.CreateErrorTask(error, vsHierarchy, itemID); errorList.AddItem(errorTask); } if (errors.Count > 0) { errorList.Provider.Show(); if (bringErrorListToFront) { errorList.Provider.BringToFront(); } } }
// <summary> // This method will log errors to the "Wizard" Multi-doc error list. // </summary> private static void LogWizardErrors(IEnumerable <EdmSchemaError> errors, ProjectItem projectItem, MARKERTYPE markerType) { if (null == errors) { throw new ArgumentNullException("errors"); } if (null == projectItem) { throw new ArgumentNullException("projectItem"); } if (PackageManager.Package != null) { var hierarchy = VsUtils.GetVsHierarchy(projectItem.ContainingProject, Services.ServiceProvider); var itemId = VsUtils.GetProjectItemId(hierarchy, projectItem); var errorList = WizardErrorList; var errorCount = 0; foreach (var error in errors) { // only display the first 100 errors. VS gets really slow if you try to display more if (errorCount++ > 99) { break; } var category = TaskErrorCategory.Message; if (error.Severity == EdmSchemaErrorSeverity.Error) { category = TaskErrorCategory.Error; } else if (error.Severity == EdmSchemaErrorSeverity.Warning) { category = TaskErrorCategory.Message; } string filePath = null; var fullPathProperty = projectItem.Properties.Item("FullPath"); if (fullPathProperty != null) { filePath = fullPathProperty.Value as String; } if (filePath == null) { filePath = projectItem.Name; } var textSpan = new TextSpan(); textSpan.iStartLine = error.Line; textSpan.iStartIndex = error.Column; textSpan.iEndLine = error.Line + 1; textSpan.iEndIndex = error.Column + 1; errorList.AddItem( EFModelErrorTaskFactory.CreateErrorTask(filePath, error.Message, textSpan, category, hierarchy, itemId, markerType)); } } }
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); }