Esempio n. 1
0
		private void ConvertHours()
		{
			int posTo = ToString.IndexOf(':');
			int posFrom = FromString.IndexOf(':');
			int toHour = 0, toMinute = 0, fromHour = 0, fromMinute = 0;

			if (posTo == -1)
			{
				int.TryParse(ToString, out toHour);
			}
			else
			{
				int.TryParse(ToString.Substring(0, posTo), out toHour);
				int.TryParse(ToString.Substring(posTo + 1), out toMinute);
			}

			if (posFrom == -1)
			{
				int.TryParse(FromString, out fromHour);
			}
			else
			{
				int.TryParse(FromString.Substring(0, posFrom), out fromHour);
				int.TryParse(FromString.Substring(posFrom + 1), out fromMinute);
			}

			To = new DateTime(1900, 1, 1, toHour, toMinute, 0);
			From = new DateTime(1900, 1, 1, fromHour, fromMinute, 0);
		}        
Esempio n. 2
0
 /// <summary>
 /// Bind collection to columns
 /// </summary>
 /// <param name="list">Collection to be bound</param>
 /// <param name="toString">Delegate that converts item to string</param>
 public void DataBind <T>(List <T> list, ToString <T> toString)
 {
     _items = new List <string>();
     foreach (T e in list)
     {
         _items.Add(toString(e));
     }
 }
Esempio n. 3
0
    public static string DicToString <T1, T2>(this Dictionary <T1, T2> values, ToString <T1> func1 = null, ToString <T2> func2 = null)
    {
        StringBuilder builder = new StringBuilder();

        foreach (var pair in values)
        {
            builder.AppendLine(string.Format("{0} : {1}", func1 == null ? pair.Key.ToString() : func1(pair.Key), func2 == null ? pair.Value.ToString() : func2(pair.Value)));
        }
        return(builder.ToString());
    }
Esempio n. 4
0
    public static string IEnumerableToString <T>(this IEnumerable <T> values, ToString <T> func = null)
    {
        StringBuilder builder = new StringBuilder();

        foreach (var value in values)
        {
            builder.AppendLine(func == null ? value.ToString() : func(value));
        }
        return(builder.ToString());
    }
        /// <summary>
        ///     Converts the given object to a string, formatting appropirate null/undefined/empty-string 
        ///     versions if the variable is in any of those states.
        /// </summary>
        /// <param name="value">The value to convert.</param>
        /// <param name="toString">Function that performs the conversion to a string.</param>
        public string FormatToString(object value, ToString toString)
        {
            // Format null text.
            if (Script.IsUndefined(value)) return "<undefined>".HtmlEncode();
            if (value == null || Script.IsNull(value)) return "<null>".HtmlEncode();

            // Convert the value to a string.
            string text = toString == null ? value.ToString() : toString(value);
            if (text == string.Empty) text = "<empty-string>".HtmlEncode();
            if (string.IsNullOrEmpty(text.Trim())) text = "<whitespace>".HtmlEncode();

            // Finish up.
            return text;
        }
Esempio n. 6
0
    private string Handle <TransitType, ArgType>(
        string tagname, string tagvalue, ArgType arg,
        WebClientImpl <TransitType> .GetItemDelegate <int, ArgType> functor,
        ToString <TransitType> transformer)
    {
        int id = 0;

        if (int.TryParse(tagvalue, out id))
        {
            TransitType t_instance = GetInstance <TransitType, int, ArgType>(id, arg, functor);
            if (t_instance != null)
            {
                return(transformer(t_instance));
            }
        }

        return(string.Format("[invalid {0}: {1}]", tagname, tagvalue));
    }
        /// <summary>
        ///     A function very similar to string.Join(), but the items are
        ///     a delegate and a prefix and suffix are supported.
        /// </summary>
        public static string ToString <T>(
            this IEnumerable items,
            string prefix,
            string suffix,
            string seperator,
            ToString <T> formatter)
        {
            var str = new StringBuilder();

            if (!string.IsNullOrEmpty(prefix))
            {
                str.Append(prefix);
            }

            if (items != null)
            {
                var isTheFirstItem = true;
                foreach (var item in items)
                {
                    if (isTheFirstItem)
                    {
                        isTheFirstItem = false;
                    }
                    else
                    {
                        str.Append(seperator);
                    }

                    str.Append(formatter((T)item));
                }
            }

            if (!string.IsNullOrEmpty(suffix))
            {
                str.Append(suffix);
            }

            return(str.ToString());
        }
