Пример #1
0
        public override void BuildUI(OptionInfo option, GameObject element)
        {
            var control = element.GetComponentInChildren <UnityEngine.UI.Toggle>();

            control.isOn = option.GetPropertyValue <bool>();
            control.onValueChanged.AddListener(value => option.SetPropertyValue(value));
        }
Пример #2
0
        public override void BuildUI(OptionInfo option, GameObject element)
        {
            var control = element.GetComponentInChildren <UnityEngine.UI.Dropdown>();

            control.options = Options.Select(opt => new UnityEngine.UI.Dropdown.OptionData(opt)).ToList();
            var valueIndex = GetInitialIndex(option.GetPropertyValue <string>());

            if (valueIndex >= 0)
            {
                control.value = valueIndex;
            }
            else
            {
                control.value = 0;
                SaveValue(option, Options[0], 0);
            }
            control.onValueChanged.AddListener(index => {
                if (index < 0 || index >= Options.Count)
                {
                    control.value = 0;
                    return;
                }
                SaveValue(option, Options[index], index);
            });
        }
Пример #3
0
        public static OptionInfo  GetOptionInfo(GMFileContent content)
        {
            var ret = new OptionInfo();

            var oe = content.Options;

            ret.InfoFlags = oe->GEN8FlagsDup;

            ret.Constants = new Dictionary <string, string>((int)oe->ConstMap.Count);
            for (uint i = 0; i < oe->ConstMap.Count; i++)
            {
                uint inoff = (&oe->ConstMap.Offsets)[i << 1];
                uint ouoff = (&oe->ConstMap.Offsets)[(i << 1) | 1];
                //Console.Error.Write(inoff.ToString("X") + " -> " + ouoff.ToString("X"));
                string instr = StringFromOffset(content, inoff);
                string oustr = StringFromOffset(content, ouoff);
                //Console.Error.WriteLine(": " + instr + " -> " + oustr);
                ret.Constants   [instr] = oustr;
            }

            ret._pad0 = new uint[2] {
                oe->_pad0[0], oe->_pad0[1]
            };
            ret._pad1 = new uint[12] {
                oe->_pad1[0], oe->_pad1[1], oe->_pad1[2], oe->_pad1[3],
                oe->_pad1[4], oe->_pad1[5], oe->_pad1[6], oe->_pad1[7],
                oe->_pad1[8], oe->_pad1[9], oe->_pad1[10], oe->_pad1[11]
            };

            return(ret);
        }
Пример #4
0
        public override bool TryFetch(OptionInfo option, string language, out object value)
        {
            if (language != LanguageNames.CSharp)
            {
                value = null;
                return false;
            }

            if (option.Key.Equals(AllLanguageOptionReferences.UseTab))
            {
                value = languageSetting.fInsertTabs != 0;
                return true;
            }

            if (option.Key == AllLanguageOptionReferences.TabSize)
            {
                value = (int)languageSetting.uTabSize;
                return true;
            }

            if (option.Key == AllLanguageOptionReferences.IndentationSize)
            {
                value = (int)languageSetting.uIndentSize;
                return true;
            }

            if (option.Key == AllLanguageOptionReferences.DebugMode)
            {
                value = option.DefaultValue;
                return true;
            }

            value = null;
            return false;
        }
Пример #5
0
        /// <summary>
        /// Provides appropriate convertor for given type
        /// </summary>
        /// <param name="info">Option info with needed type information</param>
        /// <returns></returns>
        internal static IValueConverter getConverter(OptionInfo info)
        {
            Type tp;

            if (info.IsContainer)
            {
                tp = info.ElementType;
            }
            else
            {
                tp = info.ExpectedType;
            }

            if (!convertors.ContainsKey(tp))
            {
                EnumConverter conv;
                if (EnumConverter.TryCreate(info, out conv))
                {
                    convertors.Add(tp, conv);
                }
                else
                {
                    throw new ParserException(userMsg: "Error with convertors", developerMsg: "Unable to create convertor for given type Converters::getConverter");
                }
            }

            return(convertors[tp]);
        }
Пример #6
0
        public void Stop()
        {
            voteTimer.Stop();

            ongoingVotes.Remove(this);

            IEnumerable <OptionInfo> mostVotedOptions = options.Where(a => a.votes == options.Max(a2 => a2.votes));

            if (mostVotedOptions.Count() > 1)
            {
                TShock.Utils.Broadcast("The vote has tied.", Color.Teal);
                return;
            }

            OptionInfo winningOption = mostVotedOptions.First();

            string resultsFormatted = "";

            foreach (OptionInfo optionInfo in options)
            {
                resultsFormatted += string.Format("{0} - {1} vote{2}\n", optionInfo.option, optionInfo.votes, optionInfo.votes == 1 ? "" : "s");
            }
            resultsFormatted = resultsFormatted.Trim();

            TShock.Utils.Broadcast(resultsFormatted, Color.Aqua);
            TShock.Utils.Broadcast(string.Format("The winning option was \"{0}\" with {1} vote{2}!", winningOption.option, winningOption.votes, winningOption.votes == 1 ? "" : "s"), Color.Orange);

            if (winningOption.methodUponWin == null)
            {
                return;
            }

            winningOption.methodUponWin();
        }
Пример #7
0
    public void CreateOptionInfo()
    {
        string[] rowName = new string[] {
            "id",
            "DialogueId",
            "addLove",
            "content",
        };
        string[] type = new
                        string[] {
            "INT",
            "INT",
            "INT",
            "VARCHAR(128)",
        };

        var d = CreateTable(opTable, type, rowName);


        OptionInfo w = new OptionInfo();

        w.Id         = 2;
        w.DialogueId = 3;
        w.addLove    = 0;
        w.content    = "qwe";
        var list = GetOptionInfoList(w);

        InsertToTable(opTable, list);
    }
