예제 #1
0
 /// <summary>
 /// Start the training session
 /// </summary>
 /// <returns></returns>
 public int StartTrainingSession()
 {
     User.LastCommand = DateTime.Now;
     if (MM_Database_Connector.oConn == null)
     {
         return(-1);
     }
     else
     {
         try
         {
             using (DbCommand dCmd = MM_Database_Connector.CreateCommand(Settings.Default.DatabaseTrainingStartCommand, MM_Database_Connector.oConn))
             {
                 MM_Database_Connector.AddParameter(dCmd, "UserName", User.UserName);
                 MM_Database_Connector.AddParameter(dCmd, "CurrentDate", DateTime.Now);
                 MM_Database_Connector.AddParameter(dCmd, "MachineName", Environment.MachineName);
                 DbParameter Param = MM_Database_Connector.AddParameter(dCmd, "ID", null);
                 Object      Resp  = dCmd.ExecuteScalar();
                 if (Resp == null)
                 {
                     return(Convert.ToInt32(Param.Value));
                 }
                 else
                 {
                     return(Convert.ToInt32(Resp));
                 }
             }
         }
         catch (Exception ex)
         { return(-1); }
     }
 }
예제 #2
0
        /// <summary>
        /// Load model information
        /// </summary>
        /// <param name="Model"></param>
        /// <returns></returns>
        public byte[] LoadModel(MM_Database_Model Model)
        {
            User.LastReceivedMessage = DateTime.Now;
            MM_Database_Connector.LoadNetworkModelFlatFile();
            return(MM_Database_Connector.MM_Model_File);

            //return OutString;

            /*using (OracleCommand oCmd = new OracleCommand("SELECT TO_CLOB(MMModel) FROM MM_DATABASE_MODEL WHERE ID={ModelNumber}", MM_Oracle_Connector.oConn))
             * using (OracleDataReader oRd = oCmd.ExecuteReader())
             *  while (oRd.Read())
             *      using (StreamReader sRd = new StreamReader(oRd.GetOracleLob(0), Encoding.Unicode))
             *          return sRd.ReadToEnd();
             * return null;*/
        }
예제 #3
0
 /// <summary>
 /// Write out our traning game HTML file
 /// </summary>
 /// <param name="state"></param>
 private static void WriteTrainingGameHtmlFile(object state)
 {
     while (true)
     {
         StringBuilder sB = new StringBuilder();
         using (DbCommand dCmd = MM_Database_Connector.CreateCommand(Settings.Default.TrainingGameQuery, MM_Database_Connector.oConn))
             using (DbDataReader dRd = dCmd.ExecuteReader())
                 while (dRd.Read())
                 {
                     sB.Append(ParseLine(Settings.Default.TrainingGameOutputLine, dRd));
                 }
         File.WriteAllText(Settings.Default.TrainingGameHtmlFile, Resources.TrainingGameHtmlContent.Replace("{Content}", sB.ToString()));
         Thread.Sleep(TimeSpan.FromMinutes(1));
     }
 }
예제 #4
0
 /// <summary>
 /// Update a training informational point
 /// </summary>
 /// <param name="Title"></param>
 /// <param name="NewValue"></param>
 /// <param name="SessionId"></param>
 public bool UpdateTrainingInformation(string Title, float NewValue, int SessionId)
 {
     User.LastCommand = DateTime.Now;
     using (DbCommand dCmd = MM_Database_Connector.CreateCommand(Settings.Default.DatabaseTrainingUpdateCommand.Replace("{Title}", Title), MM_Database_Connector.oConn))
     {
         Object TitleValue = null;
         if (NewValue != 0)
         {
             TitleValue = NewValue;
         }
         MM_Database_Connector.AddParameter(dCmd, "Title", TitleValue);
         MM_Database_Connector.AddParameter(dCmd, "LastUpdate", DateTime.Now);
         MM_Database_Connector.AddParameter(dCmd, "Id", SessionId);
         return(dCmd.ExecuteNonQuery() == 1);
     }
 }
예제 #5
0
        /// <summary>
        /// Load in the collection of notes
        /// </summary>
        /// <returns></returns>
        public MM_Note[] LoadNotes()
        {
            User.LastReceivedMessage = DateTime.Now;

            if (MM_Database_Connector.oConn == null || MM_Database_Connector.oConn.State != System.Data.ConnectionState.Open)
            {
                return(new MM_Note[0]);
            }
            List <MM_Note> OutNotes = new List <MM_Note>();

            using (DbCommand oCmd = MM_Database_Connector.CreateCommand("SELECT * FROM MM_NOTE", MM_Database_Connector.oConn))
                using (DbDataReader oRd = oCmd.ExecuteReader())
                    while (oRd.Read())
                    {
                        OutNotes.Add(new MM_Note(oRd));
                    }
            return(OutNotes.ToArray());
        }
