Skip to content

Commit

Permalink
Merge pull request #14 from xyx0826/dev
Browse files Browse the repository at this point in the history
Release 1.6, see changelog
  • Loading branch information
xyx0826 committed Sep 22, 2021
2 parents c6f0882 + e010437 commit d2b1aba
Show file tree
Hide file tree
Showing 18 changed files with 394 additions and 191 deletions.
14 changes: 7 additions & 7 deletions Priceall/App.config
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="Priceall.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="Priceall.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false"/>
</sectionGroup>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/>
</startup>
<userSettings>
<Priceall.Properties.Settings>
Expand Down Expand Up @@ -68,10 +68,10 @@
<value>0</value>
</setting>
<setting name="LowerColor" serializeAs="String">
<value />
<value/>
</setting>
<setting name="UpperColor" serializeAs="String">
<value />
<value/>
</setting>
<setting name="UseLowLevelHotkey" serializeAs="String">
<value>False</value>
Expand All @@ -84,4 +84,4 @@
</setting>
</Priceall.Properties.Settings>
</userSettings>
</configuration>
</configuration>
17 changes: 10 additions & 7 deletions Priceall/Appraisal/AppraisalMarket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ namespace Priceall.Appraisal
[Flags]
enum AppraisalMarket
{
Universe = 0b_0000_0001,
Jita = 0b_0000_0010,
TheForge = 0b_0000_0100,
Amarr = 0b_0000_1000,
Dodixie = 0b_0001_0000,
Hek = 0b_0010_0000,
Rens = 0b_0100_0000,
Universe = 0b_0000_0000_0001, // A_
Jita = 0b_0000_0000_0010, // AJ
TheForge = 0b_0000_0000_0100, // _J
Amarr = 0b_0000_0000_1000, // A_
Dodixie = 0b_0000_0001_0000, // A_
Hek = 0b_0000_0010_0000, // A_
Rens = 0b_0000_0100_0000, // A_
Perimeter = 0b_0000_1000_0000, // AJ
SystemR1OGn = 0b_0001_0000_0000, // _J
NPC = 0b_0010_0000_0000 // _J
}
}
41 changes: 41 additions & 0 deletions Priceall/Appraisal/AppraisalSetting.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using System.ComponentModel;
using Priceall.Services;

namespace Priceall.Appraisal
{
/// <summary>
/// A custom setting supported by an appraisal service.
/// </summary>
/// <typeparam name="T">The type of the setting value.</typeparam>
internal class AppraisalSetting<T> : JsonSetting<T>, INotifyPropertyChanged where T : struct
{
private Action<T> _onSet;

public AppraisalSetting(JsonSetting<T> setting, Action<T> onSet = null) : base(setting)
{
_onSet = onSet;
}

public override T Value
{
get => base.Value;
set
{
// Updates backing setting, fires IPropertyChanged, calls optional action
base.Value = value;
_onSet?.Invoke(value);
OnPropertyChanged(nameof(Value));
}
}

#region Binding
public event PropertyChangedEventHandler PropertyChanged;

protected void OnPropertyChanged(string name)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}
#endregion
}
}
49 changes: 0 additions & 49 deletions Priceall/Appraisal/AppraisalSettings.cs

This file was deleted.

3 changes: 2 additions & 1 deletion Priceall/Appraisal/Services/CeveMarketAppraisalService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Priceall.Services;

namespace Priceall.Appraisal
{
Expand All @@ -15,7 +16,7 @@ public AppraisalMarket GetAvailableMarkets()
throw new System.NotImplementedException();
}

public IReadOnlyCollection<AppraisalSettings> GetCustomSettings()
public IReadOnlyCollection<JsonSetting> GetCustomSettings()
{
throw new System.NotImplementedException();
}
Expand Down
55 changes: 27 additions & 28 deletions Priceall/Appraisal/Services/EvepraisalAppraisalService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,39 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Web;
using Priceall.Services;

namespace Priceall.Appraisal
{
class EvepraisalAppraisalService : IAppraisalService
{
public const string Endpoint = "https://evepraisal.com/appraisal.json";
private const string Endpoint = "https://evepraisal.com/appraisal.json";

// private AppraisalSettings<bool> _persistSetting;

// private AppraisalSettings[] _customSettings;
private readonly UriBuilder _uriBuilder;

private AppraisalMarket _market/* = AppraisalMarket.Jita*/;
private readonly AppraisalSetting<bool> _persistSetting;

// private bool _isPersist;

private readonly UriBuilder _uriBuilder;
private readonly AppraisalSetting<AppraisalMarket> _marketSetting;

public EvepraisalAppraisalService()
{
// _persistSetting = new AppraisalSettings<bool>(
// "Persist", (isPersist) => { _isPersist = isPersist; });
// _customSettings = new AppraisalSettings[] { _persistSetting };

_uriBuilder = new UriBuilder(Endpoint);
_persistSetting =
new AppraisalSetting<bool>(
JsonSettingsService.CreateSetting("Persist", false));
_marketSetting =
new AppraisalSetting<AppraisalMarket>(
JsonSettingsService.CreateSetting("Market", AppraisalMarket.Jita));
}

private void BuildUrl()
{
var qs = HttpUtility.ParseQueryString(String.Empty);
qs["market"] = _market.ToString().ToLower();
//if (!_isPersist)
//{
// qs["persist"] = "no";
//}
qs["market"] = _marketSetting.Value.ToString().ToLower();
if (!_persistSetting.Value)
{
qs["persist"] = "no";
}
_uriBuilder.Query = qs.ToString();
}

Expand Down Expand Up @@ -77,11 +76,13 @@ private AppraisalResult ParseResponse(string response)
return new AppraisalResult(AppraisalStatus.ContentError, error.ToObject<string>());
}

AppraisalResult res = new AppraisalResult(AppraisalStatus.Successful);
res.Kind = j.SelectToken("appraisal.kind").ToObject<string>();
res.BuyValue = j.SelectToken("appraisal.totals.buy").ToObject<double>();
res.SellValue = j.SelectToken("appraisal.totals.sell").ToObject<double>();
res.Volume = j.SelectToken("appraisal.totals.volume").ToObject<double>();
var res = new AppraisalResult(AppraisalStatus.Successful)
{
Kind = j.SelectToken("appraisal.kind").ToObject<string>(),
BuyValue = j.SelectToken("appraisal.totals.buy").ToObject<double>(),
SellValue = j.SelectToken("appraisal.totals.sell").ToObject<double>(),
Volume = j.SelectToken("appraisal.totals.volume").ToObject<double>()
};
return res;
}

