我想以编程方式管理我的Azure云服务.
我知道REST API,但我想知道它是否是可用的本机C#API,就像Azure存储一样.
REST API - 托管服务上的操作:http://msdn.microsoft.com/en-us/library/windowsazure/ee460812.aspx
或者我是否需要自己包装REST API,如下面的帖子所述?
Azure - 无法以编程方式执行VIP交换:Azure - 无法以编程方式执行VIP交换
谢谢.
编辑:
CSManage的建议对我帮助很大.
您可以重用ServiceManagement项目并编写自己的客户端(而不是CSManage).
使用ServiceManagementHelper设置通道以执行命令.
例:
public static string SubscriptionId { get; set; }
public static string CertificateThumbprint { get; set; }
public static X509Certificate2 Certificate { get; set; }
private void button1_Click(object sender, EventArgs e)
{
SubscriptionId = ConfigurationManager.AppSettings["SubscriptionId"];
CertificateThumbprint = ConfigurationManager.AppSettings["CertificateThumbprint"];
X509Store certificateStore = new X509Store(StoreName.My, StoreLocation.CurrentUser);
certificateStore.Open(OpenFlags.ReadOnly);
X509Certificate2Collection certs = certificateStore.Certificates.Find(X509FindType.FindByThumbprint, CertificateThumbprint, false);
if (certs.Count != 1)
{
MessageBox.Show("Client …Run Code Online (Sandbox Code Playgroud) 我需要从zipfile解压缩一个特定的目录.
例如,从zipfile'c:\ tmp\test.zip'中提取目录'test\etc\script',并将其放在c:\ tmp\output\test\etc\script中.
下面的代码有效,但有两个怪癖:
我需要递归地找到zip文件(函数finditem)中的目录('script'),虽然我已经知道了路径('c:\ tmp\test.zip\test\etc\script')
使用CopyHere我需要手动确定目标目录,特别是'test\etc'部分
更好的解决方案?谢谢.
代码:
function finditem($items, $itemname)
{
foreach($item In $items)
{
if ($item.GetFolder -ne $Null)
{
finditem $item.GetFolder.items() $itemname
}
if ($item.name -Like $itemname)
{
return $item
}
}
}
$source = 'c:\tmp\test.zip'
$target = 'c:\tmp\output'
$shell = new-object -com shell.application
# find script folder e.g. c:\tmp\test.zip\test\etc\script
$item = finditem $shell.NameSpace($source).Items() "script"
# output folder is c:\tmp\output\test\etc
$targetfolder = Join-Path $target ((split-path $item.path -Parent) -replace '^.*zip')
New-Item $targetfolder -ItemType directory -ErrorAction Ignore
# …Run Code Online (Sandbox Code Playgroud) 通过执行位于文件夹中的查询列表来更新数据库.
我需要能够检测到任何错误,这些错误也会导致SQL Server Management Studio中的"Query completed with errors".
以下工作检测"无效对象"错误:
PS SQLSERVER:\> $ErrorActionPreference
Stop
PS SQLSERVER:\> $Error.Clear()
PS SQLSERVER:\> $Error
PS SQLSERVER:\> Invoke-Sqlcmd -ServerInstance .\SQLEXPRESS -Database Test -Query "select * from doesnotexist" -ErrorAction SilentlyContinue
PS SQLSERVER:\> $Error.Exception
Invalid object name 'doesnotexist'.
PS SQLSERVER:\>
Run Code Online (Sandbox Code Playgroud)
做同样的选择1/0并没有工作:
PS SQLSERVER:\> $ErrorActionPreference
Stop
PS SQLSERVER:\> $Error.Clear()
PS SQLSERVER:\> $Error
PS SQLSERVER:\> Invoke-Sqlcmd -ServerInstance .\SQLEXPRESS -Database Test -Query "select 1/0" -ErrorAction SilentlyContinue
PS SQLSERVER:\> $Error.Exception
PS SQLSERVER:\>
Run Code Online (Sandbox Code Playgroud)
我希望这会导致像SSMS中的"遇到零除错误"错误.
没有检测到这个特定的错误让我想知道其他错误是否仍然未被发现.
知道为什么会发生这种情况以及如何确保检测到所有 …
我很高兴找到New-AzureStorageTable cmdlet,但我还没想出如何在表中插入新行.
我在互联网上找到了以下代码,但CloudTable.Execute似乎失败了.
它需要三个参数,如http://msdn.microsoft.com/en-us/library/microsoft.windowsazure.storage.table.cloudtable.execute(v=azure.10).aspx中所述,但我无法弄清楚如何调用方法.
任何想法都表示赞赏!
function InsertRow($table, [String]$partitionKey, [String]$rowKey, [int]$intValue)
{
$entity = New-Object "Microsoft.WindowsAzure.Storage.Table.DynamicTableEntity" $partitionKey, $rowKey
$entity.Properties.Add("IntValue", $intValue)
$result = $table.CloudTable.Execute([Microsoft.WindowsAzure.Storage.Table.TableOperation]::Insert($entity))
}
$StorageAccountName = "MyAccountName"
$StorageAccountKey = "MyAccountKey"
$context = New-AzureStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $StorageAccountKey
$table = New-AzureStorageTable test -Context $context
for ($p = 1; $p -le 10; $p++)
{
for ($r = 1; $r -le 10; $r++)
{
InsertRow $table "P$p" "R$r" $r
}
}
Run Code Online (Sandbox Code Playgroud)
UPDATE
如下所示,您必须使用Get-AzureStorageTable来检查表是否已经存在.
$tablename = "test"
$table = Get-AzureStorageTable $tablename -Context $context …Run Code Online (Sandbox Code Playgroud)