public string Execute1()
        {
            try
            {
                string pslsetClientRedirectionSettings = ConfigurationManager.AppSettings["psl_layer"].ToString() + "/setClientRedirectionSettings.ps1";
                string psl_Script = "";
                using (WebClient client = new WebClient())
                {
                    psl_Script = client.DownloadString(pslsetClientRedirectionSettings);
                }
                var isBurstConfigOnlyToSave = (bool)data["SaveOnlyBurstSettings"];

                if (isBurstConfigOnlyToSave)
                {
                    saveConfigToDb();
                }
                else
                {
                    string pslsavecollectionconfig = ConfigurationManager.AppSettings["psl_layer"].ToString() + "/savecollectionconfig.ps1";

                    using (WebClient client = new WebClient())
                    {
                        psl_Script = client.DownloadString(pslsavecollectionconfig);
                    }
                    var command = new ScriptCommand(psl_Script,
                                                    new[] { "ConnectionBroker", "CollectionName", "ActiveSessionLmit",
                                                            "DisconnectFromSession", "EndADisconnectedSession", "EndSession",
                                                            "IdleSessionLimit", "LoadBalancingConcurrentSessionsPerServer" });

                    command.Init(data);
                    command.Execute();

                    saveConfigToDb();

                    // Saving Client Redirection settings
                    command = new ScriptCommand(psl_Script,
                                                new[] { "ConnectionBroker", "CollectionName", "ClientDeviceRedirectionOptions", "ClientPrinterRedirected",
                                                        "ClientPrinterAsDefault", "RDEasyPrintDriverEnabled", "MaxRedirectedMonitors" });

                    command.Init(data);
                    command.Execute();
                }
                this.Result = config;
                return(string.Empty);
            }
            catch (Exception ex)
            {
                ErrorHelper.WriteErrorToEventLog(ex.Message);
                //ErrorHelper.SendExcepToDB(ex, " Execute1",);
                throw ex;
            }
        }
예제 #2
0
        public string Execute()
        {
            string psleditCollectionDescription = ConfigurationManager.AppSettings["psl_layer"].ToString() + "/editCollectionDescription.ps1";

            string psl_Script = "";

            using (WebClient client = new WebClient())
            {
                psl_Script = client.DownloadString(psleditCollectionDescription);
            }
            // Change the description using powershell
            var command = new ScriptCommand(psl_Script,
                                            new[] { "CollectionName", "CollectionDescription", "ConnectionBroker" });

            command.Init(data);

            return(AdminCommandsController.ProccessCommandSub(command));
        }
예제 #3
0
        public string Execute()
        {
            string pslremoveCollection = ConfigurationManager.AppSettings["psl_layer"].ToString() + "/removeCollection.ps1";
            string psl_Script          = "";

            using (WebClient client = new WebClient())
            {
                psl_Script = client.DownloadString(pslremoveCollection);
            }
            // Removing the collection via powershell
            var command = new ScriptCommand(psl_Script,
                                            new[] { "ConnectionBroker", "CollectionName" });

            command.Init(data);
            var result = command.Execute();

            // Removing the collection and its collection burst settings in the DB
            string stm  = "DELETE CollectionBurstSettings WHERE DeploymentFQDN = @fqdn AND CollectionName = @name";
            var    test = ServicesManager.Instance.ExecuteCommand(stm, this.brokerFqdn, this.collectionName);

            return(result);
        }
예제 #4
0
        private CollectionConfig GetRedirectSettings()
        {
            string pslgetClientRediretionSettings = ConfigurationManager.AppSettings["psl_layer"].ToString() + "/getClientRediretionSettings.ps1";
            string psl_Script = "";

            using (WebClient client = new WebClient())
            {
                psl_Script = client.DownloadString(pslgetClientRediretionSettings);
            }
            var command = new ScriptCommand(psl_Script,
                                            new[] { Param1, Param2 }, (psObject, scriptCommand) =>
            {
                var config = new CollectionConfig();
                if (psObject != null)
                {
                    var options = (RDClientDeviceRedirectionOptions)psObject.ClientDeviceRedirectionOptions;
                    config      = new CollectionConfig
                    {
                        AudioVideoPlayback = (options & RDClientDeviceRedirectionOptions.AudioVideoPlayBack) != 0,
                        AudioRecording     = (options & RDClientDeviceRedirectionOptions.AudioRecording) != 0,
                        PlugAndPlay        = (options & RDClientDeviceRedirectionOptions.PlugAndPlayDevice) != 0,
                        SmartCard          = (options & RDClientDeviceRedirectionOptions.SmartCard) != 0,
                        Clipboard          = (options & RDClientDeviceRedirectionOptions.Clipboard) != 0,
                        Drive = (options & RDClientDeviceRedirectionOptions.Drive) != 0,
                        ClientPrinterRedirected  = psObject.ClientPrinterRedirected > 0,
                        ClientPrinterAsDefault   = psObject.ClientPrinterAsDefault > 0,
                        RDEasyPrintDriverEnabled = psObject.RDEasyPrintDriverEnabled > 0,
                        MaxRedirectedMonitors    = psObject.MaxRedirectedMonitors
                    };
                }
                scriptCommand.Result = config;
            });

            command.Init(this.data);
            command.Execute();
            CollectionConfig result = (CollectionConfig)command.Result;

            return(result);
        }
