/// <summary> /// Sets the port number. /// </summary> /// <param name="serviceName">The service name the client is connected to.</param> /// <param name="portTypeName">The application port name.</param> /// <param name="portTypeNumber">The application port number.</param> /// <param name="context">The communication data.</param> /// <returns>True if the port has been set; else false.</returns> public static bool SetPortNumber(string serviceName, string portTypeName, int portTypeNumber, Nequeo.Xml.Authorisation.Communication.Data.context context) { // Validate. if (String.IsNullOrEmpty(serviceName)) { throw new ArgumentNullException("serviceName"); } if (String.IsNullOrEmpty(portTypeName)) { throw new ArgumentNullException("portTypeName"); } try { // Find all ports with service name and application name. Communication.Data.contextPort port = null; try { // Find the first item. port = context.ports.First( u => (u.serviceName.ToLower() == serviceName.ToLower())); } catch { } // If port exists. if (port != null) { Communication.Data.contextPortType type = null; try { // Find the index of the port type to set. type = port.type.First(u => u.name.ToLower().Equals(portTypeName.ToLower())); } catch { } // If port type exists. if (type != null) { // Set the port number. type.number = portTypeNumber; // Save the new data. SaveCommunicationDataAsync(context); return(true); } else { return(false); } } else { return(false); } } catch (Exception) { throw; } }
/// <summary> /// Add a new port range. /// </summary> /// <param name="serviceName">The service name the client is connected to.</param> /// <param name="portTypeName">The list of application port names</param> /// <param name="portTypeNumber">The list of application port numbers.</param> /// <param name="context">The communication data.</param> /// <returns>The object containing the new data; else null.</returns> public static bool AddPort(string serviceName, string[] portTypeName, int[] portTypeNumber, Nequeo.Xml.Authorisation.Communication.Data.context context) { // Validate. if (String.IsNullOrEmpty(serviceName)) { throw new ArgumentNullException("serviceName"); } try { // Find all ports with service name and application name. Communication.Data.contextPort port = null; try { // Find the first item. port = context.ports.First( u => (u.serviceName.ToLower() == serviceName.ToLower())); } catch { } if (port != null) { // Get the type list. Communication.Data.contextPortType[] types = port.type.AddIfNotExists <Communication.Data.contextPortType, string, int> ( portTypeName, portTypeNumber, (m, u) => m.name.ToLower() == u.ToLower(), (n, p) => { var portType = new Communication.Data.contextPortType(); portType.name = n; portType.number = p; return(portType); } ); // Assign the port type details. port.type = types; // Save the new data. SaveCommunicationDataAsync(context); return(true); } else { // Get the type list. Communication.Data.contextPortType[] types = new Communication.Data.contextPortType[portTypeName.Length]; // Assign each port detail. for (int i = 0; i < portTypeName.Length; i++) { types[i].name = portTypeName[i]; types[i].number = portTypeNumber[i]; } // Load all the ports into a temp list. List <Communication.Data.contextPort> tempPorts = new List <Communication.Data.contextPort>(context.ports); Communication.Data.contextPort portData = new Communication.Data.contextPort() { type = types, serviceName = serviceName }; // Add the port from the list. tempPorts.Add(portData); // Assign the new port list to the // new context data. context.ports = tempPorts.ToArray(); // Save the new data. SaveCommunicationDataAsync(context); return(true); } } catch (Exception) { throw; } }