private void CreateNewDatabase() { const int initialNextPageNumber = 0; State = new StorageEnvironmentState(null, initialNextPageNumber) { Options = Options }; var transactionPersistentContext = new TransactionPersistentContext(); using (var tx = NewLowLevelTransaction(transactionPersistentContext, TransactionFlags.ReadWrite)) using (var root = Tree.Create(tx, null, Constants.RootTreeNameSlice)) { // important to first create the root trees, then set them on the env tx.UpdateRootsIfNeeded(root); using (var treesTx = new Transaction(tx)) { DbId = Guid.NewGuid(); FillBase64Id(DbId); var metadataTree = treesTx.CreateTree(Constants.MetadataTreeNameSlice); metadataTree.Add("db-id", DbId.ToByteArray()); metadataTree.Add("schema-version", EndianBitConverter.Little.GetBytes(Options.SchemaVersion)); treesTx.PrepareForCommit(); tx.Commit(); } } }
public virtual int CompareTo(BTriggerSystem ts, TriggerScriptObjectWithArgs obj) { if (Name != obj.Name) { Debug.Trace.Engine.TraceInformation( "TriggerProtoDbObject: '{0}' - Encountered different names for {1}, '{2}' != '{3}'", ts, this.DbId.ToString(), this.Name, obj.Name); } if (ContainsUserClassTypeVar(ts, obj)) { Debug.Trace.Engine.TraceInformation( "TriggerProtoDbObject: {0} - Encountered {1}/{2} which has a UserClassType Var, skipping comparison", ts, DbId.ToString(), Name); return(0); } Contract.Assert(Version == obj.Version); Contract.Assert(Params.Count == obj.Args.Count); int diff = 0; for (int x = 0; x < Params.Count; x++) { int sig = Params[x].SigID; int obj_sig = obj.Args[x].SigID; sig = sig < 0 ? 0 : sig; obj_sig = obj_sig < 0 ? 0 : obj_sig; diff += sig - obj_sig; } return(diff); }
public PlayQueueSource() : base(Catalog.GetString("Play Queue"), null) { BindToDatabase(); TypeUniqueId = DbId.ToString(); Initialize(); AfterInitialized(); Order = 20; Properties.SetString("Icon.Name", "source-playlist"); Properties.SetString("RemoveTracksActionLabel", Catalog.GetString("Remove From Play Queue")); DatabaseTrackModel.ForcedSortQuery = "CorePlaylistEntries.ViewOrder ASC, CorePlaylistEntries.EntryID ASC"; DatabaseTrackModel.CanReorder = true; ServiceManager.PlayerEngine.ConnectEvent(OnPlayerEvent); ServiceManager.PlaybackController.TrackStarted += OnTrackStarted; // TODO change this Gtk.Action code so that the actions can be removed. And so this // class doesn't depend on Gtk/ThickClient. actions = new PlayQueueActions(this); Properties.SetString("ActiveSourceUIResource", "ActiveSourceUI.xml"); Properties.SetString("GtkActionPath", "/PlayQueueContextMenu"); // TODO listen to all primary sources, and handle transient primary sources ServiceManager.SourceManager.MusicLibrary.TracksChanged += HandleTracksChanged; ServiceManager.SourceManager.MusicLibrary.TracksDeleted += HandleTracksDeleted; ServiceManager.SourceManager.VideoLibrary.TracksChanged += HandleTracksChanged; ServiceManager.SourceManager.VideoLibrary.TracksDeleted += HandleTracksDeleted; populate_from = ServiceManager.SourceManager.Sources.FirstOrDefault( source => source.Name == populate_from_name) as DatabaseSource; if (populate_from != null) { populate_from.Reload(); } TrackModel.Reloaded += HandleReloaded; int saved_offset = DatabaseConfigurationClient.Client.Get(CurrentOffsetSchema, CurrentOffsetSchema.Get()); Offset = Math.Min( saved_offset, ServiceManager.DbConnection.Query <long> (@" SELECT MAX(ViewOrder) + 1 FROM CorePlaylistEntries WHERE PlaylistID = ?", DbId)); ServiceManager.SourceManager.AddSource(this); }
private void InitializeDatabase() { using (var tx = _env.NewTransaction(TransactionFlags.ReadWrite)) { _env.CreateTree(tx, LogsTreeName); _env.CreateTree(tx, EntryTermsTreeName); var metadata = _env.CreateTree(tx, MetadataTreeName); var versionReadResult = metadata.Read("version"); if (versionReadResult == null) // new db { metadata.Add("version", Encoding.UTF8.GetBytes(CurrentVersion)); DbId = Guid.NewGuid(); metadata.Add("db-id", DbId.ToByteArray()); metadata.Add("current-term", EndianBitConverter.Little.GetBytes(0L)); metadata.Add("voted-for", Encoding.UTF8.GetBytes(string.Empty)); metadata.Add("voted-for-term", EndianBitConverter.Little.GetBytes(-1L)); metadata.Add("is-leader-potential", EndianBitConverter.Little.GetBytes(0)); } else { var dbVersion = versionReadResult.Reader.ToStringValue(); if (dbVersion != CurrentVersion) { throw new InvalidOperationException("Cannot open db because its version is " + dbVersion + " but the library expects version " + CurrentVersion); } int used; var bytes = metadata.Read("db-id").Reader.ReadBytes(16, out used).Take(16).ToArray(); DbId = new Guid(bytes); CurrentTerm = metadata.Read("current-term").Reader.ReadLittleEndianInt64(); var votedFor = metadata.Read("voted-for"); VotedFor = votedFor.Reader.Length == 0 ? null : votedFor.Reader.ToStringValue(); var votedForTerm = metadata.Read("voted-for-term"); VotedForTerm = votedForTerm.Reader.ReadLittleEndianInt64(); } tx.Commit(); } }
partial void OnIdChanging(DbId <Item, System.Guid> value);
partial void OnIdChanging(DbId <Country, System.Int32> value);
partial void OnIdChanging(DbId <Address, System.Int32> value);
partial void OnIdChanging(DbId <TestTable4, System.Int32> value);
partial void OnIdChanging(DbId <TestTable2, System.Guid> value);
public int CompareTo(DbId <TDbEntity, TIdStorage> other) { return(_Id.CompareTo(other._Id)); }
partial void OnIdChanging(DbId <User, System.Int32> value);
public Post() { DbId = ObjectId.GenerateNewId(); Id = DbId.GetHashCode(); }
private unsafe void LoadExistingDatabase() { var header = stackalloc TransactionHeader[1]; bool hadIntegrityIssues = _journal.RecoverDatabase(header); if (hadIntegrityIssues) { var message = _journal.Files.Count == 0 ? "Unrecoverable database" : "Database recovered partially. Some data was lost."; _options.InvokeRecoveryError(this, message, null); } var entry = _headerAccessor.CopyHeader(); var nextPageNumber = (header->TransactionId == 0 ? entry.LastPageNumber : header->LastPageNumber) + 1; State = new StorageEnvironmentState(null, nextPageNumber) { NextPageNumber = nextPageNumber, Options = Options }; _transactionsCounter = (header->TransactionId == 0 ? entry.TransactionId : header->TransactionId); var transactionPersistentContext = new TransactionPersistentContext(true); using (var tx = NewLowLevelTransaction(transactionPersistentContext, TransactionFlags.ReadWrite)) { using (var root = Tree.Open(tx, null, Constants.RootTreeNameSlice, header->TransactionId == 0 ? &entry.Root : &header->Root)) { tx.UpdateRootsIfNeeded(root); using (var treesTx = new Transaction(tx)) { var metadataTree = treesTx.ReadTree(Constants.MetadataTreeNameSlice); if (metadataTree == null) { VoronUnrecoverableErrorException.Raise(this, "Could not find metadata tree in database, possible mismatch / corruption?"); } var dbId = metadataTree.Read("db-id"); if (dbId == null) { VoronUnrecoverableErrorException.Raise(this, "Could not find db id in metadata tree, possible mismatch / corruption?"); } var buffer = new byte[16]; var dbIdBytes = dbId.Reader.Read(buffer, 0, 16); if (dbIdBytes != 16) { VoronUnrecoverableErrorException.Raise(this, "The db id value in metadata tree wasn't 16 bytes in size, possible mismatch / corruption?"); } var databseGuidId = _options.GenerateNewDatabaseId == false ? new Guid(buffer) : Guid.NewGuid(); DbId = databseGuidId; FillBase64Id(databseGuidId); if (_options.GenerateNewDatabaseId) { // save the new database id metadataTree.Add("db-id", DbId.ToByteArray()); } var schemaVersion = metadataTree.Read("schema-version"); if (schemaVersion == null) { VoronUnrecoverableErrorException.Raise(this, "Could not find schema version in metadata tree, possible mismatch / corruption?"); } var schemaVersionVal = schemaVersion.Reader.ReadLittleEndianInt32(); if (Options.SchemaVersion != 0 && schemaVersionVal != Options.SchemaVersion) { VoronUnrecoverableErrorException.Raise(this, "The schema version of this database is expected to be " + Options.SchemaVersion + " but is actually " + schemaVersionVal + ". You need to upgrade the schema."); } tx.Commit(); } } } }
partial void OnIdChanging(DbId <Order, System.Guid> value);
public bool Equals(DbId <TDbEntity, TIdStorage> other) { return(other._Id.Equals(_Id)); }
partial void OnIdChanging(DbId <Person, System.Int32> value);
partial void OnOrderIdChanging(DbId <Order, System.Int32> value);