private void buttonJournalFilter_Click(object sender, EventArgs e) { listViewJournal.Items.Clear(); if (-1 == this.toolStripComboBoxCharacterSelection.SelectedIndex) { return; } CharacterObject charObj = (CharacterObject) this.toolStripComboBoxCharacterSelection.SelectedItem; CharacterJournalCollection col = new CharacterJournalCollection(); IDBCollection icol = col as IDBCollection; JournalFilterObject obj = comboBoxJournalFilter.SelectedItem as JournalFilterObject; if (null != obj) { if (1 == obj.Count) { icol.SetConstraint((long)CharacterJournal.QueryValues.refType, new DBConstraint(DBConstraint.QueryConstraints.Equal, obj.Value(0))); } else if (0 != obj.Count) { throw new NotImplementedException(); } } DateTime start = dateTimePickerCharJournalStart.Value; DateTime end = dateTimePickerCharJournalEnd.Value; if (!checkBoxCharJournalStartUseTime.Checked) { start = start.Date; } if (!checkBoxCharJournalEndUseTime.Checked) { end = end.Date.AddDays(1).AddSeconds(-1); } icol.SetConstraint((long)CharacterJournal.QueryValues.CharID, new DBConstraint(DBConstraint.QueryConstraints.Equal, long.Parse(charObj.CharID))); icol.SetConstraint((long)CharacterJournal.QueryValues.date, new DBConstraint(DBConstraint.QueryConstraints.Between, start.ToOADate(), end.ToOADate())); icol.SetSortConstraint((long)CharacterJournal.QueryValues.date, new DBSortConstraint(DBSortConstraint.SortConstraints.Ascending)); if (Database.DatabaseError.NoError == this.m_db.ReadRecord(icol)) { IDBCollectionContents icolcon = col as IDBCollectionContents; for (long i = 0; i < icolcon.Count(); ++i) { listViewJournal.Items.Add(new JournalListViewItem(icolcon.GetRecordInterface(i).GetDataObject() as JournalObject)); } //listViewJournal.Items.Add(new JournalListViewItem(null)); } }
private void buttonMemberActivityFetch_Click(object sender, EventArgs e) { m_MemberActivityList.Clear(); if (-1 == this.toolStripComboBoxCharacterSelection.SelectedIndex) { return; } CharacterObject charObj = (CharacterObject) this.toolStripComboBoxCharacterSelection.SelectedItem; EveApiId id = new EveApiId(charObj.UserID.ToString(), charObj.FullKey); CorporationMemberTrackingCollection collection = EveApi.GetCorporationMemberTrackingList(m_db, id, charObj.CharID, true); IDBCollectionContents contents = collection as IDBCollectionContents; if (null != contents && 0 != contents.Count()) { for (int idx = 0; idx < contents.Count(); ++idx) { CorporationMemberTrackingObject obj = contents.GetRecordInterface(idx).GetDataObject() as CorporationMemberTrackingObject; if (null != obj) { m_MemberActivityList.Add(obj); } } } }
private static string CheckRequestCache(Database db, RequestID rid, string UserID, string url) { DateTime dt = TimeZone.CurrentTimeZone.ToUniversalTime(DateTime.Now); RequestCacheCollection col = new RequestCacheCollection(); IDBCollection icol = (IDBCollection)col; icol.SetConstraint((long)RequestCache.QueryValues.UserID, new DBConstraint(DBConstraint.QueryConstraints.Equal, UserID)); icol.SetConstraint((long)RequestCache.QueryValues.ValidUntil, new DBConstraint(DBConstraint.QueryConstraints.Greater, dt.ToOADate().ToString())); icol.SetConstraint((long)RequestCache.QueryValues.url, new DBConstraint(DBConstraint.QueryConstraints.Equal, url)); db.ReadRecord((IDBCollection)col); IDBCollectionContents ccol = (IDBCollectionContents)col; if (0 == ccol.Count()) { return(null); } IDBRecord rec = ccol.GetRecordInterface(0); RequestObject obj = (RequestObject)rec.GetDataObject(); Logger.ReportNotice("Using cached response, can make a new call after " + obj.ValidUntil.ToString()); return(Compression.Decompress(obj.Response)); }
private CorpWalletNameObjectWritable ReadWalletNames() { if (-1 == this.toolStripComboBoxCharacterSelection.SelectedIndex) { return(CreateDefaultWalletNames()); } CharacterObject charObj = (CharacterObject) this.toolStripComboBoxCharacterSelection.SelectedItem; CorpWalletNameCollection col = new CorpWalletNameCollection(); IDBCollection icol = col as IDBCollection; icol.SetConstraint((long)CorpWalletName.QueryValues.CorpID, new DBConstraint(DBConstraint.QueryConstraints.Equal, charObj.CorpID)); Database.DatabaseError dbErr = this.m_db.ReadRecord(icol); if (dbErr != Database.DatabaseError.NoError && dbErr != Database.DatabaseError.NoRecordsFound ) { // should report to logging return(CreateDefaultWalletNames()); } IDBCollectionContents icolcon = col as IDBCollectionContents; if (0 == icolcon.Count()) { return(CreateDefaultWalletNames()); } return(icolcon.GetRecordInterface(0).GetDataObject() as CorpWalletNameObjectWritable); }
private void buttonSelectCharacter_Click(object sender, EventArgs e) { if (0 == this.textBoxUserID.Text.Length || (0 == this.textBoxLimitedKey.Text.Length && 0 == this.textBoxFullKey.Text.Length) ) { MessageBox.Show("You must enter a UserID, and a Key before selecting a character."); return; } EveApiId id = new EveApiId(this.textBoxUserID.Text, (0 != textBoxFullKey.Text.Length) ? textBoxFullKey.Text : textBoxLimitedKey.Text); CharacterCollection col = EveApi.GetCharacterList(m_db, id); IDBCollectionContents con = (IDBCollectionContents)col; if (1 > con.Count()) { return; } ListSelectDlg ls = new ListSelectDlg(); for (int i = 0; i < con.Count(); ++i) { IDBRecord rec = con.GetRecordInterface(i); rec.SetValueString((ulong)Character.QueryValues.UserID, this.textBoxUserID.Text); rec.SetValueString((ulong)Character.QueryValues.LimitedKey, this.textBoxLimitedKey.Text); rec.SetValueString((ulong)Character.QueryValues.FullKey, this.textBoxFullKey.Text); rec.SetValueString((ulong)Character.QueryValues.RegCode, this.textBoxRegCode.Text); CharacterObject obj = (CharacterObject)rec.GetDataObject(); string test = obj.ToString(); ls.List.Items.Add(obj); } Button btn = (Button)sender; ls.Location = this.PointToScreen(new Point(btn.Location.X, btn.Location.Y + btn.Height)); DialogResult ret = ls.ShowDialog(); if (DialogResult.OK == ret) { CharacterObject newObj = (CharacterObject)ls.List.SelectedItem; foreach (CharacterObject obj in this.listBoxCharacters.Items) { if (0 == obj.ToString().CompareTo(newObj.ToString())) { this.listBoxCharacters.SelectedItem = obj; this.textBoxLimitedKey.Text = this.textBoxLimitedKey.Text; this.textBoxFullKey.Text = this.textBoxFullKey.Text; return; } } this.listBoxCharacters.SelectedIndex = -1; m_SelectedObject = newObj; FillFromNewCharacter(); } }
private static void WriteRequestCache(Database db, RequestID rid, string UserID, string url, string s) { RequestCacheCollection col = new RequestCacheCollection(rid, UserID, url, s); IDBCollectionContents ccol = (IDBCollectionContents)col; for (int i = 0; i < ccol.Count(); ++i) { // this loop should normally have only 1 iteration Logger.ReportNotice("Response Cached."); db.InsertRecord(ccol.GetRecordInterface(i)); } }
private void CharacterEditor_Load(object sender, EventArgs e) { CharacterCollection charcol = new CharacterCollection(); m_db.ReadRecord(charcol); IDBCollectionContents col = (IDBCollectionContents)charcol; for (long idx = 0; idx < col.Count(); idx++) { IDBRecord rec = col.GetRecordInterface(idx); this.listBoxCharacters.Items.Add(rec.GetDataObject()); } }
public static void InitConstants(Database db) { ReferenceTypeCollection col = new ReferenceTypeCollection(); db.ReadRecord(col as IDBCollection); IDBCollectionContents icol = col as IDBCollectionContents; for (long i = 0; i < icol.Count(); ++i) { IDBRecord rec = icol.GetRecordInterface(i); ReferenceTypeObject obj = rec.GetDataObject() as ReferenceTypeObject; m_RefValues.Add((int)obj.refTypeID, obj.refTypeName); } }
public Form1() { InitializeComponent(); //if (!AppData.bDEBUG) // this.debugToolStripMenuItem.Visible = false; Logger.SetLogger(this.richTextBoxLogging); m_db = new Database(); if (!m_db.IsOpen()) { return; } CharacterCollection charcol = new CharacterCollection(); m_db.ReadRecord(charcol); IDBCollectionContents col = (IDBCollectionContents)charcol; for (long idx = 0; idx < col.Count(); idx++) { IDBRecord rec = col.GetRecordInterface(idx); this.toolStripComboBoxCharacterSelection.Items.Add(rec.GetDataObject()); } if (0 != this.toolStripComboBoxCharacterSelection.Items.Count) { this.toolStripComboBoxCharacterSelection.SelectedIndex = 0; } Logger.ReportNotice("Initializing Reference Types Collection"); ReferenceTypeCollection refCol = EveApi.GetRefTypesList(m_db, false); //m_db.InsertRecord(refCol); Logger.ReportNotice("Using BulkLoader"); refCol.DoBulkLoader(m_db); Logger.ReportNotice("Done With BulkLoader"); AppData.InitConstants(m_db); CharJournalInit(); CharTransactionInit(); CorpJournalInit(); CorpTransInit(); if (AppData.bAutoFetch) { } }
public DatabaseError InsertOrUpdateRecord(IDBCollectionContents contents) { for (int i = 0; i < contents.Count(); ++i) { IDBRecord irec = contents.GetRecordInterface(i); ulong val = ulong.Parse(irec.GetValueString(irec.GetIDQueryValue())); if (val == 0) { InsertRecord(irec); } else { UpdateRecord(irec); } } return(m_ErrorCode); }
// collection indexes will not be updated with this call public DatabaseError InsertRecord(IDBCollectionContents contents) { m_ErrorCode = DatabaseError.NoError; SQLiteCommand sqlite_cmd = (SQLiteCommand)m_conn.CreateCommand(); for (int i = 0; i < contents.Count(); ++i) { try { sqlite_cmd.CommandText = contents.GetRecordInterface(i).GetDBInsert(); sqlite_cmd.ExecuteNonQuery(); } catch (System.Data.SQLite.SQLiteException e) { m_ErrorCode = DatabaseError.ExceptionSQL; Logger.ReportError(sqlite_cmd.CommandText); Logger.ReportError(e.Message); } } return(m_ErrorCode); }
private DatabaseError CheckVersion() { VersionCollection ver = new VersionCollection(); IDBCollection icol = ver as IDBCollection; icol.SetConstraint((long)Version.QueryValues.TableName, new DBConstraint(DBConstraint.QueryConstraints.Equal, "Version")); DatabaseError err = ReadRecord(icol); if (DatabaseError.NoRecordsFound == err || DatabaseError.ExceptionSQL == err) { return(m_ErrorCode = DatabaseError.CheckFailed_Unidentifiable); } IDBCollectionContents icolcon = ver as IDBCollectionContents; VersionObject vobj = icolcon.GetRecordInterface(0).GetDataObject() as VersionObject; if (vobj.VersionNumber != Version.VersionNumber) { return(m_ErrorCode = DatabaseError.CheckFailed_IncorrectVersion); } return(m_ErrorCode = DatabaseError.NoError); }
private void MarkTableVersion(IDBCollection col) { VersionCollection vcol = new VersionCollection(); IDBCollection ivcol = vcol as IDBCollection; ivcol.SetConstraint((long)Version.QueryValues.TableName, new DBConstraint(DBConstraint.QueryConstraints.Equal, col.GetTableName())); if (Database.DatabaseError.NoError == this.ReadRecord(ivcol)) { IDBCollectionContents icont = vcol as IDBCollectionContents; (icont.GetRecordInterface(0).GetDataObject() as VersionObjectInternal).VersionNumber = col.GetVersionNumber(); InsertOrUpdateRecord(vcol); } else { IDBRecord irec = ivcol.CreateBlankRecord(); VersionObjectInternal obj = irec.GetDataObject() as VersionObjectInternal; obj.TableName = col.GetTableName(); obj.VersionNumber = col.GetVersionNumber(); InsertOrUpdateRecord(irec); } }
public static CharacterJournalCollection GetCharacterJournalList(Database db, EveApiId id, string CharID, string beforeRefID, bool bAutoWalk, bool bUseCache) { if (!id.IsFullKey()) { return(new CharacterJournalCollection()); // return empty } CharacterJournalCollection journal = null; long remainder = 0; long lastCount = 0; do { string url = String.Format("{0}{1}?userID={2}&characterID={3}&apiKey={4}&accountKey=1000", ApiSite, CharJournalEntries, id.UserId, CharID, id.Key); if (null != beforeRefID && 0 < long.Parse(beforeRefID)) { url += String.Format("&beforeRefID={0}", beforeRefID); } string str = CheckRequestCache(db, RequestID.CharacterJournal, id.UserId, url); if (null == str) { Stream s = openUrl(url); if (null == s) { return((null != journal) ? journal : (new CharacterJournalCollection())); } str = new StreamReader(s).ReadToEnd(); WriteRequestCache(db, RequestID.CharacterJournal, id.UserId, url, str); } else if (!bUseCache) { break; // not allowed to use caching } XmlDocument xmlDoc = GetXml(new StringReader(str)); if (null == xmlDoc) { break; } if (null == journal) { journal = new CharacterJournalCollection(CharID, xmlDoc); } else { journal.AppendList(CharID, xmlDoc); } if (null == journal) { remainder = -1; } else { IDBCollectionContents con = (IDBCollectionContents)journal; if (0 == con.Count()) { remainder = -1; } else if (lastCount == con.Count()) { remainder = -1; } else { lastCount = con.Count(); remainder = con.Count() % 1000; if (0 == remainder) { IDBRecord rec1 = con.GetRecordInterface(con.Count() - 1000); JournalObject obj1 = (JournalObject)rec1.GetDataObject(); IDBRecord rec2 = con.GetRecordInterface(con.Count() - 1); JournalObject obj2 = (JournalObject)rec2.GetDataObject(); beforeRefID = Math.Min(obj1.refID, obj2.refID).ToString(); TimeSpan span = (obj2.date > obj1.date) ? obj2.date.Subtract(obj1.date) : obj1.date.Subtract(obj2.date); if (span.Days >= 7) { remainder = -1; // more than a week, so no more accessable } } } } } while (0 == remainder && bAutoWalk); if (null == journal) { return(new CharacterJournalCollection()); // create empty } return(journal); }
private void buttonCorpMissioner_Click(object sender, EventArgs e) { CorpMissionerTotal = 0; CorpMissionerRuns = 0; CorpMissionerPeople.Clear(); if (-1 == this.toolStripComboBoxCharacterSelection.SelectedIndex) { return; } Character.CharacterObject charObj = (Character.CharacterObject) this.toolStripComboBoxCharacterSelection.SelectedItem; DateTime start = dateTimePickerCorpMissionerStart.Value; DateTime end = dateTimePickerCorpMissionerEnd.Value; start = start.Date; end = end.Date.AddDays(1).AddSeconds(-1); int[] types = { 33, 34, 85 }; foreach (int typ in types) { CorporationJournalCollection col = new CorporationJournalCollection(); IDBCollection icol = col as IDBCollection; icol.SetConstraint((long)CorporationJournal.QueryValues.CorpID, new DBConstraint(DBConstraint.QueryConstraints.Equal, charObj.CorpID)); icol.SetConstraint((long)CorporationJournal.QueryValues.Division, new DBConstraint(DBConstraint.QueryConstraints.Equal, 1000)); // set date range icol.SetConstraint((long)CorporationJournal.QueryValues.date, new DBConstraint(DBConstraint.QueryConstraints.Between, start.ToOADate(), end.ToOADate())); // set Sorting icol.SetSortConstraint((long)CorporationJournal.QueryValues.ownerName2, new DBSortConstraint(DBSortConstraint.SortConstraints.Ascending)); // do Agent Rewards icol.SetConstraint((long)CorporationJournal.QueryValues.refType, new DBConstraint(DBConstraint.QueryConstraints.Equal, typ)); if (Database.DatabaseError.NoError == m_db.ReadRecord(icol)) { IDBCollectionContents icolcon = col as IDBCollectionContents; for (long i = 0; i < icolcon.Count(); ++i) { InsertMissionerRecord(icolcon.GetRecordInterface(i).GetDataObject() as JournalObject, typ); } } } CorpMissionerPeople.Sort(delegate(CorpMissionerPerson p1, CorpMissionerPerson p2) { return(p2.Total.CompareTo(p1.Total)); }); this.listViewCorpMissioner.Items.Clear(); foreach (CorpMissionerPerson person in CorpMissionerPeople) { ListViewItem item = new ListViewItem(); item.Text = person.Name; item.SubItems.Add(person.Runs.ToString()); item.SubItems.Add(string.Format("{0:#,##0.00;(#,##0.00);''}", person.Total)); this.listViewCorpMissioner.Items.Add(item); } ListViewItem itemTotal = new ListViewItem(); itemTotal.Text = "Total"; itemTotal.SubItems.Add(CorpMissionerRuns.ToString()); itemTotal.SubItems.Add(string.Format("{0:#,##0.00;(#,##0.00);''}", CorpMissionerTotal)); this.listViewCorpMissioner.Items.Add(itemTotal); }
private DatabaseError RepairDatabaseVersion() { DatabaseError err = m_ErrorCode; if (err != DatabaseError.CheckFailed_IncorrectVersion && err != DatabaseError.CheckFailed_Unidentifiable ) { return(m_ErrorCode = DatabaseError.Unexpected); } DialogResult ret = DialogResult.No; if (err == DatabaseError.CheckFailed_Unidentifiable) { ret = MessageBox.Show(String.Format(DBUpgradeWarning, "Your database version was not reconized.\r\n"), "Upgrade Database Version?", MessageBoxButtons.YesNo); } else { ret = MessageBox.Show(String.Format(DBUpgradeWarning, "Your database version is out-of-date."), "Upgrade Database Version?", MessageBoxButtons.YesNo); } if (ret != DialogResult.Yes) { return(m_ErrorCode = DatabaseError.UserAborted); } if (err == DatabaseError.CheckFailed_Unidentifiable) { this.ExecuteCommand("DROP TABLE " + Version.TableName); Version v = new Version(); CreateTable(v); ExecuteCommand(String.Format( "INSERT INTO Version (TableName) SELECT name FROM sqlite_master; " + "UPDATE Version SET VersionNumber=0; " + "UPDATE Version SET VersionNumber={0} WHERE TableName='{1}'", Version.VersionNumber, Version.TableName)); } foreach (IDBCollection col in m_Tables) { VersionCollection vercol = new VersionCollection(); IDBCollection ivercol = vercol as IDBCollection; ivercol.SetConstraint((long)Version.QueryValues.TableName, new DBConstraint(DBConstraint.QueryConstraints.Equal, col.GetTableName())); DatabaseError colErr = ReadRecord(vercol); if (DatabaseError.NoError == colErr) { IDBCollectionContents iconVercol = vercol as IDBCollectionContents; IDBRecord rec = iconVercol.GetRecordInterface(0); VersionObjectInternal obj = rec.GetDataObject() as VersionObjectInternal; if (obj.VersionNumber == col.GetVersionNumber()) { Logger.ReportNotice(String.Format("Table '{0}' version is up to date.", col.GetTableName())); } else { Logger.ReportNotice(String.Format("Table '{0}' version mismatch ({1}!={2}). Recreating", col.GetTableName(), obj.VersionNumber, col.GetVersionNumber())); IDBUpgrade icolUpgrade = col as IDBUpgrade; colErr = icolUpgrade.Upgrade(this, obj.VersionNumber); if (colErr != DatabaseError.NoError) { return(m_ErrorCode = DatabaseError.Unexpected); } obj.VersionNumber = col.GetVersionNumber(); this.UpdateRecord(rec); } } else if (DatabaseError.NoRecordsFound == colErr) { Logger.ReportNotice(String.Format("Table '{0}' missing. Creating new", col.GetTableName())); colErr = this.CreateTable(col.CreateBlankRecord()); if (colErr != DatabaseError.NoError) { return(m_ErrorCode = DatabaseError.Unexpected); } IDBRecord rec = ivercol.CreateBlankRecord(); VersionObjectInternal obj = rec.GetDataObject() as VersionObjectInternal; obj.TableName = col.GetTableName(); obj.VersionNumber = col.GetVersionNumber(); InsertRecord(rec); } else { return(m_ErrorCode = DatabaseError.Unexpected); } } return(m_ErrorCode = DatabaseError.NoError); }