Beispiel #1
0
        internal static PSTSession CreatePstSession(string pstFilePath)
        {
            Tracer.TraceInformation("PstWriter.CreatePstSession: Creating PST session for PST file '{0}'", new object[]
            {
                pstFilePath
            });
            PSTSession pstsession = new PSTSession(new Tracer.TraceMethod(Tracer.TraceInformation), new Tracer.TraceMethod(Tracer.TraceWarning), new Tracer.TraceMethod(Tracer.TraceError));

            try
            {
                pstsession.Open(pstFilePath, true, true, false);
            }
            catch (PSTExceptionBase pstexceptionBase)
            {
                Tracer.TraceError("PstWriter.CreatePstSession: Exception: {0}", new object[]
                {
                    pstexceptionBase
                });
                throw new ExportException(ExportErrorType.FailedToOpenPstFile, pstexceptionBase);
            }
            return(pstsession);
        }
Beispiel #2
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();
            }
        }