forked from DivverGit/Daedalus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Started restructure, too many changes to name.
- Loading branch information
Showing
28 changed files
with
541 additions
and
55 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using Daedalus.Eve.Interfaces; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace Daedalus.Eve.Bot.Behaviours | ||
{ | ||
public abstract class Behavior : IPulseable | ||
{ | ||
public abstract void Pulse(); | ||
public abstract void DoWork(); | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using Newtonsoft.Json; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace Daedalus.Eve.ESI.Data | ||
{ | ||
class ESIData | ||
{ | ||
[JsonIgnore] | ||
protected string RawJSON = string.Empty; | ||
|
||
[JsonIgnore] | ||
public static string Endpoint = string.Empty; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace Daedalus.Eve.ESI.Data | ||
{ | ||
class ESIDogmaAttribute | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace Daedalus.Eve.ESI.Data | ||
{ | ||
class ESIDogmaEffect | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Text; | ||
|
||
namespace Daedalus.Eve.ESI.Data | ||
{ | ||
class ESIEntity : ESIType | ||
{ | ||
public long Capacity { get; set; } | ||
public string Description { get; set; } | ||
public Dictionary<long, double> DogmaAttributes { get; set; } | ||
public Dictionary<long, bool> DogmaEffects { get; set; } | ||
public long GraphicId { get; set; } | ||
public long GroupId { get; set; } | ||
public long Mass { get; set; } | ||
public string Name { get; set; } | ||
public long PackagedVolume { get; set; } | ||
public long PortionSize { get; set; } | ||
public bool Published { get; set; } | ||
public long Radius { get; set; } | ||
public long TypeId { get; set; } | ||
public long Volume { get; set; } | ||
|
||
} | ||
public class MyObjectManager | ||
{ | ||
public abstract class ObjectBase | ||
{ | ||
public int myInt { get; set; } | ||
} | ||
|
||
public class Object1 : ObjectBase | ||
{ | ||
|
||
public string Object1Name { get; set; } | ||
public Object1(int myint, string object1name) | ||
{ | ||
myInt = myint; | ||
Object1Name = object1name; | ||
} | ||
} | ||
|
||
public class Object2 : ObjectBase | ||
{ | ||
public string[] Object2Array { get; set; } | ||
public Object2(int myint, string[] object2array) | ||
{ | ||
myInt = myint; | ||
Object2Array = object2array; | ||
} | ||
} | ||
|
||
public bool TryGetFieldValue<T>(object item, string fieldName, out T value) | ||
{ | ||
try | ||
{ | ||
FieldInfo fi = item.GetType().GetField(fieldName); | ||
object o = fi.GetValue(item); | ||
|
||
if (o is T) | ||
{ | ||
value = (T) o; | ||
return true; | ||
} else | ||
{ | ||
value = default; | ||
return false; | ||
} | ||
} catch (Exception e) | ||
{ | ||
value = default; | ||
return false; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace Daedalus.Eve.ESI.Data | ||
{ | ||
class ESIType : ESIData | ||
{ | ||
protected int TypeID; | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
using Daedalus.Eve.ESI.Data; | ||
using Daedalus.Resources; | ||
using Daedalus.Resources.Structures; | ||
using Newtonsoft.Json; | ||
using System; | ||
using System.Collections.Concurrent; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Net; | ||
using System.Reflection; | ||
using System.Text; | ||
using System.Threading; | ||
|
||
namespace Daedalus.Eve.ESI | ||
{ | ||
class ESICache | ||
{ | ||
private ConcurrentDictionary<Type, ConcurrentDictionary<int, ESIData>> Cache = new ConcurrentDictionary<Type, ConcurrentDictionary<int, ESIData>>(); | ||
private ConcurrentDictionary<Type, BlockingCollection<int>> FinishedRequests = new ConcurrentDictionary<Type, BlockingCollection<int>>(); | ||
|
||
public bool TryGetCachedData<T>(int identifier, out T esidata, bool fetchnow = false) where T : ESIData | ||
{ | ||
esidata = null; | ||
if (Cache.TryGetValue(typeof(T), out var endpointcache)) | ||
{ | ||
if (endpointcache.TryGetValue(identifier, out var data)) | ||
{ | ||
esidata = data as T; | ||
|
||
if (esidata == null) | ||
//error occured with laoding cached data as type | ||
|
||
return esidata != null; | ||
} | ||
} else | ||
{ | ||
if (FinishedRequests.TryGetValue(typeof(T), out var bag)) | ||
{ | ||
if (bag.Contains(identifier)) | ||
{ | ||
return false; | ||
} | ||
// failed based on previous request | ||
} else | ||
{ | ||
return false; | ||
// Failed request based on no endpoint | ||
} | ||
|
||
FinishedRequests.GetOrAdd(typeof(T), new BlockingCollection<int>()).Add(identifier); | ||
if (fetchnow) | ||
{ | ||
if (TryQueryESI<T>(identifier, out T esiJsonObject)) | ||
{ | ||
Cache.GetOrAdd(typeof(T), new ConcurrentDictionary<int, ESIData>())[identifier] = esiJsonObject; | ||
esidata = esiJsonObject; | ||
return true; | ||
} | ||
else | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
new Thread(() => | ||
{ | ||
if (TryQueryESI<T>(identifier, out T esiJsonObject)) | ||
{ | ||
Cache.GetOrAdd(typeof(T), new ConcurrentDictionary<int, ESIData>())[identifier] = esiJsonObject; | ||
} else | ||
{ | ||
// Request failed, dunno what you want to do here | ||
} | ||
}).Start(); | ||
return false; | ||
} | ||
|
||
|
||
esidata = null; | ||
return false; | ||
} | ||
|
||
private bool TryQueryESI<T>(int identifier, out T esidata) where T : ESIData | ||
{ | ||
esidata = null; | ||
if (EmbeddedJsonResourceCache.Instance.TryGetResource<ESIEndpoints>("ESIEndpints.json", out ESIEndpoints endpoints)) | ||
{ | ||
if (endpoints.Endpoints.TryGetValue(typeof(T).Name, out string endpoint)) | ||
{ | ||
using (WebClient wc = new WebClient()) | ||
{ | ||
string url = string.Format(endpoint, identifier); | ||
try | ||
{ | ||
string json = wc.DownloadString(url); | ||
esidata = JsonConvert.DeserializeObject<T>(json); | ||
return true; | ||
} | ||
catch (Exception e) | ||
{ | ||
return false; | ||
} | ||
} | ||
} | ||
else | ||
{ | ||
return false; | ||
// Error finding endpoint | ||
} | ||
} | ||
else | ||
{ | ||
return false; | ||
// Error getting resource, we fucked up | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace Daedalus.Eve.Interfaces | ||
{ | ||
public interface IPulseable | ||
{ | ||
void Pulse(); | ||
} | ||
} |
Oops, something went wrong.