コード例 #1
0
        /// <summary>
        /// Constructs a class representing the relationships between a Foreign Key column and its Primary key column elsewhere in the 
        /// workbook
        /// </summary>
        /// <param name="workbook">The COBie Workbook holding all the sheets</param>
        /// <param name="column">The foreign key column</param>
        public COBieColumnRelationship(COBieWorkbook workbook, COBieColumn column)
        {

            if(workbook == null)
                throw new ArgumentNullException("workbook");
            if (column.KeyType != COBieKeyType.ForeignKey && column.KeyType != COBieKeyType.CompoundKey_ForeignKey)
                throw new ArgumentException(String.Format("Column '{0}' is not a foreign key column", column.ColumnName));
            if (string.IsNullOrEmpty(column.ReferenceColumnName))
                throw new ArgumentException(errorMessage);

            string[] sheetRefInfo = column.ReferenceColumnName.Split('.');

            if (sheetRefInfo.Length != 2)
                throw new ArgumentException(errorMessage);

            SheetName = sheetRefInfo[0];
            ColumnName = sheetRefInfo[1];
            Sheet = workbook[SheetName];

            if(Sheet == null)
                throw new ArgumentException(String.Format("Sheet '{0}' was not found in the workbook", SheetName));

            if (Sheet.Indices.ContainsKey(ColumnName) == false)
                throw new ArgumentException(String.Format("Column '{0}' was not found in the '{1}' workbook", ColumnName, SheetName));

        }
コード例 #2
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++;
            }
        }
コード例 #3
0
ファイル: COBieSheet.cs プロジェクト: diego2265/XbimExchange
        /// <summary>
        /// Validate the sheet
        /// </summary>
        /// <param name="workbook"></param>
        public void Validate(COBieWorkbook workbook, ErrorRowIndexBase errorRowIdx, ICOBieSheetValidationTemplate SheetValidator)
        {
            _errorRowIdx = errorRowIdx; //set the index for error reporting on rows
            _errors.Clear();

            ValidatePrimaryKeysUnique(SheetValidator);
            ValidateFields(SheetValidator);
            ValidateForeignKeys(workbook, SheetValidator);
        }
コード例 #4
0
ファイル: COBieBuilder.cs プロジェクト: tnesser/XbimExchange
        private void Initialise()
        {
            if (Context == null)
            {
                throw new InvalidOperationException("COBieReader can't initialise without a valid Context.");
            }
            if (Context.Model == null)
            {
                throw new ArgumentException("COBieReader context must contain a models.");
            }

            //set default date for this run, if not manually overridden
            if (!Context.RunDateManuallySet)
            {
                Context.SetRunDate(DateTime.Now);
            }

            // set all the properties
            COBieQueries cq = new COBieQueries(Context);

            //create pick list from the template sheet
            COBieSheet <COBiePickListsRow> CobiePickLists = null;

            if ((!string.IsNullOrEmpty(Context.TemplateFileName)) &&
                File.Exists(Context.TemplateFileName)
                )
            {
                COBieXLSDeserialiser deSerialiser = new COBieXLSDeserialiser(Context.TemplateFileName, Constants.WORKSHEET_PICKLISTS);
                COBieWorkbook        wbook        = deSerialiser.Deserialise();
                if (wbook.Count > 0)
                {
                    CobiePickLists = (COBieSheet <COBiePickListsRow>)wbook.FirstOrDefault();
                }
            }


            //fall back to xml file if not in template
            string pickListFileName = "PickLists.xml";

            if ((CobiePickLists == null) &&
                File.Exists(pickListFileName)
                )
            {
                CobiePickLists = cq.GetCOBiePickListsSheet(pickListFileName);// create pick lists from xml
            }
            if (Context.ExcludeFromPickList)
            {
                SetExcludeComponentTypes(CobiePickLists);
                SetExcludeObjTypeTypes(CobiePickLists);
            }
            //start the Cache
            Context.Model.CacheStart();

            //contact sheet first as it will fill contact information lookups for other sheets
            Workbook.Add(cq.GetCOBieContactSheet());
            Workbook.Add(cq.GetCOBieFacilitySheet());
            Workbook.Add(cq.GetCOBieFloorSheet());
            Workbook.Add(cq.GetCOBieSpaceSheet());
            Workbook.Add(cq.GetCOBieZoneSheet());
            Workbook.Add(cq.GetCOBieTypeSheet());
            Workbook.Add(cq.GetCOBieComponentSheet());
            Workbook.Add(cq.GetCOBieSystemSheet(Workbook[Constants.WORKSHEET_COMPONENT].Indices)); //pass component names
            Workbook.Add(cq.GetCOBieAssemblySheet());
            Workbook.Add(cq.GetCOBieConnectionSheet());
            Workbook.Add(cq.GetCOBieSpareSheet());
            Workbook.Add(cq.GetCOBieResourceSheet());
            Workbook.Add(cq.GetCOBieJobSheet());
            Workbook.Add(cq.GetCOBieImpactSheet());
            Workbook.Add(cq.GetCOBieDocumentSheet());
            Workbook.Add(cq.GetCOBieAttributeSheet());//we need to fill attributes here as it is populated by Components, Type, Space, Zone, Floors, Facility etc
            //#if GEOMETRY_IMPLEMENTED
            Workbook.Add(cq.GetCOBieCoordinateSheet());
            //#endif
            Workbook.Add(cq.GetCOBieIssueSheet());
            if (CobiePickLists != null)
            {
                Workbook.Add(CobiePickLists);
            }
            else
            {
                Workbook.Add(new COBieSheet <COBiePickListsRow>(Constants.WORKSHEET_PICKLISTS)); //add empty pick list
            }
            //clear sheet session values from context
            Context.EMails.Clear();
        }
コード例 #5
0
ファイル: COBieBuilder.cs プロジェクト: tnesser/XbimExchange
 private void ResetWorksheets()
 {
     Workbook = new COBieWorkbook();
 }