示例#1
0
        public void NewRDFunc(dynamic psObject, List <RDServer> serverList)
        {
            var server = new RDServer();

            server.Name       = psObject.Name;
            server.Status     = psObject.Status;
            server.Collection = psObject.Collection;
            server.Type       = psObject.Type[0] + " RDSH";
            serverList.Add(server);
        }
示例#2
0
        public void NewFunc(dynamic psObject, List <RDServer> serverList)
        {
            var server = new RDServer();

            server.Name   = psObject.Server;
            server.Status = psObject.Status;
            server.Roles  = new List <string>(psObject.Roles).Aggregate((inProgress, next) => inProgress + ", " + next);
            server.Status = "Unknown";
            serverList.Add(server);
        }
示例#3
0
        /// <summary>
        /// Get a list of available Session Host Servers that are not a part of any collections under the given deployment name
        /// </summary>
        /// <param name="deploymentName">Deployment FQDN name</param>
        /// <returns>List of available Session Host Servers that are not a part of any collections under the given deployment name</returns>
        private List <RDServer> GetFreeSessionHostServers(string deploymentName)
        {
            try
            {
                string pslgetAvailableServers = ConfigurationManager.AppSettings["psl_layer"].ToString() + "/getAvailableServers.ps1";
                string psl_Script             = "";
                using (WebClient client = new WebClient())
                {
                    psl_Script = client.DownloadString(pslgetAvailableServers);
                }
                // Get the available Session Host Servers via ScriptCommand/Powershell
                var command = new ScriptCommand(psl_Script, new[] { "ConnectionBroker" }, (psObject, scriptCommand) =>
                {
                    if (scriptCommand.Result == null)
                    {
                        scriptCommand.Result = new List <RDServer>();
                    }
                    var server = new RDServer {
                        Name = psObject.Server, Type = psObject.Type + " RDSH"
                    };
                    var servers = (List <RDServer>)scriptCommand.Result;
                    servers.Add(server);
                });
                var data = new Dictionary <string, object> {
                    { "ConnectionBroker", deploymentName }
                };
                command.Init(data);
                command.Execute();

                return((List <RDServer>)command.Result ?? new List <RDServer>());
            }
            catch (Exception ex)
            {
                ErrorHelper.SendExcepToDB(ex, " GetFreeSessionHostServers", deploymentName);
                throw ex;
            }
        }
示例#4
0
    static void Main(string[] args)
    {
        string          strTab        = "\t";
        string          AppPath       = AppDomain.CurrentDomain.BaseDirectory;
        string          cfgServers    = AppPath + "servers.txt";
        List <RDServer> myServers     = new List <RDServer>();
        int             clientCounter = 0;

        if (File.Exists(cfgServers))
        {
            try
            {
                var ServerList = System.IO.File.ReadAllLines(cfgServers);
                foreach (var Server in ServerList)
                {
                    if (Server.Length > 0)
                    {
                        Console.WriteLine("Collecting Sessions from " + Server);

                        List <TerminalSessionData> mySessions = new List <TerminalSessionData>();
                        mySessions = TermServicesManager.ListSessions(Server);

                        RDServer         myRDServer = new RDServer();
                        List <RDSession> RDSessions = new List <RDSession>();

                        myRDServer.Servername = Server;

                        foreach (var mySession in mySessions)
                        {
                            if (mySession.ConnectionState == TermServicesManager.WTS_CONNECTSTATE_CLASS.Active)
                            {
                                RDSession myRDSession = new RDSession();

                                myRDSession.Clientname       = TermServicesManager.GetSessionInfo(Server, mySession.SessionId).ClientName;
                                myRDSession.Username         = TermServicesManager.GetSessionInfo(Server, mySession.SessionId).UserName;
                                myRDSession.SessionID        = TermServicesManager.GetSessionInfo(Server, mySession.SessionId).SessionId;
                                clientCounter                = clientCounter + 1;
                                myRDSession.overallSessionID = clientCounter;
                                RDSessions.Add(myRDSession);
                            }
                        }

                        myRDServer.Sessions = RDSessions;
                        myServers.Add(myRDServer);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("{0} Exception caught.", e);
                Environment.Exit(1);
            }
            // Error: Use of unassigned local variable 'n'.
        }

        Console.WriteLine(".. finished collecting.");

        foreach (var Server in myServers)
        {
            foreach (var Session in Server.Sessions)
            {
                Console.WriteLine("ID: " + Session.overallSessionID + strTab + Server.Servername + "-Session#" + Session.SessionID + strTab + Session.Username + strTab + Session.Clientname);
            }
        }

        string cInput = "";

        Console.WriteLine("ID zur fernsteuerung eingeben/mit Befehl exit beenden: (funktioniert noch nicht)");

        do
        {
            cInput = Console.ReadLine();

            if (IsNumeric(cInput))
            {
                Console.WriteLine("Versuche Session " + cInput + " zu starten...");

                int InputSessionID;

                Int32.TryParse(cInput, out InputSessionID);

                foreach (var Server in myServers)
                {
                    foreach (var Session in Server.Sessions)
                    {
                        if (Session.overallSessionID == InputSessionID)
                        {
                            System.Diagnostics.Process          process   = new System.Diagnostics.Process();
                            System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
                            startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
                            startInfo.FileName    = "mstsc.exe";
                            startInfo.Arguments   = "/v: " + Server.Servername + " /shadow:" + Session.SessionID;
                            process.StartInfo     = startInfo;
                            process.Start();
                        }
                    }
                }
            }
            else
            {
                Console.WriteLine("Nummer.. sonst nix.. bitte: ");
            }
        } while (cInput != "exit");
    }