示例#1
0
        public override int Run(string[] args)
        {
            _logger = new Logger(Verbose);

            if (!Overwrite && Directory.Exists(ScriptDir))
            {
                if (!ConsoleQuestion.AskYN($"{ScriptDir} already exists - do you want to replace it"))
                {
                    return(1);
                }
            }

            var scriptCommand = new ScriptCommand {
                ConnectionString = ConnectionString,
                DbName           = DbName,
                Pass             = Pass,
                ScriptDir        = ScriptDir,
                Server           = Server,
                User             = User,
                Logger           = _logger,
                Overwrite        = Overwrite
            };

            var filteredTypes   = HandleFilteredTypes();
            var namesAndSchemas = HandleDataTables(DataTables);

            try {
                scriptCommand.Execute(namesAndSchemas, DataTablesPattern, DataTablesExcludePattern, TableHint, filteredTypes);
            } catch (Exception ex) {
                throw new ConsoleHelpAsException(ex.ToString());
            }
            return(0);
        }
示例#2
0
        public async Task <List <Server> > GetServer(string deploymentName, string collectionName)
        {
            string pslgetcollectionserver = ConfigurationManager.AppSettings["psl_layer"].ToString() + "/getcollectionserver.ps1";
            string psl_Script             = "";

            using (WebClient client = new WebClient())
            {
                psl_Script = client.DownloadString(pslgetcollectionserver);
            }
            var command = new ScriptCommand(psl_Script, new[] { "ConnectionBroker", "CollectionName" },
                                            (psObject, scriptCommand) =>
            {
                if (scriptCommand.Result == null)
                {
                    scriptCommand.Result = new List <Server>();
                }
                var server = new Server {
                    Name = psObject.SessionHost
                };
                var servers = (List <Server>)scriptCommand.Result;
                servers.Add(server);
            });
            var data = new Dictionary <string, object> {
                { "ConnectionBroker", deploymentName }, { "CollectionName", collectionName }
            };

            command.Init(data);
            command.Execute();
            return((List <Server>)command.Result ?? new List <Server>());
        }
示例#3
0
        public async Task <string> GetPSDate()
        {
            try
            {
                ICommand commandI = null;

                //string bodyText = await this.Request.Content.ReadAsStringAsync();
                //var data = JsonConvert.DeserializeObject<Dictionary<string, object>>(JsonConvert.DeserializeObject(bodyText).ToString());
                commandI = new ScriptCommand(AWSCommandResource.getProcessNew, new[] { "Id" });
                Dictionary <string, object> commandData = new Dictionary <string, object>();
                commandData.Add("Id", "temp");
                commandI.Init(commandData);
                commandI.Execute();
                if (commandI.Result != null)
                {
                    return(JsonConvert.SerializeObject(commandI.Result, Formatting.Indented));
                }
                else
                {
                    return(string.Empty);
                }
            }
            catch (Exception ex)
            {
                //ErrorHelper.WriteErrorToEventLog(ex.Message);
                ErrorHelper.SendExcepToDB(ex, "ProcessCommand", "GetDate");
                throw ex;
            }
        }
