コード例 #1
0
 public PriceGuideItem GetPriceGuide(string number, TypeDescription typedesc = TypeDescription.SET, bool New_Used = true)
 {
     try
     {
         string url = $"https://api.bricklink.com/api/store/v1/items/{typedesc.ToString()}/{number}/price";
         WebParameterCollection param = new WebParameterCollection();
         param.Add("currency_code", "EUR");
         if (New_Used)
         {
             param.Add("new_or_used", "N");
         }
         else
         {
             param.Add("new_or_used", "U");
         }
         for (int i = 0; i < retry; i++)
         {
             var strret      = ExecuteRequest(url, param);
             var retobjdeser = Newtonsoft.Json.JsonConvert.DeserializeObject <PriceMain>(strret);
             Debug.WriteLine($"{retobjdeser.meta.message}, {retobjdeser.meta.description}, {retobjdeser.meta.code}");
             if (retobjdeser.meta.message == "OK")
             {
                 return(retobjdeser.data);
             }
         }
         return(null);
     }
     catch (Exception)
     { return(null); }
 }
コード例 #2
0
 public SubSetDetail[] GetSubSets(string number, TypeDescription typedesc = TypeDescription.SET)
 {
     try
     {
         // / items /{ type}/{ no}/ subsets
         string url = $"https://api.bricklink.com/api/store/v1/items/{typedesc.ToString()}/{number}/subsets";
         for (int i = 0; i < retry; i++)
         {
             var strret      = ExecuteRequest(url);
             var retobjdeser = Newtonsoft.Json.JsonConvert.DeserializeObject <SubSetMain>(strret);
             Debug.WriteLine($"{retobjdeser.meta.message}, {retobjdeser.meta.description}, {retobjdeser.meta.code}");
             if (retobjdeser.meta.message == "OK")
             {
                 List <SubSetDetail> subdt = new List <SubSetDetail>();
                 foreach (var dt in retobjdeser.data)
                 {
                     try
                     {
                         //subdt.Add(dt.entries[dt.match_no]);
                         subdt.AddRange(dt.entries);
                     }
                     catch (Exception)
                     { }
                 }
                 return(subdt.ToArray());
             }
         }
         return(null);
     }
     catch (Exception)
     { return(null); }
 }
コード例 #3
0
        public void testJson()
        {
            TypeDescription bin = TypeDescription.createBinary();

            Assert.Equal("{\"category\": \"binary\", \"id\": 0, \"max\": 0}",
                         bin.toJson());
            Assert.Equal("binary", bin.ToString());
            TypeDescription @struct = TypeDescription.createStruct()
                                      .addField("f1", TypeDescription.createInt())
                                      .addField("f2", TypeDescription.createString())
                                      .addField("f3", TypeDescription.createDecimal());

            Assert.Equal("struct<f1:int,f2:string,f3:decimal(38,10)>",
                         @struct.ToString());
            Assert.Equal("{\"category\": \"struct\", \"id\": 0, \"max\": 3, \"fields\": [\n"
                         + "  \"f1\": {\"category\": \"int\", \"id\": 1, \"max\": 1},\n"
                         + "  \"f2\": {\"category\": \"string\", \"id\": 2, \"max\": 2},\n"
                         + "  \"f3\": {\"category\": \"decimal\", \"id\": 3, \"max\": 3, \"precision\": 38, \"scale\": 10}]}",
                         @struct.toJson());
            @struct = TypeDescription.createStruct()
                      .addField("f1", TypeDescription.createUnion()
                                .addUnionChild(TypeDescription.createByte())
                                .addUnionChild(TypeDescription.createDecimal()
                                               .withPrecision(20).withScale(10)))
                      .addField("f2", TypeDescription.createStruct()
                                .addField("f3", TypeDescription.createDate())
                                .addField("f4", TypeDescription.createDouble())
                                .addField("f5", TypeDescription.createBoolean()))
                      .addField("f6", TypeDescription.createChar().withMaxLength(100));
            Assert.Equal("struct<f1:union<tinyint,decimal(20,10)>,f2:struct<f3:date,f4:double,f5:boolean>,f6:char(100)>",
                         @struct.ToString());
            Assert.Equal(
                "{\"category\": \"struct\", \"id\": 0, \"max\": 8, \"fields\": [\n" +
                "  \"f1\": {\"category\": \"union\", \"id\": 1, \"max\": 3, \"children\": [\n" +
                "    {\"category\": \"tinyint\", \"id\": 2, \"max\": 2},\n" +
                "    {\"category\": \"decimal\", \"id\": 3, \"max\": 3, \"precision\": 20, \"scale\": 10}]},\n" +
                "  \"f2\": {\"category\": \"struct\", \"id\": 4, \"max\": 7, \"fields\": [\n" +
                "    \"f3\": {\"category\": \"date\", \"id\": 5, \"max\": 5},\n" +
                "    \"f4\": {\"category\": \"double\", \"id\": 6, \"max\": 6},\n" +
                "    \"f5\": {\"category\": \"boolean\", \"id\": 7, \"max\": 7}]},\n" +
                "  \"f6\": {\"category\": \"char\", \"id\": 8, \"max\": 8, \"length\": 100}]}",
                @struct.toJson());
        }
コード例 #4
0
        void CheckType(Type type)
        {
            var desc1  = new TypeDescription(type);
            var name   = desc1.ToString();
            var desc2  = new TypeDescription(name);
            var parsed = desc2.Resolve();
            var lookup = Type.GetType(name);

            Assert.Equal(type, parsed);
            Assert.Equal(type, lookup);
            Assert.Equal(desc1, desc2);
        }
コード例 #5
0
        public static bool IsUintConst(this TypeDescription typeDescription, out uint sz)
        {
            var type = typeDescription.ToString();

            if (type.StartsWith("int_const"))
            {
                //uint c = uint.Parse(GetNumberFromEnd(type));
                sz = 256;
                return(sz >= 0 ? true: false);
            }
            else
            {
                sz = uint.MaxValue;
                return(false);
            }
        }
コード例 #6
0
        //private static System.Collections.Generic.Dictionary<TypeDescription, string> _getTypeClass;
        public static ReceivedMessageDataBase GetReceivedMessageData(TypeDescription type, string content)
        {
            //if (_getTypeClass == null)
            //{
            //    var s = new TypeDescriptionJson().JsonClass;
            //    _getTypeClass = Newtonsoft.Json.JsonConvert.DeserializeObject<System.Collections.Generic.Dictionary<TypeDescription, string>>(s);
            //}
            //var typeKey = _getTypeClass[type];
            var typeKey = type.ToString();

            var dddtype = typeof(ReceivedMessageData <>);
            var mtype   = dddtype.Assembly.GetType("AlibabaSDK.WebSocketModels." + typeKey, false) ?? typeof(object);
            var ssss    = dddtype.MakeGenericType(mtype);

            return(Newtonsoft.Json.JsonConvert.DeserializeObject(content, ssss) as ReceivedMessageDataBase);
        }
コード例 #7
0
        public BrickItem GetCatalogItem(string number, TypeDescription typedesc = TypeDescription.SET)
        {
            try
            {
                string url = $"https://api.bricklink.com/api/store/v1/items/{typedesc.ToString()}/{number}";
                for (int i = 0; i < retry; i++)
                {
                    var strret      = ExecuteRequest(url);
                    var retobjdeser = Newtonsoft.Json.JsonConvert.DeserializeObject <CatalogMain>(strret);
                    Debug.WriteLine($"{retobjdeser.meta.message}, {retobjdeser.meta.description}, {retobjdeser.meta.code}");
                    if (retobjdeser.meta.message == "OK")
                    {
                        BrickItem retset = new BrickItem();
                        //crap but ok as enum are aligned and not searching for other elements than the one which can match
                        retset.ItemType     = (ItemType)typedesc;
                        retset.Number       = retobjdeser.data.no;
                        retset.Name         = retobjdeser.data.name;
                        retset.ThumbnailUrl = retobjdeser.data.thumbnail_url;
                        switch (typedesc)
                        {
                        case TypeDescription.MINIFIG:
                            retset.BrickURL = "https://www.bricklink.com/v2/catalog/catalogitem.page?M=" + retset.Number;
                            break;

                        case TypeDescription.PART:
                            retset.BrickURL = "https://www.bricklink.com/v2/catalog/catalogitem.page?P=" + retset.Number;
                            break;

                        case TypeDescription.SET:
                            retset.BrickURL = "https://www.bricklink.com/v2/catalog/catalogitem.page?S=" + retset.Number;
                            break;

                        case TypeDescription.BOOK:
                            retset.BrickURL = "https://www.bricklink.com/v2/catalog/catalogitem.page?B=" + retset.Number;
                            break;

                        case TypeDescription.GEAR:
                            retset.BrickURL = "https://www.bricklink.com/v2/catalog/catalogitem.page?G=" + retset.Number;
                            break;

                        case TypeDescription.CATALOG:
                            retset.BrickURL = "https://www.bricklink.com/v2/catalog/catalogitem.page?C=" + retset.Number;
                            break;

                        case TypeDescription.INSTRUCTION:
                        case TypeDescription.UNSORTED_LOT:
                        case TypeDescription.ORIGINAL_BOX:
                        default:
                            retset.BrickURL = "https://www.bricklink.com/v2/search.page?q=" + retset.Number;
                            break;
                        }
                        //clean URL, sometimes it comes without the http
                        if (retset.ThumbnailUrl.Length > 0)
                        {
                            if (retset.ThumbnailUrl.IndexOf("http", StringComparison.CurrentCultureIgnoreCase) < 0)
                            {
                                retset.ThumbnailUrl = "http:" + retset.ThumbnailUrl;
                            }
                        }
                        //need to implement category names
                        try
                        {
                            retset.Theme = categories.Where(x => x.category_id == retobjdeser.data.category_id).First().category_name;
                        }
                        catch (Exception)
                        {
                            retset.Theme = "";
                        }
                        //get all the prices details
                        PriceGuideItem retPrice = GetPriceGuide(retobjdeser.data.no, typedesc, false);
                        double         retail_price;
                        retset.New = new PriceDetails();
                        Double.TryParse(retPrice?.avg_price, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out retail_price);
                        retset.New.Average = retail_price;
                        Double.TryParse(retPrice?.min_price, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out retail_price);
                        retset.New.Min = retail_price;
                        Double.TryParse(retPrice?.max_price, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out retail_price);
                        retset.New.Max = retail_price;
                        // so far only USD, need to implement other currencies
                        retset.New.Currency = "USD";
                        retPrice            = GetPriceGuide(retobjdeser.data.no, typedesc, true);
                        retset.Used         = new PriceDetails();
                        Double.TryParse(retPrice?.avg_price, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out retail_price);
                        retset.Used.Average = retail_price;
                        Double.TryParse(retPrice?.min_price, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out retail_price);
                        retset.Used.Min = retail_price;
                        Double.TryParse(retPrice?.max_price, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out retail_price);
                        retset.Used.Max      = retail_price;
                        retset.Used.Currency = "USD";
                        retset.YearReleased  = retobjdeser.data.year_released;
                        retset.BrickService  = ServiceProvider.Bricklink;
                        return(retset);
                    }
                }
                return(null);
            }
            catch (Exception)
            { return(null); }
        }
