Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.50 KB | None | 0 0
  1. using System;
  2. using Microsoft.WindowsAzure.Storage;
  3. using Microsoft.WindowsAzure.Storage.Table;
  4. using System.Threading.Tasks;
  5. //CLASA
  6. namespace Seba
  7. {
  8. public class Student: TableEntity
  9. {
  10. public Student(string f, string r ){
  11. this.PartitionKey=f;
  12. this.RowKey=r;
  13. }
  14. public Student(){}
  15. public string Name { get; set; }
  16.  
  17. public string Email { get; set; }
  18.  
  19. }
  20. }
  21. ///main
  22. using System;
  23. using Microsoft.WindowsAzure.Storage;
  24. using Microsoft.WindowsAzure.Storage.Table;
  25. using System.Threading.Tasks;
  26.  
  27. namespace Seba
  28. {
  29. class Program
  30. {
  31. static void Main(string[] args)
  32. {
  33. Task.Run(async () => {
  34. await conectare_tabel();
  35. }).GetAwaiter().GetResult();
  36.  
  37. // try
  38. // {
  39. // // conectare_tabel().Wait();
  40. // }
  41. // catch (Exception ex)
  42. // {
  43. // Console.WriteLine($"There was an exception: {ex.ToString()}");
  44. // }
  45. }
  46. async static Task instantiere_fields(CloudTable peopleTable)
  47. {
  48. Student st = new Student("AC", "1921215355555");
  49. st.Name = "Sebastian LEONTI";
  50. st.Email = "sebastanopol@gmail.com";
  51. TableOperation insertOperation = TableOperation.Insert(st);
  52. await peopleTable.ExecuteAsync(insertOperation);
  53. }
  54. async static Task conectare_tabel()
  55. {
  56. CloudStorageAccount storageAccount = new CloudStorageAccount(
  57. new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials(
  58. "datcdemovineri", "yDSrMBCO7cHeRHJMkTbG1MZ3i7HKKWOMdcoHhe4N3iFn/VCZYgnN1AQ5Ga/LxidOzgv0llbT4ZXpUU2UO+12wQ=="), true);
  59. // Create the table client.
  60. CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
  61. // Get a reference to a table named "peopleTable"
  62. CloudTable peopleTable = tableClient.GetTableReference("StudentiLS");
  63. await CreatePeopleTableAsync(peopleTable);
  64. await cautare(peopleTable);
  65. }
  66.  
  67. async static Task CreatePeopleTableAsync(CloudTable peopleTable)
  68. {
  69. // Create the CloudTable if it does not exist
  70. await peopleTable.CreateIfNotExistsAsync();
  71. // await instantiere_fields(peopleTable);
  72. }
  73. async static Task cautare(CloudTable peopleTable)
  74. {
  75. // Construct the query operation for all customer entities where PartitionKey="Smith".
  76. TableQuery<Student> query = new TableQuery<Student>(); //.Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, "AC"));
  77.  
  78. // Print the fields for each customer.
  79. TableContinuationToken token = null;
  80. do
  81. {
  82. TableQuerySegment<Student> resultSegment = await peopleTable.ExecuteQuerySegmentedAsync(query, token);
  83. token = resultSegment.ContinuationToken;
  84.  
  85. foreach (Student entity in resultSegment.Results)
  86. {
  87. Console.WriteLine("{0}, {1}\t{2}", entity.PartitionKey, entity.RowKey,
  88. entity.Email);
  89. }
  90. } while (token != null);
  91.  
  92. }
  93.  
  94. }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement