Ejemplo n.º 1
0
        /// <summary>
        /// Send the data to the server context clients.
        /// </summary>
        /// <param name="data">The data to send to each server context client.</param>
        /// <param name="memberContexts">The collection of member context clients.</param>
        private void SendDataToClients(byte[] data, Nequeo.Net.IMemberContext[] memberContexts)
        {
            try
            {
                // Create a new queue.
                if (_queue == null)
                {
                    _queue = new ConcurrentQueue <Nequeo.Net.Provider.SendToContainer>();
                }

                // Create the container.
                Nequeo.Net.Provider.SendToContainer container = new Nequeo.Net.Provider.SendToContainer()
                {
                    Data           = data,
                    MemberContexts = memberContexts
                };

                // Queue an new container.
                _queue.Enqueue(container);

                // Send the data to the server context clients.
                SendDataToClientsAsync();
            }
            catch { }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Send to each server context the specified data.
        /// </summary>
        private void SendDataToClientsParallel()
        {
            // Error message.
            StringBuilder errorMessage = new StringBuilder();

            // Get the next item in the queue.
            Nequeo.Net.Provider.SendToContainer container = null;
            while (_queue.TryDequeue(out container))
            {
                // Get the data and list.
                byte[] data = container.Data;
                Nequeo.Net.IMemberContext[] memberContexts = container.MemberContexts;

                // If conenction exist.
                if (memberContexts != null)
                {
                    // If more than zero connections exist.
                    if (memberContexts.Count() > 0)
                    {
                        // Start a new parallel operation for each connection.
                        Parallel.ForEach <Nequeo.Net.IMemberContext>(memberContexts, u =>
                        {
                            try
                            {
                                // Make sure the current object has not be disposed.
                                if (u != null)
                                {
                                    if (data.Length > 0)
                                    {
                                        // Send the data to the current composite service.
                                        u.SentFromServer(data);

                                        // Get the current error from the server.
                                        Exception exception = u.GetLastError();
                                        if (exception != null)
                                        {
                                            errorMessage.Append(exception.Message + "\r\n");
                                        }
                                    }
                                }
                            }
                            catch { }
                        });
                    }
                }
            }
        }