コード例 #1
0
        public static EMMADataSet.JournalRow GetClosest(long ownerID, bool corp, short walletID, DateTime date)
        {
            EMMADataSet.JournalDataTable table = new EMMADataSet.JournalDataTable();
            EMMADataSet.JournalRow retVal = null;
            date = date.ToUniversalTime();
            lock (tableAdapter)
            {
                tableAdapter.FillByClosest(table, ownerID, corp, walletID, date);
            }
            if (table.Count > 0) { retVal = table[0]; }

            return retVal;
        }
コード例 #2
0
        public static EMMADataSet.JournalRow FindEntry(DateTime date, long senderID, long recieverID, decimal amount)
        {
            EMMADataSet.JournalDataTable table = new EMMADataSet.JournalDataTable();
            EMMADataSet.JournalRow retVal = null;
            date = date.ToUniversalTime();
            lock (tableAdapter)
            {
                tableAdapter.FindMatch(table, date, recieverID, senderID, amount);
            }

            // Only return a match if there is one and only one matching record found.
            if (table.Count == 1)
            {
                retVal = table[0];
            }

            return retVal;
        }
コード例 #3
0
        /// <summary>
        /// Add journal entries from the supplied XML to the database.
        /// </summary>
        /// <param name="corc"></param>
        /// <param name="fileXML"></param>
        /// <returns>The number of rows added to the journal table.</returns>
        private int UpdateJournalFromXML(CharOrCorp corc, XmlDocument fileXML, short walletID)
        {
            int retVal = 0;
            int updatedEntries = 0;
            EMMADataSet.JournalDataTable journalData = new EMMADataSet.JournalDataTable();
            long highestIDSoFar = _apiSettings.GetHighestID(corc, APIDataType.Journal);
            long oldHighestID = _apiSettings.GetHighestID(corc, APIDataType.Journal);
            DateTime dataDate = DateTime.UtcNow;

            try
            {
                XmlNodeList journEntries = null;
                XmlDocument xml = new XmlDocument();

                UpdateStatus(0, 1, "Getting journal entries from file", "", false);
                journEntries = EveAPI.GetResults(fileXML);
                dataDate = EveAPI.GetDataTime(fileXML);
                UpdateStatus(1, 1, "", journEntries.Count + " entries found in file.", false);

                if (journEntries != null && journEntries.Count > 0)
                {
                    // Offset will always be the same since CCP switched over to 64 bit IDs
                    // (At least until we break the 64bit limit... As of mid 2010, we're using
                    // around 2 billion IDs a year so breaking the 64 bit limit will take around
                    // 9 billion years... Don't think it will be a problem :))
                    long offset = 2591720933;
                    int batchPrg = 0;

                    UpdateStatus(0, journEntries.Count, "Processing entries", "", false);

                    // Loop through the results returned from this call to the API and add the line
                    // to the data table.
                    foreach (XmlNode journEntry in journEntries)
                    {
                        bool tryUpdate = false;
                        long id = long.Parse(journEntry.SelectSingleNode("@refID").Value) + offset;
                        long recieverID = 0;
                        if (corc == CharOrCorp.Corp)
                        {
                            // This is a special case.
                            // When bounty prizes are received by the player, corp tax is applied.
                            // This corp tax does not appear as a seperate journal entry for the
                            // character. It is specified by the taxReceiverID and taxAmount fields
                            // on the bounty prize entry itself in the XML.
                            // On the corp side, there is a specifc entry for the tax but it has
                            // the same journalentryID and ownerID2 as the character entry.
                            // This means that EMMA does not differentiate between them and the
                            // corp tax part is lost.
                            // In order to resolve this we simply set receiver ID to be the corp
                            // instead of character in these cases.
                            // Note that 'BuildJournalEntry' has similar processing.
                            if (int.Parse(journEntry.SelectSingleNode("@refTypeID").Value) == 85)
                            {
                                recieverID = _corpID;
                            }
                        }
                        if (recieverID == 0)
                        {
                            recieverID = long.Parse(journEntry.SelectSingleNode("@ownerID2").Value);
                        }

                        //if (id - offset > oldHighestID)
                        //{
                        if (id - offset > highestIDSoFar) { highestIDSoFar = id - offset; }
                        if (Journal.EntryExists(journalData, id, recieverID))
                        {
                            tryUpdate = true;
                        }
                        else
                        {
                            EMMADataSet.JournalRow tmpRow = journalData.FindByIDRecieverID(id, recieverID);
                            if (tmpRow == null)
                            {
                                EMMADataSet.JournalRow newRow =
                                    BuildJournalEntry(journalData, journEntry, offset, walletID, corc);

                                journalData.AddJournalRow(newRow);
                                retVal++;

                                // This section searches the character and journal ref type tables
                                // for the values used in this new journal entry.
                                // If they are not present in the tables then they are added.
                                #region Check other tables and add values if needed.
                                SortedList<long, string> entityIDs = new SortedList<long, string>();
                                entityIDs.Add(newRow.SenderID, journEntry.SelectSingleNode("@ownerName1").Value);
                                if (!entityIDs.ContainsKey(newRow.RecieverID))
                                {
                                    entityIDs.Add(newRow.RecieverID, journEntry.SelectSingleNode("@ownerName2").Value);
                                }
                                foreach (KeyValuePair<long, string> checkName in entityIDs)
                                {
                                    Names.AddName(checkName.Key, checkName.Value);
                                }
                                #endregion
                            }
                            else
                            {
                                tryUpdate = true;
                            }
                        }

                        if (tryUpdate)
                        {
                            EMMADataSet.JournalRow newRow =
                                BuildJournalEntry(journalData, journEntry, offset, walletID, corc);
                            EMMADataSet.JournalRow oldRow = journalData.FindByIDRecieverID(newRow.ID,
                                    newRow.RecieverID);
                            bool updated = false;

                            if (oldRow != null)
                            {
                                if ((newRow.RBalance > 0 && oldRow.RBalance == 0) ||
                                    (newRow.RCorpID != 0 && oldRow.RCorpID == 0))
                                {
                                    oldRow.RBalance = newRow.RBalance;
                                    oldRow.RCorpID = newRow.RCorpID;
                                    oldRow.RArgID = newRow.RArgID;
                                    oldRow.RArgName = newRow.RArgName;
                                    oldRow.RWalletID = newRow.RWalletID;
                                    updated = true;
                                }
                                if ((newRow.SBalance > 0 && oldRow.SBalance == 0) ||
                                    (newRow.SCorpID != 0 && oldRow.SCorpID == 0))
                                {
                                    oldRow.SBalance = newRow.SBalance;
                                    oldRow.SCorpID = newRow.SCorpID;
                                    oldRow.SArgID = newRow.SArgID;
                                    oldRow.SArgName = newRow.SArgName;
                                    oldRow.SWalletID = newRow.SWalletID;
                                    updated = true;
                                }
                            }

                            if (updated)
                            {
                                updatedEntries++;
                            }
                        }

                        //}

                        batchPrg++;
                        UpdateStatus(batchPrg, journEntries.Count, "", "", false);
                    }

                    SetHighestID(corc, APIDataType.Journal, highestIDSoFar);
                }

                UpdateStatus(0, 0, retVal + " journal entries added to database.", "", false);
                UpdateStatus(0, 0, updatedEntries + " existing journal entries updated.", "", true);

                if (journalData.Count > 0)
                {
                    Journal.Store(journalData);
                }
            }
            catch (Exception ex)
            {
                EMMAException emmaEx = ex as EMMAException;
                if (emmaEx == null)
                {
                    // If we've caught a standard exception rather than an EMMA one then log
                    // it by creating a new exception.
                    // Note that we don't need to actually throw it..
                    emmaEx = new EMMAException(ExceptionSeverity.Error, "Error when adding journal data", ex);
                }

                SetLastAPIUpdateError(corc, APIDataType.Journal, ex.Message);
                UpdateStatus(-1, 0, "Error", ex.Message, true);
            }

            if (UpdateEvent != null)
            {
                UpdateEvent(this, new APIUpdateEventArgs(APIDataType.Journal,
                    corc == CharOrCorp.Char ? _charID : _corpID,
                    APIUpdateEventType.UpdateCompleted));
            }

            return retVal;
        }
