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 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);
        }
Пример #3
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);
        }
Пример #4
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;
            }
        }
Пример #5
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);
        }
        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);
        }
Пример #7
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);
        }