Пример #1
0
        public void Parse()
        {
            if (Stream == null)
            {
                return;
            }

            /* Todo: fixed offsets = bad :) */
            /* Step 1: Determine if this is a market order file */
            if (Stream.Members.Length < 1)
            {
                throw new ParseException("Not a valid file");
            }

            SNode baseNode = Stream.Members[0];

            if (baseNode.Members.Length < 1)
            {
                throw new ParseException("Not a valid history file");
            }
            if (baseNode.Members[0].Members.Length < 2)
            {
                throw new ParseException("Not a valid history file");
            }

            SIdent id = baseNode.Members[0].Members[1] as SIdent;

            if (id == null)
            {
                throw new ParseException("Can't determine method name");
            }
            if (id.Value != "GetNewPriceHistory" && id.Value != "GetOldPriceHistory")
            {
                throw new ParseException("Not a valid history file");
            }

            /* Retrieve the region and type */
            SInt region = baseNode.Members[0].Members[2] as SInt;

            if (region != null)
            {
                Region = region.Value;
            }
            SInt type = baseNode.Members[0].Members[3] as SInt;

            if (type != null)
            {
                Type = type.Value;
            }

            if (id.Value == "GetNewPriceHistory")
            {
                ParseNewHistory(baseNode);
            }
        }
Пример #2
0
        public void Parse()
        {
            if (Stream == null)
            {
                return;
            }

            /* Todo: fixed offsets = bad :) */
            /* Step 1: Determine if this is a market order file */
            if (Stream[0].Members.Length < 1)
            {
                throw new ParseException("Not a valid file");
            }

            SNode baseNode = Stream[0].Members[0];

            if (baseNode.Members.Length < 1)
            {
                throw new ParseException("Not a valid orders file");
            }
            if (baseNode.Members[0].Members.Length < 2)
            {
                throw new ParseException("Not a valid orders file");
            }

            SIdent id = baseNode.Members[0].Members[1] as SIdent;

            if (id == null)
            {
                throw new ParseException("Can't determine method name");
            }
            if (id.Value != "GetOrders")
            {
                throw new ParseException("Not a valid orders file");
            }

            /* Retrieve the region and type */
            SInt region = baseNode.Members[0].Members[2] as SInt;
            SInt type   = baseNode.Members[0].Members[3] as SInt;

            List.Region = region.Value;
            List.Type   = type.Value;

            /* Try to extract the in-file timestamp */
            SDict dict = baseNode.Members[1] as SDict;

            if (dict == null)
            {
                throw new ParseException("Can't read file timestamp");
            }

            // Grab the version entry of the version tuple
            SLong time = dict.GetByName("version").Members[0] as SLong;

            if (time == null)
            {
                throw new ParseException("Can't read file timestamp");
            }

            Console.WriteLine("TS: " + time.Value);
            List.TimeStamp = new DateTime(time.Value + 504911232000000000);

            SNode obj = baseNode.Members[1].Members[0];

            if (obj == null)
            {
                return;
            }
            Parse(obj);
            Valid = true;
        }
Пример #3
0
        private void ParseDbRow(SNode node)
        {
            MarketOrder order = new MarketOrder();

            SNodeContainer members = node.Members;

            for (int i = 0; i < members.Length; i++)
            {
                SNode value = members[i];
                i++;
                SMarker key   = members[i] as SMarker;
                SIdent  ident = members[i] as SIdent;

                int typeKey = -1;

                if (key != null)
                {
                    typeKey = key.ID;
                }
                else if (ident != null && ident.Value == "issueDate")
                {
                    typeKey = 131;
                }
                else
                {
                    Console.WriteLine("Can't parse - giving up");
                    break;
                }

                SInt  intV  = value as SInt;
                SLong longV = value as SLong;
                SReal realV = value as SReal;

                int    sintV  = 0;
                long   slongV = 0;
                double srealV = 0.0;

                if (intV != null)
                {
                    sintV = intV.Value;
                }
                else if (longV != null)
                {
                    slongV = longV.Value;
                }
                else if (realV != null)
                {
                    srealV = realV.Value;
                }

                switch (typeKey)
                {
                case 139:
                    order.Price = slongV;
                    break;

                case 161:
                    order.VolRemaining = srealV;
                    break;

                case 131:
                    order.Issued = slongV;
                    break;

                case 138:
                    order.OrderID = slongV;
                    break;

                case 160:
                    order.VolEntered = sintV;
                    break;

                case 137:
                    order.MinVolume = sintV;
                    break;

                case 155:
                    order.StationID = sintV;
                    break;

                case 141:
                    order.RegionID = sintV;
                    List.Region    = sintV;
                    break;

                case 150:
                    order.SolarSystemID = sintV;
                    break;

                case 41:
                    order.Jumps = sintV;
                    break;

                case 74:
                    order.Type = sintV;
                    List.Type  = sintV;
                    break;

                case 140:
                    order.Range = sintV;
                    break;

                case 126:
                    order.Duration = sintV;
                    break;

                case 116:
                    if (sintV != 0)
                    {
                        order.IsBid = true;
                    }
                    else
                    {
                        order.IsBid = false;
                    }
                    break;

                default:
                    Console.WriteLine("Unknown key ID:" + key.ID + " r: " + srealV + " l: " + slongV + " i: " + sintV);
                    break;
                }
            }

            List.AddOrder(order);
        }
