Пример #1
0
        /// <summary>
        /// Merge the workbooks together into a single federated workbook
        /// </summary>
        /// <param name="workbooks">List of Workbooks</param>
        /// <returns>Federated COBie Workbook</returns>
        public COBieWorkbook Merge(List<COBieWorkbook> workbooks)
        {
#if DEBUG
            Stopwatch timer = new Stopwatch();
            timer.Start();
#endif
            COBieWorkbook fedWorkbook = new COBieWorkbook();
            int index = 0;
            foreach (COBieWorkbook workbook in workbooks)
            {
                index++;
                foreach (ICOBieSheet<COBieRow> worksheet in workbook)
                {
                    ICOBieSheet<COBieRow> fedSheet = fedWorkbook[worksheet.SheetName];
                    if (fedSheet == null)
                    {
                        fedSheet = CreateSheet(worksheet.SheetName); //create sheet as it does not exist
                        fedWorkbook.Add(fedSheet);
                    }
                    else if (worksheet.SheetName == Constants.WORKSHEET_PICKLISTS)
                    {
                        continue; //we have already added a pick list so jump on to next sheet
                    }

                    //copy the removed rows to the federated sheet
                    if (worksheet.RemovedRows != null)
                    {
                        foreach (var row in worksheet.RemovedRows)
                        {
                            fedSheet.AddRemovedRow(row);
                        }
                    }
                    

                    cOBieProgress.Initialise(string.Format("Federate workbook {0}, Merging {1}", index, worksheet.SheetName), worksheet.RowCount);
                    bool copy = (worksheet.SheetName == Constants.WORKSHEET_COORDINATE);
                    //copy rows to federated sheet, or add to removed rows if duplicate
                    for (int i = 0; i < worksheet.RowCount; i++)
                    {
                        cOBieProgress.IncrementAndUpdate();
                        if (copy) //copy the coordinate sheet without any removals
                        {
                            fedSheet.AddRow(worksheet[i]);
                        }
                        else
                        {
                            string hash = worksheet[i].RowMergeHashValue;
                            if (!fedSheet.HasMergeHashCode(hash, true))
                            {
                                fedSheet.AddRow(worksheet[i]);
                            }
                            else
                            {
                                fedSheet.AddRemovedRow(worksheet[i]);
                            }
                        }
                    }
                    //cOBieProgress.Finalise();
                }
            }
            
            fedWorkbook.SetInitialHashCode();//set the initial row hash value to compare against for row changes
            PopulateErrors(fedWorkbook);
#if DEBUG
            timer.Stop();
            Console.WriteLine(String.Format("Time to federate COBie = {0} seconds", timer.Elapsed.TotalSeconds.ToString("F3")));
#endif
            return fedWorkbook;
        }
Пример #2
0
        /// <summary>
        /// Merge the workbooks together into a single federated workbook
        /// </summary>
        /// <param name="workbooks">List of Workbooks</param>
        /// <returns>Federated COBie Workbook</returns>
        public COBieWorkbook Merge(List <COBieWorkbook> workbooks)
        {
#if DEBUG
            Stopwatch timer = new Stopwatch();
            timer.Start();
#endif
            COBieWorkbook fedWorkbook = new COBieWorkbook();
            int           index       = 0;
            foreach (COBieWorkbook workbook in workbooks)
            {
                index++;
                foreach (ICOBieSheet <COBieRow> worksheet in workbook)
                {
                    ICOBieSheet <COBieRow> fedSheet = fedWorkbook[worksheet.SheetName];
                    if (fedSheet == null)
                    {
                        fedSheet = worksheet.CreateEmptySheet();  //create sheet as it does not exist
                        fedWorkbook.Add(fedSheet);
                    }
                    else if (worksheet.SheetName == Constants.WORKSHEET_PICKLISTS)
                    {
                        continue; //we have already added a pick list so jump on to next sheet
                    }

                    //copy the removed rows to the federated sheet
                    if (worksheet.RemovedRows != null)
                    {
                        foreach (var row in worksheet.RemovedRows)
                        {
                            fedSheet.AddRemovedRow(row);
                        }
                    }


                    cOBieProgress.Initialise(string.Format("Federate workbook {0}, Merging {1}", index, worksheet.SheetName), worksheet.RowCount);
                    bool copy = (worksheet.SheetName == Constants.WORKSHEET_COORDINATE);
                    //copy rows to federated sheet, or add to removed rows if duplicate
                    for (int i = 0; i < worksheet.RowCount; i++)
                    {
                        cOBieProgress.IncrementAndUpdate();
                        if (copy) //copy the coordinate sheet without any removals
                        {
                            fedSheet.AddRow(worksheet[i]);
                        }
                        else
                        {
                            string hash = worksheet[i].RowMergeHashValue;
                            if (!fedSheet.HasMergeHashCode(hash, true))
                            {
                                fedSheet.AddRow(worksheet[i]);
                            }
                            else
                            {
                                fedSheet.AddRemovedRow(worksheet[i]);
                            }
                        }
                    }
                    //cOBieProgress.Finalise();
                }
            }

            fedWorkbook.SetInitialHashCode();//set the initial row hash value to compare against for row changes
            PopulateErrors(fedWorkbook);
#if DEBUG
            timer.Stop();
            Console.WriteLine(String.Format("Time to federate COBie = {0} seconds", timer.Elapsed.TotalSeconds.ToString("F3")));
#endif
            return(fedWorkbook);
        }
