/// <summary> /// Creates a new <see cref="PropertyPublisher"/> instance. /// </summary> /// <remarks> /// Subclasses must call <see cref="Initialize"/> in order to register event listeners and /// set up existing members of the collection. /// </remarks> /// <param name="owner">The <see cref="PropertyPublisher"/> to whom the collection belongs; see <see cref="Owner"/>.</param> /// <param name="property">The name of the published property of the <see cref="Owner"/> which returns the <see cref="Collection"/>.</param> public PropertyCollectionHelper(EventQueue dispatcher, PropertyPublisher owner, string property) { this.m_EventQueue = dispatcher; this.m_Owner = owner; this.m_Property = property; this.m_TagTable = Hashtable.Synchronized(new Hashtable()); }
/// <summary> /// Constructs a service to keep track of changes to the model objects and store them in the /// registry /// </summary> /// <param name="toSave">The model class with values we want to save in the registry</param> public RegistryService(PropertyPublisher toSave) { // Save the object we're serializing this.m_PropertyPublisher = toSave; // Get the registry key and if it doesn't exist the create it this.m_RegistryKey = Registry.CurrentUser.CreateSubKey(RegistryService.m_szRegistryString); // Get all the properties that are supposed to be saved and add listeners to them foreach (PropertyInfo property in this.m_PropertyPublisher.GetType().GetProperties()) { object[] publishAttribs = property.GetCustomAttributes(typeof(PropertyPublisher.PublishedAttribute), true); object[] savedAttribs = property.GetCustomAttributes(typeof(PropertyPublisher.SavedAttribute), true); // Check if the property should be saved if (savedAttribs.Length >= 1) { // Initialize Values string oldValue = this.GetStringRegistryValue(property.Name); if (oldValue != null) { this.SetModelValue(property.Name, oldValue); } // Hook a handler to events that are published so they are saved on change if (publishAttribs.Length >= 1) { this.m_PropertyPublisher.Changed[property.Name].Add(new PropertyEventHandler(this.OnPropertyChanged)); } } } }
/// <summary> /// Constructs a service to keep track of changes to the model objects and store them in the /// registry /// </summary> /// <param name="toSave">The model class with values we want to save in the registry</param> public RegistryService( PropertyPublisher toSave ) { // Save the object we're serializing this.m_PropertyPublisher = toSave; // Get the registry key and if it doesn't exist the create it this.m_RegistryKey = Registry.CurrentUser.OpenSubKey( RegistryService.m_szRegistryString, true ); if( this.m_RegistryKey == null ) { this.m_RegistryKey = Registry.CurrentUser.CreateSubKey( RegistryService.m_szRegistryString ); } // Get all the properties that are supposed to be saved and add listeners to them foreach( PropertyInfo property in this.m_PropertyPublisher.GetType().GetProperties() ) { object[] publishAttribs = property.GetCustomAttributes( typeof(PropertyPublisher.PublishedAttribute), true ); object[] savedAttribs = property.GetCustomAttributes( typeof(PropertyPublisher.SavedAttribute), true ); // Check if the property should be saved if( savedAttribs.Length >= 1 ) { // Initialize Values string oldValue = this.GetStringRegistryValue( property.Name ); if( oldValue != null ) this.SetModelValue( property.Name, oldValue ); // Hook a handler to events that are published so they are saved on change if( publishAttribs.Length >= 1 ) { this.m_PropertyPublisher.Changed[property.Name].Add(new PropertyEventHandler(this.OnPropertyChanged)); } } } }
/// <summary> /// The current networking code should register and unregister when it starts and disposes. /// The intent is that this will allow UI elements to pick up global network state /// from a corresponding property aggregated and published here in NetworkModel. We normally should have only one /// PropertyPublisher registered at a time, but we will keep track of multiple, and /// report an indeterminate state if more than one is registered. /// </summary> /// <param name="publisher">A PropertyPublisher with a NetworkStatus property</param> /// <param name="register">true to register, false to unregister</param> public void RegisterNetworkStatusProvider(PropertyPublisher publisher, bool register, NetworkStatus initialStatus) { using (Synchronizer.Lock(this.m_NetworkStatusProviders)) { if (register) { if (m_NetworkStatusProviders.ContainsKey(publisher)) { throw (new ArgumentException("A Network Status Provider can only be registered once.")); } publisher.Changed["NetworkStatus"].Add(new PropertyEventHandler(OnNetworkStatusChanged)); NetworkStatus newStatus = initialStatus.Clone(); m_NetworkStatusProviders.Add(publisher, newStatus); if (m_NetworkStatusProviders.Count > 1) { //Multiple providers --> unknown global status newStatus = new NetworkStatus(); } if (m_NetworkStatus.StatusChanged(newStatus)) { using (Synchronizer.Lock(this.SyncRoot)) { this.SetPublishedProperty("NetworkStatus", ref m_NetworkStatus, newStatus); } } } else { if (!m_NetworkStatusProviders.ContainsKey(publisher)) { throw (new ArgumentException("A Network Status Provider can't be unregistered until it has been registered.")); } m_NetworkStatusProviders.Remove(publisher); publisher.Changed["NetworkStatus"].Remove(new PropertyEventHandler(OnNetworkStatusChanged)); if (m_NetworkStatusProviders.Count == 1) { foreach (NetworkStatus ns in m_NetworkStatusProviders.Values) { if (m_NetworkStatus.StatusChanged(ns)) { using (Synchronizer.Lock(this.SyncRoot)) { this.SetPublishedProperty("NetworkStatus", ref m_NetworkStatus, ns); } } break; } } if (m_NetworkStatusProviders.Count == 0) { if (m_NetworkStatus.StatusChanged(NetworkStatus.DisconnectedNetworkStatus)) { using (Synchronizer.Lock(this.SyncRoot)) { this.SetPublishedProperty("NetworkStatus", ref m_NetworkStatus, NetworkStatus.DisconnectedNetworkStatus); } } } } } }
/// <summary> /// The current networking code should register and unregister when it starts and disposes. /// The intent is that this will allow UI elements to pick up global network state /// from a corresponding property aggregated and published here in NetworkModel. We normally should have only one /// PropertyPublisher registered at a time, but we will keep track of multiple, and /// report an indeterminate state if more than one is registered. /// </summary> /// <param name="publisher">A PropertyPublisher with a NetworkStatus property</param> /// <param name="register">true to register, false to unregister</param> public void RegisterNetworkStatusProvider(PropertyPublisher publisher, bool register, NetworkStatus initialStatus) { using (Synchronizer.Lock(this.m_NetworkStatusProviders)) { if (register) { if (m_NetworkStatusProviders.ContainsKey(publisher)) throw (new ArgumentException("A Network Status Provider can only be registered once.")); publisher.Changed["NetworkStatus"].Add(new PropertyEventHandler(OnNetworkStatusChanged)); NetworkStatus newStatus = initialStatus.Clone(); m_NetworkStatusProviders.Add(publisher, newStatus); if (m_NetworkStatusProviders.Count > 1) { //Multiple providers --> unknown global status newStatus = new NetworkStatus(); } if (m_NetworkStatus.StatusChanged(newStatus)) { using (Synchronizer.Lock(this.SyncRoot)) { this.SetPublishedProperty("NetworkStatus", ref m_NetworkStatus, newStatus); } } } else { if (!m_NetworkStatusProviders.ContainsKey(publisher)) throw (new ArgumentException("A Network Status Provider can't be unregistered until it has been registered.")); m_NetworkStatusProviders.Remove(publisher); publisher.Changed["NetworkStatus"].Remove(new PropertyEventHandler(OnNetworkStatusChanged)); if (m_NetworkStatusProviders.Count == 1) { foreach (NetworkStatus ns in m_NetworkStatusProviders.Values) { if (m_NetworkStatus.StatusChanged(ns)) { using (Synchronizer.Lock(this.SyncRoot)) { this.SetPublishedProperty("NetworkStatus", ref m_NetworkStatus, ns); } } break; } } if (m_NetworkStatusProviders.Count == 0) { if (m_NetworkStatus.StatusChanged(NetworkStatus.DisconnectedNetworkStatus)) { using (Synchronizer.Lock(this.SyncRoot)) { this.SetPublishedProperty("NetworkStatus", ref m_NetworkStatus, NetworkStatus.DisconnectedNetworkStatus); } } } } } }
/// <summary> /// Internal constructor /// </summary> /// <param name="owner">The object which the events are published from</param> /// <param name="property">The string given to the published events</param> internal ParticipantCollection( PropertyPublisher owner, string property ) : base(owner, property) { }
/// <summary> /// Internal constructor /// </summary> /// <param name="owner">The object which the events are published from</param> /// <param name="property">The string given to the published events</param> internal DeckTraversalCollection(PropertyPublisher owner, string property) : base(owner, property) { }
internal ClassroomCollection(PropertyPublisher owner, string property) : base(owner, property) { }
internal VersionExchangeCollection(PropertyPublisher owner, string property) : base(owner, property) { }
internal ParticipantCollection(PropertyPublisher owner, string property) : base(owner, property) { }
internal DeckPairCollection(PropertyPublisher owner, string property) : base(owner, property) { }
internal PresentationCollection(PropertyPublisher owner, string property) : base(owner, property) { }
internal EntryCollection(PropertyPublisher owner, string property) : base(owner, property) { this.m_Parent = owner; }
internal GroupCollection( PropertyPublisher owner, string property ) : base(owner, property) { }
internal InstructorAdvertisementCollection(PropertyPublisher owner, string property) : base(owner, property) { }
internal ProtocolCollection(PropertyPublisher owner, string property) : base(owner, property) { }
internal QuickPollResultCollection( PropertyPublisher owner, string property ) : base(owner, property) { }
internal SheetCollection(PropertyPublisher owner, string property) : base(owner, property) { }
internal QuickPollResultCollection(PropertyPublisher owner, string property) : base(owner, property) { }