Compare commits

..

No commits in common. "a6b6d139a03261a28dc96e45b8aa145a15f26006" and "d67d4a8a0442e865378301ce564bb7d7c2fe7a71" have entirely different histories.

4 changed files with 10 additions and 80 deletions

View File

@ -1,12 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MongoDB.Driver" Version="*"/>
<PackageReference Include="MongoDB.Bson" Version="*"/>
</ItemGroup>
</Project>
</Project>

View File

@ -1,46 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using MongoDB.Bson;
using MongoDB.Driver;
using EFBTracker.Tracking;
namespace EFBTracker.Mongo
{
public class Mongo
{
public static async Task<bool> UploadSimPosition(string email, SimPosition position){
try
{
MongoClient client = new MongoClient(
Environment.GetEnvironmentVariable("MongoDBConnectionString", EnvironmentVariableTarget.User)
);
MongoDatabaseBase database = (MongoDatabaseBase)client.GetDatabase("EFB");
MongoCollectionBase<SimPositionModel> collection = (MongoCollectionBase<SimPositionModel>)database.GetCollection<SimPositionModel>("Simdata");
SimPositionModel data = new SimPositionModel(email, position);
FilterDefinition<SimPositionModel> userFilter = Builders<SimPositionModel>.Filter.Eq(x => x.EMail, email);
UpdateDefinition<SimPositionModel> updateDefinition = Builders<SimPositionModel>.Update
.Set(x => x.LatestPosition, position)
.Set(x => x.LatestPacketUpdate, DateTime.Now);
var confirmation = await collection.UpdateOneAsync(userFilter, updateDefinition);
if (confirmation.ModifiedCount == 0)
{
collection.InsertOne(data);
}
return true;
}
catch (System.Exception ex)
{
Console.WriteLine(ex.Message);
return false;
}
}
}
}

View File

@ -1,27 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using EFBTracker.Tracking;
using MongoDB.Bson.Serialization.Attributes;
using MongoDB.Bson;
using MongoDB.Driver;
namespace EFBTracker.Mongo
{
public class SimPositionModel
{
[BsonId]
public ObjectId Id { get; set; }
public string EMail { get; set; } = "";
public DateTime LatestPacketUpdate { get; set; }
public SimPosition? LatestPosition { get; set; } = null;
public SimPositionModel(string email, SimPosition position){
EMail = email;
LatestPacketUpdate = DateTime.Now;
LatestPosition = position;
}
}
}

View File

@ -2,7 +2,6 @@
using System.Net.Sockets;
using System.Text;
using EFBTracker.Tracking;
using EFBTracker.Mongo;
bool done = false;
int listenPort = 49003;
@ -24,7 +23,13 @@ using(UdpClient listener = new UdpClient(listenPort))
{
SimPosition position = new SimPosition(data);
Console.WriteLine($"Latitude: {position.Latitude} Longitude: {position.Longitude} Altitude: {position.Altitude}");
await Mongo.UploadSimPosition("example@example.com", position);
}
}
}