1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
|
class Program
{
static string urllogazure = "https://xxx.blob.core.windows.net/test?svxxxxxx";
static string urlloglocal = "http://127.0.0.1:10001";
static bool updateto(bool local,string filename, string content, string test = null)
{
bool ret = false;
// if (CloudStorageAccount.TryParse(roots, out CloudStorageAccount storageAccount))
{
// CloudBlobClient BlobClient = storageAccount.CreateCloudBlobClient();
//CloudBlobContainer container = BlobClient.GetContainerReference("update");
CloudBlobContainer container = new CloudBlobContainer(new Uri(local ? urlloglocal : urllogazure));
if (true)
{
CloudBlockBlob file = container.GetBlockBlobReference(filename);
MemoryStream str = new MemoryStream();
StreamWriter ws = new StreamWriter(str);
ws.Write(content);
ws.Flush();
str.Position = 0;
file.UploadFromStream(str);
if (test != null)
{
str.Position = 0;
ws.Write(test);
ws.Flush();
str.Position = 0;
file.UploadFromStream(str);
}
str.Close();
}
else
{
contenterror("Container does not exist");
}
}
return ret;
}
static string download(bool local,string filename)
{
string retr = null;
MemoryStream ms = new MemoryStream();
// if (CloudStorageAccount.TryParse(roots, out CloudStorageAccount storageAccount))
{
// CloudBlobClient BlobClient = storageAccount.CreateCloudBlobClient();
// CloudBlobContainer container = BlobClient.GetContainerReference("update");
CloudBlobContainer container = new CloudBlobContainer(new Uri(local?urlloglocal:urllogazure));
if (true)
{
CloudBlob file = container.GetBlobReference(filename);
if (file.Exists())
{
file.DownloadToStream(ms);
Stream blobStream = file.OpenRead();
//string st = blobStream.ToString();
blobStream.Position = 0;
StreamReader reader = new StreamReader(blobStream);
retr = reader.ReadToEnd();
}
else
{
contenterror("File does not exist");
}
}
else
{
contenterror("Container does not exist");
}
}
//else
//{
// contenterror("Error opening storage");
//}
return retr;
}
static void Main(string[] args)
{
//update("adpackm", "Ca marche sas adpackm");
//string st = download("adpackm");
string namebloc = "test1/test1/README.TXT";
//updateappend(namebloc, "c'est bon\r\n","bien ajout\r\n");
//var st = download(false,namebloc);
//updateto(namebloc, "c'est bon\r\n", "bien ajout\r\n");
var st = download(false,namebloc);
Console.WriteLine(st);
updateto(false,"test1/test1(copy)/zz.txt", "xxxx\nyyyy");
copym(false, "test1/test1", "test1/test1(copy)/");
}
private static void copym(bool local, string dirsrc, string dirdst)
{
CloudBlobContainer container = new CloudBlobContainer(new Uri(local ? urlloglocal : urllogazure));
CloudBlobDirectory src=container.GetDirectoryReference(dirsrc);
CloudBlobDirectory dst = container.GetDirectoryReference(dirdst);
//dst.Container.Create();
// Create CancellationTokenSource used to cancel the transfer
DirectoryTransferContext context = new DirectoryTransferContext();
context.FileTransferred += FileTransferredCallback;
context.FileFailed += FileFailedCallback;
context.FileSkipped += FileSkippedCallback;
CancellationTokenSource cancellationSource = new CancellationTokenSource();
CopyDirectoryOptions options = new CopyDirectoryOptions()
{
SearchPattern = "*",
Recursive = true,
BlobType = BlobType.BlockBlob
};
//CopyMethod cm = new CopyMethod();
//public static Task<TransferStatus> CopyDirectoryAsync(CloudFileDirectory sourceFileDir, CloudBlobDirectory destBlobDir, CopyMethod copyMethod, CopyDirectoryOptions options, DirectoryTransferContext context);
//var cc = TransferManager.CopyDirectoryAsync(src, dst, CopyMethod.ServiceSideAsyncCopy, options, context, cancellationSource.Token);
var cc = TransferManager.CopyDirectoryAsync(src, dst, false, options, null);
Thread.Sleep(10000);
//var cc = TransferManager.CopyDirectoryAsync(src, dst, true, options, context, cancellationSource.Token);
cc.Wait();
cc = cc;
} |
Partager