Ejemplo n.º 1
0
        public static UploadFilesResult UploadFiles(CloudBlobContainer container, string localDirectory, string prefix = "")
        {
            UploadFilesResult ret = new UploadFilesResult();

            localDirectory = localDirectory.Replace("\\", "/");
            foreach (var file in Directory.GetFiles(localDirectory).Select(f => f.Replace("\\", "/")))
            {
                var blobName = ConvertLocalFileToBlobName(localDirectory, file, prefix);
                var blob     = UploadFile(container, file, blobName);

                ret.Results.Add(new UploadFileResult()
                {
                    LocalFile = file, RemoteFile = blob
                });
            }

            foreach (var child in Directory.GetDirectories(localDirectory))
            {
                var    childName = Path.GetFileName(child);
                string newPrefix;

                if (prefix.Length == 0)
                {
                    newPrefix = childName + "/";
                }
                else
                {
                    newPrefix = prefix + childName + "/";
                }

                var nestedResult = UploadFiles(container, child, newPrefix);
                ret.Merge(nestedResult);
            }

            return(ret);
        }
Ejemplo n.º 2
0
 public void Merge(UploadFilesResult other)
 {
     this.Results.AddRange(other.Results);
 }
Ejemplo n.º 3
0
        public static UploadFilesResult UploadFiles(CloudBlobContainer container, string localDirectory, string prefix = "")
        {
            UploadFilesResult ret = new UploadFilesResult();
            localDirectory = localDirectory.Replace("\\", "/");
            foreach (var file in Directory.GetFiles(localDirectory).Select(f => f.Replace("\\", "/")))
            {
                var blobName = ConvertLocalFileToBlobName(localDirectory, file, prefix);
                var blob = UploadFile(container, file, blobName);

                ret.Results.Add(new UploadFileResult() { LocalFile = file, RemoteFile = blob });
            }

            foreach (var child in Directory.GetDirectories(localDirectory))
            {
                var childName = Path.GetFileName(child);
                string newPrefix;

                if (prefix.Length == 0)
                {
                    newPrefix = childName + "/";
                }
                else
                {
                    newPrefix = prefix + childName + "/";
                }

                var nestedResult = UploadFiles(container, child, newPrefix);
                ret.Merge(nestedResult);
            }

            return ret;
        }
Ejemplo n.º 4
0
 public void Merge(UploadFilesResult other)
 {
     this.Results.AddRange(other.Results);
 }