# HG changeset patch # User Steven Hollidge # Date 1335204952 -3600 # Node ID d06c852e01670fde918b75ac2226ed73fe5761cf # Parent 177a9d1eba104f065dbed32b384a09d865ca130f looking good! diff -r 177a9d1eba10 -r d06c852e0167 SilverlightGlimpse/SilverlightGlimpse/Controls/FloatableWindow/FloatableWindow.cs --- a/SilverlightGlimpse/SilverlightGlimpse/Controls/FloatableWindow/FloatableWindow.cs Mon Apr 23 17:57:21 2012 +0100 +++ b/SilverlightGlimpse/SilverlightGlimpse/Controls/FloatableWindow/FloatableWindow.cs Mon Apr 23 19:15:52 2012 +0100 @@ -634,7 +634,7 @@ z++; Canvas.SetZIndex(this, z); #if DEBUG - this.Title = z.ToString(); + //this.Title = z.ToString(); #endif } diff -r 177a9d1eba10 -r d06c852e0167 SilverlightGlimpse/SilverlightGlimpse/Diagnostics/Stopwatch.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SilverlightGlimpse/SilverlightGlimpse/Diagnostics/Stopwatch.cs Mon Apr 23 19:15:52 2012 +0100 @@ -0,0 +1,29 @@ +using System; + +namespace SilverlightGlimpse.Diagnostics +{ + public class Stopwatch + { + private long _start; + private long _end; + + public void Start() + { + _start = DateTime.Now.Ticks; + } + + public void Stop() + { + _end = DateTime.Now.Ticks; + } + + public TimeSpan ElapsedTime { get { return new TimeSpan(_end - _start); }} + + public static Stopwatch StartNew() + { + var stopwatch = new Stopwatch(); + stopwatch.Start(); + return stopwatch; + } + } +} \ No newline at end of file diff -r 177a9d1eba10 -r d06c852e0167 SilverlightGlimpse/SilverlightGlimpse/Interfaces/IBrokenBindingsService.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SilverlightGlimpse/SilverlightGlimpse/Interfaces/IBrokenBindingsService.cs Mon Apr 23 19:15:52 2012 +0100 @@ -0,0 +1,11 @@ +using System.Collections.Generic; +using System.Windows; +using SilverlightGlimpse.Models; + +namespace SilverlightGlimpse.Interfaces +{ + public interface IBrokenBindingsService + { + void LoadBrokenBindings(UIElement uiElement, IList bindingErrors); + } +} \ No newline at end of file diff -r 177a9d1eba10 -r d06c852e0167 SilverlightGlimpse/SilverlightGlimpse/Interfaces/ILogWriter.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SilverlightGlimpse/SilverlightGlimpse/Interfaces/ILogWriter.cs Mon Apr 23 19:15:52 2012 +0100 @@ -0,0 +1,9 @@ +using System.Collections; + +namespace SilverlightGlimpse.Interfaces +{ + public interface ILogWriter + { + void Write(IList log, int maxLogItems, string text, params object[] args); + } +} \ No newline at end of file diff -r 177a9d1eba10 -r d06c852e0167 SilverlightGlimpse/SilverlightGlimpse/Models/BindingError.cs --- a/SilverlightGlimpse/SilverlightGlimpse/Models/BindingError.cs Mon Apr 23 17:57:21 2012 +0100 +++ b/SilverlightGlimpse/SilverlightGlimpse/Models/BindingError.cs Mon Apr 23 19:15:52 2012 +0100 @@ -13,7 +13,7 @@ public BindingError(string controlName, string controlTypeName, string propertyName, string path) { _controlName = controlName; - ControlTypeName = controlTypeName; + ControlType = controlTypeName; PropertyName = propertyName; Path = path; } @@ -23,7 +23,7 @@ #region Properties public string ControlName { get { return string.IsNullOrEmpty(_controlName) ? "(none)" : _controlName; } } - public string ControlTypeName { get; private set; } + public string ControlType { get; private set; } public string Path { get; private set; } public string PropertyName { get; private set; } public string ToStringProperty { get { return ToString(); } } @@ -37,7 +37,7 @@ return string.Format( "Control Name: {0}, Type: {1}, Property: {2}, Path: {3}", ControlName, - ControlTypeName, + ControlType, PropertyName, Path); } diff -r 177a9d1eba10 -r d06c852e0167 SilverlightGlimpse/SilverlightGlimpse/Models/ValidationWrapper.cs --- a/SilverlightGlimpse/SilverlightGlimpse/Models/ValidationWrapper.cs Mon Apr 23 17:57:21 2012 +0100 +++ b/SilverlightGlimpse/SilverlightGlimpse/Models/ValidationWrapper.cs Mon Apr 23 19:15:52 2012 +0100 @@ -9,11 +9,13 @@ public ValidationWrapper( ValidationErrorEventAction enumAction, string controlName, + string controlType, string errorContent) { Action = enumAction; ControlName = controlName; - Message = errorContent; + ControlType = controlType; + ErrorContent = errorContent; } #endregion @@ -22,7 +24,9 @@ public ValidationErrorEventAction Action { get; private set; } public string ControlName { get; private set; } - public string Message { get; private set; } + public string ControlType { get; private set; } + public string ErrorContent { get; private set; } + public string ToStringProperty { get { return ToString(); } } #endregion @@ -30,9 +34,15 @@ public override string ToString() { - return string.Format("({0}) - {1}", Action, Message); + return string.Format( + "Validation Action: {0}, Name: {1} Type: {2}, ErrorContent: {3}", + Action, + ControlName, + ControlType, + ErrorContent); } + #endregion } } \ No newline at end of file diff -r 177a9d1eba10 -r d06c852e0167 SilverlightGlimpse/SilverlightGlimpse/Services/BrokenBindingsService.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SilverlightGlimpse/SilverlightGlimpse/Services/BrokenBindingsService.cs Mon Apr 23 19:15:52 2012 +0100 @@ -0,0 +1,75 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Reflection; +using System.Windows; +using System.Windows.Media; +using SilverlightGlimpse.Interfaces; +using SilverlightGlimpse.Models; + +namespace SilverlightGlimpse.Services +{ + public class BrokenBindingsService : IBrokenBindingsService + { + public void LoadBrokenBindings(UIElement uiElement, IList bindingErrors) + { + var frameworkElement = uiElement as FrameworkElement; + if (frameworkElement == null) return; + + foreach (var fieldInfo in frameworkElement.GetType().GetFields(BindingFlags.Public | BindingFlags.FlattenHierarchy | BindingFlags.Instance | BindingFlags.Static)) + { + if (!ReferenceEquals(fieldInfo.FieldType, typeof(DependencyProperty))) continue; + + var bindingExpression = frameworkElement.GetBindingExpression((DependencyProperty)fieldInfo.GetValue(null)); + + if (bindingExpression == null || bindingExpression.ParentBinding.Source != null || + bindingExpression.ParentBinding.RelativeSource != null) continue; + + var isInherited = false; + + if (frameworkElement.DataContext != null && !string.IsNullOrEmpty(bindingExpression.ParentBinding.Path.Path)) + { + foreach (var propertyInfo in frameworkElement.DataContext.GetType().GetProperties(BindingFlags.Public | BindingFlags.FlattenHierarchy | BindingFlags.Static | BindingFlags.Instance)) + { + if (String.CompareOrdinal(propertyInfo.Name, bindingExpression.ParentBinding.Path.Path) != 0) continue; + isInherited = true; + break; + } + } + + if (isInherited) break; + + //this code handles empty bindings on the Button controls + // unsure as to why the Button has an empty or unresolved binding of textblock type... + if ((frameworkElement.Name == "") + && (frameworkElement.GetType().Name == "TextBlock") + && (fieldInfo.Name == "TextProperty") + && (bindingExpression.ParentBinding.Path.Path == "")) + { + continue; + } + + var brokenBinding = new BindingError( + frameworkElement.Name, + frameworkElement.GetType().Name, + fieldInfo.Name, + bindingExpression.ParentBinding.Path.Path); + + bindingErrors.Add(brokenBinding); + Debug.WriteLine("Broken Binding: {0}", brokenBinding); + } + + int children = VisualTreeHelper.GetChildrenCount(frameworkElement); + + for (int j = 0; j <= children - 1; j++) + { + var child = VisualTreeHelper.GetChild(frameworkElement, j) as FrameworkElement; + + if (child != null) + { + LoadBrokenBindings(child, bindingErrors); + } + } + } + } +} diff -r 177a9d1eba10 -r d06c852e0167 SilverlightGlimpse/SilverlightGlimpse/Services/Glimpse.cs --- a/SilverlightGlimpse/SilverlightGlimpse/Services/Glimpse.cs Mon Apr 23 17:57:21 2012 +0100 +++ b/SilverlightGlimpse/SilverlightGlimpse/Services/Glimpse.cs Mon Apr 23 19:15:52 2012 +0100 @@ -1,10 +1,11 @@ using System; using System.Collections.ObjectModel; using System.Diagnostics; -using System.Reflection; using System.Windows; using System.Windows.Controls; using System.Windows.Threading; +using SilverlightGlimpse.Diagnostics; +using SilverlightGlimpse.Interfaces; using SilverlightGlimpse.Views; using SilverlightGlimpse.Models; using System.Windows.Media; @@ -19,24 +20,27 @@ private DispatcherTimer _refreshBindingCountTimer; private static readonly TimeSpan FiveSeconds = new TimeSpan(0, 0, 0, 5); private const int MAX_LOG_ITEMS = 5; - + private readonly ILogWriter _logWriter; + private readonly IBrokenBindingsService _brokenBindingsService; #endregion #region Private constructor - private Glimpse() + private Glimpse(ILogWriter logWriter, IBrokenBindingsService brokenBindingsService) { BindingErrors = new ObservableCollection(); ValidationErrors = new ObservableCollection(); Exceptions = new ObservableCollection(); Log = new ObservableCollection(); + _logWriter = logWriter; + _brokenBindingsService = brokenBindingsService; } #endregion #region Properties - public static Glimpse Service { get { return _instance ?? (_instance = new Glimpse()); } } + public static Glimpse Service { get { return _instance ?? (_instance = new Glimpse(new LogWriter(), new BrokenBindingsService())); } } internal Application App { get; private set; } internal FloatableWindow GlimpseWindow { get; set;} internal string Title { get; set; } @@ -60,13 +64,6 @@ #endregion - private void WriteToLog(string text, params object[] args) - { - var date = DateTime.Now.ToString("HH:mm:ss.ffff"); - Log.Add(string.Concat(date, "\t", string.Format(text, args))); - if (Log.Count > MAX_LOG_ITEMS) Log.RemoveAt(0); - } - #region UI Creation and Loading public void DisplayLoadFailure(Application app, Exception ex, string title) @@ -100,7 +97,7 @@ if (Double.IsNaN(RootVisual.Width)) { //if the host control is autosized (consumes the browser window) then locate Glimpse in the top, left - GlimpseWindow.Show(5,5); + GlimpseWindow.Show(); } else { @@ -113,7 +110,7 @@ GlimpseWindow.Show(dblLeft, 10); } - LoadBrokenBindings(RootVisual); + _brokenBindingsService.LoadBrokenBindings(RootVisual, BindingErrors); _refreshBindingCountTimer = new DispatcherTimer(); _refreshBindingCountTimer.Tick += RefreshBindingCountTimer_Tick; @@ -123,71 +120,6 @@ #endregion - #region Update broken bindings collection - - private void LoadBrokenBindings(UIElement uiElement) - { - var frameworkElement = uiElement as FrameworkElement; - if (frameworkElement == null) return; - - foreach (var fieldInfo in frameworkElement.GetType().GetFields(BindingFlags.Public | BindingFlags.FlattenHierarchy | BindingFlags.Instance | BindingFlags.Static)) - { - if (!ReferenceEquals(fieldInfo.FieldType, typeof(DependencyProperty))) continue; - - var bindingExpression = frameworkElement.GetBindingExpression((DependencyProperty)fieldInfo.GetValue(null)); - - if (bindingExpression == null || bindingExpression.ParentBinding.Source != null || - bindingExpression.ParentBinding.RelativeSource != null) continue; - - var isInherited = false; - - if (frameworkElement.DataContext != null && !string.IsNullOrEmpty(bindingExpression.ParentBinding.Path.Path)) - { - foreach (var propertyInfo in frameworkElement.DataContext.GetType().GetProperties(BindingFlags.Public | BindingFlags.FlattenHierarchy | BindingFlags.Static | BindingFlags.Instance)) - { - if (String.CompareOrdinal(propertyInfo.Name, bindingExpression.ParentBinding.Path.Path) != 0) continue; - isInherited = true; - break; - } - } - - if (isInherited) break; - - //this code handles empty bindings on the Button controls - // unsure as to why the Button has an empty or unresolved binding of textblock type... - if ((frameworkElement.Name == "") - && (frameworkElement.GetType().Name == "TextBlock") - && (fieldInfo.Name == "TextProperty") - && (bindingExpression.ParentBinding.Path.Path == "")) - { - continue; - } - - var brokenBinding = new BindingError( - frameworkElement.Name, - frameworkElement.GetType().Name, - fieldInfo.Name, - bindingExpression.ParentBinding.Path.Path); - - BindingErrors.Add(brokenBinding); - Debug.WriteLine("Broken Binding: {0}", brokenBinding); - } - - int children = VisualTreeHelper.GetChildrenCount(frameworkElement); - - for (int j = 0; j <= children - 1; j++) - { - var child = VisualTreeHelper.GetChild(frameworkElement, j) as FrameworkElement; - - if (child != null) - { - LoadBrokenBindings(child); - } - } - } - - #endregion - #region Events handlers // Bindings @@ -198,10 +130,10 @@ _refreshBindingCountTimer.Stop(); BindingErrors.Clear(); - LoadBrokenBindings(RootVisual); + _brokenBindingsService.LoadBrokenBindings(RootVisual, BindingErrors); stopwatch.Stop(); - WriteToLog("Refreshing the binding error count took {0} {1}", stopwatch.ElapsedTime.Milliseconds, "ms"); + _logWriter.Write(Log, MAX_LOG_ITEMS, "Refreshing the binding errors took {0} {1}", stopwatch.ElapsedTime.Milliseconds, "ms"); _refreshBindingCountTimer.Start(); } @@ -220,6 +152,7 @@ ValidationErrors.Add( new ValidationWrapper( e.Action, + e.OriginalSource.GetType().ToString(), controlName, e.Error.ErrorContent.ToString())); } diff -r 177a9d1eba10 -r d06c852e0167 SilverlightGlimpse/SilverlightGlimpse/Services/LogWriter.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SilverlightGlimpse/SilverlightGlimpse/Services/LogWriter.cs Mon Apr 23 19:15:52 2012 +0100 @@ -0,0 +1,16 @@ +using System; +using System.Collections; +using SilverlightGlimpse.Interfaces; + +namespace SilverlightGlimpse.Services +{ + public class LogWriter : ILogWriter + { + public void Write(IList log, int maxLogItems, string text, params object[] args) + { + var date = DateTime.Now.ToString("HH:mm:ss.ffff"); + log.Add(string.Concat(date, "\t", string.Format(text, args))); + if (log.Count > maxLogItems) log.RemoveAt(0); + } + } +} diff -r 177a9d1eba10 -r d06c852e0167 SilverlightGlimpse/SilverlightGlimpse/Services/Stopwatch.cs --- a/SilverlightGlimpse/SilverlightGlimpse/Services/Stopwatch.cs Mon Apr 23 17:57:21 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,29 +0,0 @@ -using System; - -namespace SilverlightGlimpse.Services -{ - public class Stopwatch - { - private long _start; - private long _end; - - public void Start() - { - _start = DateTime.Now.Ticks; - } - - public void Stop() - { - _end = DateTime.Now.Ticks; - } - - public TimeSpan ElapsedTime { get { return new TimeSpan(_end - _start); }} - - public static Stopwatch StartNew() - { - var stopwatch = new Stopwatch(); - stopwatch.Start(); - return stopwatch; - } - } -} \ No newline at end of file diff -r 177a9d1eba10 -r d06c852e0167 SilverlightGlimpse/SilverlightGlimpse/SilverlightGlimpse.csproj --- a/SilverlightGlimpse/SilverlightGlimpse/SilverlightGlimpse.csproj Mon Apr 23 17:57:21 2012 +0100 +++ b/SilverlightGlimpse/SilverlightGlimpse/SilverlightGlimpse.csproj Mon Apr 23 19:15:52 2012 +0100 @@ -70,9 +70,16 @@ + + + + BindingsViewer.xaml + + ValidationsViewer.xaml + GlimpseViewer.xaml @@ -93,13 +100,17 @@ - + Designer MSBuild:Compile + + MSBuild:Compile + Designer + Designer MSBuild:Compile diff -r 177a9d1eba10 -r d06c852e0167 SilverlightGlimpse/SilverlightGlimpse/Views/BindingsViewer.xaml --- a/SilverlightGlimpse/SilverlightGlimpse/Views/BindingsViewer.xaml Mon Apr 23 17:57:21 2012 +0100 +++ b/SilverlightGlimpse/SilverlightGlimpse/Views/BindingsViewer.xaml Mon Apr 23 19:15:52 2012 +0100 @@ -10,8 +10,8 @@ - @@ -23,10 +23,10 @@ - + - + diff -r 177a9d1eba10 -r d06c852e0167 SilverlightGlimpse/SilverlightGlimpse/Views/ExceptionsViewer.xaml --- a/SilverlightGlimpse/SilverlightGlimpse/Views/ExceptionsViewer.xaml Mon Apr 23 17:57:21 2012 +0100 +++ b/SilverlightGlimpse/SilverlightGlimpse/Views/ExceptionsViewer.xaml Mon Apr 23 19:15:52 2012 +0100 @@ -2,96 +2,6 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> - - - - - - - - - - - - - - - - - - -