Beispiel #1
0
        public void TestFlagParsingError()
        {
            string[] args  = new string[] { "-myintflag=", "--mystringflag", "test.txt", "-myintflag=10", "-myboolFlag" };
            var      flags = new Parser();

            var intFlag    = flags.AddIntFlag("myintflag", 0, "An integer flag");             // defaults to 0
            var stringFlag = flags.AddStringFlag("mystringflag", "nothing", "A string flag"); // defaults to "nothing"
            var boolFlag   = flags.AddBoolFlag("myboolFlag", false, "A bool flag");           // defaults to false.

            flags.Parse(args);

            Assert.IsTrue(flags.HasErrors);

            // The parser breaks once an error is enountered so these values would NOT be set
            FlagValue <string> flagString = flags["mystringflag"] as FlagValue <string>;

            Assert.AreNotEqual("test.txt", flagString.Value);

            FlagValue <bool> flagBool = flags["myboolFlag"] as FlagValue <bool>;

            Assert.AreNotEqual(true, flagBool.Value);

            FlagValue <int> flagInt = flags["myintflag"] as FlagValue <int>;

            Assert.AreNotEqual(10, flagInt.Value);
        }
Beispiel #2
0
        public static void Main(string[] args)
        {
            Parser             parser = new Parser();
            FlagValue <string> file   = parser.AddStringFlag("File", "", "File to read");

            parser.Parse(args);

            if (file == null)
            {
                throw new Exception("Unable to get file information");
            }

            try
            {
                FileReader             fr        = new FileReader();
                string                 line      = fr.Read(file.Value);
                Histogram              histogram = new Histogram();
                IEnumerable <WordPair> wordPairs = histogram.CreateHistogram(line);
                foreach (var item in wordPairs)
                {
                    Console.WriteLine(@"""{0}"" {1}", item.Text, item.Count);
                }
                Console.ReadKey();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.ReadKey();
            }
        }
Beispiel #3
0
 public void TestSetup()
 {
     parser     = new Parser();
     stringFlag = parser.AddStringFlag("MyStringFlag", "");
     intFlag    = parser.AddIntFlag("MyIntFlag", 0);
     boolFlag   = parser.AddBoolFlag("MyBoolFlag", false);
 }
Beispiel #4
0
 public PatternEntry(string pattern, string pattern2, string pattern3, FlagValue condition, FlagValue condition2)
 {
     Pattern    = pattern;
     Pattern2   = pattern2;
     Pattern3   = pattern3;
     Condition  = condition;
     Condition2 = condition2;
 }
 /// <summary>
 /// Sets the value of a conditional flag.
 /// </summary>
 /// <param name="p_strFlagName">The name of the falg whose value is to be set.</param>
 /// <param name="p_strValue">The value to which to set the flag.</param>
 /// <param name="p_pifPlugin">The plugin that is responsible for setting the flag's value.</param>
 public void SetFlagValue(string p_strFlagName, string p_strValue, Option p_pifPlugin)
 {
     if (!m_dicFlags.ContainsKey(p_strFlagName))
     {
         m_dicFlags[p_strFlagName] = new FlagValue();
     }
     m_dicFlags[p_strFlagName].Value = p_strValue;
     m_dicFlags[p_strFlagName].Owner = p_pifPlugin;
 }
Beispiel #6
0
        public IActionResult DeleteFlagValue(long id)
        {
            FlagValue a = FlagValue_repo.Find(id);

            if (a == null)
            {
                return(NotFound());
            }
            FlagValue_repo.Delete(a);
            return(Ok());
        }
Beispiel #7
0
 private void SetDefault()
 {
     this.ForegroundBright     = FlagValue.Unset;
     this.BackgroundBright     = FlagValue.Unset;
     this.Underline            = FlagValue.Unset;
     this.Inverse              = FlagValue.Unset;
     this.HaveForeground       = this.HaveBackground = false;
     this.HaveBasicForeground  = this.HaveBasicBackground = true;
     this.BasicForegroundColor = DefaultForegroundColor;
     this.BasicBackgroundColor = DefaultBackgroundColor;
 }
            public void Should_Return_Correct_String_Representation_From_ToString_If_Value_Is_Not_Set(
                bool isSet,
                string expected)
            {
                // Given
                var flag = new FlagValue <string>();

                flag.IsSet = isSet;

                // When
                var result = flag.ToString();

                // Then
                result.ShouldBe(expected);
            }
            public void Should_Return_Correct_String_Representation_From_ToString(
                string value,
                bool isSet,
                string expected)
            {
                // Given
                var flag = new FlagValue <string>
                {
                    Value = value,
                    IsSet = isSet,
                };

                // When
                var result = flag.ToString();

                // Then
                result.ShouldBe(expected);
            }
        public bool ContainsFlagAt(int wordIndex, FlagValue flag)
        {
#if DEBUG
            if (wordIndex < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(wordIndex));
            }
#endif

            if (wordIndex < Words.Count)
            {
                var detail = Words[wordIndex];
                if (detail != null)
                {
                    return(detail.ContainsFlag(flag));
                }
            }

            return(false);
        }
Beispiel #11
0
        public void TestFlagParsing()
        {
            string[] args  = new string[] { "--mystringflag", "test.txt", "-myintflag=10", "-myboolFlag" };
            var      flags = new Parser();

            var intFlag    = flags.AddIntFlag("myintflag", 0, "An integer flag");             // defaults to 0
            var stringFlag = flags.AddStringFlag("mystringflag", "nothing", "A string flag"); // defaults to "nothing"
            var boolFlag   = flags.AddBoolFlag("myboolFlag", false, "A bool flag");           // defaults to false.

            flags.Parse(args);

            Assert.IsFalse(flags.HasErrors);
            FlagValue <string> flagString = flags["mystringflag"] as FlagValue <string>;

            Assert.AreEqual("test.txt", flagString.Value);

            FlagValue <bool> flagBool = flags["myboolFlag"] as FlagValue <bool>;

            Assert.AreEqual(true, flagBool.Value);

            FlagValue <int> flagInt = flags["myintflag"] as FlagValue <int>;

            Assert.AreEqual(10, flagInt.Value);
        }
Beispiel #12
0
    static bool handleProperties(XmlNode node, ElementInfo ei)
    {
        if (ei.properties == null)
          ei.properties = new ArrayList ();

        XmlElement elt = node as XmlElement;
        if (elt == null)
          return true;

        foreach (XmlElement property in elt.ChildNodes) {
          if (IsHidden (property))
        continue;

          PropertyInfo pi = new PropertyInfo ();
          pi.name = property["name"].InnerText;
          pi.managed_name = (property["managed_name"] != null) ? property["managed_name"].InnerText : null;
          pi.type = property["type"].InnerText;
          pi.readable = property["flags"].InnerText.IndexOf ('R') != -1;
          pi.writeable = property["flags"].InnerText.IndexOf ('W') != -1;

          if (property["enum-values"] != null) {
        pi.enuminfo = new EnumInfo ();
        pi.enuminfo.flag = false;
        pi.enuminfo.values = new ArrayList ();

        foreach (XmlNode val in property["enum-values"].ChildNodes) {
          EnumValue env = new EnumValue ();

          env.name = val.Attributes["nick"].InnerText;
          env.value = Int32.Parse (val.Attributes["value"].InnerText);
          pi.enuminfo.values.Add (env);
        }
          } else if (property["flags-values"] != null) {
        pi.enuminfo = new EnumInfo ();
        pi.enuminfo.flag = true;
        pi.enuminfo.values = new ArrayList ();

        foreach (XmlNode val in property["flags-values"].ChildNodes) {
          FlagValue env = new FlagValue ();

          env.name = val.Attributes["nick"].InnerText;
          env.value = UInt32.Parse (val.Attributes["value"].InnerText);
          pi.enuminfo.values.Add (env);
        }
          }

          ei.properties.Add (pi);
        }

        return true;
    }
 /// <summary>
 /// Sets the value of a conditional flag.
 /// </summary>
 /// <param name="p_strFlagName">The name of the falg whose value is to be set.</param>
 /// <param name="p_strValue">The value to which to set the flag.</param>
 /// <param name="p_pifPlugin">The plugin that is responsible for setting the flag's value.</param>
 public void SetFlagValue(string p_strFlagName, string p_strValue, PluginInfo p_pifPlugin)
 {
     if (!m_dicFlags.ContainsKey(p_strFlagName))
         m_dicFlags[p_strFlagName] = new FlagValue();
     m_dicFlags[p_strFlagName].Value = p_strValue;
     m_dicFlags[p_strFlagName].Owner = p_pifPlugin;
 }
 public bool ContainsAnyFlags(FlagValue a, FlagValue b, FlagValue c, FlagValue d) => HasFlags && Flags.ContainsAny(a, b, c, d);
 public bool ContainsAnyFlags(FlagValue a, FlagValue b) => HasFlags && Flags.ContainsAny(a, b);
 public NumberToFlagMappingBuilder <TResult> AddMapping(FlagValue digit, Expression <Func <TResult, bool> > targetExpression)
 {
     _mappingDictionary.Set((int)digit, targetExpression);
     return(this);
 }
 public Flag()
 {
     Value = FlagValue.Public;
 }
        public static void DisplayMethod(Type a, FlagValue f)
        {
            Console.Write(a.Name);
            if (f == FlagValue.Public)
            {
                Console.WriteLine(" -- public");
            }
            else if (f == FlagValue.Static)
            {
                Console.WriteLine(" -- static");
            }

            foreach (var meth in a.GetMethods())
            {
                if (f == FlagValue.Static)
                {
                    if (!meth.IsStatic)
                    {
                        continue;
                    }
                }

                if (f == FlagValue.Public)
                {
                    if (meth.IsStatic)
                    {
                        continue;
                    }
                }

                Console.Write("public ");
                if (meth.IsStatic)
                {
                    Console.Write("static ");
                }

                Console.Write(meth.ReturnType.Name + " ");
                Console.Write(meth.Name + " (");

                ArrayList paramValue = new ArrayList();
                bool      isFirst    = true;
                foreach (var param in meth.GetParameters())
                {
                    if (isFirst)
                    {
                        isFirst = false;
                    }
                    else
                    {
                        Console.Write(", ");
                    }

                    Console.Write(param.ParameterType.Name + " " + param.Name);

                    if (param.ParameterType == typeof(String))
                    {
                        paramValue.Add(GetRandomString(5));
                    }

                    if (param.ParameterType == typeof(int))
                    {
                        paramValue.Add(GetRandomInt());
                    }

                    if (param.ParameterType == typeof(double))
                    {
                        paramValue.Add((double)GetRandomInt());
                    }

                    if (param.ParameterType == typeof(object))
                    {
                        paramValue.Add(null);
                    }
                }

                Console.Write(")");
                Console.WriteLine();


                if (meth.ReturnType != typeof(void))
                {
                    if (f == FlagValue.Public)
                    {
                        Console.WriteLine("-----Rusult: " +
                                          a.GetMethod(meth.Name).Invoke(
                                              Activator.CreateInstance(a),
                                              GetObjParamValue(paramValue)
                                              ));
                    }
                    else if (f == FlagValue.Static)
                    {
                        Console.WriteLine("-----Rusult: " +
                                          a.GetMethod(meth.Name).Invoke(
                                              a,
                                              GetObjParamValue(paramValue)
                                              ));
                    }
                }
            }
        }
Beispiel #19
0
 private void Reset()
 {
     this.ForegroundBright    = this.BackgroundBright = this.Underline = this.Inverse = FlagValue.None;
     this.HaveBasicForeground = this.HaveForeground = this.HaveXtermForeground = false;
     this.HaveBasicBackground = this.HaveBackground = this.HaveXtermBackground = false;
 }
Beispiel #20
0
 public IActionResult UpdateFlagValue([FromBody] FlagValue model)
 {
     FlagValue_repo.Update(model);
     return(new OkObjectResult(new { FlagValueID = model.FlagValueId }));
 }
    static bool handleProperties(XmlNode node, ElementInfo ei)
    {
        if (ei.properties == null)
        {
            ei.properties = new ArrayList();
        }

        XmlElement elt = node as XmlElement;

        if (elt == null)
        {
            return(true);
        }

        foreach (XmlElement property in elt.ChildNodes)
        {
            if (IsHidden(property))
            {
                continue;
            }

            PropertyInfo pi = new PropertyInfo();
            pi.name         = property["name"].InnerText;
            pi.managed_name = (property["managed_name"] != null) ? property["managed_name"].InnerText : null;
            pi.type         = property["type"].InnerText;
            pi.readable     = property["flags"].InnerText.IndexOf('R') != -1;
            pi.writeable    = property["flags"].InnerText.IndexOf('W') != -1;

            if (property["enum-values"] != null)
            {
                pi.enuminfo        = new EnumInfo();
                pi.enuminfo.flag   = false;
                pi.enuminfo.values = new ArrayList();

                foreach (XmlNode val in property["enum-values"].ChildNodes)
                {
                    EnumValue env = new EnumValue();

                    env.name  = val.Attributes["nick"].InnerText;
                    env.value = Int32.Parse(val.Attributes["value"].InnerText);
                    pi.enuminfo.values.Add(env);
                }
            }
            else if (property["flags-values"] != null)
            {
                pi.enuminfo        = new EnumInfo();
                pi.enuminfo.flag   = true;
                pi.enuminfo.values = new ArrayList();

                foreach (XmlNode val in property["flags-values"].ChildNodes)
                {
                    FlagValue env = new FlagValue();

                    env.name  = val.Attributes["nick"].InnerText;
                    env.value = UInt32.Parse(val.Attributes["value"].InnerText);
                    pi.enuminfo.values.Add(env);
                }
            }

            ei.properties.Add(pi);
        }

        return(true);
    }
Beispiel #22
0
 private bool GetFlag(FlagValue flagValue)
 {
     return((Value & (ushort)flagValue) > 0);
 }
Beispiel #23
0
 private void ResetFlag(FlagValue flagValue)
 {
     Value &= (ushort)~((ushort)flagValue);
 }
Beispiel #24
0
 private void SetFlag(FlagValue flagValue)
 {
     Value |= (ushort)flagValue;
 }
        private static void FetchOptions(CommandContext state)
        {
            state.Commands.Clear();

            foreach (MethodInfo i in state.CurrentObject.GetType().GetMethods(BindingFlags.Public | BindingFlags.Instance))
            {
                var cmd = i.GetCustomAttribute(typeof(CommandAttribute)) as CommandAttribute;

                if (cmd == null)
                {
                    continue;
                }

                CommandValue value = new CommandValue()
                {
                    Arguments = cmd,
                    Method    = i,
                    Instance  = state.CurrentObject
                };
                state.Commands.Replace(value.Arguments.Name, value);
            }

            foreach (PropertyInfo i in state.CurrentObject.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance))
            {
                var cmd    = i.GetCustomAttribute(typeof(CommandAttribute)) as CommandAttribute;
                var nvalue = i.GetCustomAttribute(typeof(NamedValueAttribute)) as NamedValueAttribute;
                var flag   = i.GetCustomAttribute(typeof(FlagValueAttribute)) as FlagValueAttribute;
                if (cmd != null)
                {
                    CommandValue value = new CommandValue()
                    {
                        Arguments = cmd,
                        Property  = i,
                        Instance  = state.CurrentObject
                    };
                    state.Commands.Replace(value.Arguments.Name, value);
                }

                if (nvalue != null)
                {
                    NamedValue value = new NamedValue()
                    {
                        Arguments = nvalue,
                        Property  = i,
                        Instance  = state.CurrentObject
                    };
                    state.NamedValues.Replace(value.Arguments.Name, value);
                    if (value.Arguments.Name == "")
                    {
                        state.DefaultValue = value;
                    }
                }

                if (flag != null)
                {
                    FlagValue value = new FlagValue()
                    {
                        Arguments = flag,
                        Property  = i,
                        Instance  = state.CurrentObject
                    };
                    state.LongFlags.Replace(value.Arguments.Name, value);
                    state.ShortFlags.Replace(value.Arguments.ShortName, value);
                }
            }
        }
Beispiel #26
0
 /// <summary>
 /// Returns a <see cref="string"/> that represents this instance.
 /// </summary>
 /// <returns>A <see cref="string"/> that represents this instance.</returns>
 public override string ToString() => $"{FlagName} {FlagValue.ToString(x => x.ToString())}";
Beispiel #27
0
 /// <summary>
 /// Add your own Custom FlagValue handler for flag parsing.
 /// </summary>
 public FlagValue <T> Add <T>(string name, FlagValue <T> val)
 {
     _flags[name] = val;
     return(val);
 }
 public Flag(FlagValue a)
 {
     Value = a;
 }
 public bool ContainsFlag(FlagValue flag) => Flags.Contains(flag);
Beispiel #30
0
 internal static bool Is(this FlagValue <bool> flagValue, bool target, bool defaultValue = false)
 {
     return(flagValue.IsSet ? flagValue.Value == target : defaultValue == target);
 }
Beispiel #31
0
        public SetGraphicsRendition(string bufferData) : base(bufferData)
        {
            this.ForegroundBright = FlagValue.None;
            this.BackgroundBright = FlagValue.None;
            this.Underline        = FlagValue.None;
            this.Inverse          = FlagValue.None;

            if (this.Parameters.Count == 0)
            {
                this.SetDefault();
                return;
            }

            var p = 0;

            while (p < this.Parameters.Count)
            {
                var pValue = this.ParameterToNumber(p, defaultValue: -1);
                switch (pValue)
                {
                case 0:
                    this.SetDefault();
                    break;

                case 1:
                    this.ForegroundBright = FlagValue.Set;
                    break;

                case 22:
                    this.ForegroundBright = FlagValue.Unset;
                    break;

                case 4:
                    this.Underline = FlagValue.Set;
                    break;

                case 24:
                    this.Underline = FlagValue.Unset;
                    break;

                case 7:
                    this.Inverse = FlagValue.Set;
                    break;

                case 27:
                    this.Inverse = FlagValue.Unset;
                    break;

                case 30:
                case 31:
                case 32:
                case 33:
                case 34:
                case 35:
                case 36:
                case 37:
                    this.HaveBasicForeground  = true;
                    this.BasicForegroundColor = (Colors)(pValue - 30);
                    break;

                case 38:
                {
                    if (this.ReadXtermColorInfo(ref p, out var idx, out var color))
                    {
                        if (idx > -1)
                        {
                            this.HaveXtermForeground  = true;
                            this.XtermForegroundColor = idx;
                        }
                        else
                        {
                            this.HaveForeground  = true;
                            this.ForegroundColor = color;
                        }
                        break;
                    }
                    this.Reset();
                    return;
                }

                case 39:
                    this.HaveBasicForeground  = true;
                    this.BasicForegroundColor = DefaultForegroundColor;
                    break;

                case 40:
                case 41:
                case 42:
                case 43:
                case 44:
                case 45:
                case 46:
                case 47:
                    this.HaveBasicBackground  = true;
                    this.BasicBackgroundColor = (Colors)(pValue - 40);
                    break;

                case 48:
                {
                    if (this.ReadXtermColorInfo(ref p, out var idx, out var color))
                    {
                        if (idx > -1)
                        {
                            this.HaveXtermBackground  = true;
                            this.XtermBackgroundColor = idx;
                        }
                        else
                        {
                            this.HaveBackground  = true;
                            this.BackgroundColor = color;
                        }
                        break;
                    }
                    this.Reset();
                    return;
                }

                case 49:
                    this.HaveBasicBackground  = true;
                    this.BasicBackgroundColor = DefaultBackgroundColor;
                    break;

                case 90:
                case 91:
                case 92:
                case 93:
                case 94:
                case 95:
                case 96:
                case 97:
                    this.HaveBasicForeground  = true;
                    this.ForegroundBright     = FlagValue.Set; // XXX: idk if this is right
                    this.BasicForegroundColor = (Colors)(pValue - 90);
                    break;

                case 100:
                case 101:
                case 102:
                case 103:
                case 104:
                case 105:
                case 106:
                case 107:
                    this.HaveBasicBackground  = true;
                    this.BackgroundBright     = FlagValue.Set; // same as above.
                    this.BasicBackgroundColor = (Colors)(pValue - 100);
                    break;
                }

                ++p;
            }
        }