Пример #1
0
 public void uploadfromFilesystem(CloudBlockBlob blob, string localFilePath, string eventType)
 {
     if (eventType.Equals("create") || eventType.Equals("signUpStart"))
     {
         Program.ClientForm.addtoConsole("Upload started[create || signUpStart]:" + localFilePath);
         blob.UploadFromFile(localFilePath, FileMode.Open);
         Program.ClientForm.addtoConsole("Uploaded");
         Program.ClientForm.ballon("Uploaded:"+ localFilePath);
     }
     else
     {
         try
         {
             Program.ClientForm.addtoConsole("Upload started[change,etc]:" + localFilePath);
             string leaseId = Guid.NewGuid().ToString();
             blob.AcquireLease(TimeSpan.FromMilliseconds(16000), leaseId);
             blob.UploadFromFile(localFilePath, FileMode.Open, AccessCondition.GenerateLeaseCondition(leaseId));
             blob.ReleaseLease(AccessCondition.GenerateLeaseCondition(leaseId));
             Program.ClientForm.addtoConsole("Uploaded");
             Program.ClientForm.ballon("Uploaded:" + localFilePath);
         }
         catch (Exception ex)
         {
             Program.ClientForm.addtoConsole("Upload: second attempt");
             Thread.Sleep(5000);
             string leaseId = Guid.NewGuid().ToString();
             blob.AcquireLease(TimeSpan.FromMilliseconds(16000), leaseId);
             blob.UploadFromFile(localFilePath, FileMode.Open, AccessCondition.GenerateLeaseCondition(leaseId));
             blob.ReleaseLease(AccessCondition.GenerateLeaseCondition(leaseId));
             Program.ClientForm.addtoConsole("Uploaded");
             Program.ClientForm.ballon("Uploaded:" + localFilePath);
         }
     }
 }