Пример #8
0
        public override bool TryFetch(OptionInfo option, string language, out object value)
        {
            if (language != LanguageNames.CSharp)
            {
                value = null;
                return(false);
            }

            if (option.Key.Equals(AllLanguageOptionReferences.UseTab))
            {
                value = languageSetting.fInsertTabs != 0;
                return(true);
            }

            if (option.Key == AllLanguageOptionReferences.TabSize)
            {
                value = (int)languageSetting.uTabSize;
                return(true);
            }

            if (option.Key == AllLanguageOptionReferences.IndentationSize)
            {
                value = (int)languageSetting.uIndentSize;
                return(true);
            }

            if (option.Key == AllLanguageOptionReferences.DebugMode)
            {
                value = option.DefaultValue;
                return(true);
            }

            value = null;
            return(false);
        }
Пример #9
0
        /// <summary>
        /// Register container option, because of equality comparison.
        /// </summary>
        /// <param name="optionInfo">Option info for container option.</param>
        /// <param name="container">Container to be registered.</param>
        private void registerContainer(OptionInfo optionInfo, object container)
        {
            var containerElements = StructureFactory.GetContainerElements(container);
            var backup            = new List <object>(containerElements);

            _containerBackups[optionInfo.Name] = backup;
        }
Пример #10
0
        AddHandler(
            string stOption,                // Unique flag for Option
            string stShortcut,              // Optional shortcut (can be null);
            Blue.Public.OptionHandler ha,   // Option Handler
            string stDescription,           // short 1-line description
            string stFullHelp               // long description
            )
        {
            Debug.Assert(!m_fIsLocked, "Can't add new optionhandler after we've locked:" + stDescription);


            OptionInfo info = new OptionInfo(stOption, stShortcut, ha, stDescription, stFullHelp);


            if (m_tblOptions[stOption] == null)
            {
                if (stShortcut != null)
                {
                    Debug.Assert(m_tblOptions[stShortcut] == null);
                    m_tblOptions[stShortcut] = info;
                }
                m_tblOptions[stOption] = info;
            }
            else
            {
                // Since end users can't define option handlers, we should know about
                // any collisions during the debug phase.
                Debug.Assert(false, "Handler already defined");
            }
        }
Пример #11
0
            public sealed override object this[object key]
            {
                get
                {
                    object option = base[key];

                    if (option == null)
                    {
                        string optionKey = names[key.ToString()];

                        if (optionKey != null)
                        {
                            option = base[optionKey];
                        }
                    }

                    return(option);
                }
                set
                {
                    OptionInfo option = (OptionInfo)value;

                    base[key] = option;

                    if (option.HasBothNames)
                    {
                        names[option.LongName] = option.ShortName;
                    }
                }
            }
Пример #12
0
        public override void BuildUI(OptionInfo option, GameObject element)
        {
            var control = element.GetComponentInChildren <UnityEngine.UI.InputField>();

            control.text = option.GetPropertyValue <string>();
            control.onValueChanged.AddListener(value => option.SetPropertyValue(value));
        }
Пример #13
0
        DisplayHelpSummary()
        {
            Console.WriteLine("BLUE COMPILER OPTIONS");
            Console.WriteLine();

            foreach (DictionaryEntry x in m_tblOptions)
            {
                OptionInfo info  = (OptionInfo)x.Value;
                string     stKey = (string)x.Key;
                if (info.Option != stKey)
                {
                    continue; // skip over shortcuts
                }
                string stShortcut = "";
                if (info.Shortcut != null)
                {
                    stShortcut = "(/" + info.Shortcut + ")";
                }
                Console.WriteLine("/{0,-10}{1} {2}", info.Option, info.ShortHelp, stShortcut);
            }

            // also print help for response files
            Console.WriteLine("{0, -10} specify a response file", "@<file>");

            // Print some other general tips
            Console.WriteLine("Use /help:help for more details.");
        }
        /// <summary>
        /// 跨式期权开仓
        /// </summary>
        /// <param name="dataToday"></param>
        /// <param name="signal"></param>
        /// <param name="positions"></param>
        /// <param name="myAccount"></param>
        /// <param name="pairs"></param>
        /// <param name="today"></param>
        /// <param name="index"></param>
        /// <param name="duration"></param>
        private void openStrangle(ref Dictionary <string, List <KLine> > dataToday, ref Dictionary <string, MinuteSignal> signal, ref SortedDictionary <DateTime, Dictionary <string, PositionsWithDetail> > positions, ref BasicAccount myAccount, ref SortedDictionary <DateTime, List <StranglePair> > pairs, DateTime today, int index, double duration)
        {
            DateTime now            = TimeListUtility.IndexToMinuteDateTime(Kit.ToInt_yyyyMMdd(today), index);
            double   etfPriceNow    = dataToday[targetVariety][index].open;
            var      optionInfoList = OptionUtilities.getUnmodifiedOptionInfoList(this.optionInfoList, today);
            //选取指定的看涨期权
            var        list = OptionUtilities.getOptionListByDate(OptionUtilities.getOptionListByStrike(OptionUtilities.getOptionListByOptionType(OptionUtilities.getOptionListByDuration(optionInfoList, today, duration), "认购"), etfPriceNow, etfPriceNow + 0.5), Kit.ToInt_yyyyMMdd(today)).OrderBy(x => x.strike).ToList();
            OptionInfo call = list[0];
            //根据给定的看涨期权选取对应的看跌期权
            OptionInfo put = OptionUtilities.getCallByPutOrPutByCall(optionInfoList, call);

            if (call.strike != 0 && put.strike != 0 && (call.modifiedDate > today.AddDays(10) || call.modifiedDate < today)) //跨式期权组合存在进行开仓
            {
                tradeAssistant(ref dataToday, ref signal, call.optionCode, call.contractMultiplier, today, now, index);
                tradeAssistant(ref dataToday, ref signal, put.optionCode, put.contractMultiplier, today, now, index);
                StranglePair openPair = new StranglePair()
                {
                    callCode = call.optionCode, putCode = put.optionCode, callPosition = call.contractMultiplier, putPosition = put.contractMultiplier, endDate = call.endDate, etfPrice = etfPriceNow, callStrike = call.strike, putStrike = put.strike, modifiedDate = now, strangleOpenPrice = dataToday[call.optionCode][index].open + dataToday[put.optionCode][index].open, closeDate = new DateTime(), closePrice = 0
                };
                List <StranglePair> pairList = new List <StranglePair>();
                pairList.Add(openPair);
                pairs.Add(now, pairList);
                MinuteTransactionWithBar.ComputePosition(signal, dataToday, ref positions, ref myAccount, slipPoint: slipPoint, now: now, nowIndex: index);
            }
        }
        /// <summary>
        /// 获取对应的期权合约
        /// </summary>
        /// <param name="duration"></param>
        /// <param name="strike"></param>
        /// <param name="etfPriceNow"></param>
        /// <param name="type"></param>
        /// <param name="today"></param>
        /// <returns></returns>
        private OptionInfo getOptionCode(double duration, double etfPriceNow, string type, DateTime today)
        {
            OptionInfo option         = new OptionInfo();
            var        optionInfoList = OptionUtilities.getUnmodifiedOptionInfoList(this.optionInfoList, today);

            if (type == "认购")
            {
                //选取指定的看涨期权
                var list = OptionUtilities.getOptionListByDate(OptionUtilities.getOptionListByStrike(OptionUtilities.getOptionListByOptionType(OptionUtilities.getOptionListByDuration(optionInfoList, today, duration), "认购"), etfPriceNow, etfPriceNow + 0.5), Kit.ToInt_yyyyMMdd(today)).OrderBy(x => x.strike).ToList();
                if (list.Count > 0)
                {
                    option = list[0];
                }
            }
            else if (type == "认沽")
            {
                //选取指定的看跌期权
                var list = OptionUtilities.getOptionListByDate(OptionUtilities.getOptionListByStrike(OptionUtilities.getOptionListByOptionType(OptionUtilities.getOptionListByDuration(optionInfoList, today, duration), "认沽"), etfPriceNow - 0.5, etfPriceNow), Kit.ToInt_yyyyMMdd(today)).OrderBy(x => x.strike).ToList();
                if (list.Count > 0)
                {
                    option = list[0];
                }
            }
            return(option);
        }
