コード例 #1
0
ファイル: Vault.cs プロジェクト: benjaminc/AmazonGlacierSync
        private Exception uploadArchive(ArchiveTransferManager manager, Archive arch, string basePath)
        {
            int rep = 0;
            Exception error = null;
            isDirty = true;

            do
            {
                if (rep > 0)
                {
                    Thread.Sleep(2000);
                }

                try
                {
                    DateTime start = DateTime.Now;
                    arch.upload(manager, VaultName, basePath);
                    UploadTime += DateTime.Now.Subtract(start);
                    UploadBytes += arch.FileLength;

                    if (!inventoryByPath.ContainsKey(arch.RelativePath))
                    {
                        inventoryByPath[arch.RelativePath] = new List<Archive>();
                    }

                    inventoryByPath[arch.RelativePath].Add(arch);
                    inventoryById[arch.ArchiveId] = arch;
                    toUpload.Remove(arch);
                }
                catch(Exception ex)
                {
                    error = ex;
                }
            }
            while (++rep < 4 && error != null);

            return error;
        }
コード例 #2
0
ファイル: Vault.cs プロジェクト: benjaminc/AmazonGlacierSync
        private Exception deleteArchive(ArchiveTransferManager manager, KeyValuePair<string, List<Archive>> entryInThis, Archive archive)
        {
            int rep = 0;
            Exception error = null;
            isDirty = true;

            do
            {
                if (rep > 0)
                {
                    Thread.Sleep(2000);
                }

                try
                {
                    DateTime start = DateTime.Now;
                    manager.DeleteArchive(VaultName, archive.ArchiveId);
                    DeleteTime += DateTime.Now.Subtract(start);
                    entryInThis.Value.Remove(archive);
                    inventoryById.Remove(archive.ArchiveId);

                    if (entryInThis.Value.Count == 0)
                    {
                        inventoryByPath.Remove(entryInThis.Key);
                    }

                    toDelete.Remove(archive);
                }
                catch(Exception ex)
                {
                    error = ex;
                }
            }
            while (++rep < 4 && error != null);

            return error;
        }
コード例 #3
0
ファイル: Vault.cs プロジェクト: benjaminc/AmazonGlacierSync
        public void uploadNewAndChanged(ArchiveTransferManager manager, string basePath, Dictionary<string, FileDetail> localFiles, Func<bool> keepRunning)
        {
            Archive arch;
            bool hasMatch;
            toUpload.Clear();

            foreach (FileDetail file in localFiles.Values)
            {
                if (!keepRunning())
                {
                    return;
                }

                if (!inventoryByPath.ContainsKey(file.RelativePath))
                {
                    arch = new Archive(file);
                    toUpload.Add(arch);
                }
                else
                {
                    hasMatch = false;

                    foreach (Archive a in inventoryByPath[file.RelativePath])
                    {
                        if (a.FileLength == file.FileLength && a.LastModified == file.LastModified)
                        {
                            hasMatch = true;
                        }
                    }

                    if (!hasMatch)
                    {
                        arch = new Archive(file);
                        toUpload.Add(arch);
                    }
                }
            }

            toUpload.Sort();
            toUpload.Reverse();

            Exception error;
            for (int i = toUpload.Count - 1; i >= 0 ; i--)
            {
                if (!keepRunning())
                {
                    return;
                }

                arch = toUpload[i];
                if ((error = uploadArchive(manager, arch, basePath)) == null)
                {
                    UploadCount++;
                }
                else
                {
                    uploadErrors[arch] = error;
                }
            }
        }
コード例 #4
0
ファイル: Vault.cs プロジェクト: benjaminc/AmazonGlacierSync
        private void addNewArchive(Archive arch)
        {
            if (!inventoryByPath.ContainsKey(arch.RelativePath))
            {
                inventoryByPath[arch.RelativePath] = new List<Archive>();
            }

            inventoryByPath[arch.RelativePath].Add(arch);
            inventoryById[arch.ArchiveId] = arch;
            isDirty = true;
        }
コード例 #5
0
ファイル: Vault.cs プロジェクト: benjaminc/AmazonGlacierSync
        public bool reuploadArchive(ArchiveTransferManager manager, string archiveId, string basePath)
        {
            Archive arch = inventoryById.ContainsKey(archiveId) ? inventoryById[archiveId] : null;

            if (arch != null)
            {
                arch = new Archive(arch);
                toUpload.Add(arch);
                return uploadArchive(manager, arch, basePath) == null;
            }

            return false;
        }