コード例 #1
0
        private static void DoMake()
        {
            IBlobHandler handler       = GetHandler(_inputUrlType, _inputUrl);
            var          containerName = handler.GetContainerNameFromUrl(_inputUrl);

            handler.MakeContainer(containerName);
        }
コード例 #2
0
        /// <summary>
        /// Get all possible blobs for the handler (which had the original url passed into the constructor).
        /// </summary>
        /// <param name="inputHandler"></param>
        /// <param name="url"></param>
        /// <returns></returns>
        private static IEnumerable <BasicBlobContainer> GetSourceBlobList(IBlobHandler inputHandler)
        {
            var containerName = inputHandler.GetContainerNameFromUrl(inputHandler.GetBaseUrl());

            if (CommonHelper.IsABlob(inputHandler.GetBaseUrl()))
            {
                var blobName = inputHandler.GetBlobNameFromUrl(inputHandler.GetBaseUrl());
                var blob     = new BasicBlobContainer {
                    Name        = blobName,
                    DisplayName = blobName,
                    BlobType    = BlobEntryType.Blob,
                    Url         = inputHandler.GetBaseUrl(),
                    Container   = containerName
                };

                yield return(blob);
                //blobList.Add(blob);
            }
            else
            {
                var res = inputHandler.ListBlobsInContainer(containerName);
                foreach (var i in res)
                {
                    yield return(i);
                }
            }
        }
