1. Trang chủ
  2. » Công Nghệ Thông Tin

Introducing Windows Azure- P9 pdf

5 277 0

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 5
Dung lượng 211,4 KB

Nội dung

CHAPTER 1 ■ CREATE CLOUD TABLE STORAGE 13 When development storage is created the first time, message boxes will be popped up as shown in Figure 1-7 and Figure 1-8. The local development storage and development fabric can be manually started from the Windows Start menu as Figure 1-9 shows. Figure 1-10 and Figure 1-11 show the results of these services having been successfully started from the local development environment. Figure 1-7. Dialog message to confirm installation of development storage Figure 1-8. Confirming the settings using the default endpoint address for development storage the first time local development storage is used CHAPTER 1 ■ CREATE CLOUD TABLE STORAGE 14 Figure 1-9. Manually starting local development storage and development fabric Figure 1-10. Opening the information window to verify current status of the development fabric Figure 1-11. Right-clicking on the development storage icon to shut down the development fabric CHAPTER 1 ■ CREATE CLOUD TABLE STORAGE 15 This exercise demonstrates the basic steps to create a cloud data storage table using Windows Azure SDK development storage table service. In principle, the approach is fairly straightforward. However, in practice, since storage usage in a cloud environment is quite different from that in the regular on- premises environment, we should follow some rules and best practices. Using Portable Data Types for Data Columns Essentially, the data type of a data column should be portable to a SQL data type, or be able to be understood as a system-defined basic data type. Using Data Tables Generated by Windows Azure Development Tool Use the Azure development tool provided by the Azure development SDK to invoke the development storage service from Visual Studio to generate the data storage database and data tables. The development tool analyzes the data objects of all projects across the cloud application solution to generate the data structure for you. The number of data tables equals the number of data entity classes that derive from the TableStorageEntity class. The number of columns in a generated data table equals the number of public access properties defined in that data entity class. Solutions to Non-Portable Data Types If the data type is a custom-defined type, the SDK development tools will fail to invoke DevelopmentStorage.exe and DevtableGen.exe. The following example illustrates how to solve this problem if we have to use a data column in a data table with a custom-defined type, generally an embedded class of the parent, which is the type not portable to a SQL database. In this example, we need to define two data object classes, the State and the Address. The State is the enumeration type with total of 59 members representing the states used by United States Postal Service. Each Address class has an attribute member with this custom-defined State type as shown in Listing 1-6. Listing 1-6. An Address Class with an Attribute Member Using a Non-portable Custom-defined Type State public enum State { AL,AK,AS,AZ,AR,CA,CO,CT,DE,DC,FM,FL,GA,GU,HI, ID,IL,IN,IA,KS,KY,LA,ME,MH,MD,MA,MI,MN,MS,MO, MT,NE,NV,NH,NJ,NM,NY,NC,ND,MP,OH,OK,OR,PW,PA, PR,RI,SC,SD,TN,TX,UT,VT,VI,VA,WA,WV,WI,WY } public class Address : TableStorageEntity { public State State { get; set; } } CHAPTER 1 ■ CREATE CLOUD TABLE STORAGE 16 When we invoke Create Test Storage Table from Visual Studio again as we did before, we will be asked to confirm removal of the existing storage from the database as Figure 1-12 shows. Figure 1-12. Confirmation to remove existing table from cloud data storage dialog box when regenerating the cloud storage Click Yes to confirm this action. An error message pops up to show the failure of the action as Figure 1-13 shows. Figure 1-13. Error message from the compiler when attempting to regenerate the storage tables if a non-portable data type is added to a cloud table The error message from the output window of Visual Studio is: DevTableGen(0,0): error DG10: No tables were generated. Either no candidate classes were found or they did not meet the requirements for the table storage. CHAPTER 1 ■ CREATE CLOUD TABLE STORAGE 17 This error message does not make much sense for troubleshooting, nor does the compiler provide any specific information on why the data table could not be created. We can follow four steps to regenerate the table: 1. Make the State type inherit the type int, since int is a system-defined type and portable to a SQL database. 2. Define a member variable state with the type of State in the Address class. 3. Apply the .NET nullable design pattern to this member variable. 4. Cast the type between the portable and custom-defined enum type from the access function. The modified code is in boldface in Listing 1-7. After the modification, use Visual Studio to regenerate the table. The error will go away, and the table will be recreated in the local SQL database. Listing 1-7. An Example of Solutions for Non-portable Data Types public enum State : int { AL,AK,AS,AZ,AR,CA,CO,CT,DE,DC,FM,FL,GA,GU,HI, ID,IL,IN,IA,KS,KY,LA,ME,MH,MD,MA,MI,MN,MS,MO, MT,NE,NV,NH,NJ,NM,NY,NC,ND,MP,OH,OK,OR,PW,PA, PR,RI,SC,SD,TN,TX,UT,VT,VI,VA,WA,WV,WI,WY } public class Address : TableStorageEntity { private State _state; public int? State { get { return (int) state; } set { state = (State)value; } } } Data Context Class Inheritance In addition to the data entity class, for each data storage table, a class that inherits from the class TableStorageDataServiceContext must be defined with a data service query function implementation as Listing 1-8 shows. . Figure 1-8. The local development storage and development fabric can be manually started from the Windows Start menu as Figure 1-9 shows. Figure 1-10 and Figure 1-11 show the results of these services. STORAGE 15 This exercise demonstrates the basic steps to create a cloud data storage table using Windows Azure SDK development storage table service. In principle, the approach is fairly straightforward be able to be understood as a system-defined basic data type. Using Data Tables Generated by Windows Azure Development Tool Use the Azure development tool provided by the Azure development

Ngày đăng: 05/07/2014, 01:20

w