Пример #1
0
        static public List <JournalEntry> GetAll(int commander         = -999, DateTime?after = null, DateTime?before = null,
                                                 JournalTypeEnum[] ids = null, DateTime?allidsafter = null)
        {
            Dictionary <long, TravelLogUnit> tlus = TravelLogUnit.GetAll().ToDictionary(t => t.id);

            List <JournalEntry> list = new List <JournalEntry>();

            using (SQLiteConnectionUser cn = new SQLiteConnectionUser(utc: true))
            {
                using (DbCommand cmd = cn.CreateCommand("select * from JournalEntries"))
                {
                    string cnd = "";
                    if (commander != -999)
                    {
                        cnd = cnd.AppendPrePad("CommanderID = @commander", " and ");
                        cmd.AddParameterWithValue("@commander", commander);
                    }
                    if (after != null)
                    {
                        cnd = cnd.AppendPrePad("EventTime >= @after", " and ");
                        cmd.AddParameterWithValue("@after", after.Value);
                    }
                    if (before != null)
                    {
                        cnd = cnd.AppendPrePad("EventTime <= @before", " and ");
                        cmd.AddParameterWithValue("@before", before.Value);
                    }
                    if (ids != null)
                    {
                        int[] array = Array.ConvertAll(ids, x => (int)x);
                        if (allidsafter != null)
                        {
                            cmd.AddParameterWithValue("@idafter", allidsafter.Value);
                            cnd = cnd.AppendPrePad("(EventTypeId in (" + string.Join(",", array) + ") Or EventTime>=@idafter)", " and ");
                        }
                        else
                        {
                            cnd = cnd.AppendPrePad("EventTypeId in (" + string.Join(",", array) + ")", " and ");
                        }
                    }

                    if (cnd.HasChars())
                    {
                        cmd.CommandText += " where " + cnd;
                    }

                    cmd.CommandText += " Order By EventTime ASC";

                    DataSet ds = cn.SQLQueryText(cmd);

                    if (ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
                    {
                        return(list);
                    }

                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        JournalEntry sys = JournalEntry.CreateJournalEntry(dr);
                        sys.beta = tlus.ContainsKey(sys.TLUId) ? tlus[sys.TLUId].Beta : false;
                        list.Add(sys);
                    }

                    return(list);
                }
            }
        }
Пример #2
0
        private void FillInSystemFromDBInt(HistoryEntry syspos, ISystem edsmsys, SQLiteConnectionUser uconn, DbTransaction utn)        // call to fill in ESDM data for entry, and also fills in all others pointing to the system object
        {
            List <HistoryEntry> alsomatching = new List <HistoryEntry>();

            foreach (HistoryEntry he in historylist)       // list of systems in historylist using the same system object
            {
                if (Object.ReferenceEquals(he.System, syspos.System))
                {
                    alsomatching.Add(he);
                }
            }

            if (edsmsys != null)
            {
                ISystem oldsys = syspos.System;

                bool updateedsmid = oldsys.EDSMID <= 0 && edsmsys.EDSMID > 0;
                bool updatesyspos = !oldsys.HasCoordinate && edsmsys.HasCoordinate;
                bool updatename   = oldsys.HasCoordinate && edsmsys.HasCoordinate &&
                                    oldsys.Distance(edsmsys) < 0.1 &&
                                    !String.Equals(edsmsys.Name, oldsys.Name, StringComparison.InvariantCultureIgnoreCase) &&
                                    edsmsys.UpdateDate > syspos.EventTimeUTC;

                ISystem newsys = new SystemClass
                {
                    Name            = updatename ? edsmsys.Name : oldsys.Name,
                    X               = updatesyspos ? edsmsys.X : oldsys.X,
                    Y               = updatesyspos ? edsmsys.Y : oldsys.Y,
                    Z               = updatesyspos ? edsmsys.Z : oldsys.Z,
                    EDSMID          = updateedsmid ? edsmsys.EDSMID : oldsys.EDSMID,
                    SystemAddress   = oldsys.SystemAddress ?? edsmsys.SystemAddress,
                    Allegiance      = oldsys.Allegiance == EDAllegiance.Unknown ? edsmsys.Allegiance : oldsys.Allegiance,
                    Government      = oldsys.Government == EDGovernment.Unknown ? edsmsys.Government : oldsys.Government,
                    Population      = oldsys.Government == EDGovernment.Unknown ? edsmsys.Population : oldsys.Population,
                    PrimaryEconomy  = oldsys.PrimaryEconomy == EDEconomy.Unknown ? edsmsys.PrimaryEconomy : oldsys.PrimaryEconomy,
                    Security        = oldsys.Security == EDSecurity.Unknown ? edsmsys.Security : oldsys.Security,
                    State           = oldsys.State == EDState.Unknown ? edsmsys.State : oldsys.State,
                    Faction         = oldsys.Faction ?? edsmsys.Faction,
                    CommanderCreate = edsmsys.CommanderCreate,
                    CommanderUpdate = edsmsys.CommanderUpdate,
                    CreateDate      = edsmsys.CreateDate,
                    EDDBID          = edsmsys.EDDBID,
                    EDDBUpdatedAt   = edsmsys.EDDBUpdatedAt,
                    GridID          = edsmsys.GridID,
                    NeedsPermit     = edsmsys.NeedsPermit,
                    RandomID        = edsmsys.RandomID,
                    UpdateDate      = edsmsys.UpdateDate,
                    SystemNote      = edsmsys.SystemNote,
                    status          = SystemStatusEnum.EDSM
                };

                foreach (HistoryEntry he in alsomatching)       // list of systems in historylist using the same system object
                {
                    bool updatepos = (he.EntryType == JournalTypeEnum.FSDJump || he.EntryType == JournalTypeEnum.Location) && updatesyspos;

                    if (updatepos || updateedsmid)
                    {
                        JournalEntry.UpdateEDSMIDPosJump(he.Journalid, edsmsys, updatepos, -1, uconn, utn);   // update pos and edsmid, jdist not updated
                    }
                    he.System = newsys;
                }
            }
            else
            {
                foreach (HistoryEntry he in alsomatching)      // list of systems in historylist using the same system object
                {
                    he.System.EDSMID = -1;                     // can't do it
                }
            }
        }
