/// <summary>
		/// Determines if a port map is contained in the collection
		/// </summary>
		/// <param name="portmap"></param>
		/// <returns></returns>
		public bool Contains(PortMap portmap)
		{
			foreach(PortMap existingPortmap in base.InnerList)
				if (existingPortmap.Key == portmap.Key)
					return true;
			return false;
		}
Exemple #2
0
 /// <summary>
 /// Unregisters a PortMap
 /// </summary>
 /// <param name="portmap"></param>
 public void UnregisterPortMap(PortMap portmap)
 {
     if (_portmaps.Contains(portmap.Key))
     {
         _portmaps.Remove(portmap);
     }
 }
Exemple #3
0
 /// <summary>
 /// Accesses a port map via a keyed indexer
 /// </summary>
 public PortMap this[string key]
 {
     get
     {
         foreach (PortMap portmap in base.InnerList)
         {
             if (portmap.Key == key)
             {
                 return(portmap);
             }
         }
         return(null);
     }
     set
     {
         for (int i = 0; i < base.InnerList.Count; i++)
         {
             PortMap portmap = (PortMap)base.InnerList[i];
             if (portmap.Key == key)
             {
                 base.InnerList[i] = value;
             }
         }
     }
 }
		/// <summary>
		/// Removes a port map from the collection
		/// </summary>
		/// <param name="portmap"></param>
		public void Remove(PortMap portmap)
		{
			foreach(PortMap existingPortmap in base.InnerList)
				if (existingPortmap.Key == portmap.Key)
				{
					existingPortmap.PortDescriptorChanged -= new PortDescriptorEventHandler(this.OnPortDescriptorChanged);
					base.InnerList.Remove(existingPortmap);
					break;
				}
		}
Exemple #5
0
 /// <summary>
 /// Determines if a port map is contained in the collection
 /// </summary>
 /// <param name="portmap"></param>
 /// <returns></returns>
 public bool Contains(PortMap portmap)
 {
     foreach (PortMap existingPortmap in base.InnerList)
     {
         if (existingPortmap.Key == portmap.Key)
         {
             return(true);
         }
     }
     return(false);
 }
Exemple #6
0
        /// <summary>
        /// Registers a PortMap
        /// </summary>
        /// <param name="portmap"></param>
        public PortMap RegisterPortMap(PortMap portmap)
        {
            PortMap registeredPortMap = null;

            if (!_portmaps.Contains(portmap.Key))
            {
                _portmaps.Add(portmap);
            }
            registeredPortMap = _portmaps[portmap.Key];
            return(registeredPortMap);
        }
Exemple #7
0
 /// <summary>
 /// Removes a port map from the collection
 /// </summary>
 /// <param name="portmap"></param>
 public void Remove(PortMap portmap)
 {
     foreach (PortMap existingPortmap in base.InnerList)
     {
         if (existingPortmap.Key == portmap.Key)
         {
             existingPortmap.PortDescriptorChanged -= new PortDescriptorEventHandler(this.OnPortDescriptorChanged);
             base.InnerList.Remove(existingPortmap);
             break;
         }
     }
 }
		/// <summary>
		/// Adds a PortMap to the collection
		/// </summary>
		/// <param name="portmap"></param>
		/// <returns></returns>
		public int Add(PortMap portmap)
		{
			if (portmap == null)
				throw new NullReferenceException("A null protocol port map cannot be added to a protocol port map collection.");

			if (!this.Contains(portmap))
			{
				portmap.PortDescriptorChanged += new PortDescriptorEventHandler(this.OnPortDescriptorChanged);
				return base.InnerList.Add(portmap);
			}
			
			return -1;
		}
Exemple #9
0
        /// <summary>
        /// Adds a PortMap to the collection
        /// </summary>
        /// <param name="portmap"></param>
        /// <returns></returns>
        public int Add(PortMap portmap)
        {
            if (portmap == null)
            {
                throw new NullReferenceException("A null protocol port map cannot be added to a protocol port map collection.");
            }

            if (!this.Contains(portmap))
            {
                portmap.PortDescriptorChanged += new PortDescriptorEventHandler(this.OnPortDescriptorChanged);
                return(base.InnerList.Add(portmap));
            }

            return(-1);
        }