Пример #16
0
        static void ParseOptions(ref OptionInfo optionInfo, string[] args)
        {
            if (args.Length < 2) {
                PrintUsageAndExit();
            }

            for (int argPos = 0; argPos < args.Length; ) {
                switch (args[argPos]) {
                case "-ch0":
                    if (args.Length <= argPos + 2) {
                        PrintUsageAndExit();
                    }
                    ParseInputFileOption(ref optionInfo.channels[0], args[argPos + 1], args[argPos + 2]);
                    argPos += 3;
                    break;
                case "-ch1":
                    if (args.Length <= argPos + 2) {
                        PrintUsageAndExit();
                    }
                    ParseInputFileOption(ref optionInfo.channels[1], args[argPos + 1], args[argPos + 2]);
                    argPos += 3;
                    break;
                default:
                    optionInfo.outputWavFileName = args[argPos];
                    ++argPos;
                    break;
                }
            }

            if (optionInfo.channels[0].chFileName == string.Empty ||
                optionInfo.channels[1].chFileName == string.Empty ||
                optionInfo.outputWavFileName == string.Empty) {
                PrintUsageAndExit();
            }
        }
Пример #17
0
        private bool TryParseHelpVerb(string[] args, object options, Pair <MethodInfo, HelpVerbOptionAttribute> helpInfo,
                                      OptionMap optionMap)
        {
            TextWriter helpWriter = _settings.HelpWriter;

            if (helpInfo != null && helpWriter != null)
            {
                if (string.Compare(args[0], helpInfo.Right.LongName, GetStringComparison(_settings)) == 0)
                {
                    // User explicitly requested help
                    string verb = args.FirstOrDefault();
                    if (verb != null)
                    {
                        OptionInfo verbOption = optionMap[verb];
                        if (verbOption != null)
                        {
                            if (verbOption.GetValue(options) is null)
                            {
                                // We need to create an instance also to render help
                                verbOption.CreateInstance(options);
                            }
                        }
                    }

                    DisplayHelpVerbText(options, helpInfo, verb);
                    return(true);
                }
            }

            return(false);
        }
    private void UpdateOptionsSelectorArrowVisibility()
    {
        int cy = cursorOp.getY() - 1;

        if (cy < 0)
        {
            if (PD.gameType == PersistData.GT.Online)
            {
                cursorOp.setY(1);
                cursorOpDisplay.UpdatePosition(1, true);
                cy = 1;
            }
            else
            {
                begin.GetComponent <SpriteRenderer>().sprite = beginSheet[1];
                cursorOpDisplay.ToggleArrowVisibility(false);
            }
        }
        if (cy >= 0)
        {
            cursorOpDisplay.ToggleArrowVisibility(true);
            OptionInfo o = options[cy];
            cursorOpDisplay.HideAnArrowIfAtCorner(o.curVal, o.minVal, o.maxVal);
        }
    }
Пример #19
0
            public ParseResult Parse(StringEnumerator argumentEnumerator, IDictionary map, object options)
            {
                string[] parts = argumentEnumerator.Current.Substring(2).Split(new char[] { '=' }, 2);

                OptionInfo option = (OptionInfo)map[parts[0]];

                if (option == null)
                {
                    return(ParseResult.Failure);
                }

                option.IsDefined = true;

                if (!option.IsBoolean)
                {
                    if (parts.Length == 1 && !argumentEnumerator.IsLast && !IsInputValue(argumentEnumerator.Next))
                    {
                        return(ParseResult.Failure);
                    }

                    if (parts.Length == 2)
                    {
                        if (option.SetValue(parts[1], options))
                        {
                            return(ParseResult.Success);
                        }
                        else
                        {
                            return(ParseResult.Failure);
                        }
                    }
                    else
                    {
                        if (option.SetValue(argumentEnumerator.Next, options))
                        {
                            return(ParseResult.Success | ParseResult.MoveOnNextElement);
                        }
                        else
                        {
                            return(ParseResult.Failure);
                        }
                    }
                }
                else
                {
                    if (parts.Length == 2)
                    {
                        return(ParseResult.Failure);
                    }
                    if (option.SetValue(true, options))
                    {
                        return(ParseResult.Success);
                    }
                    else
                    {
                        return(ParseResult.Failure);
                    }
                }
            }
Пример #20
0
 public void Reset_Option()
 {
     Debug.Log("Option Info Reset");
     op = new OptionInfo();
     op.option_music = 0.5f;
     op.option_sound = 0.5f;
     Save_Option();
 }
