Exemple #1
0
 public IEnumerable <ItemId> ReadItemIds()
 {
     if (this.Exists)
     {
         FileStream fileStream = null;
         try
         {
             LocalFileHelper.CallFileOperation(delegate
             {
                 fileStream = new FileStream(this.filePath, FileMode.Open, FileAccess.Read);
             }, ExportErrorType.FailedToReadItemIdList);
             while (fileStream.Position < fileStream.Length)
             {
                 ItemId itemId = this.IsUnsearchable ? new UnsearchableItemId() : new ItemId();
                 LocalFileHelper.CallFileOperation(delegate
                 {
                     itemId.ReadFromStream(fileStream, this.SourceId);
                 }, ExportErrorType.FailedToReadItemIdList);
                 yield return(itemId);
             }
         }
         finally
         {
             if (fileStream != null)
             {
                 fileStream.Flush();
                 fileStream.Dispose();
             }
         }
     }
     yield break;
 }
Exemple #2
0
 public void Flush()
 {
     LocalFileHelper.CallFileOperation(delegate
     {
         if (this.memoryCache.Count > 0)
         {
             using (FileStream fileStream = new FileStream(this.filePath, FileMode.Append, FileAccess.Write))
             {
                 foreach (ItemId itemId in this.memoryCache)
                 {
                     itemId.WriteToStream(fileStream);
                     if (this.IsUnsearchable && !(itemId is UnsearchableItemId))
                     {
                         UnsearchableItemId.WriteDummyToStream(fileStream);
                     }
                 }
             }
             Tracer.TraceInformation("LocalFileItemList.Flush: {0} item IDs are written into '{1}'", new object[]
             {
                 this.memoryCache.Count,
                 this.filePath
             });
         }
         this.memoryCache.Clear();
     }, ExportErrorType.FailedToWriteItemIdList);
 }
 public static void RemoveFile(string filePath, ExportErrorType errorType)
 {
     LocalFileHelper.CallFileOperation(delegate
     {
         if (File.Exists(filePath))
         {
             File.Delete(filePath);
         }
     }, errorType);
 }
Exemple #4
0
 public void Rollback(SourceInformationCollection allSourceInformation)
 {
     Tracer.TraceInformation("PstTarget.Rollback - Start", new object[0]);
     Tracer.TraceInformation("PstTarget.Rollback IncludeDuplicates {0}, IncludeSearchableItems {1}, IncludeUnsearchableItems {2}", new object[]
     {
         this.ExportContext.ExportMetadata.IncludeDuplicates ? "true" : "false",
         this.ExportContext.ExportMetadata.IncludeSearchableItems ? "true" : "false",
         this.ExportContext.ExportMetadata.IncludeUnsearchableItems ? "true" : "false"
     });
     foreach (SourceInformation sourceInformation in allSourceInformation.Values)
     {
         Tracer.TraceInformation("PstTarget.Rollback source Id {0}, source Name {1}", new object[]
         {
             sourceInformation.Configuration.Id,
             sourceInformation.Configuration.Name
         });
         bool isPublicFolder = sourceInformation.Configuration.Id.StartsWith("\\");
         if (this.ExportContext.ExportMetadata.IncludeDuplicates)
         {
             if (this.ExportContext.ExportMetadata.IncludeSearchableItems)
             {
                 this.RemoveFileForSource(sourceInformation.Configuration.Name, false, isPublicFolder);
             }
             if (this.ExportContext.ExportMetadata.IncludeUnsearchableItems)
             {
                 this.RemoveFileForSource(sourceInformation.Configuration.Name, true, isPublicFolder);
             }
         }
         if (this.ExportContext.ExportMetadata.IncludeSearchableItems)
         {
             string itemIdListFilePath = this.GetItemIdListFilePath(sourceInformation.Configuration.Id, false);
             LocalFileHelper.RemoveFile(itemIdListFilePath, ExportErrorType.FailedToRollbackResultsInTargetLocation);
         }
         if (this.ExportContext.ExportMetadata.IncludeUnsearchableItems)
         {
             string itemIdListFilePath2 = this.GetItemIdListFilePath(sourceInformation.Configuration.Id, true);
             LocalFileHelper.RemoveFile(itemIdListFilePath2, ExportErrorType.FailedToRollbackResultsInTargetLocation);
         }
     }
     if (!this.ExportContext.ExportMetadata.IncludeDuplicates)
     {
         if (this.ExportContext.ExportMetadata.IncludeSearchableItems)
         {
             this.RemoveFileForSource(null, false, false);
             this.RemoveFileForSource(null, false, true);
         }
         if (this.ExportContext.ExportMetadata.IncludeUnsearchableItems)
         {
             this.RemoveFileForSource(null, true, false);
             this.RemoveFileForSource(null, true, true);
         }
     }
     Tracer.TraceInformation("PstTarget.Rollback - End", new object[0]);
 }
