private static void CreateOKMYearFolder(OKMWebservice webservice, string token, string host, string user, string password, string dynamicDocPath) { try { if (!webservice.folderExist(token, dynamicDocPath)) { webservice.createSimple(token, dynamicDocPath); } } catch (OKMWebserviceException okex) { // Re-obtaining OpenKM authentication token, and retrying... Console.WriteLine(okex.Message); Console.WriteLine(okex.Source); Console.WriteLine(okex.StackTrace); Console.WriteLine(okex.TargetSite); //Console.WriteLine("Re-obtaining OpenKM authentication token, and retrying CreateOKMYearFolder..."); //Worker.LoginToOpenKMCommunityEdition(host, user, password, ref token, ref webservice); ////recurse //CreateOKMYearFolder(ref webservice, ref token, host, user, password, dynamicDocPath); } catch (Exception ex) { Console.WriteLine(ex.Message); Console.WriteLine(ex.Source); Console.WriteLine(ex.StackTrace); Console.WriteLine(ex.TargetSite); //Console.WriteLine("Retrying CreateOKMYearFolder..."); ////recurse //CreateOKMYearFolder(ref webservice, ref token, host, user, password, dynamicDocPath); } }
// Process all files in the directory passed in, recurse on any directories // that are found, and process the files they contain. public void ProcessDirectory(string targetDirectory, OKMWebservice webservice, string token, string host, string user, string password) { //string ext = String.Empty; //string pathWithoutExtention = String.Empty; //string fileNameWithoutFolderPath = String.Empty; //string localTempPdfFilename = String.Empty; //string fileName = String.Empty; //Dictionary<string, string> metadata = null; const string baseDocPath = @"/okm:root/DocuWareToOpenKMMigration/"; string dynamicDocPath = baseDocPath; //string transformedPath = string.Empty; //string transformedPathForNonXmlFiles = string.Empty; //int year = 0; //string month = string.Empty; string quepath = @".\Private$\" + Path.GetFileName(Worker._path); // Path.GetFileName may not work with a Directory name having a trailing / MessageQueue pQueue = new MessageQueue(quepath); //Synchronous Approach while (true) { _pauseEvent.WaitOne(Timeout.Infinite); if (_shutdownEvent.WaitOne(0)) { break; } //Receiving Message Message message = pQueue.Receive(); message.Formatter = new BinaryMessageFormatter(); DocuwareMigrationDataPointer docuwareMigrationDataPointerReceiver = (DocuwareMigrationDataPointer)message.Body; string[] transformedPathTokens = docuwareMigrationDataPointerReceiver.TransformedPath.Split('/'); //year = dateOfDocumentReceiptDate.Year; //month = dateOfDocumentReceiptDate.ToString("MMMM", culture).ToLower().Trim(); //Check if folder exists and create if not. // NOTE that OpenKM folder creation fails when there is a trailing / in the docPath and when you attempt to craate nested folders at once. // The Folder creation code below works //Attempt to create the year folder in OpenKM //Modify the OpenKM path string to contain the year as a folder dynamicDocPath = dynamicDocPath + transformedPathTokens[3].Trim(); CreateOKMYearFolder(webservice, token, host, user, password, dynamicDocPath); //Attempt to create the month folder in OpenKM //Modify the OpenKM path string to contain the month as a folder dynamicDocPath = dynamicDocPath + "/" + transformedPathTokens[4].Trim(); CreateOKMMonthFolder(webservice, token, host, user, password, dynamicDocPath); ////string extension = Path.GetExtension(fileName); //pathWithoutExtention = Path.GetFileNameWithoutExtension(fileName); //fileNameWithoutFolderPath = pathWithoutExtention; //Attempt to create the file's folder in OpenKM //Modify the OpenKM path string to contain the filename as a folder dynamicDocPath = dynamicDocPath + "/" + transformedPathTokens[5].Trim(); CreateOKMFileFolder(webservice, token, host, user, password, dynamicDocPath); //transformedPath = dynamicDocPath + "/" + pathWithoutExtention.Substring(pathWithoutExtention.LastIndexOf(@"\") + 1) + ext; ///// ProcessFile(docuwareMigrationDataPointerReceiver.Path, docuwareMigrationDataPointerReceiver.Metadata, webservice, token, docuwareMigrationDataPointerReceiver.TransformedPath, host, user, password); dynamicDocPath = baseDocPath; RedisValue processedFilesSizeValue = keyValueCache.StringGet("Webservice-Consumer"); if (!processedFilesSizeValue.HasValue) { //Sum up the total files that have been processed, and store the sum in the Redis Key/Value NoSQL database. processedFilesSize += new FileInfo(docuwareMigrationDataPointerReceiver.Path).Length; keyValueCache.StringSet("Webservice-Consumer", processedFilesSize.ToString()); } else { processedFilesSize = Convert.ToSingle(processedFilesSizeValue.ToString()); //Sum up the total files that have been processed, and store the sum in the Redis Key/Value NoSQL database. processedFilesSize += new FileInfo(docuwareMigrationDataPointerReceiver.Path).Length; keyValueCache.StringSet("Webservice-Consumer", processedFilesSize.ToString()); } } }
private static void ProcessNonExistingFile(string path, Dictionary <string, string> metadata, OKMWebservice webservice, string token, string transformedPath) { if (!webservice.documentExists(token, transformedPath)) { //webservice.createSimple(token, docPath + path.Substring(path.LastIndexOf(@"\") + 1), File.ReadAllBytes(path)); // Upload the file to OpenKM webservice.createSimple(token, transformedPath, File.ReadAllBytes(path)); //Add Property Group and set the properties in the Group webservice.addGroup(token, transformedPath, "okg:systemspecs_docuware_import"); Dictionary <string, string> okmPropertiesMap = new Dictionary <string, string>(); if ((!okmPropertiesMap.ContainsKey("okp:systemspecs_docuware_import.companyname")) && (metadata.ContainsKey("COMPANY_NAME"))) { okmPropertiesMap.Add("okp:systemspecs_docuware_import.companyname", metadata["COMPANY_NAME"]); } if ((!okmPropertiesMap.ContainsKey("okp:systemspecs_docuware_import.productline")) && (metadata.ContainsKey("PRODUCT_LINE"))) { okmPropertiesMap.Add("okp:systemspecs_docuware_import.productline", metadata["PRODUCT_LINE"]); } if ((!okmPropertiesMap.ContainsKey("okp:systemspecs_docuware_import.subjectheading")) && (metadata.ContainsKey("SUBJECT_HEADING"))) { okmPropertiesMap.Add("okp:systemspecs_docuware_import.subjectheading", metadata["SUBJECT_HEADING"]); } if ((!okmPropertiesMap.ContainsKey("okp:systemspecs_docuware_import.documentdirection")) && (metadata.ContainsKey("INGOING_OUTGOING"))) { okmPropertiesMap.Add("okp:systemspecs_docuware_import.documentdirection", metadata["INGOING_OUTGOING"]); } if ((!okmPropertiesMap.ContainsKey("okp:systemspecs_docuware_import.documenttype")) && (metadata.ContainsKey("DOCUMENT_TYPE"))) { okmPropertiesMap.Add("okp:systemspecs_docuware_import.documenttype", metadata["DOCUMENT_TYPE"]); } if ((!okmPropertiesMap.ContainsKey("okp:systemspecs_docuware_import.referencenumber")) && (metadata.ContainsKey("REFERENCE_NUMBER"))) { okmPropertiesMap.Add("okp:systemspecs_docuware_import.referencenumber", metadata["REFERENCE_NUMBER"]); } if ((!okmPropertiesMap.ContainsKey("okp:systemspecs_docuware_import.date")) && (metadata.ContainsKey("DATE"))) { DateTime dateTime = DateTime.Parse(metadata["DATE"], new System.Globalization.CultureInfo("en-US", true), System.Globalization.DateTimeStyles.AssumeLocal); string dateTimeString = dateTime.Year.ToString() + "0" + dateTime.Month.ToString() + "0" + dateTime.Day.ToString() + "000000"; okmPropertiesMap.Add("okp:systemspecs_docuware_import.date", dateTimeString); } webservice.setPropertiesSimple(token, transformedPath, "okg:systemspecs_docuware_import", okmPropertiesMap); Console.WriteLine("Uploaded file from '{0}' -> '{1}'.", path, transformedPath); } else { Console.WriteLine("File already exits: for transaction '{0}' -> '{1}'.", path, transformedPath); } //Handling omitted training property group //The above is not necessary again as search and eye inspection of the filesystem repository for Docuware revealed the above property group as the only consistent one. }
// Insert logic for processing found files here. public static void ProcessFile(string path, Dictionary <string, string> metadata, OKMWebservice webservice, string token, string transformedPath, string host, string user, string password) { try { ProcessNonExistingFile(path, metadata, webservice, token, transformedPath); } catch (OKMWebserviceException okex) { // Re-obtaining OpenKM authentication token, and retrying... Console.WriteLine(okex.Message); Console.WriteLine(okex.Source); Console.WriteLine(okex.StackTrace); Console.WriteLine(okex.TargetSite); //Console.WriteLine("Re-obtaining OpenKM authentication token, and retrying ProcessNonExistingFile..."); //Worker.LoginToOpenKMCommunityEdition(host, user, password, ref token, ref webservice); ////recurse //ProcessNonExistingFile(path, metadata, webservice, token, transformedPath); } catch (Exception ex) { Console.WriteLine(ex.Message); Console.WriteLine(ex.Source); Console.WriteLine(ex.StackTrace); Console.WriteLine(ex.TargetSite); //Console.WriteLine("Retrying ProcessNonExistingFile..."); ////recurse //ProcessNonExistingFile(path, metadata, webservice, token, transformedPath); } }
public static void LoginToOpenKMCommunityEdition(string host, string user, string password, ref String token, ref OKMWebservice webservice) { try { //Assuming the Application is still logged in to OpenKM, first log out. if (webservice != null) { //Log out of OpenKM webservice.logout(token); } //Log into OpenKM //Initialise WebService webservice = OKMWebServiceFactory.getInstance(host, user, password, OKMWebServiceFactory.COMMUNITY_6_0); //prepare token token = webservice.login(); } catch (OKMWebserviceException okex) { Console.WriteLine(okex.Message); Console.WriteLine(okex.Source); Console.WriteLine(okex.StackTrace); Console.WriteLine(okex.TargetSite); //LoginToOpenKMCommunityEdition(host, user, password, ref token, ref webservice); } catch (Exception ex) { Console.WriteLine(ex.Message); Console.WriteLine(ex.Source); Console.WriteLine(ex.StackTrace); Console.WriteLine(ex.TargetSite); //LoginToOpenKMCommunityEdition(host, user, password, ref token, ref webservice); } }
public void DoWork() { string host = nvcAllAppSettings["host"]; string user = "******"; string password = "******"; String token = string.Empty; OKMWebservice webservice = null; try { RecursiveFileProcessor recursiveFileProcessor = new RecursiveFileProcessor(_shutdownEvent, _pauseEvent); Console.Title = Path.GetFileName(_path) + " Webservice-Consumer"; if (Directory.Exists(_path)) { LoginToOpenKMCommunityEdition(host, user, password, ref token, ref webservice); // This path is a directory recursiveFileProcessor.ProcessDirectory(_path, webservice, token, host, user, password); //Log out of OpenKM webservice.logout(token); webservice = null; Console.WriteLine("The thread has completed its work. Press ENTER to continue."); } else { //Console.WriteLine("{0} is not a valid file or directory.", _path); Console.WriteLine("{0} is not a valid directory.", _path); } } catch (OKMWebserviceException okex) { Console.WriteLine(okex.Message); Console.WriteLine(okex.Source); Console.WriteLine(okex.StackTrace); Console.WriteLine(okex.TargetSite); //LoginToOpenKMCommunityEdition(host, user, password, ref token, ref webservice); } catch (Exception ex) { Console.WriteLine(ex.Message); Console.WriteLine(ex.Source); Console.WriteLine(ex.StackTrace); Console.WriteLine(ex.TargetSite); //LoginToOpenKMCommunityEdition(host, user, password, ref token, ref webservice); } finally { if (webservice != null) { //Log out of OpenKM webservice.logout(token); } } }