/// <summary>
 /// Generates the MSG file.
 /// </summary>
 /// <param name="outlookMessageExtractor">The outlook message extractor.</param>
 /// <param name="pstFilePath">The PST file path.</param>
 /// <param name="keyValues">The key values.</param>
 private void GenerateMsgFile(OutlookMessageExtractor outlookMessageExtractor, string pstFilePath, KeyValuePair<string, string> keyValues)
 {
     try
     {
         outlookMessageExtractor.ExtractMessage(pstFilePath, keyValues.Key, keyValues.Value);
     }
     catch (Exception ex)
     {
         if (ex.GetErrorCode().Equals(ErrorCodes.EmptyMsgFileGenerationFaliure))
         {
             throw;
         }
         ex.AddResMsg(ErrorCodes.EDocsEmailGenaratorWorker_MsgGenerationFailed);
         ReportToDirector(ex);
         ex.Trace().Swallow();
     }
 }
        /// <summary>
        /// Processes the message.
        /// </summary>
        /// <param name="envelope">The envelope.</param>
        protected override void ProcessMessage(PipeMessageEnvelope envelope)
        {
            base.ProcessMessage(envelope);

            try
            {
                EDocsDocumentCollection eDocsDocumentCollection = envelope.Body as EDocsDocumentCollection;
                if (eDocsDocumentCollection != null
                && eDocsDocumentCollection.OutlookMailStoreDataEntity != null
                && eDocsDocumentCollection.OutlookMailStoreDataEntity.Any())
                {
                    foreach (OutlookMailStoreEntity outlookMailStoreEntity in eDocsDocumentCollection.OutlookMailStoreDataEntity)
                    {
                        if (outlookMailStoreEntity.EntryIdAndEmailMessagePairs != null && outlookMailStoreEntity.EntryIdAndEmailMessagePairs.Any())
                        {

                            string pstFilePath = outlookMailStoreEntity.PSTFile.FullName;
                            OutlookMessageExtractor outlookMessageExtractor = new OutlookMessageExtractor();

                            // extract .msg files
                            outlookMailStoreEntity.EntryIdAndEmailMessagePairs
                                .ToList().SafeForEach(keyValues => GenerateMsgFile(outlookMessageExtractor, pstFilePath, keyValues));

                            // framework call for increasing count of documents processed.
                            IncreaseProcessedDocumentsCount(outlookMailStoreEntity.EntryIdAndEmailMessagePairs.Count());

                        }
                    }
                }

                else
                {
                    throw new EVException().AddResMsg(ErrorCodes.EDocsCollectionEntityEmpty);
                }
            }
            catch (Exception ex)
            {
                ReportToDirector(ex);
                ex.Trace().Swallow();
            }
        }