Exemple #1
0
        private void ValidateDataFile(string sourceName, bool isUnsearchable, bool isPublicFolder)
        {
            string text = string.Empty;

            if (isPublicFolder)
            {
                text = this.GetPFPstFilePath(isUnsearchable, 1);
            }
            else
            {
                text = this.GetPstFilePath(sourceName, isUnsearchable, 1);
            }
            if (File.Exists(text))
            {
                try
                {
                    PstWriter.CreatePstSession(text).Close();
                }
                catch (ExportException ex)
                {
                    Tracer.TraceError("PstTarget.ValidateDateFile: Failed to create PST session. Exception: {0}", new object[]
                    {
                        ex
                    });
                    throw new ExportException(ExportErrorType.FailedToOpenExistingPstFile, text);
                }
            }
        }
Exemple #2
0
        private void CreatePstFile(string filePath)
        {
            PstWriter.CreatePstSession(filePath).Close();
            ProgressRecord progressRecord = new ProgressRecord();
            ExportRecord   exportRecord   = new ExportRecord
            {
                ExportFile = new ExportFile
                {
                    Name = Path.GetFileName(filePath),
                    Path = filePath
                },
                SourceId         = null,
                Id               = Path.GetFileNameWithoutExtension(filePath),
                OriginalPath     = null,
                Parent           = null,
                Title            = null,
                DocumentType     = "File",
                RelationshipType = "None",
                IsUnsearchable   = this.dataContext.IsUnsearchable
            };

            if (this.dataContext.IsPublicFolder)
            {
                this.currentPFRecord = exportRecord;
                if (this.dataContext.IsUnsearchable)
                {
                    this.pfUnsearchableExportResult = this.currentPFRecord;
                }
                else
                {
                    this.pfExportResult = this.currentPFRecord;
                }
                progressRecord.ReportRootRecord(this.currentPFRecord);
            }
            else
            {
                this.currentRootRecord = exportRecord;
                if (this.dataContext.IsUnsearchable)
                {
                    this.rootUnsearchableExportResult = this.currentRootRecord;
                }
                else
                {
                    this.rootExportResult = this.currentRootRecord;
                }
                progressRecord.ReportRootRecord(this.currentRootRecord);
            }
            this.progressController.ReportProgress(progressRecord);
        }
Exemple #3
0
 public void ReOpenPFDataContext()
 {
     Tracer.TraceInformation("PstWriter.ReOpenPFDataContext: SourceId:{0}", new object[]
     {
         this.dataContext.SourceId
     });
     if (this.pstPFSession != null)
     {
         Tracer.TraceInformation("PstWriter.ReOpenPFDataContext: Closing public folder PST session", new object[0]);
         this.pstPFSession.Close();
         this.pstPFSession = null;
         Tracer.TraceInformation("PstWriter.ReOpenPFDataContext: PST public folder session closed", new object[0]);
     }
     if (this.currentPFRecord != null)
     {
         this.ReportFileInformation(this.currentPFRecord);
         this.currentPFRecord = null;
         if (!this.dataContext.IsUnsearchable)
         {
             this.pfExportResult = null;
         }
         else
         {
             this.pfUnsearchableExportResult = null;
         }
     }
     this.currentPFRecord = (this.dataContext.IsUnsearchable ? this.pfUnsearchableExportResult : this.pfExportResult);
     if (this.currentPFRecord == null && this.dataContext.ItemCount > 0)
     {
         this.EnsurePFPstFileCreated();
     }
     if (this.currentPFRecord != null && this.pstPFSession == null)
     {
         this.pstPFSession = PstWriter.CreatePstSession(this.currentPFRecord.ExportFile.Path);
         this.targetFolderProvider.Reset(this.dataContext);
         Tracer.TraceInformation("PstWriter.ReOpenPFDataContext: PST pf session created.", new object[0]);
     }
 }