예제 #5
0
        public static ICommand GetCommand(Dictionary <string, object> commandInfo)
        {
            string   psl_Script  = "";
            var      commandName = commandInfo["commandName"].ToString();
            var      commandData = ((JObject)commandInfo["data"]).ToObject <Dictionary <string, object> >();
            ICommand command     = null;

            switch (commandName)
            {
            case "newdeployment":
                command = new NewDeploymentCommand();
                break;

            case "editdepoyment":
                command = new EditDepoyment();
                break;

            case "removedeployment":
                command = new RemoveDeploymentCommand();
                break;

            case "adminNewdDeployment":
                command = new AdminNewDeploymentCommand();
                break;

            case "adminRemovedeployment":
                command = new AdminRemoveDeploymentCommand();
                break;

            case "adminEditDeployment":
                command = new AdminEditDeploymentCommand();
                break;

            case "adminNewCollection":
                command = new AdminNewCollectionCommand();
                break;

            case "adminRemoveCollection":
                command = new AdminRemoveCollectionCommand();
                break;

            case "adminEditCollection":
                command = new AdminEditCollectionCommand();
                break;

            case "adminEditDeploymentBurstSettings":
                command = new AdminEditDeploymentBurstCommand();
                break;

            case "adminEditCollectionConfig":
                command = new AdminEditCollectionConfigCommand();
                break;

            case "addusercollection":
                string psl_path = ConfigurationManager.AppSettings["psl_layer"].ToString() + "/addusercollection.ps1";
                using (WebClient client = new WebClient())
                {
                    psl_Script = client.DownloadString(psl_path);
                }
                command = new ScriptCommand(psl_Script,
                                            new[] { "ConnectionBroker", "CollectionName", "UserGroup" });
                break;

            case "addbulkusercollection":
                string psladdbulkusercollection = ConfigurationManager.AppSettings["psl_layer"].ToString() + "/addbulkusercollection.ps1";

                using (WebClient client = new WebClient())
                {
                    psl_Script = client.DownloadString(psladdbulkusercollection);
                }
                command = new ScriptCommand(psl_Script,
                                            new[] { "ConnectionBroker", "CollectionName", "UserGroupsStr" });
                break;

            case "removeusercollection":
                string pslremoveusercollection = ConfigurationManager.AppSettings["psl_layer"].ToString() + "/removeusercollection.ps1";
                using (WebClient client = new WebClient())
                {
                    psl_Script = client.DownloadString(pslremoveusercollection);
                }
                command = new ScriptCommand(psl_Script,
                                            new[] { "ConnectionBroker", "CollectionName", "UserGroup" });
                break;

            case "addwappcollection":
                string psladdwappcollection = ConfigurationManager.AppSettings["psl_layer"].ToString() + "/addwappcollection.ps1";
                using (WebClient client = new WebClient())
                {
                    psl_Script = client.DownloadString(psladdwappcollection);
                }
                command = new ScriptCommand(psl_Script,
                                            new[] { "ConnectionBroker", "CollectionName", "DisplayName", "FilePath" });
                break;

            case "editwappcollection":
                string psleditwappcollection = ConfigurationManager.AppSettings["psl_layer"].ToString() + "/editwappcollection.ps1";
                using (WebClient client = new WebClient())
                {
                    psl_Script = client.DownloadString(psleditwappcollection);
                }
                command = new ScriptCommand(psl_Script,
                                            new[] { "ConnectionBroker", "CollectionName", "ApplicationName", "DisplayName" });
                break;

            case "addappcollection":
                string psladdappcollection = ConfigurationManager.AppSettings["psl_layer"].ToString() + "/addappcollection.ps1";
                using (WebClient client = new WebClient())
                {
                    psl_Script = client.DownloadString(psladdappcollection);
                }
                command = new ScriptCommand(psl_Script,
                                            new[] { "ConnectionBroker", "CollectionName", "DisplayName" });
                break;

            case "publishdesktop":
                string pslpublishdesktop = ConfigurationManager.AppSettings["psl_layer"].ToString() + "/publishdesktop.ps1";
                using (WebClient client = new WebClient())
                {
                    psl_Script = client.DownloadString(pslpublishdesktop);
                }
                command = new ScriptCommand(psl_Script,
                                            new[] { "ConnectionBroker", "CollectionName" });
                break;

            case "removeappcollection":
                string pslremoveappcollection = ConfigurationManager.AppSettings["psl_layer"].ToString() + "/removeappcollection.ps1";
                using (WebClient client = new WebClient())
                {
                    psl_Script = client.DownloadString(pslremoveappcollection);
                }
                command = new ScriptCommand(psl_Script,
                                            new[] { "ConnectionBroker", "CollectionName", "Alias" });
                break;

            //case "addserver":
            //    command = new ScriptCommand(AdminCommandResource.addserver,
            //        new[] { "ConnectionBroker", "Server"});
            //    break;
            case "addserverimport":
            case "addserver":
                command = new AdminAddDeploymentServers();
                break;

            case "removeserver":
                string pslremoveserver = ConfigurationManager.AppSettings["psl_layer"].ToString() + "/removeserver.ps1";
                using (WebClient client = new WebClient())
                {
                    psl_Script = client.DownloadString(pslremoveserver);
                }
                command = new ScriptCommand(psl_Script,
                                            new[] { "ConnectionBroker", "Server" });
                break;

            case "getAvailableServers":
                string pslgetAvailableServers = ConfigurationManager.AppSettings["psl_layer"].ToString() + "/getAvailableServers.ps1";
                using (WebClient client = new WebClient())
                {
                    psl_Script = client.DownloadString(pslgetAvailableServers);
                }
                command = new ScriptCommand(psl_Script,
                                            new[] { "ConnectionBroker" });
                break;

            case "addCollectionServer":
                string psladdCollectionServer = ConfigurationManager.AppSettings["psl_layer"].ToString() + "/addCollectionServer.ps1";

                using (WebClient client = new WebClient())
                {
                    psl_Script = client.DownloadString(psladdCollectionServer);
                }
                command = new ScriptCommand(psl_Script,
                                            new[] { "ConnectionBroker", "CollectionName", "SessionHost" });
                break;

            case "removeCollectionServer":
                string pslremoveCollectionServer = ConfigurationManager.AppSettings["psl_layer"].ToString() + "/removeCollectionServer.ps1";
                using (WebClient client = new WebClient())
                {
                    psl_Script = client.DownloadString(pslremoveCollectionServer);
                }
                command = new ScriptCommand(psl_Script,
                                            new[] { "ConnectionBroker", "SessionHost" });
                break;

            case "startserver":
                string pslstartserver = ConfigurationManager.AppSettings["psl_layer"].ToString() + "/startserver.ps1";
                using (WebClient client = new WebClient())
                {
                    psl_Script = client.DownloadString(pslstartserver);
                }
                command = new ScriptCommand(psl_Script,
                                            new[] { "ConnectionBroker", "SessionHost" });
                break;

            case "shutdownserveradmin":
                string pslshutdownserver1 = ConfigurationManager.AppSettings["psl_layer"].ToString() + "/shutdownserver1.ps1";
                using (WebClient client = new WebClient())
                {
                    psl_Script = client.DownloadString(pslshutdownserver1);
                }
                command = new ScriptCommand(psl_Script,
                                            new[] { "ConnectionBroker", "SessionHost" });
                break;

            case "shutdownserver":

                string pslshutdownserver = ConfigurationManager.AppSettings["psl_layer"].ToString() + "/shutdownserver.ps1";
                using (WebClient client = new WebClient())
                {
                    psl_Script = client.DownloadString(pslshutdownserver);
                }
                command = new ScriptCommand(psl_Script,
                                            new[] { "ConnectionBroker", "SessionHost" });
                break;

            case "sendmessageserver":
                string pslsendmessageserver = ConfigurationManager.AppSettings["psl_layer"].ToString() + "/sendmessageserver.ps1";
                using (WebClient client = new WebClient())
                {
                    psl_Script = client.DownloadString(pslsendmessageserver);
                }
                command = new ScriptCommand(psl_Script,
                                            new[] { "HostServer", "MessageTitle", "MessageBody", "ConnectionBroker" });
                break;

            case "logOffAllSessions":
                string psllogOffAllSessions = ConfigurationManager.AppSettings["psl_layer"].ToString() + "/logOffAllSessions.ps1";
                using (WebClient client = new WebClient())
                {
                    psl_Script = client.DownloadString(psllogOffAllSessions);
                }
                command = new ScriptCommand(psl_Script,
                                            new[] { "ConnectionBroker", "CollectionName" });
                break;

            case "logOffSelectedSession":
                string psllogOffSelectedSession = ConfigurationManager.AppSettings["psl_layer"].ToString() + "/logOffSelectedSession.ps1";
                using (WebClient client = new WebClient())
                {
                    psl_Script = client.DownloadString(psllogOffSelectedSession);
                }
                command = new ScriptCommand(psl_Script,
                                            new[] { "HostServer", "UnifiedSessionID" });
                break;

            case "disconnectAllSessions":
                string psldisconnectAllSessions = ConfigurationManager.AppSettings["psl_layer"].ToString() + "/disconnectAllSessions.ps1";
                using (WebClient client = new WebClient())
                {
                    psl_Script = client.DownloadString(psldisconnectAllSessions);
                }
                command = new ScriptCommand(psl_Script,
                                            new[] { "ConnectionBroker", "CollectionName" });
                break;

            case "disconnectSelectedSession":
                string psldisconnectSelectedSession = ConfigurationManager.AppSettings["psl_layer"].ToString() + "/disconnectSelectedSession.ps1";
                using (WebClient client = new WebClient())
                {
                    psl_Script = client.DownloadString(psldisconnectSelectedSession);
                }
                command = new ScriptCommand(psl_Script,
                                            new[] { "HostServer", "UnifiedSessionID" });
                break;

            case "sendmessagesession":
                string pslsendmessagesession = ConfigurationManager.AppSettings["psl_layer"].ToString() + "/sendmessagesession.ps1";
                using (WebClient client = new WebClient())
                {
                    psl_Script = client.DownloadString(pslsendmessagesession);
                }
                command = new ScriptCommand(psl_Script,
                                            new[] { "HostServer", "MessageTitle", "MessageBody", "UnifiedSessionID" });
                break;

            case "getappusercollection":
                string pslgetappusercollection = ConfigurationManager.AppSettings["psl_layer"].ToString() + "/getappusercollection.ps1";
                using (WebClient client = new WebClient())
                {
                    psl_Script = client.DownloadString(pslgetappusercollection);
                }
                command = new ScriptCommand(psl_Script,
                                            new[] { "ConnectionBroker", "CollectionName", "Alias" });
                break;

            case "addappusercollection":
                string psladdappusercollection = ConfigurationManager.AppSettings["psl_layer"].ToString() + "/addappusercollection.ps1";
                using (WebClient client = new WebClient())
                {
                    psl_Script = client.DownloadString(psladdappusercollection);
                }
                command = new ScriptCommand(psl_Script,
                                            new[] { "ConnectionBroker", "CollectionName", "Alias", "UserGroup" });
                break;

            case "removeappusercollection":
                string pslremoveappusercollection = ConfigurationManager.AppSettings["psl_layer"].ToString() + "/removeappusercollection.ps1";
                using (WebClient client = new WebClient())
                {
                    psl_Script = client.DownloadString(pslremoveappusercollection);
                }
                command = new ScriptCommand(psl_Script,
                                            new[] { "ConnectionBroker", "CollectionName", "Alias", "UserGroup" });
                break;

            case "addappbulkusercollection":
                string psladdappbulkusercollection = ConfigurationManager.AppSettings["psl_layer"].ToString() + "/addappbulkusercollection.ps1";
                using (WebClient client = new WebClient())
                {
                    psl_Script = client.DownloadString(psladdappbulkusercollection);
                }
                command = new ScriptCommand(psl_Script,
                                            new[] { "ConnectionBroker", "CollectionName", "Alias", "UserGroupsStr" });
                break;

            case "getcollectionconfig":
                command = new GetCollectionConfigCommand(1);
                break;

            case "getcollectionconfigForScaleSettings":
                command = new GetCollectionConfigCommand(2);
                break;

            case "getcollectionconfigForClientSettings":
                command = new GetCollectionConfigCommand(3);
                break;

            case "savecollectionconfig":
                command = new SaveCollectionConfigCommand(1);
                break;

            case "savecollectionconfigForScaleSettings":
                command = new SaveCollectionConfigCommand(2);
                break;

            case "savecollectionconfigForClientSettings":
                command = new SaveCollectionConfigCommand(3);
                break;

            case "getparameters":
                string pslgetparameters = ConfigurationManager.AppSettings["psl_layer"].ToString() + "/getparameters.ps1";
                using (WebClient client = new WebClient())
                {
                    psl_Script = client.DownloadString(pslgetparameters);
                }
                command = new ScriptCommand(psl_Script,
                                            new[] { "ConnectionBroker", "CollectionName", "Alias" }, (psObject, scriptCommand) =>
                {
                    var app                   = new Application();
                    app.Alias                 = psObject.Alias;
                    app.Name                  = psObject.DisplayName;
                    app.NavName               = ApplicationController.GenNavName(psObject.DisplayName);
                    app.Path                  = psObject.FilePath;
                    app.FolderPath            = psObject.FolderName;
                    app.CommandLineParameters = psObject.RequiredCommandLine;
                    app.Status                = "ok";
                    app.Type                  = "applicationType";
                    scriptCommand.Result      = app;
                });
                break;

            case "saveparameters":
                if (!commandData.ContainsKey("RequiredCommandLine") ||
                    string.IsNullOrEmpty(commandData["RequiredCommandLine"] as string))
                {
                    commandData["RequiredCommandLine"] = string.Empty;
                    commandData["CommandLineSetting"]  = "DoNotAllow";
                }
                else
                {
                    commandData["CommandLineSetting"] = "Require";
                }
                string pslsaveparameters = ConfigurationManager.AppSettings["psl_layer"].ToString() + "/saveparameters.ps1";
                using (WebClient client = new WebClient())
                {
                    psl_Script = client.DownloadString(pslsaveparameters);
                }
                command = new ScriptCommand(psl_Script,
                                            new[] { "ConnectionBroker", "CollectionName", "Alias",
                                                    "CommandLineSetting", "RequiredCommandLine", "DisplayName", "FilePath", "FolderPath" });
                break;

            default:
                throw new Exception("Unknown operation: " + commandName);
            }

            command.Init(commandData);
            return(command);
        }
