public static void processSnapshot(int snapshotId) { CcsServerEntities ctx = new CcsServerEntities(); //Grab docs from context var docs = ctx.documents .Where(d => d.snapshot_id == snapshotId); //Pipeline Debug.WriteLine("Beginning Pipeline for snapshot id " + snapshotId); Console.WriteLine("Beginning Pipeline for snapshot id " + snapshotId); var count = 1; foreach (var doc in docs) { //Initialize byte array list List <FileBytes> fbList = new List <FileBytes>(); if (doc.exception_code == null && doc.exclusion_code == null) { Operations.updateName(doc); } if (doc.exception_code == null && doc.exclusion_code == null) { //Operations.updateFilePath(doc); } if (doc.exception_code == null && doc.exclusion_code == null) { Operations.getSbFileType(doc, fbList); } count++; if (count % 1000 == 0) { Console.WriteLine(count + " Docs processed for snapshot id " + snapshotId); Debug.WriteLine(count + " Docs processed for snapshot id " + snapshotId); } } Console.WriteLine("Pipleine has completed for snapshot id " + snapshotId); Debug.WriteLine("Pipleine has completed for snapshot id " + snapshotId); Debug.WriteLine("Creating DIP for for snapshot id: " + snapshotId); var mappingIndex = getMappingIndex(); CcsFunctions.createDipFile(ctx, mappingIndex, snapshotId); Debug.WriteLine("Done creating DIP file"); ctx.SaveChanges(); }
public static void getSbFileType(document doc, List <FileBytes> fbList) { var snow = new Snowbnd(); foreach (var file in doc.files) { var bytes = CcsFunctions.readFile(file, fbList, doc); if (doc.exception_code == null) { var sbFileType = snow.CIMGLOW_get_filetype_mem(bytes); CcsServerEntities ctx = new CcsServerEntities(); var fileType = ctx.file_type .Where(f => f.sb_file_type == sbFileType) .FirstOrDefault(); file.file_type_id = fileType.id; file.sb_file_type = fileType.sb_file_type; } } }
private static List <Mappings> getMappingList(CcsServerEntities ctx) { //Loop through OnBase Key Types and add to a list of the OnBaseKeyType object List <OnBaseKeyType> oktList = new List <OnBaseKeyType>(); foreach (onbase_key_type okt in ctx.onbase_key_type) { oktList.Add(new OnBaseKeyType { onbaseKeyTypeId = okt.id, onbaseKeyTypeName = okt.name }); } List <Mappings> maps = new List <Mappings>(); //Loop through Doc Type Mapping and add to the object foreach (doc_type_mapping dMap in ctx.doc_type_mapping) { var ktmList = getKeyTypeMapset(dMap.key_type_mapset, oktList); maps.Add(new Mappings { onbaseDocType = dMap.onbase_doc_type.name.ToString(), keyTypeMapset = ktmList, lookUp0 = dMap.lookup_000.ToString() }); } return(maps); }
public static void createDipFile(CcsServerEntities ctx, JObject mappingJsonConfig, int snapShotId) { //Get docs from the database var docs = ctx.documents .Where(d => d.snapshot_id == snapShotId); //Initialize list for mappings List <Mappings> mappingList = getMappingList(ctx); //Get mappings from database var mappings = ctx.doc_type_mapping; //Parse the mappings.json file JArray mappingIndex = (JArray)mappingJsonConfig["LookupAssignments"]; string conversionIdProperty = (string)mappingJsonConfig["CcsOnBaseDocumentIdKeyTypeName"]; string legacyIdProperty = (string)mappingJsonConfig["LegacyDocumentIdKeyTypeName"]; JObject staticKeywords = (JObject)mappingJsonConfig["StaticKeywords"]; //Initialize a new list for the dipfile entries List <string> dipFileList = new List <string>(); //Loop through the docs and add to dipFileList as it goes foreach (document doc in docs) { if (doc.exception_code == null && doc.exclusion_code == null) { //Get the legacy doc type value from metadata var mappingCol = "col_" + mappingIndex[0].ToString().PadLeft(3, '0'); var legacyDocType = doc.metadata.GetType().GetProperty(mappingCol).GetValue(doc.metadata, null); //lookup the mapping for the individual doc var mapping = mappingList .Where(m => m.lookUp0 == legacyDocType.ToString()) .FirstOrDefault(); //Add the appropriate values to the DIP file var onBaseDocType = mapping.onbaseDocType; dipFileList.Add(">>BEGIN:"); dipFileList.Add(">>DocTypeName: " + onBaseDocType); dipFileList.Add(">>DocDate: " + "Needs to be added"); dipFileList.Add(String.Format("{0}: {1}", conversionIdProperty, doc.id)); dipFileList.Add(String.Format("{0}: {1}", legacyIdProperty, doc.legacy_id)); dipFileList.Add("Legacy Document Type: " + legacyDocType); foreach (var item in staticKeywords) { dipFileList.Add(String.Format("{0}: {1}", item.Key, item.Value)); } foreach (var map in mapping.keyTypeMapset) { var value = doc.metadata.GetType().GetProperty(map.metadataColIndex).GetValue(doc.metadata, null); dipFileList.Add(String.Format("{0}: {1}", map.onBaseKeywordName, value)); } foreach (var file in doc.files.OrderBy(f => f.seq)) { var fileType = file.file_type; if (fileType != null && fileType.hsi_filetypenum.ToString() != null) { dipFileList.Add(">>FileTypeNum: " + file.file_type.hsi_filetypenum); dipFileList.Add(">>FullPath: " + file.relative_path); } else { doc.exception_code = 34; } } } } TextWriter tw = new StreamWriter(@"C:\users\kenny\documents\dip_01.txt"); foreach (string s in dipFileList) { tw.WriteLine(s); } tw.Close(); }