/// <summary> /// Read and load pages data into the collection definition. /// </summary> /// <param name="cfg">The configuration profile to use.</param> /// <param name="errCode">Returns the error code of this operation.</param> /// <param name="errMsg">Returns the error string of this operation</param> /// <param name="expectedNumberOfPages">The expected nuumber of pages in the collection.</param> /// <param name="coll">The collection definition to add the data to.</param> /// <param name="colData">The data table containing the data for the collection.</param> /// <returns>An array oif file paths for files that were created in this method</returns> private static String[] ReadPagesData(CCConfiguration.CCConfigurationData cfg, out int errCode, out String errMsg, int expectedNumberOfPages, ref CCCollection coll, DataTable colData) { errCode = (int)CCEnums.CCErrorCodes.E0000; errMsg = null; List <String> result = new List <String>(); try { //-- Validate expected page count --\\ if (expectedNumberOfPages <= 0) { errCode = (int)CCEnums.CCErrorCodes.E0051; errMsg = String.Format("{0}, error code [{1}]", CCConstants.E0051, errCode); throw new Exception(errMsg); } int numberOfImagePages = CCUtils.GetImagePageCount(coll.ImagePath, null); //-- Validate page count --\\ if (numberOfImagePages <= 0) { errCode = (int)CCEnums.CCErrorCodes.E0061; errMsg = String.Format("{0}, file path [{1}], error code [{2}]", CCConstants.E0061, coll.ImagePath, errCode); throw new Exception(errMsg); } //-- Validate page count against expected page count --\\ if (numberOfImagePages != expectedNumberOfPages) { errCode = (int)CCEnums.CCErrorCodes.E0050; errMsg = String.Format("{4}. expected number of pages [{1}], actual image count [{2}], file path [{3}], error code [{0}]", errCode, expectedNumberOfPages, numberOfImagePages, coll.ImagePath, CCConstants.E0050); throw new Exception(errMsg); } List <CCCollection.CCForm> forms = new List <CCCollection.CCForm>(); for (int pageCount = 1; pageCount <= expectedNumberOfPages; pageCount++) { Dictionary <String, String> lstDct = new Dictionary <String, String>(); List <String> attachments = new List <String>(); DataRow[] pageRows = colData.Select(String.Format("{0}={1}", CCEnums.CCTableColumns.Level, IsStringData(colData.Columns[CCEnums.CCTableColumns.Level.ToString()]) ? "'" + pageCount.ToString() + "'" : pageCount.ToString())); if (pageRows == null || pageRows.Length <= 0) { pageRows = colData.Select(String.Format("{0}='{1}'", CCEnums.CCTableColumns.Level, pageCount)); } //-- Process pages data --\\ if (pageRows != null && pageRows.Length > 0) { List <int> pageNumbers = new List <int>(); String startDate = null; String endDate = null; //-- Iterate pages rows --\\ foreach (DataRow dr in pageRows) { //-- Get the page number the data is itntended to --\\ int pageNumber = CCUtils.StrToIntDef(dr[CCEnums.CCTableColumns.Level.ToString()].ToString(), -1); if (!pageNumbers.Contains(pageNumber)) { pageNumbers.Add(pageNumber); } //-- << Read pages data >>--\\ if (String.Compare(dr[CCEnums.CCTableColumns.DataType.ToString()].ToString(), CCEnums.CCPagesDataType.PageType.ToString(), true) == 0) { //-- PageType --\\ CCUtils.AddSetDictionaryItem(CCEnums.CCPagesDataType.PageType.ToString(), dr[CCEnums.CCTableColumns.Data.ToString()].ToString(), excpetionOnDictDuplicates, ref lstDct); } else if (String.Compare(dr[CCEnums.CCTableColumns.DataType.ToString()].ToString(), CCEnums.CCPagesDataType.StartDate.ToString(), true) == 0) { //-- StartDate --\\ startDate = dr[CCEnums.CCTableColumns.Data.ToString()].ToString(); CCUtils.AddSetDictionaryItem(CCEnums.CCPagesDataType.StartDate.ToString(), startDate, excpetionOnDictDuplicates, ref lstDct); } else if (String.Compare(dr[CCEnums.CCTableColumns.DataType.ToString()].ToString(), CCEnums.CCPagesDataType.EndDate.ToString(), true) == 0) { //-- EndDate --\\ endDate = dr[CCEnums.CCTableColumns.Data.ToString()].ToString(); CCUtils.AddSetDictionaryItem(CCEnums.CCPagesDataType.EndDate.ToString(), endDate, excpetionOnDictDuplicates, ref lstDct); } else if (String.Compare(dr[CCEnums.CCTableColumns.DataType.ToString()].ToString(), CCEnums.CCPagesDataType.Attachments.ToString(), true) == 0) { //-- Attachments --\\ String val = dr[CCEnums.CCTableColumns.Data.ToString()].ToString(); if (!String.IsNullOrEmpty(val) && !File.Exists(val)) { errCode = (int)CCEnums.CCErrorCodes.E0065; errMsg = String.Format("{1}, file path[{2}], error code [{0}]", errCode, CCConstants.E0065, val ?? String.Empty); throw new Exception(errMsg); } else { if (!attachments.Contains(val)) { attachments.Add(val); } } } else if (String.Compare(dr[CCEnums.CCTableColumns.DataType.ToString()].ToString(), CCEnums.CCPagesDataType.XmlPrdPath.ToString(), true) == 0) { //-- XmlPrdPath --\\ int errC = 0; String errS = null; String sourceXmlPath = dr[CCEnums.CCTableColumns.Data.ToString()].ToString(); //-- Convert XML to PRD and add as page attachment --\\ String prdPath = DeserializePRD(out errC, out errS, pageNumber, false, sourceXmlPath); if (!String.IsNullOrEmpty(prdPath)) { if (File.Exists(sourceXmlPath)) { //-- Lock PRD file --\\ String lockPrd = CCFileList.GetLockedFilePath(prdPath, cfg.LockExtension); if (String.Compare(lockPrd, prdPath, true) != 0) { if (File.Exists(lockPrd)) { File.SetAttributes(lockPrd, FileAttributes.Normal); File.Delete(lockPrd); } File.SetAttributes(prdPath, FileAttributes.Normal); File.Move(prdPath, lockPrd); } File.Delete(sourceXmlPath); if (!attachments.Contains(lockPrd)) { attachments.Add(lockPrd); } if (!result.Contains(lockPrd)) { result.Add(lockPrd); } } } } else if (String.Compare(dr[CCEnums.CCTableColumns.DataType.ToString()].ToString(), CCEnums.CCPagesDataType.MetaData.ToString(), true) == 0) { //-- Additional MetaData--\\ String tagName = dr[CCEnums.CCTableColumns.Key.ToString()] is DBNull || String.IsNullOrEmpty(dr[CCEnums.CCTableColumns.Key.ToString()].ToString()) ? null : dr[CCEnums.CCTableColumns.Key.ToString()].ToString(); if (!String.IsNullOrEmpty(tagName)) { CCUtils.AddSetDictionaryItem(tagName, dr[CCEnums.CCTableColumns.Data.ToString()].ToString(), excpetionOnDictDuplicates, ref lstDct); } } } //-- Validate page dates --\\ if (!ValidateDates(startDate, endDate, out errCode, out errMsg)) { //-- Validate start and end time\date --\\ errCode = (int)CCEnums.CCErrorCodes.E0020; errMsg = String.Format("{0}, {1} [{2}],{3} [{4}], page number [{5}], error code [{6}]", CCConstants.E0020, CCEnums.CCPagesDataType.StartDate, startDate, CCEnums.CCPagesDataType.EndDate, endDate, pageCount, errCode); throw new Exception(errMsg); } } //-- Create a form and page, NF 2011-11-07 added support for multipage per form --\\ CCCollection.CCForm frm = cfg.MultiPagePerForm ? forms.Count > 0 ? forms[0] : new CCCollection.CCForm(null, null, null) : new CCCollection.CCForm(null, null, null); if (!cfg.MultiPagePerForm || (cfg.MultiPagePerForm && forms.Count <= 0)) { frm.NamedUserTags.NativeDictionary = lstDct; //-- Add page Named user tags to Form user tags --\\ } CCCollection.CCPage pg = new CCCollection.CCPage(); pg.Attachments = attachments.ToArray(); pg.NamedUserTags.NativeDictionary = lstDct; if (!cfg.MultiPagePerForm || forms.Count <= 0) { frm.Pages = new CCCollection.CCPage[] { pg }; } else { List <CCCollection.CCPage> pgs = new List <CCCollection.CCPage>(frm.Pages); pgs.Add(pg); frm.Pages = pgs.ToArray(); } if (!cfg.MultiPagePerForm || forms.Count <= 0) { forms.Add(frm); } } //-- Do some validations --\\ if (expectedNumberOfPages != forms.Count) { if (!cfg.MultiPagePerForm || forms.Count <= 0) { errCode = (int)CCEnums.CCErrorCodes.E0090; errMsg = String.Format("Error code [{0}], {1},expected number of pages [{2}], eflow form count [{3}]", errCode, CCConstants.E0090, expectedNumberOfPages, forms.Count); throw new Exception(errMsg); } else { if (forms[0].Pages.Length != expectedNumberOfPages) { errCode = (int)CCEnums.CCErrorCodes.E0090; errMsg = String.Format("Error code [{0}], {1},expected number of pages [{2}] in one form, eflow form count [{3}]", errCode, CCConstants.E0090, expectedNumberOfPages, forms.Count); throw new Exception(errMsg); } } } errCode = (int)CCEnums.CCErrorCodes.E0001; coll.Forms = forms.ToArray(); } catch (Exception ex) { ILog.LogError(ex, false); if (String.IsNullOrEmpty(errMsg)) { errMsg = CCConstants.E0000 + "," + ex.Message; } throw (ex); } return(result.ToArray()); }