void MergeDirectory(WorkspaceDirectoryInfo WorkspaceDir, WorkspaceDirectoryInfo NewWorkspaceDir, StreamDirectoryInfo StreamDir, ThreadPoolWorkQueue Queue)
        {
            // Make sure the directory exists
            Directory.CreateDirectory(WorkspaceDir.GetFullName());

            // Update all the subdirectories
            foreach (StreamDirectoryInfo StreamSubDir in StreamDir.NameToSubDirectory.Values)
            {
                WorkspaceDirectoryInfo WorkspaceSubDir;
                if (WorkspaceDir.NameToSubDirectory.TryGetValue(StreamSubDir.Name, out WorkspaceSubDir))
                {
                    MergeSubDirectory(WorkspaceSubDir, StreamSubDir, NewWorkspaceDir, Queue);
                }
                else
                {
                    AddSubDirectory(NewWorkspaceDir, StreamSubDir, Queue);
                }
            }

            // Move files into this folder
            foreach (StreamFileInfo StreamFile in StreamDir.NameToFile.Values)
            {
                WorkspaceFileInfo WorkspaceFile;
                if (WorkspaceDir.NameToFile.TryGetValue(StreamFile.Name, out WorkspaceFile))
                {
                    NewWorkspaceDir.NameToFile.Add(WorkspaceFile.Name, WorkspaceFile);
                }
                else
                {
                    AddFile(NewWorkspaceDir, StreamFile);
                }
            }
        }
 public WorkspaceDirectoryInfo(WorkspaceDirectoryInfo ParentDirectory, string Name)
 {
     this.ParentDirectory    = ParentDirectory;
     this.Name               = Name;
     this.NameToFile         = new Dictionary <string, WorkspaceFileInfo>(StringComparer.Ordinal);
     this.NameToSubDirectory = new Dictionary <string, WorkspaceDirectoryInfo>(FileUtils.PlatformPathComparer);
 }
        void AddFile(WorkspaceDirectoryInfo NewWorkspaceDir, StreamFileInfo StreamFile)
        {
            // Create a new file for this workspace
            WorkspaceFileInfo WorkspaceFile = new WorkspaceFileInfo(NewWorkspaceDir, StreamFile.Name, StreamFile.ContentId);

            NewWorkspaceDir.NameToFile.Add(StreamFile.Name, WorkspaceFile);

            // Try to add it to the cache
            TrackedFileInfo TrackedFile;

            if (ContentIdToTrackedFile.TryGetValue(StreamFile.ContentId, out TrackedFile))
            {
                if (FilesToMove.TryAdd(TrackedFile, new WorkspaceFileToMove(StreamFile, TrackedFile, WorkspaceFile)))
                {
                    WorkspaceFile.SetMetadata(TrackedFile.Length, TrackedFile.LastModifiedTicks, TrackedFile.bReadOnly);
                }
                else
                {
                    FilesToCopy.Add(new WorkspaceFileToCopy(StreamFile, FilesToMove[TrackedFile].WorkspaceFile, WorkspaceFile));
                }
            }
            else
            {
                WorkspaceFileInfo SourceWorkspaceFile;
                if (ContentIdToWorkspaceFile.TryGetValue(StreamFile.ContentId, out SourceWorkspaceFile))
                {
                    FilesToCopy.Add(new WorkspaceFileToCopy(StreamFile, SourceWorkspaceFile, WorkspaceFile));
                }
                else
                {
                    FilesToSync.Add(new WorkspaceFileToSync(StreamFile, WorkspaceFile));
                }
            }
        }
        void AddSubDirectory(WorkspaceDirectoryInfo NewWorkspaceDir, StreamDirectoryInfo StreamSubDir, ThreadPoolWorkQueue Queue)
        {
            WorkspaceDirectoryInfo NewWorkspaceSubDir = new WorkspaceDirectoryInfo(NewWorkspaceDir, StreamSubDir.Name);

            NewWorkspaceDir.NameToSubDirectory.Add(StreamSubDir.Name, NewWorkspaceSubDir);
            Queue.Enqueue(() => AddDirectory(NewWorkspaceSubDir, StreamSubDir, Queue));
        }
示例#5
0
        void Merge(WorkspaceDirectoryInfo WorkspaceDir, WorkspaceDirectoryInfo NewWorkspaceDir, StreamDirectoryInfo StreamDir, ThreadPoolWorkQueue Queue)
        {
            // Update all the subdirectories
            foreach (WorkspaceDirectoryInfo WorkspaceSubDir in WorkspaceDir.NameToSubDirectory.Values)
            {
                StreamDirectoryInfo StreamSubDir;
                if (StreamDir.NameToSubDirectory.TryGetValue(WorkspaceSubDir.Name, out StreamSubDir))
                {
                    MergeSubDirectory(NewWorkspaceDir, WorkspaceSubDir, StreamSubDir, Queue);
                }
                else
                {
                    RemoveDirectory(WorkspaceSubDir, Queue);
                }
            }

            // Update the staged files
            foreach (WorkspaceFileInfo WorkspaceFile in WorkspaceDir.NameToFile.Values)
            {
                StreamFileInfo StreamFile;
                if (StreamDir != null && StreamDir.NameToFile.TryGetValue(WorkspaceFile.Name, out StreamFile) && StreamFile.ContentId.Equals(WorkspaceFile.ContentId))
                {
                    NewWorkspaceDir.NameToFile.Add(WorkspaceFile.Name, WorkspaceFile);
                }
                else
                {
                    RemoveFile(WorkspaceFile);
                }
            }
        }
 public WorkspaceFileInfo(WorkspaceDirectoryInfo Directory, BinaryReader Reader)
 {
     this.Directory         = Directory;
     this.Name              = Reader.ReadString();
     this.Length            = Reader.ReadInt64();
     this.LastModifiedTicks = Reader.ReadInt64();
     this.bReadOnly         = Reader.ReadBoolean();
     this.ContentId         = Reader.ReadObject <FileContentId>();
 }
 public WorkspaceFileInfo(WorkspaceDirectoryInfo Directory, string Name, long Length, long LastModifiedTicks, bool bReadOnly, FileContentId ContentId)
 {
     this.Directory         = Directory;
     this.Name              = Name;
     this.Length            = Length;
     this.LastModifiedTicks = LastModifiedTicks;
     this.bReadOnly         = bReadOnly;
     this.ContentId         = ContentId;
 }
