예제 #1
0
 /// <summary>
 /// Sends an instruction to a single client.
 /// </summary>
 /// <param name="pInstruction">Instruction to send. The receiver is set by the 'pReceiver'-parameter</param>
 public void Send(InstructionBase pInstruction)
 {
     if (!HandlerData.HaltActive)
     {
         if (pInstruction.Receiver != null)
         {
             Handler.Debug($"Queueing message for {pInstruction.Receiver.ToString()}.", DebugType.Info);
             HandlerData.OutgoingInstructions.Add(pInstruction);
         }
     }
 }
예제 #2
0
        /// <summary>
        /// Sends a instruction to a user-group.
        /// </summary>
        /// <param name="pInstruction">Instruction to send. Set the receiver-parameter to 'null'</param>
        /// <param name="pGroup">Target group</param>
        public void GroupSend(InstructionBase pInstruction, UserGroup pGroup)
        {
            if (!HandlerData.HaltActive)
            {
                try
                {
                    lock (pGroup)
                    {
                        for (int i = 0; i < pGroup.OnlineMembers.Count; i++)
                        {
                            if (!string.IsNullOrEmpty(pGroup.OnlineMembers[i].Username) && !string.IsNullOrEmpty(pGroup.OnlineMembers[i].Password))
                            {
                                try
                                {
                                    InstructionBase tmpInstruction = pInstruction.Clone();
                                    tmpInstruction.Receiver = pGroup.OnlineMembers[i];

                                    Handler.Debug($"Queueing message for {tmpInstruction.Receiver.ToString()}.", DebugType.Info);
                                    HandlerData.OutgoingInstructions.Add(tmpInstruction);
                                }
                                catch (Exception ex)
                                {
                                    Handler.Debug("GroupSend-Error.", DebugType.Error);
                                    if (HandlerData.ShowExceptions)
                                    {
                                        Handler.Debug($"({ex.GetType().Name}) {ex.Message}", DebugType.Exception);
                                    }
                                    HandlerData.LogErrorCounter++;
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Handler.Debug("Halting (02)", DebugType.Warning);
                    if (HandlerData.ShowExceptions)
                    {
                        Handler.Debug($"({ex.GetType().Name}) {ex.Message}", DebugType.Exception);
                    }
                    if (HandlerData.TryRestartOnCrash)
                    {
                        HaltAllThreads();
                    }
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Sends an instruction to all connected users.
        /// </summary>
        /// <param name="pInstruction">Instruction to send. Set the receiver-parameter to 'null'</param>
        public void Broadcast(InstructionBase pInstruction)
        {
            if (!HandlerData.HaltActive)
            {
                try
                {
                    lock (ConnectedClients)
                    {
                        for (int i = 0; i < ConnectedClients.Count; i++)
                        {
                            if (!string.IsNullOrEmpty(ConnectedClients[i].Username) && !string.IsNullOrEmpty(ConnectedClients[i].Password))
                            {
                                try
                                {
                                    InstructionBase tmpInstruction = pInstruction.Clone();
                                    tmpInstruction.Receiver = ConnectedClients[i];

                                    Handler.Debug($"Queueing message for {tmpInstruction.Receiver.ToString()}.", DebugType.Info);
                                    HandlerData.OutgoingInstructions.Add(tmpInstruction);
                                }
                                catch (Exception ex)
                                {
                                    Handler.Debug("Broadcast-Error.", DebugType.Error);
                                    if (HandlerData.ShowExceptions)
                                    {
                                        Handler.Debug($"({ex.GetType().Name}) {ex.Message}", DebugType.Exception);
                                    }
                                    HandlerData.LogErrorCounter++;
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Handler.Debug("Halting (04)", DebugType.Warning);
                    if (HandlerData.ShowExceptions)
                    {
                        Handler.Debug($"({ex.GetType().Name}) {ex.Message}", DebugType.Exception);
                    }
                    if (HandlerData.TryRestartOnCrash)
                    {
                        HaltAllThreads();
                    }
                }
            }
        }
예제 #4
0
        /// <summary>
        /// Sends an instruction to the server.
        /// </summary>
        /// <param name="pInstruction">Instruction to be sent. Set the receiver-parameter to 'null'</param>
        public void Send(InstructionBase pInstruction)
        {
            try
            {
                pInstruction.SetReceiverPublicKey(serverPublicKey);

                OutgoingInstructions.Add(pInstruction);
            }
            catch (Exception ex)
            {
                Debug("Could not add instruction to send-queue.", DebugType.Error);
                if (ShowExceptions)
                {
                    Debug($"({ex.GetType().Name}) {ex.Message}", DebugType.Exception);
                }
            }
        }
예제 #5
0
        /// <summary>
        /// Sends an instruction to a range of users.
        /// </summary>
        /// <param name="pInstruction">Instruction to send. Set the receiver-parameter to 'null'</param>
        /// <param name="pUsers">Target users</param>
        public void ListSend(InstructionBase pInstruction, params NetComUser[] pUsers)
        {
            if (!haltActive)
            {
                try
                {
                    for (int i = 0; i < pUsers.Length; i++)
                    {
                        if (!string.IsNullOrEmpty(pUsers[i].Username) && !string.IsNullOrEmpty(pUsers[i].Password))
                        {
                            try
                            {
                                InstructionBase tmpInstruction = pInstruction.Clone();
                                tmpInstruction.Receiver = pUsers[i];

                                Debug($"Queueing message for {tmpInstruction.Receiver.ToString()}.", DebugType.Info);
                                OutgoingInstructions.Add(tmpInstruction);
                            }
                            catch (Exception ex)
                            {
                                Debug("ListSend-Error.", DebugType.Error);
                                if (ShowExceptions)
                                {
                                    Debug($"({ex.GetType().Name}) {ex.Message}", DebugType.Exception);
                                }
                                _logErrorCount++;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Debug("Halting (03)", DebugType.Warning);
                    if (ShowExceptions)
                    {
                        Debug($"({ex.GetType().Name}) {ex.Message}", DebugType.Exception);
                    }
                    if (AutoRestartOnCrash)
                    {
                        HaltAllThreads();
                    }
                }
            }
        }