Exemple #4
0
 public void EnterDataContext(DataContext context)
 {
     Tracer.TraceInformation("PstWriter.EnterDataContext: {0}", new object[]
     {
         context.SourceId
     });
     LocalFileHelper.CallFileOperation(delegate
     {
         string path = context.IsUnsearchable ? this.target.ExportContext.TargetLocation.UnsearchableExportLocation : this.target.ExportContext.TargetLocation.ExportLocation;
         DirectoryInfo directoryInfo = new DirectoryInfo(path);
         if (!directoryInfo.Exists)
         {
             Tracer.TraceInformation("PstWriter.EnterDataContext: Creating directory '{0}'", new object[]
             {
                 directoryInfo.FullName
             });
             Directory.CreateDirectory(directoryInfo.FullName);
         }
     }, ExportErrorType.FailedToCreateExportLocation);
     this.dataContext = context;
     this.timer.Restart();
     this.targetFolderProvider.Reset(this.dataContext);
     if (this.dataContext.IsPublicFolder)
     {
         long num = 0L;
         foreach (ItemId itemId in this.dataContext.ItemIdList.ReadItemIds())
         {
             num += (long)((ulong)itemId.Size);
         }
         if (this.dataContext.IsUnsearchable)
         {
             if (this.unsearchablePFTotalSize > 0L && this.unsearchablePFTotalSize + num > ConstantProvider.PSTSizeLimitInBytes && num < ConstantProvider.PSTSizeLimitInBytes)
             {
                 this.ReOpenPFDataContext();
                 this.unsearchablePFTotalSize = 0L;
             }
         }
         else if (this.searchablePFTotalSize > 0L && this.searchablePFTotalSize + num > ConstantProvider.PSTSizeLimitInBytes && num < ConstantProvider.PSTSizeLimitInBytes)
         {
             this.ReOpenPFDataContext();
             this.searchablePFTotalSize = 0L;
         }
         this.currentPFRecord = (this.dataContext.IsUnsearchable ? this.pfUnsearchableExportResult : this.pfExportResult);
         if (this.currentPFRecord == null && this.dataContext.ItemCount > 0)
         {
             this.EnsurePFPstFileCreated();
         }
         if (this.currentPFRecord != null && this.pstPFSession == null)
         {
             this.pstPFSession = PstWriter.CreatePstSession(this.currentPFRecord.ExportFile.Path);
             Tracer.TraceInformation("PstWriter.EnterDataContext: PST pf session created.", new object[0]);
             return;
         }
     }
     else
     {
         this.pstMBFileCount          = 1;
         this.unsearchableMBTotalSize = 0L;
         this.searchableMBTotalSize   = 0L;
         this.currentRootRecord       = (this.dataContext.IsUnsearchable ? this.rootUnsearchableExportResult : this.rootExportResult);
         if (this.currentRootRecord == null && this.dataContext.ItemCount > 0)
         {
             this.EnsurePstFileCreated();
         }
         if (this.currentRootRecord != null)
         {
             this.pstSession = PstWriter.CreatePstSession(this.currentRootRecord.ExportFile.Path);
             Tracer.TraceInformation("PstWriter.EnterDataContext: PST session created.", new object[0]);
         }
     }
 }
