示例#1
0
        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));
            }
        }
示例#2
0
        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);
        }
示例#3
0
 /// <summary>
 /// Authenticates the specified connection.
 /// </summary>
 /// <param name="connection">The connection.</param>
 /// <param name="collection">The collection.</param>
 /// <param name="username">The username.</param>
 /// <param name="nonce">The nonce.</param>
 /// <param name="key">The key.</param>
 /// <returns></returns>
 public static bool authenticate(this IDBConnection connection, IDBCollection collection, string username, string nonce, SecureString key)
 {
     DBQuery cmd = BuildQuery_authenticate(username, nonce, key);
     IDocument result = connection.Call<Document>(new Query(new DBCursorOptions(collection, selector: cmd, limit: 1))).Documents.FirstOrDefault();
     DBError err;
     return !result.WasError(out err);
 }
示例#4
0
        public DatabaseError ReadRecord(IDBCollection record)
        {
            m_ErrorCode = DatabaseError.NoError;
            SQLiteCommand sqlite_cmd = (SQLiteCommand)m_conn.CreateCommand();

            sqlite_cmd.CommandText = record.GetDBQuery();
            try
            {
                SQLiteDataReader sqlite_datareader = sqlite_cmd.ExecuteReader();
                if (sqlite_datareader.Read())
                {
                    record.FillRecords(sqlite_datareader);
                }
                else
                {
                    m_ErrorCode = DatabaseError.NoRecordsFound;
                }
            }
            catch (System.Data.SQLite.SQLiteException e)
            {
                string msg = e.Message;
                m_ErrorCode = DatabaseError.ExceptionSQL;
            }
            return(m_ErrorCode);
        }
示例#5
0
        public IEnumerable <ISourcedEvent> GetAllEventsSinceVersion(Guid id, long version)
        {
            IDBCollection eventSources = database.GetCollection("Events");

            var       query  = new DBQuery("_SourceId", id.ToString());
            IDocument source = eventSources.FindOne();

            if (source == null)
            {
                return new SourcedEvent[] { }
            }
            ;

            var eventsAsDbObjects = ((DBObjectArray)source["_Events"]).Values.Cast <IDBObject>();

            //no benefit yield now we have single doc - might confused people due to lazy style invocation - esp if exception thrown
            var events = new List <SourcedEvent>();

            foreach (var eventDbObject in eventsAsDbObjects)
            {
                var evnt = DeserializeToEventIDBObject(eventDbObject);

                // TODO: Optimize: do not first serializing event before event sequence check.
                if (evnt.EventSequence > version)
                {
                    events.Add(evnt);
                }
            }

            // TODO: Add order to the query for optimization.
            return(events.OrderBy(evnt => evnt.EventSequence));
        }
示例#6
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));
        }