Exemple #10
0
        /// <summary>
        /// Registers a portmap. Optionally overwrites an existing portmap.
        /// </summary>
        /// <param name="portmap"></param>
        /// <param name="overwrite"></param>
        /// <returns></returns>
        public PortMap RegisterPortMap(PortMap portmap, bool overwrite)
        {
            PortMap registeredPortMap = null;

            if (!_portmaps.Contains(portmap.Key))
            {
                _portmaps.Add(portmap);
            }
            if (overwrite)
            {
                _portmaps[portmap.Key] = portmap;
            }
            registeredPortMap = _portmaps[portmap.Key];
            return(registeredPortMap);
        }
Exemple #11
0
        /// <summary>
        /// Calculates the port numbers for the managed PortMap identified by the specified key
        /// </summary>
        /// <param name="portMapKey">The key to the PortMap on which the calculations will be performed</param>
        public PortMap CalculatePortsForPortMap(string portMapKey)
        {
            /// if we are managing a port map using the key specified
            if (_portmaps.Contains(portMapKey))
            {
                PortMap portmap = _portmaps[portMapKey];

                /// assign a port number to each port descriptor
                foreach (PortDescriptor descriptor in portmap.PortDescriptors)
                {
                    /// each port descriptor evaluates to the base port plus the offset
                    descriptor.Port = _basePort + descriptor.Offset;
                }

                // raise the event to let others know we have calculated this portmap
                this.OnPortMapCalculated(this, new PortMapEventArgs(portmap));

                return(portmap);
            }
            return(null);
        }
Exemple #12
0
        /// <summary>
        /// Finds an existing portmap using the specified key, or creates, registers, and calculates a new portmap of the specified type
        /// </summary>
        /// <param name="key"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public PortMap FindOrRegister(string key, Type type, out bool registered)
        {
            PortMap portmap = null;

            registered = false;

            // if the port authority already contains the portmap
            if (_portmaps.Contains(key))
            {
                // just use the one it has already
                portmap = _portmaps[key];
            }
            else
            {
                // if a type of port map was specified
                if (type != null)
                {
                    // snag the default constructor
                    ConstructorInfo ci = type.GetConstructor(Type.EmptyTypes);
                    if (ci != null)
                    {
                        // create an instance of it
                        portmap = ci.Invoke(new object[] {}) as PortMap;
                        if (portmap != null)
                        {
                            registered = true;

                            // register it
                            portmap = this.RegisterPortMap(portmap);

                            // and calculate the ports for its portmap
                            portmap = this.CalculatePortsForPortMap(portmap.Key);
                        }
                    }
                }
            }

            return(portmap);
        }
		/// <summary>
		/// Unregisters a PortMap 
		/// </summary>
		/// <param name="portmap"></param>
		public void UnregisterPortMap(PortMap portmap)
		{
			if (_portmaps.Contains(portmap.Key))
				_portmaps.Remove(portmap);
		}
		public PortMapEventArgs(PortMap portmap) : base()
		{
			_portmap = portmap;
		}
		/// <summary>
		/// Registers a PortMap 
		/// </summary>
		/// <param name="portmap"></param>
		public PortMap RegisterPortMap(PortMap portmap)
		{
			PortMap registeredPortMap = null;
			if (!_portmaps.Contains(portmap.Key))
				_portmaps.Add(portmap);
			registeredPortMap = _portmaps[portmap.Key];
			return registeredPortMap;
		}
		/// <summary>
		/// Registers a portmap. Optionally overwrites an existing portmap.
		/// </summary>
		/// <param name="portmap"></param>
		/// <param name="overwrite"></param>
		/// <returns></returns>
		public PortMap RegisterPortMap(PortMap portmap, bool overwrite)
		{
			PortMap registeredPortMap = null;
			if (!_portmaps.Contains(portmap.Key))
				_portmaps.Add(portmap);
			if (overwrite)
				_portmaps[portmap.Key] = portmap;
			registeredPortMap = _portmaps[portmap.Key];
			return registeredPortMap;
		}
Exemple #17
0
 public PortMapEventArgs(PortMap portmap) : base()
 {
     _portmap = portmap;
 }