2012-11-28 6 views
1

내 개인 컨테이너에서 VHD를 마운트하려고합니다. Google 후에는 .net을 통해서만 가능하다는 것을 알게되었습니다. 나는 더 많은 자바 사람입니다. 배치 스크립트 나 코드가 C# (exe 파일을 얻을 수 있도록)이 필요합니다.이 스크립트는 자동으로 시작할 때 실행할 수 있고 vhd를 마운트 할 수 있습니다. 그래서 exe 파일을 얻으려면 콘솔 응용 프로그램을 만들기로 결정했습니다. (저는 C#/Visual Studio에 대한 지식이 거의 없습니다)이 작업을 위해 C# 콘솔 응용 프로그램을 사용하고 있습니다.콘솔 azure cloud 드라이브를 설치하려면

using System; 
using System.Collections.Generic; 
using System.Diagnostics; 
using System.Linq; 
using System.Net; 
using System.Threading; 
using Microsoft.WindowsAzure; 
using Microsoft.WindowsAzure.Diagnostics; 
using Microsoft.WindowsAzure.ServiceRuntime; 
using Microsoft.WindowsAzure.StorageClient; 

using Microsoft.WindowsAzure.Internal; 

namespace WorkerRole1 
{ 
public class WorkerRole : RoleEntryPoint 
{ 
    public override void Run() 
    { 
     // This is a sample worker implementation. Replace with your logic. 
     Trace.WriteLine("WorkerRole1 entry point called", "Starting"); 
     MountDrive(); 

     //while (true) 
     //{ 
     // Thread.Sleep(10000); 
     // Trace.WriteLine("Working", "Information"); 
     //} 
    } 

    public override bool OnStart() 
    { 
     // Set the maximum number of concurrent connections 
     ServicePointManager.DefaultConnectionLimit = 12; 

     // For information on handling configuration changes 
     // see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357. 

     return base.OnStart(); 
    } 

    public void MountDrive() 
    { 
     string connectionStringSettingName = "DefaultEndpointsProtocol=http;AccountName=abc;AccountKey=xyz"; 
     string azureContainerName = "vhds"; 
     string vhdName = "myvhd.vhd"; 
     CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionStringSettingName); 
     //CloudStorageAccount storageAccount = CloudStorageAccount.DevelopmentStorageAccount; 

     LocalResource localCache = RoleEnvironment.GetLocalResource("MyAzureDriveCache"); 
     CloudDrive.InitializeCache(localCache.RootPath, localCache.MaximumSizeInMegabytes); 
     Trace.WriteLine("RootPath =====" + localCache.RootPath); 
     Trace.WriteLine("MaximumSizeInMegabytes =====" + localCache.MaximumSizeInMegabytes); 
     // Just checking: make sure the container exists 
     CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); 
     blobClient.GetContainerReference(azureContainerName).CreateIfNotExist(); 

     // Create cloud drive 
     CloudDrive myCloudDrive = storageAccount.CreateCloudDrive(
      blobClient 
      .GetContainerReference(azureContainerName) 
      .GetPageBlobReference(vhdName) 
      .Uri.ToString() 
     ); 
     Trace.WriteLine("Uri =====" + blobClient 
      .GetContainerReference(azureContainerName) 
      .GetPageBlobReference(vhdName) 
      .Uri.ToString()); 

     try 
     { 
      myCloudDrive.Create(1024); 
     } 
     catch (CloudDriveException ex) 
     { 
      // handle exception here 
      // exception is also thrown if all is well but the drive already exists 
     } 

     string driveLetter = myCloudDrive.Mount(50, DriveMountOptions.Force);//Here It throws a Exception 
     Trace.WriteLine("Drive =====" + driveLetter); 

     for (int i = 0; i < 10; i++) 
     { 
      System.IO.File.WriteAllText(driveLetter + "\\" + i.ToString() + ".txt", "Test"); 
     } 


    } 

} 
} 

하지만

string driveLetter = myCloudDrive.Mount(50, DriveMountOptions.Force); 

에서 예외 ERROR_DEVFABRIC_LOCAL_MOUNT_ONLY가 계속 알려주세요 어디에 내가 잘못 갈거야?

답변

1

RoleEnvironment.IsAvailable거짓으로 설정되면 이는 Windows Azure 웹/작업자/VM 역할을 실행하고 있지 않음을 의미합니다. Windows Azure 드라이브는 RoleEnvironment에 따라 다르므로 이러한 역할에 탑재 된 경우에만 작동합니다.

자세한 내용은 whitepaper에서 확인할 수 있습니다.

+0

감사 서비스 구성에서 설정을 설정합니다. 내 질문을 편집합니다. 검토해주십시오. –

+0

컴퓨터에 Azure Drive를 마운트하려면 개발 스토리지를 사용해야합니다 :'CloudStorageAccount.DevelopmentStorageAccount;' –

0

ERROR_DEVFABRIC_LOCAL_MOUNT_ONLY은 로컬에서 실행할 때 드라이브 폼 개발 저장소를 마운트해야한다는 것을 의미합니다.

변경 다음 줄

string connectionStringSettingName = "UseDevelopmentStorage=true"; 

또는 더 나은처럼 RoleEnvironment.GetConfigurationSettingValue를 사용

string connectionStringSettingName = RoleEnvironment.GetConfigurationSettingValue("DriveConnectionString"); 

및 (파일) 빠른 응답

관련 문제