我正在爲我的應用程序開發備份功能,它應該檢查所需的文件夾是否已經存在,否則創建它。Live SDK:await client.GetAsync(「me/skydrive/files?filter = folders」)不返回
因爲我使用VB.Net我不能使用GetCompleted事件(只有在C#中,我沒有經驗)。
我目前在FolderExistsOrCreate功能代碼是這樣的:
Private Async Function FolderExistsOrCreate(ByVal Name As String) As System.Threading.Tasks.Task(Of String)
Dim ID As String = Nothing
Dim firstRecheck = True
ReCheck:
Try
_message = "Looking for folder..."
NotifyPropertyChanged("Message")
NotifyPropertyChanged("SkyDrive")
_client = New LiveConnectClient(_session)
'it stops here and does not go further
Dim res = Await _client.GetAsync("me/skydrive/files?filter=folders,albums")
Dim folderData As Dictionary(Of String, Object) = DirectCast(res.Result, Dictionary(Of String, Object))
Dim folders As List(Of Object) = DirectCast(folderData("data"), List(Of Object))
For Each item As Object In folders
Dim folder As Dictionary(Of String, Object) = DirectCast(item, Dictionary(Of String, Object))
If folder("name").ToString = Name Then
ID = folder("id").ToString()
_message = "Folder exists..."
NotifyPropertyChanged("Message")
NotifyPropertyChanged("SkyDrive")
End If
Next
If ID = Nothing Then
If firstRecheck = False Then
_message = "Creating folder failed..."
NotifyPropertyChanged("Message")
NotifyPropertyChanged("SkyDrive")
Return Nothing
End If
_message = "Creating folder..."
NotifyPropertyChanged("Message")
NotifyPropertyChanged("SkyDrive")
Dim newFolderData As New Dictionary(Of String, Object)
newFolderData.Add("name", Name)
_client = New LiveConnectClient(_session)
res = Await _client.PostAsync("me/skydrive", newFolderData)
firstRecheck = False
GoTo ReCheck
End If
Return ID
Catch ex As Exception
Return Nothing
End Try
End Function
功能是在包含簽到按鈕,我已經建立了一個控制,我已經加了我的SkyDrive類的屬性設置控制,並且它使用的_session是使用SignIn按鈕創建的會話。
我得到一個有效的客戶端,但是所有的GetAsync函數都會讓應用程序暫停,沒有任何異常。分配的範圍包含「skydrive_update」,因此授予訪問權限來創建文件夾,但代碼甚至沒有達到那麼遠。
我已經在MSDN上搜索過實時SDK論壇和論壇,可以找到任何類型的答案,但我可以找到的所有C#函數都是使用GetCompleted方法。
任何想法?
你能解釋一下爲什麼你不能在VB中使用'GetCompleted'?幾乎總是如果你可以用C#做一些事情,你也可以在VB中做。 – svick
它在VB.Net中不可用,他們在SDK文檔中提到它。文件說這樣做,但它不起作用。 –
呵呵? GetCompleted是一個標準的EventHandler委託。絕對沒有什麼能夠阻止你在VB.NET中訂閱它。任何.NET API都可用於所有.NET語言。只有語言功能不同。 –