コード例 #4
0
        public void LoadOldEmmaXML(string filename, long charID, long corpID)
        {
            EMMADataSet.JournalDataTable table = new EMMADataSet.JournalDataTable();
            XmlDocument xml = new XmlDocument();
            //UpdateStatus(0, 0, "", "Loading file", false);
            xml.Load(filename);

            XmlNodeList nodes = xml.SelectNodes("/DocumentElement/Journal");

            int counter = 0;
            UpdateStatus(0, 0, "", "Extracting data from XML", false);
            foreach (XmlNode node in nodes)
            {
                bool tryUpdate = true;
                long id = long.Parse(node.SelectSingleNode("ID").FirstChild.Value) + 1085796677;
                long recieverID = long.Parse(node.SelectSingleNode("OwnerID2").FirstChild.Value);

                if (!EntryExists(table, id, recieverID))
                {
                    EMMADataSet.JournalRow tmpRow = table.FindByIDRecieverID(id, recieverID);
                    if (tmpRow == null)
                    {
                        EMMADataSet.JournalRow newRow = BuildRow(corpID, node, id, recieverID, table);
                        table.AddJournalRow(newRow);
                        tryUpdate = false;
                    }
                }
                if (tryUpdate)
                {
                    EMMADataSet.JournalRow newRow = BuildRow(corpID, node, id, recieverID, table);
                    EMMADataSet.JournalRow oldRow = table.FindByIDRecieverID(newRow.ID,
                        newRow.RecieverID);

                    if ((newRow.RBalance > 0 && oldRow.RBalance == 0) ||
                        (newRow.RCorpID != 0 && oldRow.RCorpID == 0))
                    {
                        oldRow.RBalance = newRow.RBalance;
                        oldRow.RCorpID = newRow.RCorpID;
                        oldRow.RArgID = newRow.RArgID;
                        oldRow.RArgName = newRow.RArgName;
                        oldRow.RWalletID = newRow.RWalletID;
                    }
                    if ((newRow.SBalance > 0 && oldRow.SBalance == 0) ||
                        (newRow.SCorpID != 0 && oldRow.SCorpID == 0))
                    {
                        oldRow.SBalance = newRow.SBalance;
                        oldRow.SCorpID = newRow.SCorpID;
                        oldRow.SArgID = newRow.SArgID;
                        oldRow.SArgName = newRow.SArgName;
                        oldRow.SWalletID = newRow.SWalletID;
                    }
                }
                counter++;
                UpdateStatus(counter, nodes.Count, "", "", false);

                // If we've got 1000 rows then update the database and move on to the next batch.
                if (table.Count >= 1000)
                {
                    UpdateStatus(0, 0, "", "Updating database", false);
                    lock (tableAdapter)
                    {
                        tableAdapter.Update(table);
                        table.Clear();
                    }
                }
            }

            UpdateStatus(0, 0, "", "Updating database", false);
            lock (tableAdapter)
            {
                tableAdapter.Update(table);
            }
        }