Esempio n. 8
0
        public Expression GetNode(ExpressionParser parser)
        {
            Lexem      lex   = parser.Collection.CurrentLexem();
            Expression ex    = null;
            bool       uniar = parser.waitValue;

            if (lex.LexemType == LexType.Arfimetic)
            {
                switch (lex.LexemText)
                {
                case "+":
                    if (uniar)
                    {
                        ex = new UniarPlus_BoolExpr();
                    }
                    else
                    {
                        ex = new Plus_Arifmetic();
                    }
                    break;

                case "-":
                    if (uniar)
                    {
                        ex = new UniarMinus_BoolExpr();
                    }
                    else
                    {
                        ex = new Minus_Arifmetic();
                    }
                    break;

                case "*":
                    if (uniar)
                    {
                        ex = new AllColumnExpr();
                    }
                    else
                    {
                        ex = new Multi_Arifmetic();
                    }
                    break;

                case "/":
                    ex = new Div_Arifmetic();
                    break;

                case "<":
                    ex = new Less_CompExpr();
                    break;

                case "<=":
                    ex = new LessOrEqual_CompExpr();
                    break;

                case ">=":
                    ex = new GreatOrEqual_CompExpr();
                    break;

                case ">":
                    ex = new Great_CompExpr();
                    break;

                case "=":
                    ex = new Equal_CompExpr();
                    break;

                case "<>":
                case "!=":
                    ex = new NotEqual_CompExpr();
                    break;
                }
            }
            if (lex.LexemType == LexType.Number)
            {
                ex = new ConstExpr();
                if (lex.LexemText.Contains('.'))
                {
                    (ex as ConstExpr).Init(lex.LexemText.ParseDouble(), SimpleTypes.Float);
                }
                else
                {
                    (ex as ConstExpr).Init(long.Parse(lex.LexemText), SimpleTypes.Integer);
                }
            }
            if (lex.LexemType == LexType.Text)
            {
                if (lex.LexemText.StartsWith("'"))
                {
                    ex = new ConstExpr();
                    (ex as ConstExpr).Init(ParserUtils.StandartDecodeEscape(lex.LexemText), SimpleTypes.String);
                }
            }
            Lexem n1;

            if (lex.LexemType == LexType.Command)
            {
                switch (lex.LexemText.ToLower())
                {
                case "not":
                    n1 = parser.Collection.GetNext();
                    if (n1 != null && n1.LexemType == LexType.Command && n1.LexemText.ToLower() == "in")
                    {
                        ex = new NotInExpr();
                        parser.Collection.GotoNext();
                        break;
                    }
                    ex = new Not_BoolExpr();
                    break;

                case "case":
                    ex = new CaseExpr();
                    break;

                case "contains":
                    ex = new Contains();
                    break;

                case "containsic":     //ic = ignore case
                case "containscase":
                    ex = new ContainsIgnoreCase();
                    break;

                case "startwith":
                case "startswith":
                    ex = new StartsWith();
                    break;

                case "endwith":
                case "endswith":
                    ex = new EndsWith();
                    break;
                }
                if (parser.Collection.GetNext() != null && parser.Collection.GetNext().IsSkobraOpen())
                {
                    switch (lex.LexemText.ToLower())
                    {
                    case "cast":
                        ex = new Cast();
                        break;

                    case "in":
                        ex = new InExpr();
                        break;

                    case "abs":
                        ex = new Abs();
                        break;

                    case "substring":
                        ex = new SubString();
                        break;

                    case "position":
                        ex = new Position();
                        break;

                    case "ltrim":
                        ex = new LTrim();
                        break;

                    case "rtrim":
                        ex = new RTrim();
                        break;

                    case "trim":
                        ex = new Trim();
                        break;

                    case "length":
                        ex = new Length();
                        break;

                    case "upper":
                        ex = new Upper_operation();
                        break;

                    case "lower":
                        ex = new Lower_operation();
                        break;

                    case "left":
                        ex = new Left();
                        break;

                    case "right":
                        ex = new Right();
                        break;

                    case "replace":
                        ex = new Replace();
                        break;

                    case "now":
                        ex = new Now();
                        break;

                    case "tostr":
                        ex = new ToString();
                        break;

                    case "strtotime":
                        ex = new StrToTime();
                        break;

                    case "strtodatetime":
                        ex = new StrToDateTime();
                        break;

                    case "addseconds":
                        ex = new AddSeconds();
                        break;

                    case "addminutes":
                        ex = new AddMinutes();
                        break;

                    case "addhours":
                        ex = new AddHours();
                        break;

                    case "adddays":
                        ex = new AddDays();
                        break;

                    case "day":
                        ex = new Day();
                        break;

                    case "month":
                        ex = new Month();
                        break;

                    case "year":
                        ex = new Year();
                        break;

                    case "round":
                        ex = new ParserCore.Expr.Extend.Math.Round();
                        break;

                    case "ceiling":
                        ex = new ParserCore.Expr.Extend.Math.Ceiling();
                        break;

                    case "floor":
                        ex = new ParserCore.Expr.Extend.Math.Floor();
                        break;

                    case "pi":
                        ex = new ParserCore.Expr.Extend.Math.Pi();
                        break;

                    case "tan":
                        ex = new ParserCore.Expr.Extend.Math.Tan();
                        break;

                    case "log":
                        ex = new ParserCore.Expr.Extend.Math.Log();
                        break;
                    }
                }
            }
            return(ex);
        }