示例#7
0
 public CDKeyService(
     IDBCollection collection,
     IPlayerService playerService
     ) : base(collection.CDKeys)
 {
     this.uniqueFieldName = "_id";
     this.playerService   = playerService;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="DBCursorOptions"/> class.
        /// </summary>
        /// <param name="collection">The collection to query against.</param>
        /// <param name="selector">The selector query.</param>
        /// <param name="returnFields">The fields to be returned.</param>
        /// <param name="orderBy">The field or fields to order the results by.</param>
        /// <param name="numberToSkip">The number of results to skip.</param>
        /// <param name="numberToReturn">The number to return in a given batch.</param>
        /// <param name="limit">If specified, only this many results are returned.</param>
        /// <param name="explain">if set to <c>true</c> a query explanation will be included.</param>
        /// <param name="snapshot">if set to <c>true</c> then execute against a data snapshot.</param>
        /// <param name="flags">The option flags.</param>
        /// <param name="explicitIndexHint">The explicit index hint.</param>
        public DBCursorOptions(IDBCollection collection,
            DBQuery selector = null,
            DBFieldSet returnFields = null,
            DBFieldSet orderBy = null,
            int? numberToSkip = null,
            int? numberToReturn = null,
            int? limit = null,
            bool explain = false,
            bool snapshot = false,
            CursorFlags flags = CursorFlags.None,
            IDBIndex explicitIndexHint = null)
        {
            Condition.Requires(snapshot, "snapshot")
                .Evaluate(!(snapshot && explicitIndexHint != null), "Snapshot is not allowed when there is an explicit hint")
                .Evaluate(!(snapshot && orderBy != null), "Snapshot is not allowed when there field set to order by");
            Condition.Requires(numberToReturn, "numberToReturn")
                .Evaluate(!(numberToReturn.HasValue && limit.HasValue), "You may not specify both numberToReturn AND limit. They are ways to set a common property. Choose one to set.");

            Collection = collection;
            Selector = selector ?? DBQuery.SelectAll;
            ReturnFields = returnFields;
            Explain = explain;
            Flags = flags;
            Hint = explicitIndexHint;
            OrderBy = orderBy;
            Snapshot = snapshot;

            if (numberToSkip.HasValue)
                NumberToSkip = numberToSkip;
            if (numberToReturn.HasValue)
                NumberToReturn = numberToReturn.Value;
            if (limit.HasValue)
                Limit = limit;

            //If we have special query details
            if (OrderBy != null && OrderBy.Keys.Any() ||
                Hint != null ||
                Explain)
            {
                //Push everything into a container
                DBQuery query = Selector;
                Selector = new DBQuery();
                Selector["query"] = query;
                if (OrderBy != null && OrderBy.Keys.Any())
                    Selector["orderby"] = OrderBy;
                if (Hint != null)
                    Selector["$hint"] = Hint.Name;
                if (Explain)
                    Selector["$explain"] = true;
                if (Snapshot)
                    Selector["$snapshot"] = true;
            }
        }
示例#9
0
        private void toolStripButtonCreateTable_Click(object sender, EventArgs e)
        {
            if (-1 == this.toolStripComboBoxTableList.SelectedIndex)
            {
                return;
            }

            IDBCollection col = this.toolStripComboBoxTableList.SelectedItem as IDBCollection;

            if (null != col)
            {
                col.CreateTable(m_db);
            }
        }
示例#10
0
        /// <summary>
        /// Deletes the specified indexes.
        /// </summary>
        /// <remarks>Specifying "*" will delete all indexes on the specified collection.</remarks>
        /// <param name="db">The db.</param>
        /// <param name="collection">The collection.</param>
        /// <param name="indexName">Name of the index.</param>
        public static void deleteIndexes(this IDatabase db, IDBCollection collection, string indexName)
        {
            DBQuery cmd = new DBQuery
            {
                {"deleteIndexes", collection.Name},
                {"index", string.IsNullOrWhiteSpace(indexName)? "*" : indexName}
            };

            IDBObject res = db.ExecuteCommand(cmd);
            DBError error;
            if (res.WasError(out error))
            {
                if (error.NamespaceWasNotFound)
                    return;
                error.Throw("deleteIndexes failed");
            }
        }
示例#11
0
        public virtual void Save(IEventSource source)
        {
            IEnumerable <ISourcedEvent> eventsToSave = source.GetUncommittedEvents();

            IDBCollection sources = database.GetCollection("Events");

            if (IsNewEventSource(source))
            {
                InsertNewEventSource(source, eventsToSave, sources);
                VerifyInsertSuccessful(source);
            }
            else
            {
                PushOptimisticUpdate(source, eventsToSave, sources);
                VerifyUpdateSuccessful(source);
            }
        }
示例#12
0
        /// <summary>
        /// Groups data on the server
        /// </summary>
        /// <param name="db">The db.</param>
        /// <param name="collection">The collection.</param>
        /// <param name="key">The key.</param>
        /// <param name="cond">The cond.</param>
        /// <param name="initial">The initial.</param>
        /// <param name="reduce">The reduce.</param>
        /// <returns></returns>
        public static IDBObject group(this IDatabase db, IDBCollection collection, DBFieldSet key, DBQuery cond, IDocument initial, string reduce)
        {
            DBObject group = new DBObject()
            {
                  {"ns", collection.Name},
                  {"$reduce", reduce},
            };

            if (key != null)
                group["key"] = key;

            if (cond != null)
                group["cond"] = cond;

            if (initial != null)
                group["initial"] = initial;

            IDBObject ret = db.ExecuteCommand(new DBQuery("group", group));
            ret.ThrowIfResponseNotOK("group failed");
            return ret.GetAsIDBObject("retval");
        }
示例#13
0
        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);
        }
示例#14
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);
            }
        }
示例#15
0
 /// <summary>
 /// Drops the collection.
 /// </summary>
 /// <param name="collection">The collection.</param>
 public void DropCollection(IDBCollection collection)
 {
     if (ReadOnly)
         throw new ReadOnlyException("Cannot drop a collection when using a readonly binding");
     Condition.Requires(collection, "collection").IsNotNull();
     this.drop(collection.Name);
     collection.ClearIndexCache();
 }
示例#16
0
        private void PushOptimisticUpdate(IEventSource source, IEnumerable <ISourcedEvent> eventsToSave, IDBCollection sources)
        {
            var arrayOfEventsAsIdbObjects = GetArrayOfEventsAsIDBObjects(source, eventsToSave);

            sources.Update(new DBQuery()
            {
                { "_SourceId", source.EventSourceId.ToString() },
                { "_Version", source.InitialVersion }
            }
                           , Do.AddEachToSet("Events", arrayOfEventsAsIdbObjects
                                             ).Set("_Version", source.Version));
        }
