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

Apress Introducing Dot Net 4 With Visual Studio_9 pot

45 379 0

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

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 45
Dung lượng 3,52 MB

Nội dung

CHAPTER 16  WINDOWS AZURE 417 <ConfigurationSettings> <Setting name="DiagnosticsConnectionString" /> <Setting name="Message"/> </ConfigurationSettings> </WebRole> </ServiceDefinition> 4. We will now define the actual value of this setting, so open ServiceDefinition.cscfg and add a new setting inside the ConfigurationSettings element: <Setting name="Message" value="Hello Azure"/> 5. While we are working with ServiceDefinition.cscfg, find the element that reads <Instances count="1"/> and change it to <Instances count="5"/> 6. Changing the instances count tells Azure to create five instances of our application and simulates scaling our application to use five Azure nodes (you will need to set this back before deployment depending on your pricing structure). This setting can be easily amended online; note how easy it is to quickly scale up your application depending on demand. Microsoft recently announced Azure supports an API that allows you to do this programmatically. Your ServiceDefinition.cscfg should now look like <?xml version="1.0"?> <ServiceConfiguration serviceName="Chapter16.HelloAzure" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration"> <Role name="Chapter16.WebRole"> <Instances count="5" /> <ConfigurationSettings> <Setting name="DiagnosticsConnectionString" value="UseDevelopmentStorage=true" /> <Setting name="Message" value="Hello Azure"/> </ConfigurationSettings> </Role> </ServiceConfiguration> Open Default.aspx.cs and enter the following code: using Microsoft.WindowsAzure.ServiceRuntime; protected void Page_Load(object sender, EventArgs e) { string GreetingString = "" + RoleEnvironment.GetConfigurationSettingValue("message"); Response.Write(GreetingString + " at " + DateTime.Now.ToString()); } 7. Press F5 to run the application and you should see the greeting value we defined output to the screen with the current time and date. CHAPTER 16  WINDOWS AZURE 418 Logging and Debugging When running your Azure applications locally, you can make full use of standard Visual Studio debugging facilities. However, when applications are deployed to the cloud, debugging and logging support is a bit limited at the time of writing. At the time of writing the logging APIs are in a state of flux (http://blogs.msdn.com/windowsazure/ archive/2009/10/03/upcoming-changes-to-windows-azure-logging.aspx) so expect the final version to have performance monitoring features and integration with Azure storage (see the following). Note that the RoleManager.WriteToLog() method that was present in preview versions has been removed. Testing Azure Applications We have now finished our application's development, so we need to test it. Development would be very slow if we had to deploy to the cloud each time to test it, so Microsoft provides a local version of Azure called the development fabric that simulates how our applications will function in the cloud. Before we can run Azure our application, we will need to create the development storage database (which is just a SQL Server database). This seems to be used for deployment and testing of Azure applications. It can also be quite useful for debugging Azure storage issues (discussed later in the chapter). Creating Development Storage To create development storage, open the Windows Azure SDK command prompt (on the Windows menu under the Windows Azure SDK v1.0 folder) and then enter the following command replacing INSTANCENAME with the name of your SQL Server instance (if you don’t want to use an instance just enter a dot to refer to the machine itself): DSInit /sqlinstance:INSTANCENAME After you press return, the DSInit utility will start creating the development storage database (Figure 16-4): Figure 16-4. Creation of development storage CHAPTER 16  WINDOWS AZURE 419 Now press F5 to run your application and you should see an exciting screen like Figure 16-5: Figure 16-5. Hello Azure application Well done—you have created your first Azure application—but don’t close the web browser window just yet. Take a look at the Windows taskbar (you may have to click Show hidden icons if you are using Windows 7) where there will be a small blue Windows Azure flag showing. Left-clicking on this will show you the current Azure storage and development fabric status (Figure 16-6). Figure 16-6. Azure storage Now right-click on the blue flag and notice how you can shut down the development storage and fabric here as well. This time, however, select the option to show the development fabric UI, and you should see a screen similar to Figure 16-7: CHAPTER 16  WINDOWS AZURE 420 Figure 16-7. Development Fabric UI The window is split into two panes. On the left-hand side is a tree structure that allows you to view details of the service and individual web roles, while over on the right is the logging output from the various Azure instances. Service Details Node Click the Service Details node to show you details of where your service is running. Chapter16.HelloAzure Node Right-click on the Chapter16.HelloAzure node and you will see options for starting, suspending, and restarting the services. You can further configure the project restart configuration by right-clicking and selecting Settings. Chapter16.WebRole Node Right-click the web role node and you will see options for clearing the logs and changing the logging level. Left-clicking the web role node will expand it to show all instances of the application running, which are represented by a number of green globes. The black screens on the left show the output from the individual nodes. CHAPTER 16  WINDOWS AZURE 421 Green Globes If you right-click a green globe (web role) you will see options to attach a debugger and view the local store. Viewing Azure Logs To view the log file of your application, click one of the black screens to see the output. If you right-click on the green globe you have the options to filter the message types displayed by selecting the logging level (Figure 16-8). Figure 16-8. Viewing Azure log on development storage  TIP For applications that will be deployed to both standard web servers and Azure it can be useful to determine whether you are running in the fabric. The RoleEnvironment.IsAvailable() method returns a Boolean value indicating this. CHAPTER 16  WINDOWS AZURE 422 Deployment To deploy your application to the cloud you will need a Windows Azure account. If you do not have one yet, what are you waiting for? Go and sign up for one now at http://www.microsoft.com/ windowsazure/account/. Deploying Hello Azure Application Before you deploy your application, check whether you have reset the instance count in the .cscfg file of the Hello Azure application from five to one, as depending on your price plan; otherwise, you may receive an error when you upload your application. OK, let’s deploy the project we created earlier by right-clicking on the HelloAzure project and selecting Publish. Visual Studio will build the application, open the publish directory folder in Windows Explorer and send you to the Windows Azure platform login page. The Windows Azure Portal allows you to deploy, configure and manage your applications. Once you have logged into the services portal and you should see a screen similar to Figure 16-9: Figure 16-9. Azure Services Portal CHAPTER 16  WINDOWS AZURE 423 This page lists all the projects associated with this user. If you haven’t created a project yet, click the adding services to the project link. In the previous example, I have a project called PDC08CTP; click this and you will then be taken to the project services screen (Figure 16-10). Here, if you haven’t already, click the New Service link and add a new hosted service (in the screen shot mine is called Introducing VS2010). Then click on it. Figure 16-10. Project services screen You should then be taken to a screen that shows the current status of your Azure roles (Figure 16-11). CHAPTER 16  WINDOWS AZURE 424 Figure 16-11. Inactive web role Notice at the moment this screen shows only the production instance (see the following section for how to upload to staging instance). We want to upload our application to Windows Azure, so click the Deploy button beneath the staging cube and you will be taken to the Staging Deployment screen. We now need to upload our application itself and its service configuration file. CHAPTER 16  WINDOWS AZURE 425 Application Package Section On the Application Package section, click the Browse button and select the compiled application’s cspkg file (by default this is built at: ~\bin\Debug\Publish\). See Figure 6-12. Figure 16-12. Uploading ServiceConfiguration files Configuration Settings Section On the Configuration Settings section, click the Browse button and select the S Se rviceConfiguration file (default location: ~ ~\He lloAzure\ bin\Debug\ Publish\ServiceConfigu ration.cscfg ). Now give the deployment a descriptive label (e.g., v1.0.0) and click Deploy. Your service will now be deployed to the cloud (Figure 16-13). This is not the quickest process so you may want to go and do something else for five minutes. Once your application has been uploaded, a number of new options will appear beneath the cube enabling you to configure and run it (Figure 16-14). CHAPTER 16  WINDOWS AZURE 426 Figure 16-13. Screen after uploading an application Figure 16-14. Screen after role has been uploaded [...]... Access Control Service, 44 3 accessibility, and Silverlight 3.0, 40 5 Action delegates, 81 Action type, 48 Action type, 48 ActionDetail method, 305 ActionLink method, 307 ActionMessageFilter filter, 165 ActiveX controls, 328 activities, Windows Workflow Foundation 4 composed of other activities, 142 – 143 creating pure XAML workflows, 144 – 145 creating purely in code, 143 Activity class, 131... 383 All service, 44 4 Allow Partially Trusted Callers Attribute (APTCA), 76 analytical data, for Windows Azure deployment, 42 8 Animal class, 49 animation jQuery Core library effects, 281 effect overloads, 280–281 Glimmer, 282 jQuery tools, 282 Silverlight animation easing, 385 declarative animation, 347 – 348 programmatic, 345 – 346 responding to user events, 346 Animation.xaml file, 346 announcementEndpoint... variable, 140 , 146 BookService class, 269 Booysen, Ray, 44 5 Bounciness property, 399 br snippet, 230 breadcrumb trail, 139 bridging protocols, 166 Britcliffe, Andy, 40 7 40 9, 44 6 browser history, for Silverlight 3.0, 391 browser zoom support, for Silverlight 3.0, 40 5 BrowserInteropHelper class, 386 brushes, 367–368 C C#, using JSON with, 217 cache dynamic calls, 58 cached composition, 3 84 385 CacheMode... Authorization attribute, 312 Auto setting, 370, 383 AutoBuffered mode, 116 AutoID setting, 239 AutoScroll option, 1 14 autoupdate of Silverlight 3.0 applications, 391 axd extension, 316 Azure API, 43 1 43 2 Azure Storage, 43 1 43 2, 43 6 43 8 AzureDataServiceContext project, 44 2 AzureRawHttp application, 43 6 B Background collection, 72 Background option, 368 backupLists section, 166 Bag O'Tricks, 378 BAL (Base Activity... Path.Combine( ), 82 profiling, 76 45 2 registry access changes, 82–83 security APTCA and Evidence, 76 changes to, 75 critical code, 74 purpose of, 74 safe critical code, 74 safe critical gatekeeper, 74 SecAnnotate, 75 transparency model, 74 transparent code, 74 ServiceProcessInstaller.DelayedAuto Start, 85 Stopwatch.Restart( ), 84 Stream.CopyTo( ), 83 StringBuilder.Clear, 84 String.Concat( ) and String.Join(... http://127.0.0.1:10000/devstoreaccount1/blobs Mon, 16 Nov 2009 02:32:13 GMT 0x8CC 347 C 240 E3FE0 p p ictures 43 7 CHAPTER 16 WINDOWS AZURE http://127.0.0.1:10000/devstoreaccount1/pictures Mon, 16 Nov 2009 09:16 :40 GMT 0x8CC34B4A41BA4B0 wad-control-container http://127.0.0.1:10000/devstoreaccount1/wad-control-container... cancellation tokens, 123, 1 24 CancellationScope activity, 152 CancellationTokenSource class, 117, 122 cancelling queries, Parallel LINQ (PLINQ), 117 canvas control, Silverlight, 340 Canvas.Left property, 339, 340 Canvas.Top property, 339, 340 CaretBrush property, 40 5 CAS (Code Access Security) policies, 74 CCR (Concurrency and Coordination Runtime), 97 CDBuring folder, 84 CDS (coordination data structures)... structure, 293–2 94 purpose of, 290 real world applications, 322 returning Views, 302 routing, 301 running application, 300–301 security, 316–317 45 0 TempData, 302 testing creating fake film repository, 318 modify Film_ controller, 321 type initialization, 292 V2, 322 ViewData, 302 viewstate, 292 ASP .NET, new common language runtime (CLR), 68 AspNetCache profile attribute, 172 Aspnet.config file, 247 aspx file,... logging and analytics • Performance counters and some kind of query analyzer for Azure table storage • Option to use the distributed cache system velocity 44 5 CHAPTER 16 WINDOWS AZURE Figure 16-21 DotNetSolutions Wikipedia explorer http://www.dotnetsolutions.co.uk/ evidence/wikiexplorer/ Rusty Johnson and Andy Britcliffe, SharpCloud (www.sharpcloud.com) SharpCloud is currently developing a Silverlight/Azure... Library (BAL), 131 INDEX BasedOn property, 395 basePath property, 2 54 basicHttpBinding method, 161 BigInteger class, 78 Binary Large Object (blobs) data, 43 1 binary XML support, Silverlight 3.0 performance, 40 3 Bind attribute, 312 bind( ) method, 280 bindImages( ) method, 43 3 binding attributes in ASP .NET MVC, 311 changes for WPF 4. 0, 381–382 converters, 266 DataView declarative, 257–258 programmatic, . http:// 127.0.0.1:10000/devstoreaccount1/pictures/4d5eee66-162e-4fb1-afcb- 197 f083 840 07). Accessing REST API Directly Now that we have worked with the StorageClient, however, I think that it. creating the development storage database (Figure 16 -4) : Figure 16 -4. Creation of development storage CHAPTER 16  WINDOWS AZURE 41 9 Now press F5 to run your application and you should. should see a screen similar to Figure 16 -9: Figure 16 -9. Azure Services Portal CHAPTER 16  WINDOWS AZURE 42 3 This page lists all the projects associated with this user. If you haven’t created

Ngày đăng: 18/06/2014, 16:20