/// <summary>
        /// Parses the Cloud Storage account for a list of files to restore.
        /// </summary>
        /// <returns></returns>
        public List <RemoteItem> GetBlobItems()
        {
            Console.WriteLine("Fetching list of items in Remote Storage ...");
            var blobClient = StorageAccount.CreateCloudBlobClient();

            var container = blobClient.GetContainerReference(ContainerName);

            var blobItems = new List <RemoteItem>();

            // Loop over items within the container and fetch the blob files
            foreach (var item in container.ListBlobs(null, true))
            {
                if (item is CloudBlockBlob blockBlob)
                {
                    var blob = blockBlob;

                    if (blob.Name.Length >= 15)
                    {
                        var blobItem = new RemoteItem
                        {
                            Name         = blob.Name,
                            BackupDate   = Common.ParseDateFromFileName(blob.Name),
                            BackupType   = Common.ParseBackupTypeFromFileName(blob.Name),
                            PathOrUrl    = blob.Uri.ToString(),
                            Size         = blob.Properties.Length,
                            LastModified = blob.Properties.LastModified,
                            Type         = ItemType.Block
                        };
                        blobItems.Add(blobItem);
                    }
                }
                else
                {
                    if (!(item is CloudPageBlob pageBlob))
                    {
                        continue;
                    }
                    var blob = pageBlob;

                    if (blob.Name.Length >= 15)
                    {
                        var blobItem = new RemoteItem
                        {
                            Name         = blob.Name,
                            BackupDate   = Common.ParseDateFromFileName(blob.Name),
                            BackupType   = Common.ParseBackupTypeFromFileName(blob.Name),
                            PathOrUrl    = blob.Uri.ToString(),
                            Size         = blob.Properties.Length,
                            LastModified = blob.Properties.LastModified,
                            Type         = ItemType.Page
                        };
                        blobItems.Add(blobItem);
                    }
                }
                Console.Write("\rRetrieved {0} item(s) ...", blobItems.Count);
            }
            Console.WriteLine();
            return(blobItems);
        }
示例#2
0
        public static void SetFileCreationDate(RemoteItem file, FileSystemInfo fi)
        {
            var dt = DateTime.UtcNow;

            if (file.BackupDate == null)
            {
                if (file.LastModified != null)
                {
                    dt = file.LastModified.Value.UtcDateTime;
                }
            }
            else
            {
                dt = file.BackupDate.Value;
            }

            File.SetLastWriteTimeUtc(fi.FullName, dt);
        }
示例#3
0
        /// <summary>
        /// Parses the File Storage account for a list of files to restore.
        /// </summary>
        /// <returns></returns>
        public List <RemoteItem> GetFileItems()
        {
            Console.WriteLine("Fetching list of items in File Storage ...");

            var fileItems = new List <RemoteItem>();

            using (new NetworkConnection(m_remoteStorage, new NetworkCredential(m_remoteUsername, m_remotePassword)))
            {
                // Loop over items within the directory and fetch the files
                foreach (var item in m_common.GetFileList("*.*", m_remoteStorage))
                {
                    if (item.Name.Length >= 15)
                    {
                        var fi = new RemoteItem
                        {
                            Name         = item.Name,
                            BackupDate   = Common.ParseDateFromFileName(item.Name),
                            BackupType   = Common.ParseBackupTypeFromFileName(item.Name),
                            PathOrUrl    = item.DirectoryName,
                            FakePath     = item.FullName.Replace(m_remoteStorage, "").Replace("\\", "//"),
                            Size         = item.Length,
                            LastModified = item.LastWriteTimeUtc,
                            Type         = ItemType.File
                        };


                        if (fi.FakePath.StartsWith("//"))
                        {
                            fi.FakePath = fi.FakePath.Substring(2, fi.FakePath.Length - 2);
                        }
                        fileItems.Add(fi);
                    }

                    Console.Write($"{Environment.NewLine}Retrieved {fileItems.Count} item(s) ...");
                }
                Console.WriteLine();
            }
            return(fileItems);
        }