Пример #1
0
        private string UrlReplacement(Match match)
        {
            AnsiStringBuilder builder = new AnsiStringBuilder();

            builder.AppendLink(match.Value, match.Value);
            return(builder.ToString());
        }
Пример #2
0
        private TextResult List(CommandContext context)
        {
            string configPath = CombineWithSolutionPath(CONFIG_PATH);

            if (!File.Exists(configPath))
            {
                return("Configuration hasn't been found.");
            }

            Regex             filter  = context.GetFilterRegex();
            AnsiStringBuilder builder = new AnsiStringBuilder();

            using (FileStream configFile = File.OpenRead(configPath))
            {
                XDocument doc       = XDocument.Load(configFile);
                var       workbook  = doc.Root;
                var       nsSS      = workbook.GetNamespaceOfPrefix("ss");
                var       worksheet = workbook.Element(nsSS + "Worksheet");
                var       table     = worksheet.Element(nsSS + "Table");

                foreach (var row in table.Elements(nsSS + "Row").Skip(1))
                {
                    var    cells = row.Elements(nsSS + "Cell").ToList();
                    string name  = cells[0].Element(nsSS + "Data").Value;
                    string color = cells[1].Element(nsSS + "Data").Value;

                    if (filter.IsMatch(name))
                    {
                        WriteColor(builder, name, color);
                    }
                }
            }

            return(builder.ToString());
        }
Пример #3
0
        public string Random(CommandContext context)
        {
            AnsiStringBuilder builder = new AnsiStringBuilder();
            Faker             faker   = new Faker("en");

            // Text
            builder.AppendForegroundFormat(ConsoleColor.Gray);
            builder.Append("text");
            builder.AppendFormattingReset();
            builder.AppendLine();
            builder.AppendLine(faker.Lorem.Paragraph(6));

            // Numbers
            builder.AppendLine();
            builder.AppendForegroundFormat(ConsoleColor.Gray);
            builder.Append("numbers");
            builder.AppendFormattingReset();
            builder.AppendLine();
            int    integer    = faker.Random.Int(0, int.MaxValue);
            double fractional = faker.Random.Double();
            double @decimal   = integer + fractional;

            builder.AppendLine($"integer: {integer}    fractional: {fractional}    decimal: {@decimal}");

            // Person
            builder.AppendLine();
            builder.AppendForegroundFormat(ConsoleColor.Gray);
            builder.Append("person");
            builder.AppendFormattingReset();
            builder.AppendLine();
            Person person = faker.Person;

            builder.AppendLine($"{person.FullName} ({person.UserName})");
            builder.AppendLine($"DOB: {person.DateOfBirth.ToShortDateString()}");
            builder.AppendLine($"Phone: {person.Phone}");
            builder.AppendLine($"Email: {person.Email}");
            builder.AppendLine($"Website: {person.Website}");

            // Address
            builder.AppendLine();
            builder.AppendForegroundFormat(ConsoleColor.Gray);
            builder.Append("address");
            builder.AppendFormattingReset();
            builder.AppendLine();
            builder.AppendLine(faker.Address.FullAddress());

            // GPS
            builder.AppendLine();
            builder.AppendForegroundFormat(ConsoleColor.Gray);
            builder.Append("gps");
            builder.AppendFormattingReset();
            builder.AppendLine();
            double latittude = faker.Address.Latitude();
            double longitude = faker.Address.Longitude();

            builder.Append($"{latittude}, {longitude}");

            return(builder.ToString());
        }
Пример #4
0
        private string ReplaceBranchName(Match match)
        {
            AnsiStringBuilder builder     = new AnsiStringBuilder();
            string            helpCommand = $"git checkout {match.Value}";

            builder.AppendLink(match.Value, ActionBuilder.InputSetUri(helpCommand));
            return(builder.ToString());
        }
Пример #5
0
        private string ReplaceHelpCommand(Match match)
        {
            string            help    = match.Value.TrimEnd();
            AnsiStringBuilder builder = new AnsiStringBuilder();

            builder.AppendLink(help, ActionBuilder.InputSetUri(help));
            return(builder.ToString());
        }
Пример #6
0
        private string ReplaceHelpWithAction(Match match)
        {
            AnsiStringBuilder builder = new AnsiStringBuilder();

            builder.Append("\"");
            string helpCommand = match.Groups["help"].Value;

            builder.AppendLink(helpCommand, ActionBuilder.InputSetUri(helpCommand));
            builder.Append("\"");
            return(builder.ToString());
        }
Пример #7
0
        public string Number(CommandContext context)
        {
            AnsiStringBuilder result = new AnsiStringBuilder();

            foreach (string number in context.GetParameterValues("number"))
            {
                result.AppendLine(BuildNumberInfo(number));
            }

            RemoveLastLineEnd(result);
            return(result.ToString());
        }
Пример #8
0
        private static string BuildNumberInfo(string value)
        {
            value = value.Trim();

            try
            {
                string @decimal, hex, binary;
                int    number = 0;

                if (Regex.IsMatch(value, "^(0|b|0b)[01]+$"))
                {
                    value  = value.Substring(value.IndexOf('b') + 1);
                    number = Convert.ToInt32(value, 2);
                }
                else if (Regex.IsMatch(value, "^(x|0x)[0-9A-Fa-f]+$") ||
                         Regex.IsMatch(value, "[A-Fa-f]+"))
                {
                    value  = value.Substring(value.IndexOf('x') + 1);
                    number = Convert.ToInt32(value, 16);
                }
                else
                {
                    number = Convert.ToInt32(value);
                }

                AnsiStringBuilder builder = new AnsiStringBuilder();
                @decimal = Convert.ToString(number, 10);
                hex      = Convert.ToString(number, 16);
                binary   = Convert.ToString(number, 2);
                builder.AppendForegroundFormat(ConsoleColor.Gray);
                builder.Append("dec:");
                builder.AppendFormattingReset();
                builder.Append($" {@decimal,-10} ");
                builder.AppendForegroundFormat(ConsoleColor.Gray);
                builder.Append("hex:");
                builder.AppendFormattingReset();
                builder.Append($" {hex,7} ");
                builder.AppendForegroundFormat(ConsoleColor.Gray);
                builder.Append("bin:");
                builder.AppendFormattingReset();
                builder.Append($" {binary,22}");
                return(builder.ToString());
            }
            catch (FormatException)
            {
                return($"\"{value}\": invalid format; [0|b|0b]0101; [x|0x]0A2F");
            }
            catch (Exception anyException)
            {
                return($"\"{value}\": {anyException.Message}");
            }
        }
Пример #9
0
        public ICommandResult Execute(CommandContext context)
        {
            AnsiStringBuilder result = new AnsiStringBuilder();

            foreach (IHistoryItem historyItem in history.GetHistory())
            {
                string rawInput = historyItem.Input.ParsedInput.RawInput;
                result.AppendLink(rawInput, ActionBuilder.InputSetUri(rawInput));
                result.AppendLine();
            }

            return(new TextResult(result.ToString()));
        }
Пример #10
0
        public string List(CommandContext context)
        {
            AnsiStringBuilder builder = new AnsiStringBuilder();

            AddFunctionToList(builder, "base64", "Codes and decodes base64 string from input or a file.");
            AddFunctionToList(builder, "color", "Shows a colour(s) in multiple formats. Supported inputs: #[AA]RRGGBB; int[] { [AAA], RRR, GGG, BBB }.");
            AddFunctionToList(builder, "guid", "Generates random GUID and shows it in multiple formats.");
            AddFunctionToList(builder, "md5", "Calculates MD5 hash from input text or a file.");
            AddFunctionToList(builder, "number", "Shows a number in multiple numerical systems (dec, hex, bin). Supported inputs: 42; [0]b101010; [0]x2A.");
            AddFunctionToList(builder, "random", "Generates random text, person information, address, GPS coordinates and numbers.");
            AddFunctionToList(builder, "sha1", "Calculates SHA1 hash from input text or a file.");
            return(builder.ToString());
        }
Пример #11
0
        private TextResult Get(CommandContext context)
        {
            string configPath = CombineWithSolutionPath(CONFIG_PATH);

            if (!File.Exists(configPath))
            {
                return("Configuration hasn't been found.");
            }

            Regex             filter  = context.GetFilterRegex();
            AnsiStringBuilder builder = new AnsiStringBuilder();

            string[] languages = new[] { "en", "sv", "de", "lv", "no", "fi", "fr", "nl", "cs", "da", "es", "it", "pl", "pt", "ru", "es-mx", "en-in", "hi" };

            using (FileStream configFile = File.OpenRead(configPath))
            {
                XDocument doc       = XDocument.Load(configFile);
                var       workbook  = doc.Root;
                var       nsSS      = workbook.GetNamespaceOfPrefix("ss");
                var       worksheet = workbook.Element(nsSS + "Worksheet");
                var       table     = worksheet.Element(nsSS + "Table");

                foreach (var row in table.Elements(nsSS + "Row").Skip(1))
                {
                    var    cells = row.Elements(nsSS + "Cell").ToList();
                    string name  = cells[0].Element(nsSS + "Data").Value;
                    string color = cells[1].Element(nsSS + "Data").Value;

                    if (!filter.IsMatch(name))
                    {
                        continue;
                    }

                    builder.AppendLine(name);

                    for (int i = 1; i < cells.Count; i++)
                    {
                        WriteLanguage(builder, languages[i - 1], cells[i].Element(nsSS + "Data").Value);
                    }

                    builder.AppendLine();
                }
            }

            return(builder.ToString());
        }
Пример #12
0
        // TODO: [P3] Change how the help works and automatically generate nice help per command
        public TextResult BuildCommandHelp()
        {
            AnsiStringBuilder builder = new AnsiStringBuilder();

            builder.Append("usage: ");
            builder.AppendForegroundFormat(System.ConsoleColor.Gray);
            builder.Append("texo [--version] <command> [<args>]");
            builder.AppendFormattingReset();
            builder.AppendLine();

            builder.AppendLine();
            builder.AppendForegroundFormat(System.ConsoleColor.Yellow);
            builder.Append("commands");
            builder.AppendFormattingReset();
            builder.AppendLine();

            builder.Append($"{EnvironmentNames.QUERY_ENVIRONMENT,-15}");
            builder.AppendForegroundFormat(System.ConsoleColor.Gray);
            builder.Append("Management of environment variables.");
            builder.AppendFormattingReset();
            builder.AppendLine();

            builder.Append($"{HistoryNames.QUERY_HISTORY,-15}");
            builder.AppendForegroundFormat(System.ConsoleColor.Gray);
            builder.Append("History of commands.");
            builder.AppendFormattingReset();
            builder.AppendLine();

            builder.AppendLine();
            builder.AppendForegroundFormat(System.ConsoleColor.Yellow);
            builder.Append("options");
            builder.AppendFormattingReset();
            builder.AppendLine();

            builder.Append($"{"-v--version",-15}");
            builder.AppendForegroundFormat(System.ConsoleColor.Gray);
            builder.Append("Prints out the version of the Texo UI in use.");
            builder.AppendFormattingReset();
            builder.AppendLine();

            return(builder.ToString());
        }
Пример #13
0
        private static string BuildColorInfo(Color color)
        {
            Color blendedColor = color;

            if (color.A < 255)
            {
                blendedColor = Blend(color, Color.Black, color.A / 255.0);
            }

            AnsiStringBuilder builder = new AnsiStringBuilder();

            builder.AppendForegroundFormat(blendedColor.R, blendedColor.G, blendedColor.B);
            builder.Append(new string('█', 7));
            builder.AppendFormattingReset();
            builder.Append(" ");
            builder.Append($"#{GetHexColorPart(color.A)}{GetHexColorPart(color.R)}{GetHexColorPart(color.G)}{GetHexColorPart(color.B)} ");
            builder.Append($"#{GetHexColorPart(blendedColor.R)}{GetHexColorPart(blendedColor.G)}{GetHexColorPart(blendedColor.B)} ");
            builder.Append(string.Format("{0,-22} ", $"argb({color.A},{color.R},{color.G},{color.B})"));
            builder.Append(string.Format("{0,-17}", $"rgb({blendedColor.R},{blendedColor.G},{blendedColor.B})"));
            builder.AppendLine();
            return(builder.ToString());
        }
Пример #14
0
        public string Guid(CommandContext context)
        {
            Guid guid = System.Guid.NewGuid();
            AnsiStringBuilder builder = new AnsiStringBuilder();
            bool isLetter             = false;

            foreach (char character in guid.ToString("N").ToUpperInvariant())
            {
                if (char.IsDigit(character))
                {
                    if (isLetter)
                    {
                        builder.AppendFormattingReset();
                        isLetter = false;
                    }
                }
                else if (!isLetter)
                {
                    builder.AppendForegroundFormat(ConsoleColor.Yellow);
                    isLetter = true;
                }

                builder.Append(character.ToString());
            }

            if (isLetter)
            {
                builder.AppendFormattingReset();
            }

            builder.AppendLine();
            builder.AppendLine(guid.ToString());
            builder.AppendLine(guid.ToString("B").ToUpperInvariant());
            builder.Append(guid.ToString("X"));

            return(builder.ToString());
        }
Пример #15
0
        public string ColorFunction(CommandContext context)
        {
            AnsiStringBuilder result = new AnsiStringBuilder();
            var   parValues          = context.GetParameterValues("color");
            Color color;

            if (parValues.Count == 4 && parValues.All(par => int.TryParse(par, out _)))
            {
                color = Color.FromArgb(int.Parse(parValues[0]), int.Parse(parValues[1]), int.Parse(parValues[2]), int.Parse(parValues[3]));
                result.AppendLine(BuildColorInfo(color));
            }
            else if (parValues.Count == 3 && parValues.All(par => int.TryParse(par, out _)))
            {
                color = Color.FromArgb(255, int.Parse(parValues[0]), int.Parse(parValues[1]), int.Parse(parValues[2]));
                result.AppendLine(BuildColorInfo(color));
            }
            else
            {
                foreach (string textPar in parValues.Select(par => par.ToString()))
                {
                    color = ReadColorFromText(textPar);

                    if (color.IsEmpty)
                    {
                        result.AppendLine($"\"{textPar}\": invalid format");
                    }
                    else
                    {
                        result.AppendLine(BuildColorInfo(color));
                    }
                }
            }

            RemoveLastLineEnd(result);
            return(result.ToString());
        }
Пример #16
0
        private TextResult Set(CommandContext context)
        {
            string configPath = CombineWithSolutionPath(CONFIG_PATH);

            if (!File.Exists(configPath))
            {
                return("Configuration hasn't been found.");
            }

            string name = context.GetParameterValue(SpinSportConstants.PARAMETER_NAME);

            string[] brandValues = new[]
            {
                context.GetParameterFromOption(SpinSportConstants.OPTION_SHOWCASE) ?? string.Empty,
                context.GetParameterFromOption(SpinSportConstants.OPTION_BETWAY) ?? string.Empty,
                context.GetParameterFromOption(SpinSportConstants.OPTION_BETWAY_DARK) ?? string.Empty,
                context.GetParameterFromOption(SpinSportConstants.OPTION_BETWAY_NEW) ?? string.Empty,
                context.GetParameterFromOption(SpinSportConstants.OPTION_BETWAY_AFRICA) ?? string.Empty,
                context.GetParameterFromOption(SpinSportConstants.OPTION_BETWAY_AFRICA_MOBILE) ?? string.Empty
            };

            XDocument       doc;
            XElement        targetRow = null;
            List <XElement> cells     = new List <XElement>();

            using (FileStream configFile = File.OpenRead(configPath))
            {
                doc = XDocument.Load(configFile);
            }

            var workbook  = doc.Root;
            var nsSS      = workbook.GetNamespaceOfPrefix("ss");
            var worksheet = workbook.Elements(nsSS + "Worksheet").FirstOrDefault(w => (string)w.Attribute(nsSS + "Name") == "ColourUsage");
            var table     = worksheet.Element(nsSS + "Table");

            foreach (var row in table.Elements(nsSS + "Row").Skip(1))
            {
                cells = row.Elements(nsSS + "Cell").ToList();
                string rowName = cells[0].Element(nsSS + "Data").Value;

                if (string.Equals(rowName, name, StringComparison.OrdinalIgnoreCase))
                {
                    targetRow = row;
                    break;
                }
            }

            if (targetRow != null)
            {
                for (int i = 0; i < brandValues.Length; i++)
                {
                    int    cellIndex = i + 1;
                    string value     = brandValues[i];

                    if (cellIndex >= targetRow.Elements().Count())
                    {
                        targetRow.Add(
                            new XElement(nsSS + "Cell",
                                         new XElement(nsSS + "Data",
                                                      new XAttribute(nsSS + "Type", "String"),
                                                      value)));
                        continue;
                    }

                    var cell      = targetRow.Elements().Skip(cellIndex).First();
                    var attribute = cell.Attribute(nsSS + "Index");

                    if (attribute != null && int.TryParse(attribute.Value, out int realCellIndex))
                    {
                        if (realCellIndex > cellIndex)
                        {
                            cell.AddBeforeSelf(new XElement(nsSS + "Cell",
                                                            new XElement(nsSS + "Data",
                                                                         new XAttribute(nsSS + "Type", "String"),
                                                                         value)));
                            continue;
                        }

                        attribute.Remove();
                    }

                    cell.Element(nsSS + "Data").Value = value;
                }
            }
            else
            {
                targetRow = new XElement(nsSS + "Row",
                                         new XElement(nsSS + "Cell",
                                                      new XElement(nsSS + "Data",
                                                                   new XAttribute(nsSS + "Type", "String"),
                                                                   name)));

                foreach (string brandValue in brandValues)
                {
                    targetRow.Add(new XElement(nsSS + "Cell",
                                               new XElement(nsSS + "Data",
                                                            new XAttribute(nsSS + "Type", "String"),
                                                            brandValue)));
                }

                table.Add(targetRow);
            }

            using (FileStream configFile = File.OpenWrite(configPath))
            {
                doc.Save(configFile);
            }

            AnsiStringBuilder builder = new AnsiStringBuilder();

            WriteColorUsage(builder, targetRow, nsSS);
            return(builder.ToString());
        }
Пример #17
0
        private TextResult Set(CommandContext context)
        {
            string configPath = CombineWithSolutionPath(CONFIG_PATH);

            if (!File.Exists(configPath))
            {
                return("Configuration hasn't been found.");
            }

            string            name    = context.GetParameterValue(SpinSportConstants.PARAMETER_NAME);
            string            color   = context.GetParameterValue(SpinSportConstants.PARAMETER_VALUE);
            AnsiStringBuilder builder = new AnsiStringBuilder();
            XDocument         doc;
            XElement          targetRow = null;

            using (FileStream configFile = File.OpenRead(configPath))
            {
                doc = XDocument.Load(configFile);
            }

            var workbook  = doc.Root;
            var nsSS      = workbook.GetNamespaceOfPrefix("ss");
            var worksheet = workbook.Element(nsSS + "Worksheet");
            var table     = worksheet.Element(nsSS + "Table");

            foreach (var row in table.Elements(nsSS + "Row").Skip(1))
            {
                string rowName = row.Element(nsSS + "Cell").Element(nsSS + "Data").Value;

                if (string.Equals(rowName, name, StringComparison.OrdinalIgnoreCase))
                {
                    targetRow = row;
                    break;
                }
            }

            if (targetRow != null)
            {
                var cells = targetRow.Elements(nsSS + "Cell").ToList();
                cells[1].Element(nsSS + "Data").Value = color ?? string.Empty;
            }
            else
            {
                XElement newRow = new XElement(nsSS + "Row",
                                               new XElement(nsSS + "Cell",
                                                            new XElement(nsSS + "Data",
                                                                         new XAttribute(nsSS + "Type", "String"),
                                                                         name)),
                                               new XElement(nsSS + "Cell",
                                                            new XElement(nsSS + "Data",
                                                                         new XAttribute(nsSS + "Type", "String"),
                                                                         color)));
                table.Add(newRow);
            }

            using (FileStream configFile = File.OpenWrite(configPath))
            {
                doc.Save(configFile);
            }

            WriteColor(builder, name, color);
            return(builder.ToString());
        }
Пример #18
0
        // TODO: [P3] Refarctor this and make it generic
        private TextResult Set(CommandContext context)
        {
            string configPath = CombineWithSolutionPath(CONFIG_PATH);

            if (!File.Exists(configPath))
            {
                return("Configuration hasn't been found.");
            }

            string            name    = context.GetParameterValue(SpinSportConstants.PARAMETER_NAME);
            AnsiStringBuilder builder = new AnsiStringBuilder();

            string[]  languages = new[] { "en", "sv", "de", "lv", "no", "fi", "fr", "nl" };
            XElement  targetRow = null;
            XDocument doc;

            using (FileStream configFile = File.OpenRead(configPath))
            {
                doc = XDocument.Load(configFile);
            }

            var workbook  = doc.Root;
            var nsSS      = workbook.GetNamespaceOfPrefix("ss");
            var worksheet = workbook.Element(nsSS + "Worksheet");
            var table     = worksheet.Element(nsSS + "Table");

            foreach (var row in table.Elements(nsSS + "Row").Skip(1))
            {
                string rowName = row.Element(nsSS + "Cell").Element(nsSS + "Data").Value;

                if (string.Equals(rowName, name, StringComparison.OrdinalIgnoreCase))
                {
                    targetRow = row;
                    break;
                }
            }

            if (targetRow != null)
            {
                var cells = targetRow.Elements(nsSS + "Cell").ToList();
                builder.AppendLine(name);

                for (int i = 1; i < cells.Count; i++)
                {
                    var    cell          = cells[i];
                    string languageCode  = languages[i - 1];
                    string languageValue = context.GetParameterFromOption(languageCode) ?? string.Empty;
                    cell.Element(nsSS + "Data").Value = languageValue;
                    WriteLanguage(builder, languageCode, languageValue);
                }
            }
            else
            {
                XElement newRow = new XElement(nsSS + "Row",
                                               new XElement(nsSS + "Cell", new XElement(nsSS + "Data", new XAttribute(nsSS + "Type", "String"), name)),
                                               new XElement(nsSS + "Cell", new XElement(nsSS + "Data", new XAttribute(nsSS + "Type", "String"), context.GetParameterFromOption(SpinSportConstants.OPTION_EN) ?? string.Empty)),
                                               new XElement(nsSS + "Cell", new XElement(nsSS + "Data", new XAttribute(nsSS + "Type", "String"), context.GetParameterFromOption(SpinSportConstants.OPTION_SV) ?? string.Empty)),
                                               new XElement(nsSS + "Cell", new XElement(nsSS + "Data", new XAttribute(nsSS + "Type", "String"), context.GetParameterFromOption(SpinSportConstants.OPTION_DE) ?? string.Empty)),
                                               new XElement(nsSS + "Cell", new XElement(nsSS + "Data", new XAttribute(nsSS + "Type", "String"), context.GetParameterFromOption(SpinSportConstants.OPTION_LV) ?? string.Empty)),
                                               new XElement(nsSS + "Cell", new XElement(nsSS + "Data", new XAttribute(nsSS + "Type", "String"), context.GetParameterFromOption(SpinSportConstants.OPTION_NO) ?? string.Empty)),
                                               new XElement(nsSS + "Cell", new XElement(nsSS + "Data", new XAttribute(nsSS + "Type", "String"), context.GetParameterFromOption(SpinSportConstants.OPTION_FI) ?? string.Empty)),
                                               new XElement(nsSS + "Cell", new XElement(nsSS + "Data", new XAttribute(nsSS + "Type", "String"), context.GetParameterFromOption(SpinSportConstants.OPTION_FR) ?? string.Empty)),
                                               new XElement(nsSS + "Cell", new XElement(nsSS + "Data", new XAttribute(nsSS + "Type", "String"), context.GetParameterFromOption(SpinSportConstants.OPTION_NL) ?? string.Empty)));

                table.Add(newRow);

                builder.AppendLine(name);
                WriteLanguage(builder, SpinSportConstants.OPTION_EN, context.GetParameterFromOption(SpinSportConstants.OPTION_EN) ?? string.Empty);
                WriteLanguage(builder, SpinSportConstants.OPTION_SV, context.GetParameterFromOption(SpinSportConstants.OPTION_SV) ?? string.Empty);
                WriteLanguage(builder, SpinSportConstants.OPTION_DE, context.GetParameterFromOption(SpinSportConstants.OPTION_DE) ?? string.Empty);
                WriteLanguage(builder, SpinSportConstants.OPTION_LV, context.GetParameterFromOption(SpinSportConstants.OPTION_LV) ?? string.Empty);
                WriteLanguage(builder, SpinSportConstants.OPTION_NO, context.GetParameterFromOption(SpinSportConstants.OPTION_NO) ?? string.Empty);
                WriteLanguage(builder, SpinSportConstants.OPTION_FI, context.GetParameterFromOption(SpinSportConstants.OPTION_FI) ?? string.Empty);
                WriteLanguage(builder, SpinSportConstants.OPTION_FR, context.GetParameterFromOption(SpinSportConstants.OPTION_FR) ?? string.Empty);
                WriteLanguage(builder, SpinSportConstants.OPTION_NL, context.GetParameterFromOption(SpinSportConstants.OPTION_NL) ?? string.Empty);
            }

            using (FileStream configFile = File.OpenWrite(configPath))
            {
                doc.Save(configFile);
            }

            return(builder.ToString());
        }