Пример #3
0
        /// <summary>
        /// Validate XLS file for COBie errors, also will swap templates if required
        /// </summary>
        /// <param name="parameters">Params</param>
        /// <returns>Created file name</returns>
        private void ValidateXLSfile(Params parameters, ICOBieValidationTemplate ValidationTemplate = null)
        {
            //read xls file
            LogBackground(String.Format("Reading {0}....", parameters.ModelFile));
            COBieXLSDeserialiser deSerialiser = new COBieXLSDeserialiser(parameters.ModelFile);
            COBieWorkbook        Workbook     = deSerialiser.Deserialise();

            //extract pick list from the template sheet and swap into workbook (US / UK)
            LogBackground("Swapping PickList from template...");
            COBieSheet <COBiePickListsRow> CobiePickLists = null;

            if ((!string.IsNullOrEmpty(parameters.TemplateFile)) &&
                File.Exists(parameters.TemplateFile)
                )
            {
                //extract the pick list sheet from template
                COBieXLSDeserialiser deSerialiserPickList = new COBieXLSDeserialiser(parameters.TemplateFile, Constants.WORKSHEET_PICKLISTS);
                COBieWorkbook        wbookPickList        = deSerialiserPickList.Deserialise();
                if (wbookPickList.Count > 0)
                {
                    CobiePickLists = (COBieSheet <COBiePickListsRow>)wbookPickList.FirstOrDefault();
                }
                //check the workbook last sheet is a pick list
                if (Workbook.LastOrDefault() is COBieSheet <COBiePickListsRow> )
                {
                    //remove original pick list and replace with templates
                    Workbook.RemoveAt(Workbook.Count - 1);
                    Workbook.Add(CobiePickLists);
                }
                else
                {
                    LogBackground("Failed to Swap PickList from template...");
                }
            }

            COBieContext  context  = new COBieContext(_worker.ReportProgress);
            COBieProgress progress = new COBieProgress(context);

            context.Exclude = UserFilters;

            //Validate
            progress.Initialise("Validating Workbooks", Workbook.Count, 0);
            progress.ReportMessage("Building Indices...");
            foreach (ICOBieSheet <COBieRow> item in Workbook)
            {
                item.BuildIndices();
            }
            progress.ReportMessage("Building Indices...Finished");

            // Validate the workbook
            progress.ReportMessage("Starting Validation...");

            Workbook.Validate(ErrorRowIndexBase.RowTwo, null, (lastProcessedSheetIndex) =>
            {
                // When each sheet has been processed, increment the progress bar
                progress.IncrementAndUpdate();
            });
            progress.ReportMessage("Finished Validation");
            progress.Finalise();

            // Export
            LogBackground(String.Format("Formatting as XLS using {0} template...", Path.GetFileName(parameters.TemplateFile)));
            COBieXLSSerialiser serialiser = new COBieXLSSerialiser(parameters.ModelFile, parameters.TemplateFile);

            serialiser.Excludes = UserFilters;
            serialiser.Serialise(Workbook, ValidationTemplate);

            LogBackground(String.Format("Export Complete: {0}", parameters.ModelFile));

            Process.Start(parameters.ModelFile);

            LogBackground("Finished COBie Validation");
        }