public void Ctor_sets_properties() { var message = "Some message"; var errors = new EdmSchemaError[0]; var ex = new EdmSchemaErrorException(message, errors); Assert.Equal(message, ex.Message); Assert.Same(errors, ex.Errors); }
public void Is_serializable() { var message = "Some message"; var errors = new EdmSchemaError[0]; var formatter = new BinaryFormatter(); EdmSchemaErrorException ex; using (var stream = new MemoryStream()) { formatter.Serialize(stream, new EdmSchemaErrorException(message, errors)); stream.Position = 0; ex = (EdmSchemaErrorException)formatter.Deserialize(stream); } Assert.Equal(message, ex.Message); Assert.Equal(errors, ex.Errors); }
/// <summary> /// Creates generated view object for the combination of the <paramref name="setMapping"/>.Set and the <paramref name="type"/>. /// This constructor is used for user-defined query views only. /// </summary> internal static bool TryParseUserSpecifiedView(StorageSetMapping setMapping, EntityTypeBase type, string eSQL, bool includeSubtypes, StorageMappingItemCollection mappingItemCollection, ConfigViewGenerator config, /*out*/ IList<EdmSchemaError> errors, out GeneratedView generatedView) { bool failed = false; DbQueryCommandTree commandTree; DiscriminatorMap discriminatorMap; Exception parserException; if (!GeneratedView.TryParseView(eSQL, true, setMapping.Set, mappingItemCollection, config, out commandTree, out discriminatorMap, out parserException)) { EdmSchemaError error = new EdmSchemaError(System.Data.Entity.Strings.Mapping_Invalid_QueryView2(setMapping.Set.Name, parserException.Message), (int)StorageMappingErrorCode.InvalidQueryView, EdmSchemaErrorSeverity.Error, setMapping.EntityContainerMapping.SourceLocation, setMapping.StartLineNumber, setMapping.StartLinePosition, parserException); errors.Add(error); failed = true; } else { Debug.Assert(commandTree != null, "commandTree not set after parsing the view"); // Verify that all expressions appearing in the view are supported. foreach (var error in ViewValidator.ValidateQueryView(commandTree, setMapping, type, includeSubtypes)) { errors.Add(error); failed = true; } // Verify that the result type of the query view is assignable to the element type of the entityset CollectionType queryResultType = (commandTree.Query.ResultType.EdmType) as CollectionType; if ((queryResultType == null) || (!setMapping.Set.ElementType.IsAssignableFrom(queryResultType.TypeUsage.EdmType))) { EdmSchemaError error = new EdmSchemaError(System.Data.Entity.Strings.Mapping_Invalid_QueryView_Type(setMapping.Set.Name), (int)StorageMappingErrorCode.InvalidQueryViewResultType, EdmSchemaErrorSeverity.Error, setMapping.EntityContainerMapping.SourceLocation, setMapping.StartLineNumber, setMapping.StartLinePosition); errors.Add(error); failed = true; } } if (!failed) { generatedView = new GeneratedView(setMapping.Set, type, commandTree, eSQL, discriminatorMap, mappingItemCollection, config); return true; } else { generatedView = null; return false; } }
/// <summary> /// /// </summary> /// <param name="errorCode"></param> /// <param name="severity"></param> /// <param name="source"></param> /// <param name="lineNumber"></param> /// <param name="linePosition"></param> /// <param name="message"></param> private void AddError( ErrorCode errorCode, EdmSchemaErrorSeverity severity, string sourceLocation, int lineNumber, int linePosition, object message ) { EdmSchemaError error = null; string messageString = message as string; if ( messageString != null ) error = new EdmSchemaError( messageString, (int)errorCode, severity, sourceLocation, lineNumber, linePosition ); else { Exception ex = message as Exception; if ( ex != null ) error = new EdmSchemaError( ex.Message, (int)errorCode, severity, sourceLocation, lineNumber, linePosition, ex ); else error = new EdmSchemaError( message.ToString(), (int)errorCode, severity, sourceLocation, lineNumber, linePosition ); } Schema.AddError(error); }
// effects: Given a container, ensures that all entity/association // sets in container on the C-side have been mapped private static ErrorLog EnsureAllCSpaceContainerSetsAreMapped(IEnumerable<Cell> cells, ConfigViewGenerator config, StorageEntityContainerMapping containerMapping) { Set<EntitySetBase> mappedExtents = new Set<EntitySetBase>(); string mslFileLocation = null; EntityContainer container = null; // Determine the container and name of the file while determining // the set of mapped extents in the cells foreach (Cell cell in cells) { mappedExtents.Add(cell.CQuery.Extent); mslFileLocation = cell.CellLabel.SourceLocation; // All cells are from the same container container = cell.CQuery.Extent.EntityContainer; } Debug.Assert(container != null); List<EntitySetBase> missingExtents = new List<EntitySetBase>(); // Go through all the extents in the container and determine // extents that are missing foreach (EntitySetBase extent in container.BaseEntitySets) { if (mappedExtents.Contains(extent) == false && !(containerMapping.HasQueryViewForSetMap(extent.Name))) { AssociationSet associationSet = extent as AssociationSet; if (associationSet==null || !associationSet.ElementType.IsForeignKey) { missingExtents.Add(extent); } } } ErrorLog errorLog = new ErrorLog(); // If any extent is not mapped, add an error if (missingExtents.Count > 0) { StringBuilder extentBuilder = new StringBuilder(); bool isFirst = true; foreach (EntitySetBase extent in missingExtents) { if (isFirst == false) { extentBuilder.Append(", "); } isFirst = false; extentBuilder.Append(extent.Name); } string message = System.Data.Entity.Strings.ViewGen_Missing_Set_Mapping(extentBuilder); // Find the cell with smallest line number - so that we can // point to the beginning of the file int lowestLineNum = -1; Cell smallestCell = null; foreach (Cell cell in cells) { if (lowestLineNum == -1 || cell.CellLabel.StartLineNumber < lowestLineNum) { smallestCell = cell; lowestLineNum = cell.CellLabel.StartLineNumber; } } Debug.Assert(smallestCell != null && lowestLineNum >= 0); EdmSchemaError edmSchemaError = new EdmSchemaError(message, (int)ViewGenErrorCode.MissingExtentMapping, EdmSchemaErrorSeverity.Error, containerMapping.SourceLocation, containerMapping.StartLineNumber, containerMapping.StartLinePosition, null); ErrorLog.Record record = new ErrorLog.Record(edmSchemaError); errorLog.AddEntry(record); } return errorLog; }
private void Init(bool isError, ViewGenErrorCode errorCode, string message, IEnumerable<Cell> sourceCells, string debugMessage) { m_sourceCells = new List<Cell>(sourceCells); Debug.Assert(m_sourceCells.Count > 0, "Error record must have at least one cell"); // For certain foreign key messages, we may need the SSDL line numbers and file names CellLabel label = m_sourceCells[0].CellLabel; string sourceLocation = label.SourceLocation; int lineNumber = label.StartLineNumber; int columnNumber = label.StartLinePosition; string userMessage = InternalToString(message, debugMessage, m_sourceCells, sourceLocation, errorCode, isError, false); m_debugMessage = InternalToString(message, debugMessage, m_sourceCells, sourceLocation, errorCode, isError, true); m_mappingError = new EdmSchemaError(userMessage, (int)errorCode, EdmSchemaErrorSeverity.Error, sourceLocation, lineNumber, columnNumber); }
//There are cases when we want to create a ViewGen error that is not specific to any mapping fragment //In this case, it is better to just create the EdmSchemaError directly and hold on to it. internal Record(EdmSchemaError error) { m_debugMessage = error.ToString(); m_mappingError = error; }
internal void AddError(EdmSchemaError error) { _errors.Add(error); }
internal bool ValidateTypeConditions(bool validateAmbiguity, IList<EdmSchemaError> errors, string sourceLocation) { // Verify that all types can be produced KeyToListMap<EntityType, LineInfo> unreachableEntityTypes; KeyToListMap<EntityType, LineInfo> unreachableIsTypeOfs; GetUnreachableTypes(validateAmbiguity, out unreachableEntityTypes, out unreachableIsTypeOfs); var valid = true; foreach (var unreachableEntityType in unreachableEntityTypes.KeyValuePairs) { var lineInfo = unreachableEntityType.Value.First(); var lines = StringUtil.ToCommaSeparatedString(unreachableEntityType.Value.Select(li => li.LineNumber)); var error = new EdmSchemaError( Strings.Mapping_FunctionImport_UnreachableType(unreachableEntityType.Key.FullName, lines), (int)StorageMappingErrorCode.MappingFunctionImportAmbiguousTypeConditions, EdmSchemaErrorSeverity.Error, sourceLocation, lineInfo.LineNumber, lineInfo.LinePosition); errors.Add(error); valid = false; } foreach (var unreachableIsTypeOf in unreachableIsTypeOfs.KeyValuePairs) { var lineInfo = unreachableIsTypeOf.Value.First(); var lines = StringUtil.ToCommaSeparatedString(unreachableIsTypeOf.Value.Select(li => li.LineNumber)); var isTypeOfDescription = StorageMslConstructs.IsTypeOf + unreachableIsTypeOf.Key.FullName + StorageMslConstructs.IsTypeOfTerminal; var error = new EdmSchemaError( Strings.Mapping_FunctionImport_UnreachableIsTypeOf(isTypeOfDescription, lines), (int)StorageMappingErrorCode.MappingFunctionImportAmbiguousTypeConditions, EdmSchemaErrorSeverity.Error, sourceLocation, lineInfo.LineNumber, lineInfo.LinePosition); errors.Add(error); valid = false; } return valid; }
private static void WriteError(EdmSchemaError e) { if (e.Severity == EdmSchemaErrorSeverity.Error) { Console.Write("Error: "); } else { Console.Write("Warning: "); } Console.WriteLine(e.Message); }
private static void WriteError(EdmSchemaError e) { string error = string.Empty; if (e.Severity == EdmSchemaErrorSeverity.Error) { //Console.Write("Error: "); error += "Error: "; } else { //Console.Write("Warning: "); error += "Warning: "; } error += e.Message; Errors.Add(error); //Console.WriteLine(e.Message); }