Пример #3
0
        public static HistoryList LoadHistory(EDJournalClass journalmonitor, Func <bool> cancelRequested, Action <int, string> reportProgress,
                                              string NetLogPath           = null,
                                              bool ForceNetLogReload      = false,
                                              bool ForceJournalReload     = false,
                                              int CurrentCommander        = Int32.MinValue,
                                              bool Keepuievents           = true,
                                              int fullhistoryloaddaylimit = 0
                                              )
        {
            HistoryList hist = new HistoryList();

            if (CurrentCommander >= 0)
            {
                journalmonitor.ParseJournalFiles(() => cancelRequested(), (p, s) => reportProgress(p, s), forceReload: ForceJournalReload);   // Parse files stop monitor..

                if (NetLogPath != null)
                {
                    string errstr = null;
                    NetLogClass.ParseFiles(NetLogPath, out errstr, EliteConfigInstance.InstanceConfig.DefaultMapColour, () => cancelRequested(), (p, s) => reportProgress(p, s), ForceNetLogReload, currentcmdrid: CurrentCommander);
                }
            }

            Trace.WriteLine(BaseUtils.AppTicks.TickCountLap() + " Files read ");

            reportProgress(-1, "Reading Database");

            List <JournalEntry> jlist;

            if (fullhistoryloaddaylimit > 0)
            {
                jlist = JournalEntry.GetAll(CurrentCommander,
                                            ids: JournalEntry.EssentialEvents,
                                            allidsafter: DateTime.UtcNow.Subtract(new TimeSpan(fullhistoryloaddaylimit, 0, 0, 0))
                                            ).OrderBy(x => x.EventTimeUTC).ThenBy(x => x.Id).ToList();
            }
            else
            {
                jlist = JournalEntry.GetAll(CurrentCommander).OrderBy(x => x.EventTimeUTC).ThenBy(x => x.Id).ToList();
            }

            Trace.WriteLine(BaseUtils.AppTicks.TickCountLap() + " Database read " + jlist.Count);

            List <Tuple <JournalEntry, HistoryEntry> > jlistUpdated = new List <Tuple <JournalEntry, HistoryEntry> >();

            using (SQLiteConnectionSystem conn = new SQLiteConnectionSystem())
            {
                HistoryEntry prev  = null;
                JournalEntry jprev = null;

                reportProgress(-1, "Creating History");

                foreach (JournalEntry je in jlist)
                {
                    if (MergeEntries(jprev, je))        // if we merge.. we may have updated info, so reprint.
                    {
                        //jprev.FillInformation(out prev.EventSummary, out prev.EventDescription, out prev.EventDetailedInfo);    // need to keep this up to date..
                        continue;
                    }

                    if (je.IsUIEvent && !Keepuievents)              // filter out any UI events
                    {
                        //System.Diagnostics.Debug.WriteLine("**** Filter out " + je.EventTypeStr + " on " + je.EventTimeLocal.ToString());
                        continue;
                    }

                    bool         journalupdate = false;
                    HistoryEntry he            = HistoryEntry.FromJournalEntry(je, prev, out journalupdate, conn);

                    prev  = he;
                    jprev = je;

                    hist.historylist.Add(he);

                    if (journalupdate)
                    {
                        jlistUpdated.Add(new Tuple <JournalEntry, HistoryEntry>(je, he));
                        Debug.WriteLine("Queued update requested {0} {1}", he.System.EDSMID, he.System.Name);
                    }
                }
            }

            if (jlistUpdated.Count > 0)
            {
                reportProgress(-1, "Updating journal entries");

                using (SQLiteConnectionUser conn = new SQLiteConnectionUser(utc: true))
                {
                    using (DbTransaction txn = conn.BeginTransaction())
                    {
                        foreach (Tuple <JournalEntry, HistoryEntry> jehe in jlistUpdated)
                        {
                            JournalEntry je = jehe.Item1;
                            HistoryEntry he = jehe.Item2;

                            double dist        = (je is JournalFSDJump) ? (je as JournalFSDJump).JumpDist : 0;
                            bool   updatecoord = (je is JournalLocOrJump) ? (!(je as JournalLocOrJump).HasCoordinate && he.System.HasCoordinate) : false;

                            Debug.WriteLine("Push update {0} {1} to JE {2} HE {3}", he.System.EDSMID, he.System.Name, je.Id, he.Indexno);
                            JournalEntry.UpdateEDSMIDPosJump(je.Id, he.System, updatecoord, dist, conn, txn);
                        }

                        txn.Commit();
                    }
                }
            }

            // now database has been updated due to initial fill, now fill in stuff which needs the user database

            hist.CommanderId = CurrentCommander;

            reportProgress(-1, "Updating user statistics");

            hist.ProcessUserHistoryListEntries(h => h.ToList());      // here, we update the DBs in HistoryEntry and any global DBs in historylist

            reportProgress(-1, "Done");

            return(hist);
        }
Пример #4
0
        /// <summary>
        /// Loads the commanders from storage
        /// </summary>
        /// <param name="write">True if any migrated commanders should be written to storage</param>
        /// <param name="conn">SQLite connection</param>
        public static void Load(bool write = true, SQLiteConnectionUser conn = null)
        {
            if (_commandersDict == null)
            {
                _commandersDict = new Dictionary <int, EDCommander>();
            }

            lock (_commandersDict)
            {
                _commandersDict.Clear();

                var cmdrs = SQLiteConnectionUser.GetCommanders(conn);
                int maxnr = cmdrs.Count == 0 ? 0 : cmdrs.Max(c => c.Nr);

                foreach (EDCommander cmdr in cmdrs)
                {
                    if (!cmdr.Deleted)
                    {
                        _commandersDict[cmdr.Nr] = cmdr;
                    }
                }

                if (_commandersDict.Count == 0)
                {
                    if (write)
                    {
                        Create("Jameson (Default)");
                    }
                    else
                    {
                        _commandersDict[maxnr + 1] = new EDCommander(maxnr + 1, "Jameson (Default)", "", false, false, false, false, "", "");
                    }
                }
            }

            // For  some people sharing their user DB between different computers and having different paths to their journals on those computers.
            if (File.Exists(Path.Combine(EliteDangerousCore.EliteConfigInstance.InstanceOptions.AppDataDirectory, "CommanderPaths.json")))
            {
                JObject jo;

                using (Stream stream = File.OpenRead(Path.Combine(EliteDangerousCore.EliteConfigInstance.InstanceOptions.AppDataDirectory, "CommanderPaths.json")))
                {
                    using (StreamReader reader = new StreamReader(stream))
                    {
                        using (JsonTextReader jreader = new JsonTextReader(reader))
                        {
                            jo = JObject.Load(jreader);
                        }
                    }
                }

                foreach (var kvp in jo)
                {
                    string      name  = kvp.Key;
                    JObject     props = kvp.Value as JObject;
                    EDCommander cmdr  = GetCommander(name);
                    if (props != null && cmdr != null)
                    {
                        cmdr.JournalDir = props["JournalDir"].Str(cmdr.JournalDir);
                    }
                }
            }
        }
Пример #5
0
 private void buttonBodyClasses_CheckedChanged(object sender, EventArgs e)
 {
     SQLiteConnectionUser.PutSettingBool(DbShowClasses, checkBoxBodyClasses.Checked);
     HistoryChanged(current_historylist);
 }
Пример #6
0
 internal void SetEdsmSync(SQLiteConnectionUser cn, DbTransaction txn = null)
 {
     UpdateSyncFlagBit(SyncFlags.EDSM, true, SyncFlags.NoBit, false, cn, txn);
 }
        private void UpdateSyncFlagBit(SyncFlags bit1, bool value1, SyncFlags bit2, bool value2, SQLiteConnectionUser cn, DbTransaction txn = null)
        {
            if (value1)
            {
                Synced |= (int)bit1;
            }
            else
            {
                Synced &= ~(int)bit1;
            }

            if (value2)
            {
                Synced |= (int)bit2;
            }
            else
            {
                Synced &= ~(int)bit2;
            }

            using (DbCommand cmd = cn.CreateCommand("Update JournalEntries set Synced = @sync where ID=@journalid", txn))
            {
                cmd.AddParameterWithValue("@journalid", Id);
                cmd.AddParameterWithValue("@sync", Synced);
                System.Diagnostics.Trace.WriteLine(string.Format("Update sync flag ID {0} with {1}", Id, Synced));
                cmd.ExecuteNonQuery();
            }
        }
Пример #8
0
        //EDDiscovery Init calls this
        public void CreateTabs(EDDiscoveryForm edf)
        {
            eddiscovery = edf;

            string majortabs = SQLiteConnectionUser.GetSettingString("MajorTabControlList", "");

            string[] majortabnames = null;
            int[]    tabctrl;

            if (!majortabs.RestoreArrayFromString(out tabctrl) || tabctrl.Length == 0 || (tabctrl.Length % 2) != 1) // need it odd as we have an index tab as first
            {
                tabctrl = new int[] { 0, -1, 0,                                                                     // reset..
                                      (int)PanelInformation.PanelIDs.Route, 0,
                                      (int)PanelInformation.PanelIDs.Expedition, 0,
                                      (int)PanelInformation.PanelIDs.Settings, 0,
                                      (int)PanelInformation.PanelIDs.PanelSelector, 0 };
            }
            else
            {
                majortabnames = SQLiteConnectionUser.GetSettingString("MajorTabControlName", "").Split(';'); // if its okay, load the name list
            }
            TabPage history = TabPages[0];                                                                   // remember history page, remove

            TabPages.Clear();

            UserControls.UserControlHistory uch = history.Controls[0] as UserControls.UserControlHistory;
            travelgrid = uch.GetTravelGrid;     // remember travel grid globally for later

            bool donehistory = false;

            for (int i = 1; i < tabctrl.Length; i += 2)
            {
                int    nameindex = (i - 1) / 2;
                string name      = majortabnames != null && nameindex < majortabnames.Length && majortabnames[nameindex].Length > 0 ? majortabnames[nameindex] : null;

                if (tabctrl[i] != -1)       // this means UserControlHistory, which is a special one
                {
                    try
                    {
                        PanelInformation.PanelIDs p = (PanelInformation.PanelIDs)tabctrl[i];
                        CreateTab(p, name, tabctrl[i + 1], TabPages.Count, false); // no need the theme, will be themed as part of overall load
                                                                                   // may fail if p is crap, then just ignore
                    }
                    catch { }                                                      // paranoia in case tabctrl number is crappy.
                }
                else if (!donehistory)                                             // just double check for repeats
                {
                    if (name != null)                                              // set name. if set.
                    {
                        history.Text = name;
                    }
                    TabPages.Add(history); // add back in right place
                    donehistory = true;
                }
            }

            if (!donehistory)                                                                         // just in case its missing.. be something up if it is.
            {
                TabPages.Add(history);                                                                // add back in right place
            }
            uch.Dock     = System.Windows.Forms.DockStyle.Fill;                                       // Crucial ! uccb has to be fill, even though the VS designer does not indicate you need to set it.. copied from designer code
            uch.Location = new System.Drawing.Point(3, 3);
            uch.Init(eddiscovery, null, UserControls.UserControlCommonBase.DisplayNumberHistoryGrid); // and init at this point with 0 as dn

            EnsureMajorTabIsPresent(PanelInformation.PanelIDs.PanelSelector, true);                   // just in case it disappears due to weirdness or debugging

            if (tabctrl.Length > 0 && tabctrl[0] >= 0 && tabctrl[0] < TabPages.Count)                 // make sure external data does not crash us
            {
                SelectedIndex = tabctrl[0];
            }
        }
        public override void Init()
        {
            computer = new StarDistanceComputer();

            slideMaxItems.Value = maxitems = SQLiteConnectionUser.GetSettingInt(DbSave + "MapMaxItems", maxitems);

            textMaxRadius.ValueNoChange = SQLiteConnectionUser.GetSettingDouble(DbSave + "MapMax", defaultMapMaxRadius);
            textMinRadius.ValueNoChange = SQLiteConnectionUser.GetSettingDouble(DbSave + "MapMin", defaultMapMinRadius);
            textMinRadius.SetComparitor(textMaxRadius, -2);     // need to do this after values are set
            textMaxRadius.SetComparitor(textMinRadius, 2);

            slidetimer          = new System.Windows.Forms.Timer();
            slidetimer.Interval = 500;
            slidetimer.Tick    += Slidetimer_Tick;

            var style = chartMap.ChartAreas[0].Area3DStyle;

            style.Rotation    = Math.Min(180, Math.Max(-180, style.Rotation - (Convert.ToInt32(SQLiteConnectionUser.GetSettingDouble(DbSave + "MapRotationX", xr)))));
            style.Inclination = Math.Min(90, Math.Max(-90, style.Inclination + (Convert.ToInt32(SQLiteConnectionUser.GetSettingDouble(DbSave + "MapRotationY", yr)))));
        }
