Example #1
0
        public bool StatusChanged(NetworkStatus other)
        {
            if ((this.ConnectionStatus != other.ConnectionStatus) ||
                (this.ProtocolType != other.ProtocolType) ||
                (this.TCPRole != other.TCPRole) ||
                (this.ClientCount != other.ClientCount) ||
                (this.ClassroomName != other.ClassroomName))
            {
                return(true);
            }

            return(false);
        }
Example #2
0
 /// <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);
                     }
                 }
             }
         }
     }
 }
Example #3
0
 public NetworkModel()
 {
     this.m_Protocols = new ProtocolCollection(this, "Protocols");
     m_NetworkStatus = NetworkStatus.DisconnectedNetworkStatus;
     m_NetworkStatusProviders = new Hashtable();
 }
Example #4
0
 private void OnNetworkStatusChanged(object sender, PropertyEventArgs args)
 {
     using (Synchronizer.Lock(this.m_NetworkStatusProviders)) {
         NetworkStatus newStatus = ((NetworkStatus)((PropertyChangeEventArgs)args).NewValue).Clone();
         m_NetworkStatusProviders[sender] = newStatus;
         if (m_NetworkStatusProviders.Count != 1) {
             newStatus = new NetworkStatus();
         }
         if (m_NetworkStatus.StatusChanged(newStatus)) {
             using (Synchronizer.Lock(this.SyncRoot)) {
                 this.SetPublishedProperty("NetworkStatus", ref this.m_NetworkStatus, newStatus);
             }
         }
     }
 }
Example #5
0
        public bool StatusChanged(NetworkStatus other)
        {
            if ((this.ConnectionStatus != other.ConnectionStatus) ||
                (this.ProtocolType != other.ProtocolType) ||
                (this.TCPRole != other.TCPRole) ||
                (this.ClientCount != other.ClientCount) ||
                (this.ClassroomName != other.ClassroomName))
                return true;

            return false;
        }
Example #6
0
        public TCPServer(IPEndPoint localEP, PresenterModel model, ClassroomModel classroom,
            InstructorModel instructor)
        {
            RestoreConfig();
            m_ClientConnected = new ManualResetEvent(false);
            m_Participant = model.Participant;
            m_Classroom = classroom;
            m_ClientCount = 0;
            this.m_Network = model.Network;
            m_NetworkStatus = new NetworkStatus(ConnectionStatus.Disconnected, ConnectionProtocolType.TCP, TCPRole.Server, 0);
            this.m_Network.RegisterNetworkStatusProvider(this, true, m_NetworkStatus);

            if (localEP != null) {
                this.m_ListenEP = localEP;
            }
            else {
                this.m_ListenEP = new IPEndPoint(IPAddress.Any, DefaultPort);
            }

            m_AllClients = new Hashtable();
            m_ReceiveQueue = new Queue();

            this.m_Encoder = new Chunk.ChunkEncoder();
            this.m_ServerSender = new TCPServerSender(instructor);

            //Start bridging if config file says so
            #if RTP_BUILD
            m_U2MBridge = null;
            string enableBridge = System.Configuration.ConfigurationManager.AppSettings[this.GetType().ToString() + ".EnableBridge"];
            if (enableBridge != null) {
                bool enable = false;
                if (bool.TryParse(enableBridge, out enable) && enable) {
                    Trace.WriteLine("Unicast to Multicast Bridge enabled.", this.GetType().ToString());
                    m_U2MBridge = new UnicastToMulticastBridge(model);
                }
            }
            #endif
        }
Example #7
0
        public TCPServer(IPEndPoint localEP, PresenterModel model, ClassroomModel classroom,
            InstructorModel instructor)
        {
            string portStr = System.Configuration.ConfigurationManager.AppSettings[this.GetType().ToString() + ".TCPListenPort"];
            int p;
            if (Int32.TryParse(portStr, out p)) {
                TCPListenPort = p;
            }
            RestoreConfig();
            m_ClientConnected = new ManualResetEvent(false);
            m_Participant = model.Participant;
            m_Classroom = classroom;
            m_ClientCount = 0;
            this.m_Network = model.Network;
            m_NetworkStatus = new NetworkStatus(ConnectionStatus.Disconnected, ConnectionProtocolType.TCP, TCPRole.Server, 0);
            this.m_Network.RegisterNetworkStatusProvider(this, true, m_NetworkStatus);

            if (localEP != null) {
                this.m_ListenEP = localEP;
            }
            else {
                IPAddress ip = IPAddress.Any;
                //Use IPv4 unless it is unavailable.  TODO: Maybe this should be a configurable parameter?
                if ((!Socket.OSSupportsIPv4) && (Socket.OSSupportsIPv6)) {
                    ip = IPAddress.IPv6Any;
                }
                this.m_ListenEP = new IPEndPoint(ip, TCPListenPort);
            }

            m_AllClients = new Hashtable();
            m_ReceiveQueue = new Queue();

            this.m_Encoder = new Chunk.ChunkEncoder();
            this.m_ServerSender = new TCPServerSender(instructor);

            //Start bridging if config file says so
            #if RTP_BUILD
            m_U2MBridge = null;
            string enableBridge = System.Configuration.ConfigurationManager.AppSettings[this.GetType().ToString() + ".EnableBridge"];
            if (enableBridge != null) {
                bool enable = false;
                if (bool.TryParse(enableBridge, out enable) && enable) {
                    Trace.WriteLine("Unicast to Multicast Bridge enabled.", this.GetType().ToString());
                    m_U2MBridge = new UnicastToMulticastBridge(model);
                }
            }
            #endif
        }