Esempio n. 9
0
        static void Main(string[] args)
        {
            var openSettins = new TDFOpenSetting()
            {
                Ip             = System.Configuration.ConfigurationManager.AppSettings["IP"],                         //服务器Ip
                Port           = System.Configuration.ConfigurationManager.AppSettings["Port"],                       //服务器端口
                Username       = System.Configuration.ConfigurationManager.AppSettings["Username"],                   //服务器用户名
                Password       = System.Configuration.ConfigurationManager.AppSettings["Password"],                   //服务器密码
                Subscriptions  = System.Configuration.ConfigurationManager.AppSettings["SubScriptions"],              //订阅列表,以 ; 分割的代码列表,例如:if1406.cf;if1403.cf;如果置为空,则全市场订阅
                Markets        = System.Configuration.ConfigurationManager.AppSettings["Markets"],                    //市场列表,以 ; 分割,例如: sh;sz;cf;shf;czc;dce
                ReconnectCount = uint.Parse(System.Configuration.ConfigurationManager.AppSettings["ReconnectCount"]), //当连接断开时重连次数,断开重连在TDFDataSource.Connect成功之后才有效
                ReconnectGap   = uint.Parse(System.Configuration.ConfigurationManager.AppSettings["ReconnectGap"]),   //重连间隔秒数
                ConnectionID   = uint.Parse(System.Configuration.ConfigurationManager.AppSettings["ConnectionID"]),   //连接ID,标识某个Open调用,跟回调消息中TDFMSG结构nConnectionID字段相同
                Date           = uint.Parse(System.Configuration.ConfigurationManager.AppSettings["Date"]),           //请求的日期,格式YYMMDD,为0则请求今天
                Time           = (uint)int.Parse(System.Configuration.ConfigurationManager.AppSettings["Time"]),      //请求的时间,格式HHMMSS,为0则请求实时行情,为(uint)-1从头请求
                TypeFlags      = (uint)int.Parse(System.Configuration.ConfigurationManager.AppSettings["TypeFlags"])  //unchecked((uint)DataTypeFlag.DATA_TYPE_ALL);   //为0请求所有品种,或者取值为DataTypeFlag中多种类别,比如DATA_TYPE_MARKET | DATA_TYPE_TRANSACTION
            };

            // 使用者请注意:
            //  1. 请保持TDFSourceImp的实例到进程销毁。TDFSourceImp是数据接收者
            //  2. 本Demo只是做最简单演示,在进程(main函数)结束的时候销毁TDFSourceImp实例
            using (var dataSource = new TDFSourceImp(openSettins))
            {
                #region 调用Open,登陆服务器。初始化过程到此结束,对数据的操作,请到TDFSourceImp的两个虚函数里进行
                TDFERRNO nOpenRet = dataSource.Open();
                if (nOpenRet == TDFERRNO.TDF_ERR_SUCCESS)
                {
                    Console.WriteLine("connect success!\n");
                }
                else
                {
                    //这里判断错误代码,进行对应的操作,对于 TDF_ERR_NETWORK_ERROR,用户可以选择重连
                    Console.WriteLine("open returned:{0}, program quit", nOpenRet);
                    Console.ReadLine();
                    return;
                }
                #endregion
                #region 以下代码是演示订阅功能
                //主线程阻塞在这里,等待回调消息通知(其他消息)
                String strHelp = @"键入q退出
    以下命令,请用逗号分隔
    a 添加订阅
    d 删除订阅
    f 清除订阅
    s 设置订阅
    hs 显示完全数据
    hh 显示股票名称";
                Console.WriteLine(strHelp);
                var input = Console.ReadLine();

                while (input != "q")
                {
                    var inArgs = input.Split(',');
                    if (inArgs.Length > 1)
                    {
                        ToString convert = (String[] ary) =>
                        {
                            System.Text.StringBuilder sb = new StringBuilder();
                            for (int i = 1; i < ary.Length; ++i)
                            {
                                sb.AppendFormat("{0};", ary[i]);
                            }

                            return(sb.ToString());
                        };

                        switch (inArgs[0])
                        {
                        case "a":
                            dataSource.SetSubscription(convert(inArgs), SubscriptionType.SUBSCRIPTION_ADD);
                            break;

                        case "d":
                            dataSource.SetSubscription(convert(inArgs), SubscriptionType.SUBSCRIPTION_DEL);
                            break;

                        case "s":
                            dataSource.SetSubscription(convert(inArgs), SubscriptionType.SUBSCRIPTION_SET);
                            break;

                        case "f":
                            dataSource.SetSubscription("", SubscriptionType.SUBSCRIPTION_FULL);
                            break;

                        case "hs":
                            dataSource.ShowAllData = true;
                            break;

                        case "hh":
                            dataSource.ShowAllData = false;
                            break;
                        }
                    }
                    else if (inArgs.Length == 1)
                    {
                        switch (inArgs[0])
                        {
                        case "f":
                            dataSource.SetSubscription("", SubscriptionType.SUBSCRIPTION_FULL);
                            break;

                        case "hs":
                            dataSource.ShowAllData = true;
                            break;

                        case "hh":
                            dataSource.ShowAllData = false;
                            break;
                        }
                    }

                    Console.WriteLine(strHelp);
                    input = Console.ReadLine();
                }
                #endregion      //演示订阅功能
            }
        }
Esempio n. 10
0
 public override void Visit(ToString node)
 {
     Visit((ConversionExpression)node);
 }
Esempio n. 11
0
 public override void Visit(ToString node)
 {
     throw new InterpretException("TODO");
 }
Esempio n. 12
0
 public override void Visit(ToString node)
 {
     unfinishedClone = new ToString(GetCloneOf(node.Expression));
     base.Visit(node);
 }
Esempio n. 13
0
        /// <summary>
        /// Extended <see cref="String.Join{T}(string,IEnumerable{T})"/>
        /// </summary>
        /// <param name="seq">Sequence of elements</param>
        /// <param name="delim">Delimiter</param>
        /// <param name="toString">Function to convert each element into a <see cref="string"/></param>
        /// <typeparam name="T">Type of element</typeparam>
        public static string SpecificJoin <T>(this IEnumerable <T> seq, string delim, ToString <T> toString)
        {
            var sb = new StringBuilder();

            foreach (var v in seq)
            {
                sb.Append(toString(v))
                .Append(delim);
            }

            return(sb.RemoveTrailingDelimeter(delim).ToString());
        }
 /// <summary>
 /// To an absolute URI that can be used with Azure RM endpoints
 /// </summary>
 /// <param name="endpointName">Name of the AzureRM endpoint name (appended to the endpoint)</param>
 /// <returns>An absolute URL of the form 'https://management.azure.com/(resourceUri)/(endpointName)'</returns>
 public string ToAbsoluteAzureRMEndpointUri(string?endpointName = null)
 => $"https://management.azure.com{ToString()}{(string.IsNullOrWhiteSpace(endpointName) ? "" : "/" + endpointName)}";
 /// <summary>
 ///     Similar to string.Join(',') but with a little more.
 /// </summary>
 /// <example>
 /// psuedo code list of objects:
 ///
 ///     [ {name:1}, {name:2}, {name:3} ] => 1, 2, 3
 ///
 /// <code>
 ///    models.ToCsvString&lt;T&gt;(m => m.name)
 /// </code>
 /// </example>
 /// <seealso cref="ToCsvString{T}(System.Collections.Generic.IEnumerable{T},Toolkit.ToString{T})"/>
 public static string ToCsvString <T>(
     this IEnumerable items,
     ToString <T> formatter)
 {
     return(items.ToString(string.Empty, string.Empty, ", ", formatter));
 }
Esempio n. 16
0
    /// <summary>
    ///
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="pText"></param>
    /// <param name="iNumberStart"></param>
    /// <param name="iNumberDest"></param>
    /// <param name="fSeekPos_0_1"></param>
    /// <param name="strFormat"></param>
    /// <param name="GetLerp"></param>
    /// <param name="ToString"></param>
    private static void SeekTweenText <T>(Text pText, T iNumberStart, T iNumberDest, float fSeekPos_0_1, string strFormat, GetLerp <T> GetLerp, ToString <T> ToString)
    {
        int iVAlue = 1000;

        iVAlue.ToString();     // =1000
        iVAlue.ToString("n0"); //=1,000

        pText.text = ToString(GetLerp(iNumberStart, iNumberDest, fSeekPos_0_1), strFormat);
    }
Esempio n. 17
0
 public override void Visit(ToString node)
 {
     UpdateType(node, TypeCalculator.GetType(node));
 }
Esempio n. 18
0
 /// <summary>
 /// Adds a method for creating a string representation from objects of the specified type handle.
 /// </summary>
 /// <param name="typeHandle">Handle of the type which you want to suply the string creation method for.</param>
 /// <param name="toString">The method which can create string representations of the type.</param>
 /// <remarks>Take a look at RuntimeTypeHandle documentation on MSDN for more information.</remarks>
 public static void AddToString(RuntimeTypeHandle typeHandle, ToString toString)
 {
     _toStrings[typeHandle] = toString;
 }
Esempio n. 19
0
    public static Coroutine DoPlayTween_Number(this Text pText, MonoBehaviour pCoroutineExecuter, int iNumberStart, int iNumberDest, float fDuration, ToString <int> OnTextResult)
    {
        if (pCoroutineExecuter.gameObject.activeInHierarchy == false)
        {
            Debug.LogWarning($"{pCoroutineExecuter.name} - {nameof(DoPlayTween)} activeInHierarchy == false", pCoroutineExecuter);
            return(null);
        }

        return(pCoroutineExecuter.StartCoroutine(TweenText(pText, iNumberStart, iNumberDest, fDuration, null, GetLerp_Int, OnTextResult)));
    }
Esempio n. 20
0
 internal static void Create(object nombreStore, ToObject toObject, ToString toString)
 {
     throw new NotImplementedException();
 }
Esempio n. 21
0
 public override void Visit(ToString node)
 {
     AssignToImplicitReturn(node);
 }