Exemple #5
0
        private void RemoveFileForSource(string source, bool isUnsearchable, bool isPublicFolder)
        {
            Tracer.TraceInformation("PstTarget.RemoveFileForSource ", new object[0]);
            int    num  = 1000;
            string text = string.Empty;
            bool   flag = true;
            int    num2 = 1;

            while (flag)
            {
                if (isPublicFolder)
                {
                    text = this.GetPFPstFilePath(isUnsearchable, num2++);
                }
                else
                {
                    text = this.GetPstFilePath(source, isUnsearchable, num2++);
                }
                if (File.Exists(text))
                {
                    try
                    {
                        LocalFileHelper.RemoveFile(text, ExportErrorType.FailedToRollbackResultsInTargetLocation);
                        goto IL_81;
                    }
                    catch (ExportException ex)
                    {
                        Tracer.TraceError("PstTarget.RemoveFileForSource: Failed FileName: {0}, Exception: {1}", new object[]
                        {
                            text,
                            ex.ToString()
                        });
                        goto IL_81;
                    }
                    goto IL_7F;
                }
                goto IL_7F;
IL_81:
                if (num2 > num)
                {
                    Tracer.TraceError("PstTarget.RemoveFileForSource: Exceeded fileCount limit of {0} files for source {1}.", new object[]
                    {
                        num2,
                        source
                    });
                    return;
                }
                continue;
IL_7F:
                flag = false;
                goto IL_81;
            }
        }
Exemple #6
0
 public void CheckInitialStatus(SourceInformationCollection allSourceInformation, OperationStatus status)
 {
     foreach (SourceInformation sourceInformation in allSourceInformation.Values)
     {
         bool isPublicFolder = sourceInformation.Configuration.Id.StartsWith("\\");
         if (this.ExportContext.ExportMetadata.IncludeDuplicates)
         {
             if (this.ExportContext.ExportMetadata.IncludeSearchableItems)
             {
                 this.ValidateDataFile(sourceInformation.Configuration.Name, false, isPublicFolder);
             }
             if (this.ExportContext.ExportMetadata.IncludeUnsearchableItems)
             {
                 this.ValidateDataFile(sourceInformation.Configuration.Name, true, isPublicFolder);
             }
         }
         if (!this.ExportContext.IsResume || !sourceInformation.Status.IsSearchCompleted(this.ExportContext.ExportMetadata.IncludeSearchableItems, this.ExportContext.ExportMetadata.IncludeUnsearchableItems))
         {
             if (this.ExportContext.ExportMetadata.IncludeSearchableItems)
             {
                 string itemIdListFilePath = this.GetItemIdListFilePath(sourceInformation.Configuration.Id, false);
                 LocalFileHelper.RemoveFile(itemIdListFilePath, ExportErrorType.FailedToCleanupCorruptedStatusLog);
             }
             if (this.ExportContext.ExportMetadata.IncludeUnsearchableItems)
             {
                 string itemIdListFilePath2 = this.GetItemIdListFilePath(sourceInformation.Configuration.Id, true);
                 LocalFileHelper.RemoveFile(itemIdListFilePath2, ExportErrorType.FailedToCleanupCorruptedStatusLog);
             }
         }
     }
     if (!this.ExportContext.ExportMetadata.IncludeDuplicates)
     {
         if (this.ExportContext.ExportMetadata.IncludeSearchableItems)
         {
             this.ValidateDataFile(null, false, false);
         }
         if (this.ExportContext.ExportMetadata.IncludeUnsearchableItems)
         {
             this.ValidateDataFile(null, true, false);
         }
     }
 }
Exemple #7
0
 public void RemoveItemIdList(string mailboxId, bool isUnsearchable)
 {
     LocalFileHelper.RemoveFile(this.GetItemIdListFilePath(mailboxId, isUnsearchable), ExportErrorType.FailedToRemoveItemIdList);
 }
Exemple #8
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]);
         }
     }
 }