Пример #2
0
        /// <summary>
        /// Process sample Files for generating test data
        /// </summary>
        /// <param name="path"></param>
        /// <param name="outputStorageAccount"></param>
        /// <param name="folderPath"></param>
        /// <param name="outputTableName"></param>
        /// <param name="logger"></param>
        public static void ProcessFiles(string path, CloudStorageAccount outputStorageAccount, string folderPath, string outputTableName, IActivityLogger logger)
        {
            string[] files = Directory.GetFiles(path);

            foreach (var file in files)
            {
                if (file.Contains(@"artist_data.txt") && outputTableName.ToLower().Contains(@"catalog"))
                {
                    Uri outputBlobUri = new Uri(outputStorageAccount.BlobEndpoint, folderPath + "artist_data.txt");
                    CloudBlockBlob outputBlob = new CloudBlockBlob(outputBlobUri, outputStorageAccount.Credentials);
                    if (outputBlob.Exists())
                    {
                        outputBlob.Delete();
                    }
                    outputBlob.UploadFromFile(path + "/artist_data.txt", FileMode.Open);
                }
                if (file.Contains(@"customers.txt") && outputTableName.ToLower().Contains(@"customers"))
                {
                    Uri outputBlobUri = new Uri(outputStorageAccount.BlobEndpoint, folderPath + "customers.txt");
                    CloudBlockBlob outputBlob = new CloudBlockBlob(outputBlobUri, outputStorageAccount.Credentials);
                    if (outputBlob.Exists())
                    {
                        outputBlob.Delete();
                    }
                    outputBlob.UploadFromFile(path + "/customers.txt", FileMode.Open);
                }
                else if (file.Contains(@"artist_customer_data.txt") && outputTableName.ToLower().Contains(@"rawproducts"))
                {
                    Uri outputBlobUri = new Uri(outputStorageAccount.BlobEndpoint, folderPath + "artist_customer_data.txt");
                    CloudBlockBlob outputBlob = new CloudBlockBlob(outputBlobUri, outputStorageAccount.Credentials);
                    List<string> lines = File.ReadAllLines(path + "/artist_customer_data.txt").ToList();
                    int index = 0;

                    if (outputBlob.Exists() && index == 0)
                    {
                        outputBlob.Delete();
                    }

                    //add new column value for each row.
                    lines.Skip(0).ToList().ForEach(line =>
                    {
                        if (index >= 0 & index <= 1000)
                        {
                            lines[index] += "," + DateTime.UtcNow.AddMonths(-1).ToString("yyyy-MM-dd");
                            UploadBlobStream(outputBlob, lines[index]);
                            index++;
                        }
                        else if (index >= 1001 & index <= 2000)
                        {
                            lines[index] += "," + DateTime.UtcNow.AddMonths(-2).ToString("yyyy-MM-dd");
                            UploadBlobStream(outputBlob, lines[index]);
                            index++;
                        }
                        else if (index >= 2001 & index <= 3000)
                        {
                            lines[index] += "," + DateTime.UtcNow.AddMonths(-3).ToString("yyyy-MM-dd");
                            UploadBlobStream(outputBlob, lines[index]);
                            index++;
                        }
                        else if (index >= 3001 & index <= 4000)
                        {
                            lines[index] += "," + DateTime.UtcNow.AddMonths(-4).ToString("yyyy-MM-dd");
                            UploadBlobStream(outputBlob, lines[index]);
                            index++;
                        }
                        else if (index >= 4001 & index <= 5000)
                        {
                            lines[index] += "," + DateTime.UtcNow.AddMonths(-5).ToString("yyyy-MM-dd");
                            UploadBlobStream(outputBlob, lines[index]);
                            index++;
                        }
                        else if (index >= 5001 & index <= 6000)
                        {
                            lines[index] += "," + DateTime.UtcNow.AddMonths(-6).ToString("yyyy-MM-dd");
                            UploadBlobStream(outputBlob, lines[index]);
                            index++;
                        }
                        else if (index >= 6001 & index <= 7000)
                        {
                            lines[index] += "," + DateTime.UtcNow.AddMonths(-7).ToString("yyyy-MM-dd");
                            UploadBlobStream(outputBlob, lines[index]);
                            index++;
                        }
                        else if (index >= 7001 & index <= 8000)
                        {
                            lines[index] += "," + DateTime.UtcNow.AddMonths(-8).ToString("yyyy-MM-dd");
                            UploadBlobStream(outputBlob, lines[index]);
                            index++;
                        }
                        else if (index >= 8001 & index <= 9000)
                        {
                            lines[index] += "," + DateTime.UtcNow.AddMonths(-9).ToString("yyyy-MM-dd");
                            UploadBlobStream(outputBlob, lines[index]);
                            index++;
                        }
                        else if (index >= 9001 & index <= 10000)
                        {
                            lines[index] += "," + DateTime.UtcNow.AddMonths(-10).ToString("yyyy-MM-dd");
                            UploadBlobStream(outputBlob, lines[index]);
                            index++;
                        }
                        else if (index >= 10001 & index <= 11000)
                        {
                            lines[index] += "," + DateTime.UtcNow.AddMonths(-11).ToString("yyyy-MM-dd");
                            UploadBlobStream(outputBlob, lines[index]);
                            index++;
                        }
                        else if (index >= 11001 & index <= 12000)
                        {
                            lines[index] += "," + DateTime.UtcNow.AddMonths(-12).ToString("yyyy-MM-dd");
                            UploadBlobStream(outputBlob, lines[index]);
                            index++;
                        }
                        Console.WriteLine("Writing blob number: {0}", index);
                        logger.Write(TraceEventType.Information, "Writing blob number: {0}", index);
                    });
                }
            }
        }
        private void UploadFileToApplicationPackage(
            string resourceGroupName,
            string accountName,
            string applicationId,
            string version,
            string filePath,
            string storageUrl,
            bool appPackageAlreadyExists)
        {
            try
            {
                CloudBlockBlob blob = new CloudBlockBlob(new Uri(storageUrl));
                blob.UploadFromFile(filePath, FileMode.Open);
            }
            catch (Exception exception)
            {
                // If the application package has already been created we don't want to delete the application package mysteriously.
                if (appPackageAlreadyExists)
                {
                    // If we are creating a new application package and the upload fails we should delete the application package.
                    try
                    {
                        DeleteApplicationPackage(resourceGroupName, accountName, applicationId, version);
                    }
                    catch
                    {
                        // Need to throw if we fail to delete the application while attempting to clean it up.
                        var deleteMessage = string.Format(Resources.FailedToUploadAndDelete, filePath, exception.Message);
                        throw new NewApplicationPackageException(deleteMessage, exception);
                    }
                }

                // Need to throw if we fail to upload the file's content.
                var uploadMessage = string.Format(Resources.FailedToUpload, filePath, exception.Message);
                throw new NewApplicationPackageException(uploadMessage, exception);
            }
        }