Пример #4
0
        protected SNode ParseOne()
        {
            EStreamCode check;
            byte        isshared  = 0;
            SNode       thisobj   = null;
            SDBRow      lastDbRow = null;

            try
            {
                byte type = Reader.ReadByte();
                check    = (EStreamCode)(type & 0x3f);
                isshared = (byte)(type & 0x40);
            }
            catch (EndOfFileException)
            {
                return(null);
            }

            #region EStreamCode Switch
            switch (check)
            {
            case EStreamCode.EStreamStart:
                break;

            case EStreamCode.ENone:
                thisobj = new SNone();
                break;

            case EStreamCode.EString:
                thisobj = new SString(Reader.ReadString(Reader.ReadByte()));
                break;

            case EStreamCode.ELong:
                thisobj = new SLong(Reader.ReadLong());
                break;

            case EStreamCode.EInteger:
                thisobj = new SInt(Reader.ReadInt());
                break;

            case EStreamCode.EShort:
                thisobj = new SInt(Reader.ReadShort());
                break;

            case EStreamCode.EByte:
                thisobj = new SInt(Reader.ReadByte());
                break;

            case EStreamCode.ENeg1Integer:
                thisobj = new SInt(-1);
                break;

            case EStreamCode.E0Integer:
                thisobj = new SInt(0);
                break;

            case EStreamCode.E1Integer:
                thisobj = new SInt(1);
                break;

            case EStreamCode.EReal:
                thisobj = new SReal(Reader.ReadDouble());
                break;

            case EStreamCode.E0Real:
                thisobj = new SReal(0);
                break;

            case EStreamCode.E0String:
                thisobj = new SString(null);
                break;

            case EStreamCode.EString3:
                thisobj = new SString(Reader.ReadString(1));
                break;

            case EStreamCode.EString4:
                goto case EStreamCode.EString;

            case EStreamCode.EMarker:
                thisobj = new SMarker((byte)GetLength());
                break;

            case EStreamCode.EUnicodeString:
                goto case EStreamCode.EString;

            case EStreamCode.EIdent:
                thisobj = new SIdent(Reader.ReadString(GetLength()));
                break;

            case EStreamCode.ETuple:
            {
                int length = GetLength();
                thisobj = new STuple((uint)length);
                Parse(thisobj, length);
                break;
            }

            case EStreamCode.ETuple2:
                goto case EStreamCode.ETuple;

            case EStreamCode.EDict:
            {
                int   len  = (GetLength() * 2);
                SDict dict = new SDict((uint)len);
                thisobj = dict;
                Parse(dict, len);
                break;
            }

            case EStreamCode.EObject:
                thisobj = new SObject();
                Parse(thisobj, 2);
                break;

            case EStreamCode.ESharedObj:
                thisobj = ShareGet(GetLength());
                break;

            case EStreamCode.EChecksum:
                thisobj = new SString("checksum");
                Reader.ReadInt();
                break;

            case EStreamCode.EBoolTrue:
                thisobj = new SInt(1);
                break;

            case EStreamCode.EBoolFalse:
                thisobj = new SInt(0);
                break;

            case EStreamCode.EObject22:
            {
                SObject obj = new SObject();
                thisobj = obj;
                Parse(thisobj, 1);

                string oclass = obj.Name;
                if (oclass == "dbutil.RowList")
                {
                    SNode row;
                    while ((row = ParseOne()) != null)
                    {
                        obj.AddMember(row);
                    }
                }
                break;
            }

            case EStreamCode.EObject23:
                goto case EStreamCode.EObject22;

            case EStreamCode.E0Tuple:
                thisobj = new STuple(0);
                break;

            case EStreamCode.E1Tuple:
                thisobj = new STuple(1);
                Parse(thisobj, 1);
                break;

            case EStreamCode.E0Tuple2:
                goto case EStreamCode.E0Tuple;

            case EStreamCode.E1Tuple2:
                goto case EStreamCode.E1Tuple;

            case EStreamCode.EEmptyString:
                thisobj = new SString(string.Empty);
                break;

            case EStreamCode.EUnicodeString2:
                /* Single unicode character */
                thisobj = new SString(Reader.ReadString(2));
                break;

            case EStreamCode.ECompressedRow:
                thisobj = GetDBRow();
                break;

            case EStreamCode.ESubstream:
            {
                int             len       = GetLength();
                CacheFileReader readerSub = new CacheFileReader(Reader, len);
                SSubStream      ss        = new SSubStream(len);
                thisobj = ss;
                CacheFileParser sp = new CacheFileParser(readerSub);
                sp.Parse();
                for (int i = 0; i < sp.Streams.Count; i++)
                {
                    ss.AddMember(sp.Streams[i].Clone());
                }

                Reader.Seek(readerSub.Position, SeekOrigin.Begin);
                break;
            }

            case EStreamCode.E2Tuple:
                thisobj = new STuple(2);
                Parse(thisobj, 2);
                break;

            case EStreamCode.EString2:
                goto case EStreamCode.EString;

            case EStreamCode.ESizedInt:
                switch (Reader.ReadByte())
                {
                case 8:
                    thisobj = new SLong(Reader.ReadLong());
                    break;

                case 4:
                    thisobj = new SInt(Reader.ReadInt());
                    break;

                case 3:
                    // The following seems more correct than the forumla used.
                    // int value = (Reader.Char() << 16) + (Reader.ReadByte());
                    thisobj = new SInt((Reader.ReadByte()) + (Reader.ReadByte() << 16));
                    break;

                case 2:
                    thisobj = new SInt(Reader.ReadShort());
                    break;
                }
                break;

            case (EStreamCode)0x2d:
                if (Reader.ReadByte() != (byte)0x2d)
                {
                    throw new ParseException("Didn't encounter a double 0x2d where one was expected at " + (Reader.Position - 2));
                }
                else if (lastDbRow != null)
                {
                    lastDbRow.IsLast = true;
                }
                return(null);

            case 0:
                break;

            default:
                throw new ParseException("Can't identify type " + String.Format("{0:x2}", (int)check) +
                                         " at position " + String.Format("{0:x2}", Reader.Position) + " limit " + Reader.Length);
            }
            #endregion

            if (thisobj == null)
            {
                throw new ParseException("no thisobj in parseone");
            }

            if (isshared != 0)
            {
                if (thisobj == null)
                {
                    throw new ParseException("shared flag but no obj");
                }
                ShareAdd(thisobj);
            }

            return(thisobj);
        }
