Exemplo n.º 1
0
        /// <summary>
        /// Match either side of a : delimited string or all of the string including the delimiter
        /// </summary>
        /// <param name="hashSet">List of strings</param>
        /// <param name="foreignKeyValue">string to match</param>
        /// <returns>true if a match, false if none</returns>
        private bool PickListMatch(COBieColumnRelationship reference, COBieCell cell)
        {
            if (cell.CellValue == Constants.DEFAULT_STRING)
            {
                return(false);
            }

            if (reference.HasKeyMatch(cell.CellValue))
            {
                return(true);
            }

            // There are no current cases where PickLists can have Many to Many mappings - only One to Many. So don't worry about MultipleValues.

            // Due to the way some Categories/Classifications in Pick lists are compound keys (e.g. 11-11 11 14: Exhibition Hall ... where the code and name are stored separately in IFC)
            // we need to special case partial matches, since we may have the code, name, or code:name (perhaps with differing white space)

            if (cell.CellValue.Contains(":")) //assume category split
            {
                return(reference.HasPartialMatch(cell.CellValue, ':'));
            }


            return(false);
        }
Exemplo n.º 2
0
        /// <summary>
        ///  Validate system sheet for merge types in ComponentName, depending on the role of the model this worksheet was built from
        /// </summary>
        /// <param name="names">string list holding the name properties removed from the component sheet</param>
        /// <returns>Number removed</returns>
        public int ValidateSystemMerge(List <string> names)
        {
            COBieColumn compName   = Columns.Where(c => c.Value.ColumnName == "ComponentNames").Select(c => c.Value).FirstOrDefault();
            List <T>    RemainRows = new List <T>();

            if (compName != null)
            {
                for (int i = 0; i < Rows.Count; i++)
                {
                    COBieRow  row           = Rows[i];
                    COBieCell cell          = row[compName.ColumnOrder];
                    string    componentName = cell.CellValue;
                    if (names.Contains(componentName))
                    {
                        RowsRemoved.Add((T)row);
                    }
                    else
                    {
                        RemainRows.Add((T)row);
                    }
                }
                Rows = RemainRows;
            }
            return(RowsRemoved.Count);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Validate type sheet for merge types depending on the role of the model this worksheet was built from
        /// </summary>
        ///<param name="GlobalIds">List of GlobalId's</param>
        ///<returns>Number of rows removed</returns>
        public int ValidateTypeMerge(List <string> GlobalIds)
        {
            COBieColumn colExtId   = Columns.Where(c => c.Value.ColumnName == "ExtIdentifier").Select(c => c.Value).FirstOrDefault();
            List <T>    RemainRows = new List <T>();

            if (colExtId != null)
            {
                for (int i = 0; i < Rows.Count; i++)
                {
                    COBieRow  row   = Rows[i];
                    COBieCell cell  = row[colExtId.ColumnOrder];
                    string    extId = cell.CellValue;
                    if (GlobalIds.Contains(extId))
                    {
                        RowsRemoved.Add((T)row);
                    }
                    else
                    {
                        RemainRows.Add((T)row);
                    }
                }
                Rows = RemainRows;
            }
            return(RowsRemoved.Count);
        }
Exemplo n.º 4
0
        /// <summary>
        ///  Validate attribute sheet for merge types depending on the role of the model this worksheet was built from
        /// </summary>
        /// <param name="keys">string list holding the sheetname and name property concatenated together</param>
        /// <returns>Number removed</returns>
        public int ValidateAttributeMerge(List <string> keys)
        {
            COBieColumn colSheet   = Columns.Where(c => c.Value.ColumnName == "SheetName").Select(c => c.Value).FirstOrDefault();
            COBieColumn colName    = Columns.Where(c => c.Value.ColumnName == "RowName").Select(c => c.Value).FirstOrDefault();
            List <T>    RemainRows = new List <T>();

            if ((colSheet != null) && (colName != null))
            {
                for (int i = 0; i < Rows.Count; i++)
                {
                    COBieRow  row       = Rows[i];
                    COBieCell cellSheet = row[colSheet.ColumnOrder];
                    string    sheetName = cellSheet.CellValue;
                    COBieCell cellName  = row[colName.ColumnOrder];
                    string    rowName   = cellName.CellValue;
                    if (keys.Contains(sheetName + rowName))
                    {
                        RowsRemoved.Add((T)row);
                    }
                    else
                    {
                        RemainRows.Add((T)row);
                    }
                }
                Rows = RemainRows;
            }
            return(RowsRemoved.Count);
        }
Exemplo n.º 5
0
        public COBieCell this[int i]
        {
            get
            {
                COBieColumn cobieColumn = ParentSheet.Columns.Where(idxcol => idxcol.Key == i).Select(idxcol => idxcol.Value).FirstOrDefault();
                if (cobieColumn != null)
                {
                    object pVal = cobieColumn.PropertyInfo.GetValue(this, null);

                    string    cellValue = (pVal != null) ? pVal.ToString() : Constants.DEFAULT_STRING;
                    COBieCell thiscell  = new COBieCell(cellValue, cobieColumn);
                    return(thiscell);
                }


                return(null);
            }
            set
            {
                COBieColumn cobieColumn = ParentSheet.Columns.Where(idxcol => idxcol.Key == i).Select(idxcol => idxcol.Value).FirstOrDefault();
                if (cobieColumn != null)
                {
                    cobieColumn.PropertyInfo.SetValue(this, value.CellValue, null);
                }
            }
        }
Exemplo n.º 6
0
        public COBieCell this[int i]
        {
            get
            {
                COBieColumn cobieColumn = ParentSheet.Columns.Where(idxcol => idxcol.Key == i).Select(idxcol => idxcol.Value).FirstOrDefault();
                if (cobieColumn != null)
                {
                    object pVal = cobieColumn.PropertyInfo.GetValue(this, null);

                    string cellValue = (pVal != null) ? pVal.ToString() : Constants.DEFAULT_STRING;
                    COBieCell thiscell = new COBieCell(cellValue, cobieColumn);
                    return thiscell;
                }
                
                
                return null;
            }
            set
            {
                COBieColumn cobieColumn = ParentSheet.Columns.Where(idxcol => idxcol.Key == i).Select(idxcol => idxcol.Value).FirstOrDefault();
                if (cobieColumn != null)
                    cobieColumn.PropertyInfo.SetValue(this, value.CellValue, null);

            }
            
        }
Exemplo n.º 7
0
        /// <summary>
        /// Validate the existence of the Foreign Key value on the referencing sheet, if not add error
        /// </summary>
        /// <param name="context">COBieContext object holding global values for this model</param>
        private void ValidateForeignKeys(COBieWorkbook workbook, ICOBieSheetValidationTemplate SheetValidator)
        {
            int rowIndex = 1;

            foreach (COBieRow row in Rows)
            {
                foreach (COBieColumn foreignKeyColumn in ForeignKeyColumns)
                {
                    // TODO: COBieColumn should own the relationship rather than creating a new one each time.
                    COBieColumnRelationship cobieReference = new COBieColumnRelationship(workbook, foreignKeyColumn);

                    if ((SheetValidator == null) ||
                        (SheetValidator.IsRequired.ContainsKey(foreignKeyColumn.ColumnOrder) && SheetValidator.IsRequired[foreignKeyColumn.ColumnOrder])
                        )
                    {
                        if (!string.IsNullOrEmpty(foreignKeyColumn.ReferenceColumnName))
                        {
                            COBieCell cell = row[foreignKeyColumn.ColumnOrder];

                            string foreignKeyValue = cell.CellValue;

                            // Don't validate nulls. Will be reported by the Foreign Key null value check, so just skip here
                            if (!string.IsNullOrEmpty(foreignKeyValue))
                            {
                                bool isValid = false;

                                bool isPickList = (cobieReference.SheetName == Constants.WORKSHEET_PICKLISTS);

                                if (isPickList)
                                {
                                    isValid = PickListMatch(cobieReference, cell);
                                }
                                else
                                {
                                    isValid = ForeignKeyMatch(cobieReference, cell);
                                }
                                //report no match
                                if (!isValid)
                                {
                                    string errorDescription = BuildErrorMessage(cobieReference, isPickList);

                                    COBieError.ErrorTypes errorType = isPickList == true
                                        ? COBieError.ErrorTypes.PickList_Violation
                                        : COBieError.ErrorTypes.ForeignKey_Violation;

                                    COBieError error = new COBieError(SheetName, foreignKeyColumn.ColumnName,
                                                                      errorDescription, errorType,
                                                                      COBieError.ErrorLevels.Error, row.InitialRowHashValue,
                                                                      foreignKeyColumn.ColumnOrder, rowIndex);
                                    _errors.Add(error);
                                }
                            }
                        }
                    }
                }
                rowIndex++;
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Check for Field format length
        /// </summary>
        /// <param name="cell">COBieCell</param>
        /// <param name="sheetName">Sheet name</param>
        /// <param name="row">Row index</param>
        /// <param name="col">Column index</param>
        /// <param name="initialRowHash">Initial row hash value</param>
        /// <returns>COBieError or null</returns>
        public COBieError GetCOBieFieldOutOfBoundsError(COBieCell cell, COBieAttributeState state, COBieError.ErrorLevels errorLevel, string sheetName, int row, int col, string initialRowHash)
        {
            COBieError err = new COBieError(sheetName, cell.COBieColumn.ColumnName, "", COBieError.ErrorTypes.None, COBieError.ErrorLevels.None, initialRowHash, col, row);

            int maxLength = cell.COBieColumn.ColumnLength;

            if (cell.CellValue.Length > maxLength)
            {
                err.ErrorDescription = String.Format(ErrorDescription.Value_Out_of_Bounds, maxLength);
                err.ErrorType        = COBieError.ErrorTypes.Value_Out_of_Bounds;
                err.ErrorLevel       = errorLevel; // GetErroLevel(cell.COBieColumn.AttributeState);
                err.FieldValue       = cell.CellValue;
                return(err);
            }
            return(null);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Match the Foreign Key with the primary key field
        /// </summary>
        /// <param name="reference">The COBie Index to cross reference</param>
        /// <param name="cell">The COBie Cell to validate</param>
        /// <returns>bool</returns>
        private bool ForeignKeyMatch(COBieColumnRelationship reference, COBieCell cell)
        {
            if (reference.HasKeyMatch(cell.CellValue))
            {
                return(true);
            }

            if (cell.COBieColumn.AllowsMultipleValues == true)
            {
                foreach (string value in cell.CellValues)
                {
                    if (!reference.HasKeyMatch(value))
                    {
                        return(false);
                    }
                }
                return(true);
            }

            return(false);
        }
Exemplo n.º 10
0
        /// <summary>
        /// check for Field format Error in passed cell
        /// </summary>
        /// <param name="cell">COBieCell</param>
        /// <param name="sheetName">Sheet name</param>
        /// <param name="row">Row index</param>
        /// <param name="col">Column index</param>
        /// <param name="initialRowHash">Initial row hash value</param>
        /// <returns>COBieError or null</returns>
        public COBieError GetCOBieFieldFormatError(COBieCell cell, COBieAttributeState state, COBieError.ErrorLevels errorLevel, string sheetName, int row, int col, string initialRowHash)
        {
            COBieError err = new COBieError(sheetName, cell.COBieColumn.ColumnName, "", COBieError.ErrorTypes.None, COBieError.ErrorLevels.None, initialRowHash, col, row);


            int maxLength = cell.COBieColumn.ColumnLength;
            COBieAllowedType allowedType = cell.COBieColumn.AllowedType;

            if ((state == COBieAttributeState.Required_IfSpecified) ||
                (state == COBieAttributeState.Required_System) ||
                (state == COBieAttributeState.Required_System_IfSpecified)
                ) //if a required value but marked as n/a then do not class as error
            {
                if (cell.CellValue == Constants.DEFAULT_STRING)
                {
                    return(null);
                }
            }

            //check cell.COBieColumn.AllowedType for format errors
            switch (allowedType)
            {
            case COBieAllowedType.AlphaNumeric:
                if (!cell.IsAlphaNumeric())
                {
                    err.ErrorDescription = ErrorDescription.AlphaNumeric_Value_Expected;
                    err.ErrorType        = COBieError.ErrorTypes.AlphaNumeric_Value_Expected;
                }
                break;

            case COBieAllowedType.Email:
                if (!cell.IsEmailAddress())
                {
                    err.ErrorDescription = ErrorDescription.ISODate_Value_Expected;
                    err.ErrorType        = COBieError.ErrorTypes.ISODate_Value_Expected;
                }
                break;

            case COBieAllowedType.ISODate:
            case COBieAllowedType.ISODateTime:
                if (!cell.IsDateTime())
                {
                    err.ErrorDescription = ErrorDescription.ISODate_Value_Expected;
                    err.ErrorType        = COBieError.ErrorTypes.ISODate_Value_Expected;
                }
                break;

            case COBieAllowedType.Numeric:
                if (!cell.IsNumeric())
                {
                    err.ErrorDescription = ErrorDescription.Numeric_Value_Expected;
                    err.ErrorType        = COBieError.ErrorTypes.Numeric_Value_Expected;
                }
                break;

            case COBieAllowedType.AnyType:
            case COBieAllowedType.Text:
                if (!cell.IsText())
                {
                    err.ErrorDescription = ErrorDescription.Text_Value_Expected;
                    err.ErrorType        = COBieError.ErrorTypes.Text_Value_Expected;
                }
                break;

            default:
                break;
            }
            if (err.ErrorType != COBieError.ErrorTypes.None)
            {
                err.FieldValue = cell.CellValue;
                if (err.ErrorLevel == COBieError.ErrorLevels.None) //if set above, just in case we do set above
                {
                    err.ErrorLevel = errorLevel;
                }
                return(err);
            }
            return(null);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Validating of the column COBieAttributeState attributes for null or n/a values
        /// </summary>
        /// <param name="cell">COBieCell</param>
        /// <param name="sheetName">Sheet name</param>
        /// <param name="row">Row index</param>
        /// <param name="col">Column index</param>
        /// <param name="initialRowHash">Initial row hash value</param>
        /// <returns>COBieError or null</returns>
        private COBieError GetCobieFieldNullError(COBieCell cell, COBieAttributeState state, COBieError.ErrorLevels errorLevel, string sheetName, int row, int col, string initialRowHash)
        {
            COBieError err = new COBieError(sheetName, cell.COBieColumn.ColumnName, "", COBieError.ErrorTypes.None, COBieError.ErrorLevels.None, initialRowHash, col, row);

            if ((string.IsNullOrEmpty(cell.CellValue)) ||
                (cell.CellValue == Constants.DEFAULT_STRING)
                )
            {
                switch (state)
                {
                case COBieAttributeState.Required_PrimaryKey:
                case COBieAttributeState.Required_CompoundKeyPart:
                    err.ErrorDescription = ErrorDescription.PrimaryKey_Violation;
                    err.ErrorType        = COBieError.ErrorTypes.PrimaryKey_Violation;
                    err.ErrorLevel       = errorLevel;
                    break;

                case COBieAttributeState.Required_Information:
                case COBieAttributeState.Required_System:
                    switch (cell.COBieColumn.AllowedType)
                    {
                    case COBieAllowedType.AlphaNumeric:
                        err.ErrorDescription = ErrorDescription.AlphaNumeric_Value_Expected;
                        err.ErrorType        = COBieError.ErrorTypes.AlphaNumeric_Value_Expected;
                        break;

                    case COBieAllowedType.Email:
                        err.ErrorDescription = ErrorDescription.Email_Value_Expected;
                        err.ErrorType        = COBieError.ErrorTypes.Email_Value_Expected;
                        break;

                    case COBieAllowedType.ISODateTime:
                    case COBieAllowedType.ISODate:
                        err.ErrorDescription = ErrorDescription.ISODate_Value_Expected;
                        err.ErrorType        = COBieError.ErrorTypes.ISODate_Value_Expected;
                        break;

                    case COBieAllowedType.Numeric:
                        err.ErrorDescription = ErrorDescription.Numeric_Value_Expected;
                        err.ErrorType        = COBieError.ErrorTypes.Numeric_Value_Expected;
                        break;

                    case COBieAllowedType.AnyType:
                    case COBieAllowedType.Text:
                        err.ErrorDescription = ErrorDescription.Text_Value_Expected;
                        err.ErrorType        = COBieError.ErrorTypes.Text_Value_Expected;
                        break;

                    default:
                        err.ErrorDescription = ErrorDescription.Text_Value_Expected;
                        err.ErrorType        = COBieError.ErrorTypes.Text_Value_Expected;
                        break;
                    }
                    err.ErrorLevel = errorLevel;
                    //err.ErrorLevel = COBieError.ErrorLevels.Warning; //set as a warning
                    break;

                case COBieAttributeState.Required_Reference_PrimaryKey:
                case COBieAttributeState.Required_Reference_PickList:
                case COBieAttributeState.Required_Reference_ForeignKey:
                    err.ErrorDescription = ErrorDescription.Null_ForeignKey_Value;
                    err.ErrorType        = COBieError.ErrorTypes.Null_ForeignKey_Value;
                    err.ErrorLevel       = errorLevel;
                    break;

                case COBieAttributeState.Required_IfSpecified:
                case COBieAttributeState.Required_System_IfSpecified:
                case COBieAttributeState.Required_PrimaryKey_IfSpecified:
                    if (cell.CellValue == Constants.DEFAULT_STRING)
                    {
                        return(null);    //if a required value but not required in validation template then do not class as error
                    }
                    break;

                default:
                    return(null);
                }
                if (err.ErrorType != COBieError.ErrorTypes.None)
                {
                    err.FieldValue = cell.CellValue;
                    return(err);
                }
            }
            return(null);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Validate component sheet for merge types depending on the role of the model this worksheet was built from
        /// </summary>
        /// <param name="model">model the cobie file was generated from</param>
        /// <param name="fileRoles">the file roles</param>
        public List <string> ValidateComponentMerge(XbimModel model, COBieMergeRoles fileRoles)
        {
            List <string> typeObjectGlobalId     = new List <string>();
            List <string> typeObjectGlobalIdKeep = new List <string>();

            //RowsRemoved.Clear();
            if (fileRoles != COBieMergeRoles.Unknown) //if role is a single value of unknown then do no merging
            {
                COBieColumn colExtObj = Columns.Where(c => c.Value.ColumnName == "ExtObject").Select(c => c.Value).FirstOrDefault();
                COBieColumn colExtId  = Columns.Where(c => c.Value.ColumnName == "ExtIdentifier").Select(c => c.Value).FirstOrDefault();

                List <IfcElement> elements = model.InstancesLocal.OfType <IfcElement>().ToList(); //get all IfcElements,

                List <T> RemainRows = new List <T>();
                if (colExtObj != null)
                {
                    FilterValuesOnMerge mergeHelper = new FilterValuesOnMerge();

                    for (int i = 0; i < Rows.Count; i++)
                    {
                        COBieRow  row       = Rows[i];//.ElementAt(i);
                        COBieCell cell      = row[colExtObj.ColumnOrder];
                        string    extObject = cell.CellValue;
                        if (mergeHelper.Merge(extObject)) //object can be tested on
                        {
                            COBieCell cellExtId = row[colExtId.ColumnOrder];
                            string    extId     = cellExtId.CellValue;

                            IfcElement IfcElement = elements.Where(ie => ie.GlobalId.ToString() == extId).FirstOrDefault();
                            if (IfcElement != null)
                            {
                                //we need to remove the ObjectType from the type sheet
                                IfcRelDefinesByType elementDefinesByType = IfcElement.IsDefinedBy.OfType <IfcRelDefinesByType>().FirstOrDefault(); //should be only one
                                IfcTypeObject       elementType          = null;
                                if (elementDefinesByType != null)
                                {
                                    elementType = elementDefinesByType.RelatingType;
                                }

                                if (mergeHelper.Merge(IfcElement, fileRoles))
                                {
                                    RemainRows.Add((T)row);
                                    if ((elementType != null) && (!typeObjectGlobalIdKeep.Contains(elementType.GlobalId)))
                                    {
                                        typeObjectGlobalIdKeep.Add(elementType.GlobalId);
                                    }
                                }
                                else
                                {
                                    RowsRemoved.Add((T)row);
                                    if ((elementType != null) && (!typeObjectGlobalId.Contains(elementType.GlobalId)))
                                    {
                                        typeObjectGlobalId.Add(elementType.GlobalId);
                                    }
                                }
                            }
                            else
                            {
                                RemainRows.Add((T)row); //cannot evaluate IfcType so keep
                            }
                        }
                    }
                    Rows = RemainRows;
                }
            }

            typeObjectGlobalId.RemoveAll(Id => typeObjectGlobalIdKeep.Contains(Id)); //ensure we remove any type we have kept from the type object GlobalId list (ones to remove)
            return(typeObjectGlobalId);
        }
Exemplo n.º 13
0
        private bool SetCellTypedValue(ICell excelCell, COBieCell cell)
        {
            bool processed = false;

            try
            {
                if (String.IsNullOrEmpty(cell.CellValue) || cell.CellValue == Constants.DEFAULT_STRING)
                {
                    return false;
                }

                // We need to set the value in the most appropriate overload of SetCellValue, so the parsing/formatting is correct
                switch (cell.COBieColumn.AllowedType)
                {
                    case COBieAllowedType.ISODateTime:
                    case COBieAllowedType.ISODate:
                        DateTime date;
                        if (DateTime.TryParse(cell.CellValue, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal, out date))
                        {
                            excelCell.SetCellValue(date);
                            processed = true;
                        }
                        break;

                    case COBieAllowedType.Numeric:
                        Double val;
                        if (Double.TryParse(cell.CellValue, out val))
                        {
                            excelCell.SetCellValue(val);
                            processed = true;
                        }
                        break;

                    default:
                        break;
                }
            }
            catch (SystemException)
            { /* Carry on */ }

            return processed;
        }
Exemplo n.º 14
0
 private void SetCellValue(ICell excelCell, COBieCell cell)
 {
     if (SetCellTypedValue(excelCell, cell) == false)
     {
         //check text length will fit in cell
         if (cell.CellValue.Length >= short.MaxValue)
         { 
             //truncate cell text to max length
             excelCell.SetCellValue(cell.CellValue.Substring(0, short.MaxValue - 1));
         }
         else
         {
             excelCell.SetCellValue(cell.CellValue);
         }
     }
 }
Exemplo n.º 15
0
        private void FormatCell(ICell excelCell, COBieCell cell)
        {
            HSSFCellStyle style;
            if (_cellStyles.TryGetValue(cell.COBieColumn.AllowedType, out style))
            {
                excelCell.CellStyle = style;
            }

        }