// Test code public static void AddOldDocTypes(string filename, DocTypesMatcher docTypesMatcher) { ScanMan.OldXmlRulesManager xmlRulesManager = new ScanMan.OldXmlRulesManager(filename); List<ScanMan.OldXmlRulesManager.DocType> oldDocTypeList = xmlRulesManager.GetAllDocTypes(); // Handle match expression foreach (ScanMan.OldXmlRulesManager.DocType oldDocType in oldDocTypeList) { DocType newDocType = new DocType(); newDocType.docTypeName = oldDocType.dtName; if (oldDocType.goodStrings.Count > 0) { newDocType.matchExpression = ""; foreach (ScanMan.OldXmlRulesManager.CheckItem chkItem in oldDocType.goodStrings) { if (newDocType.matchExpression != "") newDocType.matchExpression += " & "; chkItem.checkString = chkItem.checkString.Replace(",", "&"); if (chkItem.checkString.Contains('|')) newDocType.matchExpression += "( " + chkItem.checkString + " )"; else newDocType.matchExpression += chkItem.checkString; } } string notStr = ""; if (oldDocType.badStrings.Count > 0) { notStr = "( "; foreach (ScanMan.OldXmlRulesManager.CheckItem chkItem in oldDocType.badStrings) { if (notStr != "( ") notStr += " & "; chkItem.checkString = chkItem.checkString.Replace(",", "&"); if (chkItem.checkString.Contains('|')) notStr += "( " + chkItem.checkString + " )"; else notStr += chkItem.checkString; } notStr += " )"; } if (notStr != "") newDocType.matchExpression = "( " + newDocType.matchExpression + " ) & !" + notStr; // Handle thumbnail if (oldDocType.thumbFileNames.Count > 0) { string thumbFile = oldDocType.thumbFileNames[0].Replace('\\', '/'); if (File.Exists(thumbFile)) { DateTime fileDateTime = File.GetCreationTime(thumbFile); string uniqName = ScanDocInfo.GetUniqNameForFile(thumbFile, fileDateTime); newDocType.thumbnailForDocType = uniqName; } else { newDocType.thumbnailForDocType = ""; } } else { newDocType.thumbnailForDocType = ""; } // Handle paths string newPath = oldDocType.moveTo; newDocType.moveFileToPath = docTypesMatcher.ComputeMinimalPath(newPath); // Handle rename string newName = oldDocType.renameTo; newDocType.renameFileTo = newName; // Update DB if (!docTypesMatcher.AddOrUpdateDocTypeRecInDb(newDocType)) logger.Info("Failed to add doc type record {0}", newDocType.docTypeName); } logger.Info("Finished loading legacy doc types"); }
public static void ReplaceDocTypeThumbnailStrs(DocTypesMatcher docTypesMatcher) { foreach (DocType dt in docTypesMatcher.ListDocTypes()) { if (dt.thumbnailForDocType != "") { DateTime fileDateTime = File.GetCreationTime(dt.thumbnailForDocType); string uniqName = ScanDocInfo.GetUniqNameForFile(dt.thumbnailForDocType, fileDateTime); dt.thumbnailForDocType = uniqName; if (!docTypesMatcher.AddOrUpdateDocTypeRecInDb(dt)) logger.Info("Failed to update doc type record {0}", dt.docTypeName); } } }