Example #1
0
        static void OnMessageArrival(IAsyncResult ar)
        {
            //Cast the state object to type MessageQueue
            MQObjectStateStore mQObjectStateStore = (MQObjectStateStore)ar.AsyncState;

            //MessageQueue pQueue = (MessageQueue)ar.AsyncState;
            try
            {
                Message message = mQObjectStateStore.PQueue.EndReceive(ar);
                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
                mQObjectStateStore.DynamicDocPath = mQObjectStateStore.DynamicDocPath + transformedPathTokens[3].Trim();

                CreateOKMYearFolder(mQObjectStateStore.Webservice, mQObjectStateStore.Token, mQObjectStateStore.Host, mQObjectStateStore.User, mQObjectStateStore.Password, mQObjectStateStore.DynamicDocPath);

                //Attempt to create the month folder in OpenKM
                //Modify the OpenKM path string to contain the month as a folder
                mQObjectStateStore.DynamicDocPath = mQObjectStateStore.DynamicDocPath + "/" + transformedPathTokens[4].Trim();

                CreateOKMMonthFolder(mQObjectStateStore.Webservice, mQObjectStateStore.Token, mQObjectStateStore.Host, mQObjectStateStore.User, mQObjectStateStore.Password, mQObjectStateStore.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
                mQObjectStateStore.DynamicDocPath = mQObjectStateStore.DynamicDocPath + "/" + transformedPathTokens[5].Trim();

                CreateOKMFileFolder(mQObjectStateStore.Webservice, mQObjectStateStore.Token, mQObjectStateStore.Host, mQObjectStateStore.User, mQObjectStateStore.Password, mQObjectStateStore.DynamicDocPath);

                //transformedPath = dynamicDocPath + "/" + pathWithoutExtention.Substring(pathWithoutExtention.LastIndexOf(@"\") + 1) + ext;

                /////

                ProcessFile(docuwareMigrationDataPointerReceiver.Path, docuwareMigrationDataPointerReceiver.Metadata, mQObjectStateStore.Webservice, mQObjectStateStore.Token, docuwareMigrationDataPointerReceiver.TransformedPath, mQObjectStateStore.Host, mQObjectStateStore.User, mQObjectStateStore.Password);
            }
            catch
            {
                Console.WriteLine("MessageQueue TimeOut Occurred! Recovering...");
            }
            finally
            {
                mQObjectStateStore.PQueue.BeginReceive(TimeSpan.FromSeconds(5), mQObjectStateStore.PQueue, new AsyncCallback(OnMessageArrival));
            }
        }
Example #2
0
        // 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());
                }
            }
        }