コード例 #8
0
        // "Out" parameter "value" is only used when IsUintConst is called in the context off a BinaryOperation on constants with the power operator.
        public static bool IsUintConst(this TypeDescription typeDescription, Expression constant, out BigInteger value, out uint sz)
        {
            sz = 256;
            try
            {
                var type = typeDescription.ToString();
                if (type.StartsWith("int_const"))
                {
                    if (constant is Literal)
                    {
                        string constStr = ((Literal)constant).Value;
                        value = BigInteger.Parse(constStr);
                        int res = GetConstantSize(value);
                        if (res == -1)
                        {
                            // Constant > 2^256:
                            Console.WriteLine($"Warning: uint constant > 2**256");
                            sz = 256;
                            return(true);
                        }
                        else
                        {
                            sz = (uint)res;
                            return(true);
                        }
                    }
                    else if (constant is BinaryOperation)
                    {
                        BinaryOperation binaryConstantExpr = (BinaryOperation)constant;

                        if (binaryConstantExpr.LeftExpression is Literal && binaryConstantExpr.RightExpression is Literal)
                        {
                            // Get expression value from TypeDescriptions (but not if the constant is too big)
                            string typeStr = binaryConstantExpr.TypeDescriptions.TypeString;

                            if (typeDescription.TypeString.Contains("omitted"))
                            {
                                // Large constant which is abbreviated in the typeDescription:
                                // This would probably never happen, because Solidity compiler reports type errors for such constants
                                Console.WriteLine($"Warning: constant expression contains large constant(s);");
                                Console.WriteLine($"if the large constant is an operand in a power operation,");
                                Console.WriteLine($"modulo arithmetic check will not work correctly");
                                value = 0;
                                sz    = 256;
                                return(false);
                            }
                            else
                            {
                                value = BigInteger.Parse(GetNumberFromEnd(typeStr));
                                sz    = 256;
                                return(true);
                            }
                        }
                        else
                        {
                            // TODO: The warning below could probably be suppressed:
                            // this is the case of exprs like (2+2+2...), where left and right expressions are BinaryOperation;
                            // in these cases, "value" is never used (it is only used for power operation on two literals)
                            Console.WriteLine($"Warning in IsUintConst: constant expression is neither Literal nor BinaryOperation with Literal operands; hint: use temps for subexpressions");
                            value = 0;
                            sz    = 256;
                            return(false);
                        }
                    }
                    else
                    {
                        // TODO: constant is TupleExpression:
                        Console.WriteLine($"Warning in IsUintConst: constant expression is neither Literal nor BinaryOperation; hint: use temps for subexpressions");
                        value = 0;
                        sz    = 256;
                        return(false);
                    }
                }
                else
                {
                    sz    = 256;
                    value = 0;
                    return(false);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine($"VeriSol translation error: exception in IsUintConst: {e.Message}");
                value = 0;
                sz    = 256;
                return(false);
            }
        }