private static ErrorLog EnsureAllCSpaceContainerSetsAreMapped(
            IEnumerable <Cell> cells,
            EntityContainerMapping containerMapping)
        {
            Set <EntitySetBase> set             = new Set <EntitySetBase>();
            EntityContainer     entityContainer = (EntityContainer)null;

            foreach (Cell cell in cells)
            {
                set.Add(cell.CQuery.Extent);
                string sourceLocation = cell.CellLabel.SourceLocation;
                entityContainer = cell.CQuery.Extent.EntityContainer;
            }
            List <EntitySetBase> entitySetBaseList = new List <EntitySetBase>();

            foreach (EntitySetBase baseEntitySet in entityContainer.BaseEntitySets)
            {
                if (!set.Contains(baseEntitySet) && !containerMapping.HasQueryViewForSetMap(baseEntitySet.Name))
                {
                    AssociationSet associationSet = baseEntitySet as AssociationSet;
                    if (associationSet == null || !associationSet.ElementType.IsForeignKey)
                    {
                        entitySetBaseList.Add(baseEntitySet);
                    }
                }
            }
            ErrorLog errorLog = new ErrorLog();

            if (entitySetBaseList.Count > 0)
            {
                StringBuilder stringBuilder = new StringBuilder();
                bool          flag          = true;
                foreach (EntitySetBase entitySetBase in entitySetBaseList)
                {
                    if (!flag)
                    {
                        stringBuilder.Append(", ");
                    }
                    flag = false;
                    stringBuilder.Append(entitySetBase.Name);
                }
                string message = Strings.ViewGen_Missing_Set_Mapping((object)stringBuilder);
                int    num     = -1;
                foreach (Cell cell in cells)
                {
                    if (num == -1 || cell.CellLabel.StartLineNumber < num)
                    {
                        num = cell.CellLabel.StartLineNumber;
                    }
                }
                ErrorLog.Record record = new ErrorLog.Record(new EdmSchemaError(message, 3027, EdmSchemaErrorSeverity.Error, containerMapping.SourceLocation, containerMapping.StartLineNumber, containerMapping.StartLinePosition, (Exception)null));
                errorLog.AddEntry(record);
            }
            return(errorLog);
        }
        // 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,
            EntityContainerMapping containerMapping)
        {
            var 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 (var 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);

            var missingExtents = new List<EntitySetBase>();
            // Go through all the extents in the container and determine
            // extents that are missing
            foreach (var extent in container.BaseEntitySets)
            {
                if (mappedExtents.Contains(extent) == false
                    && !(containerMapping.HasQueryViewForSetMap(extent.Name)))
                {
                    var associationSet = extent as AssociationSet;
                    if (associationSet == null
                        || !associationSet.ElementType.IsForeignKey)
                    {
                        missingExtents.Add(extent);
                    }
                }
            }
            var errorLog = new ErrorLog();
            // If any extent is not mapped, add an error
            if (missingExtents.Count > 0)
            {
                var extentBuilder = new StringBuilder();
                var isFirst = true;
                foreach (var extent in missingExtents)
                {
                    if (isFirst == false)
                    {
                        extentBuilder.Append(", ");
                    }
                    isFirst = false;
                    extentBuilder.Append(extent.Name);
                }
                var message = Strings.ViewGen_Missing_Set_Mapping(extentBuilder);
                // Find the cell with smallest line number - so that we can
                // point to the beginning of the file
                var lowestLineNum = -1;
                Cell smallestCell = null;
                foreach (var cell in cells)
                {
                    if (lowestLineNum == -1
                        || cell.CellLabel.StartLineNumber < lowestLineNum)
                    {
                        smallestCell = cell;
                        lowestLineNum = cell.CellLabel.StartLineNumber;
                    }
                }
                Debug.Assert(smallestCell != null && lowestLineNum >= 0);
                var edmSchemaError = new EdmSchemaError(
                    message, (int)ViewGenErrorCode.MissingExtentMapping,
                    EdmSchemaErrorSeverity.Error, containerMapping.SourceLocation, containerMapping.StartLineNumber,
                    containerMapping.StartLinePosition, null);
                var record = new ErrorLog.Record(edmSchemaError);
                errorLog.AddEntry(record);
            }
            return errorLog;
        }
Exemple #3
0
        // 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,
            EntityContainerMapping containerMapping)
        {
            var             mappedExtents = new Set <EntitySetBase>();
            EntityContainer container     = null;

            // Determine the container and name of the file while determining
            // the set of mapped extents in the cells
            foreach (var cell in cells)
            {
                mappedExtents.Add(cell.CQuery.Extent);
                // All cells are from the same container
                container = cell.CQuery.Extent.EntityContainer;
            }
            Debug.Assert(container != null);

            var missingExtents = new List <EntitySetBase>();

            // Go through all the extents in the container and determine
            // extents that are missing
            foreach (var extent in container.BaseEntitySets)
            {
                if (mappedExtents.Contains(extent) == false &&
                    !(containerMapping.HasQueryViewForSetMap(extent.Name)))
                {
                    var associationSet = extent as AssociationSet;
                    if (associationSet == null ||
                        !associationSet.ElementType.IsForeignKey)
                    {
                        missingExtents.Add(extent);
                    }
                }
            }
            var errorLog = new ErrorLog();

            // If any extent is not mapped, add an error
            if (missingExtents.Count > 0)
            {
                var extentBuilder = new StringBuilder();
                var isFirst       = true;
                foreach (var extent in missingExtents)
                {
                    if (isFirst == false)
                    {
                        extentBuilder.Append(", ");
                    }
                    isFirst = false;
                    extentBuilder.Append(extent.Name);
                }
                var message = Strings.ViewGen_Missing_Set_Mapping(extentBuilder);
                // Find the cell with smallest line number - so that we can
                // point to the beginning of the file
                var  lowestLineNum = -1;
                Cell smallestCell  = null;
                foreach (var cell in cells)
                {
                    if (lowestLineNum == -1 ||
                        cell.CellLabel.StartLineNumber < lowestLineNum)
                    {
                        smallestCell  = cell;
                        lowestLineNum = cell.CellLabel.StartLineNumber;
                    }
                }
                Debug.Assert(smallestCell != null && lowestLineNum >= 0);
                var edmSchemaError = new EdmSchemaError(
                    message, (int)ViewGenErrorCode.MissingExtentMapping,
                    EdmSchemaErrorSeverity.Error, containerMapping.SourceLocation, containerMapping.StartLineNumber,
                    containerMapping.StartLinePosition, null);
                var record = new ErrorLog.Record(edmSchemaError);
                errorLog.AddEntry(record);
            }
            return(errorLog);
        }