示例#1
0
        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));
        }
示例#2
0
        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();
            }
        }
示例#3
0
        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());
            }
        }
示例#4
0
        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);
            }
        }
示例#5
0
        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)
            {
            }
        }
示例#6
0
        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);
        }
示例#8
0
        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);
        }