Skip to content
8 changes: 5 additions & 3 deletions src/MalikP. IVAO Library/MalikP. IVAO Library.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MalikP.IVAO.Library.App", "
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MalikP.IVAO.Library", "MalikP.IVAO.Library\MalikP.IVAO.Library.csproj", "{95BCECFF-D358-4FD8-BC81-3DF6C04DC8A2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MalikP.IVAO.Library.Test", "MalikP.IVAO.Library.Test\MalikP.IVAO.Library.Test.csproj", "{6939AC5E-4B9B-40B3-8044-437D0E20102F}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MalikP.IVAO.Library.Test", "MalikP.IVAO.Library.Test\MalikP.IVAO.Library.Test.csproj", "{6939AC5E-4B9B-40B3-8044-437D0E20102F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MalikP.IVAO.Library.IoC", "MalikP.IVAO.Library.IoC\MalikP.IVAO.Library.IoC.csproj", "{35EADA32-399B-4DB5-BBAD-773603F127A9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -16,9 +18,7 @@ Global
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{DB2048CA-9DAA-4CFF-8840-481086CEDF70}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DB2048CA-9DAA-4CFF-8840-481086CEDF70}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DB2048CA-9DAA-4CFF-8840-481086CEDF70}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DB2048CA-9DAA-4CFF-8840-481086CEDF70}.Release|Any CPU.Build.0 = Release|Any CPU
{95BCECFF-D358-4FD8-BC81-3DF6C04DC8A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{95BCECFF-D358-4FD8-BC81-3DF6C04DC8A2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{95BCECFF-D358-4FD8-BC81-3DF6C04DC8A2}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -27,6 +27,8 @@ Global
{6939AC5E-4B9B-40B3-8044-437D0E20102F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6939AC5E-4B9B-40B3-8044-437D0E20102F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6939AC5E-4B9B-40B3-8044-437D0E20102F}.Release|Any CPU.Build.0 = Release|Any CPU
{35EADA32-399B-4DB5-BBAD-773603F127A9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{35EADA32-399B-4DB5-BBAD-773603F127A9}.Release|Any CPU.ActiveCfg = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MalikP.IoC" Version="0.6.7" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\MalikP.IVAO.Library.IoC\MalikP.IVAO.Library.IoC.csproj" />
<ProjectReference Include="..\MalikP.IVAO.Library\MalikP.IVAO.Library.csproj" />
</ItemGroup>

Expand Down
93 changes: 73 additions & 20 deletions src/MalikP. IVAO Library/MalikP.IVAO.Library.App/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;
using System.Text;
using System.Xml;

using MalikP.IoC;
using MalikP.IoC.Factories;
using MalikP.IVAO.Library.Common;
using MalikP.IVAO.Library.Common.Enhancers;
using MalikP.IVAO.Library.Common.Parsers;
using MalikP.IVAO.Library.Common.Selector;
using MalikP.IVAO.Library.Data.Source;
Expand All @@ -26,6 +26,66 @@ internal static class Program
public static void Main(string[] args)
{
string path = GetPath();

OptionIoC(path);

OptionDirect(path);
}

private static void OptionIoC(string path)
{
IIoC ioc = Locator.GetContainer(new AdvancedContainerFactory());

ioc.RegisterIvaoDefaultWhazzupServices();
ioc.RegisterIvaoModelBuilders();
ioc.RegisterIvaoCachedDataSource();

ioc.Register<IIVAOWhazzupSpecificDataSource, LocalGZippedIVAOWhazzupDataSource>()
.Extend()
.WithSpecific<string>(path);

//IIVAOWhazzupDataSource nonCachedWebDataSource = new WebIVAOWhazzupDataSource("http://api.ivao.aero/getdata/whazzup/whazzup.txt");
//IIVAOWhazzupDataSource nonCachedWebGZippedDataSource = new WebGZippedIVAOWhazzupDataSource("http://api.ivao.aero/getdata/whazzup/whazzup.txt.gz", compression);

//IIVAOWhazzupDataSource nonCachedLocalDataSource = new LocalIVAOWhazzupDataSource(path);
//IIVAOWhazzupDataSource nonCachedLocalGZippedDataSource = new LocalGZippedIVAOWhazzupDataSource(path, compression);

IGeneralDataProvider generalDataProvider = ioc.Resolve<IGeneralDataProvider>();
IClientsProvider clientsDataProvider = ioc.Resolve<IClientsProvider>();
IServersProvider serversDataProvider = ioc.Resolve<IServersProvider>();
IAirportsProvider airportsDataProvider = ioc.Resolve<IAirportsProvider>();

IClientsProvider atcClientsDataProvider = ioc.Resolve<IAirTrafficControllersProvider>();
IClientsProvider pilotClientsDataProvider = ioc.Resolve<IPilotsProvider>();
IClientsProvider followMeClientsDataProvider = ioc.Resolve<IFollowMesProvider>();

IEnumerable<IClientsProvider> providers = ioc.ResolveAll<IClientsProvider>();

List<GeneralData> generalDataModels = generalDataProvider.GetData().ToList();
List<Client> clientDataModels = clientsDataProvider.GetData().ToList();
List<Server> serversDataModels = serversDataProvider.GetData().ToList();
List<Airport> airportsDataModels = airportsDataProvider.GetData().ToList();

List<Client> atcDataModels = atcClientsDataProvider.GetData().ToList();
List<Client> pilotDataModels = pilotClientsDataProvider.GetData().ToList();
List<Client> followMeDataModels = followMeClientsDataProvider.GetData().ToList();

IAirTrafficControllerServerEnhancer atcServerEnhancer = ioc.Resolve<IAirTrafficControllerServerEnhancer>();
IPilotServerEnhancer pilotServerEnhancer = ioc.Resolve<IPilotServerEnhancer>();
IFollowMeServerEnhancer followMeServerEnhancer = ioc.Resolve<IFollowMeServerEnhancer>();

atcDataModels = atcDataModels.Select(atcServerEnhancer.Enhance).Cast<Client>().ToList();
pilotDataModels = pilotDataModels.Select(pilotServerEnhancer.Enhance).Cast<Client>().ToList();
followMeDataModels = followMeDataModels.Select(followMeServerEnhancer.Enhance).Cast<Client>().ToList();

Client item = pilotDataModels.First();

IModelCloner modelCloner = ioc.Resolve<IModelCloner>();
Client m = modelCloner.Clone(pilotDataModels[0]);
}

private static void OptionDirect(string path)
{
IGZipCompression compression = new GZipCompression();

IIVAOWhazzupDataSource nonCachedWebDataSource = new WebIVAOWhazzupDataSource("http://api.ivao.aero/getdata/whazzup/whazzup.txt");
Expand All @@ -37,6 +97,7 @@ public static void Main(string[] args)
ICachedIVAOWhazzupDataSource dataSource = new CachedIVAOWhazzupDataSource(nonCachedLocalGZippedDataSource);

IParserFactory parserFactory = new ParserFactory();

IGeneralSelector generalSelector = new GeneralSelector();
IClientsSelector clientsSelector = new ClientsSelector();
IServersSelector serverSelector = new ServersSelector();
Expand All @@ -60,26 +121,18 @@ public static void Main(string[] args)
List<Client> pilotDataModels = pilotClientsDataProvider.GetData().ToList();
List<Client> followMeDataModels = followMeClientsDataProvider.GetData().ToList();

Client item = pilotDataModels.First();
IAirTrafficControllerServerEnhancer atcServerEnhancer = new AirTrafficControllerServerEnhancer(serversDataProvider);
IPilotServerEnhancer pilotServerEnhancer = new PilotServerEnhancer(serversDataProvider);
IFollowMeServerEnhancer followMeServerEnhancer = new FollowMeServerEnhancer(serversDataProvider);

TrySerialize(item);
}
atcDataModels = atcDataModels.Select(atcServerEnhancer.Enhance).Cast<Client>().ToList();
pilotDataModels = pilotDataModels.Select(pilotServerEnhancer.Enhance).Cast<Client>().ToList();
followMeDataModels = followMeDataModels.Select(followMeServerEnhancer.Enhance).Cast<Client>().ToList();

private static void TrySerialize(Client item)
{
using (MemoryStream ms = new MemoryStream())
{
DataContractSerializer ser = new DataContractSerializer(typeof(Pilot));
ser.WriteObject(ms, item);

byte[] d = ms.ToArray();
string s = Encoding.UTF8.GetString(d);

ms.Position = 0;
Client item = pilotDataModels.First();

XmlDictionaryReader reader = XmlDictionaryReader.CreateTextReader(ms, new XmlDictionaryReaderQuotas());
object deserializedPerson = ser.ReadObject(reader, true);
}
IModelCloner modelCloner = new ModelCloner();
Client m = modelCloner.Clone(pilotDataModels[0]);
}

private static string GetPath()
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
using MalikP.IVAO.Library.Common;
using MalikP.IVAO.Library.Common.Enhancers;
using MalikP.IVAO.Library.Common.Parsers;
using MalikP.IVAO.Library.Common.Selector;
using MalikP.IVAO.Library.Data.Source;
using MalikP.IVAO.Library.Models.Airports;
using MalikP.IVAO.Library.Models.Clients;
using MalikP.IVAO.Library.Models.General;
using MalikP.IVAO.Library.Models.Other;
using MalikP.IVAO.Library.Models.Servers;
using MalikP.IVAO.Library.Providers;

namespace MalikP.IoC
{
public static class IvaoIocExtensions
{
public static IIoC RegisterIvaoDefaultWhazzupServices(this IIoC ioc)
{
ioc.Register<IParserFactory, ParserFactory>();

ioc.Register<IGZipCompression, GZipCompression>();

//ioc.Register<IIVAOWhazzupDataSource, WebIVAOWhazzupDataSource>();
//ioc.Register<IIVAOWhazzupDataSource, WebGZippedIVAOWhazzupDataSource>();
//ioc.Register<IIVAOWhazzupDataSource, LocalIVAOWhazzupDataSource>();
//ioc.Register<IIVAOWhazzupDataSource, LocalGZippedIVAOWhazzupDataSource>();

ioc.Register<IGeneralSelector, GeneralSelector>();
ioc.Register<IClientsSelector, ClientsSelector>();
ioc.Register<IServersSelector, ServersSelector>();
ioc.Register<IAirportsSelector, AirportsSelector>();

ioc.Register<IGeneralDataProvider, GeneralDataProvider>();
ioc.Register<IClientsProvider, ClientsDataProvider>();
ioc.Register<IServersProvider, ServersDataProvider>();
ioc.Register<IAirportsProvider, AirportsDataProvider>();

ioc.Register<IAirTrafficControllersProvider, AirTrafficControllersDataProvider>();
ioc.Register<IPilotsProvider, PilotsDataProvider>();
ioc.Register<IFollowMesProvider, FollowMesDataProvider>();

ioc.Register<IClientsProvider, AirTrafficControllersDataProvider>();
ioc.Register<IClientsProvider, PilotsDataProvider>();
ioc.Register<IClientsProvider, FollowMesDataProvider>();

ioc.Register<IAirTrafficControllerServerEnhancer, AirTrafficControllerServerEnhancer>();
ioc.Register<IPilotServerEnhancer, PilotServerEnhancer>();
ioc.Register<IFollowMeServerEnhancer, FollowMeServerEnhancer>();

ioc.Register<IModelCloner, ModelCloner>();

return ioc;
}

/// <summary>
/// You have to register one <see cref="IIVAOWhazzupSpecificDataSource"/> service manually.
/// Possibilities: <see cref="WebIVAOWhazzupDataSource"/>, <see cref="WebGZippedIVAOWhazzupDataSource"/>,
/// <see cref="LocalIVAOWhazzupDataSource"/>, <see cref="LocalGZippedIVAOWhazzupDataSource"/>
/// </summary>
/// <param name="ioc"><see cref="IIoC"/> container</param>
/// <returns><see cref="IIoC"/> container</returns>
public static IIoC RegisterIvaoCachedDataSource(this IIoC ioc)
{
ioc.Register<ICachedIVAOWhazzupDataSource, CachedIVAOWhazzupDataSource>()
.Extend()
.ToSingleton();

ioc.Register<IIVAOWhazzupDataSource>(d => d.Resolve<ICachedIVAOWhazzupDataSource>());

return ioc;
}

public static IIoC RegisterIvaoSpecificDataSource<TSpecific>(this IIoC ioc, TSpecific instance)
where TSpecific : IIVAOWhazzupSpecificDataSource
{
ioc.Register<IIVAOWhazzupSpecificDataSource, TSpecific>(instance);

return ioc;
}

public static IIoC RegisterIvaoModelBuilders(this IIoC ioc)
{
ioc.Register<AirportBuilder>(_ => AirportBuilder.Create());

ioc.Register<AirTrafficControllerBuilder>(_ => AirTrafficControllerBuilder.Create());
ioc.Register<FollowMeBuilder>(_ => FollowMeBuilder.Create());
ioc.Register<PilotBuilder>(_ => PilotBuilder.Create());

ioc.Register<GeneralDataBuilder>(_ => GeneralDataBuilder.Create());

ioc.Register<FlightPlanBuilder>(_ => FlightPlanBuilder.Create());
ioc.Register<GPSBuilder>(_ => GPSBuilder.Create());

ioc.Register<ServerBuilder>(_ => ServerBuilder.Create());

return ioc;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.1;netstandard2.0;net472;net471;net47;net462;net461;net46;net452;net451;net45</TargetFrameworks>
<!--net472;net471;-->
<PackageId>MalikP.IVAO.Library.IoC</PackageId>
<Version>0.8.6</Version>
<Authors>Peter Malik (MalikP.)</Authors>
<Company>Peter Malik (MalikP.)</Company>
<Product>MalikP. IVAO Library - IoC</Product>
<Description>Library to process IVAO data</Description>
<Copyright>Copyright © 2019 Peter Malik. (MalikP.)</Copyright>
<PackageProjectUrl>https://github.com/peterM/IVAO-Library</PackageProjectUrl>
<RepositoryUrl>https://github.com/peterM/IVAO-Library</RepositoryUrl>
<RepositoryType>GIT</RepositoryType>
<PackageTags>IVAO;WHAZZUP</PackageTags>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<ApplicationIcon>IVAOLibrary.ico</ApplicationIcon>
<PackageIconUrl>https://raw.githubusercontent.com/peterM/IVAO-Library/master/resource/IVAOLibrary64x64.png</PackageIconUrl>
<!--<ApplicationIcon />-->
<!--<Win32Resource />-->
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MalikP.IoC" Version="0.6.7" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\MalikP.IVAO.Library\MalikP.IVAO.Library.csproj" />
</ItemGroup>

<ItemGroup>
<None Include="..\..\..\LICENSE">
<Pack>True</Pack>
<PackagePath></PackagePath>
</None>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void Equals_WhenTwoSameInstancesAreCreated_ThenInstancesAreEqual()
.WithName("name")
.WithProtocol("protocol")
.WithRating(ATCRating.SeniorController)
.WithServer("server")
.WithServer(null)
.WithSoftwareName("IVAC")
.WithSoftwareVersion("1.2.3")
.WithVID("123456")
Expand Down Expand Up @@ -66,7 +66,7 @@ public void Equals_WhenTwoDifferentInstancesAreCreated_ThenInstancesAreNotEqual(
.WithName("name")
.WithProtocol("protocol")
.WithRating(ATCRating.SeniorController)
.WithServer("server")
.WithServer(null)
.WithSoftwareName("IVAC")
.WithSoftwareVersion("1.2.3")
.WithVID("123456")
Expand All @@ -81,7 +81,7 @@ public void Equals_WhenTwoDifferentInstancesAreCreated_ThenInstancesAreNotEqual(
.WithName("name")
.WithProtocol("protocol")
.WithRating(ATCRating.SeniorController)
.WithServer("server")
.WithServer(null)
.WithSoftwareName("IVAC")
.WithSoftwareVersion("1.2.3")
.WithVID("123456")
Expand Down Expand Up @@ -117,7 +117,7 @@ public void GetHashCode_WhenTwoSameInstancesAreCreated_ThenInstanceHashCodesAreE
.WithName("name")
.WithProtocol("protocol")
.WithRating(ATCRating.SeniorController)
.WithServer("server")
.WithServer(null)
.WithSoftwareName("IVAC")
.WithSoftwareVersion("1.2.3")
.WithVID("123456")
Expand Down Expand Up @@ -154,7 +154,7 @@ public void GetHashCode_WhenTwoDifferentInstancesAreCreated_ThenInstanceHashCode
.WithName("name")
.WithProtocol("protocol")
.WithRating(ATCRating.SeniorController)
.WithServer("server")
.WithServer(null)
.WithSoftwareName("IVAC")
.WithSoftwareVersion("1.2.3")
.WithVID("123456")
Expand All @@ -169,7 +169,7 @@ public void GetHashCode_WhenTwoDifferentInstancesAreCreated_ThenInstanceHashCode
.WithName("name")
.WithProtocol("protocol")
.WithRating(ATCRating.SeniorController)
.WithServer("server")
.WithServer(null)
.WithSoftwareName("IVAC")
.WithSoftwareVersion("1.2.3")
.WithVID("123456")
Expand Down Expand Up @@ -206,7 +206,7 @@ public void Equals_WhenInstanceIsDeseraializeAndSerializedBack_ThenInstancesAreE
.WithName("name")
.WithProtocol("protocol")
.WithRating(ATCRating.SeniorController)
.WithServer("server")
.WithServer(null)
.WithSoftwareName("IVAC")
.WithSoftwareVersion("1.2.3")
.WithVID("123456")
Expand Down Expand Up @@ -245,7 +245,7 @@ public void GetHashCode_WhenInstanceIsDeseraializeAndSerializedBack_ThenInstance
.WithName("name")
.WithProtocol("protocol")
.WithRating(ATCRating.SeniorController)
.WithServer("server")
.WithServer(null)
.WithSoftwareName("IVAC")
.WithSoftwareVersion("1.2.3")
.WithVID("123456")
Expand Down Expand Up @@ -285,7 +285,7 @@ public void Clone_WhenInstanceCloned_ThenInstancesHashCodesAreEqual()
.WithName("name")
.WithProtocol("protocol")
.WithRating(ATCRating.SeniorController)
.WithServer("server")
.WithServer(null)
.WithSoftwareName("IVAC")
.WithSoftwareVersion("1.2.3")
.WithVID("123456")
Expand Down Expand Up @@ -324,7 +324,7 @@ public void Clone_WhenInstanceCloned_ThenInstancesAreEqual()
.WithName("name")
.WithProtocol("protocol")
.WithRating(ATCRating.SeniorController)
.WithServer("server")
.WithServer(null)
.WithSoftwareName("IVAC")
.WithSoftwareVersion("1.2.3")
.WithVID("123456")
Expand Down
Loading