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.Runtime.Serialization;
- using System.ServiceModel;
- using System.ServiceModel.Web;
- using System.Text;
- namespace WCFServiceWebRole1
- {
- // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
- // NOTE: In order to launch WCF Test Client for testing this service, please select Service1.svc or Service1.svc.cs at the Solution Explorer and start debugging.
- public class Service1 : IService1
- {
- public bool SprawdzOsobe(string login, string haslo)
- {
- var account = CloudStorageAccount.DevelopmentStorageAccount;
- CloudTableClient cl = account.CreateCloudTableClient();
- var table = cl.GetTableReference("kuku");
- table.CreateIfNotExists(); // utworzenie tabeli jeżeli nie istnieje
- TableOperation op = TableOperation.Retrieve<Osoba>(login, login);
- var res = table.Execute(op);
- Osoba e = (Osoba)res.Result;
- return e.haslo == haslo;
- }
- public void DodajOsobe(string login, string haslo)
- {
- var account = CloudStorageAccount.DevelopmentStorageAccount;
- CloudTableClient cl = account.CreateCloudTableClient();
- var table = cl.GetTableReference("kuku");
- table.CreateIfNotExists(); // utworzenie tabeli jeżeli nie istnieje
- var e = new Osoba(login, haslo);
- TableOperation op = TableOperation.Insert(e);
- table.Execute(op);
- }
- public void DodajPlik(string login, string haslo, string nazwa, string zawartosc)
- {
- var account = CloudStorageAccount.DevelopmentStorageAccount;
- CloudBlobClient client = account.CreateCloudBlobClient();
- CloudBlobContainer container = client.GetContainerReference(login);
- container.CreateIfNotExists();
- // pobranie referencji do blokowego BLOBa
- var blob = container.GetBlockBlobReference(nazwa);
- // null gdy nie istnieje
- // zapisanie strumienia do BLOBa
- var bytes = new System.Text.ASCIIEncoding().GetBytes(zawartosc);
- var s = new System.IO.MemoryStream(bytes);
- blob.UploadFromStream(s);
- }
- public string PobierzPlik(string login, string haslo, string nazwa)
- {
- var account = CloudStorageAccount.DevelopmentStorageAccount;
- CloudBlobClient client = account.CreateCloudBlobClient();
- CloudBlobContainer container = client.GetContainerReference(login);
- container.CreateIfNotExists();
- // pobranie referencji do blokowego BLOBa
- var blob = container.GetBlockBlobReference(nazwa);
- var s2 = new System.IO.MemoryStream();
- blob.DownloadToStream(s2);
- string content = System.Text.Encoding.UTF8.GetString(s2.ToArray());
- return content;
- }
- public string ListaPlikow(string login, string haslo)
- {
- var account = CloudStorageAccount.DevelopmentStorageAccount;
- CloudBlobClient client = account.CreateCloudBlobClient();
- CloudBlobContainer container = client.GetContainerReference(login);
- container.CreateIfNotExists();
- string lst = "";
- foreach (IListBlobItem item in container.ListBlobs(null, false))
- {
- // string nazwa = item.
- if (item.GetType() == typeof(CloudBlockBlob))
- {
- CloudBlockBlob blob = (CloudBlockBlob)item;
- lst += blob.Name + "\n";
- // lst += String.Format("Block blob of length {0}: {1}",
- // blob.Properties.Length, blob.Uri) + "\n";
- }
- else if (item.GetType() == typeof(CloudPageBlob))
- {
- CloudPageBlob pageBlob = (CloudPageBlob)item;
- lst += String.Format("Page blob of length {0}: {1}",
- pageBlob.Properties.Length, pageBlob.Uri) + "\n";
- }
- else if (item.GetType() == typeof(CloudBlobDirectory))
- {
- CloudBlobDirectory directory = (CloudBlobDirectory)item;
- lst += String.Format("Directory: {0}", directory.Uri) + "\n";
- }
- }
- return lst;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement