public bool Delete() { using (SQLiteConnectionED cn = new SQLiteConnectionED()) { return(Delete(cn)); } }
public bool Update() { using (SQLiteConnectionED cn = new SQLiteConnectionED()) { return(Update(cn)); } }
public static bool GetAllSystemNotes() { try { using (SQLiteConnectionED cn = new SQLiteConnectionED()) { using (DbCommand cmd = cn.CreateCommand("select * from SystemNote")) { DataSet ds = SQLiteDBClass.SQLQueryText(cn, cmd); if (ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0) { return(false); } globalSystemNotes.Clear(); foreach (DataRow dr in ds.Tables[0].Rows) { SystemNoteClass sys = new SystemNoteClass(dr); globalSystemNotes[sys.Name.ToLower()] = sys; } return(true); } } } catch { return(false); } }
static public List <VisitedSystemsClass> GetAll(int commander) { List <VisitedSystemsClass> list = new List <VisitedSystemsClass>(); using (SQLiteConnectionED cn = new SQLiteConnectionED()) { using (DbCommand cmd = cn.CreateCommand("select * from VisitedSystems where commander=@commander Order by Time ")) { cmd.AddParameterWithValue("@commander", commander); DataSet ds = SQLiteDBClass.SQLQueryText(cn, cmd); if (ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0) { return(list); } foreach (DataRow dr in ds.Tables[0].Rows) { VisitedSystemsClass sys = new VisitedSystemsClass(dr); list.Add(sys); } return(list); } } }
public static bool GetAllBookmarks() { try { using (SQLiteConnectionED cn = new SQLiteConnectionED()) { using (DbCommand cmd = cn.CreateCommand("select * from Bookmarks")) { DataSet ds = null; ds = SQLiteDBClass.SQLQueryText(cn, cmd); if (ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0) { return(false); } bookmarks.Clear(); foreach (DataRow dr in ds.Tables[0].Rows) { BookmarkClass bc = new BookmarkClass(dr); bookmarks.Add(bc); } return(true); } } } catch { return(false); } }
public bool Add(SQLiteConnectionED cn, DbTransaction tn = null) { using (DbCommand cmd = cn.CreateCommand("Insert into VisitedSystems (Name, Time, Unit, Commander, Source, edsm_sync, map_colour, X, Y, Z, id_edsm_assigned) values (@name, @time, @unit, @commander, @source, @edsm_sync, @map_colour, @x, @y, @z, @id_edsm_assigned)", tn)) { cmd.AddParameterWithValue("@name", Name); cmd.AddParameterWithValue("@time", Time); cmd.AddParameterWithValue("@unit", Unit); cmd.AddParameterWithValue("@commander", Commander); cmd.AddParameterWithValue("@source", Source); cmd.AddParameterWithValue("@edsm_sync", EDSM_sync); cmd.AddParameterWithValue("@map_colour", MapColour); cmd.AddParameterWithValue("@x", X); cmd.AddParameterWithValue("@y", Y); cmd.AddParameterWithValue("@z", Z); cmd.AddParameterWithValue("@id_edsm_assigned", id_edsm_assigned); SQLiteDBClass.SQLNonQueryText(cn, cmd); using (DbCommand cmd2 = cn.CreateCommand("Select Max(id) as id from VisitedSystems")) { id = (long)SQLiteDBClass.SQLScalar(cn, cmd2); } return(true); } }
public bool Add() { using (SQLiteConnectionED cn = new SQLiteConnectionED()) { bool ret = Add(cn); return(ret); } }
private bool Delete(SQLiteConnectionED cn) { using (DbCommand cmd = cn.CreateCommand("DELETE FROM Bookmarks WHERE id = @id")) { cmd.AddParameterWithValue("@id", id); SQLiteDBClass.SQLNonQueryText(cn, cmd); bookmarks.RemoveAll(x => x.id == id); // remove from list any containing id. return(true); } }
internal static bool Exist(string name, DateTime time) { using (SQLiteConnectionED cn = new SQLiteConnectionED()) { using (DbCommand cmd = cn.CreateCommand("select * from VisitedSystems where name=@name and Time=@time Order by Time DESC Limit 1")) { cmd.AddParameterWithValue("@name", name); cmd.AddParameterWithValue("@time", time); DataSet ds = SQLiteDBClass.SQLQueryText(cn, cmd); return(!(ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)); } } }
public bool Update(SQLiteConnectionED cn, DbTransaction tn = null) { using (DbCommand cmd = cn.CreateCommand("Update TravelLogUnit set Name=@Name, Type=@type, size=@size, Path=@Path where ID=@id", tn)) { cmd.AddParameterWithValue("@ID", id); cmd.AddParameterWithValue("@Name", Name); cmd.AddParameterWithValue("@Type", type); cmd.AddParameterWithValue("@size", Size); cmd.AddParameterWithValue("@Path", Path); SQLiteDBClass.SQLNonQueryText(cn, cmd); return(true); } }
private bool Update(SQLiteConnectionED cn) { using (DbCommand cmd = cn.CreateCommand("Update SystemNote set Name=@Name, Time=@Time, Note=@Note where ID=@id")) { cmd.AddParameterWithValue("@ID", id); cmd.AddParameterWithValue("@Name", Name); cmd.AddParameterWithValue("@Note", Note); cmd.AddParameterWithValue("@Time", Time); SQLiteDBClass.SQLNonQueryText(cn, cmd); globalSystemNotes[Name.ToLower()] = this; return(true); } }
private bool Add(SQLiteConnectionED cn) { using (DbCommand cmd = cn.CreateCommand("Insert into SystemNote (Name, Time, Note) values (@name, @time, @note)")) { cmd.AddParameterWithValue("@name", Name); cmd.AddParameterWithValue("@time", Time); cmd.AddParameterWithValue("@note", Note); SQLiteDBClass.SQLNonQueryText(cn, cmd); using (DbCommand cmd2 = cn.CreateCommand("Select Max(id) as id from SystemNote")) { id = (long)SQLiteDBClass.SQLScalar(cn, cmd2); } globalSystemNotes[Name.ToLower()] = this; return(true); } }
static public VisitedSystemsClass GetLast() { List <VisitedSystemsClass> list = new List <VisitedSystemsClass>(); using (SQLiteConnectionED cn = new SQLiteConnectionED()) { using (DbCommand cmd = cn.CreateCommand("select * from VisitedSystems Order by Time DESC Limit 1")) { DataSet ds = SQLiteDBClass.SQLQueryText(cn, cmd); if (ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0) { return(null); } VisitedSystemsClass sys = new VisitedSystemsClass(ds.Tables[0].Rows[0]); return(sys); } } }
public static TravelLogUnit Get(string name) { using (SQLiteConnectionED cn = new SQLiteConnectionED()) { using (DbCommand cmd = cn.CreateCommand("SELECT * FROM TravelLogUnit WHERE Name = @name ORDER BY Id DESC")) { cmd.AddParameterWithValue("@name", name); using (DbDataReader reader = cmd.ExecuteReader()) { if (reader.Read()) { return(new TravelLogUnit(reader)); } } } } return(null); }
private bool Add(SQLiteConnectionED cn) { using (DbCommand cmd = cn.CreateCommand("Insert into TravelLogUnit (Name, type, size, Path) values (@name, @type, @size, @Path)")) { cmd.AddParameterWithValue("@name", Name); cmd.AddParameterWithValue("@type", type); cmd.AddParameterWithValue("@size", Size); cmd.AddParameterWithValue("@Path", Path); SQLiteDBClass.SQLNonQueryText(cn, cmd); using (DbCommand cmd2 = cn.CreateCommand("Select Max(id) as id from TravelLogUnit")) { id = (long)SQLiteDBClass.SQLScalar(cn, cmd2); } return(true); } }
public static List <string> GetAllNames() { List <string> names = new List <string>(); using (SQLiteConnectionED cn = new SQLiteConnectionED()) { using (DbCommand cmd = cn.CreateCommand("SELECT DISTINCT Name FROM TravelLogUnit")) { using (DbDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { names.Add((string)reader["Name"]); } } } } return(names); }
public static List <VisitedSystemsClass> GetAll(TravelLogUnit tlu) { List <VisitedSystemsClass> vsc = new List <VisitedSystemsClass>(); using (SQLiteConnectionED cn = new SQLiteConnectionED()) { using (DbCommand cmd = cn.CreateCommand("SELECT * FROM VisitedSystems WHERE Source = @source ORDER BY Time ASC")) { cmd.AddParameterWithValue("@source", tlu.id); using (DbDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { vsc.Add(new VisitedSystemsClass(reader)); } } } } return(vsc); }
public static VisitedSystemsClass GetLast(int cmdrid, DateTime before) { using (SQLiteConnectionED cn = new SQLiteConnectionED()) { using (DbCommand cmd = cn.CreateCommand("SELECT * FROM VisitedSystems WHERE Commander = @commander AND Time < @before ORDER BY Time DESC LIMIT 1")) { cmd.AddParameterWithValue("@commander", cmdrid); cmd.AddParameterWithValue("@before", before); using (DbDataReader reader = cmd.ExecuteReader()) { if (reader.Read()) { return(new VisitedSystemsClass(reader)); } } } } return(null); }
private bool Update(SQLiteConnectionED cn) { using (DbCommand cmd = cn.CreateCommand("Update VisitedSystems set Name=@Name, Time=@Time, Unit=@Unit, Commander=@commander, Source=@Source, edsm_sync=@edsm_sync, map_colour=@map_colour, X=@x, Y=@y, Z=@z, id_edsm_assigned=@id_edsm_assigned where ID=@id")) { cmd.AddParameterWithValue("@ID", id); cmd.AddParameterWithValue("@Name", Name); cmd.AddParameterWithValue("@Time", Time); cmd.AddParameterWithValue("@unit", Unit); cmd.AddParameterWithValue("@commander", Commander); cmd.AddParameterWithValue("@source", Source); cmd.AddParameterWithValue("@edsm_sync", EDSM_sync); cmd.AddParameterWithValue("@map_colour", MapColour); cmd.AddParameterWithValue("@x", X); cmd.AddParameterWithValue("@y", Y); cmd.AddParameterWithValue("@z", Z); cmd.AddParameterWithValue("@id_edsm_assigned", id_edsm_assigned); SQLiteDBClass.SQLNonQueryText(cn, cmd); return(true); } }
private bool Update(SQLiteConnectionED cn) { using (DbCommand cmd = cn.CreateCommand("Update Bookmarks set StarName=@sname, x = @xp, y = @yp, z = @zp, Time=@time, Heading = @head, Note=@note where ID=@id")) { cmd.AddParameterWithValue("@ID", id); cmd.AddParameterWithValue("@sname", StarName); cmd.AddParameterWithValue("@xp", x); cmd.AddParameterWithValue("@yp", y); cmd.AddParameterWithValue("@zp", z); cmd.AddParameterWithValue("@time", Time); cmd.AddParameterWithValue("@head", Heading); cmd.AddParameterWithValue("@note", Note); SQLiteDBClass.SQLNonQueryText(cn, cmd); bookmarks.RemoveAll(x => x.id == id); // remove from list any containing id. bookmarks.Add(this); return(true); } }
private bool Add(SQLiteConnectionED cn) { using (DbCommand cmd = cn.CreateCommand("Insert into Bookmarks (StarName, x, y, z, Time, Heading, Note) values (@sname, @xp, @yp, @zp, @time, @head, @note)")) { cmd.AddParameterWithValue("@sname", StarName); cmd.AddParameterWithValue("@xp", x); cmd.AddParameterWithValue("@yp", y); cmd.AddParameterWithValue("@zp", z); cmd.AddParameterWithValue("@time", Time); cmd.AddParameterWithValue("@head", Heading); cmd.AddParameterWithValue("@note", Note); SQLiteDBClass.SQLNonQueryText(cn, cmd); using (DbCommand cmd2 = cn.CreateCommand("Select Max(id) as id from Bookmarks")) { id = (long)SQLiteDBClass.SQLScalar(cn, cmd2); } bookmarks.Add(this); return(true); } }
static public List <TravelLogUnit> GetAll() { List <TravelLogUnit> list = new List <TravelLogUnit>(); using (SQLiteConnectionED cn = new SQLiteConnectionED()) { using (DbCommand cmd = cn.CreateCommand("select * from TravelLogUnit")) { DataSet ds = SQLiteDBClass.SQLQueryText(cn, cmd); if (ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0) { return(list); } foreach (DataRow dr in ds.Tables[0].Rows) { TravelLogUnit sys = new TravelLogUnit(dr); list.Add(sys); } return(list); } } }
private void NamedStars() // background thread.. run after timer tick { try // just in case someone tears us down.. { int lylimit = (int)(_starlimitly / _lastcamera.LastZoom); lylimit = Math.Max(lylimit, 20); //Console.Write("Look down " + _camera_paint_lookdown + " look forward " + _camera_paint_lookforward); //Console.Write("Repaint " + _repaintall + " Stars " + _starlimitly + " within " + lylimit + " "); int sqlylimit = lylimit * lylimit; // in squared distance limit from viewpoint Vector3 modcampos = _lastcamera.CameraPos; modcampos.Y = -modcampos.Y; StarGrid.TransFormInfo ti = new StarGrid.TransFormInfo(_resmat, _znear, _glControl.Width, _glControl.Height, sqlylimit, modcampos); SortedDictionary <float, StarGrid.InViewInfo> inviewlist = new SortedDictionary <float, StarGrid.InViewInfo>(new DuplicateKeyComparer <float>()); // who's in view, sorted by distance _stargrids.GetSystemsInView(ref inviewlist, 2000.0, ti); // consider all grids under 2k from current pos. float textscalingw = Math.Min(_starnamemaxly, Math.Max(_starnamesizely / _lastcamera.LastZoom, _starnameminly)); // per char float textscalingh = textscalingw * 4; float textoffset = .20F; float starsize = Math.Min(Math.Max(_lastcamera.LastZoom / 10F, 1.0F), 20F); // Normal stars are at 1F. //Console.WriteLine("Per char {0} h {1} sc {2} ", textscalingw, textscalingh, starsize); lock (deletelock) // can't delete during update, can paint.. { foreach (StarNames s in _starnames.Values) // all items not processed { s.todispose = true; // only items remaining will clear this } int limit = 1000; // max number of stars to show.. int painted = 0; using (SQLiteConnectionED cn = new SQLiteConnectionED()) { foreach (StarGrid.InViewInfo inview in inviewlist.Values) // for all in viewport, sorted by distance from camera position { StarNames sys = null; bool draw = false; if (_starnames.ContainsKey(inview.position)) // if already there.. { sys = _starnames[inview.position]; sys.todispose = false; // forced redraw due to change in orientation, or due to disposal draw = _flippedorzoomed || (_nameson && sys.newstar == null) || (_discson && sys.nametexture == null); painted++; } else if (painted < limit) { ISystem sc = _formmap.FindSystem(inview.position, cn); // with the open connection, find this star.. if (sc != null) // if can't be resolved, ignore { sys = new StarNames(sc); lock (_starnames) { _starnames.Add(inview.position, sys); // need to lock over add.. in case display is working } draw = true; painted++; } else { // Console.WriteLine("Failed to find " + pos.X + "," + pos.Y + "," + pos.Z); } } else { break; // no point doing any more.. Either the closest ones have been found, or a new one was painted } if (draw) { if (_nameson) { float width = textscalingw * sys.name.Length; Bitmap map; // now, delete is the only one who removed newtexture // and we are protected against delete.. if (sys.nametexture == null) // so see if newtexture is there { map = DatasetBuilder.DrawString(sys.name, Color.Orange, _starfont); sys.newnametexture = TexturedQuadData.FromBitmap(map, new PointData(sys.x, sys.y, sys.z), _lastcamera.Rotation, width, textscalingh, textoffset + width / 2, 0); } else { sys.newnamevertices = TexturedQuadData.CalcVertices(new PointData(sys.x, sys.y, sys.z), _lastcamera.Rotation, width, textscalingh, textoffset + width / 2, 0); } } if (_discson) { sys.newstar = new PointData(sys.x, sys.y, sys.z, starsize, Color.FromArgb(255, inview.colour & 255, (inview.colour >> 8) & 255, (inview.colour >> 16) & 255)); } } } } foreach (StarNames s in _starnames.Values) // only items above will remain. { s.inview = !s.todispose; // copy flag over, causes foreground to start removing them } } //Console.WriteLine(" " + (Environment.TickCount % 10000) + "Paint " + painted); } catch (Exception ex) { System.Diagnostics.Trace.WriteLine("Exception watcher: " + ex.Message); System.Diagnostics.Trace.WriteLine("Trace: " + ex.StackTrace); } _formmap.Invoke((System.Windows.Forms.MethodInvoker) delegate // kick the UI thread to process. { _formmap.ChangeNamedStars(); }); }
// called during start up and if refresh history is pressed public List <VisitedSystemsClass> ParseFiles(out string error, int defaultMapColour, Func <bool> cancelRequested, Action <int, string> updateProgress) { error = null; string datapath = GetNetLogPath(); if (datapath == null) { error = "Netlog directory not found!" + Environment.NewLine + "Specify location in settings tab"; return(null); } if (!Directory.Exists(datapath)) // if logfiles directory is not found { error = "Netlog directory is not present!" + Environment.NewLine + "Specify location in settings tab"; return(null); } List <VisitedSystemsClass> vsSystemsList = VisitedSystemsClass.GetAll(EDDConfig.Instance.CurrentCmdrID); List <VisitedSystemsClass> visitedSystems = new List <VisitedSystemsClass>(); Dictionary <string, TravelLogUnit> m_travelogUnits = TravelLogUnit.GetAll().Where(t => t.type == 1).GroupBy(t => t.Name).Select(g => g.First()).ToDictionary(t => t.Name); Dictionary <string, List <VisitedSystemsClass> > vsc_lookup = VisitedSystemsClass.GetAll().GroupBy(v => v.Unit).ToDictionary(g => g.Key, g => g.ToList()); if (vsSystemsList != null) { foreach (VisitedSystemsClass vs in vsSystemsList) { if (visitedSystems.Count == 0) { visitedSystems.Add(vs); } else if (!visitedSystems.Last <VisitedSystemsClass>().Name.Equals(vs.Name)) // Avoid duplicate if times exist in same system from different files. { visitedSystems.Add(vs); } else { VisitedSystemsClass vs2 = (VisitedSystemsClass)visitedSystems.Last <VisitedSystemsClass>(); if (vs2.id != vs.id) { vs.Commander = -2; // Move to dupe user vs.Update(); } } } } // order by file write time so we end up on the last one written FileInfo[] allFiles = Directory.EnumerateFiles(datapath, "netLog.*.log", SearchOption.AllDirectories).Select(f => new FileInfo(f)).OrderBy(p => p.LastWriteTime).ToArray(); List <NetLogFileReader> readersToUpdate = new List <NetLogFileReader>(); for (int i = 0; i < allFiles.Length; i++) { FileInfo fi = allFiles[i]; var reader = OpenFileReader(fi, m_travelogUnits, vsc_lookup); if (!m_travelogUnits.ContainsKey(reader.TravelLogUnit.Name)) { m_travelogUnits[reader.TravelLogUnit.Name] = reader.TravelLogUnit; reader.TravelLogUnit.Add(); } if (!netlogreaders.ContainsKey(reader.TravelLogUnit.Name)) { netlogreaders[reader.TravelLogUnit.Name] = lastnfi; } if (reader.filePos != fi.Length || i == allFiles.Length - 1) // File not already in DB, or is the last one { readersToUpdate.Add(reader); } } using (SQLiteConnectionED cn = new SQLiteConnectionED()) { for (int i = 0; i < readersToUpdate.Count; i++) { NetLogFileReader reader = readersToUpdate[i]; updateProgress(i * 100 / readersToUpdate.Count, reader.TravelLogUnit.Name); using (DbTransaction tn = cn.BeginTransaction()) { foreach (VisitedSystemsClass ps in reader.ReadSystems(cancelRequested)) { ps.EDSM_sync = false; ps.MapColour = defaultMapColour; ps.Commander = EDDConfig.Instance.CurrentCmdrID; ps.Add(cn, tn); visitedSystems.Add(ps); } reader.TravelLogUnit.Update(cn, tn); tn.Commit(); } if (updateProgress != null) { updateProgress((i + 1) * 100 / readersToUpdate.Count, reader.TravelLogUnit.Name); } lastnfi = reader; } } return(visitedSystems); }