メソッドの実装
ShowConfigurationSettingsメソッドに処理を追記します。
引数のpersistXmlについてですが,
<UserName>[ユーザー名]</UserName>
初めてプラグインが実行されたとき,
PostURIを取得するところまで書いてみましょう。コードは次のように書くことができます。
' XDocument へ変換
Dim persist As XDocument
Try
If persistXml.InnerXml <> "" Then
persist = XDocument.Parse(persistXml.InnerXml)
Else
persist = New XDocument
End If
Catch xmlEx As Xml.XmlException
persist = New XDocument
End Try
Dim userName As String
Dim password As String
' ConfigureForm 表示
Dim result As DialogResult
Using frm = New ConfigureForm(persist.<UserName>.Value) ' <UserName>要素を指定
result = frm.ShowDialog(parentWindow)
If result = Windows.Forms.DialogResult.OK Then
' 投稿ボタンをクリックした場合
userName = frm.UserName
password = frm.Password
Else
' キャンセルボタンをクリックした場合
Return False
End If
End Using
' PostURI 取得
Dim title As String = Nothing
Dim postUri As String
Try
postUri = GetPostUri(userName, password, title)
Catch webEx As WebException
MessageBox.Show(webEx.Message, "Error")
Return False
End Try
次は,
<PhotoGalleryPublishSession>
<PublishParameters>
<PostUri>[PostURI]</PostUri>
<UserName>[ユーザー名]</UserName>
<Password>[パスワード]</Password>
</PublishParameters>
</PhotoGalleryPublishSession>
コードは次のようになります。コードの最後では,
' Session XML にユーザー情報とPostURI 保存
Dim session = XDocument.Parse(sessionXml.InnerXml)
With session.<PhotoGalleryPublishSession>.<PublishParameters>.First
.Add(<PostUri><%= postUri %></PostUri>)
.Add(<UserName><%= userName %></UserName>)
.Add(<Password><%= password %></Password>)
End With
' XmlDocument へ反映
persistXml.LoadXml(<UserName><%= userName %></UserName>.ToString)
sessionXml.LoadXml(session.ToString)
Return True
上記のコードでは引数のXmlDocumentオブジェクトからXDocumentオブジェクトへ変換してVisual BasicのXMLリテラルを使用してXMLの操作をしています。編集内容を反映させるため最後にXmlDocumentオブジェクトへ戻しています。
Session XMLとPersist XML
既に設定ウィンドウ表示処理に出てきたようにLiveアプリケーションとプラグインとのやり取りにはXLM文書
Session XML
Session XMLはユーザーが選択した動画像の情報を参照するためと,
Session XMLの例を以下に示します。
<PhotoGalleryPublishSession versionMajor="1" versionMinor="0">
<PublishParameters>
<MaxWidth>1024</MaxWidth>
<MaxHeight>1024</MaxHeight>
</PublishParameters>
<ItemSet>
<Item id="19">
<FullFilePath>C:\Users\UserName\Pictures\background.jpg</FullFilePath>
<OriginalFileName>background.jpg</OriginalFileName>
<OriginalFileExtension>.jpg</OriginalFileExtension>
<PerceivedType>image</PerceivedType>
<Title></Title>
<OriginalWidth>2560</OriginalWidth>
<OriginalHeight>1920</OriginalHeight>
<LengthMS>0</LengthMS>
<FileSize>1620000</FileSize>
<KeywordSet>
<Keyword>meatball</Keyword>
<Keyword>double tooth</Keyword>
</KeywordSet>
<PeopleRegionSet>
<PersonRegion left="0.6" top="0.1" width="0.1" height="0.2">M.K</PersonRegion>
</PeopleRegionSet>
</Item>
<Item id="20">
...
</Item>
<Item id="21">
...
</Item>
</ItemSet>
</PhotoGalleryPublishSession>
<ItemSet>要素内に選択された動画像の数だけ<Item>要素があり,
プラグインが使用するセッション中の情報は,