Skip to content

Commit

Permalink
Started restructure, too many changes to name.
Browse files Browse the repository at this point in the history
  • Loading branch information
CryoMyst committed Oct 10, 2019
1 parent e2e551d commit dd257b7
Show file tree
Hide file tree
Showing 28 changed files with 541 additions and 55 deletions.
Binary file added DLLs/ISXEVEWrapper.dll
Binary file not shown.
Binary file added DLLs/Lavish.InnerSpace.dll
Binary file not shown.
49 changes: 30 additions & 19 deletions Daedalus.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,10 @@
<HintPath>packages\Costura.Fody.4.1.0\lib\net40\Costura.dll</HintPath>
</Reference>
<Reference Include="ISXEVEWrapper">
<HintPath>..\..\..\..\..\Program Files (x86)\InnerSpace\.NET Programs\ISXEVEWrapper.dll</HintPath>
<HintPath>DLLs\ISXEVEWrapper.dll</HintPath>
</Reference>
<Reference Include="Lavish.InnerSpace, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9029a3ab4cbe108d, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\Program Files (x86)\InnerSpace\Lavish.InnerSpace.dll</HintPath>
</Reference>
<Reference Include="Lavish.LavishVMRuntime, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9029a3ab4cbe108d, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\Program Files (x86)\InnerSpace\Lavish.LavishVMRuntime.dll</HintPath>
<Reference Include="Lavish.InnerSpace">
<HintPath>DLLs\Lavish.InnerSpace.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>packages\Newtonsoft.Json.12.0.2\lib\net40\Newtonsoft.Json.dll</HintPath>
Expand All @@ -83,16 +78,21 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Behaviours\b_Combat.cs" />
<Compile Include="Behaviours\b_Space.cs" />
<Compile Include="Behaviours\b_Station.cs" />
<Compile Include="Controllers\c_Modules.cs" />
<Compile Include="Daedalus.cs" />
<Content Include="Data\Cache.csv">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Compile Include="Data\d_ESI.cs" />
<Compile Include="Data\d_Weapon_Groups.cs" />
<Compile Include="Eve\Bot\Behaviours\Behavior.cs" />
<Compile Include="Eve\Bot\Behaviours\b_Combat.cs" />
<Compile Include="Eve\Bot\Behaviours\b_Space.cs" />
<Compile Include="Eve\Bot\Behaviours\b_Station.cs" />
<Compile Include="Eve\ESI\Data\ESIData.cs" />
<Compile Include="Eve\ESI\Data\ESIDogmaAttribute.cs" />
<Compile Include="Eve\ESI\Data\ESIDogmaEffect.cs" />
<Compile Include="Eve\ESI\Data\ESIEntity.cs" />
<Compile Include="Eve\ESI\Data\ESIType.cs" />
<Compile Include="Eve\ESI\ESICache.cs" />
<Compile Include="Eve\Interfaces\IPulseable.cs" />
<Compile Include="Eve\Wrappers\DEntity.cs" />
<Compile Include="Eve\Wrappers\DEve.cs" />
<Compile Include="Functions\f_Bookmarks.cs" />
<Compile Include="Functions\f_Drones.cs" />
<Compile Include="Functions\f_Entities.cs" />
Expand All @@ -105,6 +105,12 @@
<Compile Include="Controllers\c_Routines.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Resources\Data\d_ESI.cs" />
<Compile Include="Resources\Data\d_Weapon_Groups.cs" />
<Compile Include="Resources\EmbeddedJsonResourceCache.cs" />
<Compile Include="Resources\FileJsonResourceCache.cs" />
<Compile Include="Resources\Structures\ESIEndpoints.cs" />
<Compile Include="Resources\Structures\JsonResource.cs" />
<Compile Include="Routines\r_Combat_Active.cs" />
<Compile Include="Routines\r_Combat_Idle.cs" />
<Compile Include="Routines\r_Space_Warp.cs" />
Expand All @@ -130,7 +136,6 @@
<DependentUpon>UI.cs</DependentUpon>
</EmbeddedResource>
<None Include="app.config" />
<None Include="Data\dgmTypeAttributes.csv" />
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
Expand All @@ -141,6 +146,11 @@
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<None Include="README.md" />
<None Include="Resources\Data\Cache.csv" />
<None Include="Resources\Data\dgmTypeAttributes.csv" />
<None Include="Resources\Data\dgmTypeEffects.csv" />
<None Include="Resources\Data\ESIEndpoints.json" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
Expand All @@ -150,10 +160,11 @@
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Data\Weapon_Groups.xml" />
<Content Include="FodyWeavers.xml" />
<Content Include="Resources\Data\Weapon_Groups.xml" />
</ItemGroup>
<ItemGroup>
<None Include="Data\dgmTypeEffects.csv" />
<Folder Include="Eve\Bot\Controllers\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="packages\Fody.6.0.0\build\Fody.targets" Condition="Exists('packages\Fody.6.0.0\build\Fody.targets')" />
Expand Down
14 changes: 14 additions & 0 deletions Eve/Bot/Behaviours/Behavior.cs
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.
17 changes: 17 additions & 0 deletions Eve/ESI/Data/ESIData.cs
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;
}
}
11 changes: 11 additions & 0 deletions Eve/ESI/Data/ESIDogmaAttribute.cs
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
{
}
}
11 changes: 11 additions & 0 deletions Eve/ESI/Data/ESIDogmaEffect.cs
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
{
}
}
78 changes: 78 additions & 0 deletions Eve/ESI/Data/ESIEntity.cs
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;
}
}
}
}
13 changes: 13 additions & 0 deletions Eve/ESI/Data/ESIType.cs
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;

}
}
118 changes: 118 additions & 0 deletions Eve/ESI/ESICache.cs
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
}
}
}
}
12 changes: 12 additions & 0 deletions Eve/Interfaces/IPulseable.cs
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();
}
}
Loading

0 comments on commit dd257b7

Please sign in to comment.