示例#4
0
 public void Process(List <string> resourceList)
 {
     foreach (var res in resourceList)
     {
         ScriptLoader loader = new ScriptLoader();
         ScriptFile   file;
         file = loader.Parse(res, ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME);
         ScriptCommand namespaceCmd = (ScriptCommand)file.Commands[0];
         if (namespaceCmd != null && namespaceCmd.GetType().Equals(typeof(NamespaceScriptCommand)))
         {
             namespaceCmd.Execute(this);
         }
         else
         {
             if (namespaceFileDic.ContainsKey("(default)"))
             {
                 if (namespaceFileDic["(default)"] == null)
                 {
                     namespaceFileDic["(default)"] = new List <ScriptFile>();
                 }
                 namespaceFileDic["(default)"].Add(file);
             }
             else
             {
                 namespaceFileDic.Add("(default)", new List <ScriptFile>()
                 {
                     file
                 });
             }
         }
     }
 }
        private void GetUserProfileDiskSettings()
        {
            string pslgetUserProfileDiskSettings = ConfigurationManager.AppSettings["psl_layer"].ToString() + "/getUserProfileDiskSettings.ps1";
            string psl_Script = "";

            using (WebClient client = new WebClient())
            {
                psl_Script = client.DownloadString(pslgetUserProfileDiskSettings);
            }
            var command = new ScriptCommand(psl_Script,
                                            new[] { Param1, Param2 }, (psObject, scriptCommand) =>
            {
                var settings = new CollectionDashboardConfig
                {
                    EnableUserProfileDisk = psObject.EnableUserProfileDisk,
                    DiskPath = psObject.DiskPath,
                    MaxUserProfileDiskSizeGB = psObject.MaxUserProfileDiskSizeGB
                };
                scriptCommand.Result = settings;
            });

            command.Init(Data);
            command.Execute();

            var result = (CollectionDashboardConfig)command.Result;

            this.Result.EnableUserProfileDisk = result.EnableUserProfileDisk;
            this.Result.DiskPath = result.DiskPath;
            this.Result.MaxUserProfileDiskSizeGB = result.MaxUserProfileDiskSizeGB;
        }
示例#6
0
        public ExecutionResponse CreateSnapshot(string connectionString, string scriptDir, bool overwrite)
        {
            try
            {
                connectionString.Should().NotBeNullOrWhiteSpace();
                scriptDir.Should().NotBeNullOrWhiteSpace();

                var scriptCommand = new ScriptCommand
                {
                    ConnectionString = connectionString,
                    ScriptDir = scriptDir,
                    Overwrite = overwrite
                };

                var filteredTypes = HandleFilteredTypes();
                var namesAndSchemas = HandleDataTables(DataTables);

                scriptCommand.Execute(namesAndSchemas, DataTablesPattern, DataTablesExcludePattern, TableHint, filteredTypes);
                return new ExecutionResponse(true);
            }
            catch (Exception ex)
            {
                return new ExecutionResponse(false, "", ex);
            }
        }
示例#7
0
        public override async Task ExecuteAsync(GameEvent E)
        {
            var cmd = new ScriptCommand()
            {
                CommandName      = "killplayer",
                ClientNumber     = E.Target.ClientNumber,
                CommandArguments = new[] { E.Origin.ClientNumber.ToString() }
            };

            await cmd.Execute(E.Owner);
        }
        public AdminCollection GetCollectionProperty(string deploymentName, string collectionName)
        {
            try
            {
                string pslgetCollection = ConfigurationManager.AppSettings["psl_layer"].ToString() + "/getCollection.ps1";
                string psl_Script       = "";
                using (WebClient client = new WebClient())
                {
                    psl_Script = client.DownloadString(pslgetCollection);
                }
                AdminCollection result = new AdminCollection();

                // Get Audit location
                result.AuditLocation = string.Empty;    // TODO: populate real data when this feature is ready

                // Get the description using powershell
                var command = new ScriptCommand(psl_Script,
                                                new[] { "CollectionName", "ConnectionBroker" }, (psObject, scriptCommand) =>
                {
                    result.Name           = psObject.CollectionName;
                    result.Size           = psObject.Size;
                    result.CollectionType = psObject.ResourceType;
                    result.Description    = psObject.CollectionDescription;
                });
                var data = new Dictionary <string, object> {
                    { "ConnectionBroker", deploymentName }, { "CollectionName", collectionName }
                };
                command.Init(data);

                command.Execute();
                return(result);
            }
            catch (Exception ex)
            {
                ErrorHelper.SendExcepToDB(ex, "GetCollectionProperty", deploymentName);
                throw ex;
            }
        }
示例#9
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;
            }
        }
示例#10
0
 public void Invoke(object host)
 {
     Command.Execute(host, Arguments.ToArray());
 }
示例#11
0
 public TResult ExecuteScript <TResult>(ScriptCommand <TResult> cmd)
 {
     cmd.LazyContext = LazyScriptContext;
     return(cmd.Execute());
 }
示例#12
0
 public TResult ExecuteScript <TResult>(ScriptCommand <TResult> cmd)
 {
     //TODO: only one by request
     cmd.Context = ScriptContext;
     return(cmd.Execute());
 }