Пример #10
0
 private int GetSettingInt(string key)
 {
     return(GetSetting <int>(key, (k, d) => SQLiteConnectionUser.GetSettingInt(k, d)));
 }
Пример #11
0
 private bool PutSettingInt(string key, int value)
 {
     return(PutSetting <int>(key, value, (k, v) => SQLiteConnectionUser.PutSettingInt(k, v)));
 }
Пример #12
0
 public void SetEGOSync(SQLiteConnectionUser cn = null, DbTransaction txn = null)
 {
     UpdateSyncFlagBit(SyncFlags.EGO, true, SyncFlags.NoBit, false, cn, txn);
 }
Пример #13
0
 public void ClearStartEndFlag(SQLiteConnectionUser cn = null, DbTransaction txn = null)
 {
     UpdateSyncFlagBit(SyncFlags.StartMarker, false, SyncFlags.StopMarker, false, cn, txn);
 }
Пример #14
0
 public void CloseDown()
 {
     actionrunasync.WaitTillFinished(10000);
     SQLiteConnectionUser.PutSettingString("UserGlobalActionVars", PersistentVariables.ToString());
 }
Пример #15
0
        static public void ParseFiles(string datapath, out string error, int defaultMapColour, Func <bool> cancelRequested, Action <int, string> updateProgress, bool forceReload = false, Dictionary <string, NetLogFileReader> netlogreaders = null, int currentcmdrid = -1)
        {
            error = null;

            if (datapath == null)
            {
                error = "Netlog directory not set!";
                return;
            }

            if (!Directory.Exists(datapath))   // if logfiles directory is not found
            {
                error = "Netlog directory is not present!";
                return;
            }

            if (netlogreaders == null)
            {
                netlogreaders = new Dictionary <string, NetLogFileReader>();
            }

            if (currentcmdrid < 0)
            {
                currentcmdrid = EDCommander.CurrentCmdrID;
            }

            // TLUs
            List <TravelLogUnit> tlus = TravelLogUnit.GetAll();
            Dictionary <string, TravelLogUnit>            netlogtravelogUnits  = tlus.Where(t => t.type == TravelLogUnit.NetLogType).GroupBy(t => t.Name).Select(g => g.First()).ToDictionary(t => t.Name);
            Dictionary <long, string>                     travellogunitid2name = netlogtravelogUnits.Values.ToDictionary(t => t.id, t => t.Name);
            Dictionary <string, List <JournalLocOrJump> > vsc_lookup           = JournalEntry.GetAll().OfType <JournalLocOrJump>().GroupBy(v => v.TLUId).Where(g => travellogunitid2name.ContainsKey(g.Key)).ToDictionary(g => travellogunitid2name[g.Key], g => g.ToList());

            // list of systems in journal, sorted by time
            List <JournalLocOrJump> vsSystemsEnts = JournalEntry.GetAll(currentcmdrid).OfType <JournalLocOrJump>().OrderBy(j => j.EventTimeUTC).ToList();

            // 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, netlogtravelogUnits, vsc_lookup, netlogreaders);

                if (!netlogtravelogUnits.ContainsKey(reader.TravelLogUnit.Name))
                {
                    netlogtravelogUnits[reader.TravelLogUnit.Name] = reader.TravelLogUnit;
                    reader.TravelLogUnit.Add();
                }

                if (!netlogreaders.ContainsKey(reader.TravelLogUnit.Name))
                {
                    netlogreaders[reader.TravelLogUnit.Name] = reader;
                }

                if (forceReload)
                {
                    // Force a reload of the travel log
                    reader.TravelLogUnit.Size = 0;
                }

                if (reader.filePos != fi.Length || i == allFiles.Length - 1)  // File not already in DB, or is the last one
                {
                    readersToUpdate.Add(reader);
                }
            }

            for (int i = 0; i < readersToUpdate.Count; i++)
            {
                using (SQLiteConnectionUser cn = new SQLiteConnectionUser(utc: true))
                {
                    int ji = 0;

                    NetLogFileReader reader = readersToUpdate[i];
                    updateProgress(i * 100 / readersToUpdate.Count, reader.TravelLogUnit.Name);

                    using (DbTransaction tn = cn.BeginTransaction())
                    {
                        foreach (JObject jo in reader.ReadSystems(cancelRequested, currentcmdrid))
                        {
                            jo["EDDMapColor"] = defaultMapColour;

                            JournalLocOrJump je = new JournalFSDJump(jo);
                            je.SetTLUCommander(reader.TravelLogUnit.id, currentcmdrid);

                            while (ji < vsSystemsEnts.Count && vsSystemsEnts[ji].EventTimeUTC < je.EventTimeUTC)
                            {
                                ji++;   // move to next entry which is bigger in time or equal to ours.
                            }

                            JournalLocOrJump prev = (ji > 0 && (ji - 1) < vsSystemsEnts.Count) ? vsSystemsEnts[ji - 1] : null;
                            JournalLocOrJump next = ji < vsSystemsEnts.Count ? vsSystemsEnts[ji] : null;

                            bool previssame = (prev != null && prev.StarSystem.Equals(je.StarSystem, StringComparison.CurrentCultureIgnoreCase) && (!prev.HasCoordinate || !je.HasCoordinate || (prev.StarPos - je.StarPos).LengthSquared < 0.01));
                            bool nextissame = (next != null && next.StarSystem.Equals(je.StarSystem, StringComparison.CurrentCultureIgnoreCase) && (!next.HasCoordinate || !je.HasCoordinate || (next.StarPos - je.StarPos).LengthSquared < 0.01));

                            // System.Diagnostics.Debug.WriteLine("{0} {1} {2}", ji, vsSystemsEnts[ji].EventTimeUTC, je.EventTimeUTC);

                            if (!(previssame || nextissame))
                            {
                                je.Add(jo, cn, tn);
                                System.Diagnostics.Debug.WriteLine("Add {0} {1}", je.EventTimeUTC, jo.ToString());
                            }
                        }

                        tn.Commit();

                        reader.TravelLogUnit.Update();
                    }

                    if (updateProgress != null)
                    {
                        updateProgress((i + 1) * 100 / readersToUpdate.Count, reader.TravelLogUnit.Name);
                    }
                }
            }
        }
