PageRenderTime 97ms CodeModel.GetById 7ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/src/net40/Radical.Windows.Presentation/Regions/___ActiveContentChangedMonitor.cs

#
C# | 211 lines | 0 code | 26 blank | 185 comment | 0 complexity | c66eddd7db7c0e377e42635540d67d7d MD5 | raw file
  1. //using System;
  2. //using System.Linq;
  3. //using System.Collections.Generic;
  4. //using Topics.Radical.Validation;
  5. //using Topics.Radical.Conversions;
  6. //using Topics.Toolkits.Ran.ComponentModel.Presentation;
  7. //using Topics.Radical.Observers;
  8. //namespace Topics.Toolkits.Ran.Windows.Presentation.Regions
  9. //{
  10. // /// <summary>
  11. // /// A concrete implementation of the <see cref="IActiveContentChangedMonitor"/> interface.
  12. // /// </summary>
  13. // public sealed class ActiveContentChangedMonitor : IActiveContentChangedMonitor
  14. // {
  15. // sealed class Monitorer : AbstractMonitor<ISwitchingElementsRegion>,
  16. // IRegionMonitor,
  17. // IDisposable
  18. // {
  19. // readonly EventHandler<ActiveContentChangedEventArgs> h;
  20. // readonly ISwitchingElementsRegion region;
  21. // //IView previousContent;
  22. // /// <summary>
  23. // /// Initializes a new instance of the <see cref="Monitorer"/> class.
  24. // /// </summary>
  25. // /// <param name="region">The region.</param>
  26. // /// <param name="onActiveContentChangedUserCallback">The on active content changed user callback.</param>
  27. // /// <param name="iMonitorCallback">The i monitor callback.</param>
  28. // public Monitorer( ISwitchingElementsRegion region, ActiveContentChanged onActiveContentChangedUserCallback, Action iMonitorCallback )
  29. // : base( region )
  30. // {
  31. // Ensure.That( onActiveContentChangedUserCallback ).Named( "onActiveContentChangedUserCallback" ).IsNotNull();
  32. // Ensure.That( iMonitorCallback ).Named( "iMonitorCallback" ).IsNotNull();
  33. // this.h = ( s, e ) =>
  34. // {
  35. // this.OnChanged();
  36. // onActiveContentChangedUserCallback( this, e );
  37. // iMonitorCallback();
  38. // };
  39. // this.region = region;
  40. // this.region.ActiveContentChanged += this.h;
  41. // }
  42. // /// <summary>
  43. // /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
  44. // /// </summary>
  45. // public void Dispose()
  46. // {
  47. // this.OnStopMonitoring( false );
  48. // }
  49. // protected override void OnStopMonitoring( bool targetDisposed )
  50. // {
  51. // if( this.h != null && this.region != null )
  52. // {
  53. // this.region.ActiveContentChanged -= this.h;
  54. // }
  55. // }
  56. // public IView ActiveContent
  57. // {
  58. // get { return this.region.ActiveContent; }
  59. // }
  60. // public IView PreviousActiveContent
  61. // {
  62. // get { return this.region.PreviousActiveContent; }
  63. // }
  64. // public bool TryGetViewModel<T>( IView sourceView, out T viewModel )
  65. // where T : class, IViewModel
  66. // {
  67. // if( sourceView != null )
  68. // {
  69. // viewModel = sourceView.DataContext as T;
  70. // }
  71. // else
  72. // {
  73. // viewModel = null;
  74. // }
  75. // return viewModel != null;
  76. // }
  77. // public T GetViewModel<T>( IView sourceView )
  78. // where T : class, IViewModel
  79. // {
  80. // return ( T )sourceView.DataContext;
  81. // }
  82. // public bool TryGetViewModel<T>( IView sourceView, Action<T> succesfullGetInterceptor ) where T : class, IViewModel
  83. // {
  84. // T vm;
  85. // if( this.TryGetViewModel<T>( sourceView, out vm ) )
  86. // {
  87. // succesfullGetInterceptor( vm );
  88. // return true;
  89. // }
  90. // return false;
  91. // }
  92. // }
  93. // /// <summary>
  94. // /// Occurs when the source monitored by this monitor changes.
  95. // /// </summary>
  96. // public event EventHandler Changed;
  97. // private void OnChanged()
  98. // {
  99. // if( this.Changed != null )
  100. // {
  101. // this.Changed( this, EventArgs.Empty );
  102. // }
  103. // }
  104. // readonly IRegionService svc;
  105. // readonly IDictionary<String, Monitorer> monitoredRegions = new Dictionary<String, Monitorer>();
  106. // /// <summary>
  107. // /// Initializes a new instance of the <see cref="ActiveContentChangedMonitor"/> class.
  108. // /// </summary>
  109. // /// <param name="svc">The SVC.</param>
  110. // public ActiveContentChangedMonitor( IRegionService svc )
  111. // {
  112. // Ensure.That( svc ).Named( "svc" ).IsNotNull();
  113. // this.svc = svc;
  114. // }
  115. // /// <summary>
  116. // /// Monitors the specified region within the given region manager.
  117. // /// </summary>
  118. // /// <param name="regionManager">The region manager.</param>
  119. // /// <param name="regionName">Name of the region.</param>
  120. // /// <param name="onActiveContentChanged">The on active content changed delegate invoked whenever the active content changes.</param>
  121. // /// <returns>The region monitor instance.</returns>
  122. // public IRegionMonitor Monitor( IRegionManager regionManager, String regionName, ActiveContentChanged onActiveContentChanged )
  123. // {
  124. // Monitorer monitorer;
  125. // if( !this.monitoredRegions.TryGetValue( regionName, out monitorer ) )
  126. // {
  127. // ISwitchingElementsRegion region;
  128. // if( regionManager.TryGetRegion<ISwitchingElementsRegion>( regionName, out region ) )
  129. // {
  130. // monitorer = new Monitorer( region, onActiveContentChanged, () => this.OnChanged() );
  131. // this.monitoredRegions.Add( regionName, monitorer );
  132. // }
  133. // else
  134. // {
  135. // throw new ArgumentOutOfRangeException( "regionName", "Cannot find the given region within the given RegionManager" );
  136. // }
  137. // }
  138. // return monitorer;
  139. // }
  140. // /// <summary>
  141. // /// Monitors the specified region.
  142. // /// </summary>
  143. // /// <typeparam name="TView">The type of the view.</typeparam>
  144. // /// <param name="regionName">Name of the region.</param>
  145. // /// <param name="onActiveContentChanged">The on active content changed delegate invoked whenever the active content changes.</param>
  146. // /// <returns>The region monitor instance.</returns>
  147. // public IRegionMonitor Monitor<TView>( String regionName, ActiveContentChanged onActiveContentChanged ) where TView : IView
  148. // {
  149. // var rgm = this.svc.GetKnownRegionManager<TView>();
  150. // return this.Monitor( rgm, regionName, onActiveContentChanged );
  151. // }
  152. // /// <summary>
  153. // /// Stops monitoring the region idenfied by the given region name.
  154. // /// </summary>
  155. // /// <param name="regionName">Name of the region.</param>
  156. // public void StopMonitoring( String regionName )
  157. // {
  158. // if( this.monitoredRegions.ContainsKey( regionName ) )
  159. // {
  160. // var m = this.monitoredRegions[ regionName ];
  161. // m.Dispose();
  162. // this.monitoredRegions.Remove( regionName );
  163. // }
  164. // }
  165. // /// <summary>
  166. // /// Stops all the monitoring operation.
  167. // /// </summary>
  168. // public void StopMonitoring()
  169. // {
  170. // var all = this.monitoredRegions.Keys.ToArray();
  171. // foreach( var mr in all )
  172. // {
  173. // this.StopMonitoring( mr );
  174. // }
  175. // }
  176. // /// <summary>
  177. // /// Asks this monitor to raise a change notification in order
  178. // /// to trigger all the listeners.
  179. // /// </summary>
  180. // public void NotifyChanged()
  181. // {
  182. // this.OnChanged();
  183. // }
  184. // }
  185. //}