예제 #6
0
        public string Execute()
        {
            CollectionConfig config = new CollectionConfig();

            config.PeakStartTime  = "00:00";
            config.PeakEndTime    = "00:00";
            config.LogoffWaitTime = 0;

            try
            {
                if (operation == 1)
                {
                    var    count = 0;
                    string pslgetcollectionconfig = ConfigurationManager.AppSettings["psl_layer"].ToString() + "/getcollectionconfig.ps1";
                    string psl_Script             = "";
                    using (WebClient client = new WebClient())
                    {
                        psl_Script = client.DownloadString(pslgetcollectionconfig);
                    }
                    var command = new ScriptCommand(psl_Script,
                                                    new[] { Param1, Param2 }, (psObject, scriptCommand) =>
                    {
                        if (count == 0)
                        {
                            if (psObject != null)
                            {
                                config.ActiveSessionLmit       = psObject.ActiveSessionLimitMin == null ? 0 : psObject.ActiveSessionLimitMin;
                                config.DisconnectFromSession   = psObject.DisconnectedSessionLimitMin == null ? 0 : psObject.DisconnectedSessionLimitMin;
                                config.IdleSessionLimit        = psObject.IdleSessionLimitMin == null ? 0 : psObject.IdleSessionLimitMin;
                                config.EndADisconnectedSession = psObject.BrokenConnectionAction == null ? false : psObject.BrokenConnectionAction.ToString().Equals("Logoff", StringComparison.OrdinalIgnoreCase);
                                config.EndSession = psObject.AutomaticReconnectionEnabled == null ? false : psObject.AutomaticReconnectionEnabled;
                            }
                        }
                        else
                        {
                            if (psObject != null)
                            {
                                config.LoadBalancingConcurrentSessionsPerServer = psObject.SessionLimit == null ? 0 : psObject.SessionLimit;
                            }
                        }
                        count++;
                        scriptCommand.Result = config;
                    });

                    command.Init(data);
                    command.Execute();
                    if (config.LoadBalancingConcurrentSessionsPerServer == 999999)
                    {
                        config.LoadBalancingConcurrentSessionsPerServer = 9999;
                    }
                }
                else if (operation == 2)
                {
                    ServicesManager.Instance.ExecuteQuery <CollectionConfig>("SELECT * FROM [CollectionBurstSettings] WHERE DeploymentFQDN = @FQDN AND CollectionName = @Name", (rdr, list) =>
                    {
                        config.PeakStartTime           = TimeSpan.Parse(rdr["StartTime"].ToString()).ToString(@"hh\:mm") ?? "00:00";
                        config.PeakEndTime             = TimeSpan.Parse(rdr["EndTime"].ToString()).ToString(@"hh\:mm") ?? "00:00";
                        config.LogoffWaitTime          = byte.Parse(rdr["LogOffWaitTime"].ToString());
                        config.SessionThreshholdPerCPU = byte.Parse(rdr["SessionThresholdPerCPU"].ToString());
                        config.MinServerCount          = Int16.Parse(rdr["MinServerCount"].ToString());
                    }, deploymentInfo, collectionName);
                }
                else if (operation == 3)
                {
                    // Get the Client Redirection Settings via ScriptCommand/Powershell
                    config = GetRedirectSettings();
                }

                this.Result = config;

                return(string.Empty);
            }
            catch (Exception ex)
            {
                ErrorHelper.WriteErrorToEventLog(ex.Message);
                throw ex;
            }
        }
        public string Execute()
        {
            try
            {
                string psl_Script = "";
                string pslsetClientRedirectionSettings = ConfigurationManager.AppSettings["psl_layer"].ToString() + "/setClientRedirectionSettings.ps1";

                using (WebClient client = new WebClient())
                {
                    psl_Script = client.DownloadString(pslsetClientRedirectionSettings);
                }
                var s = string.Empty;
                if (this.correlationId == null)
                {
                    this.correlationId = Guid.NewGuid().ToString();

                    s = "{\"status\": \"executing\",\"correlationId\":\""
                        + this.correlationId + "\"}";
                    this.Result = s;

                    if (openCommands.TryAdd(correlationId,
                                            new Tuple <string, DateTime?, bool>(null, DateTime.UtcNow, false)))
                    {
                        //var isBurstConfigOnlyToSave = (bool)data["SaveOnlyBurstSettings"];

                        //if (isBurstConfigOnlyToSave)
                        //{
                        //    saveConfigToDb();

                        //    var val = new Tuple<string, DateTime?, bool>(s, DateTime.UtcNow, true);
                        //    openCommands.AddOrUpdate(this.correlationId, val, (x, y) =>
                        //    {
                        //        return val;
                        //    });

                        //    this.PurgeCache();
                        //}
                        //else
                        //{
                        if (operation == 1)
                        {
                            string pslsavecollectionconfig = ConfigurationManager.AppSettings["psl_layer"].ToString() + "/savecollectionconfig.ps1";

                            using (WebClient client = new WebClient())
                            {
                                psl_Script = client.DownloadString(pslsavecollectionconfig);
                            }
                            var command = new ScriptCommand(psl_Script,
                                                            new[] { "ConnectionBroker", "CollectionName", "ActiveSessionLmit",
                                                                    "DisconnectFromSession", "EndADisconnectedSession", "EndSession",
                                                                    "IdleSessionLimit", "LoadBalancingConcurrentSessionsPerServer" });

                            command.Init(data);

                            s += AdminCommandsController.ProccessCommandSub(command);
                        }
                        else if (operation == 2)
                        {
                            saveConfigToDb();
                        }
                        else if (operation == 3)
                        {
                            // Saving Client Redirection settings
                            var command = new ScriptCommand(psl_Script,
                                                            new[] { "ConnectionBroker", "CollectionName", "ClientDeviceRedirectionOptions", "ClientPrinterRedirected",
                                                                    "ClientPrinterAsDefault", "RDEasyPrintDriverEnabled", "MaxRedirectedMonitors" });

                            command.Init(data);
                            s += AdminCommandsController.ProccessCommandSub(command);

                            var val = new Tuple <string, DateTime?, bool>(s, DateTime.UtcNow, true);
                            openCommands.AddOrUpdate(this.correlationId, val, (x, y) =>
                            {
                                return(val);
                            });

                            this.PurgeCache();
                        }

                        //Commented Threading part to get the results synchronously
                        // System.Threading.ThreadPool.QueueUserWorkItem((state) =>
                        //  {



                        // });
                        //}
                    }
                    else
                    {
                        s = "{\"status\": \"executing\",\"correlationId\":\""
                            + this.correlationId + "\"}";
                        this.Result = s;
                    }
                }
                else
                {
                    Tuple <string, DateTime?, bool> current = null;
                    if (!openCommands.TryGetValue(this.correlationId, out current))
                    {
                        s = "{\"status\": \"correlation id not found\"}";
                    }
                    else if (current.Item3)
                    {
                        openCommands.TryRemove(this.correlationId, out current);
                        s = current.Item1;
                    }
                    else
                    {
                        s = @"{""status"": ""executing"",""correlationId"": """ + this.correlationId + @"""}";
                    }
                }

                this.Result = s;
                return(s);
            }
            catch (Exception ex)
            {
                ErrorHelper.WriteErrorToEventLog(ex.Message);
                throw ex;
            }
        }
예제 #8
0
        public string Execute()
        {
            string res            = "";
            string psl_Script     = "";
            string validatebroker = string.Empty;
            string pslvalidateconnectionbroker = ConfigurationManager.AppSettings["psl_layer"].ToString() + "/validateconnectionbroker.ps1";

            using (WebClient client = new WebClient())
            {
                psl_Script = client.DownloadString(pslvalidateconnectionbroker);
            }
            var commands = new ScriptCommand(psl_Script, new[] { "strbroker" },
                                             (psObject, scriptCommand) =>
            {
                validatebroker = (psObject.message as string);
            });
            var vdata = new Dictionary <string, object> {
                { "strbroker", brokerfqdn }
            };

            commands.Init(vdata);
            commands.Execute();

            if (validatebroker == "Success")
            {
                string validateAzurecredentials    = string.Empty;
                string pslvalidateAzurecredentials = ConfigurationManager.AppSettings["psl_layer"].ToString() + "/azureloginvalidation.ps1";

                using (WebClient client = new WebClient())
                {
                    psl_Script = client.DownloadString(pslvalidateAzurecredentials);
                }
                var aCommand = new ScriptCommand(psl_Script, new[] { "Auname", "Apassword", "subid", "ResourceGroupPassed" },
                                                 (psObject, scriptCommand) =>
                {
                    validateAzurecredentials = (psObject.message as string);
                });
                var vadata = new Dictionary <string, object> {
                    { "Auname", AzureLoginName }, { "Apassword", AzurePassword }, { "subid", AzureSubscriptionID }, { "ResourceGroupPassed", AzureResourceGroup }
                };
                aCommand.Init(vadata);
                aCommand.Execute();
                if (validateAzurecredentials == "Success")
                {
                    string pslencryptString = ConfigurationManager.AppSettings["psl_layer"].ToString() + "/encryptString.ps1";
                    using (WebClient client = new WebClient())
                    {
                        psl_Script = client.DownloadString(pslencryptString);
                    }
                    string stm       = "INSERT INTO Deployments(Id, Name, FQDN) VALUES(@Id, @Name, @FQDN)";
                    var    updateNum = ServicesManager.Instance.ExecuteCommand(stm, this.id, this.friendlyName, this.brokerfqdn);
                    if (updateNum == 0)
                    {
                        res = "Error adding deployment.";
                    }
                    else
                    {
                        string encryptedPassword = string.Empty;
                        if (!string.IsNullOrEmpty(AzurePassword))
                        {
                            // Encrypt the password before saving it in the DB
                            var command = new ScriptCommand(psl_Script, new[] { "String", "SecureString" },
                                                            (psObject, scriptCommand) =>
                            {
                                encryptedPassword = psObject.ToString();
                            });
                            var data = new Dictionary <string, object> {
                                { "String", "1234" }, { "SecureString", GetSecureString(AzurePassword) }
                            };
                            command.Init(data);
                            command.Execute();
                        }
                        // Adding a deployment burst settings to this new deployment in the DeploymentBurstSettings Table
                        stm = "INSERT INTO DeploymentBurstSettings(DeploymentFQDN, IsActive, PublishUserName, PublishPassword,"
                              + " AzureSubscriptionName, ResourceGroupName, CreatedDate, LastModifiedDate)"
                              + " VALUES(@DeploymentFQDN, 0,@AzureLoginName,@AzurePassword,@AzureSubscriptionID,@AzureResourceGroup,@CreatedDate, @LastModifiedDate)";
                        if (0 == ServicesManager.Instance.ExecuteCommand(stm, brokerfqdn, AzureLoginName, encryptedPassword, AzureSubscriptionID, AzureResourceGroup, DateTime.Now, DateTime.Now))
                        {
                            res = "Error adding burst settings to DeploymentBurstSettings Table for deployment " + brokerfqdn;
                        }
                        else
                        {
                            res = "Success";
                        }
                    }
                }
                else
                {
                    res = validateAzurecredentials;
                }
            }
            else
            {
                res = "Invalid connection broker " + brokerfqdn;
            }
            this.Result = res;
            return(res);
        }
예제 #9
0
        public string Execute()
        {
            try
            {
                string psladdserver = ConfigurationManager.AppSettings["psl_layer"].ToString() + "/addserver.ps1";

                string psl_Script = "";
                using (WebClient client = new WebClient())
                {
                    psl_Script = client.DownloadString(psladdserver);
                }
                var s = string.Empty;
                if (this.coorelationId == null)
                {
                    this.coorelationId = Guid.NewGuid().ToString();

                    s = "{\"status\": \"executing\",\"coorelationId\":\""
                        + this.coorelationId + "\"}";
                    this.Result = s;

                    if (openCommands.TryAdd(coorelationId,
                                            new Tuple <string, DateTime?, bool>(null, DateTime.UtcNow, false)))
                    {
                        System.Threading.ThreadPool.QueueUserWorkItem((state) =>
                        {
                            Parallel.ForEach(this.Servers, server =>
                            {
                                var data = new Dictionary <string, object> {
                                    { "ConnectionBroker", brokerFqdn }, { "Server", server }
                                };
                                var command = new ScriptCommand(psl_Script,
                                                                new[] { "ConnectionBroker", "Server" });
                                command.Init(data);
                                s += AdminCommandsController.ProccessCommandSub(command);
                            });

                            var val = new Tuple <string, DateTime?, bool>(s, DateTime.UtcNow, true);
                            openCommands.AddOrUpdate(this.coorelationId, val, (x, y) =>
                            {
                                return(val);
                            });

                            this.PurgeCache();
                        });

                        //s = "{\"status\": \"unable to execute\"}";
                    }
                    else
                    {
                        s = "{\"status\": \"executing\",\"coorelationId\":\""
                            + this.coorelationId + "\"}";
                        this.Result = s;
                    }
                }
                else
                {
                    Tuple <string, DateTime?, bool> current = null;
                    if (!openCommands.TryGetValue(this.coorelationId, out current))
                    {
                        s = "{\"status\": \"coorelation id not found\"}";
                    }
                    else if (current.Item3)
                    {
                        openCommands.TryRemove(this.coorelationId, out current);
                        s = current.Item1;
                    }
                    else
                    {
                        s = @"{""status"": ""executing"",""coorelationId"": """ + this.coorelationId + @"""}";
                    }
                }

                this.Result = s;
                return(s);
            }
            catch (Exception ex)
            {
                ErrorHelper.WriteErrorToEventLog(ex.Message);
                throw ex;
            }
        }
        public string Execute()
        {
            ScriptCommand command;
            Dictionary <string, object> data;
            string msg        = string.Empty;
            string psl_Script = "";

            try
            {
                // Saving User Profile Disk Settings
                if (EnableUserProfileDisks)
                {
                    string Validatesharedfileloc    = string.Empty;
                    string pslValidatesharedfileloc = ConfigurationManager.AppSettings["psl_layer"].ToString() + "/Validatesharedfileloc.ps1";
                    using (WebClient client = new WebClient())
                    {
                        psl_Script = client.DownloadString(pslValidatesharedfileloc);
                    }
                    var aCommand = new ScriptCommand(psl_Script, new[] { "FileServer" },
                                                     (psObject, scriptCommand) =>
                    {
                        Validatesharedfileloc = (psObject.message as string);
                    });
                    var vadata = new Dictionary <string, object> {
                        { "FileServer", UserProfileDisksLocation }
                    };
                    aCommand.Init(vadata);
                    aCommand.Execute();
                    if (Validatesharedfileloc == "Success")
                    {
                        string pslenableUserProfileDisk = ConfigurationManager.AppSettings["psl_layer"].ToString() + "/enableUserProfileDisk.ps1";

                        using (WebClient client = new WebClient())
                        {
                            psl_Script = client.DownloadString(pslenableUserProfileDisk);
                        }
                        command = new ScriptCommand(psl_Script,
                                                    new[] { "ConnectionBroker", "CollectionName", "DiskPath", "MaxUserProfileDiskSizeGB" });
                        data = new Dictionary <string, object> {
                            { "ConnectionBroker", DeploymentFqdn }, { "CollectionName", CollectionName },
                            { "DiskPath", UserProfileDisksLocation }, { "MaxUserProfileDiskSizeGB", UserProfileDisksMaxSizeGB }
                        };
                        command.Init(data);
                        var result = AdminCommandsController.ProccessCommandSub(command);
                        msg = "Success";
                    }
                    else
                    {
                        msg = "Invalid User Profile Disks Location";
                    }
                }
                else
                {
                    string psldisableUserProfileDisk = ConfigurationManager.AppSettings["psl_layer"].ToString() + "/disableUserProfileDisk.ps1";
                    using (WebClient client = new WebClient())
                    {
                        psl_Script = client.DownloadString(psldisableUserProfileDisk);
                    }
                    command = new ScriptCommand(psl_Script,
                                                new[] { "ConnectionBroker", "CollectionName" });
                    data = new Dictionary <string, object> {
                        { "ConnectionBroker", DeploymentFqdn }, { "CollectionName", CollectionName }
                    };
                    command.Init(data);
                    var result = AdminCommandsController.ProccessCommandSub(command);
                    msg = "Success";
                }
                //// Try update Collection Burst IsActive field in the databsae, if not, create corresponding entries in the DB
                //string stm = @"UPDATE CollectionBurstSettings SET IsActive = @IsActive
                //              WHERE DeploymentFQDN=@DeploymentFQDN AND CollectionName=@Name";
                //if (0 == DBHelper.ExecuteCommand(stm, IsBurstActive, this.DeploymentFqdn, this.CollectionName))
                //{
                //    AdminNewCollectionCommand.CreateDbCollectionEntry(this.DeploymentFqdn, this.CollectionName, IsBurstActive);
                //}
            }
            catch (Exception ex)
            {
                ErrorHelper.WriteErrorToEventLog(ex.Message);
                //ErrorHelper.SendExcepToDB(ex, "Execute", DeploymentFqdn);
                msg = ex.Message;
            }
            this.Result = msg;
            return(msg);
        }
예제 #11
0
        public string Execute()
        {
            string res        = "";
            string psl_Script = "";
            string validateAzurecredentials = string.Empty;

            if (IsActive)
            {
                string pslvalidateAzurecredentials = ConfigurationManager.AppSettings["psl_layer"].ToString() + "/azureloginvalidation.ps1";
                using (WebClient client = new WebClient())
                {
                    psl_Script = client.DownloadString(pslvalidateAzurecredentials);
                }
                var aCommand = new ScriptCommand(psl_Script, new[] { "Auname", "Apassword", "subid", "ResourceGroupPassed" },
                                                 (psObject, scriptCommand) =>
                {
                    validateAzurecredentials = (psObject.message as string);
                });
                var vadata = new Dictionary <string, object> {
                    { "Auname", PublishUserName }, { "Apassword", PublishPassword }, { "subid", AzureSubscriptionName }, { "ResourceGroupPassed", ResourceGroupName }
                };
                aCommand.Init(vadata);
                aCommand.Execute();
            }
            else
            {
                validateAzurecredentials = "Success";
            }
            if (validateAzurecredentials == "Success")
            {
                string pslencryptString = ConfigurationManager.AppSettings["psl_layer"].ToString() + "/encryptString.ps1";
                using (WebClient client = new WebClient())
                {
                    psl_Script = client.DownloadString(pslencryptString);
                }
                string encryptedPassword = string.Empty;
                if (!string.IsNullOrEmpty(PublishPassword))
                {
                    // Encrypt the password before saving it in the DB
                    var command = new ScriptCommand(psl_Script, new[] { "String", "SecureString" },
                                                    (psObject, scriptCommand) =>
                    {
                        encryptedPassword = psObject.ToString();
                    });
                    var data = new Dictionary <string, object> {
                        { "String", encryptionKey }, { "SecureString", GetSecureString(PublishPassword) }
                    };
                    command.Init(data);
                    command.Execute();
                }

                // Update deployment burst settings in database & propogate the status to collections burst settings
                this.LastModifiedDate = DateTime.Now;
                if (!IsActive)
                {
                    var inactive = @"UPDATE DeploymentBurstSettings SET IsActive = 0, LastModifiedDate = @LastModifiedDate WHERE DeploymentFQDN = @DeploymentFQDN";
                    if (0 >= ServicesManager.Instance.ExecuteCommand(inactive, LastModifiedDate, DeploymentFQDN))
                    {
                        res = "Error updating deployment burst settings.";
                    }
                    else
                    {
                        res = "Success";
                    }
                }
                else
                {
                    string stm = @"UPDATE DeploymentBurstSettings 
                              SET IsActive = 1,
                                  PublishUserName = @PublishUserName,
                                  PublishPassword = @PublishPassword,
                                  AzureSubscriptionName = @AzureSubscriptionName,
                                  ResourceGroupName = @ResourceGroupName,
                                  LastModifiedDate = @LastModifiedDate
                              WHERE DeploymentFQDN = @DeploymentFQDN";
                    if (0 >= ServicesManager.Instance.ExecuteCommand(stm, PublishUserName, encryptedPassword, AzureSubscriptionName,
                                                                     ResourceGroupName, LastModifiedDate, DeploymentFQDN))
                    {
                        res = "Error updating deployment burst settings.";
                    }
                    else
                    {
                        res = "Success";
                    }
                }
            }
            else
            {
                res = validateAzurecredentials;
            }
            this.Result = res;
            return(res);
        }