本文整理汇总了C#中Microsoft.WindowsAzure.CloudStorageAccount.CreateCloudDrive方法的典型用法代码示例。如果您正苦于以下问题:C# CloudStorageAccount.CreateCloudDrive方法的具体用法?C# CloudStorageAccount.CreateCloudDrive怎么用?C# CloudStorageAccount.CreateCloudDrive使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.WindowsAzure.CloudStorageAccount
的用法示例。
在下文中一共展示了CloudStorageAccount.CreateCloudDrive方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnInitialize
private void OnInitialize()
{
var selfInstance = InstanceEnumerator.EnumerateInstances().First(i => i.IsSelf);
cloudStorageAccount = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue(ConfigurationSettingsKeys.StorageConnectionString));
log.Info("Storage account selected: {0}",cloudStorageAccount.BlobEndpoint);
cloudBlobClient = cloudStorageAccount.CreateCloudBlobClient();
log.Info("Storage client created");
var containerName = ConfigurationProvider.GetSetting(ConfigurationSettingsKeys.StorageContainerName,"ravendb");
// In order to force a connection we just enumerate all available containers:
var availableContainers = cloudBlobClient.ListContainers().ToArray();
foreach (var container in availableContainers)
{
log.Info("Available container: {0}",container.Name);
}
if (!availableContainers.Any(c => c.Name.Equals(containerName)))
{
log.Info("Container {0} does not exist, creating",containerName);
// Container does not exist:
cloudBlobClient.GetContainerReference(containerName).Create();
}
cloudBlobContainer = cloudBlobClient.GetContainerReference(containerName);
log.Info("Container {0} selected",cloudBlobContainer.Name);
localCache = RoleEnvironment.GetLocalResource(ConfigurationSettingsKeys.StorageCacheResource);
log.Info("Cache resource retrieved: {0}, path: {1}",localCache.Name,localCache.RootPath);
CloudDrive.InitializeCache(localCache.RootPath, localCache.MaximumSizeInMegabytes);
log.Info("Cache initialized: {0} mb",localCache.MaximumSizeInMegabytes);
var driveName = string.Format("{0}{1}.vhd", selfInstance.InstanceType, selfInstance.InstanceIndex).ToLowerInvariant();
log.Info("Virtual drive name: {0}",driveName);
var pageBlob = cloudBlobContainer.GetPageBlobReference(driveName);
log.Info("Virtual drive blob: {0}",pageBlob.Uri);
cloudDrive = cloudStorageAccount.CreateCloudDrive(pageBlob.Uri.ToString());
log.Info("Virtual drive created: {0}",cloudDrive.Uri);
var storageSize = ConfigurationProvider.GetSetting(ConfigurationSettingsKeys.StorageSize, 50000);
log.Info("Storage size: {0} mb",storageSize);
cloudDrive.CreateIfNotExist(storageSize);
log.Info("Virtual drive initialized: {0}",cloudDrive.Uri);
var mountedDirectoryPath = cloudDrive.Mount(storageSize, DriveMountOptions.None);
log.Info("Virtual drive mounted at: {0}",mountedDirectoryPath);
mountedDirectory = new DirectoryInfo(mountedDirectoryPath);
log.Info("Ensuring drive is available: {0}",mountedDirectoryPath);
UpdateTestFile();
log.Info("Storage initialization succeeded");
}
示例2: OnStart
//.........这里部分代码省略.........
SampleRate = TimeSpan.FromSeconds(10d)
});
cfg.PerformanceCounters.DataSources.Add(new PerformanceCounterConfiguration
{
CounterSpecifier = @"\PhysicalDisk(_Total)\Avg. Disk Queue Length",
SampleRate = TimeSpan.FromSeconds(10d)
});
cfg.PerformanceCounters.ScheduledTransferPeriod = TimeSpan.FromMinutes(1d);
DiagnosticMonitor.Start("Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString", cfg);
#endregion
#if !DEBUG
// Configuration of the firewall
// FirewallManagement.ConfigureFirewall();
#else
Trace.TraceInformation("DEBUG Mode : Firewall not configured !!");
#endif
SetCurrentState(RoutingConfigRoleState.Starting);
#region Path for the storage
//Drive only for S+C role
if (MongoDBAzurePlatform.Instance.MyFunctionnalRoutingRole == MongoDBAzurePlatform.FunctionnalRoutingRole.RoutingAndConfigRole)
{
Trace.TraceInformation("Instance start - Mounting cloud drive for MongoC data");
// Get the local cache for the cloud drive
LocalResource localCache = RoleEnvironment.GetLocalResource("MongocCache");
// we'll use all the cache space we can (note: InitializeCache doesn't work with trailing slash)
CloudDrive.InitializeCache(localCache.RootPath.TrimEnd('\\'), localCache.MaximumSizeInMegabytes);
// connect to the storage account
storageAccount = CloudStorageAccount.FromConfigurationSetting("MongoDbData");
// client for talking to our blob files
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
// the container that our dive is going to live in
CloudBlobContainer drives = blobClient.GetContainerReference(RoleEnvironment.GetConfigurationSettingValue("ContainerName"));
// create blob container (it has to exist before creating the cloud drive)
try { drives.CreateIfNotExist(); }
catch { }
// get the url to the vhd page blob we'll be using
var vhdUrl = drives.GetPageBlobReference(string.Format("mongoc-{0}.vhd", RoleEnvironment.CurrentRoleInstance.Id)).Uri.ToString();
mongoDrive = storageAccount.CreateCloudDrive(vhdUrl);
try
{
mongoDrive.Create(localCache.MaximumSizeInMegabytes);
}
catch (CloudDriveException)
{
// exception is thrown if all is well but the drive already exists
}
dbConfigPath = mongoDrive.Mount(localCache.MaximumSizeInMegabytes, DriveMountOptions.Force) + @"\";
Trace.TraceInformation("Instance start - Cloud drive mounted");
}
#endregion
switch (MongoDBAzurePlatform.Instance.MyFunctionnalRoutingRole)
{
case MongoDBAzurePlatform.FunctionnalRoutingRole.RoutingAndConfigRole:
Trace.TraceInformation(string.Format("Instance Start (S+C) - Registering mongoc and mongos instance as 'stopped', MongoConfig IP is {0}, MongoS IP is {1}", MongoDBAzurePlatform.Instance.MyMongoCAddress.ToString(),MongoDBAzurePlatform.Instance.MyMongoSAddress.ToString()));
break;
case MongoDBAzurePlatform.FunctionnalRoutingRole.RoutingOnlyRole:
Trace.TraceInformation(string.Format("Instance Start (S only) - Registering mongoc and mongos instance as 'stopped', MongoS IP is {0}", MongoDBAzurePlatform.Instance.MyMongoSAddress.ToString()));
break;
default:
Trace.TraceError("On Start : Wrong Functionnal Role : " + (MongoDBAzurePlatform.Instance.MyFunctionnalRoutingRole.ToString()));
break;
}
MongoHelper.RegisterInstanceOrUpdate(MongoHelper.RoutingConfigRoleMongoProcessState.Stopped, "mongoc");
MongoHelper.RegisterInstanceOrUpdate(MongoHelper.RoutingConfigRoleMongoProcessState.Stopped, "mongos");
//Start MongoDB performance counters collection for MongoC process
Trace.TraceInformation("Instance start - Starting custom performance counters");
if (MongoDBAzurePlatform.Instance.MyFunctionnalRoutingRole == MongoDBAzurePlatform.FunctionnalRoutingRole.RoutingAndConfigRole)
MongoDB.PerformanceCounters.PerformanceMonitor.Start(MongoDBAzurePlatform.Instance.MyMongoCAddress.Host, MongoDBAzurePlatform.Instance.MyMongoCAddress.Port, int.Parse(RoleEnvironment.GetConfigurationSettingValue("PerfCountersSamplingIntervalInMs")));
Trace.TraceInformation("Instance start - end of instance start");
switch (MongoDBAzurePlatform.Instance.MyFunctionnalRoutingRole)
{
case MongoDBAzurePlatform.FunctionnalRoutingRole.RoutingAndConfigRole:
SetCurrentState(RoutingConfigRoleState.MongoConfig_NotRunning);
break;
case MongoDBAzurePlatform.FunctionnalRoutingRole.RoutingOnlyRole:
SetCurrentState(RoutingConfigRoleState.MongoShard_NotRunning);
break;
default:
Trace.TraceError("On Start : Wrong Functionnal Role : "+(MongoDBAzurePlatform.Instance.MyFunctionnalRoutingRole.ToString()));
break;
}
return base.OnStart();
}