Exemplo n.º 1
0
        public static JournalEDDCommodityPrices AddEDDCommodityPrices(int cmdrid, DateTime dt, string station, string faction, JArray jcommodities)     // add item, return journal ID
        {
            JObject jo;

            using (SQLiteConnectionUser cn = new SQLiteConnectionUser(utc: true))
            {
                jo = new JObject();
                jo["timestamp"]   = dt;
                jo["event"]       = JournalTypeEnum.EDDCommodityPrices.ToString();
                jo["station"]     = station;
                jo["faction"]     = faction;
                jo["commodities"] = jcommodities;
                JournalEDDCommodityPrices jis = new JournalEDDCommodityPrices(jo);
                jis.CommanderId = cmdrid;
                jis.Add(jo, cn);

                if (jis.Commodities.Count == 0)
                {
                    return(null);
                }
                else
                {
                    return(jis);
                }
            }
        }
Exemplo n.º 2
0
        private void Controller_NewEntrySecond(HistoryEntry he, HistoryList hl)         // called after all UI's have had their chance
        {
            actioncontroller.ActionRunOnEntry(he, "NewEntry");

            if (he.EntryType == JournalTypeEnum.Docked)
            {
                if (Capi.IsCommanderLoggedin(EDCommander.Current.Name))
                {
                    if (he.ContainsRares())
                    {
                        LogLine("Not performing Companion API get due to carrying rares");
                    }
                    else
                    {
                        System.Diagnostics.Debug.WriteLine("Commander " + EDCommander.Current.Name + " in CAPI");
                        try
                        {
                            Capi.GetProfile();
                            JournalEDDCommodityPrices entry = JournalEntry.AddEDDCommodityPrices(EDCommander.Current.Nr, he.journalEntry.EventTimeUTC.AddSeconds(1), Capi.Profile.StarPort.name, Capi.Profile.StarPort.faction, Capi.Profile.StarPort.jcommodities);
                            if (entry != null)
                            {
                                Controller.NewEntry(entry);
                                OnNewCompanionAPIData?.Invoke(Capi, he);

                                if (EDCommander.Current.SyncToEddn)
                                {
                                    SendPricestoEDDN(he);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            LogLineHighlight("Companion API get failed: " + ex.Message);
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        private void Display()
        {
            Stopwatch swp = new Stopwatch();

            swp.Start();

            DataGridViewColumn sortcol   = dataGridViewMarketData.SortedColumn != null ? dataGridViewMarketData.SortedColumn : dataGridViewMarketData.Columns[0];
            SortOrder          sortorder = dataGridViewMarketData.SortOrder;

            int    firstdisplayed = dataGridViewMarketData.FirstDisplayedScrollingRowIndex;
            string commodity      = (dataGridViewMarketData.CurrentRow != null) ? (string)dataGridViewMarketData.CurrentRow.Cells[1].Value : null;
            int    currentoffset  = (dataGridViewMarketData.CurrentRow != null) ? dataGridViewMarketData.CurrentRow.Index - firstdisplayed : 0;

            dataGridViewMarketData.Rows.Clear();
            labelLocation.Text = "No Data";
            toolTip.SetToolTip(labelLocation, null);

            HistoryEntry left  = (eddmd_left != null) ? eddmd_left : last_eddmd; // if we have a selected left, use it, else use the last eddmd
            HistoryEntry cargo = (eddmd_left != null) ? eddmd_left : last_he;    // if we have a selected left, use it, else use the last he

            if (left != null)                                                    // we know it has a journal entry of EDD commodity..
            {
                System.Diagnostics.Debug.WriteLine(Environment.NewLine + "From " + current_displayed?.WhereAmI + " to " + left.WhereAmI);

                JournalEDDCommodityPrices ecp  = left.journalEntry as JournalEDDCommodityPrices;
                List <CCommodities>       list = ecp.Commodities;

                System.Diagnostics.Debug.WriteLine("Test Right " + eddmd_right?.WhereAmI + " vs " + left.WhereAmI);
                if (eddmd_right != null && !Object.ReferenceEquals(eddmd_right, left))   // if got a comparision, and not the same data..
                {
                    if (checkBoxAutoSwap.Checked &&
                        left.System.name.Equals(eddmd_right.System.name) &&     // if left system being displayed is same as right system
                        left.WhereAmI.Equals(eddmd_right.WhereAmI))             // that means we can autoswap comparisions around
                    {
                        System.Diagnostics.Debug.WriteLine("Arrived at last left station, repick " + current_displayed.WhereAmI + " as comparision");

                        int index = comboboxentries.FindIndex(x => x.System.name.Equals(current_displayed.System.name) && x.WhereAmI.Equals(current_displayed.WhereAmI));
                        if (index >= 0)         // if found it, swap to last instance of system
                        {
                            comboBoxCustomTo.Enabled       = false;
                            comboBoxCustomTo.SelectedIndex = index + 1;
                            comboBoxCustomTo.Enabled       = true;
                            eddmd_right = comboboxentries[index];
                            System.Diagnostics.Debug.WriteLine("Right is now " + eddmd_right.WhereAmI);
                        }
                    }

                    System.Diagnostics.Debug.WriteLine("Right " + eddmd_right.System.name + " " + eddmd_right.WhereAmI);
                    list = CCommodities.Merge(list, ((JournalEDDCommodityPrices)eddmd_right.journalEntry).Commodities, eddmd_right.WhereAmI);
                }

                List <MaterialCommodities> mclist   = cargo.MaterialCommodity.Sort(true);   // stuff we have..  commodities only
                List <MaterialCommodities> notfound = new List <MaterialCommodities>();
                foreach (MaterialCommodities m in mclist)
                {
                    int index = list.FindIndex(x => x.name.EqualsAlphaNumOnlyNoCase(m.name));   // try and match, remove any spaces/_ and lower case it for matching
                    if (index >= 0)
                    {
                        list[index].CargoCarried = m.count; // found it, set cargo count..
                    }
                    else
                    {
                        notfound.Add(m);        // not found, add to list for bottom
                    }
                }

                FontFamily ff      = new FontFamily(this.Font.Name);
                bool       buyonly = checkBoxBuyOnly.Checked;

                foreach (CCommodities c in list)
                {
                    if (!buyonly || (c.buyPrice > 0 || c.ComparisionBuy))
                    {
                        object[] rowobj = { c.type,
                                            c.name,
                                            c.sellPrice > 0 ? c.sellPrice.ToString() : "",
                                            c.buyPrice > 0 ? c.buyPrice.ToString() : "",
                                            c.CargoCarried,
                                            c.demand > 1 ? c.demand.ToString() : "",
                                            c.stock > 0 ? c.stock.ToString() : "",
                                            c.meanPrice > 0 ? c.meanPrice.ToString() : "",
                                            c.ComparisionLR,
                                            c.ComparisionRL, };

                        int rowno = dataGridViewMarketData.Rows.Add(rowobj);

                        if (c.ComparisionRightOnly && ff != null && ff.IsStyleAvailable(FontStyle.Italic))
                        {
                            for (int i = 1; i < dataGridViewMarketData.Columns.Count; i++)
                            {
                                dataGridViewMarketData.Rows[rowno].Cells[i].Style.Font = new Font(this.Font, FontStyle.Italic);
                            }
                        }

                        dataGridViewMarketData.Rows[rowno].Cells[0].ToolTipText     =
                            dataGridViewMarketData.Rows[rowno].Cells[1].ToolTipText = c.ToString();
                    }
                }

                foreach (MaterialCommodities m in notfound)
                {
                    if (m.count > 0)
                    {
                        object[] rowobj = { m.type,
                                            m.name,
                                            "",
                                            "",
                                            m.count,
                                            "",
                                            "",
                                            "",
                                            "",
                                            "", };

                        int rowno = dataGridViewMarketData.Rows.Add(rowobj);
                        dataGridViewMarketData.Rows[rowno].Cells[0].ToolTipText     =
                            dataGridViewMarketData.Rows[rowno].Cells[1].ToolTipText = "Cargo only, no market data on this item";
                    }
                }

                current_displayed  = left;
                labelLocation.Text = left.System.name + ":" + left.WhereAmI;
                string r = "Recorded at " + ((EDDiscoveryForm.EDDConfig.DisplayUTC) ? left.EventTimeUTC.ToString() : left.EventTimeLocal.ToString());
                toolTip.SetToolTip(labelLocation, r);
            }

            dataGridViewMarketData.Sort(sortcol, (sortorder == SortOrder.Descending) ? ListSortDirection.Descending : ListSortDirection.Ascending);
            dataGridViewMarketData.Columns[sortcol.Index].HeaderCell.SortGlyphDirection = sortorder;

            if (commodity != null)
            {
                foreach (DataGridViewRow rw in dataGridViewMarketData.Rows)
                {
                    string v = (string)rw.Cells[1].Value;
                    if (v.Equals(commodity))            // Find the commodity, and set it to the same relative position as before.
                    {
                        dataGridViewMarketData.CurrentCell = dataGridViewMarketData.Rows[rw.Index].Cells[1];
                        dataGridViewMarketData.FirstDisplayedScrollingRowIndex = Math.Max(rw.Index - currentoffset, 0);
                        break;
                    }
                }
            }

            System.Diagnostics.Debug.WriteLine("Stop watch" + swp.ElapsedMilliseconds);
        }
Exemplo n.º 4
0
        public void Display()
        {
            DataGridViewColumn sortcol   = dataGridViewMarketData.SortedColumn != null ? dataGridViewMarketData.SortedColumn : dataGridViewMarketData.Columns[0];
            SortOrder          sortorder = dataGridViewMarketData.SortOrder;

            dataGridViewMarketData.Rows.Clear();
            labelLocation.Text = "No Data";
            toolTip1.SetToolTip(labelLocation, null);

            HistoryEntry left  = (eddmd_left != null) ? eddmd_left : last_eddmd; // if we have a selected left, use it, else use the last eddmd
            HistoryEntry cargo = (eddmd_left != null) ? eddmd_left : last_he;    // if we have a selected left, use it, else use the last he

            if (left != null)                                                    // we know it has a journal entry of EDD commodity..
            {
                JournalEDDCommodityPrices ecp  = left.journalEntry as JournalEDDCommodityPrices;
                List <CCommodities>       list = ecp.Commodities;

                if (eddmd_right != null && !Object.ReferenceEquals(eddmd_right, left))   // if got a comparision, and not the same
                {
                    list = CCommodities.Merge(list, ((JournalEDDCommodityPrices)eddmd_right.journalEntry).Commodities, eddmd_right.WhereAmI);
                }

                List <MaterialCommodities> mclist   = cargo.MaterialCommodity.Sort(true);   // stuff we have..  commodities only
                List <MaterialCommodities> notfound = new List <MaterialCommodities>();
                foreach (MaterialCommodities m in mclist)
                {
                    int index = list.FindIndex(x => x.name.EqualsAlphaNumOnlyNoCase(m.name));   // try and match, remove any spaces/_ and lower case it for matching
                    if (index >= 0)
                    {
                        list[index].CargoCarried = m.count; // found it, set cargo count..
                    }
                    else
                    {
                        notfound.Add(m);        // not found, add to list for bottom
                    }
                }

                FontFamily ff      = new FontFamily(this.Font.Name);
                bool       buyonly = checkBoxBuyOnly.Checked;

                foreach (CCommodities c in list)
                {
                    if (!buyonly || (c.buyPrice > 0 || c.ComparisionBuy))
                    {
                        object[] rowobj = { c.type,
                                            c.name,
                                            c.sellPrice > 0 ? c.sellPrice.ToString() : "",
                                            c.buyPrice > 0 ? c.buyPrice.ToString() : "",
                                            c.CargoCarried,
                                            c.demand > 1 ? c.demand.ToString() : "",
                                            c.stock > 0 ? c.stock.ToString() : "",
                                            c.meanPrice > 0 ? c.meanPrice.ToString() : "",
                                            c.ComparisionLR,
                                            c.ComparisionRL, };

                        int rowno = dataGridViewMarketData.Rows.Add(rowobj);

                        if (c.ComparisionRightOnly && ff != null && ff.IsStyleAvailable(FontStyle.Italic))
                        {
                            for (int i = 1; i < dataGridViewMarketData.Columns.Count; i++)
                            {
                                dataGridViewMarketData.Rows[rowno].Cells[i].Style.Font = new Font(this.Font, FontStyle.Italic);
                            }
                        }

                        dataGridViewMarketData.Rows[rowno].Cells[0].ToolTipText     =
                            dataGridViewMarketData.Rows[rowno].Cells[1].ToolTipText = c.ToString();
                    }
                }

                foreach (MaterialCommodities m in notfound)
                {
                    if (m.count > 0)
                    {
                        object[] rowobj = { m.type,
                                            m.name,
                                            "",
                                            "",
                                            m.count,
                                            "",
                                            "",
                                            "",
                                            "",
                                            "", };

                        int rowno = dataGridViewMarketData.Rows.Add(rowobj);
                        dataGridViewMarketData.Rows[rowno].Cells[0].ToolTipText     =
                            dataGridViewMarketData.Rows[rowno].Cells[1].ToolTipText = "Cargo only, no market data on this item";
                    }
                }

                labelLocation.Text = left.System.name + ":" + left.WhereAmI;
                string r = "Recorded at " + ((EDDiscoveryForm.EDDConfig.DisplayUTC) ? left.EventTimeUTC.ToString() : left.EventTimeLocal.ToString());
                toolTip1.SetToolTip(labelLocation, r);
            }

            dataGridViewMarketData.Sort(sortcol, (sortorder == SortOrder.Descending) ? ListSortDirection.Descending : ListSortDirection.Ascending);
            dataGridViewMarketData.Columns[sortcol.Index].HeaderCell.SortGlyphDirection = sortorder;
        }
Exemplo n.º 5
0
        static public bool?SendToEDDN(HistoryEntry he, bool debugonly = false)
        {
            EDDNClass eddn = new EDDNClass();

            if (he.Commander != null)
            {
                eddn.commanderName = he.Commander.EdsmName;
                if (string.IsNullOrEmpty(eddn.commanderName))
                {
                    eddn.commanderName = he.Commander.Name;
                }

                if (he.Commander.Name.StartsWith("[BETA]", StringComparison.InvariantCultureIgnoreCase))
                {
                    eddn.isBeta = true;
                }
            }

            if (he.IsBetaMessage)
            {
                eddn.isBeta = true;
            }

            JournalEntry je = he.journalEntry;

            if (je == null)
            {
                je = JournalEntry.Get(he.Journalid);
            }

            BaseUtils.JSON.JObject msg = null;

            if (je.EventTypeID == JournalTypeEnum.FSDJump)
            {
                msg = eddn.CreateEDDNMessage(je as JournalFSDJump);
            }
            else if (je.EventTypeID == JournalTypeEnum.Location)
            {
                msg = eddn.CreateEDDNMessage(je as JournalLocation);
            }
            else if (je.EventTypeID == JournalTypeEnum.CarrierJump)
            {
                msg = eddn.CreateEDDNMessage(je as JournalCarrierJump);
            }
            else if (je.EventTypeID == JournalTypeEnum.Docked)
            {
                msg = eddn.CreateEDDNMessage(je as JournalDocked, he.System);
            }
            else if (je.EventTypeID == JournalTypeEnum.Scan)
            {
                msg = eddn.CreateEDDNMessage(je as JournalScan, he.System);
            }
            else if (je.EventTypeID == JournalTypeEnum.SAASignalsFound)
            {
                msg = eddn.CreateEDDNMessage(je as JournalSAASignalsFound, he.System);
            }
            else if (je.EventTypeID == JournalTypeEnum.Outfitting)
            {
                msg = eddn.CreateEDDNOutfittingMessage(je as JournalOutfitting);
            }
            else if (je.EventTypeID == JournalTypeEnum.Shipyard)
            {
                msg = eddn.CreateEDDNShipyardMessage(je as JournalShipyard);
            }
            else if (je.EventTypeID == JournalTypeEnum.Market)
            {
                JournalMarket jm = je as JournalMarket;
                msg = eddn.CreateEDDNCommodityMessage(jm.Commodities, jm.StarSystem, jm.Station, jm.MarketID, jm.EventTimeUTC);      // if its devoid of data, null returned
            }
            else if (je.EventTypeID == JournalTypeEnum.EDDCommodityPrices)
            {
                JournalEDDCommodityPrices jm = je as JournalEDDCommodityPrices;
                msg = eddn.CreateEDDNCommodityMessage(jm.Commodities, jm.StarSystem, jm.Station, jm.MarketID, jm.EventTimeUTC);      // if its devoid of data, null returned
            }

            if (msg != null)
            {
                System.Diagnostics.Debug.WriteLine("Send to EDDN " + msg.ToString(true));

                if (!debugonly && eddn.PostMessage(msg))
                {
                    he.journalEntry.SetEddnSync();
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(null);
            }
        }