Blueprint loading works
This commit is contained in:
10
EveCalc.Shared/AssemblyInfo.cs
Normal file
10
EveCalc.Shared/AssemblyInfo.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using System.Windows;
|
||||
|
||||
[assembly: ThemeInfo(
|
||||
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
|
||||
//(used if a resource is not found in the page,
|
||||
// or application resource dictionaries)
|
||||
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
|
||||
//(used if a resource is not found in the page,
|
||||
// app, or any theme specific resource dictionaries)
|
||||
)]
|
||||
19
EveCalc.Shared/Enums.cs
Normal file
19
EveCalc.Shared/Enums.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace EveCalc.Shared
|
||||
{
|
||||
public enum Materials
|
||||
{
|
||||
Tritanium = 34,
|
||||
Pyerite = 35,
|
||||
Mexallon = 36,
|
||||
Isogen = 37,
|
||||
Nocxium = 38,
|
||||
Zydrine = 39,
|
||||
Megacyte = 40
|
||||
}
|
||||
}
|
||||
25
EveCalc.Shared/EveCalc.Shared.csproj
Normal file
25
EveCalc.Shared/EveCalc.Shared.csproj
Normal file
@@ -0,0 +1,25 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Library</OutputType>
|
||||
<TargetFramework>net5.0-windows</TargetFramework>
|
||||
<UseWPF>true</UseWPF>
|
||||
<StartupObject></StartupObject>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="ESI.NET" Version="2020.12.8" />
|
||||
<PackageReference Include="Microsoft.Data.Sqlite" Version="5.0.2" />
|
||||
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.705.50" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Remove="C:\Users\Dani\.nuget\packages\microsoft.web.webview2\1.0.705.50\build\\..\runtimes\win-arm\native\WebView2Loader.dll" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Remove="C:\Users\Dani\.nuget\packages\microsoft.web.webview2\1.0.705.50\build\\..\runtimes\win-x64\native\WebView2Loader.dll" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
201
EveCalc.Shared/Logic/EsiClientWrapper.cs
Normal file
201
EveCalc.Shared/Logic/EsiClientWrapper.cs
Normal file
@@ -0,0 +1,201 @@
|
||||
using ESI.NET;
|
||||
using ESI.NET.Enumerations;
|
||||
using ESI.NET.Models.SSO;
|
||||
using EveCalc.Shared.ObjectModel;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace EveCalc.Shared.Logic
|
||||
{
|
||||
public partial class EsiClientWrapper
|
||||
{
|
||||
private readonly EsiClient client;
|
||||
private AuthorizedCharacterData charData;
|
||||
private string loginState = "guguseli123";
|
||||
|
||||
public EsiClientWrapper()
|
||||
{
|
||||
IOptions<EsiConfig> config = Options.Create(new EsiConfig()
|
||||
{
|
||||
EsiUrl = "https://esi.evetech.net/",
|
||||
DataSource = DataSource.Tranquility,
|
||||
ClientId = "f6892ca208364df1b0b8984773e16a2f",
|
||||
SecretKey = "u5SqGF6ZkEdvjLBRn5rzU1Lz3oaFcpsGDX8Ki6Jn",
|
||||
CallbackUrl = "https://localhost/evecalc",
|
||||
UserAgent = "EveCalc.Test",
|
||||
AuthVersion = AuthVersion.v2
|
||||
});
|
||||
|
||||
this.client = new EsiClient(config);
|
||||
|
||||
// Init existsing token
|
||||
if (File.Exists("token.json"))
|
||||
{
|
||||
var json = File.ReadAllText("token.json");
|
||||
this.charData = JsonConvert.DeserializeObject<AuthorizedCharacterData>(json);
|
||||
this.client.SetCharacterData(this.charData);
|
||||
if (this.charData.ExpiresOn.AddHours(1) < DateTime.Now)
|
||||
{
|
||||
this.RefreshToken();
|
||||
}
|
||||
}
|
||||
|
||||
// Init cache
|
||||
this.LoadNameCache();
|
||||
}
|
||||
|
||||
public string GetLoginUrl()
|
||||
{
|
||||
var scopes = new List<string>
|
||||
{
|
||||
"publicData",
|
||||
//"esi-calendar.respond_calendar_events.v1",
|
||||
//"esi-calendar.read_calendar_events.v1",
|
||||
//"esi-location.read_location.v1",
|
||||
//"esi-location.read_ship_type.v1",
|
||||
//"esi-mail.organize_mail.v1",
|
||||
//"esi-mail.read_mail.v1",
|
||||
//"esi-mail.send_mail.v1",
|
||||
//"esi-skills.read_skills.v1",
|
||||
//"esi-skills.read_skillqueue.v1",
|
||||
"esi-wallet.read_character_wallet.v1",
|
||||
"esi-wallet.read_corporation_wallet.v1",
|
||||
//"esi-search.search_structures.v1",
|
||||
//"esi-clones.read_clones.v1",
|
||||
//"esi-characters.read_contacts.v1",
|
||||
"esi-universe.read_structures.v1",
|
||||
//"esi-bookmarks.read_character_bookmarks.v1",
|
||||
//"esi-killmails.read_killmails.v1",
|
||||
"esi-corporations.read_corporation_membership.v1",
|
||||
"esi-assets.read_assets.v1",
|
||||
//"esi-planets.manage_planets.v1",
|
||||
//"esi-fleets.read_fleet.v1",
|
||||
//"esi-fleets.write_fleet.v1",
|
||||
//"esi-ui.open_window.v1",
|
||||
//"esi-ui.write_waypoint.v1",
|
||||
//"esi-characters.write_contacts.v1",
|
||||
//"esi-fittings.read_fittings.v1",
|
||||
//"esi-fittings.write_fittings.v1",
|
||||
"esi-markets.structure_markets.v1",
|
||||
"esi-corporations.read_structures.v1",
|
||||
//"esi-characters.read_loyalty.v1",
|
||||
//"esi-characters.read_opportunities.v1",
|
||||
//"esi-characters.read_chat_channels.v1",
|
||||
//"esi-characters.read_medals.v1",
|
||||
//"esi-characters.read_standings.v1",
|
||||
//"esi-characters.read_agents_research.v1",
|
||||
//"esi-industry.read_character_jobs.v1",
|
||||
"esi-markets.read_character_orders.v1",
|
||||
"esi-characters.read_blueprints.v1",
|
||||
//"esi-characters.read_corporation_roles.v1",
|
||||
//"esi-location.read_online.v1",
|
||||
//"esi-contracts.read_character_contracts.v1",
|
||||
//"esi-clones.read_implants.v1",
|
||||
//"esi-characters.read_fatigue.v1",
|
||||
//"esi-killmails.read_corporation_killmails.v1",
|
||||
//"esi-corporations.track_members.v1",
|
||||
"esi-wallet.read_corporation_wallets.v1",
|
||||
//"esi-characters.read_notifications.v1",
|
||||
//"esi-corporations.read_divisions.v1",
|
||||
//"esi-corporations.read_contacts.v1",
|
||||
"esi-assets.read_corporation_assets.v1",
|
||||
//"esi-corporations.read_titles.v1",
|
||||
"esi-corporations.read_blueprints.v1",
|
||||
//"esi-bookmarks.read_corporation_bookmarks.v1",
|
||||
//"esi-contracts.read_corporation_contracts.v1",
|
||||
//"esi-corporations.read_standings.v1",
|
||||
//"esi-corporations.read_starbases.v1",
|
||||
//"esi-industry.read_corporation_jobs.v1",
|
||||
"esi-markets.read_corporation_orders.v1",
|
||||
//"esi-corporations.read_container_logs.v1",
|
||||
//"esi-industry.read_character_mining.v1",
|
||||
//"esi-industry.read_corporation_mining.v1",
|
||||
//"esi-planets.read_customs_offices.v1",
|
||||
//"esi-corporations.read_facilities.v1",
|
||||
//"esi-corporations.read_medals.v1",
|
||||
//"esi-characters.read_titles.v1",
|
||||
//"esi-alliances.read_contacts.v1",
|
||||
//"esi-characters.read_fw_stats.v1",
|
||||
//"esi-corporations.read_fw_stats.v1",
|
||||
//"esi-characterstats.read.v1"
|
||||
};
|
||||
return client.SSO.CreateAuthenticationUrl(scopes, this.loginState);
|
||||
}
|
||||
|
||||
public async void SetAuthCode(string code)
|
||||
{
|
||||
SsoToken token = await this.client.SSO.GetToken(GrantType.AuthorizationCode, code);
|
||||
this.charData = await client.SSO.Verify(token);
|
||||
this.client.SetCharacterData(this.charData);
|
||||
|
||||
var json = JsonConvert.SerializeObject(this.charData);
|
||||
File.WriteAllText("token.json", json);
|
||||
}
|
||||
|
||||
public async void RefreshToken()
|
||||
{
|
||||
var token = await this.client.SSO.GetToken(GrantType.RefreshToken, this.charData.RefreshToken);
|
||||
this.charData = await client.SSO.Verify(token);
|
||||
this.client.SetCharacterData(this.charData);
|
||||
}
|
||||
|
||||
public async void Test()
|
||||
{
|
||||
var response = await client.Universe.Names(new List<long>()
|
||||
{
|
||||
1590304510,
|
||||
99006319,
|
||||
20000006
|
||||
});
|
||||
}
|
||||
|
||||
public async Task<List<Blueprint>> GetCorpBlueprints()
|
||||
{
|
||||
var response = await this.client.Corporation.Blueprints();
|
||||
|
||||
var result = new List<Blueprint>();
|
||||
foreach (var blueprint in response.Data)
|
||||
{
|
||||
var blueprint2 = new Blueprint(blueprint);
|
||||
blueprint2.TypeName = await this.GetFromNameCache(blueprint2.TypeId);
|
||||
result.Add(blueprint2);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<object> GetCorpMats()
|
||||
{
|
||||
var response = await this.client.Assets.ForCorporation();
|
||||
|
||||
//var result = new List<Blueprint>();
|
||||
//foreach (var blueprint in response.Data)
|
||||
//{
|
||||
// var blueprint2 = new Blueprint(blueprint);
|
||||
// blueprint2.TypeName = await this.GetFromNameCache(blueprint2.TypeId);
|
||||
// result.Add(blueprint2);
|
||||
//}
|
||||
|
||||
return response.Data;
|
||||
}
|
||||
|
||||
public async Task<Dictionary<long, string>> Search(string query)
|
||||
{
|
||||
var response = await this.client.Search.Query(SearchType.Public, query, SearchCategory.InventoryType);
|
||||
var result = new Dictionary<long, string>();
|
||||
|
||||
foreach (var data in response.Data.InventoryTypes)
|
||||
{
|
||||
var name = await this.GetFromNameCache(data);
|
||||
result.Add(data, name);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
67
EveCalc.Shared/Logic/NameCache.cs
Normal file
67
EveCalc.Shared/Logic/NameCache.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace EveCalc.Shared.Logic
|
||||
{
|
||||
public partial class EsiClientWrapper
|
||||
{
|
||||
private static string nameCacheFileName = "namecache.json";
|
||||
private Dictionary<long, string> nameCache = new Dictionary<long, string>();
|
||||
|
||||
public void LoadNameCache()
|
||||
{
|
||||
if (File.Exists(nameCacheFileName))
|
||||
{
|
||||
var json = File.ReadAllText(nameCacheFileName);
|
||||
this.nameCache = JsonConvert.DeserializeObject<Dictionary<long, string>>(json);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddToNameCache(long id, string name)
|
||||
{
|
||||
if (this.nameCache.ContainsKey(id))
|
||||
{
|
||||
if (this.nameCache[id] != name)
|
||||
{
|
||||
this.nameCache[id] = name;
|
||||
this.SaveCache();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.nameCache.Add(id, name);
|
||||
this.SaveCache();
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<string> GetFromNameCache(long id)
|
||||
{
|
||||
if (this.nameCache.ContainsKey(id))
|
||||
{
|
||||
return this.nameCache[id];
|
||||
}
|
||||
|
||||
// Get from api
|
||||
var response2 = await client.Universe.Names(new List<long> { id });
|
||||
if (response2.Data != null && response2.Data.Count > 0)
|
||||
{
|
||||
var name = response2.Data[0].Name;
|
||||
this.AddToNameCache(id, name);
|
||||
return name;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private void SaveCache()
|
||||
{
|
||||
var json = JsonConvert.SerializeObject(this.nameCache);
|
||||
File.WriteAllText(nameCacheFileName, json);
|
||||
}
|
||||
}
|
||||
}
|
||||
25
EveCalc.Shared/ObjectModel/Blueprint.cs
Normal file
25
EveCalc.Shared/ObjectModel/Blueprint.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace EveCalc.Shared.ObjectModel
|
||||
{
|
||||
public class Blueprint : ESI.NET.Models.Corporation.Blueprint
|
||||
{
|
||||
public string TypeName { get; set; }
|
||||
|
||||
public Blueprint(ESI.NET.Models.Corporation.Blueprint blueprint) : base()
|
||||
{
|
||||
this.ItemId = blueprint.ItemId;
|
||||
this.LocationFlag = blueprint.LocationFlag;
|
||||
this.LocationId = blueprint.LocationId;
|
||||
this.MaterialEfficiency = blueprint.MaterialEfficiency;
|
||||
this.Quantity = blueprint.Quantity;
|
||||
this.Runs = blueprint.Runs;
|
||||
this.TimeEfficiency = blueprint.TimeEfficiency;
|
||||
this.TypeId = blueprint.TypeId;
|
||||
}
|
||||
}
|
||||
}
|
||||
17
EveCalc.Shared/ObjectModel/BlueprintMaterial.cs
Normal file
17
EveCalc.Shared/ObjectModel/BlueprintMaterial.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace EveCalc.Shared.ObjectModel
|
||||
{
|
||||
public class BlueprintMaterial
|
||||
{
|
||||
public long MaterialTypeId { get; set; }
|
||||
|
||||
public string MaterialTypeName { get; set; }
|
||||
|
||||
public long Quantity { get; set; }
|
||||
}
|
||||
}
|
||||
51
EveCalc.Shared/StaticData/StaticDataProvider.cs
Normal file
51
EveCalc.Shared/StaticData/StaticDataProvider.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using EveCalc.Shared.ObjectModel;
|
||||
using Microsoft.Data.Sqlite;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace EveCalc.Shared.StaticData
|
||||
{
|
||||
public class StaticDataProvider
|
||||
{
|
||||
public StaticDataProvider()
|
||||
{
|
||||
}
|
||||
public List<BlueprintMaterial> GetMaterialsForBlueprint(long id)
|
||||
{
|
||||
var result = new List<BlueprintMaterial>();
|
||||
|
||||
using (var connection = new SqliteConnection("Data Source=StaticData\\staticdata.sqlite"))
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
var command = connection.CreateCommand();
|
||||
command.CommandText = @"select materialTypeID, invTypes.typename, quantity "
|
||||
+ "from industryActivityMaterials "
|
||||
+ "inner join invTypes on invTypes.typeID=industryActivityMaterials.materialTypeID "
|
||||
+ "where blueprintTypeID=$id";
|
||||
command.Parameters.AddWithValue("id", id);
|
||||
|
||||
using (var reader = command.ExecuteReader())
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
var material = new BlueprintMaterial();
|
||||
material.MaterialTypeId = reader.GetInt64(0);
|
||||
material.MaterialTypeName = reader.GetString(1);
|
||||
material.Quantity = reader.GetInt64(2);
|
||||
result.Add(material);
|
||||
}
|
||||
}
|
||||
|
||||
connection.Close();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
BIN
EveCalc.Shared/StaticData/staticdata.sqlite
Normal file
BIN
EveCalc.Shared/StaticData/staticdata.sqlite
Normal file
Binary file not shown.
18
EveCalc.Shared/Views/BrowserView.xaml
Normal file
18
EveCalc.Shared/Views/BrowserView.xaml
Normal file
@@ -0,0 +1,18 @@
|
||||
<Window
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:wpf="clr-namespace:Microsoft.Web.WebView2.Wpf;assembly=Microsoft.Web.WebView2.Wpf"
|
||||
x:Class="EveCalc.Shared.Views.BrowserView"
|
||||
mc:Ignorable="d"
|
||||
Title="BrowserView" Height="450" Width="800">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
<TextBox x:Name="TxtUrl" Grid.Row="0" Height="25"/>
|
||||
<wpf:WebView2 x:Name="WbrBrowser" Grid.Row="1" NavigationStarting="WbrBrowser_NavigationStarting"/>
|
||||
|
||||
</Grid>
|
||||
</Window>
|
||||
48
EveCalc.Shared/Views/BrowserView.xaml.cs
Normal file
48
EveCalc.Shared/Views/BrowserView.xaml.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace EveCalc.Shared.Views
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for BrowserView.xaml
|
||||
/// </summary>
|
||||
public partial class BrowserView : Window
|
||||
{
|
||||
public string AuthCode { get; private set; }
|
||||
public BrowserView()
|
||||
{
|
||||
this.InitializeComponent();
|
||||
//this.WbrBrowser.EnsureCoreWebView2Async().Wait();
|
||||
}
|
||||
|
||||
public BrowserView(string url) : this()
|
||||
{
|
||||
this.WbrBrowser.Source = new Uri(url);
|
||||
}
|
||||
|
||||
private void WbrBrowser_NavigationStarting(object sender, Microsoft.Web.WebView2.Core.CoreWebView2NavigationStartingEventArgs e)
|
||||
{
|
||||
this.TxtUrl.Text = e.Uri.ToString();
|
||||
|
||||
if (this.TxtUrl.Text.StartsWith("https://localhost/evecalc?code="))
|
||||
{
|
||||
// Habemus login
|
||||
var split = this.TxtUrl.Text.Split(new[] { "code=", "&state=" }, StringSplitOptions.None);
|
||||
this.AuthCode = split[1];
|
||||
this.DialogResult = true;
|
||||
this.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user