Пример #16
0
 public override void Closing()
 {
     SQLiteConnectionUser.PutSettingInt(DbSelectedSave, tabStrip.SelectedIndex);
     tabStrip.Close();
 }
        static public MaterialCommoditiesList Process(JournalEntry je, MaterialCommoditiesList oldml, SQLiteConnectionUser conn,
                                                      bool clearzeromaterials, bool clearzerocommodities)
        {
            MaterialCommoditiesList newmc = (oldml == null) ? new MaterialCommoditiesList() : oldml;

            if (je is IMaterialCommodityJournalEntry)
            {
                IMaterialCommodityJournalEntry e = je as IMaterialCommodityJournalEntry;
                newmc = newmc.Clone(clearzeromaterials, clearzerocommodities);          // so we need a new one
                e.MaterialList(newmc, conn);
            }

            return(newmc);
        }
Пример #18
0
        public ActionController(EDDiscoveryForm frm, EDDiscoveryController ctrl, System.Drawing.Icon ic) : base(frm, ic)
        {
            discoveryform       = frm;
            discoverycontroller = ctrl;

            #if !NO_SYSTEM_SPEECH
            // Windows TTS (2000 and above). Speech *recognition* will be Version.Major >= 6 (Vista and above)
            if (Environment.OSVersion.Platform == PlatformID.Win32NT && Environment.OSVersion.Version.Major >= 5 && !EDDOptions.Instance.NoSound)
            {
                audiodriverwave   = new AudioExtensions.AudioDriverCSCore(EDDConfig.Instance.DefaultWaveDevice);
                audiodriverspeech = new AudioExtensions.AudioDriverCSCore(EDDConfig.Instance.DefaultVoiceDevice);
                speechsynth       = new AudioExtensions.SpeechSynthesizer(new AudioExtensions.WindowsSpeechEngine());
                voicerecon        = new AudioExtensions.VoiceRecognitionWindows();
            }
            else
            {
                audiodriverwave   = new AudioExtensions.AudioDriverDummy();
                audiodriverspeech = new AudioExtensions.AudioDriverDummy();
                speechsynth       = new AudioExtensions.SpeechSynthesizer(new AudioExtensions.DummySpeechEngine());
                voicerecon        = new AudioExtensions.VoiceRecognitionDummy();
            }
#else
            audiodriverwave   = new AudioExtensions.AudioDriverDummy();
            audiodriverspeech = new AudioExtensions.AudioDriverDummy();
            speechsynth       = new AudioExtensions.SpeechSynthesizer(new AudioExtensions.DummySpeechEngine());
            voicerecon        = new AudioExtensions.VoiceRecognitionDummy();
#endif
            audioqueuewave   = new AudioExtensions.AudioQueue(audiodriverwave);
            audioqueuespeech = new AudioExtensions.AudioQueue(audiodriverspeech);

            frontierbindings    = new BindingsFile();
            inputdevices        = new DirectInputDevices.InputDeviceList(a => discoveryform.BeginInvoke(a));
            inputdevicesactions = new Actions.ActionsFromInputDevices(inputdevices, frontierbindings, this);

            frontierbindings.LoadBindingsFile();
            //System.Diagnostics.Debug.WriteLine("Bindings" + frontierbindings.ListBindings());
            //System.Diagnostics.Debug.WriteLine("Key Names" + frontierbindings.ListKeyNames("{","}"));

            voicerecon.SpeechRecognised    += Voicerecon_SpeechRecognised;
            voicerecon.SpeechNotRecognised += Voicerecon_SpeechNotRecognised;

            ConditionFunctions.GetCFH = DefaultGetCFH;

            LoadPeristentVariables(new ConditionVariables(SQLiteConnectionUser.GetSettingString("UserGlobalActionVars", ""), ConditionVariables.FromMode.MultiEntryComma));

            lasteditedpack = SQLiteConnectionUser.GetSettingString("ActionPackLastFile", "");

            ActionBase.AddCommand("Bookmarks", typeof(ActionBookmarks), ActionBase.ActionType.Cmd);
            ActionBase.AddCommand("Commodities", typeof(ActionCommodities), ActionBase.ActionType.Cmd);
            ActionBase.AddCommand("EliteBindings", typeof(ActionEliteBindings), ActionBase.ActionType.Cmd);
            ActionBase.AddCommand("Event", typeof(ActionEventCmd), ActionBase.ActionType.Cmd);
            ActionBase.AddCommand("Historytab", typeof(ActionHistoryTab), ActionBase.ActionType.Cmd);
            ActionBase.AddCommand("Key", typeof(ActionKeyED), ActionBase.ActionType.Cmd);       // override key
            ActionBase.AddCommand("Ledger", typeof(ActionLedger), ActionBase.ActionType.Cmd);
            ActionBase.AddCommand("Materials", typeof(ActionMaterials), ActionBase.ActionType.Cmd);
            ActionBase.AddCommand("MenuItem", typeof(ActionMenuItem), ActionBase.ActionType.Cmd);
            ActionBase.AddCommand("Perform", typeof(ActionPerform), ActionBase.ActionType.Cmd);
            ActionBase.AddCommand("Play", typeof(ActionPlay), ActionBase.ActionType.Cmd);
            ActionBase.AddCommand("Popout", typeof(ActionPopout), ActionBase.ActionType.Cmd);
            ActionBase.AddCommand("ProgramWindow", typeof(ActionProgramwindow), ActionBase.ActionType.Cmd);
            ActionBase.AddCommand("Scan", typeof(ActionScan), ActionBase.ActionType.Cmd);
            ActionBase.AddCommand("Ship", typeof(ActionShip), ActionBase.ActionType.Cmd);
            ActionBase.AddCommand("Star", typeof(ActionStar), ActionBase.ActionType.Cmd);
            ActionBase.AddCommand("Timer", typeof(ActionTimer), ActionBase.ActionType.Cmd);
        }
Пример #19
0
        //dist >0 to update
        internal static void UpdateEDSMIDPosJump(long journalid, ISystem system, bool jsonpos, double dist, SQLiteConnectionUser cn, DbTransaction tn = null)
        {
            bool updatejson = jsonpos || dist > 0;

            JObject jo = updatejson ? GetJson(journalid, cn, tn) : null;       // if JSON pos update, get it, else null

            // no need to JSON read if just doing an EDSM update
            if (jo != null || !updatejson)        // if got it, or no pos
            {
                if (jsonpos)
                {
                    jo["StarPos"] = new JArray()
                    {
                        system.X, system.Y, system.Z
                    };
                    jo["StarPosFromEDSM"] = true;
                }

                if (dist > 0)
                {
                    jo["JumpDist"] = dist;
                }

                using (DbCommand cmd2 = cn.CreateCommand("Update JournalEntries set EdsmId = @EdsmId where ID = @ID", tn))
                {
                    if (updatejson)
                    {
                        cmd2.CommandText = "Update JournalEntries set EventData = @EventData, EdsmId = @EdsmId where ID = @ID";
                        cmd2.AddParameterWithValue("@EventData", jo.ToString());
                        System.Diagnostics.Trace.WriteLine(string.Format("Update journal ID {0} with pos/edsmid {1} dist {2}", journalid, system.EDSMID, dist));
                    }
                    else
                    {
                        System.Diagnostics.Trace.WriteLine(string.Format("Update journal ID {0} with edsmid {1}", journalid, system.EDSMID));
                    }

                    cmd2.AddParameterWithValue("@ID", journalid);
                    cmd2.AddParameterWithValue("@EdsmId", system.EDSMID);

                    cmd2.ExecuteNonQuery();
                }
            }
        }