示例#8
0
        public WorkspaceTransactionRemove(WorkspaceDirectoryInfo WorkspaceRootDir, StreamDirectoryInfo StreamRootDir, Dictionary <FileContentId, TrackedFileInfo> ContentIdToTrackedFile)
        {
            this.NewWorkspaceRootDir    = new WorkspaceDirectoryInfo(WorkspaceRootDir.GetLocation());
            this.ContentIdToTrackedFile = ContentIdToTrackedFile;

            using (ThreadPoolWorkQueue Queue = new ThreadPoolWorkQueue())
            {
                Queue.Enqueue(() => Merge(WorkspaceRootDir, NewWorkspaceRootDir, StreamRootDir, Queue));
            }
        }
示例#9
0
        void RemoveDirectory(WorkspaceDirectoryInfo WorkspaceDir, ThreadPoolWorkQueue Queue)
        {
            DirectoriesToDelete.Add(WorkspaceDir);

            foreach (WorkspaceDirectoryInfo WorkspaceSubDir in WorkspaceDir.NameToSubDirectory.Values)
            {
                Queue.Enqueue(() => RemoveDirectory(WorkspaceSubDir, Queue));
            }
            foreach (WorkspaceFileInfo WorkspaceFile in WorkspaceDir.NameToFile.Values)
            {
                RemoveFile(WorkspaceFile);
            }
        }
        void AddDirectory(WorkspaceDirectoryInfo NewWorkspaceDir, StreamDirectoryInfo StreamDir, ThreadPoolWorkQueue Queue)
        {
            // Make sure the directory exists
            Directory.CreateDirectory(NewWorkspaceDir.GetFullName());

            // Add all the sub directories and files
            foreach (StreamDirectoryInfo StreamSubDir in StreamDir.NameToSubDirectory.Values)
            {
                AddSubDirectory(NewWorkspaceDir, StreamSubDir, Queue);
            }
            foreach (StreamFileInfo StreamFile in StreamDir.NameToFile.Values)
            {
                AddFile(NewWorkspaceDir, StreamFile);
            }
        }
        public void Read(BinaryReader Reader)
        {
            WorkspaceFileInfo[] Files = new WorkspaceFileInfo[Reader.ReadInt32()];
            for (int Idx = 0; Idx < Files.Length; Idx++)
            {
                Files[Idx] = new WorkspaceFileInfo(this, Reader);
            }
            NameToFile = Files.ToDictionary(x => x.Name, x => x, StringComparer.Ordinal);

            int NumSubDirectories = Reader.ReadInt32();

            for (int Idx = 0; Idx < NumSubDirectories; Idx++)
            {
                WorkspaceDirectoryInfo SubDirectory = new WorkspaceDirectoryInfo(this, Reader.ReadString());
                SubDirectory.Read(Reader);
                NameToSubDirectory[SubDirectory.Name] = SubDirectory;
            }
        }
        public WorkspaceTransactionAdd(WorkspaceDirectoryInfo WorkspaceRootDir, StreamDirectoryInfo StreamRootDir, Dictionary <FileContentId, TrackedFileInfo> ContentIdToTrackedFile)
        {
            this.NewWorkspaceRootDir = new WorkspaceDirectoryInfo(WorkspaceRootDir.GetLocation());

            this.ContentIdToTrackedFile = ContentIdToTrackedFile;

            List <WorkspaceFileInfo> WorkspaceFiles = WorkspaceRootDir.GetFiles();

            foreach (WorkspaceFileInfo WorkspaceFile in WorkspaceFiles)
            {
                ContentIdToWorkspaceFile[WorkspaceFile.ContentId] = WorkspaceFile;
            }

            using (ThreadPoolWorkQueue Queue = new ThreadPoolWorkQueue())
            {
                Queue.Enqueue(() => MergeDirectory(WorkspaceRootDir, NewWorkspaceRootDir, StreamRootDir, Queue));
            }
        }
 public WorkspaceFileInfo(WorkspaceDirectoryInfo Directory, string Name, FileInfo Info, FileContentId ContentId)
     : this(Directory, Name, Info.Length, Info.LastWriteTimeUtc.Ticks, Info.Attributes.HasFlag(FileAttributes.ReadOnly), ContentId)
 {
 }
 public WorkspaceFileInfo(WorkspaceDirectoryInfo Directory, string Name, FileContentId ContentId)
 {
     this.Directory = Directory;
     this.Name      = Name;
     this.ContentId = ContentId;
 }