Expand All @@ -95,15 +96,13 @@ public AppraisalMarket GetAvailableMarkets()
| AppraisalMarket.Universe;
}

public IReadOnlyCollection<AppraisalSettings> GetCustomSettings()
{
return Array.Empty<AppraisalSettings>();
// return _customSettings;
}
public IReadOnlyCollection<JsonSetting> GetCustomSettings()
=> Array.Empty<JsonSetting>();
// => new JsonSetting[] { _persistSetting };

public void SetCurrentMarket(AppraisalMarket market)
{
_market = market;
_marketSetting.Value = market;
}
}
}
11 changes: 10 additions & 1 deletion Priceall/Appraisal/Services/IAppraisalService.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Priceall.Services;

namespace Priceall.Appraisal
{
/// <summary>
/// An online appraisal service.
/// </summary>
interface IAppraisalService
{
/// <summary>
Expand All @@ -21,8 +25,13 @@ interface IAppraisalService
/// Gets a collection of custom settings used by the appraisal service.
/// </summary>
/// <returns>A read-only collection of custom settings.</returns>
IReadOnlyCollection<AppraisalSettings> GetCustomSettings();
IReadOnlyCollection<JsonSetting> GetCustomSettings();

/// <summary>
/// Asynchronously runs an appraisal.
/// </summary>
/// <param name="content">The content to appraise.</param>
/// <returns>Appraisal result.</returns>
Task<AppraisalResult> AppraiseAsync(string content);
}
}
32 changes: 20 additions & 12 deletions Priceall/Appraisal/Services/JaniceAppraisalService.cs
Original file line number Diff line number Diff line change
@@ -1,35 +1,44 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Priceall.Http;
using Priceall.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;

namespace Priceall.Appraisal
{
class JaniceAppraisalService : IAppraisalService
{
public const string Endpoint = "https://janice.e-351.com/api/rest/v1/appraisal";
private const string Endpoint = "https://janice.e-351.com/api/rest/v1/appraisal";

private const string ApiKey = "A3lmazJdrn52ugFuVFrLd0mVqxfApYSx";

private AppraisalMarket _market;

private readonly UriBuilder _uriBuilder;

private AppraisalSetting<AppraisalMarket> _marketSetting;

public JaniceAppraisalService()
{
_uriBuilder = new UriBuilder(Endpoint);
_marketSetting = new AppraisalSetting<AppraisalMarket>(
JsonSettingsService.CreateSetting("Market", AppraisalMarket.TheForge));
}

private void BuildUrl()
{
var qs = HttpUtility.ParseQueryString(String.Empty);
qs["key"] = ApiKey;
qs["market"] = _market == AppraisalMarket.TheForge ? "1" : "2";
qs["market"] = _marketSetting.Value switch
{
AppraisalMarket.Jita => "2",
AppraisalMarket.SystemR1OGn => "3",
AppraisalMarket.Perimeter => "4",
AppraisalMarket.TheForge => "5",
AppraisalMarket.NPC => "6",
_ => throw new ArgumentOutOfRangeException()
};
qs["designation"] = "100"; // appraisal
qs["pricing"] = "200"; // split
_uriBuilder.Query = qs.ToString();
Expand Down Expand Up @@ -86,17 +95,16 @@ private AppraisalResult ParseResponse(string response)

public AppraisalMarket GetAvailableMarkets()
{
return AppraisalMarket.Jita | AppraisalMarket.TheForge;
return AppraisalMarket.Jita | AppraisalMarket.SystemR1OGn | AppraisalMarket.Perimeter |
AppraisalMarket.TheForge | AppraisalMarket.NPC;
}

public IReadOnlyCollection<AppraisalSettings> GetCustomSettings()
{
return Array.Empty<AppraisalSettings>();
}
public IReadOnlyCollection<JsonSetting> GetCustomSettings()
=> Array.Empty<JsonSetting>();

public void SetCurrentMarket(AppraisalMarket market)
{
_market = market;
_marketSetting.Value = market;
}
}
}
Loading

0 comments on commit d2b1aba

Please sign in to comment.