Пример #20
0
        private void FetcherThreadProc()
        {
            bool jupdate = false;

            LastEventTime  = DateTime.UtcNow;
            FirstEventTime = LastEventTime;

            int waittime = 2000; // Max 1 request every 2 seconds, with a backoff if the rate limit is hit

            if (EDSMRequestBackoffTime > DateTime.UtcNow)
            {
                waittime = (int)Math.Min(EDSMMaxLogAgeMinutes * 60000, Math.Min(BackoffInterval.TotalSeconds * 1000, EDSMRequestBackoffTime.Subtract(DateTime.UtcNow).TotalSeconds * 1000));
            }

            while (!ExitRequested.WaitOne(waittime))
            {
                EDSMClass edsm = new EDSMClass {
                    apiKey = Commander.APIKey, commanderName = Commander.EdsmName
                };
                List <HistoryEntry> edsmlogs     = null;
                DateTime            logstarttime = DateTime.MinValue;
                DateTime            logendtime   = DateTime.MinValue;
                int res = -1;

                if (edsm.IsApiKeySet && Commander.SyncFromEdsm && DateTime.UtcNow > EDSMRequestBackoffTime)
                {
                    if (DateTime.UtcNow.Subtract(LastEventTime).TotalMinutes >= EDSMMaxLogAgeMinutes)
                    {
                        Trace.WriteLine($"Retrieving logs starting {LastEventTime}");
                        res = edsm.GetLogs(LastEventTime, null, out edsmlogs, out logstarttime, out logendtime);
                    }
                    else if (FirstEventTime > GammaStart)
                    {
                        Trace.WriteLine($"Retrieving logs ending {FirstEventTime}");
                        res = edsm.GetLogs(null, FirstEventTime, out edsmlogs, out logstarttime, out logendtime);
                    }
                }

                if (ExitRequested.WaitOne(0))
                {
                    return;
                }

                if (res == 429) // Rate Limit Exceeded
                {
                    Trace.WriteLine($"EDSM Log request rate limit hit - backing off for {BackoffInterval.TotalSeconds}s");
                    EDSMRequestBackoffTime = DateTime.UtcNow + BackoffInterval;
                    BackoffInterval        = BackoffInterval + TimeSpan.FromSeconds(60);
                }
                else if (logstarttime > LastEventTime && logendtime < FirstEventTime)
                {
                    Trace.WriteLine($"Bad start and/or end times returned by EDSM - backing off for {BackoffInterval.TotalSeconds}s");
                    EDSMRequestBackoffTime = DateTime.UtcNow + BackoffInterval;
                    BackoffInterval        = BackoffInterval + TimeSpan.FromSeconds(60);
                }
                else if (res == 100 && edsmlogs != null)
                {
                    BackoffInterval = TimeSpan.FromSeconds(60);

                    if (logendtime > DateTime.UtcNow)
                    {
                        logendtime = DateTime.UtcNow;
                    }

                    List <HistoryEntry> hlfsdlist  = JournalEntry.GetAll(Commander.Nr).OfType <JournalLocOrJump>().OrderBy(je => je.EventTimeUTC).Select(je => HistoryEntry.FromJournalEntry(je, null, false, out jupdate)).ToList();
                    HistoryList         hl         = new HistoryList(hlfsdlist);
                    List <DateTime>     hlfsdtimes = hlfsdlist.Select(he => he.EventTimeUTC).ToList();

                    List <HistoryEntry> toadd = new List <HistoryEntry>();

                    int previdx = -1;
                    foreach (HistoryEntry he in edsmlogs)      // find out list of ones not present
                    {
                        int index = hlfsdlist.FindIndex(x => x.System.name.Equals(he.System.name, StringComparison.InvariantCultureIgnoreCase) && x.EventTimeUTC.Ticks == he.EventTimeUTC.Ticks);

                        if (index < 0)
                        {
                            // Look for any entries where DST may have thrown off the time
                            foreach (var vi in hlfsdlist.Select((v, i) => new { v = v, i = i }).Where(vi => vi.v.System.name.Equals(he.System.name, StringComparison.InvariantCultureIgnoreCase)))
                            {
                                if (vi.i > previdx)
                                {
                                    double hdiff = vi.v.EventTimeUTC.Subtract(he.EventTimeUTC).TotalHours;
                                    if (hdiff >= -2 && hdiff <= 2 && hdiff == Math.Floor(hdiff))
                                    {
                                        if (vi.v.System.id_edsm <= 0)
                                        {
                                            vi.v.System.id_edsm = 0;
                                            hl.FillEDSM(vi.v);
                                        }

                                        if (vi.v.System.id_edsm <= 0 || vi.v.System.id_edsm == he.System.id_edsm)
                                        {
                                            index = vi.i;
                                            break;
                                        }
                                    }
                                }
                            }
                        }

                        if (index < 0)
                        {
                            toadd.Add(he);
                        }
                        else
                        {
                            HistoryEntry lhe = hlfsdlist[index];

                            if (he.IsEDSMFirstDiscover && !lhe.IsEDSMFirstDiscover)
                            {
                                lhe.SetFirstDiscover();
                            }

                            previdx = index;
                        }
                    }

                    if (toadd.Count > 0)                         // if we have any, we can add
                    {
                        TravelLogUnit tlu = new TravelLogUnit(); // need a tlu for it
                        tlu.type        = 2;                     // EDSM
                        tlu.Name        = "EDSM-" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);
                        tlu.Size        = 0;
                        tlu.Path        = "EDSM";
                        tlu.CommanderId = EDCommander.CurrentCmdrID;
                        tlu.Add();  // Add to Database

                        using (SQLiteConnectionUser cn = new SQLiteConnectionUser(utc: true))
                        {
                            foreach (HistoryEntry he in toadd)
                            {
                                JObject jo = EDDiscovery.EliteDangerous.JournalEntry.CreateFSDJournalEntryJson(he.EventTimeUTC,
                                                                                                               he.System.name, he.System.x, he.System.y, he.System.z,
                                                                                                               EDDConfig.Instance.DefaultMapColour);
                                EDDiscovery.EliteDangerous.JournalEntry je =
                                    EDDiscovery.EliteDangerous.JournalEntry.CreateFSDJournalEntry(tlu.id, tlu.CommanderId.Value,
                                                                                                  (int)EDDiscovery.EliteDangerous.SyncFlags.EDSM, jo);

                                System.Diagnostics.Trace.WriteLine(string.Format("Add {0} {1}", je.EventTimeUTC, he.System.name));
                                je.Add(jo, cn);
                            }
                        }

                        LogLine($"Retrieved {toadd.Count} log entries from EDSM, from {logstarttime.ToLocalTime().ToString()} to {logendtime.ToLocalTime().ToString()}");

                        if (logendtime > LastEventTime || logstarttime <= GammaStart)
                        {
                            if (OnDownloadedSystems != null)
                            {
                                OnDownloadedSystems();
                            }
                        }
                    }

                    if (logstarttime < FirstEventTime)
                    {
                        FirstEventTime = logstarttime;
                    }

                    if (logendtime > LastEventTime)
                    {
                        LastEventTime = logendtime;
                    }
                }
            }
        }
Пример #21
0
        /// <summary>
        /// Write commander information to storage.
        /// </summary>
        /// <param name="cmdrlist">The new list of <see cref="EDCommander"/> instances.</param>
        /// <param name="reload">Whether to refresh the in-memory list after writing.</param>
        public static void Update(List <EDCommander> cmdrlist, bool reload)
        {
            using (SQLiteConnectionUser conn = new SQLiteConnectionUser())
            {
                using (DbCommand cmd = conn.CreateCommand("UPDATE Commanders SET Name=@Name, EdsmName=@EdsmName, EdsmApiKey=@EdsmApiKey, NetLogDir=@NetLogDir, JournalDir=@JournalDir, " +
                                                          "SyncToEdsm=@SyncToEdsm, SyncFromEdsm=@SyncFromEdsm, SyncToEddn=@SyncToEddn, SyncToEGO=@SyncToEGO, EGOName=@EGOName, " +
                                                          "EGOAPIKey=@EGOApiKey WHERE Id=@Id"))
                {
                    cmd.AddParameter("@Id", DbType.Int32);
                    cmd.AddParameter("@Name", DbType.String);
                    cmd.AddParameter("@EdsmName", DbType.String);
                    cmd.AddParameter("@EdsmApiKey", DbType.String);
                    cmd.AddParameter("@NetLogDir", DbType.String);
                    cmd.AddParameter("@JournalDir", DbType.String);
                    cmd.AddParameter("@SyncToEdsm", DbType.Boolean);
                    cmd.AddParameter("@SyncFromEdsm", DbType.Boolean);
                    cmd.AddParameter("@SyncToEddn", DbType.Boolean);
                    cmd.AddParameter("@SyncToEGO", DbType.Boolean);
                    cmd.AddParameter("@EGOName", DbType.String);
                    cmd.AddParameter("@EGOApiKey", DbType.String);

                    foreach (EDCommander edcmdr in cmdrlist) // potential NRE
                    {
                        cmd.Parameters["@Id"].Value           = edcmdr.Nr;
                        cmd.Parameters["@Name"].Value         = edcmdr.Name;
                        cmd.Parameters["@EdsmName"].Value     = edcmdr.EdsmName;
                        cmd.Parameters["@EdsmApiKey"].Value   = edcmdr.APIKey != null ? edcmdr.APIKey : "";
                        cmd.Parameters["@NetLogDir"].Value    = ""; // unused field
                        cmd.Parameters["@JournalDir"].Value   = edcmdr.JournalDir != null ? edcmdr.JournalDir : "";
                        cmd.Parameters["@SyncToEdsm"].Value   = edcmdr.SyncToEdsm;
                        cmd.Parameters["@SyncFromEdsm"].Value = edcmdr.SyncFromEdsm;
                        cmd.Parameters["@SyncToEddn"].Value   = edcmdr.SyncToEddn;
                        cmd.Parameters["@SyncToEGO"].Value    = edcmdr.SyncToEGO;
                        cmd.Parameters["@EGOName"].Value      = edcmdr.EGOName != null ? edcmdr.EGOName : "";
                        cmd.Parameters["@EGOApiKey"].Value    = edcmdr.EGOAPIKey != null ? edcmdr.EGOAPIKey : "";
                        cmd.ExecuteNonQuery();

                        _Commanders[edcmdr.Nr] = edcmdr;
                    }

                    if (reload)
                    {
                        Load(true, conn);       // refresh in-memory copy
                    }
                }
            }

            // For  some people sharing their user DB between different computers and having different paths to their journals on those computers.
            JObject jo = new JObject();

            foreach (EDCommander cmdr in _commandersDict.Values)
            {
                JObject j = new JObject();
                if (cmdr.JournalDir != null)
                {
                    jo["JournalDir"] = cmdr.JournalDir;
                }
                jo[cmdr.Name] = j;
            }

            using (Stream stream = File.OpenWrite(Path.Combine(EliteDangerousCore.EliteConfigInstance.InstanceOptions.AppDataDirectory, "CommanderPaths.json.tmp")))
            {
                using (StreamWriter writer = new StreamWriter(stream))
                {
                    using (JsonTextWriter jwriter = new JsonTextWriter(writer))
                    {
                        jo.WriteTo(jwriter);
                    }
                }
            }

            File.Delete(Path.Combine(EliteDangerousCore.EliteConfigInstance.InstanceOptions.AppDataDirectory, "CommanderPaths.json"));
            File.Move(Path.Combine(EliteDangerousCore.EliteConfigInstance.InstanceOptions.AppDataDirectory, "CommanderPaths.json.tmp"),
                      Path.Combine(EliteDangerousCore.EliteConfigInstance.InstanceOptions.AppDataDirectory, "CommanderPaths.json"));
        }
Пример #22
0
 public static void AddNewType(SQLiteConnectionUser cn, string c, string namelist, string t)
 {
     AddNewTypeC(cn, c, Color.Green, namelist, t);
 }
Пример #23
0
        public void ProcessWithUserDb(JournalEntry je, HistoryEntry prev, HistoryList hl, SQLiteConnectionUser conn)      // called after above with a USER connection
        {
            materialscommodities = MaterialCommoditiesList.Process(je, prev?.materialscommodities, conn, EliteConfigInstance.InstanceConfig.ClearMaterials, EliteConfigInstance.InstanceConfig.ClearCommodities);

            snc = SystemNoteClass.GetSystemNote(Journalid, IsFSDJump, System);       // may be null
        }
Пример #24
0
        public static void SetUpInitialTable()
        {
            using (SQLiteConnectionUser cn = new SQLiteConnectionUser())
            {
                AddNewTypeC(cn, MaterialRawCategory, Color.Red, "Antimony", "Very Rare", "Sb");
                AddNewTypeC(cn, MaterialRawCategory, Color.Red, "Polonium", "Very Rare", "Po");
                AddNewTypeC(cn, MaterialRawCategory, Color.Red, "Ruthenium", "Very Rare", "Ru");
                AddNewTypeC(cn, MaterialRawCategory, Color.Red, "Technetium", "Very Rare", "Tc");
                AddNewTypeC(cn, MaterialRawCategory, Color.Red, "Tellurium", "Very Rare", "Te");
                AddNewTypeC(cn, MaterialRawCategory, Color.Red, "Yttrium", "Very Rare", "Y");

                AddNewTypeC(cn, MaterialRawCategory, Color.Yellow, "Cadmium", "Rare", "Cd");
                AddNewTypeC(cn, MaterialRawCategory, Color.Yellow, "Mercury", "Rare", "Hg");
                AddNewTypeC(cn, MaterialRawCategory, Color.Yellow, "Molybdenum", "Rare", "Mo");
                AddNewTypeC(cn, MaterialRawCategory, Color.Yellow, "Niobium", "Rare", "Nb");
                AddNewTypeC(cn, MaterialRawCategory, Color.Yellow, "Tin", "Rare", "Sn");
                AddNewTypeC(cn, MaterialRawCategory, Color.Yellow, "Tungsten", "Rare", "W");

                AddNewTypeC(cn, MaterialRawCategory, Color.Cyan, "Carbon", "Very Common", "C");
                AddNewTypeC(cn, MaterialRawCategory, Color.Cyan, "Iron", "Very Common", "Fe");
                AddNewTypeC(cn, MaterialRawCategory, Color.Cyan, "Nickel", "Very Common", "Ni");
                AddNewTypeC(cn, MaterialRawCategory, Color.Cyan, "Phosphorus", "Very Common", "P");
                AddNewTypeC(cn, MaterialRawCategory, Color.Cyan, "Sulphur", "Very Common", "S");

                AddNewTypeC(cn, MaterialRawCategory, Color.Green, "Arsenic", "Common", "As");
                AddNewTypeC(cn, MaterialRawCategory, Color.Green, "Chromium", "Common", "Cr");
                AddNewTypeC(cn, MaterialRawCategory, Color.Green, "Germanium", "Common", "Ge");
                AddNewTypeC(cn, MaterialRawCategory, Color.Green, "Manganese", "Common", "Mn");
                AddNewTypeC(cn, MaterialRawCategory, Color.Green, "Selenium", "Common", "Se");
                AddNewTypeC(cn, MaterialRawCategory, Color.Green, "Vanadium", "Common", "V");
                AddNewTypeC(cn, MaterialRawCategory, Color.Green, "Zinc", "Common", "Zn");
                AddNewTypeC(cn, MaterialRawCategory, Color.Green, "Zirconium", "Common", "Zr");

                AddNewType(cn, CommodityCategory, "Explosives;Hydrogen Fuel;Hydrogen Peroxide;Liquid Oxygen;Mineral Oil;Nerve Agents;Pesticides;Surface Stabilisers;Synthetic Reagents;Water", "Chemicals");
                AddNewType(cn, CommodityCategory, "Clothing;Consumer Technology;Domestic Appliances;Evacuation Shelter;Survival Equipment", "Consumer Items");
                AddNewType(cn, CommodityCategory, "Algae;Animal Meat;Coffee;Fish;Food Cartridges;Fruit and Vegetables;Grain;Synthetic Meat;Tea", "Foods");
                AddNewType(cn, CommodityCategory, "Ceramic Composites;CMM Composite;Insulating Membrane;Meta-Alloys;Micro-Weave Cooling Hoses;Neofabric Insulation;Polymers;Semiconductors;Superconductors", "Industrial Materials");
                AddNewType(cn, CommodityCategory, "Beer;Bootleg Liquor;Liquor;Narcotics;Tobacco;Wine", "Legal Drugs");
                AddNewType(cn, CommodityCategory, "Articulation Motors;Atmospheric Processors;Building Fabricators;Crop Harvesters;Emergency Power Cells;Energy Grid Assembly;Exhaust Manifold;Geological Equipment", "Machinery");
                AddNewType(cn, CommodityCategory, "Heatsink Interlink;HN Shock Mount;Ion Distributor;Magnetic Emitter Coil;Marine Equipment", "Machinery");
                AddNewType(cn, CommodityCategory, "Microbial Furnaces;Mineral Extractors;Modular Terminals;Power Converter;Power Generators;Power Transfer Bus", "Machinery");
                AddNewType(cn, CommodityCategory, "Radiation Baffle;Reinforced Mounting Plate;Skimmer Components;Thermal Cooling Units;Water Purifiers", "Machinery");
                AddNewType(cn, CommodityCategory, "Advanced Medicines;Agri-Medicines;Basic Medicines;Combat Stabilisers;Performance Enhancers;Progenitor Cells", "Medicines");
                AddNewType(cn, CommodityCategory, "Aluminium;Beryllium;Bismuth;Cobalt;Copper;Gallium;Gold;Hafnium 178;Indium;Lan;hanum;Lithium;Osmium;Palladium;Platinum;Praseodymium;Samarium;Silver;Tantalum;Thallium;Thorium;Titanium;Uranium", "Metals");
                AddNewType(cn, CommodityCategory, "Bauxite;Bertrandite;Bromellite;Coltan;Cryolite;Gallite;Goslarite", "Minerals");
                AddNewType(cn, CommodityCategory, "Indite;Jadeite;Lepidolite;Lithium Hydroxide;Low Temperature Diamonds;Methane ;lathrate;Methanol Monohydrate;Moissanite;Painite;Pyrophyllite;Rutile;Taaffeite;Uraninite", "Minerals");
                AddNewType(cn, CommodityCategory, "Ai Relics;Ancient Artefact;Antimatter Containment Unit;Antiquities;Assault Plans;Black Box;Commercial Samples;Data Core;Diplomatic Bag;Encrypted Correspondence;Encrypted Data Storage;Experimental Chemicals;Fossil Remnants", "Salvage");
                AddNewType(cn, CommodityCategory, "Galactic Travel Guide;Geological Samples;Hostage;Military Intelligence;Military Plans (USS Cargo);Mysterious Idol;Occupied CryoPod;Occupied Escape Pod;Personal Effects;Political Prisoner;Precious Gems;Prohibited Research Materials;Prototype Tech", "Salvage");
                AddNewType(cn, CommodityCategory, "Rare Artwork;Rebel Transmissions;Salvageable Wreckage;Sap 8 Core Container;Sc;entific Research;Scientific Samples;Space Pioneer Relics;Tactical Data;Technical Blueprints;Trade Data;Unknown Artefact;Unknown Probe;Unstable Data Core", "Salvage");
                AddNewType(cn, CommodityCategory, "Imperial Slaves;Slaves", "Slavery");
                AddNewType(cn, CommodityCategory, "Advanced Catalysers;Animal Monitors;Aquaponic Systems;Auto-Fabricators;Bioreducing Lichen;Computer Components", "Technology");
                AddNewType(cn, CommodityCategory, "H.E. Suits;Hardware Diagnostic Sensor;Land Enrichment Systems;Medical Diagnostic Equipment;Micro Controllers;Muon Imager", "Technology");
                AddNewType(cn, CommodityCategory, "Nanobreakers;Resonating Separators;Robotics;Structural Regulators;Telemetry Suite", "Technology");
                AddNewType(cn, CommodityCategory, "Conductive Fabrics;Leather;Military Grade Fabrics;Natural Fabrics;Synthetic Fabrics", "Textiles");
                AddNewType(cn, CommodityCategory, "Biowaste;Chemical Waste;Scrap;Toxic Waste", "Waste");
                AddNewType(cn, CommodityCategory, "Battle Weapons;Landmines;Non-lethal Weapons;Personal Weapons;Reactive Armour", "Weapons");

                AddNewType(cn, "Encoded", "Scan Data Banks;Disrupted Wake Echoes;Datamined Wake;Hyperspace Trajectories;Wake Solutions", "");
                AddNewType(cn, "Encoded", "Shield Density Reports;Shield Pattern Analysis;Shield Cycle Recordings;Emission Data;Bulk Scan Data;Consumer Firmware;Shield Soak Analysis;Legacy Firmware", "");
                AddNewType(cn, "Encoded", "Aberrant Shield Pattern Analysis;Abnormal Compact Emission Data;Adaptive Encryptors Capture;", "");
                AddNewType(cn, "Encoded", "Anomalous Bulk Scan Data;Anomalous FSD Telemetry;Atypical Disrupted Wake Echoes;Atypical Encryption Archives;Classified Scan Databanks", "");
                AddNewType(cn, "Encoded", "Classified Scan Fragment;Cracked Industrial Firmware;Datamined Wake Exceptions;Decoded Emission Data;Distorted Shield Cycle Recordings", "");
                AddNewType(cn, "Encoded", "Divergent Scan Data;Eccentric Hyperspace Trajectories;Exceptional Scrambled Emission Data;Inconsistent Shield Soak Analysis;Irregular Emission Data", "");
                AddNewType(cn, "Encoded", "Modified Consumer Firmware;Modified Embedded Firmware;Open Symmetric Keys;Peculiar Shield Frequency Data;Security Firmware Patch;Specialised Legacy Firmware", "");
                AddNewType(cn, "Encoded", "Strange Wake Solutions;Tagged Encryption Codes;Unexpected Emission Data;Unidentified Scan Archives;Untypical Shield Scans;Unusual Encrypted Files", "");

                AddNewType(cn, "Manufactured", "Uncut Focus Crystals;Basic Conductors;Biotech Conductors;Chemical Distillery;Chemical Manipulators;Chemical Processors;Chemical Storage Units", "");
                AddNewType(cn, "Manufactured", "Refined Focus Crystals;Compact Composites;Compound Shielding;Conductive Ceramics;Conductive Components;Conductive Polymers;Configurable Components", "");
                AddNewType(cn, "Manufactured", "Core Dynamics Composites;Crystal Shards;Electrochemical Arrays;Exquisite Focus Crystals;Filament Composites;Flawed Focus Crystals", "");
                AddNewType(cn, "Manufactured", "Focus Crystals;Galvanising Alloys;Grid Resistors;Heat Conduction Wiring;Heat Dispersion Plate;Heat Exchangers;Heat Resistant Ceramics", "");
                AddNewType(cn, "Manufactured", "Heat Vanes;High Density Composites;Hybrid Capacitors;Imperial Shielding;Improvised Components;Mechanical Components;Mechanical Equipment", "");
                AddNewType(cn, "Manufactured", "Mechanical Scrap;Military Grade Alloys;Military Supercapacitors;Pharmaceutical Isolators;Phase Alloys;Polymer Capacitors;Precipitated Alloys", "");
                AddNewType(cn, "Manufactured", "Proprietary Composites;Proto Heat Radiators;Proto Light Alloys;Proto Radiolic Alloys;Salvaged Alloys", "");
                AddNewType(cn, "Manufactured", "Shield Emitters;Shielding Sensors;Tempered Alloys;Thermic Alloys;Unknown Fragment;Worn Shield Emitters", "");

                loadedlist = GetAll(cn);
            }
        }
Пример #25
0
 private void buttonJumponium_CheckedChanged(object sender, EventArgs e)
 {
     SQLiteConnectionUser.PutSettingBool(DbShowJumponium, checkBoxJumponium.Checked);
     HistoryChanged(current_historylist);
 }
Пример #26
0
        static public MaterialCommoditiesList Process(JournalEntry je, MaterialCommoditiesList oldml, SQLiteConnectionUser conn,
                                                      bool clearzeromaterials, bool clearzerocommodities)
        {
            MaterialCommoditiesList newmc = (oldml == null) ? new MaterialCommoditiesList() : oldml;

            Type jtype = JournalEntry.TypeOfJournalEntry(je.EventTypeStr);

            if (jtype != null)
            {
                System.Reflection.MethodInfo m = jtype.GetMethod("MaterialList");  // see if the class defines this function..

                if (m != null)                                                     // event wants to change it
                {
                    newmc = newmc.Clone(clearzeromaterials, clearzerocommodities); // so we need a new one

                    m.Invoke(Convert.ChangeType(je, jtype), new Object[] { newmc, conn });
                }
            }

            return(newmc);
        }
Пример #27
0
        // Called on a New Entry, by EDDiscoveryController:NewEntry, to add an journal entry in

        public HistoryEntry AddJournalEntry(JournalEntry je, Action <string> logerror)   // always return he
        {
            HistoryEntry prev = GetLast;

            bool         journalupdate = false;
            HistoryEntry he            = HistoryEntry.FromJournalEntry(je, prev, out journalupdate); // we may check edsm for this entry

            if (journalupdate)
            {
                JournalFSDJump jfsd = je as JournalFSDJump;

                if (jfsd != null)
                {
                    JournalEntry.UpdateEDSMIDPosJump(jfsd.Id, he.System, !jfsd.HasCoordinate && he.System.HasCoordinate, jfsd.JumpDist);
                }
            }

            using (SQLiteConnectionUser conn = new SQLiteConnectionUser())
            {
                he.ProcessWithUserDb(je, prev, this, conn);           // let some processes which need the user db to work

                cashledger.Process(je, conn);
                he.Credits = cashledger.CashTotal;

                shipyards.Process(je, conn);
                outfitting.Process(je, conn);

                Tuple <ShipInformation, ModulesInStore> ret = shipinformationlist.Process(je, conn, he.WhereAmI, he.System);
                he.ShipInformation = ret.Item1;
                he.StoredModules   = ret.Item2;

                he.MissionList = missionlistaccumulator.Process(je, he.System, he.WhereAmI, conn);
            }

            historylist.Add(he);

            if (je.EventTypeID == JournalTypeEnum.Scan)
            {
                JournalScan      js = je as JournalScan;
                JournalLocOrJump jl;
                HistoryEntry     jlhe;
                if (!starscan.AddScanToBestSystem(js, Count - 1, EntryOrder, out jlhe, out jl))
                {
                    // Ignore scans where the system name has been changed
                    // Also ignore belt clusters
                    if (jl == null || (jl.StarSystem.Equals(jlhe.System.Name, StringComparison.InvariantCultureIgnoreCase) && !js.BodyDesignation.ToLowerInvariant().Contains(" belt cluster ")))
                    {
                        logerror("Cannot add scan to system - alert the EDDiscovery developers using either discord or Github (see help)" + Environment.NewLine +
                                 "Scan object " + js.BodyName + " in " + he.System.Name);
                    }
                }
            }
            else if (je is IBodyNameAndID)
            {
                JournalLocOrJump jl;
                HistoryEntry     jlhe;
                starscan.AddBodyToBestSystem((IBodyNameAndID)je, Count - 1, EntryOrder, out jlhe, out jl);
            }

            return(he);
        }
Пример #28
0
        private void buttonExtImport_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();

            dlg.InitialDirectory = SQLiteConnectionUser.GetSettingString("BookmarkFormImportExcelFolder", "c:\\");

            if (!System.IO.Directory.Exists(dlg.InitialDirectory))
            {
                System.IO.Directory.CreateDirectory(dlg.InitialDirectory);
            }

            dlg.DefaultExt   = "csv";
            dlg.AddExtension = true;
            dlg.Filter       = "CVS Files (*.csv)|*.csv|All files (*.*)|*.*";

            if (dlg.ShowDialog(this) == DialogResult.OK)
            {
                string path = dlg.FileName;

                BaseUtils.CSVFile csv = new BaseUtils.CSVFile();

                if (csv.Read(path, System.IO.FileShare.ReadWrite))
                {
                    List <BaseUtils.CSVFile.Row> rows = csv.RowsExcludingHeaderRow;

                    BookmarkClass currentbk = null;

                    var Regexyyyyddmm = new System.Text.RegularExpressions.Regex(@"\d\d\d\d-\d\d-\d\d", System.Text.RegularExpressions.RegexOptions.Compiled | System.Text.RegularExpressions.RegexOptions.Singleline);

                    foreach (var r in rows)
                    {
                        string type = r[0];
                        string date = r[1];

                        if (type.HasChars() && date.HasChars())
                        {
                            bool region = type?.Equals("Region", StringComparison.InvariantCultureIgnoreCase) ?? false;

                            DateTime time = DateTime.MinValue;

                            bool isyyyy = Regexyyyyddmm.IsMatch(date);      // excel, after getting our output in, converts the damn thing to local dates.. this distinguishes it.

                            bool success = isyyyy ? DateTime.TryParse(date, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.AssumeLocal, out time) :
                                           DateTime.TryParse(date, System.Globalization.CultureInfo.CurrentCulture, System.Globalization.DateTimeStyles.AssumeLocal, out time);

                            if (success)
                            {
                                string name = r[2];
                                string note = r[3];
                                double?x    = r[4].InvariantParseDoubleNull();
                                double?y    = r[5].InvariantParseDoubleNull();
                                double?z    = r[6].InvariantParseDoubleNull();

                                if (x != null && y != null && z != null)
                                {
                                    System.Diagnostics.Debug.WriteLine("Bookmark {0} {1} {2} {3} ({4},{5},{6}", type, time.ToStringZulu(), name, note, x, y, z);

                                    currentbk = GlobalBookMarkList.Instance.FindBookmark(name, region);

                                    if (currentbk != null)
                                    {
                                        GlobalBookMarkList.Instance.AddOrUpdateBookmark(currentbk, !region, name, x.Value, y.Value, z.Value, time, note, currentbk.PlanetaryMarks);
                                    }
                                    else
                                    {
                                        currentbk = GlobalBookMarkList.Instance.AddOrUpdateBookmark(null, !region, name, x.Value, y.Value, z.Value, time, note, null);
                                    }
                                }
                                else
                                {
                                    System.Diagnostics.Debug.WriteLine("Not a system with valid coords {0} {1}", r[0], r[1]);
                                }
                            }
                            else
                            {
                                System.Diagnostics.Debug.WriteLine("Rejected due to date {0} {1}", r[0], r[1]);
                            }
                        }

                        string planet = r[7];

                        if (planet.HasChars() && currentbk != null)
                        {
                            string locname   = r[8];
                            string comment   = r[9];
                            double?latitude  = r[10].InvariantParseDoubleNull();
                            double?longitude = r[11].InvariantParseDoubleNull();

                            if (!locname.HasChars() && latitude == null && longitude == null) // whole planet bookmark
                            {
                                currentbk.AddOrUpdatePlanetBookmark(planet, comment);
                            }
                            else if (locname.HasChars() && latitude.HasValue && longitude.HasValue)
                            {
                                currentbk.AddOrUpdateLocation(planet, locname, comment, latitude.Value, longitude.Value);
                            }
                        }
                    }

                    SQLiteConnectionUser.PutSettingString("BookmarkFormImportExcelFolder", System.IO.Path.GetDirectoryName(path));
                }
                else
                {
                    ExtendedControls.MessageBoxTheme.Show(FindForm(), "Failed to read " + path, "Import Failed", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
        }
Пример #29
0
        //dist >0 to update
        public static void UpdateEDSMIDPosJump(long journalid, ISystem system, bool jsonpos, double dist, SQLiteConnectionUser cn = null, DbTransaction tn = null)
        {
            bool ownconn = false;

            try
            {
                if (cn == null)
                {
                    ownconn = true;
                    cn      = new SQLiteConnectionUser(utc: true);
                }

                JObject jo = GetJson(journalid, cn, tn);

                if (jo != null)
                {
                    if (jsonpos)
                    {
                        jo["StarPos"] = new JArray()
                        {
                            system.x, system.y, system.z
                        };
                        jo["StarPosFromEDSM"] = true;
                    }

                    if (dist > 0)
                    {
                        jo["JumpDist"] = dist;
                    }

                    using (DbCommand cmd2 = cn.CreateCommand("Update JournalEntries set EventData = @EventData, EdsmId = @EdsmId where ID = @ID", tn))
                    {
                        cmd2.AddParameterWithValue("@ID", journalid);
                        cmd2.AddParameterWithValue("@EventData", jo.ToString());
                        cmd2.AddParameterWithValue("@EdsmId", system.id_edsm);

                        //System.Diagnostics.Trace.WriteLine(string.Format("Update journal ID {0} with pos {1}/edsmid {2} dist {3}", journalid, jsonpos, system.id_edsm, dist));
                        cmd2.ExecuteNonQuery();
                    }
                }
            }
            finally
            {
                if (ownconn)
                {
                    cn.Dispose();
                }
            }
        }
Пример #30
0
        private void UpdateSyncFlagBit(SyncFlags bit1, bool value1, SyncFlags bit2, bool value2, SQLiteConnectionUser cn = null, DbTransaction txn = null)
        {
            bool closeConn = false;

            try
            {
                if (cn == null)
                {
                    closeConn = true;
                    cn        = new SQLiteConnectionUser(utc: true);
                }

                if (value1)
                {
                    Synced |= (int)bit1;
                }
                else
                {
                    Synced &= ~(int)bit1;
                }

                if (value2)
                {
                    Synced |= (int)bit2;
                }
                else
                {
                    Synced &= ~(int)bit2;
                }

                using (DbCommand cmd = cn.CreateCommand("Update JournalEntries set Synced = @sync where ID=@journalid", txn))
                {
                    cmd.AddParameterWithValue("@journalid", Id);
                    cmd.AddParameterWithValue("@sync", Synced);
                    System.Diagnostics.Trace.WriteLine(string.Format("Update sync flag ID {0} with {1}", Id, Synced));
                    cn.SQLNonQueryText(cmd);
                }
            }
            finally
            {
                if (closeConn && cn != null)
                {
                    cn.Dispose();
                }
            }
        }