Пример #1
0
        /// <summary>
        /// Handle message completion
        /// </summary>
        /// <param name="ar"></param>
        private static void MessageSentCompletion(IAsyncResult ar)
        {
            MM_WCF_Interface FoundConnection = (MM_WCF_Interface)ar.AsyncState;

            FoundConnection.User.LastSentMessage = DateTime.Now;
            //MM_Notification.WriteLine(ConsoleColor.Green, "Sent {0} to {1}", "?", FoundConnection.User.UserName);
        }
 /// <summary>
 /// Send a close message to all clients
 /// </summary>
 public void CloseAllClients()
 {
     foreach (MM_WCF_Interface Interface in MM_Server.ConnectedUserList)
     {
         MM_WCF_Interface.SendMessage(Interface.User.UserId, "CloseClient");
     }
 }
 /// <summary>
 /// Send a message to all users
 /// </summary>
 /// <param name="Message"></param>
 /// <param name="MessageSource"></param>
 /// <param name="Icon"></param>
 public void SendMessageToAllClients(string Message, String MessageSource, MessageBoxIcon Icon)
 {
     foreach (MM_WCF_Interface Interface in MM_Server.ConnectedUserList)
     {
         MM_WCF_Interface.SendMessage(Interface.User.UserId, "ReceiveMessage", Message, MessageSource, Icon);
     }
 }
Пример #4
0
 /// <summary>
 /// Send our message internally
 /// </summary>
 /// <param name="SystemGuid"></param>
 /// <param name="ProcedureName"></param>
 /// <param name="Parameters"></param>
 private static void SendMessageInternal(MethodInfo Method, MM_WCF_Interface FoundConnection, object[] parameters)
 {
     try
     {
         Method.Invoke(FoundConnection.ConversationHandler, parameters);
     }
     catch (Exception ex)
     {
         MM_Notification.WriteLine(ConsoleColor.Red, "Error sending {0} to {1}: {2}", Method.Name, FoundConnection.User.UserName, ex.Message);
     }
 }
Пример #5
0
        /// <summary>
        /// Send a command
        /// </summary>
        /// <param name="Command"></param>
        /// <param name="OldValue"></param>
        /// <returns></returns>
        public bool SendCommand(string Command, String OldValue)
        {
            byte[]   OutBytes = new UTF8Encoding(false).GetBytes("#CMD_TYPE,APP,FAM,CMD_NAME,DB,RECORD,FIELD,TEID,VALUE" + Environment.NewLine + Command + Environment.NewLine);
            DateTime SimTime  = MM_Server.SimulatorTimeData.Length == 0 ? DateTime.Now : MM_Server.SimulatorTimeData[0].Simulation_Time;

            if (!String.IsNullOrEmpty(Settings.Default.OperatorCommandTCPAddress))
            {
                try
                {
                    using (TcpClient Client = new TcpClient())
                    {
                        Client.Connect(Settings.Default.OperatorCommandTCPAddress, Settings.Default.OperatorCommandTCPPort);
                        using (NetworkStream nS = Client.GetStream())
                            nS.Write(OutBytes, 0, OutBytes.Length);
                        MM_Notification.WriteLine(ConsoleColor.White, "Sent {1} command to TEDE/TCP: by {0} on {2}. SimTime {3}", User.UserName, Command, DateTime.Now, SimTime);
                        MM_Database_Connector.LogCommand(Command, User, "TCP");
                    }
                }
                catch (Exception ex)
                {
                    MM_Notification.WriteLine(ConsoleColor.Red, "Error sending {1} command to TEDE/TCP: by {0} on {2} SimTime {3}: {4} ", User.UserName, Command, DateTime.Now, SimTime, ex);
                    return(false);
                }
            }

            if (!String.IsNullOrEmpty(Properties.Settings.Default.OperatorCommandPath))
            {
                String[] splStr         = Command.TrimEnd(',').Split(',');
                String   TargetFileName = Path.Combine(Properties.Settings.Default.OperatorCommandPath, ((splStr[0].Equals("REFRESH")) ? "EMS_REFRESH_" : "EMS_COMMANDS_") + RandomGenerator.Next().ToString() + ".csv");
                using (FileStream fS = new FileStream(TargetFileName, FileMode.CreateNew, FileAccess.Write))
                    fS.Write(OutBytes, 0, OutBytes.Length);
                MM_Notification.WriteLine(ConsoleColor.White, "Sent {1} command to TEDE/File: by {0} on {2}. SimTime {3}", User.UserName, Command, DateTime.Now, SimTime);
                MM_Database_Connector.LogCommand(Command, User, "File");
            }

            //Now, write out our command
            MM_EMS_Command[] OutCommands = new MM_EMS_Command[] { new MM_EMS_Command(Command, User.UserName, User.MachineName, SimTime, OldValue) };
            try
            {
                List <String> OutLines = new List <string>();
                if (!File.Exists("EMSCommands.csv"))
                {
                    OutLines.Add(MM_EMS_Command.HeaderLine());
                }

                OutLines.Add(OutCommands[0].BuildLine());
                File.AppendAllLines("EMSCommands.csv", OutLines.ToArray());
            }
            catch (Exception ex)
            {
                MM_Notification.WriteLine(ConsoleColor.Red, "Unable to write out command to local log: {0}", ex);
            }

            //Now, send our commands to all administrators
            if (Properties.Settings.Default.ForwardCommandsToAdminClients)
            {
                foreach (MM_Administrator_Types Interface in MM_Server.ConnectedAdministatorList)
                {
                    try
                    {
                        MM_Administrator_Types.SendMessageToConsole(Interface.ConversationGuid, "AddEMSCommands", new object[] { OutCommands });
                    }
                    catch (Exception ex)
                    {
                        MM_Notification.WriteLine(ConsoleColor.Red, "Unable to send {0} to Admin: {1}", "AddEMSCommands", ex);
                    }
                }
            }

            //Now, send out our commands to all clients
            if (Properties.Settings.Default.ForwardCommandsToERCOTClients)
            {
                foreach (MM_WCF_Interface Interface in MM_Server.ConnectedUserList)
                {
                    if (Interface.User.LoggedOnTime != default(DateTime) && Interface.User.ERCOTUser)
                    {
                        try
                        {
                            MM_WCF_Interface.SendMessage(Interface.User.UserId, "AddEMSCommands", new object[] { OutCommands });
                        }
                        catch (Exception ex)
                        {
                            MM_Notification.WriteLine(ConsoleColor.Red, "Unable to send {0} to {1}: {2}", "AddEMSCommands", Interface.User.UserName, ex);
                        }
                    }
                }
            }
            User.LastCommand = DateTime.Now;
            return(true);
        }
 /// <summary>
 /// Send a close message to a particular client
 /// </summary>
 /// <param name="Client"></param>
 public void CloseClient(MM_User Client)
 {
     MM_WCF_Interface.SendMessage(Client.UserId, "CloseClient");
 }
 /// <summary>
 /// Send a message to our client
 /// </summary>
 /// <param name="User"></param>
 /// <param name="Message"></param>
 /// <param name="MessageSource"></param>
 /// <param name="Icon"></param>
 public void SendMessage(MM_User User, string Message, String MessageSource, MessageBoxIcon Icon)
 {
     MM_WCF_Interface.SendMessage(User.UserId, "ReceiveMessage", Message, MessageSource, Icon);
 }