Facebook
From Gracious Tapir, 6 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 267
  1. using Microsoft.WindowsAzure.Storage;
  2. using Microsoft.WindowsAzure.Storage.Blob;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Drawing;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10.  
  11. namespace ConsoleApplication5
  12. {
  13.     class Program
  14.     {
  15.         static string CreateImage(byte r, byte g, byte b)
  16.         {
  17.             Bitmap bmp = new Bitmap(10, 10);
  18.             for (int i = 0; i < 10; i++)
  19.             {
  20.                 for (int j = 0; j < 10; j++)
  21.                 {
  22.                     bmp.SetPixel(i, j, Color.FromArgb(r, g, b));
  23.                 }
  24.             }
  25.             string path = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName() + ".png");
  26.             bmp.Save(path);
  27.             return path;
  28.         }
  29.  
  30.         static IEnumerable<string> CreateImages(int count)
  31.         {
  32.             return Enumerable.Range(0, count).Select(n => CreateImage((byte)((double)n / count * 255), 0, 0));
  33.         }
  34.  
  35.         static void Copy()
  36.         {
  37.             var src = new CloudBlobContainer(new Uri(@"https://dnyczstorage.blob.core.windows.net/zdjecia?sv=2017-04-17&ss=b&srt=sco&sp=rwdlac&se=2018-01-15T22:00:34Z&st=2018-01-13T14:00:34Z&spr=https&sig=LmSs8HO3VyOxejkAXL2E8nx8sfYgiMbLCQ4dhhOY1SU%3D"));
  38.             var dst = new CloudBlobContainer(new Uri(@"https://myfuckingstorage.blob.core.windows.net/copy?sv=2017-04-17&ss=bfqt&srt=sco&sp=rwdlacup&se=2018-01-14T21:43:10Z&st=2018-01-13T10:43:10Z&spr=https&sig=l8fHWJT10CySa%2Fqzbz%2B4AFcgW%2FURAlhuNeQJ%2BIvzfWg%3D"));
  39.  
  40.             foreach (var i in src.ListBlobs())
  41.             {
  42.                 var bbr = dst.GetBlockBlobReference(Path.GetFileName(i.Uri.ToString()));
  43.                 bbr.StartCopy(i.Uri);
  44.                 Console.WriteLine(i.Uri);
  45.             }
  46.         }
  47.  
  48.         private static void Upload()
  49.         {
  50.             var csa = CloudStorageAccount.Parse(@"DefaultEndpointsProtocol=https;AccountName=myfuckingstorage;AccountKey=uNmgCLfBpfriY3JRnk8P4krQuV1Tp27JdPmou4cUIHLArKf9k7ON8lYfCQHihqJDKrm78GfSTwL+bqEFgQmlGw==;EndpointSuffix=core.windows.net");
  51.             var ccbc = csa.CreateCloudBlobClient();
  52.             var zdjecia = ccbc.GetContainerReference("zdjecia");
  53.  
  54.             var images = CreateImages(5);
  55.             foreach (var image in images)
  56.             {
  57.                 var b = zdjecia.GetBlockBlobReference(Path.GetFileName(image));
  58.                 b.UploadFromFile(image);
  59.                 Console.WriteLine(image);
  60.             }
  61.         }
  62.  
  63.         static void Main(string[] args)
  64.         {
  65.             Copy();
  66.             //Upload();
  67.         }
  68.     }
  69. }
  70.