Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Microsoft.WindowsAzure.Storage;
- using Microsoft.WindowsAzure.Storage.Blob;
- using Microsoft.WindowsAzure.Storage.Table;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using WCFServiceWebRole1;
- namespace Klient
- {
- class Program
- {
- static void Main(string[] args)
- {
- Dictionary<String, UsersEntity> blobs = new Dictionary<String, UsersEntity>();
- var account = CloudStorageAccount.DevelopmentStorageAccount;
- CloudTableClient cl = account.CreateCloudTableClient();
- var table = cl.GetTableReference("userzy");
- table.CreateIfNotExists();
- bool endFlag = false;
- CloudBlobClient client = account.CreateCloudBlobClient();
- while (!endFlag)
- {
- Console.WriteLine();
- Console.WriteLine("Wybierz opcję:");
- Console.WriteLine("1. Dodaj usera.");
- Console.WriteLine("2. Przesyłanie blobów.");
- Console.WriteLine("3. Odczytanie bloba.");
- Console.WriteLine("4. Lista wszystkich blobów.");
- Console.WriteLine("ESC. Wyjście.");
- Console.WriteLine();
- ConsoleKey option= Console.ReadKey().Key;
- Console.Clear();
- switch (option)
- {
- case ConsoleKey.D1:
- Console.WriteLine();
- Console.WriteLine("Login:");
- String username = "";
- while (username == "")
- {
- username = Console.ReadLine();
- }
- Console.WriteLine("Haslo:");
- String password = "";
- while (password == "")
- {
- password = Console.ReadLine();
- }
- var e = new UsersEntity(username, password);
- TableOperation testOperation = TableOperation.Retrieve<UsersEntity>(username, password);
- var res = table.Execute(testOperation);
- UsersEntity test = (UsersEntity)res.Result;
- if (test == null)
- {
- TableOperation insertOperation = TableOperation.Insert(e);
- table.Execute(insertOperation);
- Console.WriteLine("Dodano usera: " + username);
- }
- else
- {
- Console.WriteLine("Uzytkownik: " + username + " istnieje juz w bazie");
- }
- break;
- case ConsoleKey.D2:
- Console.WriteLine("Nazwa usera: ");
- String username2 = Console.ReadLine();
- Console.WriteLine("Haslo: ");
- String password2 = Console.ReadLine();
- Console.WriteLine("Nazwa bloba: ");
- String blobName = Console.ReadLine();
- Console.WriteLine("Content: ");
- String content = Console.ReadLine();
- TableOperation testOperation2 = TableOperation.Retrieve<UsersEntity>(username2, password2);
- var res2 = table.Execute(testOperation2);
- UsersEntity test2 = (UsersEntity)res2.Result;
- if (test2 == null)
- {
- Console.WriteLine("Przesylanie nie powiodlo sie, poniewaz podany user " + username2 + " nie istnieje");
- }
- else
- {
- CloudBlobContainer container = client.GetContainerReference(username2 + password2);
- container.CreateIfNotExists();
- var blob = container.GetBlockBlobReference(blobName);
- var bytes = new System.Text.ASCIIEncoding().GetBytes(content);
- var s = new System.IO.MemoryStream(bytes);
- blob.UploadFromStream(s);
- }
- break;
- case ConsoleKey.D3:
- Console.WriteLine("Nazwa usera: ");
- String username3 = Console.ReadLine();
- Console.WriteLine("Haslo: ");
- String password3 = Console.ReadLine();
- Console.WriteLine("Nazwa bloba: ");
- String blobName3 = Console.ReadLine();
- TableOperation testOperation3 = TableOperation.Retrieve<UsersEntity>(username3, password3);
- var res3 = table.Execute(testOperation3);
- UsersEntity test3 = (UsersEntity)res3.Result;
- if (test3 == null)
- {
- Console.WriteLine("Przesylanie nie powiodlo sie, poniewaz podany user " + username3 + " nie istnieje");
- }
- else
- {
- CloudBlobContainer container = client.GetContainerReference(username3 + password3);
- var blob = container.GetBlockBlobReference(blobName3);
- var s2 = new System.IO.MemoryStream();
- blob.DownloadToStream(s2);
- string content3 = System.Text.Encoding.UTF8.GetString(s2.ToArray());
- Console.WriteLine("Zawartosc bloba: " + content3);
- }
- break;
- case ConsoleKey.D4:
- Console.WriteLine("Lista wszystkich blobow:");
- Console.WriteLine("Nazwa usera: ");
- String username4 = Console.ReadLine();
- Console.WriteLine("Haslo: ");
- String password4 = Console.ReadLine();
- CloudBlobContainer container4 = client.GetContainerReference(username4 + password4);
- string lst4 = "";
- foreach (IListBlobItem item in container4.ListBlobs(null, false))
- {
- if (item.GetType() == typeof(CloudBlockBlob))
- {
- CloudBlockBlob blob = (CloudBlockBlob)item;
- lst4 += String.Format("Block blob of length {0}: {1}",
- blob.Properties.Length, blob.Uri) + "\n";
- }
- else if (item.GetType() == typeof(CloudPageBlob))
- {
- CloudPageBlob pageBlob = (CloudPageBlob)item;
- lst4 += String.Format("Page blob of length {0}: {1}",
- pageBlob.Properties.Length, pageBlob.Uri) + "\n";
- }
- else if (item.GetType() == typeof(CloudBlobDirectory))
- {
- CloudBlobDirectory directory = (CloudBlobDirectory)item;
- lst4 += String.Format("Directory: {0}", directory.Uri) + "\n";
- }
- }
- Console.Write(lst4);
- break;
- case ConsoleKey.Escape:
- endFlag = true;
- break;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement