/// <summary> /// Prevent cross thread calls. /// </summary> /// <param name="call"></param> /// <param name="clear"></param> private void UpdateListViewResults(string call, PrefixKind kind, string country, string province, string dxcc, string flags) { if (!InvokeRequired) { ListViewItem item; if (kind == PrefixKind.DXCC) { item = new ListViewItem(call) { BackColor = Color.Honeydew }; } else { item = new ListViewItem("--- " + call) { BackColor = Color.LightGray }; } item.SubItems.Add(kind.ToString()); item.SubItems.Add(country); item.SubItems.Add(province ?? ""); item.SubItems.Add(dxcc); item.SubItems.Add(flags); ListViewResults.Items.Add(item); Application.DoEvents(); } else { BeginInvoke(new Action <string, PrefixKind, string, string, string, string>(UpdateListViewResults), call, kind, country, province, dxcc, flags); return; } }
/// <summary> /// Initializes an instance of the <see cref="Prefix"/> class. /// </summary> /// <param name="name">The name.</param> /// <param name="symbol">The symbol.</param> /// <param name="multiplier">The multiplier.</param> /// <param name="kind">The prefix kind.</param> internal Prefix(string name, char symbol, float multiplier, PrefixKind kind) { Name = name; Symbol = symbol; Multiplier = multiplier; Kind = kind; }
/// <summary> /// Renders a single option name/value pair with a given prefix. <paramref name="value"/> may be null. /// </summary> public virtual string RenderSingleOption(PrefixKind prefixKind, string name, string value) { Contract.Requires(name != null); var prefix = GetPrefixString(string.IsNullOrWhiteSpace(name) ? PrefixKind.None : prefixKind); var separator = GetSeparatorString(prefixKind, name, value); return(I($"{prefix}{EscapeArg(name)}{separator}{EscapeArg(value ?? string.Empty)}")); }
protected override void AppendPrefixParts(PrefixKind prefix) { var prefixString = prefix == PrefixKind.Awaitable ? "awaitable" : prefix == PrefixKind.Extension ? "extension" : "awaitable, extension"; AppendParts( SymbolDescriptionKind.Main, CreatePunctuation("("), CreateText(prefixString), CreatePunctuation(")"), CreateSpaces()); }
/// <summary> /// Converts a value of a specific unit to the specified target unit. /// </summary> /// <param name="source">The source unit value.</param> /// <param name="targetUnit">The target unit.</param> /// <param name="targetPrefix">The target prefix.</param> /// <returns></returns> public static decimal Calculate(UnitValue source, UnitKind targetUnit, PrefixKind targetPrefix = PrefixKind.None) { if (!CanConvert(source.Unit, targetUnit)) { throw new Exception("The specified source unit cannot be converted to the target unit."); } Prefix prefix = Prefixes .FirstOrDefault(x => x.Kind == targetPrefix) != null ? Prefixes.First(x => x.Kind == targetPrefix) : Prefixes.First(x => x.Kind == PrefixKind.None); return((decimal)Converters[source.Unit][targetUnit](source.GetValue()) / (decimal)prefix.Multiplier); }
private void loadFromStrings(List <string> lines) { for (int line = 0; line < lines.Count; line++) { if (!lines[line].StartsWith("#")) { string[] parts = lines[line].Split('|'); List <string> tokens = new List <string>(); tokens.AddRange(parts); if (tokens.Count < 4) { continue; } if (tokens[0].Length > 0 && (tokens[0].StartsWith("L") || tokens[0].StartsWith("M") || tokens[0].StartsWith("-"))) { tokens[0] = tokens[0].Substring(1); } PrefixKind entryKind = (PrefixKind)Convert.ToInt32(tokens[0].Substring(0, 2)); if (!entryKind.Equals(PrefixKind.DXCC)) { continue; } // populate new entry PrefixEntry entry = new PrefixEntry(); entry.Id = Entries.Count; entry.Kind = entryKind; // level string level = tokens[0].Substring(2); entry.Level = String.IsNullOrEmpty(level) ? 0 : Convert.ToInt32(level); // location entry.Data.Location.X = String.IsNullOrEmpty(tokens[1]) ? 0 : Convert.ToInt32(tokens[1]); entry.Data.Location.Y = String.IsNullOrEmpty(tokens[2]) ? 0 : Convert.ToInt32(tokens[2]); // rest entry.Data.Territory = tokens[3]; entry.Data.Prefix = tokens[4]; entry.Data.CQ = tokens[5]; entry.Data.ITU = tokens[6]; entry.Data.Continent = tokens[7]; entry.Data.TZ = tokens[8]; entry.Data.ADIF = tokens[9]; entry.Data.ProvinceCode = tokens[10]; entry.Mask = tokens[13]; Entries.Add(entry); } } }
private double Convert(PrefixKind kind) { Kind = kind; if (BytesLength == 0) { return(BytesLength); } switch (kind) { case PrefixKind.Binary: ConvertBinary(); break; case PrefixKind.Decimal: ConvertDecimal(); break; } return(ConvertedBytes); }
private void AssertOption(PrefixKind expectedPrefix, string expectedKey, string expectedValue, ParsedOption actualOption) { Assert.Equal(expectedPrefix, actualOption.PrefixKind); Assert.Equal(expectedKey, actualOption.Key); Assert.Equal(expectedValue, actualOption.Value); }
/// <nodoc/> public ParsedOption(PrefixKind prefixKind, string key, string value) { PrefixKind = prefixKind; Key = key; Value = value; }
/// <inheritdoc/> protected override string GetSeparatorString(PrefixKind prefix, string name, string value) => string.IsNullOrWhiteSpace(name) || string.IsNullOrWhiteSpace(value) ? string.Empty : " ";
/// <inheritdoc/> protected override string GetPrefixString(PrefixKind prefix) => prefix == PrefixKind.Long ? LongPrefix : prefix == PrefixKind.Either ? LongPrefix : prefix == PrefixKind.Short ? ShortPrefix : string.Empty;
/// <inheritdoc/> protected override string GetPrefixString(PrefixKind prefix) => prefix == PrefixKind.None ? string.Empty : "/";
/// <summary>Returns the separator (between key vand value) to use when rendering a single option (<seealso cref="RenderSingleOption"/>).</summary> protected abstract string GetSeparatorString(PrefixKind prefix, string name, string value);
/// <summary>Returns the prefix to use when rendering a single option (<seealso cref="RenderSingleOption"/>).</summary> protected abstract string GetPrefixString(PrefixKind prefix);
/// <summary> /// Writes a prefix /// </summary> /// <param name="instruction">Instruction</param> /// <param name="text">Prefix text</param> /// <param name="prefix">Prefix</param> public virtual void WritePrefix(ref Instruction instruction, string text, PrefixKind prefix) => Write(text, FormatterOutputTextKind.Prefix);
public void Parser_ParseTests(Type parserType, string[] args, int expectedRemainingArgs, PrefixKind expectedPrefix, string expectedKey, string expectedValue) { var parser = GetParserForType(parserType); var queue = new Queue <string>(args); var parsedOption = parser.Parse(queue); Assert.Equal(expectedRemainingArgs, queue.Count); AssertOption(expectedPrefix, expectedKey, expectedValue, parsedOption); // ensure that when render and then re-parse we get the same ParsedOption var rendered = parser.RenderSingleOption(expectedPrefix, expectedKey, expectedValue); var regenArgs = parser.SplitArgs(rendered); var reparsedOption = parser.Parse(new Queue <string>(regenArgs)); AssertOption(expectedPrefix, expectedKey, expectedValue, reparsedOption); }
/// <summary> /// Initializes an instance of the <see cref="UnitValue"/> class. /// </summary> /// <param name="baseValue">The base value.</param> /// <param name="unit">The unit kind.</param> /// <param name="prefix">The prefix.</param> public UnitValue(float baseValue, UnitKind unit, PrefixKind prefix) { BaseValue = baseValue; Prefix = prefix; Unit = unit; }
/// <summary> /// Converts the current bytes to the give kind /// </summary> /// <param name="kind">The kind of the bytes to be converted</param> /// <returns>The converted bytes</returns> public double ConvertTo(PrefixKind kind) => Convert(kind);
public void ByteConversionKindTest(ulong bytes, PrefixKind kind, double expected) { var converted = new ByteConversion(bytes, kind); Assert.Equal(expected, converted.ConvertedBytes); }
/// <summary> /// Converts the specified prefix to a float value. /// </summary> /// <param name="prefix">The prefix.</param> /// <returns></returns> public static float ToFloat(PrefixKind prefix) { switch (prefix) { case PrefixKind.None: return(1e0f); case PrefixKind.Deka: return(1e1f); case PrefixKind.Hekto: return(1e2f); case PrefixKind.Kilo: return(1e3f); case PrefixKind.Mega: return(1e6f); case PrefixKind.Giga: return(1e9f); case PrefixKind.Tera: return(1e12f); case PrefixKind.Peta: return(1e15f); case PrefixKind.Exa: return(1e18f); case PrefixKind.Deci: return(1e-1f); case PrefixKind.Centi: return(1e-2f); case PrefixKind.Milli: return(1e-3f); case PrefixKind.Mikro: return(1e-6f); case PrefixKind.Nano: return(1e-9f); case PrefixKind.Piko: return(1e-12f); case PrefixKind.Femto: return(1e-15f); case PrefixKind.Atto: return(1e-18f); case PrefixKind.Zepto: return(1e-21f); default: return(-1); } }
/// <summary> /// Creates a new instance of the <see cref="ByteConversion"/> class /// </summary> /// <param name="bytes">The bytes to be converted</param> /// <param name="kind">The kind of the bytes to be converted</param> public ByteConversion(ulong bytes, PrefixKind kind) { BytesLength = bytes; Convert(kind); }