今回もいきなりソースを。
MSDN を見てもらうとわかるように、色々とパラメータ指定ができますがとりあえず必須指定となっている開始日時と終了日時の指定を行うようにしています。実際に実行すると次のような履歴が取得できます。1: Imports System.Activities
2: Imports System.IO
3: Imports System.Net
4: Imports System.Security.Cryptography.X509Certificates
5:6: Public Class GetAzureSubscriptionOperationsActivity7: Inherits AsyncCodeActivity
8:9: Public Property SubscriptionID As String10: Public Property CertThumbPrint As String11: Public Property ServiceName As String12:13: Public Property StartDatetime As DateTime14: Public Property EndDatetime As DateTime15:16: Public Property ResultDocument As OutArgument(Of String)17:18: Private Delegate Function AsyncGetWebDataDelegate(ByVal subscription As String,19: ByVal service As String,20: ByVal startFrame As DateTime,21: ByVal endFrame As DateTime,22: ByVal thumbprint As String) As String23:24: Protected Overrides Function BeginExecute(context As System.Activities.AsyncCodeActivityContext, callback As System.AsyncCallback, state As Object) As System.IAsyncResult25: Dim asyncExecute = New AsyncGetWebDataDelegate(AddressOf GetWebData)26: context.UserState = asyncExecute27:28: Return asyncExecute.BeginInvoke(Me.SubscriptionID, Me.ServiceName,29: Me.StartDatetime, Me.EndDatetime,30: Me.CertThumbPrint, callback, state)
31: End Function32:33: Protected Overrides Sub EndExecute(context As System.Activities.AsyncCodeActivityContext, result As System.IAsyncResult)34: Dim asyncExecute = TryCast(context.UserState, AsyncGetWebDataDelegate)35: Dim getResult = asyncExecute.EndInvoke(result)
36:37: context.SetValue(Me.ResultDocument, getResult)
38: End Sub39:40: Private Function GetWebData(ByVal subscription As String, ByVal service As String,41: ByVal startFrame As DateTime, ByVal endFrame As DateTime,42: ByVal thumbprint As String) As String43: Dim resultStrings As String = ""44: Try
45: Dim certStore As X509Store = New X509Store(StoreName.My, StoreLocation.CurrentUser)46: certStore.Open(OpenFlags.ReadOnly)
47:48: Dim certCollection As X509Certificate2Collection = certStore.Certificates.Find(X509FindType.FindByThumbprint, thumbprint, False)49: certStore.Close()50:51: If certCollection.Count <= 0 Then52: Throw New ApplicationException("証明書がありません")53: End If54: Dim certificate As X509Certificate2 = certCollection(0)55:56: Dim st = startFrame.ToUniversalTime.ToString("yyyy-MM-dd") + "T" + startFrame.ToUniversalTime.ToString("HH:mm:ss") + "Z"57: Dim ed = endFrame.ToUniversalTime.ToString("yyyy-MM-dd") + "T" + endFrame.ToUniversalTime.ToString("HH:mm:ss") + "Z"58:59: Dim requestUri As New Uri("https://management.core.windows.net/" _60: + subscription _61: + "/operations?" _
62: + "StartTime=" + st _
63: + "&EndTime=" + ed
64: )65: Dim localWebRequest = TryCast(HttpWebRequest.Create(requestUri), HttpWebRequest)66: localWebRequest.ClientCertificates.Add(certificate)67: localWebRequest.Headers.Add("x-ms-version", "2011-02-25")68:69: Using webResponse = TryCast(localWebRequest.GetResponse(), HttpWebResponse)70: Using responseStream = webResponse.GetResponseStream()
71: Using reader As New StreamReader(responseStream)72: resultStrings = reader.ReadToEnd73: End Using74: End Using75: End Using76:77: Catch ex As Exception78: resultStrings = ex.Message79: End Try80: Return resultStrings
81: End Function82:83: End Class
日時の指定範囲によってはものすごい量の履歴が取得できます。上記で最初に表示されている履歴が、CreateHostedService (ホスティングサービスの新規作成) になっているのがわかると思います。返却される xml のスキーマについても MSDN に記載されていますので、必要に応じて LINQ 等による抽出を行えば、色々と活用できるのではないでしょうか。
0 件のコメント:
コメントを投稿