Imports Microsoft.WindowsAzure
Imports Microsoft.WindowsAzure.StorageClient
Public Class MessageBody
Inherits TableServiceEntity
Public Property Body As String
Public Property CryptographID As Integer
Public Property Subject As String
Public Sub New()
MyBase.New()
End Sub
Public Sub New(ByVal partitionKey As String, ByVal rowKey As String)
MyBase.New(partitionKey, rowKey)
End Sub
Public Sub New(ByVal partitionKey As String, ByVal rowKey As String, ByVal timestamp As Date, ByVal body As String, ByVal cryptographID As String, ByVal subject As String)
MyBase.New(partitionKey, rowKey)
Me.Timestamp = timestamp
Me.Body = body
Me.CryptographID = cryptographID
Me.Subject = subject
End Sub
End Class
Module Module1
Sub Main()
Dim account As CloudStorageAccount = CloudStorageAccount.Parse("DefaultEndpointsProtocol=http;AccountName=your_storage_account_name;AccountKey=your_storage_account_key")
Dim tableClient As CloudTableClient = account.CreateCloudTableClient()
Dim context As TableServiceContext = tableClient.GetDataServiceContext
Console.WriteLine("開始")
Console.ReadLine()
Dim query = From r In context.CreateQuery(Of MessageBody)("MessageBody")
' 表示
For Each row In query
Console.WriteLine(row.RowKey)
Next
' 更新(RowKeyは更新できないかった……)
Console.WriteLine("更新")
Console.ReadLine()
For Each row In query
' 更新
Mid(row.RowKey, 17, 1) = "1"
Console.WriteLine(row.RowKey)
context.UpdateObject(row)
Next
' 削除
Console.WriteLine("削除")
Console.ReadLine()
For Each row In query
If Mid(row.RowKey, 17, 1) = "1" Then
Console.WriteLine(row.RowKey)
context.DeleteObject(row)
End If
Next
context.SaveChanges()
' 追加
Console.WriteLine("追加")
Console.ReadLine()
For Each row In query
Dim newRowKey As String = row.RowKey
Mid(newRowKey, 17, 1) = "1"
Dim newRow As New MessageBody(row.PartitionKey, newRowKey, row.Timestamp, row.Body, row.CryptographID, row.Subject)
Console.WriteLine(newRow.RowKey)
context.AddObject("MessageBody", newRow)
context.SaveChanges()
Next
' まとめてやると、エラーになった
'context.SaveChanges()
Console.WriteLine("終了")
Console.ReadLine()
End Sub
End Module