Advertisement
Guest User

Untitled

a guest
May 27th, 2019
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.64 KB | None | 0 0
  1. using Microsoft.WindowsAzure.Storage;
  2. using Microsoft.WindowsAzure.Storage.Blob;
  3. using Microsoft.WindowsAzure.Storage.Table;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Runtime.Serialization;
  8. using System.ServiceModel;
  9. using System.ServiceModel.Web;
  10. using System.Text;
  11.  
  12. namespace WCFServiceWebRole1
  13. {
  14. // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
  15. // 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.
  16. public class Service1 : IService1
  17. {
  18. public bool SprawdzOsobe(string login, string haslo)
  19. {
  20. var account = CloudStorageAccount.DevelopmentStorageAccount;
  21. CloudTableClient cl = account.CreateCloudTableClient();
  22. var table = cl.GetTableReference("kuku");
  23. table.CreateIfNotExists(); // utworzenie tabeli jeżeli nie istnieje
  24. TableOperation op = TableOperation.Retrieve<Osoba>(login, login);
  25. var res = table.Execute(op);
  26. Osoba e = (Osoba)res.Result;
  27. return e.haslo == haslo;
  28. }
  29.  
  30. public void DodajOsobe(string login, string haslo)
  31. {
  32. var account = CloudStorageAccount.DevelopmentStorageAccount;
  33. CloudTableClient cl = account.CreateCloudTableClient();
  34. var table = cl.GetTableReference("kuku");
  35. table.CreateIfNotExists(); // utworzenie tabeli jeżeli nie istnieje
  36. var e = new Osoba(login, haslo);
  37. TableOperation op = TableOperation.Insert(e);
  38. table.Execute(op);
  39. }
  40.  
  41. public void DodajPlik(string login, string haslo, string nazwa, string zawartosc)
  42. {
  43. var account = CloudStorageAccount.DevelopmentStorageAccount;
  44.  
  45. CloudBlobClient client = account.CreateCloudBlobClient();
  46. CloudBlobContainer container = client.GetContainerReference(login);
  47. container.CreateIfNotExists();
  48. // pobranie referencji do blokowego BLOBa
  49. var blob = container.GetBlockBlobReference(nazwa);
  50. // null gdy nie istnieje
  51. // zapisanie strumienia do BLOBa
  52. var bytes = new System.Text.ASCIIEncoding().GetBytes(zawartosc);
  53. var s = new System.IO.MemoryStream(bytes);
  54. blob.UploadFromStream(s);
  55.  
  56. }
  57.  
  58. public string PobierzPlik(string login, string haslo, string nazwa)
  59. {
  60. var account = CloudStorageAccount.DevelopmentStorageAccount;
  61.  
  62. CloudBlobClient client = account.CreateCloudBlobClient();
  63. CloudBlobContainer container = client.GetContainerReference(login);
  64. container.CreateIfNotExists();
  65. // pobranie referencji do blokowego BLOBa
  66. var blob = container.GetBlockBlobReference(nazwa);
  67. var s2 = new System.IO.MemoryStream();
  68. blob.DownloadToStream(s2);
  69. string content = System.Text.Encoding.UTF8.GetString(s2.ToArray());
  70. return content;
  71. }
  72.  
  73. public string ListaPlikow(string login, string haslo)
  74. {
  75. var account = CloudStorageAccount.DevelopmentStorageAccount;
  76.  
  77. CloudBlobClient client = account.CreateCloudBlobClient();
  78. CloudBlobContainer container = client.GetContainerReference(login);
  79. container.CreateIfNotExists();
  80. string lst = "";
  81. foreach (IListBlobItem item in container.ListBlobs(null, false))
  82. {
  83. // string nazwa = item.
  84. if (item.GetType() == typeof(CloudBlockBlob))
  85. {
  86. CloudBlockBlob blob = (CloudBlockBlob)item;
  87. lst += blob.Name + "\n";
  88. // lst += String.Format("Block blob of length {0}: {1}",
  89. // blob.Properties.Length, blob.Uri) + "\n";
  90. }
  91. else if (item.GetType() == typeof(CloudPageBlob))
  92. {
  93. CloudPageBlob pageBlob = (CloudPageBlob)item;
  94. lst += String.Format("Page blob of length {0}: {1}",
  95. pageBlob.Properties.Length, pageBlob.Uri) + "\n";
  96. }
  97. else if (item.GetType() == typeof(CloudBlobDirectory))
  98. {
  99. CloudBlobDirectory directory = (CloudBlobDirectory)item;
  100. lst += String.Format("Directory: {0}", directory.Uri) + "\n";
  101. }
  102. }
  103. return lst;
  104. }
  105. }
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement