Esempio n. 1
0
        /// <summary> 
        /// Imports a DxfFile that is in the specified Format. Any changes on the import schema may cause Errors!
        /// </summary>
        /// <param name="filepath"></param>
        public static void importFromDxf(string filepath, string DB_PATH)
        {
            StreamReader sr = new StreamReader(filepath);
            DatabaseDataContext dataContext = new DatabaseDataContext(DB_PATH);
            foreach (t_PolygonPoint tp in dataContext.t_PolygonPoints)
            {
                dataContext.t_PolygonPoints.DeleteOnSubmit(tp);
            }
               ///dataContext.t_PolygonPoints.DeleteAllOnSubmit(dataContext.t_PolygonPoints.ToList());
            dataContext.SubmitChanges();
            dataContext.t_Polygons.DeleteAllOnSubmit(dataContext.t_Polygons);
            dataContext.SubmitChanges();
            int id = 1;

            List<string> lineList = new List<string>();
            while (!sr.EndOfStream)
            {
                lineList.Add(sr.ReadLine());
            }
            string[] lines = lineList.ToArray();
            for (int i = 1; i < lines.Length; i++) //Looping through Array, starting with 1 (lines[0] is "0")
            {
                //Find Lines Containing a new Element Definition
                if (lines[i] == "LWPOLYLINE" && lines[i - 1] == "  0") //
                {
                    //Reading out Layer ( "8" [\n] layerName) = Type of Element
                    if (lines[i + 5] == "  8" && lines[i + 6].Contains("PROH")) // "Prohibited Zone" = ForbiddenZone
                    {
                        if (lines[i + 9] == " 90")
                        {
                            int numberOfVertexes = int.Parse(lines[i + 10]);
                            t_Polygon p = new t_Polygon();
                            p.ID = id++;

                            for (int j = 0; j < numberOfVertexes; j++)
                            {
                                t_PolygonPoint point = new t_PolygonPoint();
                                GpsPoint gp = new GpsPoint(double.Parse(lines[i + (j * 4) + 18], NumberFormatInfo.InvariantInfo) * 1000, double.Parse(lines[i + (j * 4) + 16], NumberFormatInfo.InvariantInfo) * 1000, GpsPointFormatImport.Swiss);
                                point.longitude = (decimal)gp.Longitude;
                                point.latitude = (decimal)gp.Latitude;
                                point.ID_Polygon = p.ID;
                                dataContext.t_PolygonPoints.InsertOnSubmit(point);
                            }
                            dataContext.t_Polygons.InsertOnSubmit(p);
                        }
                    }
                }
            }

            dataContext.SubmitChanges();
        }
Esempio n. 2
0
 /// <summary>
 /// Add a Log entry
 /// </summary>
 /// <param name="DB_Path">Path of the DB to add the Log</param>
 /// <param name="Level">Level of the Log 0 = Error, 4 = information</param>
 /// <param name="Project">Project which throw this log entry</param>
 /// <param name="Text">Description / Data of this Log</param>
 public static void AddLog(string DB_Path,int Level, string Project, string Text)
 {
     DatabaseDataContext dataContext = new DatabaseDataContext(DB_Path);
     t_Log LogEntry = new t_Log();
     LogEntry.level = Level;
     LogEntry.project = Project;
     LogEntry.Text = Text;
     LogEntry.timestamp = DateTime.Now;
     dataContext.t_Logs.InsertOnSubmit(LogEntry);
     dataContext.SubmitChanges();
 }
Esempio n. 3
0
 private void btnAddNewAirplaneToTracker_Click(object sender, EventArgs e)
 {
     if (lstTrackers.SelectedItems.Count == 1)
     {
         DatabaseDataContext dataContext = new DatabaseDataContext(DB_Path);
         t_Pilot f = new t_Pilot();
         f.ID_Tracker = ((TrackerListEntry)lstTrackers.SelectedItems[0]).ID_Tracker;
         f.LastName = txtPilot.Text;
         f.SureName = txtAirplane.Text;
         dataContext.t_Pilots.InsertOnSubmit(f);
         dataContext.SubmitChanges();
         RefreshTrackerList();
     }
 }
Esempio n. 4
0
 private void btnAddAirplaneToTracker_Click(object sender, EventArgs e)
 {
     if (lstTrackers.SelectedItems.Count == 1 && drpAirplane.SelectedItem != null)
     {
         TrackerListEntry tle = (TrackerListEntry)lstTrackers.SelectedItems[0];
         DatabaseDataContext dataContext = new DatabaseDataContext(DB_Path);
         foreach (t_Pilot f in dataContext.t_Pilots.Where(p => p.ID_Tracker == tle.ID_Tracker))
         {
             f.ID_Tracker = 0;
         }
         t_Pilot fl = dataContext.t_Pilots.Single(p=>p.ID == ((AirplaneListEntry)drpAirplane.SelectedItem).ID);
         fl.ID_Tracker = tle.ID_Tracker;
         dataContext.SubmitChanges();
         RefreshTrackerList();
     }
 }
Esempio n. 5
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="LastName"></param>
 /// <param name="SureName"></param>
 /// <param name="Color"></param>
 /// <returns></returns>
 public int AddNewPilot(String LastName, String SureName, String Color, byte[] Picture, int Id_Flag)
 {
     try
     {
         LogManager.AddLog(DB_PATH, 4, "ANRLDataService.svc.cs:AddNewAirplane", LastName + SureName);
         DatabaseDataContext dataContext = new DatabaseDataContext(DB_PATH);
         t_Pilot f = new t_Pilot();
         f.LastName = LastName;
         f.SureName = SureName;
         f.Color = Color;
         f.Picture = new System.Data.Linq.Binary(Picture);
         f.ID_Flag = Id_Flag;
         dataContext.t_Pilots.InsertOnSubmit(f);
         dataContext.SubmitChanges();
         return f.ID;
     }
     catch (Exception ex)
     {
         LogManager.AddLog(DB_PATH, 0, "ANRLDataService.svc.cs:AddNewPilot", ex.ToString());
     }
     return -1;
 }
Esempio n. 6
0
        /// <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>
        void CalculateTabels_Elapsed(object sender, ElapsedEventArgs e)
        {
            try
            {
                DataService.DatabaseDataContext dataContext = new DatabaseDataContext(DB_PATH);
                List<t_GPS_IN> Positions = dataContext.t_GPS_INs.Where(a => !a.Processed).OrderBy(t => t.TimestampTracker).ToList();
                List<t_Tracker> Trackers = dataContext.t_Trackers.ToList();

                if (Positions.Count > 0)LogManager.AddLog(DB_PATH, 4, "RecieverService.cs:CalculateTabels_Elapsed:Lists","Positions.Count=" + Positions.Count + " Trackers.count=" + Trackers.Count);

                foreach (t_Tracker tr in Trackers)
                {
                    List<t_GPS_IN> Positions_Tracker = Positions.Where(a => a.IMEI == tr.IMEI).OrderBy(a => a.TimestampTracker).ToList();
                    foreach (t_GPS_IN GPS_IN in Positions_Tracker)
                    {
                        t_Daten InsertData = new t_Daten();
                        InsertData.ID_Tracker = tr.ID;
                        InsertData.Timestamp = GPS_IN.TimestampTracker;
                        InsertData.Latitude = decimal.Round(ConvertCoordinates(GPS_IN.latitude), 16);
                        InsertData.Longitude = decimal.Round(ConvertCoordinates(GPS_IN.longitude), 16);
                        InsertData.Altitude = decimal.Parse(GPS_IN.altitude);
                        dataContext.t_Datens.InsertOnSubmit(InsertData);
                        GPS_IN.Processed = true;
                    }
                }
                dataContext.SubmitChanges();
            }
            catch (Exception ex)
            {
                LogManager.AddLog(DB_PATH, 0, "RecieverService.cs:CalculateTabels_Elapsed:Error", ex.ToString());
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Handels the Data recieved and processed in the Message_Received_Processor
        /// Adds the Data to the Database
        /// For Threat-Security
        /// </summary>
        /// <param name="GPSData">THe Data</param>
        public void ProcessRecievedGPSData(string GPSData)
        {
            LogManager.AddLog(DB_PATH, 4, "Reciever.cs:ProcessRecievedGPSData:Start", GPSData);
            try
            {
                String trimedGPSData = GPSData.Trim(new char[] { '!', '$' });
                String[] GPScoords = trimedGPSData.Split(new char[] { ',', '*' });
                DatabaseDataContext dataContext = new DatabaseDataContext(DB_PATH);
                if (dataContext.t_Trackers.Count(p => p.IMEI == GPScoords[0]) == 0)
                {
                    t_Tracker t = new t_Tracker();
                    t.IMEI = GPScoords[0];
                    dataContext.t_Trackers.InsertOnSubmit(t);
                    dataContext.SubmitChanges();
                    OnTrackerAddded.Invoke(null, null);
                }
                string yy = GPScoords[3].Substring(4, 2);
                string mm = GPScoords[3].Substring(2, 2);
                string dd = GPScoords[3].Substring(0, 2);
                if (yy != "00" && mm != "00" && dd != "00") //Only save sensefull data
                {
                    DataService.t_GPS_IN new_position = new DataService.t_GPS_IN();
                    new_position.IMEI = GPScoords[0];
                    new_position.Status = Int32.Parse(GPScoords[1]);
                    new_position.GPS_fix = Int32.Parse(GPScoords[2]);
                    new_position.TimestampTracker = new DateTime(
                                            Int32.Parse("20" + yy),
                                            Int32.Parse(mm),
                                            Int32.Parse(dd),
                                            Int32.Parse(GPScoords[4].Substring(0, 2)),
                                            Int32.Parse(GPScoords[4].Substring(2, 2)),
                                            Int32.Parse(GPScoords[4].Substring(4, 2)));
                    new_position.longitude = GPScoords[5];
                    new_position.latitude = GPScoords[6];
                    new_position.altitude = GPScoords[7];
                    new_position.speed = GPScoords[8];
                    new_position.heading = GPScoords[9];
                    new_position.nr_used_sat = Int32.Parse(GPScoords[10]);
                    new_position.HDOP = GPScoords[11];
                    new_position.Timestamp = DateTime.Now;
                    new_position.Processed = false;

                    dataContext.t_GPS_INs.InsertOnSubmit(new_position);
                    dataContext.SubmitChanges();
                }
            }
            catch
            {
                LogManager.AddLog(DB_PATH, 0, "Reciever.cs:ProcessRecievedGPSData:Error", GPSData);
            }
        }
Esempio n. 8
0
 /// <summary>
 /// Add Existim Pilot, may be modified
 /// </summary>
 /// <param name="PilotID"></param>
 /// <param name="TrackerID"></param>
 /// <param name="LastName"></param>
 /// <param name="SureName"></param>
 /// <param name="Color"></param>
 public void AddPilot(int PilotID, int TrackerID, String LastName, String SureName, String Color, byte[] Picture, int Id_Flag)
 {
     try
     {
         LogManager.AddLog(DB_PATH, 4, "ANRLDataService.svc.cs:AddAirplane", PilotID.ToString() + " " + TrackerID.ToString());
         DatabaseDataContext dataContext = new DatabaseDataContext(DB_PATH);
         foreach (t_Pilot f in dataContext.t_Pilots.Where(p => p.ID_Tracker == TrackerID))
         {
             f.ID_Tracker = 0;
         }
         t_Pilot fl = dataContext.t_Pilots.Single(p => p.ID == PilotID);
         fl.LastName = LastName;
         fl.SureName = SureName;
         fl.Color = Color;
         fl.ID_Tracker = TrackerID;
         fl.Picture = new System.Data.Linq.Binary(Picture);
         fl.ID_Flag = Id_Flag;
         dataContext.SubmitChanges();
     }
     catch (Exception ex)
     {
         LogManager.AddLog(DB_PATH, 0, "ANRLDataService.svc.cs:AddPilot", ex.ToString());
     }
 }
Esempio n. 9
0
 /// <summary>
 /// Remove the Race
 /// </summary>
 /// <param name="Race_ID">Remove Race</param>
 /// <returns></returns>
 public void RemoveRace(int Race_ID)
 {
     try
     {
         LogManager.AddLog(DB_PATH, 4, "ANRLDataService.svc.cs:RemoveRace", Race_ID.ToString());
         DatabaseDataContext context = new DatabaseDataContext(DB_PATH);
         context.t_Races.DeleteOnSubmit(context.t_Races.Single(p => p.ID == Race_ID));
         context.SubmitChanges();
     }
     catch (Exception ex)
     {
         LogManager.AddLog(DB_PATH, 0, "ANRLDataService.svc.cs:RemoveRace", ex.ToString());
     }
 }
Esempio n. 10
0
 /// <summary>
 /// Remove this Tracker from any Airplane
 /// </summary>
 /// <param name="TrackerID"> ID of the Tracker</param>
 public void CleanTracker(int TrackerID)
 {
     try
     {
         LogManager.AddLog(DB_PATH, 4, "ANRLDataService.svc.cs:CleanTracker", TrackerID.ToString());
         DatabaseDataContext dataContext = new DatabaseDataContext(DB_PATH);
         foreach (t_Pilot f in dataContext.t_Pilots.Where(p => p.ID_Tracker == TrackerID))
         {
             f.ID_Tracker = 0;
         }
         dataContext.SubmitChanges();
     }
     catch (Exception ex)
     {
         LogManager.AddLog(DB_PATH, 0, "ANRLDataService.svc.cs:CleanTracker", ex.ToString());
     }
 }
Esempio n. 11
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="Race"></param>
        public void AddRace(t_Race Race)
        {
            try
            {
                LogManager.AddLog(DB_PATH, 4, "ANRLDataService.svc.cs:AddRace", "");
                DatabaseDataContext dataContext = new DatabaseDataContext(DB_PATH);
                t_PolygonGroup PolygonGroup = new t_PolygonGroup();

                #region Polygongroup & Polygons & PolygonPoints
                if (Race.t_PolygonGroup != null)
                {
                    if (Race.ID_PolygonGroup == 0)
                    {
                        PolygonGroup.Name = Race.t_PolygonGroup.Name;
                        dataContext.t_PolygonGroups.InsertOnSubmit(PolygonGroup);
                        dataContext.SubmitChanges();

                        if (Race.t_PolygonGroup.t_Polygons.Count > 0)
                        {
                            foreach (t_Polygon poly in Race.t_PolygonGroup.t_Polygons)
                            {
                                t_Polygon tmp_poly = new t_Polygon();
                                tmp_poly.Type = poly.Type;
                                tmp_poly.ID_PolygonGroup = PolygonGroup.ID;
                                dataContext.t_Polygons.InsertOnSubmit(tmp_poly);
                                dataContext.SubmitChanges();
                                foreach (t_PolygonPoint pp in poly.t_PolygonPoints)
                                {
                                    t_PolygonPoint tmpPoint = new t_PolygonPoint();
                                    tmpPoint.ID_Polygon = tmp_poly.ID;
                                    tmpPoint.longitude = pp.longitude;
                                    tmpPoint.latitude = pp.latitude;
                                    tmpPoint.altitude = pp.altitude;
                                    dataContext.t_PolygonPoints.InsertOnSubmit(tmpPoint);
                                }
                            }
                        }
                    }
                    else
                    {
                        PolygonGroup.ID = (int)Race.ID_PolygonGroup;
                    }
                    dataContext.SubmitChanges();
                }
                #endregion
                t_Race r = new t_Race();
                if (Race.ID_Pilot_0 != 0) r.ID_Pilot_0 = Race.ID_Pilot_0;
                if (Race.ID_Pilot_1 != 0) r.ID_Pilot_1 = Race.ID_Pilot_1;
                if (Race.ID_Pilot_2 != 0) r.ID_Pilot_2 = Race.ID_Pilot_2;
                if (Race.ID_Pilot_3 != 0) r.ID_Pilot_3 = Race.ID_Pilot_3;
                if (Race.ID_PolygonGroup != 0)
                {
                    r.ID_PolygonGroup = Race.ID_PolygonGroup;
                }
                else
                {
                    r.ID_PolygonGroup = PolygonGroup.ID;
                }
                r.Name = Race.Name;
                r.TimeEnd = Race.TimeEnd;
                r.TimeStart = Race.TimeStart;
                dataContext.t_Races.InsertOnSubmit(r);
                dataContext.SubmitChanges();
                LogManager.AddLog(DB_PATH, 4, "ANRLDataService.svc.cs:AddRace", "Sucessfull Added " + r.ID);
            }
            catch (Exception ex)
            {
                LogManager.AddLog(DB_PATH, 0, "ANRLDataService.svc.cs:AddRace", ex.ToString());
            }
        }
Esempio n. 12
0
        private void btnRemvAirplaneFromTracker_Click(object sender, EventArgs e)
        {
            if (lstTrackers.SelectedItems.Count == 1)
            {
                TrackerListEntry tle = (TrackerListEntry)lstTrackers.SelectedItems[0];

                DatabaseDataContext dataContext = new DatabaseDataContext(DB_Path);
                foreach (t_Pilot f in dataContext.t_Pilots.Where(p => p.ID_Tracker == tle.ID_Tracker))
                {
                    f.ID_Tracker = 0;
                }

                dataContext.SubmitChanges();
            }
            RefreshTrackerList();
        }
Esempio n. 13
0
 private void RefreshTrackerList()
 {
     LogManager.AddLog(DB_Path, 4, "ControllCenter.cs:RefreshTrackerList", "Start");
     DatabaseDataContext dataContext = new DatabaseDataContext(DB_Path);
     lstTrackers.Items.Clear();
     foreach (t_Tracker t in dataContext.t_Trackers)
     {
         TrackerListEntry tle = new TrackerListEntry(t.ID, t.IMEI);
         #region Check airplanes attached ?
         //Remove GPS-Trackers if added to may Airplanes
         int Count = dataContext.t_Pilots.Count(p => p.ID_Tracker == t.ID);
         if (Count > 1)
         {
             foreach (t_Pilot f in dataContext.t_Pilots.Where(p => p.ID_Tracker == t.ID))
             {
                 f.ID_Tracker = 0;
             }
             dataContext.SubmitChanges();
         }
         else if (Count == 1)
         {
             t_Pilot f = dataContext.t_Pilots.Single(p=>p.ID_Tracker==t.ID);
             tle.ID_Pilot = f.ID;
             tle.SureName = f.SureName;
             tle.LastName = f.LastName;
         }
         #endregion
         tle.Set();
         lstTrackers.Items.Add(tle);
     }
     drpAirplane.Items.Clear();
     foreach (t_Pilot f in dataContext.t_Pilots.Where(p=>p.ID_Tracker == 0))
     {
         drpAirplane.Items.Add(new AirplaneListEntry(f));
     }
     CheckButtons();
     LogManager.AddLog(DB_Path, 4, "ControllCenter.cs:RefreshTrackerList", "Ende");
 }
Esempio n. 14
0
 void of_FileOk(object sender, CancelEventArgs e)
 {
     OpenFileDialog of = sender as OpenFileDialog;
     if (of != null)
     {
         DatabaseDataContext dataContext = new DatabaseDataContext(DB_Path);
         dataContext.t_Pictures.DeleteAllOnSubmit(dataContext.t_Pictures.Where(p => p.isFlag));
         dataContext.SubmitChanges();
         foreach (String s in of.FileNames)
         {
             FileStream fs = File.OpenRead(s);
             List<Byte> lb = new List<Byte>();
             lb.Clear();
             int b;
             while ((b = fs.ReadByte()) >= 0)
             {
                 lb.Add((Byte)b);
             }
             t_Picture p = new t_Picture();
             p.isFlag = true;
             String[] Name = s.Split(new char[]{'\\'});
             p.Name = Name[Name.Length - 1].Split(new char[] {'.'})[0];
             if (p.Name.Contains("flag_"))
             {
                 p.Name = p.Name.Substring(5);
             }
             p.Data = new Binary(lb.ToArray());
             fs.Close();
             dataContext.t_Pictures.InsertOnSubmit(p);
             dataContext.SubmitChanges();
         }
         dataContext.SubmitChanges();
     }
 }