/// <summary> /// Serialize an expression tree. /// </summary> /// <param name="root">The root <see cref="Expression"/>.</param> /// <param name="config">Optional configuration.</param> /// <returns>The serialized <see cref="Expression"/> tree.</returns> /// <exception cref="ArgumentNullException">Thrown when the <see cref="Expression"/> is <c>null</c>.</exception> public static string Serialize( Expression root, Action <IConfigurationBuilder> config = null) { Ensure.NotNull(() => root); SerializationState state; if (config != null) { var builder = ServiceHost.GetService <IConfigurationBuilder>(); config(builder); state = builder.Configure(); } else { state = DefaultConfiguration.Value.GetDefaultState(); } if (state.CompressExpression) { root = Compressor.EvalAndCompress(root); } var serializeRoot = new SerializationRoot(SerializerValue.Serialize(root, state)) { TypeIndex = state.TypeIndex.ToArray(), }; return(JsonSerializer.Serialize(serializeRoot, state.Options)); }
/// <summary> /// Deserialize to an <see cref="Expression"/> tree. /// </summary> /// <param name="root">The root expression.</param> /// <param name="queryRoot">The root of the query to apply.</param> /// <param name="config">Optional configuration.</param> /// <param name="stateCallback">Register a callback to inspect the state.</param> /// <returns>The deserialized <see cref="Expression"/> or <c>null</c>.</returns> /// <exception cref="ArgumentException">Thrown when the json is <c>null</c> or whitespace.</exception> public static Expression Deserialize( SerializationRoot root, Expression queryRoot = null, Action <IConfigurationBuilder> config = null, Action <SerializationState> stateCallback = null) { SerializationState state; if (config != null) { var builder = ServiceHost.GetService <IConfigurationBuilder>(); config(builder); state = builder.Configure(); } else { state = DefaultConfiguration.Value.GetDefaultState(); } state.QueryRoot = queryRoot; state.TypeIndex = new List <string>( root.TypeIndex ?? new string[0]); var result = SerializerValue.Deserialize(root.Expression, state); stateCallback?.Invoke(state); return(result); }
/// <summary> /// Получить предложения продажи биткоинов. Либо без фильтра (страна, валюта, метод оплаты), либо с одним из наборов филтров /// !!! - Необходимо указывать валюту или страну. Если не указать явно, то определиться по IP пдресу страна и валюта. /// !!! - Если набор фильтров будет не верным-то запрос вернёт null /// ??? - Параметр pagination_url отключает все фильтры. pagination_url используется для разбивки на порции результат и в себе уже имеет все фильтры /// 0) Без филтра совсем. /// 1) По методу оплаты (payment_method) /// 2) По валюте (currency) /// 3) По валюте и методу оплаты (currency & payment_method) /// 4) По коду старны и названию страны (countrycode & country_name) /// 5) По коду старны, названию страны и методу оплаты (countrycode & country_name & payment_method) /// </summary> /// <param name="countrycode">Код старны</param> /// <param name="country_name">Название старны</param> /// <param name="currency">Валюта</param> /// <param name="payment_method">Метод оплаты</param> /// <param name="pagination_url">URL запроса разделения результата на порции/страницы</param> public AdListBitcoinsOnlineSerializationClass SellBitcoinsOnline(string countrycode = "", string country_name = "", string currency = "", string payment_method = "", string pagination_url = "") { if (string.IsNullOrEmpty(pagination_url) && string.IsNullOrEmpty(currency) && !string.IsNullOrEmpty(countrycode) && !string.IsNullOrEmpty(country_name) && !string.IsNullOrEmpty(payment_method)) { return((AdListBitcoinsOnlineSerializationClass)SerializationRoot.ReadObject(typeof(AdListBitcoinsOnlineSerializationClass), api_raw.Sell_bitcoins_online_by_country_and_payment(countrycode, country_name, payment_method))); } else if (string.IsNullOrEmpty(pagination_url) && string.IsNullOrEmpty(currency + payment_method) && !string.IsNullOrEmpty(countrycode) && !string.IsNullOrEmpty(country_name)) { return((AdListBitcoinsOnlineSerializationClass)SerializationRoot.ReadObject(typeof(AdListBitcoinsOnlineSerializationClass), api_raw.Sell_bitcoins_online_by_country(countrycode, country_name))); } else if (string.IsNullOrEmpty(pagination_url) && string.IsNullOrEmpty(countrycode + country_name) && !string.IsNullOrEmpty(currency) && !string.IsNullOrEmpty(payment_method)) { return((AdListBitcoinsOnlineSerializationClass)SerializationRoot.ReadObject(typeof(AdListBitcoinsOnlineSerializationClass), api_raw.Sell_bitcoins_online_by_currency_and_payment(currency, payment_method))); } else if (string.IsNullOrEmpty(pagination_url) && string.IsNullOrEmpty(countrycode + country_name + payment_method) && !string.IsNullOrEmpty(currency)) { return((AdListBitcoinsOnlineSerializationClass)SerializationRoot.ReadObject(typeof(AdListBitcoinsOnlineSerializationClass), api_raw.Sell_bitcoins_online_by_currency(currency))); } else if (string.IsNullOrEmpty(pagination_url) && string.IsNullOrEmpty(countrycode + country_name + currency) && !string.IsNullOrEmpty(payment_method)) { return((AdListBitcoinsOnlineSerializationClass)SerializationRoot.ReadObject(typeof(AdListBitcoinsOnlineSerializationClass), api_raw.Sell_bitcoins_online_by_payment(payment_method))); } else if (!string.IsNullOrEmpty(pagination_url) || string.IsNullOrEmpty(countrycode + country_name + currency + payment_method)) { return((AdListBitcoinsOnlineSerializationClass)SerializationRoot.ReadObject(typeof(AdListBitcoinsOnlineSerializationClass), api_raw.Sell_bitcoins_online(pagination_url))); } return(null); }
/// <summary> /// Deserializes a query from the raw json. /// </summary> /// <typeparam name="T">The type of the query.</typeparam> /// <param name="root">The serialization root.</param> /// <param name="host">The <see cref="IQueryable{T}"/> host to create the query.</param> /// <param name="config">The optional configuration.</param> /// <param name="stateCallback">Register a callback to inspect the state.</param> /// <returns>The deserialized <see cref="IQueryable{T}"/>.</returns> public static IQueryable <T> DeserializeQuery <T>( SerializationRoot root, IQueryable host = null, Action <IConfigurationBuilder> config = null, Action <SerializationState> stateCallback = null) { host = host ?? IQueryableExtensions.CreateQueryTemplate <T>(); return(DeserializeQuery(host, root, config, stateCallback) as IQueryable <T>); }
/// <summary> /// Overload to return a specific type. /// </summary> /// <remarks> /// Do not use this method to deserialize <see cref="IQueryable"/> or <see cref="IQueryable{T}"/>. /// The <see cref="DeserializeQuery(IQueryable, SerializationRoot, Action{IConfigurationBuilder}, Action{SerializationState})"/> method is provided for this. /// </remarks> /// <typeparam name="T">The type of the <see cref="Expression"/> root.</typeparam> /// <param name="root">The root for serialization.</param> /// <param name="queryRoot">The root of the query to apply.</param> /// <param name="config">Optional configuration.</param> /// <param name="stateCallback">Register a callback to inspect the state.</param> /// <returns>The <see cref="Expression"/> or <c>null</c>.</returns> public static T Deserialize <T>( SerializationRoot root, Expression queryRoot = null, Action <IConfigurationBuilder> config = null, Action <SerializationState> stateCallback = null) where T : Expression => (T)Deserialize( root, queryRoot, config, stateCallback);
/// <summary> /// Deserializes a query from the raw json. /// </summary> /// <param name="host">The host to create the <see cref="IQueryable"/>.</param> /// <param name="root">The root that was serialized.</param> /// <param name="config">Optional configuratoin.</param> /// <returns>The deserialized <see cref="IQueryable"/>.</returns> /// <param name="stateCallback">Register a callback to inspect the state.</param> /// <exception cref="ArgumentNullException">Throws when host is null.</exception> /// <exception cref="ArgumentException">Throws when the json is empty or whitespace.</exception> public static IQueryable DeserializeQuery( IQueryable host, SerializationRoot root, Action <IConfigurationBuilder> config = null, Action <SerializationState> stateCallback = null) { Ensure.NotNull(() => host); var expression = Deserialize(root, host.Expression, config, stateCallback); IQueryable result; result = host.Provider.CreateQuery(expression); return(result); }
/// <summary> /// Получить методы оплаты. Все или в определённой стране /// </summary> /// <param name="countrycode">Код старны (напрмиер RU). Если не указать то возвращается все</param> /// <returns></returns> public Dictionary <string, PaymentMethodsSerializationClass> PaymentMethods(string countrycode = "") { string json; if (string.IsNullOrEmpty(countrycode)) { json = api_raw.Payment_methods; } else { json = api_raw.Payment_methods_by_countrycode(countrycode); } Regex re = new Regex(@"^{\s*""\s*data\s*""\s*:\s*{\s*""\s*methods\s*""\s*:\s*{\s*(.+)\s*}\s*,\s*""\s*method_count\s*""\s*:\s*\d+\s*}\s*}$"); MatchCollection m = re.Matches(json); json = m[0].Groups[1].Value.Trim(); re = new Regex(@"(""\s*[^""]+\s*""\s*:\s*{\s*[^}]+\s*})", RegexOptions.Compiled); m = re.Matches(json); re = new Regex(@"""([^""]+)"":(.+)", RegexOptions.Compiled); Dictionary <string, PaymentMethodsSerializationClass> pay_metgods = new Dictionary <string, PaymentMethodsSerializationClass>(); foreach (Match _m in m) { json = _m.Groups[1].Value.Trim(); Match my_match = re.Match(json); pay_metgods.Add(my_match.Groups[1].Value, (PaymentMethodsSerializationClass)SerializationRoot.ReadObject(typeof(PaymentMethodsSerializationClass), my_match.Groups[2].Value.Trim())); } return(pay_metgods.ToList().OrderBy(x => x.Value.code).ToDictionary(x => x.Key, x => x.Value)); }
/////////////////////////////////////////// #region Advertisements - Announcements of sale/purchase of bitcoins #region authenticated (to perform these requests requires authorization on the site) /// <summary> /// Возвращает все рекламные объявления владельца ключа в виде ad_list данных. Если объявлений много, ответ будет разбит на страницы. Вы можете отфильтровать ответ, используя необязательные аргументы. /// </summary> /// <returns></returns> public AdListBitcoinsOnlineSerializationClass AdsByFilter(bool?visible = null, string trade_type = "", string currency = "", string countrycode = "") { return((AdListBitcoinsOnlineSerializationClass)SerializationRoot.ReadObject(typeof(AdListBitcoinsOnlineSerializationClass), api_raw.Get_ADs_by_filter(visible, trade_type, currency, countrycode))); }
/// <summary> /// Журнал ордеров /// </summary> /// <param name="currency">Валюта (например RUB)</param> /// <returns></returns> public OrdersSerializationClass Orderbook(string currency) { return((OrdersSerializationClass)SerializationRoot.ReadObject(typeof(OrdersSerializationClass), api_raw.Bitcoincharts_orderbook_by_currency(currency))); }
/// <summary> /// Все закрытые сделки онлайн покупки/продажи. Обновляются каждые 15 минут. Максимальный размер партии выборки - 500 записей.Используйте "?since=parameter" с последним tid что бы получить нужный сдвиг /// </summary> /// <param name="currency"></param> /// <returns></returns> public TradeItemSerializationClass[] Trades(string currency) { return((TradeItemSerializationClass[])SerializationRoot.ReadObject(typeof(TradeItemSerializationClass[]), api_raw.Bitcoincharts_trades_by_currency(currency))); }
/// <summary> /// Получить места покупки/продажи около GPS lat/lon. /// </summary> /// <param name="lat">Широта (например 55.7542359)</param> /// <param name="lon">Долгота (например 37.6194498)</param> /// <param name="countrycode">Код страны (напрмиер RU)</param> /// <param name="location_string">Описание места</param> /// <returns></returns> public PlacesSerializationClass Places(string lat, string lon, string countrycode = "", string location_string = "") { return((PlacesSerializationClass)SerializationRoot.ReadObject(typeof(PlacesSerializationClass), api_raw.Places(lat, lon, countrycode, location_string))); }
/// <summary> /// Serialize the <see cref="SerializationRoot"/>. /// </summary> /// <param name="root">The <see cref="SerializationRoot"/>.</param> /// <param name="options">The serialization options.</param> /// <returns>The serialized json in text.</returns> public string FromSerializationRoot(SerializationRoot root, JsonSerializerOptions options = null) => JsonSerializer.Serialize(root, PrepareOptions(options));