2021-04-23 20:11:49 +00:00
|
|
|
|
using System;
|
2021-05-09 06:49:37 +00:00
|
|
|
|
using System.Collections;
|
2021-04-23 20:11:49 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Net;
|
|
|
|
|
using System.Net.Http;
|
2021-05-09 06:49:37 +00:00
|
|
|
|
using System.Text.Json;
|
|
|
|
|
using System.Text.Json.Serialization;
|
2021-04-23 20:11:49 +00:00
|
|
|
|
using System.Text.RegularExpressions;
|
2021-05-09 06:49:37 +00:00
|
|
|
|
using System.Threading;
|
2021-04-23 20:11:49 +00:00
|
|
|
|
using System.Threading.Tasks;
|
2021-05-09 06:49:37 +00:00
|
|
|
|
using GameServiceWarden.Core.Collection;
|
2021-05-21 18:32:25 +00:00
|
|
|
|
using MultiShop.Shop.Framework;
|
2021-04-23 20:11:49 +00:00
|
|
|
|
using SimpleLogger;
|
|
|
|
|
|
2021-05-21 18:32:25 +00:00
|
|
|
|
namespace MultiShop.Shop.AliExpressModule
|
2021-04-23 20:11:49 +00:00
|
|
|
|
{
|
|
|
|
|
public class Shop : IShop
|
|
|
|
|
{
|
|
|
|
|
public string ShopName => "AliExpress";
|
|
|
|
|
|
|
|
|
|
public string ShopDescription => "A China based online store.";
|
|
|
|
|
|
2021-05-09 06:49:37 +00:00
|
|
|
|
public string ShopModuleAuthor => "Reslate";
|
2021-04-23 20:11:49 +00:00
|
|
|
|
|
2021-05-09 06:49:37 +00:00
|
|
|
|
public bool UseProxy { get; set; } = true;
|
2021-04-23 20:11:49 +00:00
|
|
|
|
|
2021-05-09 06:49:37 +00:00
|
|
|
|
private HttpClient http;
|
|
|
|
|
private string query;
|
|
|
|
|
private Currency currency;
|
|
|
|
|
private bool disposedValue;
|
2021-04-23 20:11:49 +00:00
|
|
|
|
|
|
|
|
|
|
2021-05-09 06:49:37 +00:00
|
|
|
|
public void Initialize()
|
|
|
|
|
{
|
|
|
|
|
if (http != null) throw new InvalidOperationException("HttpClient already instantiated.");
|
|
|
|
|
this.http = new HttpClient();
|
2021-04-23 20:11:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected virtual void Dispose(bool disposing)
|
|
|
|
|
{
|
|
|
|
|
if (!disposedValue)
|
|
|
|
|
{
|
|
|
|
|
if (disposing)
|
|
|
|
|
{
|
2021-05-09 06:49:37 +00:00
|
|
|
|
if (http == null) throw new InvalidOperationException("HttpClient not instantiated.");
|
|
|
|
|
http.Dispose();
|
2021-04-23 20:11:49 +00:00
|
|
|
|
}
|
|
|
|
|
disposedValue = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
Dispose(disposing: true);
|
|
|
|
|
GC.SuppressFinalize(this);
|
|
|
|
|
}
|
2021-05-09 06:49:37 +00:00
|
|
|
|
|
|
|
|
|
public void SetupSession(string query, Currency currency)
|
|
|
|
|
{
|
|
|
|
|
this.query = query;
|
|
|
|
|
this.currency = currency;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IAsyncEnumerator<ProductListing> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
|
|
|
|
{
|
2021-05-11 01:03:08 +00:00
|
|
|
|
return new ShopEnumerator(cancellationToken, query, currency, http, UseProxy);
|
2021-05-09 06:49:37 +00:00
|
|
|
|
}
|
2021-04-23 20:11:49 +00:00
|
|
|
|
}
|
|
|
|
|
}
|