Ejemplo n.º 1
0
        public bool RunRecycleApplicationPoolByOrder()
        {
            var                       runIsOk      = default(bool);
            const string              fileName     = "Script_IISAppPoolRecyclerBat.Bat";
            var                       loggerHelper = new LogTracker();
            IScriptShellLoadable      objLoader    = new ShellScriptReader();
            IShellScriptExecutionable objRunner    = new ShellScriptRunner();

            var fullPathForScript = objLoader.MakeFullPathFromEnvironmentAndFileName(fileName);

            if (!string.IsNullOrEmpty(fullPathForScript))
            {
                var scriptInfo = objLoader.LoadSpecificShellScriptFromPath(fullPathForScript);

                if (objLoader.CheckIfScriptFileIsFromType(transversal.dto.Enums.EnumScriptRunner.TypeOfScriptFile.Bat,
                                                          fullPathForScript) && (scriptInfo.Exists))
                {
                    runIsOk = objRunner.ExecuteBatThatTriggerPowerShell(new transversal.dto.ValueObject.
                                                                        Scripts.PowerShellScriptVo()
                    {
                        FileName         = fullPathForScript,
                        ScriptFileObject = scriptInfo
                    });

                    if (runIsOk)
                    {
                        loggerHelper.RegisterLogFacade(transversal.dto.Enums.Nlog.EnumNLogStruct.LogType.Info,
                                                       "file: Script_IISAppPoolRecyclerBat executed OK");
                    }
                }
            }

            return(runIsOk);
        }
        public bool RunRecycleApplicationPoolByOrder()
        {
            var runIsOk = default(bool);
            const string fileName = "Script_IISAppPoolRecyclerBat.Bat";
            var loggerHelper = new LogTracker();
            IScriptShellLoadable objLoader = new ShellScriptReader();
            IShellScriptExecutionable objRunner = new ShellScriptRunner();

            var fullPathForScript = objLoader.MakeFullPathFromEnvironmentAndFileName(fileName);

            if (!string.IsNullOrEmpty(fullPathForScript))
            {
                var scriptInfo = objLoader.LoadSpecificShellScriptFromPath(fullPathForScript);

                if (objLoader.CheckIfScriptFileIsFromType(transversal.dto.Enums.EnumScriptRunner.TypeOfScriptFile.Bat,
                    fullPathForScript) && (scriptInfo.Exists))
                {
                    runIsOk = objRunner.ExecuteBatThatTriggerPowerShell(new transversal.dto.ValueObject.
                        Scripts.PowerShellScriptVo()
                    {
                        FileName = fullPathForScript,
                        ScriptFileObject = scriptInfo
                    });

                    if (runIsOk)
                    {
                        loggerHelper.RegisterLogFacade(transversal.dto.Enums.Nlog.EnumNLogStruct.LogType.Info,
                        "file: Script_IISAppPoolRecyclerBat executed OK");
                    }   
                }
            } 
               
            return runIsOk;
        }
        public bool ExecuteBatThatTriggerPowerShell(PowerShellScriptVo shellScript)
        {
            var executeOk = default(bool);
            IScriptShellLoadable objLoader = default(IScriptShellLoadable);
            var loggerHelper = new LogTracker();

            if (!object.ReferenceEquals(shellScript, null))
            {
                objLoader = new ShellScriptReader();

                if (objLoader.CheckIfScriptFileIsFromType(transversal.dto.Enums.EnumScriptRunner.TypeOfScriptFile.Bat,
                    shellScript.ScriptFileObject.FullName))
                {
                    loggerHelper.RegisterLogFacade(EnumNLogStruct.LogType.Info,
                        $"Loaded script: {shellScript.FileName} " +
                     $"from Folder {shellScript.FileName} and Type {shellScript.ScriptFileObject.Extension}");

                    try
                    {
                        var objProcess = new Process()
                        {
                            StartInfo =
                                {
                                    FileName = shellScript.ScriptFileObject.FullName,
                                    Arguments = shellScript.ScriptFileObject.FullName,
                                    UseShellExecute = false,
                                    RedirectStandardOutput = true,
                                    RedirectStandardError = true

                                }
                        };

                        executeOk = string.IsNullOrEmpty(objProcess.StandardError.ReadToEnd());

                    }
                    catch (Exception ex)
                    {
                        loggerHelper.RegisterLogWithFatalExceptionFacade(ex, this.GetType().
                            Name);
                    }
                }


            }

            return executeOk; 
        }
Ejemplo n.º 4
0
        public bool ExecuteBatThatTriggerPowerShell(PowerShellScriptVo shellScript)
        {
            var executeOk = default(bool);
            IScriptShellLoadable objLoader = default(IScriptShellLoadable);
            var loggerHelper = new LogTracker();

            if (!object.ReferenceEquals(shellScript, null))
            {
                objLoader = new ShellScriptReader();

                if (objLoader.CheckIfScriptFileIsFromType(transversal.dto.Enums.EnumScriptRunner.TypeOfScriptFile.Bat,
                                                          shellScript.ScriptFileObject.FullName))
                {
                    loggerHelper.RegisterLogFacade(EnumNLogStruct.LogType.Info,
                                                   $"Loaded script: {shellScript.FileName} " +
                                                   $"from Folder {shellScript.FileName} and Type {shellScript.ScriptFileObject.Extension}");

                    try
                    {
                        var objProcess = new Process()
                        {
                            StartInfo =
                            {
                                FileName               = shellScript.ScriptFileObject.FullName,
                                Arguments              = shellScript.ScriptFileObject.FullName,
                                UseShellExecute        = false,
                                RedirectStandardOutput = true,
                                RedirectStandardError  = true
                            }
                        };

                        executeOk = string.IsNullOrEmpty(objProcess.StandardError.ReadToEnd());
                    }
                    catch (Exception ex)
                    {
                        loggerHelper.RegisterLogWithFatalExceptionFacade(ex, this.GetType().
                                                                         Name);
                    }
                }
            }

            return(executeOk);
        }