Пример #1
0
        public async void Execute()
        {
            outPut = _cmd.ExecuteCommandSync(string.Format("ping {0} /t", Options.Ip));
            var val = string.Empty;

            do
            {
                val = await outPut.ReadLineAsync();

                ConsoleResult.Add(val);

                //mis a jour du graph
                int suc = IsSuccessTime(val);
                GraphVM.Values.Add(suc);
                if (GraphVM.Values.Count > MainWindow.MaxValues)
                {
                    GraphVM.Values.RemoveAt(0);
                }

                //mis a jour de l'affichage
                if (ConsoleResult.Count >= MaxValues)
                {
                    ConsoleResult.RemoveAt(0);
                }
            } while (true);
        }
Пример #2
0
        //delegate void DataReceivedEventHandlers(object sender, EventArgs e);
        //public event System.Diagnostics.DataReceivedEventHandler DataReceived;
        //public event System.Diagnostics.DataReceivedEventHandler ErrorDataReceived;



        public ConsoleResult Execute(String Commands)
        {
            ConsoleResult s = new ConsoleResult();

            ProcessStartInfo processStartInfo = new ProcessStartInfo(CMD);

            processStartInfo.RedirectStandardInput  = true;
            processStartInfo.RedirectStandardOutput = true;
            processStartInfo.RedirectStandardError  = true;
            processStartInfo.CreateNoWindow         = false;
            processStartInfo.WindowStyle            = ProcessWindowStyle.Hidden;
            processStartInfo.UseShellExecute        = false;

            Process process = Process.Start(processStartInfo);

            for (int i = 0; i < Repetition; i++)
            {
                foreach (String command in Commands.Split(LineDelimiter.ToCharArray()))
                {
                    process.StandardInput.WriteLine(command);
                }
            }
            process.StandardInput.Close();
            string outputString = process.StandardOutput.ReadToEnd();
            string outputError  = process.StandardError.ReadToEnd();

            s.Error  = outputError;
            s.Output = outputString;
            return(s);
        }
Пример #3
0
        private static ConsoleResult <ServicesConfiguration> ParseConfigFile(string fileContent)
        {
            var result = new ConsoleResult <ServicesConfiguration>();

            var lines = fileContent.Split(Environment.NewLine).ToList();

            var hasAllData = lines[0].StartsWith("HOSTNAME: ") &&
                             lines[1].StartsWith("CLIENT ID: ") &&
                             lines[2].StartsWith("CLIENT SECRET: ") &&
                             lines[3].StartsWith("SCOPE: ");

            if (!hasAllData)
            {
                result.AddErrorMessage("Error: Authentication parameters not defined");
            }
            else
            {
                result.Data = new ServicesConfiguration
                {
                    Hostname     = lines[0].Replace("HOSTNAME: ", "").Trim(),
                    ClientId     = lines[1].Replace("CLIENT ID: ", "").Trim(),
                    ClientSecret = lines[2].Replace("CLIENT SECRET: ", "").Trim(),
                    ClientScope  = lines[3].Replace("SCOPE: ", "").Trim()
                };
            }

            return(result);
        }
Пример #4
0
        internal static ConsoleResult <ServicesConfiguration> GetServicesConfigurationCommandParams()
        {
            var result = new ConsoleResult <ServicesConfiguration>();

            var consoleArgsUndefined = string.IsNullOrEmpty(IS4Manager.AuthHostname) ||
                                       string.IsNullOrEmpty(IS4Manager.AuthClientId) ||
                                       string.IsNullOrEmpty(IS4Manager.AuthClientSecret) ||
                                       string.IsNullOrEmpty(IS4Manager.AuthScope);

            if (consoleArgsUndefined)
            {
                result.AddInfoMessage("Info: Authorization configuration not set in arguments");
            }
            else
            {
                result.AddInfoMessage("Info: Authorization configuration set in arguments");

                result.Data = new ServicesConfiguration
                {
                    Hostname     = IS4Manager.AuthHostname,
                    ClientId     = IS4Manager.AuthClientId,
                    ClientSecret = IS4Manager.AuthClientSecret,
                    ClientScope  = IS4Manager.AuthScope
                };
            }

            return(result);
        }
Пример #5
0
        public ConsoleResult Run(string[] args)
        {
            if (args.Length > 1)
            {
                return(new ConsoleErrorResult("No parameters needed"));
            }

            string lineBreak     = "<br>";
            var    consoleResult = new ConsoleResult($"<div style='float:left;width:270px;'>1. 'Delete All'</div><div style='width:20px;float:left;'>-</div><div style='float:left;'>Deletes all todo items</div>{lineBreak}<div style='float:left;width:270px;'>2. 'Delete Completed'</div><div style='width:20px;float:left;'>-</div><div style='float:left;'>Deletes all todo items completed</div>{lineBreak}<div style='float:left;width:270px;'>3. Save [0]</div><div style='width:20px;float:left;'>-</div><div style='float:left;'>Save a todo item where [0] is item to save</div>");

            consoleResult.isHTML = true;

            return(consoleResult);
        }
Пример #6
0
        internal static ConsoleResult <ServicesConfiguration> GetServicesConfigurationFromFiles()
        {
            var result = new ConsoleResult <ServicesConfiguration>();

            string currentDirectory = Environment.CurrentDirectory;
            string exeLocation      = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);

            //Need to take distinct in case console app is running from exe directory
            var configFilePaths = new string[] {
                Path.Combine(currentDirectory, configFileName),
                Path.Combine(exeLocation, configFileName)
            }
            .Distinct();

            string pathToUse = configFilePaths.Where(x => File.Exists(x)).FirstOrDefault();

            if (string.IsNullOrEmpty(pathToUse))
            {
                result.AddMessages(FileNotFoundInfoMessage(configFilePaths));
                result.AddMessages(ConfigFileMessage());
            }
            else
            {
                string text       = File.ReadAllText(pathToUse);
                var    configFile = ParseConfigFile(text);

                if (configFile.HasErrors)
                {
                    result.AddMessages(ConfigFileMessage(text));
                }
                else
                {
                    result.AddInfoMessage($"Info: Using configuration file '{pathToUse}'");
                    result.Data = configFile.Data;
                }
            }

            return(result);
        }
Пример #7
0
        protected override DataTemplate SelectTemplateCore(object item, DependencyObject container)
        {
            Guard.IsNotNull(item, nameof(item));

            DataTemplate?template = item switch
            {
                ConsoleCommand _ => CommandTemplate,
                ConsoleResult _ => ResultTemplate,
                ConsoleSyntaxError _ => SyntaxErrorTemplate,
                ConsoleException _ => ExceptionTemplate,
                ConsoleRestart _ => RestartTemplate,
                        _ => ThrowHelper.ThrowArgumentException <DataTemplate>("Invalid input item type")
            };

            if (template is null)
            {
                ThrowHelper.ThrowInvalidOperationException("The requested template is null");
            }

            return(template);
        }
    }
Пример #8
0
 protected abstract void ConsoleKick(ConsoleResult result, object data);
Пример #9
0
 protected abstract void ConsoleStatus(ConsoleResult result, object data);
Пример #10
0
 protected abstract void ConsoleShutdown(ConsoleResult result, object data);
Пример #11
0
 protected abstract void ConsoleLogout(ConsoleResult result, object data);