Пример #4
0
        private static void UploadBlob(string packageFileName, string packageUrl, string storageAccountName, string storageAccountKey)
        {
            OurTrace.TraceInfo(string.Format("Uploading blob from {0} to {1}", packageFileName, packageUrl));

            var packageUri = new Uri(packageUrl);
            var credentials = new StorageCredentials(storageAccountName, storageAccountKey);
            var blobRef = new CloudBlockBlob(packageUri, credentials);

            blobRef.ServiceClient.DefaultRequestOptions.ServerTimeout = TimeSpan.FromMinutes(15);
            blobRef.ServiceClient.DefaultRequestOptions.MaximumExecutionTime = blobRef.ServiceClient.DefaultRequestOptions.ServerTimeout;
            blobRef.Container.CreateIfNotExists();

            blobRef.UploadFromFile(packageFileName, FileMode.Open);
        }
Пример #5
0
        public static void TaskMain(string[] args)
        {
            if (args == null || args.Length != 4)
            {
                throw new Exception("Usage: ImageBlur.exe --Task <blobpath> <storageAccountName> <storageAccountKey>");
            }

            string blobName = args[1];
            string storageAccountName = args[2];
            string storageAccountKey = args[3];
            string workingDirectory = Environment.GetEnvironmentVariable("AZ_BATCH_TASK_WORKING_DIR");
            int numberToBlur = 3;

            Console.WriteLine();
            Console.WriteLine("    blobName: <{0}>", blobName);
            Console.WriteLine("    storageAccountName: <{0}>", storageAccountName);
            Console.WriteLine("    number to blur: <{0}>", numberToBlur);
            Console.WriteLine();

            // get source image from cloud blob
            var storageCred = new StorageCredentials(storageAccountName, storageAccountKey);
            CloudBlockBlob blob = new CloudBlockBlob(new Uri(blobName), storageCred);

            using (MemoryStream inStream = new MemoryStream())
            {
                blob.DownloadToStream(inStream);
                Image img = Image.FromStream(inStream);
                int imgWidth = img.Width;
                int imgHeight = img.Height;
                Size size = new Size(imgWidth, imgHeight);
                ISupportedImageFormat format = new JpegFormat { Quality = 70 };

                // Print image properties to stdout
                Console.WriteLine("    Image Properties:");
                Console.WriteLine("        Format: {0}", FormatUtilities.GetFormat(inStream));
                Console.WriteLine("        Size: {0}", size.ToString());
                Console.WriteLine();

                for (var i = 0; i < numberToBlur; i++)
                {
                    using (ImageFactory imageFactory = new ImageFactory(preserveExifData: true))
                    {
                        int blurIndex = (i * 5) + 10;
                        imageFactory.Load(inStream);
                        imageFactory.Resize(size)
                                    .Format(format)
                                    .GaussianBlur(blurIndex)
                                    .Save(workingDirectory + "/resultimage" + i + ".Jpeg");
                                    //.Save(@"C:/Users/jiata/Desktop/imageblur/results/resultimage" + i + ".Jpeg");
                    }
                }
            }

            // TODO - not working
            for (var i = 0; i < numberToBlur; i++)
            {
                blob.UploadFromFile(workingDirectory + "/resultimage" + i + ".Jpeg", FileMode.Open);
            }

            Environment.Exit(1);
        }
        /// <summary>
        /// Uploads an application package to Storage
        /// </summary>
        public static AddApplicationPackageResult CreateApplicationPackage(BatchController controller, BatchAccountContext context, string applicationId, string version, string filePath)
        {
            AddApplicationPackageResult applicationPackage = null;

            if (HttpMockServer.Mode == HttpRecorderMode.Record)
            {
                applicationPackage = controller.BatchManagementClient.Application.AddApplicationPackage(
                    context.ResourceGroupName,
                    context.AccountName,
                    applicationId,
                    version);

                CloudBlockBlob blob = new CloudBlockBlob(new Uri(applicationPackage.StorageUrl));
                blob.UploadFromFile(filePath, FileMode.Open);
            }

            return applicationPackage;
        }