Skip to content

Commit

Permalink
local scan updates
Browse files Browse the repository at this point in the history
  • Loading branch information
BitBaboonSteve committed Oct 12, 2022
1 parent 0aa88a3 commit d39520a
Showing 1 changed file with 145 additions and 75 deletions.
220 changes: 145 additions & 75 deletions SMT/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Net.Http;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
Expand Down Expand Up @@ -39,6 +40,10 @@ public partial class MainWindow : Window

private List<InfoItem> InfoLayer;

private Dictionary<string, long> CharacterNameIDCache;
private Dictionary<long, string> CharacterIDNameCache;


public JumpRoute CapitalRoute { get; set; }

/// <summary>
Expand All @@ -53,6 +58,9 @@ public MainWindow()
Uri woopUri = new Uri(AppDomain.CurrentDomain.BaseDirectory + @"\Sounds\woop.mp3");
mediaPlayer.Open(woopUri);

CharacterNameIDCache = new Dictionary<string, long>();
CharacterIDNameCache = new Dictionary<long, string>();

InitializeComponent();

Title = "SMT (a new step : " + SMT_VERSION + ")";
Expand Down Expand Up @@ -1867,45 +1875,45 @@ private void JumpPlannerJDC_OnSelectionChanged(object sender, SelectionChangedEv

private void CurrentCapitalRouteItem_Selected(object sender, RoutedEventArgs e)
{
if(dgCapitalRouteCurrentRoute.SelectedItem != null)
if (dgCapitalRouteCurrentRoute.SelectedItem != null)
{
Navigation.RoutePoint rp = dgCapitalRouteCurrentRoute.SelectedItem as Navigation.RoutePoint;
string sel = rp.SystemName;

UniverseUC.ShowSystem(sel);

lblAlternateMids.Content = sel;
if(CapitalRoute.AlternateMids.ContainsKey(sel))
if (CapitalRoute.AlternateMids.ContainsKey(sel))
{
lbAlternateMids.ItemsSource = CapitalRoute.AlternateMids[sel];
}
else
{
lbAlternateMids.ItemsSource = null;
}

}

}

private void CapitalWaypointsContextMenuMoveUp_Click(object sender, RoutedEventArgs e)
{
if(capitalRouteWaypointsLB.SelectedItem != null && capitalRouteWaypointsLB.SelectedIndex != 0)
if (capitalRouteWaypointsLB.SelectedItem != null && capitalRouteWaypointsLB.SelectedIndex != 0)
{
CapitalRoute.WayPoints.Move(capitalRouteWaypointsLB.SelectedIndex, capitalRouteWaypointsLB.SelectedIndex - 1);
CapitalRoute.Recalculate();
}

}

private void CapitalWaypointsContextMenuMoveDown_Click(object sender, RoutedEventArgs e)
{
if (capitalRouteWaypointsLB.SelectedItem != null && capitalRouteWaypointsLB.SelectedIndex != CapitalRoute.WayPoints.Count -1 )
if (capitalRouteWaypointsLB.SelectedItem != null && capitalRouteWaypointsLB.SelectedIndex != CapitalRoute.WayPoints.Count - 1)
{
CapitalRoute.WayPoints.Move(capitalRouteWaypointsLB.SelectedIndex, capitalRouteWaypointsLB.SelectedIndex + 1);
CapitalRoute.Recalculate();
}

}

private void CapitalWaypointsContextMenuDelete_Click(object sender, RoutedEventArgs e)
Expand All @@ -1925,13 +1933,13 @@ private void CapitalRouteContextMenuUseAlt_Click(object sender, RoutedEventArgs

// need to find where to insert the new waypoint
int waypointIndex = -1;
foreach(Navigation.RoutePoint rp in CapitalRoute.CurrentRoute)
foreach (Navigation.RoutePoint rp in CapitalRoute.CurrentRoute)
{
if(rp.SystemName == CapitalRoute.WayPoints[waypointIndex +1])
if (rp.SystemName == CapitalRoute.WayPoints[waypointIndex + 1])
{
waypointIndex++;
}
if(CapitalRoute.AlternateMids.ContainsKey(rp.SystemName))
if (CapitalRoute.AlternateMids.ContainsKey(rp.SystemName))
{
foreach (string alt in CapitalRoute.AlternateMids[rp.SystemName])
{
Expand Down Expand Up @@ -1971,112 +1979,172 @@ private async void localScanInput_TextChanged(object sender, TextChangedEventArg
{
// look up every character
string[] characterNameArray = localScanInput.Text.Split("\n", StringSplitOptions.RemoveEmptyEntries); ;
//list<string> results = new List<string>();

int count = -1;
bool done = false;
int textCount = 0;

List<string> currentBatch = new List<string>();
List<ESI.NET.Models.Universe.ResolvedInfo> parseResults = new List<ESI.NET.Models.Universe.ResolvedInfo>();

while (!done)
//list<string> results = new List<string>();
await Task.Run(async () =>
{
if(count+1 < characterNameArray.Length)
{
if(textCount + characterNameArray[count+1].Length < 100)
{
textCount += characterNameArray[count + 1].Length;
currentBatch.Add(characterNameArray[count + 1]);
count++;
}
else
int count = -1;
bool done = false;
int textCount = 0;

List<string> currentBatch = new List<string>();

List<Task<ESI.NET.EsiResponse<ESI.NET.Models.Universe.IDLookup>>> OpenRequests = new List<Task<ESI.NET.EsiResponse<ESI.NET.Models.Universe.IDLookup>>>();


while (!done)
{
if(currentBatch.Count == 0)
// if(CharacterNameIDCache.ContainsKey(characterNameArray[count + 1]))
// {
// count++;
// continue;
// }

if (count + 1 < characterNameArray.Length)
{
// error
return;
if (textCount + characterNameArray[count + 1].Length < 100)
{
textCount += characterNameArray[count + 1].Length;
currentBatch.Add(characterNameArray[count + 1]);
count++;
}
else
{
if (currentBatch.Count == 0)
{
// error
return;
}

OpenRequests.Add(EVEManager.ESIClient.Universe.IDs(currentBatch));
currentBatch.Clear();
textCount = 0;
}
}
ESI.NET.EsiResponse<ESI.NET.Models.Universe.IDLookup> esra = await EVEManager.ESIClient.Universe.IDs(currentBatch);
foreach (ESI.NET.Models.Universe.ResolvedInfo i in esra.Data.Characters)
else
{
parseResults.Add(i);
if (currentBatch.Count > 0)
{
OpenRequests.Add(EVEManager.ESIClient.Universe.IDs(currentBatch));
}
done = true;
}
currentBatch.Clear();
textCount = 0;

}
}
else
{
if(currentBatch.Count > 0)

Task.WaitAll(OpenRequests.ToArray());

foreach (Task<ESI.NET.EsiResponse<ESI.NET.Models.Universe.IDLookup>> t in OpenRequests)
{
ESI.NET.EsiResponse<ESI.NET.Models.Universe.IDLookup> esra = await EVEManager.ESIClient.Universe.IDs(currentBatch);
foreach (ESI.NET.Models.Universe.ResolvedInfo i in esra.Data.Characters)
if (t.Result.Data != null)
{
parseResults.Add(i);
if (t.Result.Data.Characters != null)
{
foreach (ESI.NET.Models.Universe.ResolvedInfo ri in t.Result.Data.Characters)
{
CharacterIDNameCache[ri.Id] = ri.Name;
CharacterNameIDCache[ri.Name] = ri.Id;
parseResults.Add(ri);
}
}
}
}
done = true;




}

}
);


foreach (ESI.NET.Models.Universe.ResolvedInfo i in parseResults)
{
LocalScanCharacterInfo lcsi = new LocalScanCharacterInfo();
lcsi.Name = i.Name;
lcsi.ID = i.Id;
lcsi.AllianceID = 0;
// now get the esi info for every characcter

// now get the public character info
ESI.NET.EsiResponse<ESI.NET.Models.Character.Information> esra = await EVEManager.ESIClient.Character.Information(i.Id);
List<Task<ESI.NET.EsiResponse<ESI.NET.Models.Character.Information>>> charRequests = new List<Task<ESI.NET.EsiResponse<ESI.NET.Models.Character.Information>>>();
List<Task<string>> zkillRequests = new List<Task<string>>();

if(esra.Data != null)
{
lcsi.AllianceID = esra.Data.AllianceId;
}
List<KeyValuePair<Task<string>, Task<ESI.NET.EsiResponse<ESI.NET.Models.Character.Information>>>> requestPairs = new List<KeyValuePair<Task<string>, Task<ESI.NET.EsiResponse<ESI.NET.Models.Character.Information>>>>();

string url = @"https://zkillboard.com/api/stats/characterID/" + i.Id.ToString() + "/";
string strContent = string.Empty;
string dangerRating = "???";
try
await Task.Run(async () =>
{
foreach (ESI.NET.Models.Universe.ResolvedInfo i in parseResults)
{
HttpClient hc = new HttpClient();
hc.DefaultRequestHeaders.UserAgent.Add(new System.Net.Http.Headers.ProductInfoHeaderValue("SMT", SMT_VERSION));
var response = await hc.GetAsync(url);
response.EnsureSuccessStatusCode();
strContent = await response.Content.ReadAsStringAsync();
Task<string> zkr = null;
Task<ESI.NET.EsiResponse<ESI.NET.Models.Character.Information>> esr;


// now get the public character info
esr = EVEManager.ESIClient.Character.Information(i.Id);
charRequests.Add(esr);

string url = @"https://zkillboard.com/api/stats/characterID/" + i.Id.ToString() + "/";
try
{
HttpClient hc = new HttpClient();
hc.DefaultRequestHeaders.UserAgent.Add(new System.Net.Http.Headers.ProductInfoHeaderValue("SMT", SMT_VERSION));
var response = await hc.GetAsync(url);
response.EnsureSuccessStatusCode();
zkr = response.Content.ReadAsStringAsync();
zkillRequests.Add(zkr);

Thread.Sleep(50);
}
catch
{

}
requestPairs.Add(new KeyValuePair<Task<string>, Task<ESI.NET.EsiResponse<ESI.NET.Models.Character.Information>>>(zkr, esr));
}
catch


}
);

Task.WaitAll(charRequests.ToArray());
Task.WaitAll(zkillRequests.ToArray());

foreach(KeyValuePair<Task<string>, Task<ESI.NET.EsiResponse<ESI.NET.Models.Character.Information>>> kvp in requestPairs)
{
LocalScanCharacterInfo lcsi = new LocalScanCharacterInfo();
if(kvp.Value.Result == null || kvp.Value.Result.Data == null)
{
;
continue;
}

if(!string.IsNullOrEmpty(strContent))
lcsi.Name = kvp.Value.Result.Data.Name;
lcsi.ID = CharacterNameIDCache[kvp.Value.Result.Data.Name];
lcsi.AllianceID = 0;

string strContent = kvp.Key.Result;
string dangerRating = "???";

if (!string.IsNullOrEmpty(strContent))
{
try
{
JObject zkillInfo = JObject.Parse(strContent);
if(zkillInfo != null)
if (zkillInfo != null)
{
if(zkillInfo["dangerRatio"] != null)
if (zkillInfo["dangerRatio"] != null)
{
dangerRating = zkillInfo["dangerRatio"].ToString();
}
}

}
catch
catch
{

}

}
lcsi.dangerRating = dangerRating;
if(ActiveCharacter != null && ActiveCharacter.ESILinked)

if (ActiveCharacter != null && ActiveCharacter.ESILinked)
{
if(ActiveCharacter.Standings.ContainsKey(lcsi.AllianceID))
if (ActiveCharacter.Standings.ContainsKey(lcsi.AllianceID) && lcsi.AllianceID != ActiveCharacter.AllianceID)
{
if (ActiveCharacter.Standings[lcsi.AllianceID] <= 0)
{
Expand All @@ -2090,9 +2158,11 @@ private async void localScanInput_TextChanged(object sender, TextChangedEventArg
}

}

}




private void btnClearLocal_Click(object sender, RoutedEventArgs e)
{
localScanResults.Items.Clear();
Expand Down

0 comments on commit d39520a

Please sign in to comment.