/* Copyright (C) Elisy.Net 2008 http://code.elisy.net This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ using System; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Ink; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; using System.Windows.Browser; namespace Elisy.Scab.Services { public class TraceModule : Module { public override void Initialize(WorkItem workItem) { if (!workItem.IsRegistered(typeof(Trace), null)) workItem.RegisterType(typeof(Trace), typeof(Trace), null); } } public class Trace { public Trace() { IndentLevel = 0; } /// /// Id of the element on the Html page /// public string DestinationId { get; set; } private HtmlElement _destination; public HtmlElement Destination { get { if(string.IsNullOrEmpty(DestinationId)) DestinationId = "guid_" + Guid.NewGuid().ToString().Replace("-", "_"); else _destination = HtmlPage.Document.GetElementById(DestinationId); if (_destination == null) { _destination = HtmlPage.Document.CreateElement("div"); _destination.SetProperty("id", DestinationId); HtmlPage.Document.Body.AppendChild(_destination); } return _destination; } set { _destination = value; DestinationId = _destination.GetProperty("id").ToString(); } } /// /// Gets or sets the indent level. /// public int IndentLevel { get; set; } /// /// Writes a message to the trace destination /// /// public void Write(string message) { string innerHtml = Destination.GetProperty("innerHTML").ToString(); Destination.SetProperty("innerHTML", innerHtml + GetSeparator() + message); } private string GetSeparator() { string value = ""; for (int i=0; i /// Writes a html fragment to the trace destination /// /// public void WriteHtml(string html) { string innerHtml = Destination.GetProperty("innerHTML").ToString(); Destination.SetProperty("innerHTML", innerHtml + html); } /// /// Writes a message to the trace destination /// /// public void WriteLine(string message) { string innerHtml = Destination.GetProperty("innerHTML").ToString(); Destination.SetProperty("innerHTML", innerHtml + GetSeparator() + message + "
"); } } }