props/MultiShop-Modules/MultiShop.Shop/AliExpressModule/Shop.cs

71 lines
1.9 KiB
C#
Raw Normal View History

using System;
2021-05-09 06:49:37 +00:00
using System.Collections;
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;
using System.Text.RegularExpressions;
2021-05-09 06:49:37 +00:00
using System.Threading;
using System.Threading.Tasks;
2021-05-09 06:49:37 +00:00
using GameServiceWarden.Core.Collection;
using MultiShop.Shop.Framework;
using SimpleLogger;
namespace MultiShop.Shop.AliExpressModule
{
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-05-09 06:49:37 +00:00
public bool UseProxy { get; set; } = true;
2021-05-09 06:49:37 +00:00
private HttpClient http;
private string query;
private Currency currency;
private bool disposedValue;
2021-05-09 06:49:37 +00:00
public void Initialize()
{
if (http != null) throw new InvalidOperationException("HttpClient already instantiated.");
this.http = new HttpClient();
}
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();
}
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)
{
return new ShopEnumerator(cancellationToken, query, currency, http, UseProxy);
2021-05-09 06:49:37 +00:00
}
}
}