Esempio n. 22
0
        public void Parse()
        {
            var current = _reader.BaseStream.Position;

            _reader.BaseStream.Seek(_offset, SeekOrigin.Begin);
            bool parsing     = true;
            bool branched    = false;
            int  branchBytes = 0;

            while (parsing)
            {
                //now reader the instructions
                var type    = _reader.ReadByteAsEnum <InstructionType>();
                var aligned = InstructionAlignment.IsAligned(type);

                if (aligned)
                {
                    var padding = _reader.Align(4);
                    if (padding > 0)
                    {
                        Items.Add(new Padding(padding));
                        if (branched)
                        {
                            branchBytes -= (int)padding;

                            if (branchBytes <= 0)
                            {
                                branched    = false;
                                branchBytes = 0;
                            }
                        }
                    }
                }

                InstructionBase instruction = null;
                List <Value>    parameters  = new List <Value>();

                switch (type)
                {
                case InstructionType.ToNumber:
                    instruction = new ToNumber();
                    break;

                case InstructionType.NextFrame:
                    instruction = new NextFrame();
                    break;

                case InstructionType.Play:
                    instruction = new Play();
                    break;

                case InstructionType.Stop:
                    instruction = new Stop();
                    break;

                case InstructionType.Add:
                    instruction = new Add();
                    break;

                case InstructionType.Subtract:
                    instruction = new Subtract();
                    break;

                case InstructionType.Multiply:
                    instruction = new Multiply();
                    break;

                case InstructionType.Divide:
                    instruction = new Divide();
                    break;

                case InstructionType.Not:
                    instruction = new Not();
                    break;

                case InstructionType.StringEquals:
                    instruction = new StringEquals();
                    break;

                case InstructionType.Pop:
                    instruction = new Pop();
                    break;

                case InstructionType.ToInteger:
                    instruction = new ToInteger();
                    break;

                case InstructionType.GetVariable:
                    instruction = new GetVariable();
                    break;

                case InstructionType.SetVariable:
                    instruction = new SetVariable();
                    break;

                case InstructionType.StringConcat:
                    instruction = new StringConcat();
                    break;

                case InstructionType.GetProperty:
                    instruction = new GetProperty();
                    break;

                case InstructionType.SetProperty:
                    instruction = new SetProperty();
                    break;

                case InstructionType.Trace:
                    instruction = new Trace();
                    break;

                case InstructionType.Delete:
                    instruction = new Delete();
                    break;

                case InstructionType.Delete2:
                    instruction = new Delete2();
                    break;

                case InstructionType.DefineLocal:
                    instruction = new DefineLocal();
                    break;

                case InstructionType.CallFunction:
                    instruction = new CallFunction();
                    break;

                case InstructionType.Return:
                    instruction = new Return();
                    break;

                case InstructionType.NewObject:
                    instruction = new NewObject();
                    break;

                case InstructionType.InitArray:
                    instruction = new InitArray();
                    break;

                case InstructionType.InitObject:
                    instruction = new InitObject();
                    break;

                case InstructionType.TypeOf:
                    instruction = new InitObject();
                    break;

                case InstructionType.Add2:
                    instruction = new Add2();
                    break;

                case InstructionType.LessThan2:
                    instruction = new LessThan2();
                    break;

                case InstructionType.Equals2:
                    instruction = new Equals2();
                    break;

                case InstructionType.ToString:
                    instruction = new ToString();
                    break;

                case InstructionType.PushDuplicate:
                    instruction = new PushDuplicate();
                    break;

                case InstructionType.GetMember:
                    instruction = new GetMember();
                    break;

                case InstructionType.SetMember:
                    instruction = new SetMember();
                    break;

                case InstructionType.Increment:
                    instruction = new Increment();
                    break;

                case InstructionType.Decrement:
                    instruction = new Decrement();
                    break;

                case InstructionType.CallMethod:
                    instruction = new CallMethod();
                    break;

                case InstructionType.Enumerate2:
                    instruction = new Enumerate2();
                    break;

                case InstructionType.EA_PushThis:
                    instruction = new PushThis();
                    break;

                case InstructionType.EA_PushZero:
                    instruction = new PushZero();
                    break;

                case InstructionType.EA_PushOne:
                    instruction = new PushOne();
                    break;

                case InstructionType.EA_CallFunc:
                    instruction = new CallFunc();
                    break;

                case InstructionType.EA_CallMethodPop:
                    instruction = new CallMethodPop();
                    break;

                case InstructionType.BitwiseXOr:
                    instruction = new BitwiseXOr();
                    break;

                case InstructionType.Greater:
                    instruction = new Greater();
                    break;

                case InstructionType.EA_PushThisVar:
                    instruction = new PushThisVar();
                    break;

                case InstructionType.EA_PushGlobalVar:
                    instruction = new PushGlobalVar();
                    break;

                case InstructionType.EA_ZeroVar:
                    instruction = new ZeroVar();
                    break;

                case InstructionType.EA_PushTrue:
                    instruction = new PushTrue();
                    break;

                case InstructionType.EA_PushFalse:
                    instruction = new PushFalse();
                    break;

                case InstructionType.EA_PushNull:
                    instruction = new PushNull();
                    break;

                case InstructionType.EA_PushUndefined:
                    instruction = new PushUndefined();
                    break;

                case InstructionType.GotoFrame:
                    instruction = new GotoFrame();
                    parameters.Add(Value.FromInteger(_reader.ReadInt32()));
                    break;

                case InstructionType.GetURL:
                    instruction = new GetUrl();
                    parameters.Add(Value.FromString(_reader.ReadStringAtOffset()));
                    parameters.Add(Value.FromString(_reader.ReadStringAtOffset()));
                    break;

                case InstructionType.SetRegister:
                    instruction = new SetRegister();
                    parameters.Add(Value.FromInteger(_reader.ReadInt32()));
                    break;

                case InstructionType.ConstantPool:
                {
                    instruction = new ConstantPool();
                    var count     = _reader.ReadUInt32();
                    var constants = _reader.ReadFixedSizeArrayAtOffset <uint>(() => _reader.ReadUInt32(), count);

                    foreach (var constant in constants)
                    {
                        parameters.Add(Value.FromConstant(constant));
                    }
                }
                break;

                case InstructionType.GotoLabel:
                    instruction = new GotoLabel();
                    parameters.Add(Value.FromString(_reader.ReadStringAtOffset()));
                    break;

                case InstructionType.DefineFunction2:
                {
                    instruction = new DefineFunction2();
                    var name       = _reader.ReadStringAtOffset();
                    var nParams    = _reader.ReadUInt32();
                    var nRegisters = _reader.ReadByte();
                    var flags      = _reader.ReadUInt24();

                    //list of parameter strings
                    var paramList = _reader.ReadFixedSizeListAtOffset <FunctionArgument>(() => new FunctionArgument()
                        {
                            Register  = _reader.ReadInt32(),
                            Parameter = _reader.ReadStringAtOffset(),
                        }, nParams);

                    parameters.Add(Value.FromString(name));
                    parameters.Add(Value.FromInteger((int)nParams));
                    parameters.Add(Value.FromInteger((int)nRegisters));
                    parameters.Add(Value.FromInteger((int)flags));
                    foreach (var param in paramList)
                    {
                        parameters.Add(Value.FromInteger(param.Register));
                        parameters.Add(Value.FromString(param.Parameter));
                    }
                    //body size of the function
                    parameters.Add(Value.FromInteger(_reader.ReadInt32()));
                    //skip 8 bytes
                    _reader.ReadUInt64();
                }
                break;

                case InstructionType.PushData:
                {
                    instruction = new PushData();

                    var count     = _reader.ReadUInt32();
                    var constants = _reader.ReadFixedSizeArrayAtOffset <uint>(() => _reader.ReadUInt32(), count);

                    foreach (var constant in constants)
                    {
                        parameters.Add(Value.FromConstant(constant));
                    }
                }
                break;

                case InstructionType.BranchAlways:
                    instruction = new BranchAlways();
                    if (!branched)
                    {
                        branchBytes = _reader.ReadInt32();
                        parameters.Add(Value.FromInteger(branchBytes));

                        if (branchBytes > 0)
                        {
                            branchBytes += (int)instruction.Size + 1;
                            branched     = true;
                        }
                    }
                    else
                    {
                        parameters.Add(Value.FromInteger(_reader.ReadInt32()));
                    }
                    break;

                case InstructionType.GetURL2:
                    instruction = new GetUrl2();
                    break;

                case InstructionType.DefineFunction:
                {
                    instruction = new DefineFunction();
                    var name = _reader.ReadStringAtOffset();
                    //list of parameter strings
                    var paramList = _reader.ReadListAtOffset <string>(() => _reader.ReadStringAtOffset());

                    parameters.Add(Value.FromString(name));
                    parameters.Add(Value.FromInteger(paramList.Count));
                    foreach (var param in paramList)
                    {
                        parameters.Add(Value.FromString(param));
                    }
                    //body size of the function
                    parameters.Add(Value.FromInteger(_reader.ReadInt32()));
                    //skip 8 bytes
                    _reader.ReadUInt64();
                }
                break;

                case InstructionType.BranchIfTrue:
                    instruction = new BranchIfTrue();
                    if (!branched)
                    {
                        branchBytes = _reader.ReadInt32();
                        parameters.Add(Value.FromInteger(branchBytes));

                        if (branchBytes > 0)
                        {
                            branchBytes += (int)instruction.Size + 1;
                            branched     = true;
                        }
                    }
                    else
                    {
                        parameters.Add(Value.FromInteger(_reader.ReadInt32()));
                    }
                    break;

                case InstructionType.GotoFrame2:
                    instruction = new GotoFrame2();
                    parameters.Add(Value.FromInteger(_reader.ReadByte()));
                    break;

                case InstructionType.EA_PushString:
                    instruction = new PushString();
                    //the constant id that should be pushed
                    parameters.Add(Value.FromString(_reader.ReadStringAtOffset()));
                    break;

                case InstructionType.EA_PushConstantByte:
                    instruction = new PushConstantByte();
                    //the constant id that should be pushed
                    parameters.Add(Value.FromConstant(_reader.ReadByte()));
                    break;

                case InstructionType.EA_GetStringVar:
                    instruction = new GetStringVar();
                    parameters.Add(Value.FromString(_reader.ReadStringAtOffset()));
                    break;

                case InstructionType.EA_SetStringVar:
                    instruction = new SetStringMember();
                    parameters.Add(Value.FromString(_reader.ReadStringAtOffset()));
                    break;

                case InstructionType.EA_GetStringMember:
                    instruction = new GetStringMember();
                    parameters.Add(Value.FromString(_reader.ReadStringAtOffset()));
                    break;

                case InstructionType.EA_SetStringMember:
                    instruction = new SetStringMember();
                    parameters.Add(Value.FromString(_reader.ReadStringAtOffset()));
                    break;

                case InstructionType.EA_PushValueOfVar:
                    instruction = new PushValueOfVar();
                    //the constant id that should be pushed
                    parameters.Add(Value.FromConstant(_reader.ReadByte()));
                    break;

                case InstructionType.EA_GetNamedMember:
                    instruction = new GetNamedMember();
                    parameters.Add(Value.FromConstant(_reader.ReadByte()));
                    break;

                case InstructionType.EA_CallNamedFuncPop:
                    instruction = new CallNamedFuncPop();
                    parameters.Add(Value.FromConstant(_reader.ReadByte()));
                    break;

                case InstructionType.EA_CallNamedFunc:
                    instruction = new CallNamedFunc();
                    parameters.Add(Value.FromConstant(_reader.ReadByte()));
                    break;

                case InstructionType.EA_CallNamedMethodPop:
                    instruction = new CallNamedMethodPop();
                    parameters.Add(Value.FromConstant(_reader.ReadByte()));
                    break;

                case InstructionType.EA_PushFloat:
                    instruction = new PushFloat();
                    parameters.Add(Value.FromFloat(_reader.ReadSingle()));
                    break;

                case InstructionType.EA_PushByte:
                    instruction = new PushByte();
                    parameters.Add(Value.FromInteger(_reader.ReadByte()));
                    break;

                case InstructionType.EA_PushShort:
                    instruction = new PushShort();
                    parameters.Add(Value.FromInteger(_reader.ReadUInt16()));
                    break;

                case InstructionType.End:
                    instruction = new End();

                    if (!branched)
                    {
                        parsing = false;
                    }
                    break;

                case InstructionType.EA_CallNamedMethod:
                    instruction = new CallNamedMethod();
                    parameters.Add(Value.FromConstant(_reader.ReadByte()));
                    break;

                case InstructionType.Var:
                    instruction = new Var();

                    break;

                default:
                    throw new InvalidDataException("Unimplemented bytecode instruction:" + type.ToString());
                }

                if (instruction != null)
                {
                    instruction.Parameters = parameters;
                    Items.Add(instruction);
                }

                if (branched)
                {
                    branchBytes -= (int)instruction.Size + 1;

                    if (branchBytes <= 0)
                    {
                        branched = false;
                    }
                }
            }
            _reader.BaseStream.Seek(current, SeekOrigin.Begin);
        }
