コード例 #1
0
        /// <summary>
        /// Load the client service context data.
        /// </summary>
        /// <returns>The collection of communication data.</returns>
        public static Nequeo.Xml.Authorisation.Communication.Data.contextService LoadClientServiceData()
        {
            try
            {
                string xmlValidationMessage = string.Empty;

                // Get the xml file location and
                // the xsd file schema.
                string xml = (String.IsNullOrEmpty(ClientServiceReader.ClientServiceXmlPath) ? Helper.ClientServiceXmlPath : ClientServiceReader.ClientServiceXmlPath);
                string xsd = Nequeo.Xml.Authorisation.Properties.Resources.ClientServiceProvider;

                // Validate the filter xml file.
                if (!Validation.IsXmlValidEx(xsd, xml, out xmlValidationMessage))
                {
                    throw new Exception("Xml validation. " + xmlValidationMessage);
                }

                // Deserialise the xml file into
                // the log directory list object
                GeneralSerialisation serial = new GeneralSerialisation();
                Nequeo.Xml.Authorisation.Communication.Data.contextService authData =
                    ((Nequeo.Xml.Authorisation.Communication.Data.contextService)serial.Deserialise(typeof(Nequeo.Xml.Authorisation.Communication.Data.contextService), xml));

                // Return the communication data.
                return(authData);
            }
            catch (Exception)
            {
                return(null);
            }
        }
コード例 #2
0
        /// <summary>
        /// Save the client service context data.
        /// </summary>
        /// <param name="context">The client service data to save.</param>
        private static async void SaveClientServiceDataAsync(Nequeo.Xml.Authorisation.Communication.Data.contextService context)
        {
            var result = Nequeo.Threading.AsyncOperationResult <int> .
                         RunTask(() => SaveClientServiceData(context));

            await result;
        }
コード例 #3
0
        /// <summary>
        /// Save the client service context data.
        /// </summary>
        /// <param name="context">The client service data to save.</param>
        public static void SaveClientServiceData(Nequeo.Xml.Authorisation.Communication.Data.contextService context)
        {
            lock (_lockObject)
            {
                try
                {
                    string xmlValidationMessage = string.Empty;

                    // Get the xml file location and
                    // the xsd file schema.
                    string xml = (String.IsNullOrEmpty(ClientServiceReader.ClientServiceXmlPath) ? Helper.ClientServiceXmlPath : ClientServiceReader.ClientServiceXmlPath);
                    string xsd = Nequeo.Xml.Authorisation.Properties.Resources.ClientServiceProvider;

                    // Deserialise the xml file into
                    // the log directory list object
                    GeneralSerialisation serial = new GeneralSerialisation();
                    bool authData = serial.Serialise(context, typeof(Nequeo.Xml.Authorisation.Communication.Data.contextService), xml);

                    // Validate the filter xml file.
                    if (!Validation.IsXmlValidEx(xsd, xml, out xmlValidationMessage))
                    {
                        throw new Exception("Xml validation. " + xmlValidationMessage);
                    }
                }
                catch { }
            }
        }
