Создание модели данных для элементов в table storage 


Мы поможем в написании ваших работ!



ЗНАЕТЕ ЛИ ВЫ?

Создание модели данных для элементов в table storage



  1. В Solution Explorer нажмите правой кнопкой мыши по Begin, выберите Add | New Project.
  2. В диалоге Add New Project, разверните узел Visual C# в списке Installed Templates, выберите категорию Windows и выделите Class Library в списке шаблонов. Убедитесь что выбрат. NET Framework 3.5. Введите имя GuestBook_Data и нажмите OK.

 

 

Создание библиотеки классов

  1. Удалите файл класса по умолчанию. Нажмите правой кнопкой по Class1.cs и выберите Delete. Нажмите OK.
  2. Добавьте ссылку на библиотеку.NET для ADO.NET в проект GuestBook_Data. В Solution Explorer нажмите правой кнопкой по проекту GuestBook_Data, выберите Add Reference, затем выберите закладку .NET, выделите компонент System.Data.Service.Client и нажмите OK.
  3. Выполните пункт 4, добавив ссылку библиотеку Microsoft.WindowsAzure.StorageClient

 

 

  1. Нажмите правой кнопкой мыши по GuestBook_Data в Solution Explorer, выберите Add, затем Class. В диалоге Add New Item введите имя GuestBookEntry.cs и нажмите Add.

 

 

  1. Откройте файл GuestBookEntry.cs, добавьте в начало файла using Microsoft.WindowsAzure.StorageClient;
  2. Измените объявление класса GuestBookEntry

9. public class GuestBookEntry:

10. Microsoft.WindowsAzure.StorageClient.TableServiceEntity

11. {

}

  1. Добавьте конструктор по умолчанию

13.public GuestBookEntry()

14. {

15. PartitionKey = DateTime.UtcNow.ToString("MMddyyyy");

16.

17. // Row key allows sorting, so we make sure the rows come back in time order.

18. RowKey = string.Format("{0:10}_{1}", DateTime.MaxValue.Ticks - DateTime.Now.Ticks, Guid.NewGuid());

}

  1. Добавьте свойства

20.public string Message { get; set; }

21. public string GuestName { get; set; }

22. public string PhotoUrl { get; set; }

public string ThumbnailUrl { get; set; }

  1. Сохраните файл GuestBookEntry.cs.
  2. Нажмите правой кнопкой мыши по GuestBook_Data в Solution Explorer, выберите Add, затем Class. В диалоге Add New Item введите имя GuestBookDataContext.cs и нажмите Add.
  3. Откройте файл GuestBookDataContext.cs, добавьте в начало файла

26.using Microsoft.WindowsAzure;

using Microsoft.WindowsAzure.StorageClient;

  1. Измените объявление класса GuestBookDataContext и добавьте конструктор

28.public class GuestBookDataContext: TableServiceContext

29. {

30. public GuestBookDataContext(string baseAddress, StorageCredentials credentials)

31.: base(baseAddress, credentials)

32. { }

}

  1. Добавьте свойство

34.public class GuestBookDataContext: TableServiceContext

35. {

36....

37. public IQueryable<GuestBookEntry> GuestBookEntry

38. {

39. get

40. {

41. return this.CreateQuery<GuestBookEntry>("GuestBookEntry");

42. }

43. }

}

  1. Нажмите правой кнопкой мыши по GuestBook_Data в Solution Explorer, выберите Add, затем Class. В диалоге Add New Item введите имя GuestBookDataContext.cs и нажмите Add.
  2. Откройте файл GuestBookEntryDataSource.cs, добавьте в начало файла

46.using Microsoft.WindowsAzure;

using Microsoft.WindowsAzure.StorageClient;

  1. Далее измените класс

48.public class GuestBookEntryDataSource

49. {

50. private static CloudStorageAccount storageAccount;

51. private GuestBookDataContext context;

}

  1. Добавьте конструктор

53.public class GuestBookEntryDataSource

54. {

55. private static CloudStorageAccount storageAccount;

56. private GuestBookDataContext context;

57.

58. static GuestBookEntryDataSource()

59. {

60. storageAccount = CloudStorageAccount.FromConfigurationSetting("DataConnectionString");

61.

62. CloudTableClient.CreateTablesFromModel(

63. typeof(GuestBookDataContext),

64. storageAccount.TableEndpoint.AbsoluteUri,

65. storageAccount.Credentials);

66. }

}

  1. Добавьте конструктор для класса GuestBookDataEntrySource

68.public GuestBookEntryDataSource()

69. {

70. this.context = new GuestBookDataContext(storageAccount.TableEndpoint.AbsoluteUri, storageAccount.Credentials);

71. this.context.RetryPolicy = RetryPolicies.Retry(3, TimeSpan.FromSeconds(1));

}

  1. Добавьте методы

73.public IEnumerable<GuestBookEntry> Select()

74. {

75. var results = from g in this.context.GuestBookEntry

76. where g.PartitionKey == DateTime.UtcNow.ToString("MMddyyyy")

77. select g;

78. return results;

79. }

80.

81. public void UpdateImageThumbnail(string partitionKey, string rowKey, string thumbUrl)

82. {

83. var results = from g in this.context.GuestBookEntry

84. where g.PartitionKey == partitionKey && g.RowKey == rowKey

85. select g;

86.

87. var entry = results.FirstOrDefault<GuestBookEntry>();

88. entry.ThumbnailUrl = thumbUrl;

89. this.context.UpdateObject(entry);

90. this.context.SaveChanges();

}



Поделиться:


Последнее изменение этой страницы: 2016-12-12; просмотров: 249; Нарушение авторского права страницы; Мы поможем в написании вашей работы!

infopedia.su Все материалы представленные на сайте исключительно с целью ознакомления читателями и не преследуют коммерческих целей или нарушение авторских прав. Обратная связь - 3.147.65.65 (0.008 с.)