コード例 #3
0
        static void DoList(bool debugMode)
        {
            IBlobHandler handler = GetHandler(_inputUrlType, _inputUrl);

            var containerName = handler.GetContainerNameFromUrl(_inputUrl);

            if (DebugMode)
            {
                Console.WriteLine("container name " + containerName);
            }

            var blobPrefix = handler.GetBlobNameFromUrl(_inputUrl);
            var blobList   = handler.ListBlobsInContainer(containerName, blobPrefix, DebugMode);

            foreach (var blob in blobList)
            {
                Console.WriteLine(string.Format("{0}  ({1} {2})", blob.DisplayName, blob.Name, blob.Url));
            }
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: kpfaulkner/azurecopy
        /// <summary>
        /// Get all possible blobs for the handler (which had the original url passed into the constructor).
        /// </summary>
        /// <param name="inputHandler"></param>
        /// <param name="url"></param>
        /// <returns></returns>
        private static IEnumerable<BasicBlobContainer> GetSourceBlobList(IBlobHandler inputHandler)
        {
            var containerName = inputHandler.GetContainerNameFromUrl(inputHandler.GetBaseUrl());

            if (CommonHelper.IsABlob(inputHandler.GetBaseUrl()))
            {
                var blobName = inputHandler.GetBlobNameFromUrl( inputHandler.GetBaseUrl());
                var blob = new BasicBlobContainer{
                    Name = blobName,
                    DisplayName = blobName,
                    BlobType = BlobEntryType.Blob,
                    Url = inputHandler.GetBaseUrl(),
                    Container = containerName
                };

                yield return blob;
                //blobList.Add(blob);
            }
            else
            {
                var res = inputHandler.ListBlobsInContainer(containerName);
                foreach( var i in res)
                {
                    yield return i;
                }
            }
        }
コード例 #5
0
        static void DoNormalCopy()
        {
            IBlobHandler inputHandler  = GetHandler(_inputUrlType, _inputUrl);
            IBlobHandler outputHandler = GetHandler(_outputUrlType, _outputUrl);

            if (inputHandler != null && outputHandler != null)
            {
                // handle multiple files.
                //currently sequentially.
                var sourceBlobList = GetSourceBlobList(inputHandler);

                if (ConfigHelper.UseBlobCopy)
                {
                    AzureBlobCopyHandler.StartCopyList(sourceBlobList, _outputUrl, _destinationBlobType);
                }
                else
                {
                    foreach (var blob in sourceBlobList)
                    {
                        var fileName = "";
                        if (ConfigHelper.AmDownloading)
                        {
                            fileName = GenerateFileName(ConfigHelper.DownloadDirectory, blob.Name);
                        }

                        var sourceContainer = inputHandler.GetContainerNameFromUrl(_inputUrl);

                        // read blob
                        var inputBlob = inputHandler.ReadBlob(sourceContainer, blob.Name, fileName);

                        // if blob is marked with type "Unknown" then set it to what was passed in on command line.
                        // if nothing was passed in, then default to block?
                        if (inputBlob.BlobType == DestinationBlobType.Unknown)
                        {
                            if (_destinationBlobType != DestinationBlobType.Unknown)
                            {
                                inputBlob.BlobType = _destinationBlobType;
                            }
                            else
                            {
                                inputBlob.BlobType = DestinationBlobType.Block;
                            }
                        }

                        Console.WriteLine(string.Format("Copying blob to {0}", _outputUrl));

                        // write blob
                        var destContainerName = outputHandler.GetContainerNameFromUrl(_outputUrl);
                        var destBlobName      = outputHandler.GetBlobNameFromUrl(_outputUrl);

                        // take the inputBlob name and remove the default prefix.

                        if (!string.IsNullOrEmpty(blob.BlobPrefix))
                        {
                            destBlobName += inputBlob.Name.Substring(blob.BlobPrefix.Length);
                        }
                        else
                        {
                            // if destBlobName ends with / then its a prefix.
                            // if it does not, then its an absolute blob name (ie when the blob was copied then it was also being renamed).
                            if (destBlobName.EndsWith("/"))
                            {
                                destBlobName += inputBlob.Name;
                            }
                            else
                            {
                                // if destBlobName is empty then take it from blob.
                                // else it appears we were told the name to use so leave it.
                                if (string.IsNullOrWhiteSpace(destBlobName))
                                {
                                    destBlobName = inputBlob.Name;
                                }
                                else
                                {
                                    // leave it.
                                }
                            }
                        }

                        outputHandler.WriteBlob(destContainerName, destBlobName, inputBlob, ConfigHelper.ParallelFactor, ConfigHelper.ChunkSizeInMB);

                        if (inputBlob.BlobSavedToFile)
                        {
                            if (File.Exists(inputBlob.FilePath))
                            {
                                File.Delete(inputBlob.FilePath);
                            }
                        }
                    }
                }
            }
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: tusharkhanka/azurecopy
        static void DoNormalCopy(bool debugMode)
        {
            IBlobHandler inputHandler  = GetHandler(_inputUrlType, _inputUrl);
            IBlobHandler outputHandler = GetHandler(_outputUrlType, _outputUrl);

            // can only use skip when destination is Azure (simply because I haven't coded other options yet).
            if (!(_outputUrlType == UrlType.Azure || _outputUrlType == UrlType.Dropbox) && skip)
            {
                Console.WriteLine("-skip option only valid when destination is Azure blob storage or Dropbox. This will change soon.");
                return;
            }

            if (inputHandler != null && outputHandler != null)
            {
                // handle multiple files.
                //currently sequentially.
                var sourceBlobList = GetSourceBlobList(inputHandler);

                if (ConfigHelper.UseBlobCopy)
                {
                    AzureBlobCopyHandler.StartCopyList(sourceBlobList, _outputUrl, _destinationBlobType, debugMode, skip);
                }
                else
                {
                    foreach (var blob in sourceBlobList)
                    {
                        var fileName = "";
                        if (ConfigHelper.AmDownloading)
                        {
                            fileName = GenerateFileName(ConfigHelper.DownloadDirectory, blob.Name);
                        }

                        var sourceContainer = inputHandler.GetContainerNameFromUrl(_inputUrl);


                        // write blob
                        var destContainerName = outputHandler.GetContainerNameFromUrl(_outputUrl);
                        var destBlobName      = outputHandler.GetBlobNameFromUrl(_outputUrl);

                        // take the inputBlob name and remove the default prefix.

                        if (!string.IsNullOrEmpty(blob.BlobPrefix))
                        {
                            destBlobName += blob.Name.Substring(blob.BlobPrefix.Length);
                        }
                        else
                        {
                            // if destBlobName ends with / then its a prefix.
                            // if it does not, then its an absolute blob name (ie when the blob was copied then it was also being renamed).
                            if (destBlobName.EndsWith("/"))
                            {
                                destBlobName += blob.Name;
                            }
                            else
                            {
                                // if destBlobName is empty then take it from blob.
                                // else it appears we were told the name to use so leave it.
                                if (string.IsNullOrWhiteSpace(destBlobName))
                                {
                                    destBlobName = blob.Name;
                                }
                                else
                                {
                                    // leave it.
                                }
                            }
                        }

                        if (skip)
                        {
                            // check if destination blob exists.
                            // if it does, then dont even bother reading the blob and just continue to the next one.

                            var alreadyExists = outputHandler.DoesBlobExists(destContainerName, destBlobName);
                            if (alreadyExists)
                            {
                                Console.WriteLine("Skipping " + blob.Url);
                                continue;
                            }
                        }

                        Console.WriteLine(string.Format("Copying blob to {0}", _outputUrl));

                        // read blob
                        var inputBlob = inputHandler.ReadBlob(sourceContainer, blob.Name, fileName);
                        // if blob is marked with type "Unknown" then set it to what was passed in on command line.
                        // if nothing was passed in, then default to block?
                        if (inputBlob.BlobType == DestinationBlobType.Unknown)
                        {
                            if (_destinationBlobType != DestinationBlobType.Unknown)
                            {
                                inputBlob.BlobType = _destinationBlobType;
                            }
                            else
                            {
                                inputBlob.BlobType = DestinationBlobType.Block;
                            }
                        }

                        outputHandler.WriteBlob(destContainerName, destBlobName, inputBlob, ConfigHelper.ParallelFactor, ConfigHelper.ChunkSizeInMB);

                        if (inputBlob.BlobSavedToFile)
                        {
                            if (File.Exists(inputBlob.FilePath))
                            {
                                File.Delete(inputBlob.FilePath);
                            }
                        }
                    }
                }
            }
        }