Ejemplo n.º 1
0
        /// <summary>
        /// shows the menu and processes the selections of the administrator
        /// </summary>
        public static void Menu()
        {
            bool   ReadLineLoopEnd;
            bool   EntryParsedOK;
            String ServerAdminCommand;
            String ConsoleInput;
            String ClientTaskCode;
            String ClientTaskGroup;

            System.Int16 ClientID           = 0;                    // assignment only to make code compile; has no functional implication
            System.Int16 ClientTaskPriority = 1;                    // assignment only to make code compile; has no functional implication

            // label
            // ReadClientID,               used only for repeating invalid command line input
            // ReadClientTaskPriority;     used only for repeating invalid command line input

            DisplayPetraServerInformation();

            //
            // Startup done.
            // From now on just listen on menu commands...
            //
            Console.WriteLine(Environment.NewLine + "-> Press \"m\" for menu.");
            Console.Write(ServerAdminPrompt);

            // ServerAdmin stops after leaving the following loop...!
            ReadLineLoopEnd = false;

            do
            {
                ServerAdminCommand = (Console.ReadLine());

                if (ServerAdminCommand.Length > 0)
                {
                    ServerAdminCommand = ServerAdminCommand.Substring(0, 1);

                    switch (Convert.ToChar(ServerAdminCommand))
                    {
                    case 'm':
                    case 'M':
                        Console.WriteLine(Environment.NewLine + "-> Available commands <-");
                        Console.WriteLine("     c: list connected Clients / C: list disconnected Clients");
                        Console.WriteLine("     d: disconnect a certain Client");
                        Console.WriteLine("     p: perform timed server processing manually now");
                        Console.WriteLine("     q: queue a Client Task for a certain Client");
                        Console.WriteLine("     s: Server Status");

                        if (TLogging.DebugLevel > 0)
                        {
                            Console.WriteLine("     y: show Server memory");
                            Console.WriteLine("     g: perform Server garbage collection (for debugging purposes only!)");
                        }

                        Console.WriteLine("     e: export the database to yml.gz");
                        Console.WriteLine("     i: import a yml.gz, which will overwrite the database");
                        Console.WriteLine("     j: upgrade the database");

                        if (TLogging.DebugLevel > 0)
                        {
                            Console.WriteLine("     r: Mark all Cached Tables for Refreshing");
                        }

                        Console.WriteLine("     o: controlled Server shutdown (gets all connected clients to disconnect)");
                        Console.WriteLine("     u: unconditional Server shutdown (forces 'hard' disconnection of all Clients!)");

                        Console.WriteLine("     x: exit PETRAServerADMIN");
                        Console.Write(ServerAdminPrompt);
                        break;

                    case 'c':
                        Console.WriteLine(Environment.NewLine + "-> Connected Clients <-");
                        Console.WriteLine(TRemote.FormatClientList(false));
                        Console.Write(ServerAdminPrompt);
                        break;

                    case 'C':
                        Console.WriteLine(Environment.NewLine + "-> Disconnected Clients <-");
                        Console.WriteLine(TRemote.FormatClientList(true));
                        Console.Write(ServerAdminPrompt);
                        break;

                    case 'd':
                    case 'D':
                        Console.WriteLine(Environment.NewLine + "-> Disconnect a certain Client <-");

                        if (TRemote.GetClientList().Count > 0)
                        {
                            Console.WriteLine(TRemote.FormatClientList(false));
                            Console.Write("     Enter ClientID: ");
                            ConsoleInput = Console.ReadLine();
                            DisconnectClient(ConsoleInput);
                        }
                        else
                        {
                            Console.WriteLine("  * no Clients connected *");
                        }

                        Console.Write(ServerAdminPrompt);

                        // queue a Client Task for a certain Client
                        break;

                    case 'e':
                    case 'E':
                        Console.WriteLine(Environment.NewLine + "-> Export the database to yml.gz file <-");

                        ExportDatabase();

                        Console.Write(ServerAdminPrompt);

                        // queue a Client Task for a certain Client
                        break;

                    case 'i':
                    case 'I':
                        Console.WriteLine(Environment.NewLine + "-> Restore the database from yml.gz file <-");

                        RestoreDatabase();

                        Console.Write(ServerAdminPrompt);

                        // queue a Client Task for a certain Client
                        break;

                    case 'j':
                        Console.WriteLine(Environment.NewLine + "-> Upgrade the database ...");

                        UpgradeDatabase();

                        break;

                    case 'r':
                    case 'R':
                        Console.WriteLine(Environment.NewLine + "-> Marking all Cached Tables for Refreshing... <-");

                        RefreshAllCachedTables();

                        Console.Write(ServerAdminPrompt);

                        break;

                    case 'p':
                    case 'P':
#if TODORemoting
                        string resp = "";

                        Console.WriteLine("  Server Timed Processing Status: " +
                                          "runs daily at " + TRemote.GetTimedProcessingDailyStartTime24Hrs + ".");
                        Console.WriteLine("    Partner Reminders: " +
                                          (TRemote.TimedProcessingJobEnabled("TProcessPartnerReminders") ? "On" : "Off"));
                        Console.WriteLine("    Automatic Intranet Export: " +
                                          (TRemote.TimedProcessingJobEnabled("TProcessAutomatedIntranetExport") ? "On" : "Off"));
                        Console.WriteLine("    Data Checks: " + (TRemote.TimedProcessingJobEnabled("TProcessDataChecks") ? "On" : "Off"));

                        Console.WriteLine("  SMTP Server used for sending e-mails: " + TRemote.SMTPServer);

                        if (TRemote.TimedProcessingJobEnabled("TProcessPartnerReminders"))
                        {
                            Console.WriteLine("");
                            Console.WriteLine("Do you want to run Reminder Processing now?");
                            Console.Write("Type YES to continue, anything else to skip:");
                            resp = Console.ReadLine();

                            if (resp == "YES")
                            {
                                TRemote.PerformTimedProcessingNow("TProcessPartnerReminders");
                            }
                        }

                        if (TRemote.TimedProcessingJobEnabled("TProcessAutomatedIntranetExport"))
                        {
                            Console.WriteLine("");
                            Console.WriteLine("Do you want to run Intranet Export Processing now?");
                            Console.Write("Type YES to continue, anything else to skip:");
                            resp = Console.ReadLine();

                            if (resp == "YES")
                            {
                                TRemote.PerformTimedProcessingNow("TProcessAutomatedIntranetExport");
                            }
                        }

                        if (TRemote.TimedProcessingJobEnabled("TProcessDataChecks"))
                        {
                            Console.WriteLine("");
                            Console.WriteLine("Do you want to run Data Checks Processing now?");
                            Console.Write("Type YES to continue, anything else to skip:");
                            resp = Console.ReadLine();

                            if (resp == "YES")
                            {
                                TRemote.PerformTimedProcessingNow("TProcessDataChecks");
                            }
                        }
                        Console.Write(ServerAdminPrompt);
#endif
                        break;

                    case 's':
                    case 'S':
                        Console.WriteLine(Environment.NewLine + "-> Server Status <-");
                        Console.WriteLine();

                        DisplayPetraServerInformation();

                        Console.Write(ServerAdminPrompt);

                        break;

                    case 'q':
                    case 'Q':
                        Console.WriteLine(Environment.NewLine + "-> Queue a Client Task for a certain Client <-");

                        if (TRemote.GetClientList().Count > 0)
                        {
                            Console.WriteLine(TRemote.FormatClientList(false));

                            // ReadClientID:
                            Console.Write("     Enter ClientID: ");
                            ConsoleInput  = Console.ReadLine();
                            EntryParsedOK = false;
                            try
                            {
                                ClientID      = System.Int16.Parse(ConsoleInput);
                                EntryParsedOK = true;
                            }
                            catch (System.FormatException)
                            {
                                Console.WriteLine("  Entered ClientID is not numeric!");
                            }

                            if (!EntryParsedOK)
                            {
                            }

                            // goto ReadClientID;
                            Console.Write("     Enter Client Task Group: ");
                            ClientTaskGroup = Console.ReadLine();
                            Console.Write("     Enter Client Task Code: ");
                            ClientTaskCode = Console.ReadLine();

                            // ReadClientTaskPriority:
                            Console.Write("     Enter Client Task Priority: ");
                            ConsoleInput       = Console.ReadLine();
                            ClientTaskPriority = -1;
                            try
                            {
                                ClientTaskPriority = System.Int16.Parse(ConsoleInput);
                                EntryParsedOK      = true;
                            }
                            catch (System.FormatException)
                            {
                                Console.WriteLine("  Entered Client Task Priority is not numeric!");
                                EntryParsedOK = false;
                            }

                            if (!EntryParsedOK)
                            {
                            }

                            // goto ReadClientTaskPriority;
                            try
                            {
                                if (TRemote.QueueClientTask(ClientID, ClientTaskGroup, ClientTaskCode, ClientTaskPriority))
                                {
                                    TLogging.Log("Client Task queued for Client #" + ClientID.ToString() + " on admin request.");
                                }
                                else
                                {
                                    TLogging.Log("Client Task for Client #" + ClientID.ToString() + " could not be queued on admin request.");
                                }
                            }
                            catch (Exception exp)
                            {
                                TLogging.Log(
                                    Environment.NewLine + "Exception occured while queueing a Client Task on admin request:" +
                                    Environment.NewLine +
                                    exp.ToString());
                            }
                        }
                        else
                        {
                            Console.WriteLine("  * no Clients connected *");
                        }

                        Console.Write(ServerAdminPrompt);
                        break;

                    case 'y':
                    case 'Y':
                        Console.WriteLine("Server memory: " + TRemote.GetServerInfoMemory().ToString());
                        Console.Write(ServerAdminPrompt);
                        break;

                    case 'g':
                    case 'G':
                        GC.Collect();
                        Console.WriteLine("GarbageCollection performed. Server memory: " + TRemote.PerformGC().ToString());
                        Console.Write(ServerAdminPrompt);
                        break;

                    case 'o':
                    case 'O':
                        ReadLineLoopEnd = ShutDownControlled(true);
                        break;

                    case 'u':
                    case 'U':
                        ReadLineLoopEnd = ShutDown(true);
                        break;

                    case 'x':
                    case 'X':

                        // exit loop, ServerAdmin stops then
                        ReadLineLoopEnd = true;
                        break;

                    default:
                        Console.WriteLine(Environment.NewLine + "-> Unrecognised command '" + ServerAdminCommand + "' <-   (Press 'm' for menu)");
                        Console.Write(ServerAdminPrompt);
                        break;
                    }

                    // case Convert.ToChar( ServerAdminCommand )
                }
                // if ServerAdminCommand.Length > 0
                else
                {
                    Console.Write(ServerAdminPrompt);
                }
            } while (!(ReadLineLoopEnd == true));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// shows the menu and processes the selections of the administrator
        /// </summary>
        public static void Menu()
        {
            bool   ReadLineLoopEnd;
            bool   EntryParsedOK;
            String ServerAdminCommand;
            String ConsoleInput;
            String ClientTaskCode;
            String ClientTaskGroup;
            String AdministrativeMessage;

            System.Int16 ClientID           = 0;                    // assignment only to make code compile; has no functional implication
            System.Int16 ClientTaskPriority = 1;                    // assignment only to make code compile; has no functional implication

            // label
            // ReadClientID,               used only for repeating invalid command line input
            // ReadClientTaskPriority;     used only for repeating invalid command line input

            DisplayPetraServerInformation();

            //
            // Startup done.
            // From now on just listen on menu commands...
            //
            Console.WriteLine(Environment.NewLine + "-> Press \"m\" for menu.");
            Console.Write(ServerAdminPrompt);

            // ServerAdmin stops after leaving the following loop...!
            ReadLineLoopEnd = false;

            do
            {
                ServerAdminCommand = (Console.ReadLine());

                if (ServerAdminCommand.Length > 0)
                {
                    ServerAdminCommand = ServerAdminCommand.Substring(0, 1);

                    switch (Convert.ToChar(ServerAdminCommand))
                    {
                    case 'm':
                    case 'M':
                        Console.WriteLine(Environment.NewLine + "-> Available commands <-");
                        Console.WriteLine("     c: list connected Clients / C: list disconnected Clients");
                        Console.WriteLine("     d: disconnect a certain Client");
                        Console.WriteLine("     p: perform timed server processing manually now");
                        Console.WriteLine("     q: queue a Client Task for a certain Client");
                        Console.WriteLine("     s: Server Status");

                        if (TLogging.DebugLevel > 0)
                        {
                            Console.WriteLine("     y: show Server memory");
                            Console.WriteLine("     g: perform Server garbage collection (for debugging purposes only!)");
                        }

                        Console.WriteLine("     e: export the database to yml.gz");
                        Console.WriteLine("     i: import a yml.gz, which will overwrite the database");
                        Console.WriteLine("     j: upgrade the database");

                        if (TLogging.DebugLevel > 0)
                        {
                            Console.WriteLine("     r: Mark all Cached Tables for Refreshing");
                        }

                        Console.WriteLine("     a: send administrative message to all connected clients");
                        Console.WriteLine("     o: controlled Server shutdown (gets all connected clients to disconnect)");
                        Console.WriteLine("     u: unconditional Server shutdown (forces 'hard' disconnection of all Clients!)");
#if DEBUG
                        Console.WriteLine("     v: Clear all RDBMS Connection Pools");
#endif
                        Console.WriteLine("     x: exit PETRAServerADMIN");
                        Console.Write(ServerAdminPrompt);
                        break;

                    case 'c':
                        Console.WriteLine(Environment.NewLine + "-> Connected Clients <-");
                        Console.WriteLine(TRemote.FormatClientList(false));
                        Console.Write(ServerAdminPrompt);
                        break;

                    case 'C':
                        Console.WriteLine(Environment.NewLine + "-> Disconnected Clients <-");
                        Console.WriteLine(TRemote.FormatClientList(true));
                        Console.Write(ServerAdminPrompt);
                        break;

                    case 'd':
                    case 'D':
                        Console.WriteLine(Environment.NewLine + "-> Disconnect a certain Client <-");

                        if (TRemote.GetClientList().Count > 0)
                        {
                            Console.WriteLine(TRemote.FormatClientList(false));
                            Console.Write("     Enter ClientID: ");
                            ConsoleInput = Console.ReadLine();
                            DisconnectClient(ConsoleInput);
                        }
                        else
                        {
                            Console.WriteLine("  * no Clients connected *");
                        }

                        Console.Write(ServerAdminPrompt);

                        break;

                    case 'e':
                    case 'E':
                        Console.WriteLine(Environment.NewLine + "-> Export the database to yml.gz file <-");

                        ExportDatabase();

                        Console.Write(ServerAdminPrompt);

                        break;

                    case 'i':
                    case 'I':
                        Console.WriteLine(Environment.NewLine + "-> Restore the database from yml.gz file <-");

                        RestoreDatabase();

                        Console.Write(ServerAdminPrompt);

                        break;

                    case 'j':
                        Console.WriteLine(Environment.NewLine + "-> Upgrade the database ...");

                        UpgradeDatabase();

                        break;

                    case 'r':
                    case 'R':
                        Console.WriteLine(Environment.NewLine + "-> Marking all Cached Tables for Refreshing... <-");

                        RefreshAllCachedTables();

                        Console.Write(ServerAdminPrompt);

                        break;

                    case 'v':
                    case 'V':
                        Console.WriteLine(Environment.NewLine + "-> Clearing all RDBMS Connection Pools... <-");

                        int NumberOfDBConnectionsAfterClearing = ClearConnectionPoolAndGetNumberOfDBConnections();

                        Console.WriteLine(Environment.NewLine + "  Number of DB Connections after clearing all " +
                                          "RDBMS Connection Pools: " + NumberOfDBConnectionsAfterClearing.ToString());

                        Console.Write(ServerAdminPrompt);

                        break;

                    case 'p':
                    case 'P':
                        TRemote.PerformTimedProcessingNow("TProcessPartnerReminders");
                        TRemote.PerformTimedProcessingNow("TProcessDataChecks");

                        Console.Write(ServerAdminPrompt);

                        break;

                    case 's':
                    case 'S':
                        Console.WriteLine(Environment.NewLine + "-> Server Status <-");
                        Console.WriteLine();

                        DisplayPetraServerInformation();

                        Console.Write(ServerAdminPrompt);

                        break;

                    case 'q':
                    case 'Q':
                        Console.WriteLine(Environment.NewLine + "-> Queue a Client Task for a certain Client <-");

                        if (TRemote.GetClientList().Count > 0)
                        {
                            Console.WriteLine(TRemote.FormatClientList(false));

                            // ReadClientID:
                            Console.Write("     Enter ClientID: ");
                            ConsoleInput  = Console.ReadLine();
                            EntryParsedOK = false;
                            try
                            {
                                ClientID      = System.Int16.Parse(ConsoleInput);
                                EntryParsedOK = true;
                            }
                            catch (System.FormatException)
                            {
                                Console.WriteLine("  Entered ClientID is not numeric!");
                            }

                            if (!EntryParsedOK)
                            {
                            }

                            // goto ReadClientID;
                            Console.Write("     Enter Client Task Group: ");
                            ClientTaskGroup = Console.ReadLine();
                            Console.Write("     Enter Client Task Code: ");
                            ClientTaskCode = Console.ReadLine();

                            // ReadClientTaskPriority:
                            Console.Write("     Enter Client Task Priority: ");
                            ConsoleInput       = Console.ReadLine();
                            ClientTaskPriority = -1;
                            try
                            {
                                ClientTaskPriority = System.Int16.Parse(ConsoleInput);
                                EntryParsedOK      = true;
                            }
                            catch (System.FormatException)
                            {
                                Console.WriteLine("  Entered Client Task Priority is not numeric!");
                                EntryParsedOK = false;
                            }

                            if (!EntryParsedOK)
                            {
                            }

                            try
                            {
                                if (TRemote.QueueClientTask(ClientID, ClientTaskGroup, ClientTaskCode, null, null, null, null,
                                                            ClientTaskPriority))
                                {
                                    TLogging.Log("Client Task queued for Client #" + ClientID.ToString() + " on admin request.");
                                }
                                else
                                {
                                    TLogging.Log("Client Task for Client #" + ClientID.ToString() + " could not be queued on admin request.");
                                }
                            }
                            catch (Exception exp)
                            {
                                TLogging.Log(
                                    Environment.NewLine + "Exception occured while queueing a Client Task on admin request:" +
                                    Environment.NewLine +
                                    exp.ToString());
                            }
                        }
                        else
                        {
                            Console.WriteLine("  * no Clients connected *");
                        }

                        Console.Write(ServerAdminPrompt);
                        break;

                    case 'y':
                    case 'Y':
                        Console.WriteLine("Server memory: " + TRemote.GetServerInfoMemory().ToString());
                        Console.Write(ServerAdminPrompt);
                        break;

                    case 'g':
                    case 'G':
                        GC.Collect();
                        Console.WriteLine("GarbageCollection performed. Server memory: " + TRemote.PerformGC().ToString());
                        Console.Write(ServerAdminPrompt);
                        break;

                    case 'a':
                    case 'A':
                        Console.Write("     Enter Administrative Message (leave blank not to send a message): ");
                        AdministrativeMessage = Console.ReadLine();

                        if (AdministrativeMessage.Trim() != String.Empty)
                        {
                            try
                            {
                                if (TRemote.QueueClientTask(-1, SharedConstants.CLIENTTASKGROUP_USERMESSAGE,
                                                            AdministrativeMessage, "MODAL", null, Catalog.GetString("Administrative Message"), null,
                                                            ClientTaskPriority))
                                {
                                    TLogging.Log("Administrative message queued for all connected clients.");
                                }
                                else
                                {
                                    TLogging.Log("An error occured when trying to queue an administrative message for all clients.");
                                }
                            }
                            catch (Exception exp)
                            {
                                TLogging.Log(
                                    Environment.NewLine +
                                    "Exception occured while queueing a Client Task for sending an administrative message on admin request:" +
                                    Environment.NewLine +
                                    exp.ToString());
                            }
                        }

                        Console.Write(ServerAdminPrompt);
                        break;

                    case 'o':
                    case 'O':
                        ReadLineLoopEnd = ShutDownControlled(true);
                        break;

                    case 'u':
                    case 'U':
                        ReadLineLoopEnd = ShutDown(true);
                        break;

                    case 'x':
                    case 'X':

                        // exit loop, ServerAdmin stops then
                        ReadLineLoopEnd = true;
                        break;

                    default:
                        Console.WriteLine(Environment.NewLine + "-> Unrecognised command '" + ServerAdminCommand + "' <-   (Press 'm' for menu)");
                        Console.Write(ServerAdminPrompt);
                        break;
                    }

                    // case Convert.ToChar( ServerAdminCommand )
                }
                // if ServerAdminCommand.Length > 0
                else
                {
                    Console.Write(ServerAdminPrompt);
                }
            } while (!(ReadLineLoopEnd == true));
        }