Пример #21
0
 public void Delete_Option()
 {
     Debug.Log("Option Info Deleted");
     op = new OptionInfo();
     if (File.Exists(Application.persistentDataPath + "/optionInfo.gd"))
     {
         File.Delete(Application.persistentDataPath + "/optionInfo.gd");
     }
 }
Пример #22
0
 public List <string> GetOptionInfoList(OptionInfo info)
 {
     tmpValuesList.Clear();
     tmpValuesList.Add(info.Id.ToString());
     tmpValuesList.Add(info.DialogueId.ToString());
     tmpValuesList.Add(info.addLove.ToString());
     tmpValuesList.Add(info.content);
     return(tmpValuesList);
 }
Пример #23
0
        public override void BuildUI(OptionInfo option, GameObject element)
        {
            var sliderObj = element.GetComponentInChildren <UnityEngine.UI.Slider>();

            sliderObj.minValue = Min;
            sliderObj.maxValue = Max;
            sliderObj.value    = option.GetPropertyValue <float>();
            sliderObj.onValueChanged.AddListener(value => option.SetPropertyValue(value));
        }
Пример #24
0
        public override void Set(OptionInfo info, string arg)
        {
            var argIndex = ArgList.IndexOf(arg);
            var argValue = ArgList[argIndex + 1];
            var value    = TranslateActivator.Activate(info.TranslatorType, info.TargetType, argValue);
            var property = typeof(TOptions).GetProperty(info.Name);

            property?.SetValue(Options, value);
        }
Пример #25
0
        //-------------------------------------------------------------------------
        // Dispatch a single option
        //-------------------------------------------------------------------------
        internal void DispatchOption(string stArg, ArrayList alFiles)
        {
            int cch = stArg.Length;

            if (cch >= 2)
            {
                // Repsonse file
                if (stArg[0] == '@')
                {
                    DispatchResponseFile(stArg.Substring(1), alFiles);
                }

                // Normal option, connected to an OptionHandler
                else if (stArg[0] == '/')
                {
                    string stParam = "";
                    int    i       = stArg.IndexOf(':');
                    if (i > -1)
                    {
                        stParam = stArg.Substring(i + 1);
                    }

                    string stOption = (i == -1) ? stArg : stArg.Substring(0, i);

                    OptionInfo info = m_tblOptions[stOption.Substring(1)] as OptionInfo;

                    if (info != null)
                    {
                        Blue.Public.OptionHandler handler = info.Handler;

                        try
                        {
                            handler(stParam);
                        }
                        catch (OptionErrorException e)
                        {
                            PrintError_OptionError(stOption, stParam, e.Message);
                        }
                    }
                    else
                    {
                        PrintError_UnrecognizedOption(stOption);
                    }
                }

                // Filename
                else
                {
                    alFiles.Add(stArg);
                }
            }
            else
            {
                // @todo - we're just ignoring the others, is that ok?
            }
        }
        public void ForSetup_AsRequired_SetsDefaultValueNull()
        {
            var parser = new CommandLineParser <TestOptions>();
            var info   = new OptionInfo("Path", typeof(string));
            var setup  = new OptionSetup <TestOptions, string>(parser, info);

            setup.AsRequired("Path to files", "-p", "--path");

            info.DefaultValue.ShouldBeNull();
        }
        public void ForSetupWithDefault_AsOptional_SetsDefaultValue()
        {
            var parser = new CommandLineParser <TestOptions>();
            var info   = new OptionInfo("Path", typeof(string));
            var setup  = new OptionSetup <TestOptions, string>(parser, info);

            setup.AsOptional("Path to files", "-p", "--path", @"c:\temp");

            info.DefaultValue.ShouldBe(@"c:\temp");
        }
        public void ForSetup_AsOptional_SetsIsOptionalTrue()
        {
            var parser = new CommandLineParser <TestOptions>();
            var info   = new OptionInfo("Path", typeof(string));
            var setup  = new OptionSetup <TestOptions, string>(parser, info);

            setup.AsOptional("Path to files", "-p", "--path");

            info.IsOptional.ShouldBeTrue();
        }
        public void ForSetup_AsOptional_SetsDefaultTranslator()
        {
            var parser = new CommandLineParser <TestOptions>();
            var info   = new OptionInfo("Path", typeof(string));
            var setup  = new OptionSetup <TestOptions, string>(parser, info);

            setup.AsOptional("Path to files", "-p", "--path");

            info.TranslatorType.Name.ShouldContain("DefaultTranslator");
        }
Пример #30
0
        public ParserContext ToCoreInstance(OptionInfo verbOption)
        {
            var newArguments = new string[this.Arguments.Length - 1];
            if (this.Arguments.Length > 1)
            {
                Array.Copy(this.Arguments, 1, newArguments, 0, this.Arguments.Length - 1);
            }

            return new ParserContext(newArguments, verbOption.GetValue(this.Target));
        }
Пример #31
0
        private static IParsingResult GetParseResult(OptionInfo <string> optionInfo, OptionData optionData)
        {
            ParsingResult <string> result = ParsingResult <string> .SuccessfulResult(optionData.Data.FirstOrDefault());

            if (optionData.Data.Count > 1)
            {
                result = ParsingResult <string> .FailedResult($"Error: {optionInfo.Name} can only be specified once");
            }
            return(optionInfo.Parse(new SuccessfulResultCollection(optionInfo, result)));
        }
        public void ForSetupWithTranslator_AsRequired_SetsTranslator()
        {
            var parser = new CommandLineParser <TestOptions>();
            var info   = new OptionInfo("Loggers", typeof(string[]));
            var setup  = new OptionSetup <TestOptions, string[]>(parser, info);

            setup.AsRequired <TestLoggerListTranslator>("List of loggers", "-l", "--loggers");

            info.TranslatorType.Name.ShouldContain("TestLoggerListTranslator");
        }
        public sealed override ParserState Parse(IStringEnumerator argumentEnumerator, IOptionMap map, object options)
        {
            string[]   parts  = argumentEnumerator.Current.Substring(2).Split(new char[] { '=' }, 2);
            OptionInfo option = map[parts[0]];

            if (option == null)
            {
                return(ParserState.Failure);
            }
            option.IsDefined = true;
            if (!option.IsBoolean)
            {
                if (parts.Length == 1 && !argumentEnumerator.IsLast && !ArgumentParser.IsInputValue(argumentEnumerator.Next))
                {
                    return(ParserState.Failure);
                }
                if (parts.Length == 2)
                {
                    if (option.SetValue(parts[1], options))
                    {
                        return(ParserState.Success);
                    }
                    else
                    {
                        return(ParserState.Failure);
                    }
                }
                else
                {
                    if (option.SetValue(argumentEnumerator.Next, options))
                    {
                        return(ParserState.Success | ParserState.MoveOnNextElement);
                    }
                    else
                    {
                        return(ParserState.Failure);
                    }
                }
            }
            else
            {
                if (parts.Length == 2)
                {
                    return(ParserState.Failure);
                }
                if (option.SetValue(true, options))
                {
                    return(ParserState.Success);
                }
                else
                {
                    return(ParserState.Failure);
                }
            }
        }
Пример #34
0
        static void Main(string[] args)
        {
            OptionInfo optionInfo = new OptionInfo(2);

            ParseOptions(ref optionInfo, args);

            WavData ch0Wav = ReadWavFromFile(optionInfo.channels[0].chFileName);
            WavData ch1Wav = ReadWavFromFile(optionInfo.channels[1].chFileName);

            if (ch0Wav.NumSamples != ch1Wav.NumSamples) {
                Console.WriteLine("E: NumSamples mismatch. ch0.numSamples={0}, ch1.numSamples={1}",
                    ch0Wav.NumSamples, ch1Wav.NumSamples);
                PrintUsageAndExit();
            }

            WavData writeWav = new WavData();
            List<PcmSamples1Channel> channels = new List<PcmSamples1Channel>();
            for (int i=0; i<2; ++i) {
                channels.Add(new PcmSamples1Channel(ch0Wav.NumSamples, ch0Wav.BitsPerSample));
            }

            int ch0UseCh = optionInfo.channels[0].chFileUseCh;
            int ch1UseCh = optionInfo.channels[1].chFileUseCh;
            for (int i=0; i<ch0Wav.NumSamples; ++i) {
                channels[0].Set16(i, ch0Wav.Sample16Get(ch0UseCh, i));
                channels[1].Set16(i, ch1Wav.Sample16Get(ch1UseCh, i));
            }

            writeWav.Create(ch0Wav.SampleRate, ch0Wav.BitsPerSample, channels);

            try {
                using (BinaryWriter bw = new BinaryWriter(File.Open(optionInfo.outputWavFileName, FileMode.CreateNew))) {
                    writeWav.Write(bw);
                }
            } catch (Exception ex) {
                Console.WriteLine("E: {0}", ex);
                PrintUsageAndExit();
            }
        }
Пример #35
0
        public override bool TryPersist(OptionInfo option, string language, object value)
        {
            if (language != LanguageNames.CSharp)
            {
                value = null;
                return false;
            }

            if (option.Key == AllLanguageOptionReferences.UseTab)
            {
                languageSetting.fInsertTabs = (uint)((bool)value ? 1 : 0);
                SetUserPreferences();
                return true;
            }

            if (option.Key == AllLanguageOptionReferences.TabSize)
            {
                languageSetting.uTabSize = (uint)value;
                SetUserPreferences();
                return true;
            }

            if (option.Key == AllLanguageOptionReferences.IndentationSize)
            {
                languageSetting.uIndentSize = (uint)value;
                SetUserPreferences();
                return true;
            }

            if (option.Key == AllLanguageOptionReferences.DebugMode)
            {
                // Currently we don't store it.
                return true;
            }

            return false;
        }
Пример #36
0
 private object ValidateValue(OptionInfo info, string value, ref string message)
 {
     object result = null;
     try
     {
         if (info.Descriptor.PropertyType.IsEnum)
         {
             result = Enum.Parse(info.Descriptor.PropertyType, value, true);
         }
         else
         {
             result = Convert.ChangeType(value.Trim(new[] { '\"' }), info.Descriptor.PropertyType);
         }
     }
     catch
     {
         message = "Value '$VALUE$' for command line option '$OPTION$' is not valid.".FormatNamed("option", info.Descriptor.DisplayName, "value", value);
         return null;
     }
     if (info.Attribute.MinValue != null)
     {
         IComparable comparable = result as IComparable;
         if (comparable.CompareTo(info.Attribute.MinValue) == -1)
         {
             message = "Value '$VALUE$' for command line option '$OPTION$' is out of bounds.".FormatNamed("option", info.Descriptor.DisplayName, "value", value);
             return null;
         }
     }
     if (info.Attribute.MaxValue != null)
     {
         IComparable comparable = result as IComparable;
         if (comparable.CompareTo(info.Attribute.MaxValue) == 1)
         {
             message = "Value '$VALUE$' for command line option '$OPTION$' is out of bounds.".FormatNamed("option", info.Descriptor.DisplayName, "value", value);
             return null;
         }
     }
     return result;
 }
Пример #37
0
        public static OptionMap Create(object target, IParserSettings settings)
        {
            var list = ReflectionUtil.RetrievePropertyList<BaseOptionAttribute>(target);
            if (list == null)
            {
                return null;
            }

            var map = new OptionMap(list.Count, settings);

            foreach (var pair in list)
            {
                if (pair.Left != null && pair.Right != null)
                {
                    string uniqueName;
                    if (pair.Right.AutoLongName)
                    {
                        uniqueName = pair.Left.Name.ToLowerInvariant();
                        pair.Right.LongName = uniqueName;
                    }
                    else
                    {
                        uniqueName = pair.Right.UniqueName;
                    }

                    map[uniqueName] = new OptionInfo(pair.Right, pair.Left, settings.ParsingCulture);
                }
            }

            map.RawOptions = target;
            return map;
        }
Пример #38
0
        private void SetSettingsObject(object settingsObj)
        {
            _setttingsObject = settingsObj;
            _options.Clear();
            _optionDict.Clear();

            PropertyDescriptorCollection descriptors = TypeDescriptor.GetProperties(_setttingsObject);
            foreach (PropertyDescriptor descriptor in descriptors)
            {
                CommandLineOptionAttribute attribute = descriptor.Attributes[typeof(CommandLineOptionAttribute)] as CommandLineOptionAttribute;
                if (attribute != null)
                {
            #if DEBUG
                    ValidateOption(attribute, descriptor);
            #endif
                    OptionInfo info = new OptionInfo()
                    {
                        Attribute = attribute,
                        Descriptor = descriptor
                    };
                    _options.Add(info);
                    if (attribute.Alias == null)
                    {
                        _optionDict.Add(descriptor.DisplayName, info);
                    }
                    else
                    {
                        _optionDict.Add(attribute.Alias, info);
                    }
                }
            }
        }
Пример #39
0
        public static OptionMap Create(
            object target,
            IList<Pair<PropertyInfo, VerbOptionAttribute>> verbs,
            IParserSettings settings)
        {
            var map = new OptionMap(verbs.Count, settings);

            foreach (var verb in verbs)
            {
                var optionInfo = new OptionInfo(verb.Right, verb.Left, settings.ParsingCulture)
                {
                    HasParameterLessCtor = verb.Left.PropertyType.GetConstructor(Type.EmptyTypes) != null
                };

                if (!optionInfo.HasParameterLessCtor && verb.Left.GetValue(target, null) == null)
                {
                    throw new ParserException("Type {0} must have a parameterless constructor or" +
                        " be already initialized to be used as a verb command.".FormatInvariant(verb.Left.PropertyType));
                }

                map[verb.Right.UniqueName] = optionInfo;
            }

            map.RawOptions = target;
            return map;
        }
Пример #40
0
        private void BuildMutuallyExclusiveMap(OptionInfo option)
        {
            var setName = option.MutuallyExclusiveSet;
            if (!this.mutuallyExclusiveSetMap.ContainsKey(setName))
            {
                this.mutuallyExclusiveSetMap.Add(setName, new MutuallyExclusiveInfo(option));
            }

            this.mutuallyExclusiveSetMap[setName].IncrementOccurrence();
        }
Пример #41
0
        private void FillOptionInfo(TradeInfo info, FXOption fxo, OptionInfo optionInfo)
        {
            if (info.SecurityType.Equals(FxoInfo.SimpleFXO))
            {
                // european digital and european
                if (info.OptionStyle.Equals("D"))
                {
                    var dinfo = optionInfo as DigitalInfo;
                    if (dinfo == null)
                    {
                        dinfo = new DigitalInfo();
                        fxo.OptionInfo = dinfo;
                        dinfo.Option = fxo;
                    }
                    fxo.ExerciseType = OptionExerciseType.Digital;
                    dinfo.ExerciseType = OptionExerciseType.European;
                    dinfo.StartDate = info.Maturity;
                    dinfo.EndDate = info.Maturity;
                    if (fxo.OptionType == OptionType.Call)
                    {
                        dinfo.BarrierStrike = fxo.OptionStrike;
                        dinfo.BarrierType = OptionBarrierType.Touch;
                        dinfo.LowerBarrierStrike = 0;
                        dinfo.LowerBarrierType = OptionBarrierType.None;
                    }
                    else
                    {
                        dinfo.LowerBarrierStrike = fxo.OptionStrike;
                        dinfo.LowerBarrierType = OptionBarrierType.Touch;
                        dinfo.BarrierStrike = 0;
                        dinfo.BarrierType = OptionBarrierType.None;
                    }
                    // pay off, currency, and payout style: deferred or...
                }
                else
                    fxo.ExerciseType = OptionExerciseType.European;
                    // settle currency
            }
            /*
            else if (info.SecurityType.Equals(TradeInfo.BarrierFXO))
            {
                // barrier
                var binfo = optionInfo as BarrierInfo;
                if (binfo == null)
                {
                    binfo = new BarrierInfo();
                    fxo.OptionInfo = binfo;
                    binfo.Option = fxo;
                }
                binfo.ExerciseType = OptionExerciseType.European;
                // start/end date
                // barrier type and strike

            }
            else if (info.SecurityType.Equals(TradeInfo.TouchFXO))
            {
                // touch
                var tinfo = optionInfo as DigitalInfo;
                if (tinfo == null)
                {
                    tinfo = new DigitalInfo();
                    fxo.OptionInfo = tinfo;
                    tinfo.Option = fxo;
                }
                tinfo.ExerciseType = OptionExerciseType.American;
                // barrier strike and type
                // rebate amount
            }*/
        }
Пример #42
0
    public static AvailableOptions workOutOptionsForActivityAndLangArea(ApplicationID para_appID, int para_langArea)
    {
        //int appID = (int) para_appID;

        string levelDBFilePath = "Localisation_Files/"+langCode+"/Instructions_"+langCode+"_"+para_appID;

        Dictionary<string,List<int>> validKeysAndCodes = new Dictionary<string, List<int>>();
        List<string> listKeys = new List<string>();

        TextAsset ta = (TextAsset) Resources.Load(levelDBFilePath,typeof(TextAsset));

        if(ta==null){
            Debug.LogError("Localisation_Files/"+langCode+"/Instructions_"+langCode+"_"+para_appID);

        }
        string text = ta.text;
        string[] lineArr = text.Split('\n');
        foreach(string line in lineArr)
        {
            string[] values = line.Split(',');

            // values[0] == application ID
            // values[1] == language area
            // values[3] == index
            // values[4] == default level string.

            if(System.Convert.ToInt32(values[0]) == para_langArea)
            {
                // Check for valid attributes.

                string lvlStr = values[3];
                string[] lvlStrParts = lvlStr.Split('-');

                for(int i=0; i<lvlStrParts.Length; i++)
                {
                    string tmpPart = lvlStrParts[i];
                    string charKey = ""+tmpPart[0];
                    int numCode = int.Parse(tmpPart.Substring(1));

                    if( ! validKeysAndCodes.ContainsKey(charKey))
                    {
                        validKeysAndCodes.Add(charKey,new List<int>());
                        listKeys.Add (charKey);
                    }

                    if( ! (validKeysAndCodes[charKey].Contains(numCode)))
                    {
                        validKeysAndCodes[charKey].Add(numCode);
                    }
                }
            }
        }

        // Sort items.
        List<string> tmpKeys = new List<string>(validKeysAndCodes.Keys);
        for(int i=0; i<tmpKeys.Count; i++)
        {
            validKeysAndCodes[tmpKeys[i]].Sort();
        }

        Dictionary<string,string[]> validKeysAndReadableOptions = new Dictionary<string, string[]>();
        Dictionary<string,string> validKeysAndTitles = new Dictionary<string, string>();

        foreach(string key in listKeys)
        {

            List<string> nxtReadableOptions = new List<string>();

            //if(wvServCom.language==LanguageCode.EN){
            // Special override for text to speech. (Displays Off and On instead of 0 and 1).
            if(key == "T")
            {
                if (validKeysAndCodes[key].Count==1)
                    continue;

                validKeysAndTitles.Add(key,LocalisationMang.translate("Text-to-speech"));

                nxtReadableOptions.AddRange(new string[] {LocalisationMang.translate("Off"),LocalisationMang.translate("On")});
                for(int k=2; k<validKeysAndCodes[key].Count; k++)
                {
                    nxtReadableOptions.Add("?");
                }
                validKeysAndReadableOptions.Add(key,nxtReadableOptions.ToArray());

            }
            else if((key == "A"))
            {
                if (validKeysAndCodes[key].Count==1)
                    continue;

                string title = LocalisationMang.translate("Accuracy");

                if(para_appID==ApplicationID.MAIL_SORTER){
                    title = LocalisationMang.translate("Packages");
                }else if(para_appID==ApplicationID.SERENADE_HERO){
                    title = LocalisationMang.translate("Alternatives");
                }else if(para_appID==ApplicationID.WHAK_A_MOLE){
                    title = LocalisationMang.translate("Distractors");
                }else if(para_appID==ApplicationID.MOVING_PATHWAYS){
                    title = LocalisationMang.translate("Number of paths");
                }else if(para_appID==ApplicationID.ENDLESS_RUNNER){
                    title = LocalisationMang.translate("Words per door");
                }

                validKeysAndTitles.Add(key,title);

                if(para_appID==ApplicationID.MAIL_SORTER){
                    for(int k=0; k<validKeysAndCodes[key].Count; k++)
                    {
                        nxtReadableOptions.Add(""+(validKeysAndCodes[key][k]+1));
                    }

                }else{

                    for(int k=0; k<validKeysAndCodes[key].Count; k++)
                    {
                        nxtReadableOptions.Add(""+validKeysAndCodes[key][k]);
                    }

                }
                validKeysAndReadableOptions.Add(key,nxtReadableOptions.ToArray());

            }else if(key == "S")
            {
                if (validKeysAndCodes[key].Count==1)
                    continue;

                string title = LocalisationMang.translate("Speed");

                if(para_appID==ApplicationID.MAIL_SORTER){
                    title = LocalisationMang.translate("Rotating speed");
                }else if(para_appID==ApplicationID.WHAK_A_MOLE){
                    title = LocalisationMang.translate("Monkey speed");
                }else if(para_appID==ApplicationID.MOVING_PATHWAYS){
                    title = LocalisationMang.translate("Square size");
                }else if(para_appID==ApplicationID.ENDLESS_RUNNER){
                    title = LocalisationMang.translate("Monkey speed");
                }else if(para_appID==ApplicationID.DROP_CHOPS){
                    title = LocalisationMang.translate("Split time");
                }else if(para_appID==ApplicationID.SERENADE_HERO){
                    title = LocalisationMang.translate("Speed");
                }else if(para_appID==ApplicationID.TRAIN_DISPATCHER){
                    title = LocalisationMang.translate("Attempts");
                }

                validKeysAndTitles.Add(key,title);

                if(para_appID==ApplicationID.DROP_CHOPS){//Invert the labels for solomon
                    for(int k=0; k<validKeysAndCodes[key].Count; k++)
                    {
                        nxtReadableOptions.Add(new string[]{LocalisationMang.translate("High"),LocalisationMang.translate("Medium"),LocalisationMang.translate("Low")}[validKeysAndCodes[key][k]]);
                    }

                }else{
                for(int k=0; k<validKeysAndCodes[key].Count; k++)
                {
                    nxtReadableOptions.Add(new string[]{LocalisationMang.translate("Low"),LocalisationMang.translate("Medium"),LocalisationMang.translate("High")}[validKeysAndCodes[key][k]]);
                }
                }
                validKeysAndReadableOptions.Add(key,nxtReadableOptions.ToArray());

            }else if(key == "M")
            {
                if (validKeysAndCodes[key].Count==1)
                    continue;

                string title = LocalisationMang.translate("Mode");

                validKeysAndTitles.Add(key,title);

                if(langCode==LanguageCode.EN){

                    if(para_langArea==6){
                        nxtReadableOptions.Add("Letter to letter");
                        nxtReadableOptions.Add("Letter to word");

                    }else if(para_langArea==3){
                        nxtReadableOptions.Add("Category");
                        nxtReadableOptions.Add("Count");

                    }else{

                        for(int k=0; k<validKeysAndCodes[key].Count; k++)
                        {
                            nxtReadableOptions.Add(""+validKeysAndCodes[key][k]);
                        }
                    }

                }else{

                    //if(para_appID==ApplicationID.MOVING_PATHWAYS){

                    nxtReadableOptions.Add(LocalisationMang.translate("Letter to letter"));
                    nxtReadableOptions.Add(LocalisationMang.translate("Letter to word"));

                    //}else{

                    //}
                }
                validKeysAndReadableOptions.Add(key,nxtReadableOptions.ToArray());

            }else if(key == "W")
            {

                validKeysAndTitles.Add(key,LocalisationMang.translate("Word difficulty"));

                if (validKeysAndCodes[key].Count==1){

                    List<int> options = new List<int>();
                    for(int k=0; k<3; k++)
                    {
                        nxtReadableOptions.Add(new string[]{LocalisationMang.translate("Easy"),LocalisationMang.translate("Medium"),LocalisationMang.translate("Hard")}[k]);
                        options.Add((k+1)*3);
                    }

                    validKeysAndCodes[key] = options;
                }else{
                    for(int k=0; k<validKeysAndCodes[key].Count; k++)
                    {
                        //Debug.Log(validKeysAndCodes[key][k]);
                        nxtReadableOptions.Add(new string[]{LocalisationMang.translate("Easy"),"","","",LocalisationMang.translate("Medium"),"","","","",LocalisationMang.translate("Hard")}[validKeysAndCodes[key][k]]);
                    }

                }
                validKeysAndReadableOptions.Add(key,nxtReadableOptions.ToArray());

            }else if(key == "B")
            {
                if (validKeysAndCodes[key].Count==1)
                    continue;

                string title = LocalisationMang.translate("Number of words");

                if(para_appID==ApplicationID.MAIL_SORTER){
                    title = LocalisationMang.translate("Number of rounds");
                }else if(para_appID==ApplicationID.MOVING_PATHWAYS){
                    title = LocalisationMang.translate("Words per difficulty");
                }

                validKeysAndTitles.Add(key,title);

                if (validKeysAndCodes[key].Count==1){

                    List<int> options = new List<int>();
                    for(int k=1; k<10; k++)
                    {
                        nxtReadableOptions.Add(""+k);
                        options.Add((k));
                    }

                    validKeysAndCodes[key] = options;

                }else{

                    if(para_appID==ApplicationID.MAIL_SORTER){
                        for(int k=0; k<validKeysAndCodes[key].Count; k++)
                        {
                            nxtReadableOptions.Add(""+validKeysAndCodes[key][k]/4);
                        }
                    }else{
                        for(int k=0; k<validKeysAndCodes[key].Count; k++)
                        {
                            nxtReadableOptions.Add(""+validKeysAndCodes[key][k]);
                        }
                    }

                }
                validKeysAndReadableOptions.Add(key,nxtReadableOptions.ToArray());

            }else if(key=="X"){

                if (validKeysAndCodes[key].Count==1)
                    continue;

                validKeysAndTitles.Add(key,LocalisationMang.translate("Tricky words"));
                for(int k=0; k<validKeysAndCodes[key].Count; k++)
                {
                    nxtReadableOptions.Add(new string[]{"0/4","1/4","2/4","3/4"}[validKeysAndCodes[key][k]]);
                }
                validKeysAndReadableOptions.Add(key,nxtReadableOptions.ToArray());

            }else if(key=="D"){
                if (validKeysAndCodes[key].Count==1)
                    continue;

                validKeysAndTitles.Add(key,LocalisationMang.translate("Distractors"));
                for(int k=0; k<validKeysAndCodes[key].Count; k++)
                {
                    nxtReadableOptions.Add(new string[]{"0/4","1/4","2/4","3/4"}[validKeysAndCodes[key][k]]);
                }
                validKeysAndReadableOptions.Add(key,nxtReadableOptions.ToArray());

            }

        }

        // Construct the AvailableOptions data structure.
        AvailableOptions avOps = null;
        Dictionary<string,OptionInfo> opInfoLookup = new Dictionary<string, OptionInfo>();

        foreach(KeyValuePair<string,string[]> pair in  validKeysAndReadableOptions)
        {
            if( ! opInfoLookup.ContainsKey(pair.Key))
            {
                OptionInfo nxtOpInf = new OptionInfo(pair.Key,validKeysAndCodes[pair.Key],validKeysAndReadableOptions[pair.Key],validKeysAndTitles[pair.Key]);
                opInfoLookup.Add(pair.Key,nxtOpInf);
            }
        }

        avOps = new AvailableOptions(new List<string>(validKeysAndReadableOptions.Keys),opInfoLookup);
        return avOps;
    }
