Esempio n. 1
0
        public string Execute()
        {
            string psl_Script       = "";
            string pslnewCollection = ConfigurationManager.AppSettings["psl_layer"].ToString() + "/newCollection.ps1";

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

            command.Init(data);
            var result = AdminCommandsController.ProccessCommandSub(command);

            // Only add user when the user has entered the user group info
            if (userList != null && userList.Count() > 0)
            {
                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" });
                command.Init(data);
                result += AdminCommandsController.ProccessCommandSub(command);
            }
            CreateDbCollectionEntry(this.brokerFqdn, this.collectionName);
            return(result);
        }
        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));
        }
        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;
            }
        }
Esempio n. 4
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);
        }