Exemplo n.º 1
0
        public bool TryConvert(object from, Type toType, object conversionHint, out object result)
        {
            result = null;

            if (toType == typeof(string))
            {
                result = from?.ToString();
                return(true);
            }
            if (toType == typeof(StringOption))
            {
                if (from is string value)
                {
                    var option = StringOptions.GetAnyByValue(value);
                    return(option != null);
                }
            }
            if (toType == typeof(Enum))
            {
                // compiler doesn't recognize this...?
                //if (Enum.TryParse(toType, from.ToString(), out var val))
                result = Enum.Parse(toType, from.ToString());
                return(true);
            }
            if (toType == typeof(object))
            {
                result = from?.ToString();
                return(true);
            }
            return(false);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Creates a slider with discrete string options. Enables use of
 /// <seealso cref="Items"/> and <seealso cref="SelectedItem"/>.
 /// </summary>
 /// <param name="name">Name that appears as the title</param>
 /// <param name="value">Initial value of the slider</param>
 /// <param name="options">The <seealso cref="IOption.Name"/>s 
 /// of this are used to set <seealso cref="SelectedItem"/></param>
 /// <param name="returnValue"></param>
 public PopSlider(string name, string value, StringOptions options, Action<string> returnValue)
 {
     InitializeComponent();
     this.BindingContext = options;
     InitializeDiscreteSteps(name, value, options.ToNames());
     WireEvents(returnValue, null);
 }
 internal StringSubType(string start, string end, StringOptions flags, byte index)
 {
     Start = start;
     End   = end;
     Flags = flags;
     Index = index;
 }
Exemplo n.º 4
0
            public void PrintOptions(string indent)
            {
                StringOptions options = new StringOptions(null);

                options.PrintOptions(indent);
                options.PrintDerivedOptions(indent);
            }
Exemplo n.º 5
0
    /// <summary>
    /// Returns a string that represents the current object with the specified options.
    /// </summary>
    /// <param name="options">The options to represent the current object.</param>
    /// <returns>A string that represents the current object.</returns>
    public string ToString(StringOptions options)
    {
        var assertionProperties = string.Join(
            options.Separator,
            GetAssertionProperties().Select(p =>
                                            $"{p.Description}: {(p.Value as AssertionObject)?.ToString(options.ToNextLevel()) ?? p.Value ?? "<null>"}"
                                            )
            );

        return($"{options.Prefix}{assertionProperties}{options.Suffix}");
    }
Exemplo n.º 6
0
        private static string Format(string input, StringOptions options)
        {
            if (options.HasFlag(StringOptions.IgnoreCase))
            {
                input = input.ToUpperInvariant();
            }

            if (options.HasFlag(StringOptions.IgnoreWhitespace))
            {
                input = input.Trim();
            }

            return(input);
        }
Exemplo n.º 7
0
        public int IndexStringFlag(string param)
        {
            //
            // Returnerer lengden på flagget som ble funnet, 0 dersom ikke funnet
            //
            var best_match  = new StringOptions();
            int best_length = 0;

            // Sjekk mot longname først
            foreach (var item in so)
            {
                if (param.StartsWith(item.longname) && item.longname != "")
                {
                    if (item.longname.Length > best_length)
                    {
                        best_length = item.longname.Length;
                        best_match  = item;
                    }
                }
            }

            if (best_length != 0)
            {
                return(best_match.longname.Length);
            }

            // Ikke funnet som longname, sjekk mot shortname
            foreach (var item in so)
            {
                if (param.StartsWith(item.shortname) && item.shortname != "")
                {
                    if (item.shortname.Length > best_length)
                    {
                        best_length = item.shortname.Length;
                        best_match  = item;
                    }
                }
            }

            if (best_length != 0)
            {
                return(best_match.shortname.Length);
            }

            return(0);  // Default
        }
Exemplo n.º 8
0
        public void AddStringOpt(string flags)
        {
            // Oppretter ny StringOpions med lange og korte flaggnavn

            StringOptions stro = new StringOptions();

            string[] f = flags.Split(" ");


            if (f.Length == 1)
            {
                stro.shortname = f[0];
                stro.longname  = "";
            }
            if (f.Length == 2)
            {
                stro.shortname = f[0];
                stro.longname  = f[1];
            }

            so.Add(stro);
        }
Exemplo n.º 9
0
        private static void Init(string id_property, StringOptions str, EnumerableOptions enumr)
        {
            if (_id == null)
            {
                _id = id_property;
            }

            if (_stroptions == null)
            {
                _stroptions = str;
            }

            if (_enumerableoptions == null)
            {
                _enumerableoptions = enumr;
            }

            if (_tracker == null)
            {
                _tracker = new List <int>();
            }
        }
 internal void Add(string start, string end, StringOptions flags)
 {
     base.Add(new StringSubType(start, end, flags, (byte)this.Count));
 }
 public void AddPrefix(string prefix, StringOptions flags)
 {
     base.AddPrefixFlag(prefix, (short)flags);
 }
 public void AddStartEnd(string startSymbol, string endSymbol, StringOptions stringOptions)
 {
     _subtypes.Add(startSymbol, endSymbol, stringOptions);
 }
 public void AddStartEnd(string startEndSymbol, StringOptions stringOptions)
 {
     AddStartEnd(startEndSymbol, startEndSymbol, stringOptions);
 }
Exemplo n.º 14
0
 public StandardStringMatcher(string start, string end, StringOptions flags)
     : base(flags)
 {
     Start = start;
     End   = end;
 }
Exemplo n.º 15
0
 public bool Initialize(ILogOptions logoptions, string[] args)
 {
     this.options = new StringOptions(logoptions);
     this.options.Parse(args);
     return(!this.options.HasErrors);
 }
Exemplo n.º 16
0
 private static bool IsSet(this StringOptions stringOptions, StringOptions flags)
 {
     return (stringOptions & flags) == flags;
 }
Exemplo n.º 17
0
 public static FingerprintBuilder <T> Add <T>(this FingerprintBuilder <T> builder, Expression <Func <T, string> > getInputExpression, StringOptions options = StringOptions.None)
 {
     return(builder.Add(getInputExpression, input => Format(input, options)));
 }
Exemplo n.º 18
0
        /// <summary>
        /// Creates the random string of predefined character types to the specified length.
        /// </summary>
        /// <returns></returns>
        public static string RandomString(int length, StringOptions stringOptions)
        {
            var builder = new StringBuilder(length);

            var actions = new List<Action>();

            if (StringOptions.All == stringOptions || stringOptions.IsSet(StringOptions.Space))
            {
                actions.Add(() => builder.Append(' '));
            }

            if (StringOptions.All == stringOptions || stringOptions.IsSet(StringOptions.AlphaLower))
            {
                actions.Add(() => builder.Append(Convert.ToChar(Convert.ToInt32(Math.Floor(26 * Generator.NextDouble() + 97)))));
            }

            if (StringOptions.All == stringOptions || stringOptions.IsSet(StringOptions.AlphaUpper))
            {
                actions.Add(() => builder.Append(Convert.ToChar(Convert.ToInt32(Math.Floor(26 * Generator.NextDouble() + 65)))));
            }

            if (StringOptions.All == stringOptions || stringOptions.IsSet(StringOptions.Numeric))
            {
                actions.Add(() => builder.Append(Convert.ToChar(Convert.ToInt32(Math.Floor(10 * Generator.NextDouble() + 48)))));
            }

            if (StringOptions.All == stringOptions || stringOptions.IsSet(StringOptions.Punctuation))
            {
                actions.Add(() => builder.Append(RandomPunctuation()));
            }

            if (StringOptions.All == stringOptions || stringOptions.IsSet(StringOptions.Typography))
            {
                actions.Add(() => builder.Append(RandomTypography()));
            }

            if (actions.Count == 0)
            {
                throw new ArgumentException("Unknown string options configuration", "stringOptions");
            }

            for (int i = 0; i < length; i++)
            {
                actions[Generator.Next(0, actions.Count)]();
            }

            return builder.ToString();
        }
Exemplo n.º 19
0
 public RegexStringMatcher(Regex start, string shortcut, string endFormat, StringOptions flags)
     : base(flags)
 {
     Start         = start;
     StartShortcut = shortcut;
     Format        = endFormat;
 }
Exemplo n.º 20
0
 public static BnfiTermConversion <string> CreateStringLiteral(string name, string startEndSymbol, StringOptions options)
 {
     return(new StringLiteral(name, startEndSymbol, options).IntroStringLiteral());
 }
 public StringLiteral(string name, string startEndSymbol, StringOptions stringOptions) : this(name) {
     _subtypes.Add(startEndSymbol, startEndSymbol, stringOptions);
 }
Exemplo n.º 22
0
        /// <summary>
        /// Creates the random string of predefined character types to the specified length
        /// </summary>
        /// <returns></returns>
        public static string RandomString(int length, StringOptions stringOptions)
        {
            StringBuilder builder = new StringBuilder(length);
            Random random = RandomGenerator();

            Action spc = () => builder.Append(' ');
            Action ucc = () => builder.Append(Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65))));
            Action lcc = () => builder.Append(Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 97))));
            Action nmc = () => builder.Append(Convert.ToChar(Convert.ToInt32(Math.Floor(10 * random.NextDouble() + 48))));
            Action puc = () => builder.Append(RandomPunctuation());
            Action tyc = () => builder.Append(RandomTypography());

            List<Action> actions = new List<Action>();

            if (StringOptions.All == stringOptions)
            {
                actions.Add(spc);
                actions.Add(ucc);
                actions.Add(lcc);
                actions.Add(nmc);
                actions.Add(puc);
                actions.Add(tyc);
            }
            else
            {
                if (stringOptions.IsSet(StringOptions.Space))
                {
                    actions.Add(spc);
                }

                if (stringOptions.IsSet(StringOptions.AlphaLower))
                {
                    actions.Add(lcc);
                }

                if (stringOptions.IsSet(StringOptions.AlphaUpper))
                {
                    actions.Add(ucc);
                }

                if (stringOptions.IsSet(StringOptions.Numeric))
                {
                    actions.Add(nmc);
                }

                if (stringOptions.IsSet(StringOptions.Punctuation))
                {
                    actions.Add(puc);
                }

                if (stringOptions.IsSet(StringOptions.Typography))
                {
                    actions.Add(tyc);
                }
            }

            if (actions.Count == 0)
            {
                throw new ArgumentException("Unknown string options configuration", "stringOptions");
            }

            for (int i = 0; i < length; i++)
            {
                actions[random.Next(0, actions.Count)]();
            }

            return builder.ToString();
        }
 public StringLiteral(string name, string startEndSymbol, StringOptions options, Type astNodeType)
     : this(name, startEndSymbol, options)
 {
     base.AstNodeType = astNodeType;
 }
 public StringLiteral(string name, string startEndSymbol, StringOptions options, AstNodeCreator astNodeCreator)
     : this(name, startEndSymbol, options)
 {
     base.AstNodeCreator = astNodeCreator;
 }
Exemplo n.º 25
0
        public async Task SendQueryAsync()
        {
            IsEnabled = false;
            var path    = ProtocolCommand.FormatPath();
            var command = $"{path}?";

            var result = "";

            if (App.Mock)
            {
                await Task.Delay(1);

                result = DefaultResponse;
            }
            else
            {
                var response = await AppLocator.TelnetService.SendCommandAsync(command, true);

                // remove line terminator
                result = response?.TrimEnd();
            }
            if (result.Length == 0)
            {
                return;
            }

            if (result == "Command error")
            {
                throw new InvalidOperationException($"Command error: {command}");
            }

            var propInfo = _propInfo ?? this.GetType().GetProperty(nameof(Value));

            if (_propInfo == null)
            {
                _propInfo = propInfo;
            }
            var type = typeof(T);

            if (type == typeof(string) || type == typeof(StringOption))
            {
                var value = StringOptions.GetByTerm(ProtocolCommand.Options, result);
                propInfo.SetValue(this, $"{value}");
            }
            else if (type == typeof(bool))
            {
                propInfo.SetValue(this, result == "1");
            }
            else if (type == typeof(int) || type == typeof(IntegerOption))
            {
                if (int.TryParse(result, out var val))
                {
                    propInfo.SetValue(this, val);
                }
            }
            else if (type == typeof(double) || type == typeof(RealOption))
            {
                if (double.TryParse(result, out var val))
                {
                    propInfo.SetValue(this, val);
                }
            }
            IsEnabled = true;
            if (!ProtocolCommand.Name.Contains("Status"))
            {
                System.Diagnostics.Debug.WriteLine($"{ProtocolCommand.Name}: {Value}");
            }
        }
Exemplo n.º 26
0
 public StringMatcher(StringOptions flags)
 {
     Flags = flags;
 }