public Root PostData(Root root) { WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Origin", "*"); WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Methods", "GET, POST, OPTIONS"); WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Headers", "Content-Type"); WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Max-Age", "1728000"); AnrlDataContext db = new AnrlDataContext(); Root response = new Root(); response.response = new Response(); response.response.countAdded = 0; try { if (root != null && root.gpsdata.Count > 0) { t_Tracker tracker; if (db.t_Trackers.Count(p => p.IMEI == root.gpsdata[0].identifier) == 1) { tracker = db.t_Trackers.Single(p => p.IMEI == root.gpsdata[0].identifier); } else { tracker = new t_Tracker(); tracker.IMEI = root.gpsdata[0].identifier; db.t_Trackers.InsertOnSubmit(tracker); db.SubmitChanges(); } foreach (GPSData data in root.gpsdata) { t_Daten t_d = new t_Daten(); t_d.Accuracy = data.accuracy; t_d.Altitude = data.altitude; t_d.Bearing = data.bearing; t_d.Latitude = data.latitude; t_d.Longitude = data.longitude; t_d.Speed = data.speed; t_d.Timestamp = data.timestampGPS; t_d.ID_Tracker = tracker.ID; db.t_Datens.InsertOnSubmit(t_d); response.response.countAdded++; } db.SubmitChanges(); } } catch (Exception ex) { #if !DEBUG //Logger.Log("Exception in GPSRequestProcessor.proccessRequest" + ex.ToString(), 9); #else //System.Console.WriteLine("Exception in GPSRequestProcessor.proccessRequest " + ex.ToString()); #endif response.exception = ex.ToString(); } finally { db.Dispose(); } return response; }
/// <summary> /// Calculate the Tables of t_Data and Insert all needed Entries /// Will be trigered form a 1 sec-Timer /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void CalculateTabels_Elapsed(object sender, ElapsedEventArgs e) { AnrlDB.AnrlDataContext db = new AnrlDB.AnrlDataContext(); try { List<t_GPS_IN> Positions = db.t_GPS_INs.Where(a => !a.Processed).OrderBy(t => t.TimestampTracker).ToList(); List<t_Tracker> Trackers = db.t_Trackers.ToList(); foreach (t_Tracker tr in Trackers) { try { List<t_GPS_IN> Positions_Tracker = Positions.Where(a => a.IMEI.Trim() == tr.IMEI.Trim()).OrderBy(a => a.TimestampTracker).ToList(); foreach (t_GPS_IN GPS_IN in Positions_Tracker) { try { t_Daten InsertData = new t_Daten(); InsertData.t_Tracker = tr; InsertData.Timestamp = GPS_IN.TimestampTracker.Ticks; InsertData.Latitude = ConvertCoordinates(GPS_IN.latitude); InsertData.Longitude = ConvertCoordinates(GPS_IN.longitude); InsertData.Altitude = double.Parse(GPS_IN.altitude, NumberFormatInfo.InvariantInfo); db.t_Datens.InsertOnSubmit(InsertData); } catch (Exception ex) { Logger.Log("Exception in Server.CalculateTabels_Elapsed" + ex.ToString(), 18); } GPS_IN.Processed = true; } } catch (Exception ex) { Logger.Log("Exception in Server.CalculateTabels_Elapsed" + ex.ToString(), 19); } } db.SubmitChanges(); } catch (Exception ex) { Logger.Log("Exception in Server.CalculateTabels_Elapsed" + ex.ToString(), 20); } finally { db.Dispose(); } }
private void detach_t_Datens(t_Daten entity) { this.SendPropertyChanging(); entity.t_Tracker = null; }
private void attach_t_Datens(t_Daten entity) { this.SendPropertyChanging(); entity.t_Tracker = this; }
partial void Deletet_Daten(t_Daten instance);
partial void Updatet_Daten(t_Daten instance);
partial void Insertt_Daten(t_Daten instance);
public RootMessage proccessRequest(RootMessage request) { AnrlDataContext db = new AnrlDataContext(); RootMessage response = new RootMessage(); response.response = new Response(); response.response.countAdded = 0; try { if (request != null && request.gpsdata.Count > 0) { t_Tracker tracker; if (db.t_Trackers.Count(p => p.IMEI == request.gpsdata[0].identifier) == 1) { tracker = db.t_Trackers.Single(p => p.IMEI == request.gpsdata[0].identifier); } else { tracker = new t_Tracker(); tracker.IMEI = request.gpsdata[0].identifier; db.t_Trackers.InsertOnSubmit(tracker); db.SubmitChanges(); } foreach (GPSData data in request.gpsdata) { t_Daten t_d = new t_Daten(); t_d.Accuracy = data.accuracy; t_d.Altitude = data.altitude; t_d.Bearing = data.bearing; t_d.Latitude = data.latitude; t_d.Longitude = data.longitude; t_d.Speed = data.speed; //Convert Javas millis to C#'s nano- Ticks //Hack to fix the Bug from Android (One day in future) long day = TimeSpan.TicksPerDay; long hours = TimeSpan.TicksPerHour; long timestampGPS = UTCBaseTime.Add(new TimeSpan(data.timestampGPS * TimeSpan.TicksPerMillisecond)).Ticks; long timestampSender = UTCBaseTime.Add(new TimeSpan(data.timestampSender * TimeSpan.TicksPerMillisecond)).Ticks; if ((timestampGPS - day + hours) > timestampSender) { timestampGPS -= day; } t_d.Timestamp = timestampGPS; t_d.ID_Tracker = tracker.ID; db.t_Datens.InsertOnSubmit(t_d); response.response.countAdded++; } db.SubmitChanges(); } } catch (Exception ex) { #if !DEBUG Logger.Log("Exception in GPSRequestProcessor.proccessRequest" + ex.ToString(), 9); #else //System.Console.WriteLine("Exception in GPSRequestProcessor.proccessRequest " + ex.ToString()); #endif response.exception = ex.ToString(); } finally { db.Dispose(); } return response; }