private void FuncShowObjects(Mission[] missionsToShow) { SIMCONNECT_DATA_INITPOSITION init; Nme2Ws.Nme2Ws ws = new Nme2Ws.Nme2Ws(); IList <MissionObject> objects = ws.MissionObjectServiceGetMissionObjectsForMissions(missionsToShow); foreach (MissionObject missionObject in objects) { init.Airspeed = 0; init.Altitude = missionObject.Altitude; init.Bank = missionObject.Bank; init.Heading = missionObject.Heading; init.Latitude = missionObject.Lat; init.Longitude = missionObject.Lon; init.OnGround = missionObject.OnGround == 0 ? 0 : (uint)1; init.Pitch = missionObject.Pitch; int reqId = new Random().Next(0, 999999); _currentObjectsInSim.Add(new SimconnectSimObject() { RequestId = reqId, MissionObject = missionObject }); //reqId, missionObject); _simconnectService.AiCreateSimulatedObject(missionObject.Simobject.SimName, init, reqId); } }
public void FuncCheckMissions(double lat, double lon) { if (RequestTimerStop != null) { RequestTimerStop(this, EventArgs.Empty); } // Check for missions Nme2Ws.Nme2Ws ws = new Nme2Ws.Nme2Ws(); _remoteMissions = ws.MissionServiceGetMissionsWithin(lat, lon); foreach (Mission mission in _remoteMissions) { bool exists = false; foreach (Mission local in _localMissions.Where(local => local.Id == mission.Id)) { exists = true; } if (exists) { string locVersion = _localMissions.First(m => mission.Id == m.Id).Version; string remVersion = mission.Version; if (locVersion != remVersion) { FuncRemoveMissionFromFs(mission); //FuncBuildMission(mission.Id.ToString()); FuncShowObjects(new[]{mission}); } } else { //FuncBuildMission(mission.Id.ToString()); FuncShowObjects(new[] { mission }); } } // Suche Missionen die nicht mehr Remote vorhanden sind und daher local gelöscht werden können. IList<Mission> deleteMissions = (from mission in _localMissions let found = _remoteMissions.Any(remMission => remMission.Id == mission.Id) where !found select mission).ToList(); foreach (Mission toDelete in deleteMissions) { FuncRemoveMissionFromFs(toDelete); } deleteMissions.Clear(); _localMissions = _remoteMissions.ToList(); if (RequestTimerStart != null) { RequestTimerStart(this, EventArgs.Empty); } }
public void FuncCheckMissions(double lat, double lon) { if (RequestTimerStop != null) { RequestTimerStop(this, EventArgs.Empty); } // Check for missions Nme2Ws.Nme2Ws ws = new Nme2Ws.Nme2Ws(); _remoteMissions = ws.MissionServiceGetMissionsWithin(lat, lon); foreach (Mission mission in _remoteMissions) { bool exists = false; foreach (Mission local in _localMissions.Where(local => local.Id == mission.Id)) { exists = true; } if (exists) { string locVersion = _localMissions.First(m => mission.Id == m.Id).Version; string remVersion = mission.Version; if (locVersion != remVersion) { FuncRemoveMissionFromFs(mission); //FuncBuildMission(mission.Id.ToString()); FuncShowObjects(new[] { mission }); } } else { //FuncBuildMission(mission.Id.ToString()); FuncShowObjects(new[] { mission }); } } // Suche Missionen die nicht mehr Remote vorhanden sind und daher local gelöscht werden können. IList <Mission> deleteMissions = (from mission in _localMissions let found = _remoteMissions.Any(remMission => remMission.Id == mission.Id) where !found select mission).ToList(); foreach (Mission toDelete in deleteMissions) { FuncRemoveMissionFromFs(toDelete); } deleteMissions.Clear(); _localMissions = _remoteMissions.ToList(); if (RequestTimerStart != null) { RequestTimerStart(this, EventArgs.Empty); } }
public static void StartSync() { // load local catalog CustomObjectCatalog localObjects = null; try { localObjects = DeSerializer.Deserializer<CustomObjectCatalog>("localObjects.xml"); } catch { } if (localObjects == null) { bool ok = DeSerializer.Serialize<CustomObjectCatalog>(new CustomObjectCatalog(new List<CustomObject>()), "localObjects.xml"); if (ok) localObjects = DeSerializer.Deserializer<CustomObjectCatalog>("localObjects.xml"); } if (localObjects != null) { // ask for update // TODO: invoke message box to ask user if he realy wants to sync. // get catalog from net Nme2Ws.Nme2Ws ws = new Nme2Ws.Nme2Ws(); CustomObjectCatalog webObjects = new CustomObjectCatalog(ws.CustomObjectServiceGetAllCustomObjectsAsArray()); // compare catalog IList<LocalCustomObject> toBeDeleted = new List<LocalCustomObject>(); IList<LocalCustomObject> newItems = new List<LocalCustomObject>(); foreach (LocalCustomObject webObject in webObjects.CustomObjects) { bool exists = false; foreach (LocalCustomObject localObject in localObjects.CustomObjects) { if (webObject.Id == localObject.Id && webObject.Version == localObject.Version) { exists = true; } else if (webObject.Id == localObject.Id && webObject.Version != localObject.Version) { exists = true; if (!toBeDeleted.Contains(webObject)) toBeDeleted.Add(localObject); if (!newItems.Contains(webObject)) newItems.Add(webObject); } } if (!exists) { if (!newItems.Contains(webObject)) newItems.Add(webObject); } } foreach (LocalCustomObject localObject in localObjects.CustomObjects) { bool clearedForDelete = true; foreach (LocalCustomObject webObject in webObjects.CustomObjects) { if (localObject.Id == webObject.Id) { clearedForDelete = false; } } if (clearedForDelete) if (!toBeDeleted.Contains(localObject)) toBeDeleted.Add(localObject); } // delete old items string customObjectPath = Settings.Default.CustomSimObjectPath; foreach (LocalCustomObject localOject in toBeDeleted) { Directory.Delete(customObjectPath + Path.DirectorySeparatorChar + localOject.Id + "_" + localOject.Version, true); } // download new items foreach (LocalCustomObject webObject in newItems) { // extract to custom object folder WebClient client = new WebClient(); // Load new object from remot to [temp] string copysource = webObject.DownloadPath; string destinationFilename = webObject.Id + "_" + webObject.Version + ".zip"; string unzipDestination = webObject.Id + "_" + webObject.Version; string destination = "./[temp]/" + destinationFilename; System.Diagnostics.Trace.Write(copysource); //Console.ForegroundColor = Program.ConsoleOrange; System.Diagnostics.Trace.Write("Inet access for download ..."); client.DownloadFile(copysource, destination); //File.Copy(copysource, "./[temp]/" + ObjectName.Replace('.', '_') + ".zip",true); //Console.ForegroundColor = Program.ConsoleGreen; System.Diagnostics.Trace.Write("... completed"); //Console.ForegroundColor = Program.ConsoleWhite; // unzip to simobject folder string unzipdir = customObjectPath + Path.DirectorySeparatorChar + unzipDestination; Directory.CreateDirectory(unzipdir); UnZipFiles(destination, unzipdir, "", false); // delete from [temp] File.Delete(destination); } // save catalog as new local DeSerializer.Serialize(webObjects, "localObjects.xml"); } }
private void FuncShowObjects(Mission[] missionsToShow) { SIMCONNECT_DATA_INITPOSITION init; Nme2Ws.Nme2Ws ws = new Nme2Ws.Nme2Ws(); IList<MissionObject> objects = ws.MissionObjectServiceGetMissionObjectsForMissions(missionsToShow); foreach (MissionObject missionObject in objects) { init.Airspeed = 0; init.Altitude = missionObject.Altitude; init.Bank = missionObject.Bank; init.Heading = missionObject.Heading; init.Latitude = missionObject.Lat; init.Longitude = missionObject.Lon; init.OnGround = missionObject.OnGround == 0 ? 0 : (uint)1; init.Pitch = missionObject.Pitch; int reqId = new Random().Next(0,999999); _currentObjectsInSim.Add(new SimconnectSimObject(){RequestId = reqId, MissionObject = missionObject});//reqId, missionObject); _simconnectService.AiCreateSimulatedObject(missionObject.Simobject.SimName, init, reqId); } }
public static void StartSync() { // load local catalog CustomObjectCatalog localObjects = null; try { localObjects = DeSerializer.Deserializer <CustomObjectCatalog>("localObjects.xml"); } catch { } if (localObjects == null) { bool ok = DeSerializer.Serialize <CustomObjectCatalog>(new CustomObjectCatalog(new List <CustomObject>()), "localObjects.xml"); if (ok) { localObjects = DeSerializer.Deserializer <CustomObjectCatalog>("localObjects.xml"); } } if (localObjects != null) { // ask for update // TODO: invoke message box to ask user if he realy wants to sync. // get catalog from net Nme2Ws.Nme2Ws ws = new Nme2Ws.Nme2Ws(); CustomObjectCatalog webObjects = new CustomObjectCatalog(ws.CustomObjectServiceGetAllCustomObjectsAsArray()); // compare catalog IList <LocalCustomObject> toBeDeleted = new List <LocalCustomObject>(); IList <LocalCustomObject> newItems = new List <LocalCustomObject>(); foreach (LocalCustomObject webObject in webObjects.CustomObjects) { bool exists = false; foreach (LocalCustomObject localObject in localObjects.CustomObjects) { if (webObject.Id == localObject.Id && webObject.Version == localObject.Version) { exists = true; } else if (webObject.Id == localObject.Id && webObject.Version != localObject.Version) { exists = true; if (!toBeDeleted.Contains(webObject)) { toBeDeleted.Add(localObject); } if (!newItems.Contains(webObject)) { newItems.Add(webObject); } } } if (!exists) { if (!newItems.Contains(webObject)) { newItems.Add(webObject); } } } foreach (LocalCustomObject localObject in localObjects.CustomObjects) { bool clearedForDelete = true; foreach (LocalCustomObject webObject in webObjects.CustomObjects) { if (localObject.Id == webObject.Id) { clearedForDelete = false; } } if (clearedForDelete) { if (!toBeDeleted.Contains(localObject)) { toBeDeleted.Add(localObject); } } } // delete old items string customObjectPath = Settings.Default.CustomSimObjectPath; foreach (LocalCustomObject localOject in toBeDeleted) { Directory.Delete(customObjectPath + Path.DirectorySeparatorChar + localOject.Id + "_" + localOject.Version, true); } // download new items foreach (LocalCustomObject webObject in newItems) { // extract to custom object folder WebClient client = new WebClient(); // Load new object from remot to [temp] string copysource = webObject.DownloadPath; string destinationFilename = webObject.Id + "_" + webObject.Version + ".zip"; string unzipDestination = webObject.Id + "_" + webObject.Version; string destination = "./[temp]/" + destinationFilename; System.Diagnostics.Trace.Write(copysource); //Console.ForegroundColor = Program.ConsoleOrange; System.Diagnostics.Trace.Write("Inet access for download ..."); client.DownloadFile(copysource, destination); //File.Copy(copysource, "./[temp]/" + ObjectName.Replace('.', '_') + ".zip",true); //Console.ForegroundColor = Program.ConsoleGreen; System.Diagnostics.Trace.Write("... completed"); //Console.ForegroundColor = Program.ConsoleWhite; // unzip to simobject folder string unzipdir = customObjectPath + Path.DirectorySeparatorChar + unzipDestination; Directory.CreateDirectory(unzipdir); UnZipFiles(destination, unzipdir, "", false); // delete from [temp] File.Delete(destination); } // save catalog as new local DeSerializer.Serialize(webObjects, "localObjects.xml"); } }