Пример #5
0
        private void ParseDbRow(SNode node)
        {
            MarketHistory history = new MarketHistory();

            history.Region = Region;
            history.Type   = Type;

            SNodeContainer members = node.Members;

            for (int i = 0; i < members.Length; i++)
            {
                SNode  value = members[i++];
                SIdent ident = members[i] as SIdent;

                SInt  intV  = value as SInt;
                SLong longV = value as SLong;

                int  sintV  = 0;
                long slongV = 0;

                if (intV != null)
                {
                    sintV = intV.Value;
                }
                else if (longV != null)
                {
                    slongV = longV.Value;
                }

                switch (ident.Value)
                {
                case "historyDate":
                    history.HistoryTicks = slongV;
                    break;

                case "lowPrice":
                    history.LowPrice = slongV;
                    break;

                case "highPrice":
                    history.HighPrice = slongV;
                    break;

                case "avgPrice":
                    history.AveragePrice = slongV;
                    break;

                case "volume":
                    history.Volume = slongV;
                    break;

                case "orders":
                    history.Orders = sintV;
                    break;

                default:
                    throw new ParseException("Can't parse " + ident);
                }
            }
            List.Add(history);
        }
Пример #6
0
		protected SNode ParseOne()
		{
			EStreamCode check;
			byte isshared = 0;
			SNode thisobj = null;
			SDBRow lastDbRow = null;

			try
			{
				byte type = Reader.ReadByte();
				check = (EStreamCode)(type & 0x3f);
				isshared = (byte)(type & 0x40);
			}
			catch (EndOfFileException)
			{
				return null;
			}

			#region EStreamCode Switch
			switch (check)
			{
				case EStreamCode.EStreamStart:
					break;
				case EStreamCode.ENone:
					thisobj = new SNone();
					break;
				case EStreamCode.EString:
					thisobj = new SString(Reader.ReadString(Reader.ReadByte()));
					break;
				case EStreamCode.ELong:
					thisobj = new SLong(Reader.ReadLong());
					break;
				case EStreamCode.EInteger:
					thisobj = new SInt(Reader.ReadInt());
					break;
				case EStreamCode.EShort:
					thisobj = new SInt(Reader.ReadShort());
					break;
				case EStreamCode.EByte:
					thisobj = new SInt(Reader.ReadByte());
					break;
				case EStreamCode.ENeg1Integer:
					thisobj = new SInt(-1);
					break;
				case EStreamCode.E0Integer:
					thisobj = new SInt(0);
					break;
				case EStreamCode.E1Integer:
					thisobj = new SInt(1);
					break;
				case EStreamCode.EReal:
					thisobj = new SReal(Reader.ReadDouble());
					break;
				case EStreamCode.E0Real:
					thisobj = new SReal(0);
					break;
				case EStreamCode.E0String:
					thisobj = new SString(null);
					break;
				case EStreamCode.EString3:
					thisobj = new SString(Reader.ReadString(1));
					break;
				case EStreamCode.EString4:
					goto case EStreamCode.EString;
				case EStreamCode.EMarker:
					thisobj = new SMarker((byte)GetLength());
					break;
				case EStreamCode.EUnicodeString:
					goto case EStreamCode.EString;
				case EStreamCode.EIdent:
					thisobj = new SIdent(Reader.ReadString(GetLength()));
					break;
				case EStreamCode.ETuple:
					{
						int length = GetLength();
						thisobj = new STuple((uint)length);
						Parse(thisobj, length);
						break;
					}
				case EStreamCode.ETuple2:
					goto case EStreamCode.ETuple;
				case EStreamCode.EDict:
					{
						int len = (GetLength() * 2);
						SDict dict = new SDict((uint)len);
						thisobj = dict;
						Parse(dict, len);
						break;
					}
				case EStreamCode.EObject:
					thisobj = new SObject();
					Parse(thisobj, 2);
					break;
				case EStreamCode.ESharedObj:
					thisobj = ShareGet(GetLength());
					break;
				case EStreamCode.EChecksum:
					thisobj = new SString("checksum");
					Reader.ReadInt();
					break;
				case EStreamCode.EBoolTrue:
					thisobj = new SInt(1);
					break;
				case EStreamCode.EBoolFalse:
					thisobj = new SInt(0);
					break;
				case EStreamCode.EObject22:
					{
						SObject obj = new SObject();
						thisobj = obj;
						Parse(thisobj, 1);

						string oclass = obj.Name;
						if (oclass == "dbutil.RowList")
						{
							SNode row;
							while ((row = ParseOne()) != null)
								obj.AddMember(row);
						}
						break;
					}
				case EStreamCode.EObject23:
					goto case EStreamCode.EObject22;
				case EStreamCode.E0Tuple:
					thisobj = new STuple(0);
					break;
				case EStreamCode.E1Tuple:
					thisobj = new STuple(1);
					Parse(thisobj, 1);
					break;
				case EStreamCode.E0Tuple2:
					goto case EStreamCode.E0Tuple;
				case EStreamCode.E1Tuple2:
					goto case EStreamCode.E1Tuple;
				case EStreamCode.EEmptyString:
					thisobj = new SString(string.Empty);
					break;
				case EStreamCode.EUnicodeString2:
					/* Single unicode character */
					thisobj = new SString(Reader.ReadString(2));
					break;
				case EStreamCode.ECompressedRow:
					thisobj = GetDBRow();
					break;
				case EStreamCode.ESubstream:
					{
						int len = GetLength();
						CacheFileReader readerSub = new CacheFileReader(Reader, len);
						SSubStream ss = new SSubStream(len);
						thisobj = ss;
						CacheFileParser sp = new CacheFileParser(readerSub);
						sp.Parse();
						for (int i = 0; i < sp.Streams.Count; i++)
							ss.AddMember(sp.Streams[i].Clone());

						Reader.Seek(readerSub.Position, SeekOrigin.Begin);
						break;
					}
				case EStreamCode.E2Tuple:
					thisobj = new STuple(2);
					Parse(thisobj, 2);
					break;
				case EStreamCode.EString2:
					goto case EStreamCode.EString;
				case EStreamCode.ESizedInt:
					switch (Reader.ReadByte())
					{
						case 8:
							thisobj = new SLong(Reader.ReadLong());
							break;
						case 4:
							thisobj = new SInt(Reader.ReadInt());
							break;
						case 3:
							// The following seems more correct than the forumla used.
							// int value = (Reader.Char() << 16) + (Reader.ReadByte());
							thisobj = new SInt((Reader.ReadByte()) + (Reader.ReadByte() << 16));
							break;
						case 2:
							thisobj = new SInt(Reader.ReadShort());
							break;
					}
					break;
				case (EStreamCode)0x2d:
					if (Reader.ReadByte() != (byte)0x2d)
						throw new ParseException("Didn't encounter a double 0x2d where one was expected at " + (Reader.Position - 2));
					else if (lastDbRow != null)
						lastDbRow.IsLast = true;
					return null;
				case 0:
					break;
				default:
					throw new ParseException("Can't identify type " + String.Format("{0:x2}", (int)check) +
											" at position " + String.Format("{0:x2}", Reader.Position) + " limit " + Reader.Length);
			}
			#endregion

			if (thisobj == null)
				throw new ParseException("no thisobj in parseone");

			if (isshared != 0)
			{
				if (thisobj == null)
					throw new ParseException("shared flag but no obj");
				ShareAdd(thisobj);
			}

			return thisobj;
		}