private string GetOptionAttribute(System.Reflection.FieldInfo f)
        {
            object[] attrs = f.GetCustomAttributes(typeof(OptionDescription), true);
            if (attrs != null && attrs.Length == 1)
            {
                StringBuilder     result = new StringBuilder();
                OptionDescription descr  = (OptionDescription)attrs[0];
                if (descr.Required)
                {
                    result.Append("(required) ");
                }
                result.Append(descr.Description);
                if (descr.ShortForm != null)
                {
                    result.Append("[short form: " + descr.ShortForm + "]");
                }
                object[] optionsFor = f.GetCustomAttributes(typeof(OptionFor), true);
                string[] options;

                if (optionsFor != null && optionsFor.Length == 1 && TryGetOptions(((OptionFor)optionsFor[0]).options, out options))
                {
                    result.AppendLine(Environment.NewLine + "Detailed explanation:");
                    for (int i = 0; i < options.Length; i++)
                    {
                        result.Append(string.Format("{0} : {1}" + Environment.NewLine, i, options[i]));
                    }
                }

                return(result.ToString());
            }
            return(null);
        }
            /// <summary>
            /// Creates an instance of OptionDescription from a handle to IOptionDescription
            /// </summary>
            internal static OptionDescription Create(IOptionDescription optionDescription, bool shouldSuppressCOMExceptions = true, bool shouldReleaseCOMObject = true)
            {
                if (optionDescription == null)
                {
                    throw new ArgumentNullException(nameof(optionDescription));
                }

                var od = new OptionDescription(optionDescription.Id, optionDescription.Heading, optionDescription.Description);

                try
                {
                    od._labels = optionDescription.Labels.ToList();
                }
                catch (COMException) when(shouldSuppressCOMExceptions)
                {
                    // do nothing here - the exception filter does it all.
                }
                finally
                {
                    if (shouldReleaseCOMObject)
                    {
                        Marshal.ReleaseComObject(optionDescription);
                    }
                }

                return(od);
            }
Example #3
0
        public Dialog(ICanyonShooterGame game, OptionDescription xml, int district,
                      Dictionary <string, object> Data, Dictionary <string, string> Format, List <string> Names)
            : base(game as Game)
        {
            this.game     = game;
            this.xml      = xml;
            this.Data     = Data;
            this.Format   = Format;
            this.Names    = Names;
            this.district = district;
            this.visible  = true;
            this.list     = new OptionList(game, xml, district, Data, Format, Names, false, this);

            OptMod   = new Dictionary <string, OptionModulationButton>();
            SlideMod = new Dictionary <string, HSlideBar>();
            int counter = Names.Count;

            foreach (Button g in this.list)
            {
                OptionModulationButton opt = getOptionModulationButton(g, Names[Names.Count - counter]);
                if (opt != null)
                {
                    OptMod.Add(g.getButtonName(), opt);
                }
                else
                {
                    HSlideBar hsb = getSlideBar(g, Names[Names.Count - counter]);
                    if (hsb != null)
                    {
                        SlideMod.Add(g.getButtonName(), hsb);
                    }
                }
                counter--;
            }

            foreach (OptionpartDescription i in xml.OptionParts)
            {
                if (i.Number == this.district)
                {
                    this.Position = new Rectangle(game.Graphics.Device.Viewport.Width - 398 + (i.Position.X - 398),
                                                  i.Position.Y, i.Position.Width, list.Height + i.Position.Height);
                    this.startposition = new Vector2(game.Graphics.Device.Viewport.Width - 398 + (i.StartPosition.X - 398),
                                                     i.StartPosition.Y);
                    foreach (OptionButtonDescription g in i.Buttons)
                    {
                        if (g.ButtonName == "Akzeptieren")
                        {
                            accept = new Button(game, g.ButtonName, startposition, g.height, g.width,
                                                "OptionDialog\\" + g.ButtonImage, true, this);
                        }
                        else if (g.ButtonName == "Ablehnen")
                        {
                            decline = new Button(game, g.ButtonName, startposition, g.height, g.width,
                                                 "OptionDialog\\" + g.ButtonImage, true, this);
                        }
                    }
                }
            }
        }
Example #4
0
 public void PrintCategoryUsage(OptionDescription.OptionCategory category)
 {
     Console.WriteLine(s_optionCategoryName[(int)category]);
     foreach (KeyValuePair <string, OptionDescription> kvp in m_optionMap)
     {
         OptionDescription option = kvp.Value;
         if (option.m_optionCategory == category && kvp.Key == option.m_shortName)
         {
             PrintOptionUsage(option);
         }
     }
 }
Example #5
0
            private OptionDescription GetOptionDescriptionImplWithRetries(string optionId, bool suppressCOMExceptions)
            {
                OptionDescription optionDescription = null;
                bool callSucceeded =
                    RetryHelper.TryExecuteFunction(
                        func: () => GetOptionDescriptionImpl(optionId),
                        result: out optionDescription,
                        preamble: () => Init(suppressCOMExceptions),
                        ignoredExceptions: SuppressedExceptions[suppressCOMExceptions]);

                return(callSucceeded ? optionDescription : null);
            }