コード例 #4
0
        /// <summary>
        /// Remove the client.
        /// </summary>
        /// <param name="uniqueIdentifier">The unique client identifier.</param>
        /// <param name="serviceName">The service name the client is connected to.</param>
        /// <param name="activeConnections">The number of active connection using this client.</param>
        /// <param name="context">The communication data.</param>
        /// <returns>The object containing the new data; else null.</returns>
        public static bool RemoveClient(string uniqueIdentifier, string serviceName, int activeConnections,
                                        Nequeo.Xml.Authorisation.Communication.Data.contextService context)
        {
            // Validate.
            if (String.IsNullOrEmpty(uniqueIdentifier))
            {
                throw new ArgumentNullException("uniqueIdentifier");
            }
            if (String.IsNullOrEmpty(serviceName))
            {
                throw new ArgumentNullException("serviceName");
            }

            try
            {
                // Find all clients with unique identifier.
                Communication.Data.contextServiceClient client = null;

                try
                {
                    // Find the first item.
                    client = context.clients.First(
                        u => (u.uniqueIdentifier.ToString().ToLower() == uniqueIdentifier.ToLower()) &&
                        (u.serviceName.ToLower() == serviceName.ToLower()));
                }
                catch { }

                if (client != null)
                {
                    // If there is one or less active client connections
                    // then remove the client.
                    if (activeConnections < 2)
                    {
                        // Find the index of the client to remove.
                        context.clients = context.clients.Remove(u => u.Equals(client));
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
コード例 #5
0
        /// <summary>
        /// Get the host details for the identities.
        /// </summary>
        /// <param name="uniqueIdentifier">The unique client identifier.</param>
        /// <param name="serviceName">The service name the client is connected to.</param>
        /// <param name="context">The communication data.</param>
        /// <returns>The host details containing the name (host); else null.</returns>
        public static string GetHost(string uniqueIdentifier, string serviceName, Nequeo.Xml.Authorisation.Communication.Data.contextService context)
        {
            // Validate.
            if (String.IsNullOrEmpty(uniqueIdentifier))
            {
                throw new ArgumentNullException("uniqueIdentifier");
            }
            if (String.IsNullOrEmpty(serviceName))
            {
                throw new ArgumentNullException("serviceName");
            }

            try
            {
                // Find all clients with unique identifier.
                Communication.Data.contextServiceClient client = null;

                try
                {
                    // Find the first item.
                    client = context.clients.First(
                        u => (u.uniqueIdentifier.ToString().ToLower() == uniqueIdentifier.ToLower()) &&
                        (u.serviceName.ToLower() == serviceName.ToLower()));
                }
                catch { }

                if (client != null)
                {
                    // Get the host.
                    string hostName = client.host;

                    // Return the host information.
                    return(hostName);
                }

                return(null);
            }
            catch (Exception)
            {
                throw;
            }
        }
コード例 #6
0
        /// <summary>
        /// Set the communication token.
        /// </summary>
        /// <param name="uniqueIdentifier">The unique client identifier.</param>
        /// <param name="serviceName">The service name the client is connected to.</param>
        /// <param name="communicationToken">The client communication token.</param>
        /// <param name="context">The communication data.</param>
        public static void SetClientCommunicationToken(string uniqueIdentifier, string serviceName, string communicationToken,
                                                       Nequeo.Xml.Authorisation.Communication.Data.contextService context)
        {
            // Validate.
            if (String.IsNullOrEmpty(uniqueIdentifier))
            {
                throw new ArgumentNullException("uniqueIdentifier");
            }
            if (String.IsNullOrEmpty(serviceName))
            {
                throw new ArgumentNullException("serviceName");
            }

            try
            {
                // Find all clients with unique identifier.
                Communication.Data.contextServiceClient client = null;

                try
                {
                    // Find the first item.
                    client = context.clients.First(
                        u => (u.uniqueIdentifier.ToString().ToLower() == uniqueIdentifier.ToLower()) &&
                        (u.serviceName.ToLower() == serviceName.ToLower()));
                }
                catch { }

                if (client != null)
                {
                    // Get the client reference.
                    client.Value = (String.IsNullOrEmpty(communicationToken) ? "" : communicationToken);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
コード例 #7
0
        /// <summary>
        /// Add a new client.
        /// </summary>
        /// <param name="uniqueIdentifier">The unique client identifier.</param>
        /// <param name="serviceName">The service name the client is connected to.</param>
        /// <param name="hostName">The host machine the client must connect to.</param>
        /// <param name="context">The communication data.</param>
        /// <param name="active">Is the communication currenlty active.</param>
        /// <param name="communicationToken">The common token used for communication.</param>
        /// <returns>The object containing the new data; else null.</returns>
        public static bool AddClient(string uniqueIdentifier, string serviceName, string hostName,
                                     Nequeo.Xml.Authorisation.Communication.Data.contextService context, bool active = false, string communicationToken = "")
        {
            // Validate.
            if (String.IsNullOrEmpty(uniqueIdentifier))
            {
                throw new ArgumentNullException("uniqueIdentifier");
            }
            if (String.IsNullOrEmpty(hostName))
            {
                throw new ArgumentNullException("hostName");
            }
            if (String.IsNullOrEmpty(serviceName))
            {
                throw new ArgumentNullException("serviceName");
            }

            try
            {
                // Find all clients with unique identifier.
                Communication.Data.contextServiceClient client = null;

                try
                {
                    // Find the first item.
                    client = context.clients.First(
                        u => (u.uniqueIdentifier.ToString().ToLower() == uniqueIdentifier.ToLower()) &&
                        (u.serviceName.ToLower() == serviceName.ToLower()) &&
                        (u.host.ToLower() == hostName.ToLower()));
                }
                catch { }

                if (client != null)
                {
                    // Get the client reference.
                    client.active    = active;
                    client.dateAdded = DateTime.Now;
                    client.Value     = (String.IsNullOrEmpty(communicationToken) ? "" : communicationToken);

                    // Save the new data.
                    SaveClientServiceDataAsync(context);
                    return(true);
                }
                else
                {
                    // Load all the clients into a temp list.
                    List <Communication.Data.contextServiceClient> tempClients = new List <Communication.Data.contextServiceClient>(context.clients);
                    Communication.Data.contextServiceClient        clientData  = new Communication.Data.contextServiceClient()
                    {
                        uniqueIdentifier = Int32.Parse(uniqueIdentifier),
                        host             = hostName,
                        serviceName      = serviceName,
                        active           = active,
                        dateAdded        = DateTime.Now,
                        Value            = (String.IsNullOrEmpty(communicationToken) ? "" : communicationToken)
                    };

                    // Add the client from the list.
                    tempClients.Add(clientData);

                    // Assign the new client list to the
                    // new context data.
                    context.clients = tempClients.ToArray();
                    return(true);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
コード例 #8
0
        /// <summary>
        /// Get the host details for the identities.
        /// </summary>
        /// <param name="uniqueIdentifiers">The unique client identifiers.</param>
        /// <param name="serviceName">The service name the client is connected to.</param>
        /// <param name="context">The communication data.</param>
        /// <param name="contextClient">The client service data.</param>
        /// <returns>The host details containing the names (host or "" if not found); else null.</returns>
        /// <exception cref="System.Exception"></exception>
        /// <exception cref="System.ArgumentNullException"></exception>
        public static string[] GetHosts(string[] uniqueIdentifiers, string serviceName,
                                        Nequeo.Xml.Authorisation.Communication.Data.context context,
                                        Nequeo.Xml.Authorisation.Communication.Data.contextService contextClient)
        {
            // Validate.
            if (uniqueIdentifiers == null)
            {
                throw new ArgumentNullException("uniqueIdentifiers");
            }

            try
            {
                List <string> hosts    = new List <string>();
                List <string> tempHost = new List <string>();

                // Set up the number of identifiers to find.
                object monitor      = new object();
                int    numberToFind = uniqueIdentifiers.Length;
                bool[] found        = new bool[numberToFind];

                // For each client.
                foreach (Communication.Data.contextServiceClient item in contextClient.clients)
                {
                    int numberFound = 0;

                    // For each unique identifier.
                    for (int i = 0; i < numberToFind; i++)
                    {
                        // If the service name is empty.
                        if (String.IsNullOrEmpty(serviceName))
                        {
                            // If the unique identifier has been found.
                            if ((item.uniqueIdentifier.ToString().ToLower() == uniqueIdentifiers[i].ToLower()))
                            {
                                // Add the server context item.
                                tempHost.Add(item.host);
                                found[i] = true;
                            }
                        }
                        else
                        {
                            // If the unique identifier has been found.
                            if ((item.uniqueIdentifier.ToString().ToLower() == uniqueIdentifiers[i].ToLower()) &&
                                (item.serviceName.ToLower() == serviceName.ToLower()))
                            {
                                // Add the server context item.
                                tempHost.Add(item.host);
                                found[i] = true;
                            }
                        }

                        // If the current identifier
                        // has been found then stop the
                        // search for the current identifier.
                        if (found[i])
                        {
                            break;
                        }
                    }

                    // Count the number of items found.
                    Parallel.For(0, numberToFind, () => 0, (j, state, local) =>
                    {
                        // If found then increment the count.
                        if (found[j])
                        {
                            return(local = 1);
                        }
                        else
                        {
                            return(local = 0);
                        }
                    }, local =>
                    {
                        // Add one to the count.
                        lock (monitor)
                            numberFound += local;
                    });

                    // If all the machine names have been found
                    // then stop the search.
                    if (numberFound >= numberToFind)
                    {
                        break;
                    }
                }

                // Construct the hosts
                Parallel.For(0, numberToFind, () => - 1, (i, state, local) =>
                {
                    // If found then add the host, else add empty string.
                    if (found[i])
                    {
                        // Found item.
                        return(i);
                    }
                    return(-1);
                }, local =>
                {
                    // Add one to the count.
                    lock (monitor)
                    {
                        // If a valid index.
                        if (local > -1)
                        {
                            hosts.Add(tempHost[local]);
                        }
                        else
                        {
                            hosts.Add("");
                        }
                    }
                });

                // If host list exists the host list else null.
                return(hosts.Count > 0 ? hosts.ToArray() : null);
            }
            catch (Exception)
            {
                throw;
            }
        }