Пример #19
0
        public Task <OutputModel> ProcessAsync(OutputModel data)
        {
            if (!data.Flags.Contains(TransformationFlags.GET_CHILD_ITEM))
            {
                return(Task.FromResult(data));
            }

            string text = data.Output;
            string itemPath;
            int    index;

            if (data.Flags.Contains(TransformationFlags.GET_CHILD_ITEM_NAME))
            {
                itemPath = text.TrimEnd();
                index    = 0;
            }
            else if (data.Properties.TryGetValue(TransformationProperties.INDEX, out object value))
            {
                index = (int)value;

                if (text.Length <= index)
                {
                    return(Task.FromResult(data));
                }

                itemPath = text.Substring(index).TrimEnd();
            }
            else
            {
                if (text.StartsWith("Mode", StringComparison.OrdinalIgnoreCase) &&
                    text.Contains("Name"))
                {
                    int indexOfName = text.LastIndexOf("Name");
                    data.Properties[TransformationProperties.INDEX] = indexOfName;
                }

                return(Task.FromResult(data));
            }

            if (string.IsNullOrWhiteSpace(itemPath))
            {
                return(Task.FromResult(data));
            }

            string parentPath = data.Input.ParsedInput.Tokens
                                .Skip(1)
                                .FirstOrDefault(t => !string.Equals(t, "-name", StringComparison.OrdinalIgnoreCase));

            if (string.IsNullOrEmpty(parentPath))
            {
                parentPath = PathConstants.RELATIVE_CURRENT_DIRECTORY;
            }

            string path = Path.Combine(parentPath, itemPath);

            if (path.GetPathType() == PathTypeEnum.NonExistent)
            {
                return(Task.FromResult(data));
            }

            string            fullPath = path.GetFullConsolidatedPath();
            AnsiStringBuilder builder  = new AnsiStringBuilder();

            builder.Append(text.Substring(0, index));
            builder.AppendLink(itemPath, ActionBuilder.PathUri(fullPath));

            int endIndex = index + itemPath.Length;

            if (endIndex < text.Length)
            {
                builder.Append(text.Substring(endIndex));
            }

            data.Output = builder.ToString();
            return(Task.FromResult(data));
        }
Пример #20
0
        public Task <OutputModel> ProcessAsync(OutputModel data)
        {
            if (!data.Flags.Contains(TransformationFlags.GIT_STATUS))
            {
                return(Task.FromResult(data));
            }

            string line = data.Output;
            Match  match;

            if (data.Flags.Contains(TransformationFlags.GIT_UNTRACKED))
            {
                match = untrackedFileRegex.Match(line);
            }
            else
            {
                if (line.StartsWith("Untracked files", StringComparison.OrdinalIgnoreCase))
                {
                    data.Flags.Add(TransformationFlags.GIT_UNTRACKED);
                    return(Task.FromResult(data));
                }

                match = fileRegex.Match(line);
            }

            if (!match.Success)
            {
                return(Task.FromResult(data));
            }

            Group  fileGroup = match.Groups["path"];
            string path      = fileGroup.Value;

            if (!path.IsValidPath())
            {
                return(Task.FromResult(data));
            }

            Func <string, bool> pathCheckFunc = path.EndsWith("/") ? (Func <string, bool>)Directory.Exists : File.Exists;
            string fullPath = Path.Combine(PathConstants.RELATIVE_CURRENT_DIRECTORY, path);

            if (!pathCheckFunc(fullPath))
            {
                return(Task.FromResult(data));
            }

            fullPath = fullPath.GetFullConsolidatedPath();
            AnsiStringBuilder builder = new AnsiStringBuilder();

            builder.Append(line.Substring(0, fileGroup.Index));
            builder.AppendLink(path, ActionBuilder.PathUri(fullPath));

            int endIndex = fileGroup.Index + fileGroup.Length;

            if (endIndex < line.Length)
            {
                builder.Append(line.Substring(endIndex));
            }

            data.Output = builder.ToString();
            return(Task.FromResult(data));
        }