Example #6
0
        public OptionList(ICanyonShooterGame game, OptionDescription xml, int district, Dictionary <string, object> Data, Dictionary <string, string> Format, List <string> Names, bool hori, object caller)
            : base(game as ICanyonShooterGame)
        {
            this.caller   = caller;
            this.xml      = xml;
            this.Data     = Data;
            this.Format   = Format;
            this.Names    = Names;
            this.district = district;
            this.height   = 0;
            init("", hori);

            changes = new Dictionary <string, int>();
            this.setChanges();
        }
 public void PrintCategoryUsage(OptionDescription.OptionCategory category)
 {
     Console.WriteLine(s_optionCategoryName[(int)category]);
     foreach (KeyValuePair<string, OptionDescription> kvp in m_optionMap)
     {
         OptionDescription option = kvp.Value;
         if (option.m_optionCategory == category && kvp.Key == option.m_shortName)
         {
             PrintOptionUsage(option);
         }
     }
 }
 public void PrintOptionUsage(OptionDescription option)
 {
     Console.WriteLine("    {-{0}|-{1}} {2}", option.m_shortName, option.m_longName, option.m_arguments);
     Console.WriteLine("    {0}", option.m_descriptionText);
 }
 public void AddOptionsToMap(OptionDescription[] optionArray)
 {
     foreach (OptionDescription option in optionArray)
     {
         m_optionMap.Add(option.m_shortName, option);
         m_optionMap.Add(option.m_longName, option);
     }            
 }
Example #10
0
 //getter for possible descriptions
 public string[] GetOptionDescription()
 {
     return(OptionDescription.Split(","));
 }
Example #11
0
        public bool ParseCommandLineFlags(string[] args)
        {
            bool retVal = true;

            for (int index = 0; index < args.Length; index++)
            {
                string            arg    = args[index].Substring(args[index].IndexOf("-") + 1);
                OptionDescription option = null;
                m_optionMap.TryGetValue(arg, out option);
                if (option == null)
                {
                    retVal = false;
                    break;
                }
                int optionIndex = option.m_optionIndex;

                switch (optionIndex)
                {
                case (int)DryadLINQAppOptions.BDJAO_AMD64:
                case (int)DryadLINQAppOptions.BDJAO_I386:
                case (int)DryadLINQAppOptions.BDJAO_Retail:
                case (int)DryadLINQAppOptions.BDJAO_Debug:
                    break;

                case (int)DryadLINQAppOptions.DNAO_MaxAggregateInputs:
                    if ((index + 1) >= args.Length)
                    {
                        DryadLogger.LogCritical(String.Format("The argument for option '{0}' was missing.\n", args[index]));
                        retVal = false;
                    }
                    else
                    {
                        int maxInputs;
                        if (!Int32.TryParse(args[index + 1], out maxInputs))
                        {
                            DryadLogger.LogCritical(String.Format("The argument '{0}' for option '{1}' could not be parsed as an integer.\n", args[index + 1], args[index]));
                            retVal = false;
                        }
                        else
                        {
                            m_maxAggregateInputs = maxInputs;
                            index++;
                        }
                    }
                    break;

                case (int)DryadLINQAppOptions.DNAO_MaxAggregateFilterInputs:
                    if ((index + 1) >= args.Length)
                    {
                        DryadLogger.LogCritical(String.Format("The argument for option '{0}' was missing.\n", args[index]));
                        retVal = false;
                    }
                    else
                    {
                        int maxInputs;
                        if (!Int32.TryParse(args[index + 1], out maxInputs))
                        {
                            DryadLogger.LogCritical(String.Format("The argument '{0}' for option '{1}' could not be parsed as an integer.\n", args[index + 1], args[index]));
                            retVal = false;
                        }
                        else
                        {
                            m_maxAggregateFilterInputs = maxInputs;
                            index++;
                        }
                    }
                    break;


                case (int)DryadLINQAppOptions.DNAO_AggregateThreshold:
                    if ((index + 1) >= args.Length)
                    {
                        DryadLogger.LogCritical(String.Format("The argument for option '{0}' was missing.\n", args[index]));
                        retVal = false;
                    }
                    else
                    {
                        UInt64 threshold;
                        if (!UInt64.TryParse(args[index + 1], out threshold))
                        {
                            DryadLogger.LogCritical(String.Format("The argument '{0}' for option '{1}' could not be parsed as a UIN64.\n", args[index + 1], args[index]));
                            retVal = false;
                        }
                        else
                        {
                            m_aggregateThreshold = threshold;
                            index++;
                        }
                    }
                    break;

                case (int)DryadLINQAppOptions.DNAO_NoClusterAffinity:
                    m_clusterAffinity = false;
                    break;

                default:
                    DryadLogger.LogCritical(String.Format("Unknown command-line option {0}\n", optionIndex));
                    retVal = false;
                    break;
                }
            }

            if (!retVal)
            {
                PrintUsage(args[0]);
            }
            return(retVal);
        }
Example #12
0
 public void PrintOptionUsage(OptionDescription option)
 {
     Console.WriteLine("    {-{0}|-{1}} {2}", option.m_shortName, option.m_longName, option.m_arguments);
     Console.WriteLine("    {0}", option.m_descriptionText);
 }
Example #13
0
 public Option(OptionDescription description)
 {
     Description = description;
 }
Example #14
0
            private OptionDescription GetOptionDescriptionImpl(string optionId)
            {
                IOptionDescription iod = _speller.Value.GetOptionDescription(optionId);

                return((iod != null) ? OptionDescription.Create(iod, false, true) : null);
            }