Esempio n. 23
0
    /// <summary>
    /// 텍스트 애니메이션
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="pText">애니메이션 타겟</param>
    /// <param name="iNumberStart">시작 숫자</param>
    /// <param name="iNumberDest">끝 숫자</param>
    /// <param name="fDuration">애니메이션 총 걸리는 시간</param>
    /// <param name="strFormat">텍스트를 출력할 포멧</param>
    /// <param name="GetLerp">보간 로직</param>
    /// <param name="ToString">텍스트 출력 함수</param>
    private static IEnumerator TweenText <T>(Text pText, T iNumberStart, T iNumberDest, float fDuration, string strFormat, GetLerp <T> GetLerp, ToString <T> ToString)
    {
        float fProgress_0_1 = 0f;

        while (fProgress_0_1 < 1f)
        {
            SeekTweenText(pText, iNumberStart, iNumberDest, fProgress_0_1, strFormat, GetLerp, ToString);
            fProgress_0_1 += Time.deltaTime / fDuration;

            yield return(null);
        }

        pText.text = ToString(iNumberDest, strFormat);
    }
Esempio n. 24
0
        public static InstructionCollection Parse(Stream input, long instructionsPosition)
        {
            var instructions = new SortedList <int, InstructionBase>();

            using (var helper = new InstructionParseHelper(input, instructionsPosition))
            {
                var reader = helper.GetReader();
                while (helper.CanParse(instructions))
                {
                    //now reader the instructions
                    var instructionPosition = helper.CurrentPosition;
                    var type             = reader.ReadByteAsEnum <InstructionType>();
                    var requireAlignment = InstructionAlignment.IsAligned(type);

                    if (requireAlignment)
                    {
                        reader.Align(4);
                    }

                    InstructionBase instruction = null;
                    var             parameters  = new List <Value>();

                    switch (type)
                    {
                    case InstructionType.ToNumber:
                        instruction = new ToNumber();
                        break;

                    case InstructionType.NextFrame:
                        instruction = new NextFrame();
                        break;

                    case InstructionType.Play:
                        instruction = new Play();
                        break;

                    case InstructionType.Stop:
                        instruction = new Stop();
                        break;

                    case InstructionType.Add:
                        instruction = new Add();
                        break;

                    case InstructionType.Subtract:
                        instruction = new Subtract();
                        break;

                    case InstructionType.Multiply:
                        instruction = new Multiply();
                        break;

                    case InstructionType.Divide:
                        instruction = new Divide();
                        break;

                    case InstructionType.Not:
                        instruction = new Not();
                        break;

                    case InstructionType.StringEquals:
                        instruction = new StringEquals();
                        break;

                    case InstructionType.Pop:
                        instruction = new Pop();
                        break;

                    case InstructionType.ToInteger:
                        instruction = new ToInteger();
                        break;

                    case InstructionType.GetVariable:
                        instruction = new GetVariable();
                        break;

                    case InstructionType.SetVariable:
                        instruction = new SetVariable();
                        break;

                    case InstructionType.StringConcat:
                        instruction = new StringConcat();
                        break;

                    case InstructionType.GetProperty:
                        instruction = new GetProperty();
                        break;

                    case InstructionType.SetProperty:
                        instruction = new SetProperty();
                        break;

                    case InstructionType.Trace:
                        instruction = new Trace();
                        break;

                    case InstructionType.Random:
                        instruction = new RandomNumber();
                        break;

                    case InstructionType.Delete:
                        instruction = new Delete();
                        break;

                    case InstructionType.Delete2:
                        instruction = new Delete2();
                        break;

                    case InstructionType.DefineLocal:
                        instruction = new DefineLocal();
                        break;

                    case InstructionType.CallFunction:
                        instruction = new CallFunction();
                        break;

                    case InstructionType.Return:
                        instruction = new Return();
                        break;

                    case InstructionType.Modulo:
                        instruction = new Modulo();
                        break;

                    case InstructionType.NewObject:
                        instruction = new NewObject();
                        break;

                    case InstructionType.InitArray:
                        instruction = new InitArray();
                        break;

                    case InstructionType.InitObject:
                        instruction = new InitObject();
                        break;

                    case InstructionType.TypeOf:
                        instruction = new TypeOf();
                        break;

                    case InstructionType.Add2:
                        instruction = new Add2();
                        break;

                    case InstructionType.LessThan2:
                        instruction = new LessThan2();
                        break;

                    case InstructionType.Equals2:
                        instruction = new Equals2();
                        break;

                    case InstructionType.ToString:
                        instruction = new ToString();
                        break;

                    case InstructionType.PushDuplicate:
                        instruction = new PushDuplicate();
                        break;

                    case InstructionType.GetMember:
                        instruction = new GetMember();
                        break;

                    case InstructionType.SetMember:
                        instruction = new SetMember();
                        break;

                    case InstructionType.Increment:
                        instruction = new Increment();
                        break;

                    case InstructionType.Decrement:
                        instruction = new Decrement();
                        break;

                    case InstructionType.CallMethod:
                        instruction = new CallMethod();
                        break;

                    case InstructionType.Enumerate2:
                        instruction = new Enumerate2();
                        break;

                    case InstructionType.EA_PushThis:
                        instruction = new PushThis();
                        break;

                    case InstructionType.EA_PushZero:
                        instruction = new PushZero();
                        break;

                    case InstructionType.EA_PushOne:
                        instruction = new PushOne();
                        break;

                    case InstructionType.EA_CallFunc:
                        instruction = new CallFunc();
                        break;

                    case InstructionType.EA_CallMethodPop:
                        instruction = new CallMethodPop();
                        break;

                    case InstructionType.BitwiseXOr:
                        instruction = new BitwiseXOr();
                        break;

                    case InstructionType.Greater:
                        instruction = new Greater();
                        break;

                    case InstructionType.EA_PushThisVar:
                        instruction = new PushThisVar();
                        break;

                    case InstructionType.EA_PushGlobalVar:
                        instruction = new PushGlobalVar();
                        break;

                    case InstructionType.EA_ZeroVar:
                        instruction = new ZeroVar();
                        break;

                    case InstructionType.EA_PushTrue:
                        instruction = new PushTrue();
                        break;

                    case InstructionType.EA_PushFalse:
                        instruction = new PushFalse();
                        break;

                    case InstructionType.EA_PushNull:
                        instruction = new PushNull();
                        break;

                    case InstructionType.EA_PushUndefined:
                        instruction = new PushUndefined();
                        break;

                    case InstructionType.GotoFrame:
                        instruction = new GotoFrame();
                        parameters.Add(Value.FromInteger(reader.ReadInt32()));
                        break;

                    case InstructionType.GetURL:
                        instruction = new GetUrl();
                        parameters.Add(Value.FromString(reader.ReadStringAtOffset()));
                        parameters.Add(Value.FromString(reader.ReadStringAtOffset()));
                        break;

                    case InstructionType.SetRegister:
                        instruction = new SetRegister();
                        parameters.Add(Value.FromInteger(reader.ReadInt32()));
                        break;

                    case InstructionType.ConstantPool:
                    {
                        instruction = new ConstantPool();
                        var count     = reader.ReadUInt32();
                        var constants = reader.ReadFixedSizeArrayAtOffset <uint>(() => reader.ReadUInt32(), count);

                        foreach (var constant in constants)
                        {
                            parameters.Add(Value.FromConstant(constant));
                        }
                    }
                    break;

                    case InstructionType.GotoLabel:
                        instruction = new GotoLabel();
                        parameters.Add(Value.FromString(reader.ReadStringAtOffset()));
                        break;

                    case InstructionType.DefineFunction2:
                    {
                        instruction = new DefineFunction2();
                        var name       = reader.ReadStringAtOffset();
                        var nParams    = reader.ReadUInt32();
                        var nRegisters = reader.ReadByte();
                        var flags      = reader.ReadUInt24();

                        //list of parameter strings
                        var paramList = reader.ReadFixedSizeListAtOffset <FunctionArgument>(() => new FunctionArgument()
                            {
                                Register  = reader.ReadInt32(),
                                Parameter = reader.ReadStringAtOffset(),
                            }, nParams);

                        parameters.Add(Value.FromString(name));
                        parameters.Add(Value.FromInteger((int)nParams));
                        parameters.Add(Value.FromInteger((int)nRegisters));
                        parameters.Add(Value.FromInteger((int)flags));
                        foreach (var param in paramList)
                        {
                            parameters.Add(Value.FromInteger(param.Register));
                            parameters.Add(Value.FromString(param.Parameter));
                        }
                        //body size of the function
                        parameters.Add(Value.FromInteger(reader.ReadInt32()));
                        //skip 8 bytes
                        reader.ReadUInt64();
                    }
                    break;

                    case InstructionType.PushData:
                    {
                        instruction = new PushData();

                        var count     = reader.ReadUInt32();
                        var constants = reader.ReadFixedSizeArrayAtOffset <uint>(() => reader.ReadUInt32(), count);

                        foreach (var constant in constants)
                        {
                            parameters.Add(Value.FromConstant(constant));
                        }
                    }
                    break;

                    case InstructionType.BranchAlways:
                    {
                        instruction = new BranchAlways();
                        var offset = reader.ReadInt32();
                        parameters.Add(Value.FromInteger(offset));
                        helper.ReportBranchOffset(offset);
                    }
                    break;

                    case InstructionType.GetURL2:
                        instruction = new GetUrl2();
                        break;

                    case InstructionType.DefineFunction:
                    {
                        instruction = new DefineFunction();
                        var name = reader.ReadStringAtOffset();
                        //list of parameter strings
                        var paramList = reader.ReadListAtOffset <string>(() => reader.ReadStringAtOffset());

                        parameters.Add(Value.FromString(name));
                        parameters.Add(Value.FromInteger(paramList.Count));
                        foreach (var param in paramList)
                        {
                            parameters.Add(Value.FromString(param));
                        }
                        //body size of the function
                        parameters.Add(Value.FromInteger(reader.ReadInt32()));
                        //skip 8 bytes
                        reader.ReadUInt64();
                    }
                    break;

                    case InstructionType.BranchIfTrue:
                    {
                        instruction = new BranchIfTrue();
                        var offset = reader.ReadInt32();
                        parameters.Add(Value.FromInteger(offset));
                        helper.ReportBranchOffset(offset);
                    }
                    break;

                    case InstructionType.GotoFrame2:
                        instruction = new GotoFrame2();
                        parameters.Add(Value.FromInteger(reader.ReadInt32()));
                        break;

                    case InstructionType.EA_PushString:
                        instruction = new PushString();
                        //the constant id that should be pushed
                        parameters.Add(Value.FromString(reader.ReadStringAtOffset()));
                        break;

                    case InstructionType.EA_PushConstantByte:
                        instruction = new PushConstantByte();
                        //the constant id that should be pushed
                        parameters.Add(Value.FromConstant(reader.ReadByte()));
                        break;

                    case InstructionType.EA_GetStringVar:
                        instruction = new GetStringVar();
                        parameters.Add(Value.FromString(reader.ReadStringAtOffset()));
                        break;

                    case InstructionType.EA_SetStringVar:
                        instruction = new SetStringVar();
                        parameters.Add(Value.FromString(reader.ReadStringAtOffset()));
                        break;

                    case InstructionType.EA_GetStringMember:
                        instruction = new GetStringMember();
                        parameters.Add(Value.FromString(reader.ReadStringAtOffset()));
                        break;

                    case InstructionType.EA_SetStringMember:
                        instruction = new SetStringMember();
                        parameters.Add(Value.FromString(reader.ReadStringAtOffset()));
                        break;

                    case InstructionType.EA_PushValueOfVar:
                        instruction = new PushValueOfVar();
                        //the constant id that should be pushed
                        parameters.Add(Value.FromConstant(reader.ReadByte()));
                        break;

                    case InstructionType.EA_GetNamedMember:
                        instruction = new GetNamedMember();
                        parameters.Add(Value.FromConstant(reader.ReadByte()));
                        break;

                    case InstructionType.EA_CallNamedFuncPop:
                        instruction = new CallNamedFuncPop();
                        parameters.Add(Value.FromConstant(reader.ReadByte()));
                        break;

                    case InstructionType.EA_CallNamedFunc:
                        instruction = new CallNamedFunc();
                        parameters.Add(Value.FromConstant(reader.ReadByte()));
                        break;

                    case InstructionType.EA_CallNamedMethodPop:
                        instruction = new CallNamedMethodPop();
                        parameters.Add(Value.FromConstant(reader.ReadByte()));
                        break;

                    case InstructionType.EA_PushFloat:
                        instruction = new PushFloat();
                        parameters.Add(Value.FromFloat(reader.ReadSingle()));
                        break;

                    case InstructionType.EA_PushByte:
                        instruction = new PushByte();
                        parameters.Add(Value.FromInteger(reader.ReadByte()));
                        break;

                    case InstructionType.EA_PushShort:
                        instruction = new PushShort();
                        parameters.Add(Value.FromInteger(reader.ReadUInt16()));
                        break;

                    case InstructionType.End:
                        instruction = new End();
                        break;

                    case InstructionType.EA_CallNamedMethod:
                        instruction = new CallNamedMethod();
                        parameters.Add(Value.FromConstant(reader.ReadByte()));
                        break;

                    case InstructionType.Var:
                        instruction = new Var();
                        break;

                    case InstructionType.EA_PushRegister:
                        instruction = new PushRegister();
                        parameters.Add(Value.FromInteger(reader.ReadByte()));
                        break;

                    case InstructionType.EA_PushConstantWord:
                        instruction = new PushConstantWord();
                        parameters.Add(Value.FromConstant(reader.ReadUInt16()));
                        break;

                    case InstructionType.EA_CallFuncPop:
                        instruction = new CallFunctionPop();
                        break;

                    case InstructionType.StrictEqual:
                        instruction = new StrictEquals();
                        break;

                    default:
                        throw new InvalidDataException("Unimplemented bytecode instruction:" + type.ToString());
                    }

                    if (instruction != null)
                    {
                        instruction.Parameters = parameters;
                        instructions.Add(instructionPosition, instruction);
                    }
                }
            }

            return(new InstructionCollection(instructions));
        }
Esempio n. 25
0
 /// <summary>
 /// Extended <see cref="String.Join{T}(string,IEnumerable{T})"/>
 /// </summary>
 /// <param name="seq">Sequence of elements</param>
 /// <param name="toString">Function to convert each element into a <see cref="string"/></param>
 /// <typeparam name="T">Type of element</typeparam>
 public static string SpecificJoin <T>(this IEnumerable <T> seq, ToString <T> toString)
 => seq.SpecificJoin(StringConstants.JOIN_COMMA, toString);
Esempio n. 26
0
 /// <summary>
 /// Adds a method for creating a string representation from objects of the specified type.
 /// </summary>
 /// <typeparam name="T">The type that we want to make strings from objects of it.</typeparam>
 /// <param name="toString">The method which creates the string using the provided object.</param>
 public static void AddToString <T>(ToString toString)
 {
     AddToString(typeof(T).TypeHandle, toString);
 }
Esempio n. 27
0
 protected override void onGUI()
 {
     ToString myTarget = (ToString)target;
 }