Exemple #5
0
        public void WriteDataBatch(List <ItemInformation> dataBatch)
        {
            Tracer.TraceInformation("PstWriter.WriteDataBatch: Writing data batch for mailbox '{0}', item count: {1}", new object[]
            {
                this.dataContext.SourceId,
                dataBatch.Count
            });
            ProgressRecord progressRecord = new ProgressRecord(this.dataContext);
            PSTSession     pstsession     = this.dataContext.IsPublicFolder ? this.pstPFSession : this.pstSession;

            try
            {
                foreach (ItemInformation itemInformation in dataBatch)
                {
                    if (this.progressController.IsStopRequested)
                    {
                        Tracer.TraceInformation("PstWriter.WriteDataBatch: Stop requested when processing mailbox '{0}'", new object[]
                        {
                            this.dataContext.SourceId
                        });
                        break;
                    }
                    try
                    {
                        if (this.dataContext.IsPublicFolder)
                        {
                            if (this.dataContext.IsUnsearchable)
                            {
                                if (this.unsearchablePFTotalSize > 0L && this.unsearchablePFTotalSize + (long)((ulong)itemInformation.Id.Size) > ConstantProvider.PSTSizeLimitInBytes)
                                {
                                    this.ReOpenPFDataContext();
                                    pstsession = this.pstPFSession;
                                    this.unsearchablePFTotalSize = 0L;
                                }
                                this.unsearchablePFTotalSize += (long)((ulong)itemInformation.Id.Size);
                            }
                            else
                            {
                                if (this.searchablePFTotalSize > 0L && this.searchablePFTotalSize + (long)((ulong)itemInformation.Id.Size) > ConstantProvider.PSTSizeLimitInBytes)
                                {
                                    this.ReOpenPFDataContext();
                                    pstsession = this.pstPFSession;
                                    this.searchablePFTotalSize = 0L;
                                }
                                this.searchablePFTotalSize += (long)((ulong)itemInformation.Id.Size);
                            }
                        }
                        else if (this.dataContext.IsUnsearchable)
                        {
                            if (this.unsearchableMBTotalSize > 0L && this.unsearchableMBTotalSize + (long)((ulong)itemInformation.Id.Size) > ConstantProvider.PSTSizeLimitInBytes)
                            {
                                this.ReOpenMBDataContext();
                                pstsession = this.pstSession;
                                this.unsearchableMBTotalSize = 0L;
                            }
                            this.unsearchableMBTotalSize += (long)((ulong)itemInformation.Id.Size);
                        }
                        else
                        {
                            if (this.searchableMBTotalSize > 0L && this.searchableMBTotalSize + (long)((ulong)itemInformation.Id.Size) > ConstantProvider.PSTSizeLimitInBytes)
                            {
                                this.ReOpenMBDataContext();
                                pstsession = this.pstSession;
                                this.searchableMBTotalSize = 0L;
                            }
                            this.searchableMBTotalSize += (long)((ulong)itemInformation.Id.Size);
                        }
                        if (itemInformation.Error == null)
                        {
                            if (itemInformation.Id.IsDuplicate)
                            {
                                progressRecord.ReportItemExported(itemInformation.Id, null, null);
                            }
                            else
                            {
                                IFolder parentFolder = this.targetFolderProvider.GetParentFolder(pstsession, itemInformation.Id.ParentFolder, this.target.ExportContext.ExportMetadata.IncludeDuplicates);
                                if (parentFolder == null)
                                {
                                    if (!this.dataContext.IsPublicFolder)
                                    {
                                        progressRecord.ReportItemError(itemInformation.Id, this.currentRootRecord, ExportErrorType.ParentFolderNotFound, string.Format(CultureInfo.CurrentCulture, "Parent folder '{0}' is missing, this may caused by newly created folder", new object[]
                                        {
                                            itemInformation.Id.ParentFolder
                                        }));
                                        Tracer.TraceError("PstWriter.WriteDataBatch: Failed to get the parent folder of current message to export. Mailbox: '{0}', Message Id: '{1}', Folder Path: '{2}'", new object[]
                                        {
                                            this.dataContext.SourceId,
                                            itemInformation.Id.Id,
                                            itemInformation.Id.ParentFolder
                                        });
                                    }
                                    else
                                    {
                                        progressRecord.ReportItemError(itemInformation.Id, this.currentPFRecord, ExportErrorType.ParentFolderNotFound, string.Format(CultureInfo.CurrentCulture, "Parent folder '{0}' is missing, this may caused by newly created folder", new object[]
                                        {
                                            itemInformation.Id.ParentFolder
                                        }));
                                        Tracer.TraceError("PstWriter.WriteDataBatch: Failed to get the parent folder of current message to export. Mailbox: '{0}', Message Id: '{1}', Folder Path: '{2}'", new object[]
                                        {
                                            this.dataContext.SourceId,
                                            itemInformation.Id.Id,
                                            itemInformation.Id.ParentFolder
                                        });
                                    }
                                }
                                else
                                {
                                    IMessage message = PstWriter.CreatePstMessage(pstsession, parentFolder, itemInformation, !this.target.ExportContext.ExportMetadata.IncludeDuplicates);
                                    if (!this.dataContext.IsPublicFolder)
                                    {
                                        progressRecord.ReportItemExported(itemInformation.Id, this.currentRootRecord.ExportFile.Name + '/' + PstWriter.CreateEntryIdFromNodeId(pstsession.MessageStore.Guid, message.Id), this.currentRootRecord);
                                    }
                                    else
                                    {
                                        progressRecord.ReportItemExported(itemInformation.Id, this.currentPFRecord.ExportFile.Name + '/' + PstWriter.CreateEntryIdFromNodeId(pstsession.MessageStore.Guid, message.Id), this.currentPFRecord);
                                    }
                                }
                            }
                        }
                        else if (!this.dataContext.IsPublicFolder)
                        {
                            progressRecord.ReportItemError(itemInformation.Id, this.currentRootRecord, itemInformation.Error.ErrorType, itemInformation.Error.Message);
                        }
                        else
                        {
                            progressRecord.ReportItemError(itemInformation.Id, this.currentPFRecord, itemInformation.Error.ErrorType, itemInformation.Error.Message);
                        }
                    }
                    catch (ExportException ex)
                    {
                        Tracer.TraceError("PstWriter.WriteDataBatch: Exception happed. Mailbox:'{0}'. Exception:'{1}'", new object[]
                        {
                            this.dataContext.SourceId,
                            ex
                        });
                        if (!this.dataContext.IsPublicFolder)
                        {
                            progressRecord.ReportItemError(itemInformation.Id, this.currentRootRecord, ex.ErrorType, ex.Message);
                        }
                        else
                        {
                            progressRecord.ReportItemError(itemInformation.Id, this.currentPFRecord, ex.ErrorType, ex.Message);
                        }
                    }
                }
            }
            finally
            {
                this.timer.Stop();
                progressRecord.ReportDuration(this.timer.Elapsed);
                this.progressController.ReportProgress(progressRecord);
                this.timer.Restart();
            }
        }