CommandManager.InvalidateRequerySuggested();
を実行して、RequerySuggestedイベントを強制的に発生させてCanExecuteが実行されるようにできる。
UIスレッドと別スレッドから呼び出すときはDispatcher.Invoke()やDispatcher.BeginInvokeのデリゲートから呼び出す。
CommandManager.InvalidateRequerySuggested();
を実行して、RequerySuggestedイベントを強制的に発生させてCanExecuteが実行されるようにできる。
UIスレッドと別スレッドから呼び出すときはDispatcher.Invoke()やDispatcher.BeginInvokeのデリゲートから呼び出す。
WebRequest クラスの最大同時接続数のデフォルト値は2のため、
複数のサイトに動じアクセスする場合は変更する必要がある。
変更するには
System.Net.ServicePointManager.DefaultConnectionLimit
プロパティに設定を行えばよい。
下記のように外部スクリプトとして追加することで実行できるようになった。
var webBrowser = new WebBrowser();
HtmlElement scriptElem= webBrowser.Document.CreateElement(“Script”);
scriptElem.SetAttribute(“type”, “text/javascript”);
scriptElem.SetAttribute(“src”, http://localhost/script.js);
<Script>タグ内へinnerHtml, innerTextを使ってコードを追加できなかった。また、srcの参照先を”file:///“で始まるものにすると、実行時にエラーとなる。javascriptの関数を実行するには
object obj = webBrowser.Document.InvokeScript(“functionname”);
と記述する。第2パラメータにobjectの配列を渡すことで引数を指定することが可能。
WPFでWindows FormのApplication.DoEventsメソッドと同様に長時間かかる処理の間にUIのイベントを処理させるには、下記のように行う。(MSDNより)
[SecurityPermissionAttribute(SecurityAction.Demand, Flags = SecurityPermissionFlag.UnmanagedCode)]
public void DoEvents()
{
DispatcherFrame frame = new DispatcherFrame();
Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background,
new DispatcherOperationCallback(ExitFrame), frame);
Dispatcher.PushFrame(frame);
}public object ExitFrame(object f)
{
((DispatcherFrame)f).Continue = false;return null;
}
Xml-Rpc With WCFから「XML-RPC for WCF」をダウンロード。
上記blogのコメントに従ってXmlRpcDataContractSerializationHelperクラスのDeserializeStructメソッドのループ
while (reader.NodeType != XmlNodeType.EndElement)
{
}
の最後に、下記を追加。(ホワイトスペースと改行(XmlNodeType.Text)をスキップするため)
while (reader.NodeType == XmlNodeType.Whitespace || reader.NodeType == XmlNodeType.Text)
{
reader.Skip();
}
また、Desirializeメソッドでswitch (reader.LocalName)の case XmlRpcProtocol.DateTime:の日付の形式が、dateTime.iso8601の形式(下記例参照)でなかったため修正。
<dateTime.iso8601>19980717T14:08:55</dateTime.iso8601>
また、Desirializeメソッドで<value>の内側に型のタグがない場合stringにする処理がなかったため、メソッドの一番最後に
else if (reader.NodeType == XmlNodeType.Text)
{
returnValue = reader.ReadString();
}
を追加した。このモジュールの使う手順は下記。
<system.serviceModel>
<extensions>
<behaviorExtensions>
<add name=”xmlRpcEndpointBehavior”
type=”Microsoft.Samples.XmlRpc.XmlRpcEndpointBehaviorSection, Microsoft.Samples.XmlRpc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null” />
</behaviorExtensions>
</extensions>
<services>
<service behaviorConfiguration=”debugBehavior” name=”実装したクラス名”>
<host>
</host>
<endpoint address=”" behaviorConfiguration=”xmlRpcBehavior” binding=”webHttpBinding”
contract=”定義したインタフェース名” />
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name=”xmlRpcBehavior”>
<xmlRpcEndpointBehavior />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name=”debugBehavior”>
<serviceMetadata httpGetEnabled=”true” />
<serviceDebug includeExceptionDetailInFaults=”true” />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled=”true” />
</system.serviceModel>
<script src=”Scripts/MicrosoftAjax.js” type=”text/javascript></script>
<script src=”Scripts/MicrosoftMvcValidation.js” type=”text/javascript></script><% Html.EnableClientValidation(); %>
[[MetadataType(typeof(PersonMetadata))]
public partial class Person
{
}
[Bind(Exclude="ID")]
public class PersonMetadata
{
[Required(ErrorMessage = "名前を入力してください。")]
public string Name { get; set; }
}
ValidationAttributeクラスを継承したクラスを作ることによって、独自の検証属性を作ることも可能。
public ActionResult View(int id, [DefaultValue(1)]int page) {
}
のような使い方が可能。
参考サイト
http://www.asp.net/learn/whitepapers/what-is-new-in-aspnet-mvc/
http://www.atmarkit.co.jp/fdotnet/scottgublog/20100113aspnetmvc2/aspnetmvc2.html
IronPythonのインストールディレクトリにあるIronPython.dll, Microsoft.Scripting.dll, Microsoft.Scripting.Core.dll, Nicrosoft.Dynamic.dllに参照を通す。
下記のソースコードのような方法でC#のコードからPythonのスクリプトの実行と変数の値のやりとりが可能。
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Scripting.Hosting;
using IronPython.Hosting;public class Class1
{
public IronPython.Runtime.List Val1;
public IronPython.Runtime.List Val2;
}
class Program
{
static void Main(string[] args)
{
ScriptEngine engine = Python.CreateEngine();
ScriptSource source = engine.CreateScriptSourceFromString(
@”print obj1.Val1
result = obj1.Val2″);
ScriptScope scope = engine.CreateScope();
var obj1 = new Class1()
{
Val1 = new IronPython.Runtime.List { 1, “abc” },
Val2 = new IronPython.Runtime.List { 2, “def”}
};
scope.SetVariable(“obj1″, obj1);
source.Execute(scope);
object[] result = scope.GetVariable<IronPython.Runtime.List>(“result”).ToArray();
Console.WriteLine(“{0},{1}”, result[0], result[1]);
}}