예제 #6
0
 #pragma warning disable 0618
 /// <summary>
 /// Report the most recent note date
 /// </summary>
 /// <returns></returns>
 public DateTime GetMostRecentNoteDate()
 {
     User.LastReceivedMessage = DateTime.Now;
     try
     {
         object Resp;
         using (DbCommand oCmd = MM_Database_Connector.CreateCommand("SELECT MAX(CreatedOn) FROM MM_Note", MM_Database_Connector.oConn))
             Resp = oCmd.ExecuteScalar();
         if (Resp is DateTime)
         {
             return((DateTime)Resp);
         }
         else
         {
             return(DateTime.MinValue);
         }
     }
     catch { return(DateTime.MinValue); }
 }
예제 #7
0
        /// <summary>
        /// Start up the full Macomber Map server
        /// </summary>
        public static void StartServer()
        {
            ApplicationName    = Assembly.GetCallingAssembly().GetCustomAttribute <AssemblyProductAttribute>().Product;
            ApplicationVersion = Assembly.GetCallingAssembly().GetCustomAttribute <AssemblyFileVersionAttribute>().Version;
            MM_Notification.WriteLine(ConsoleColor.Green, ApplicationName + " " + ApplicationVersion + " starting up.");
            MM_Notification.Notify("SERVER: Macomber Map Service starting", "The Macomber Map Service is starting, ConsoleMode=" + Environment.UserInteractive.ToString());
            StartTime = DateTime.Now;

            //Start our EMS TCP listener
            MM_EMSReader_TCP.Initialize();
            MM_EMSReader_File.Initialize();

            //Start our database service
            MM_Database_Connector.StartServer();

            //Start our PI interface
            MM_Historic_Reader.StartServer();

            //If we have commands, pull them in
            DateTime BatchDate = DateTime.Now;

            if (File.Exists(Properties.Settings.Default.CommandFileLocation))
            {
                using (StreamReader sRd = new StreamReader(Properties.Settings.Default.CommandFileLocation))
                    MM_EMSReader_File.ProcessStreamRead(sRd, Properties.Settings.Default.CommandFileLocation, typeof(MM_EMS_Command), ref BatchDate);
            }

            //Start our WCF interfaces
            MacomberMapServerAddress = Settings.Default.MacomberMapServerAddress.Split(',')[0].Replace("localhost", Dns.GetHostEntry(IPAddress.Loopback).HostName);
            ServerURI            = new Uri(MacomberMapServerAddress);
            Instance_MMServer    = StartWCFServer <MM_WCF_Interface>(Settings.Default.MacomberMapServerAddress.Split(','));
            Instance_AdminServer = StartWCFServer <MM_Administrator_Types>(Settings.Default.MacomberMapAdministratorAddress.Split(','));

            ThreadPool.QueueUserWorkItem(new WaitCallback(MeasureSystemState));
            ThreadPool.QueueUserWorkItem(new WaitCallback(SendUDPMessage));
            ThreadPool.QueueUserWorkItem(new WaitCallback(WriteTrainingGameHtmlFile));
            Thread.Sleep(Timeout.Infinite);
        }
예제 #8
0
        /// <summary>
        /// Upload a note, and return the new ID
        /// </summary>
        /// <param name="Note"></param>
        /// <returns></returns>
        public int UploadNote(MM_Note Note)
        {
            User.LastCommand = DateTime.Now;

            if (MM_Database_Connector.oConn == null || MM_Database_Connector.oConn.State != System.Data.ConnectionState.Open)
            {
                return(new Random().Next());
            }
            using (DbCommand oCmd = MM_Database_Connector.CreateCommand(Settings.Default.DatabaseNoteInsertCommand, MM_Database_Connector.oConn))
            {
                oCmd.Prepare();

                MM_Database_Connector.AddParameter(oCmd, "CreatedOn", Note.CreatedOn);
                MM_Database_Connector.AddParameter(oCmd, "Author", Note.Author);
                MM_Database_Connector.AddParameter(oCmd, "Note", Note.Note);
                MM_Database_Connector.AddParameter(oCmd, "AssociatedElement", Note.AssociatedElement);
                MM_Database_Connector.AddParameter(oCmd, "Acknowledged", Note.Acknowledged);
                DbParameter Param = MM_Database_Connector.AddParameter(oCmd, "ID", null);
                Param.Direction = System.Data.ParameterDirection.Output;
                Param.DbType    = System.Data.DbType.Int32;
                oCmd.ExecuteNonQuery();
                return(Convert.ToInt32(oCmd.Parameters["ID"].Value));
            }
        }
예제 #9
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);
        }
예제 #10
0
 /// <summary>
 /// Post coordinate suggestions
 /// </summary>
 /// <param name="Suggestions"></param>
 /// <returns></returns>
 public bool PostCoordinateSuggestions(MM_Coordinate_Suggestion[] Suggestions)
 {
     User.LastCommand = DateTime.Now;
     MM_Database_Connector.PostCoordinateSuggestions(Suggestions);
     return(true);
 }