コード例 #5
0
        public static EMMADataSet.JournalDataTable LoadEntriesData(List<FinanceAccessParams> accessParams, 
            List<short> typeIDs, DateTime startDate, DateTime endDate, string nameProfile)
        {
            EMMADataSet.JournalDataTable table = new EMMADataSet.JournalDataTable();

            startDate = startDate.ToUniversalTime();
            endDate = endDate.ToUniversalTime();
            if (startDate.CompareTo(SqlDateTime.MinValue.Value) < 0) startDate = SqlDateTime.MinValue.Value;
            if (endDate.CompareTo(SqlDateTime.MinValue.Value) < 0) endDate = SqlDateTime.MinValue.Value;
            if (startDate.CompareTo(SqlDateTime.MaxValue.Value) > 0) startDate = SqlDateTime.MaxValue.Value;
            if (endDate.CompareTo(SqlDateTime.MaxValue.Value) > 0) endDate = SqlDateTime.MaxValue.Value;

            if (typeIDs.Count == 0) { typeIDs.Add(0); }

            string typeString = "";
            foreach (short typeID in typeIDs) { typeString = typeString + (typeString.Length == 0 ? "" : ",") + typeID; }
            lock (tableAdapter)
            {
                Diagnostics.StartTimer("Journal.LoadEntries.Database");
                if (string.IsNullOrEmpty(nameProfile))
                {
                    tableAdapter.FillByAny(table, FinanceAccessParams.BuildAccessList(accessParams), typeString,
                        startDate, endDate);
                }
                else
                {
                    tableAdapter.FillByAnyAndName(table, FinanceAccessParams.BuildAccessList(accessParams),
                        typeString, startDate, endDate, nameProfile);
                }
                Diagnostics.StopTimer("Journal.LoadEntries.Database");
            }
            return table;
        }
コード例 #6
0
        public static bool HasBrokerFeePayment(long ownerID, DateTime date, decimal expectedFee)
        {
            EMMADataSet.JournalDataTable table = new EMMADataSet.JournalDataTable();
            bool retVal = false;
            DateTime startDate, endDate;
            date = date.ToUniversalTime();
            startDate = date.AddMinutes(-1);
            endDate = date.AddMinutes(1);
            lock (tableAdapter)
            {
                tableAdapter.FillByRefTypeAndTime(table, ownerID, startDate, endDate, 46);
            }
            foreach (EMMADataSet.JournalRow row in table)
            {
                if (row.Amount > expectedFee * 0.95m && row.Amount < expectedFee * 1.05m)
                {
                    retVal = true;
                }
            }

            return retVal;
        }
コード例 #7
0
 public static EMMADataSet.JournalDataTable GetUnprocessedDivs()
 {
     EMMADataSet.JournalDataTable table = new EMMADataSet.JournalDataTable();
     lock (tableAdapter)
     {
         tableAdapter.FillByUnprocessedDivs(table, FinanceAccessParams.BuildAccessList(
             UserAccount.CurrentGroup.GetFinanceAccessParams(APIDataType.Journal)));
     }
     return table;
 }