Пример #43
0
        private static void SetParserStateIfNeeded(object options, OptionInfo option, bool? required, bool? mutualExclusiveness)
        {
            var list = ReflectionUtil.RetrievePropertyList<ParserStateAttribute>(options);
            if (list.Count == 0)
            {
                return;
            }

            var property = list[0].Left;

            // This method can be called when parser state is still not intialized
            if (property.GetValue(options, null) == null)
            {
                property.SetValue(options, new CommandLine.ParserState(), null);
            }

            var parserState = (IParserState)property.GetValue(options, null);
            if (parserState == null)
            {
                return;
            }

            var error = new ParsingError
            {
                BadOption =
                {
                    ShortName = option.ShortName,
                    LongName = option.LongName
                }
            };

            if (required != null)
            {
                error.ViolatesRequired = required.Value;
            }

            if (mutualExclusiveness != null)
            {
                error.ViolatesMutualExclusiveness = mutualExclusiveness.Value;
            }

            parserState.Errors.Add(error);
        }
Пример #44
0
     AddHandler(
     string stOption,                    // Unique flag for Option
     string stShortcut,                  // Optional shortcut (can be null);
     Blue.Public.OptionHandler ha,       // Option Handler
     string stDescription,               // short 1-line description
     string stFullHelp                   // long description
     )        
 {
     Debug.Assert(!m_fIsLocked, "Can't add new optionhandler after we've locked:"+ stDescription);
     
     
     OptionInfo info = new OptionInfo(stOption, stShortcut, ha, stDescription, stFullHelp);
             
     
     if (m_tblOptions[stOption] == null)
     {               
         if (stShortcut != null)
         {
             Debug.Assert(m_tblOptions[stShortcut] == null);
             m_tblOptions[stShortcut] = info;
         }
         m_tblOptions[stOption] = info;            
         
     } 
     else 
     {
         // Since end users can't define option handlers, we should know about
         // any collisions during the debug phase.
         Debug.Assert(false, "Handler already defined");
     }
 }
Пример #45
0
 public MutuallyExclusiveInfo(OptionInfo option)
 {
     this.BadOption = option;
 }
Пример #46
0
 // Print detailed help on the specific option
 private void PrintDetailedHelp(OptionInfo info)
 {
     Console.WriteLine("command /{0}:", info.Option);
     if (info.Shortcut != null)
         Console.WriteLine("shortcut:/{0}", info.Shortcut);
     Console.WriteLine("short help:{0}", info.ShortHelp);
     Console.WriteLine(info.FullHelp);
     Console.WriteLine();
 }