Windows Phone 8 C# アプリケーション内で Python で記述された Skeinforge スライサー プログラムを実行したいと考えています。これを行うにはおそらく IronPython を使用する必要があると判断しました。IronPython をインストールしたときに取得した ipy.exe ターミナル内で Skeinforge を実行できることは既に判断しています。私の問題は、Windows Phone 8 内で IronPython を使用して Python スクリプトをホストおよび実行する方法を理解するのに苦労していることです。また、アプリケーション コンソールを転送するデスクトップ Windows フォーム アプリケーション内で実行される単純な hello world スクリプトを取得することもできました。次のコードをデバッグ コンソールに出力します。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;
using IronPython.Hosting;
using Microsoft.Scripting.Hosting;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
DebugWriter debugW = new DebugWriter();
Console.SetOut(debugW);
}
private void button1_Click(object sender, EventArgs e)
{
TextWriter tw = new StreamWriter("Test.py");
tw.Write(scriptBox.Text);
tw.Close();
try
{
var ipy = Python.CreateRuntime();
dynamic test = ipy.UseFile("Test.py");
}
catch (Exception ex)
{
Debug.WriteLine("Error: " + ex.Message);
}
}
}
}
これが DebugWriter です。
class DebugWriter : TextWriter
{
private StringBuilder content = new StringBuilder();
public DebugWriter()
{
Debug.WriteLine("Writing console to debug");
}
public override void Write(char value)
{
base.Write(value);
if (value == '\n')
{
Debug.WriteLine(content.ToString());
content = new StringBuilder();
}
else
{
content.Append(value);
}
}
public override Encoding Encoding
{
get { return System.Text.Encoding.UTF8; }
}
}
標準ライブラリはインポートされないため、IronPython ライブラリを Windows Phone 8 アプリケーションに追加する方法さえわかりません。どうやら現在は機能していない Windows Phone 7 ライブラリをマスター ソース コードでコンパイルしようとしましたが、これらのライブラリをインポートできますが、hello world スクリプトを実行しようとすると、デバッグ ターミナルでまったく応答がありません。
Windows Phone 8でこれを実行する方法を知っている人はいますか? Windows 8/Metro/RTでこれを行う方法を知っていれば、おそらくWP8でも機能します.
更新: デバッグ出力をもう一度見たところ、WP7 ライブラリを使用して hello world スクリプトを実行しようとすると、次のエラーが発生するようです。
A first chance exception of type 'System.NotImplementedException' occurred in Microsoft.Scripting.DLL
Error: The method or operation is not implemented.