Exemplo n.º 1
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);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        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);
                            }
                        }
                    }
                }
            }
        }