Exportar (0) Imprimir
Expandir Tudo

Classe LocalResource

[Este tópico é uma documentação de pré-lançamento e está sujeito a alterações em versões futuras. Os tópicos em branco são incluídos como espaços reservados.]

Represents a local storage resource that is reserved for a hosted service.

Namespace: Microsoft.WindowsAzure.ServiceRuntime
Assembly: Microsoft.WindowsAzure.ServiceRuntime (em microsoft.windowsazure.serviceruntime.dll)

'Uso
Dim instance As LocalResource

public abstract class LocalResource
public abstract class LocalResource
public abstract class LocalResource

A local storage resource is a reserved directory in the file system of the virtual machine in which an instance of a role is running. To define a local storage resource for your hosted service, you must add a LocalResources element with LocalStorage elements to the ServiceDefinition.csdef file of the hosted service for each directory that you want to create. For more information about defining local storage resources, see the How to Configure Local Storage Resources.

After you define the local storage resources in the ServiceDefinition.csdef file, you can access the directories by using the properties defined in the LocalResource class. The following code example shows how you can write text to a file in the local storage resource:


// Retrieve an object that points to the local storage resource
LocalResource localResource = RoleEnvironment.GetLocalResource("localStoreTwo");

//Define the file name and path
string[] paths = { localResource.RootPath, "MyStorageTest.txt"};
String filePath = Path.Combine(paths);

using (FileStream writeStream = File.Create(filePath))
{
   Byte[] textToWrite = new UTF8Encoding(true).GetBytes("Testing Web role storage");
   writeStream.Write(textToWrite, 0, textToWrite.Length);
}
using (StreamReader streamReader = File.OpenText(filePath)
{
   string fileText = "";
   while ((fileText = streamReader.ReadLine()) != null)
   {
      Trace.WriteLine("The text from the file is: " + fileText, "Information");
   }
}

System.Object
  Microsoft.WindowsAzure.ServiceRuntime.LocalResource

Todos os membros estáticos públicos (Compartilhados no Visual Basic) desse tipo são thread-safe. Quaisquer membros de instância não têm garantia de ser thread-safe.

Plataformas de desenvolvimento

Windows XP Professional com Service Pack 2 (SP2)

Plataformas de destino

Contribuições da comunidade

Mostrar:
© 2014 Microsoft