示例#17
0
 public CollectionNode(IDBCollection collection, DatabaseNode parent)
     : base(parent)
 {
     Collection = collection;
 }
示例#18
0
 private void PushOptimisticUpdate(IEventSource source, IEnumerable<ISourcedEvent> eventsToSave, IDBCollection sources)
 {
     var arrayOfEventsAsIdbObjects = GetArrayOfEventsAsIDBObjects(source, eventsToSave);
     sources.Update(new DBQuery()
                        {
                            {"_SourceId", source.EventSourceId.ToString()},
                            {"_Version", source.InitialVersion}
                        }
                    , Do.AddEachToSet("Events", arrayOfEventsAsIdbObjects
                          ).Set("_Version", source.Version));
 }
示例#19
0
 public PlayerService(IDBCollection collection) : base(collection.Players)
 {
     this.uniqueFieldName = "dbname";
 }
示例#20
0
 public GameService(IDBCollection collection) : base(collection.Games)
 {
     this.uniqueFieldName = "dbname";
 }
示例#21
0
        private void InsertNewEventSource(IEventSource source, IEnumerable<ISourcedEvent> eventsToSave, IDBCollection sources)
        {
            var arrayOfEventsAsIdbObjects = GetArrayOfEventsAsIDBObjects(source, eventsToSave);
            var doc = new Document
                          {
                              {"_SourceId", source.EventSourceId.ToString()},
                              {"_Events", arrayOfEventsAsIdbObjects},
                              {"_Version", arrayOfEventsAsIdbObjects.Length}
                          };

            // TODO: Add thread safe check. But, the driver should support checks on insert.
            sources.Insert(doc);
            VerifyInsertSuccessful(source);
        }
 static Program()
 {
     objDBCollection = new SuperHeroDBCollection();
 }
示例#23
0
        private void InsertNewEventSource(IEventSource source, IEnumerable <ISourcedEvent> eventsToSave, IDBCollection sources)
        {
            var arrayOfEventsAsIdbObjects = GetArrayOfEventsAsIDBObjects(source, eventsToSave);
            var doc = new Document
            {
                { "_SourceId", source.EventSourceId.ToString() },
                { "_Events", arrayOfEventsAsIdbObjects },
                { "_Version", arrayOfEventsAsIdbObjects.Length }
            };

            // TODO: Add thread safe check. But, the driver should support checks on insert.
            sources.Insert(doc);
            VerifyInsertSuccessful(source);
        }
示例#24
0
 public Processor(Id id, IDBCollection coll)
     : base(id, coll)
 {
 }
示例#25
0
 public RAM(Id id, IDBCollection coll)
     : base(id, coll)
 {
 }
示例#26
0
 public Foo(Id id, IDBCollection _dbCollection)
     : base(id, _dbCollection)
 {
 }
示例#27
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DBRef"/> class.
 /// </summary>
 /// <param name="collection">The collection.</param>
 /// <param name="id">The id.</param>
 public DBRef(IDBCollection collection, object id)
 {
     Collection = collection;
     ID = id;
 }
示例#28
0
 /// <summary>
 /// Gets a nonce for subsequent communication
 /// </summary>
 /// <param name="connection">The connection.</param>
 /// <param name="cmdCollection">The CMD collection.</param>
 /// <returns></returns>
 public static string nonce(this IDBConnection connection, IDBCollection cmdCollection)
 {
     IDocument result = connection.Call<Document>(new Query(new DBCursorOptions(cmdCollection, selector: _getnonce, limit: 1))).Documents.FirstOrDefault();
     result.ThrowIfResponseNotOK("unable to get nonce value for authentication");
     return result.GetAsString("nonce");
 }
示例#29
0
        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);
        }
示例#30
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);
        }
示例#31
0
 string _testMulti(IDBCollection c)
 {
     string test = "";
     foreach (IDBObject z in c.Find(orderBy:"_id"))
     {
         if (test.Length > 0)
             test += ",";
         test += z["test"];
     }
     return test;
 }
示例#32
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MapReduceInfo"/> class.
 /// </summary>
 /// <param name="from">From.</param>
 /// <param name="raw">The raw.</param>
 public MapReduceInfo(IDBCollection from, DBObject raw)
 {
     ResultingCollection = from.Database.GetCollection(raw.GetAsString("result"));
     Counts = (IDocument)raw["counts"];
 }