#region Imported Libraries using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; using System.Windows.Controls; using System.Diagnostics; #endregion #region Namespace Declaration namespace Org.TechA.Wpf.UserControls { #region Internal Supporting Classes /// /// Textwriter class that acts as a decorator /// for the textbox that will accept output from /// the IronPython Runtime IO /// internal sealed class TextBoxWriter : TextWriter { private TextBox _textBox; private delegate void UiSwitcherFromIoRedirects(string value); internal TextBoxWriter(TextBox textBox) { _textBox = textBox; } public override Encoding Encoding { get { return Encoding.Default; } } public override void Write(string value) { _textBox.Dispatcher.BeginInvoke(new UiSwitcherFromIoRedirects(UpdateUiFromDispatcherForWrite), new object[]{value}); } private void UpdateUiFromDispatcherForWrite(string value) { _textBox.AppendText(value.Replace("\n", "")); Debug.WriteLine(value); } private void UpdateUiFromDispatherForWriteline(string value) { Write(value); Write(NewLine); _textBox.ScrollToEnd(); } public override void WriteLine(string value) { _textBox.Dispatcher.BeginInvoke(new UiSwitcherFromIoRedirects(UpdateUiFromDispatherForWriteline), new object[] { value }); } } /// /// The stream to have the IronPython IO /// redirected to. /// internal sealed class TextWriterStream : Stream { #region Private Members private TextWriter Writer; #endregion #region Constructor public TextWriterStream(TextWriter writer) { Writer = writer; } #endregion #region Overriden Methods public override bool CanRead { get { throw new NotImplementedException(); } } public override bool CanSeek { get { throw new NotImplementedException(); } } public override bool CanWrite { get { throw new NotImplementedException(); } } public override void Flush() { throw new NotImplementedException(); } public override long Length { get { throw new NotImplementedException(); } } public override long Position { get { throw new NotImplementedException(); } set { throw new NotImplementedException(); } } public override int Read(byte[] buffer, int offset, int count) { throw new NotImplementedException(); } public override long Seek(long offset, SeekOrigin origin) { throw new NotImplementedException(); } public override void SetLength(long value) { throw new NotImplementedException(); } public override void Write(byte[] buffer, int offset, int count) { Writer.Write(Encoding.Default.GetString(buffer, offset, count)); } #endregion } #endregion } #endregion