本文整理汇总了C#中Microsoft.Isam.Esent.Interop.Session类的典型用法代码示例。如果您正苦于以下问题:C# Session类的具体用法?C# Session怎么用?C# Session使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Session类属于Microsoft.Isam.Esent.Interop命名空间,在下文中一共展示了Session类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestSessionToString
public void TestSessionToString()
{
using (var session = new Session(this.instance))
{
StringAssert.StartsWith(session.ToString(), "Session (");
}
}
示例2: Setup
public void Setup()
{
Microsoft.Isam.Esent.Interop.JET_TABLEID tableid;
this.directory = SetupHelper.CreateRandomDirectory();
this.database = Path.Combine(this.directory, "database.edb");
this.tablename = "table";
this.instance = SetupHelper.CreateNewInstance(this.directory);
// turn off logging so initialization is faster
Microsoft.Isam.Esent.Interop.Api.JetSetSystemParameter(this.instance, Microsoft.Isam.Esent.Interop.JET_SESID.Nil, Microsoft.Isam.Esent.Interop.JET_param.Recovery, 0, "off");
Microsoft.Isam.Esent.Interop.Api.JetSetSystemParameter(this.instance, Microsoft.Isam.Esent.Interop.JET_SESID.Nil, Microsoft.Isam.Esent.Interop.JET_param.MaxTemporaryTables, 0, null);
Microsoft.Isam.Esent.Interop.Api.JetInit(ref this.instance);
this.session = new Session(this.instance);
Microsoft.Isam.Esent.Interop.Api.JetCreateDatabase(this.session, this.database, String.Empty, out this.dbid, Microsoft.Isam.Esent.Interop.CreateDatabaseGrbit.None);
Microsoft.Isam.Esent.Interop.Api.JetBeginTransaction(this.session);
Microsoft.Isam.Esent.Interop.Api.JetCreateTable(this.session, this.dbid, this.tablename, 0, 100, out tableid);
var columndef = new Microsoft.Isam.Esent.Interop.JET_COLUMNDEF() { coltyp = Microsoft.Isam.Esent.Interop.JET_coltyp.Long };
Microsoft.Isam.Esent.Interop.Api.JetAddColumn(this.session, tableid, "Long", columndef, null, 0, out this.columnid);
string indexDef = "+long\0\0";
Microsoft.Isam.Esent.Interop.Api.JetCreateIndex(this.session, tableid, "primary", Microsoft.Isam.Esent.Interop.CreateIndexGrbit.IndexPrimary, indexDef, indexDef.Length, 100);
Microsoft.Isam.Esent.Interop.Api.JetCloseTable(this.session, tableid);
Microsoft.Isam.Esent.Interop.Api.JetCommitTransaction(this.session, Microsoft.Isam.Esent.Interop.CommitTransactionGrbit.LazyFlush);
Microsoft.Isam.Esent.Interop.Api.JetOpenTable(this.session, this.dbid, this.tablename, null, 0, Microsoft.Isam.Esent.Interop.OpenTableGrbit.None, out this.tableid);
}
示例3: CreateTable
internal static void CreateTable(Session session, JET_DBID dbid)
{
JET_TABLEID tableid;
Api.JetCreateTable(session, dbid, ifcHeaderTableName, 1, 100, out tableid);
using (var transaction = new Microsoft.Isam.Esent.Interop.Transaction(session))
{
JET_COLUMNID columnid;
var columndef = new JET_COLUMNDEF
{
coltyp = JET_coltyp.Long,
grbit = ColumndefGrbit.ColumnAutoincrement
};
Api.JetAddColumn(session, tableid, _colNameHeaderId, columndef, null, 0, out columnid);
columndef.coltyp = JET_coltyp.Currency;
columndef.grbit = ColumndefGrbit.ColumnNotNULL;
Api.JetAddColumn(session, tableid, _colNameEntityCount, columndef, null, 0, out columnid);
columndef.coltyp = JET_coltyp.LongBinary;
columndef.grbit = ColumndefGrbit.ColumnNotNULL;
Api.JetAddColumn(session, tableid, _colNameHeaderData, columndef, null, 0, out columnid);
columndef.coltyp = JET_coltyp.Text;
columndef.grbit = ColumndefGrbit.ColumnNotNULL;
columndef.cbMax = 32;
Api.JetAddColumn(session, tableid, _colNameFileVersion, columndef, null, 0, out columnid);
transaction.Commit(CommitTransactionGrbit.LazyFlush);
}
}
示例4: WithDatabase
public static void WithDatabase(this JET_INSTANCE instance, string database, Func<Session, JET_DBID, Transaction, Transaction> action)
{
using (var session = new Session(instance))
{
var tx = new Transaction(session);
try
{
JET_DBID dbid;
Api.JetOpenDatabase(session, database, "", out dbid, OpenDatabaseGrbit.None);
try
{
tx = action(session, dbid, tx);
}
finally
{
Api.JetCloseDatabase(session, dbid, CloseDatabaseGrbit.None);
}
tx.Commit(CommitTransactionGrbit.None);
}
finally
{
if(tx != null)
tx.Dispose();
}
}
}
示例5: StorageActionsAccessor
public StorageActionsAccessor(TableColumnsCache tableColumnsCache, JET_INSTANCE instance, string databaseName, UuidGenerator uuidGenerator, OrderedPartCollection<AbstractFileCodec> fileCodecs)
{
this.tableColumnsCache = tableColumnsCache;
this.uuidGenerator = uuidGenerator;
this.fileCodecs = fileCodecs;
try
{
session = new Session(instance);
transaction = new Transaction(session);
Api.JetOpenDatabase(session, databaseName, null, out database, OpenDatabaseGrbit.None);
}
catch (Exception original)
{
log.WarnException("Could not create accessor", original);
try
{
Dispose();
}
catch (Exception e)
{
log.WarnException("Could not properly dispose accessor after exception in ctor.", e);
}
throw;
}
}
示例6: Update
public void Update(Session session, JET_DBID dbid, Action<string> output)
{
using (var table = new Table(session, dbid, "indexes_stats", OpenTableGrbit.None))
{
byte[] defaultValue = BitConverter.GetBytes(1);
JET_COLUMNID columnid;
Api.JetAddColumn(session, table, "priority", new JET_COLUMNDEF
{
coltyp = JET_coltyp.Long,
grbit = ColumndefGrbit.ColumnFixed | ColumndefGrbit.ColumnNotNULL
}, defaultValue, defaultValue.Length, out columnid);
defaultValue = BitConverter.GetBytes(0);
Api.JetAddColumn(session, table, "created_timestamp", new JET_COLUMNDEF
{
cbMax = 8, //64 bits
coltyp = JET_coltyp.Binary,
grbit = ColumndefGrbit.ColumnFixed | ColumndefGrbit.ColumnNotNULL
}, defaultValue, defaultValue.Length, out columnid);
Api.JetAddColumn(session, table, "last_indexing_time", new JET_COLUMNDEF
{
cbMax = 8, //64 bits
coltyp = JET_coltyp.Binary,
grbit = ColumndefGrbit.ColumnFixed | ColumndefGrbit.ColumnNotNULL
}, defaultValue, defaultValue.Length, out columnid);
}
SchemaCreator.UpdateVersion(session, dbid, "4.6");
}
示例7: CreateAndEndSession
public void CreateAndEndSession()
{
using (var session = new Session(this.instance))
{
session.End();
}
}
示例8: CreateDatabase
/// <summary>
/// Create a new database and return a connection to
/// the database. The database will be overwritten if
/// it already exists.
/// </summary>
/// <param name="database">The path to the database.</param>
/// <param name="mode">Creation mode for the database.</param>
/// <returns>A new connection to the database.</returns>
public virtual Connection CreateDatabase(string database, DatabaseCreationMode mode)
{
database = Path.GetFullPath(database);
lock (this.lockObject)
{
this.SetGlobalParameters();
this.Tracer.TraceInfo("create database '{0}'", database);
// Create the database then open it
using (var instance = new Instance(this.GetNewInstanceName()))
{
SetParametersAndInitializeInstance(database, instance);
using (var session = new Session(instance))
{
CreateDatabaseGrbit grbit = (DatabaseCreationMode.OverwriteExisting == mode) ?
CreateDatabaseGrbit.OverwriteExisting : CreateDatabaseGrbit.None;
JET_DBID dbid;
Api.JetCreateDatabase(session, database, String.Empty, out dbid, grbit);
Api.JetCloseDatabase(session, dbid, CloseDatabaseGrbit.None);
Api.JetDetachDatabase(session, database);
}
}
return this.AttachDatabase(database, DatabaseOpenMode.ReadWrite);
}
}
示例9: DumpTable
public static void DumpTable(Session session, Table table, Stream stream)
{
using (var writer = new StreamWriter(stream))
{
var cols = Api.GetTableColumns(session, table).ToArray();
foreach (var col in cols)
{
writer.Write(col);
writer.Write(",");
}
writer.WriteLine("#");
Api.MoveBeforeFirst(session, table);
int count = 0;
while (Api.TryMoveNext(session, table))
{
foreach (var col in cols)
{
var val = GetvalueFromTable(session, table, col) ?? "NULL";
writer.Write(val);
writer.Write(",");
}
writer.WriteLine(++count);
}
writer.Flush();
}
}
示例10: EsentSession
public EsentSession(IEsentDatabase database, Session session, IWriteLockable writeLockable)
{
Database = database;
_session = session;
_writeLockable = writeLockable;
JetDbid = JET_DBID.Nil;
}
示例11: InitColumDictionaries
public void InitColumDictionaries(JET_INSTANCE instance, string database)
{
using (var session = new Session(instance))
{
var dbid = JET_DBID.Nil;
try
{
Api.JetOpenDatabase(session, database, null, out dbid, OpenDatabaseGrbit.None);
using (var usage = new Table(session, dbid, "usage", OpenTableGrbit.None))
UsageColumns = Api.GetColumnDictionary(session, usage);
using (var details = new Table(session, dbid, "details", OpenTableGrbit.None))
DetailsColumns = Api.GetColumnDictionary(session, details);
using (var pages = new Table(session, dbid, "pages", OpenTableGrbit.None))
PagesColumns = Api.GetColumnDictionary(session, pages);
using (var files = new Table(session, dbid, "files", OpenTableGrbit.None))
FilesColumns = Api.GetColumnDictionary(session, files);
using (var signatures = new Table(session, dbid, "signatures", OpenTableGrbit.None))
SignaturesColumns = Api.GetColumnDictionary(session, signatures);
using (var config = new Table(session, dbid, "config", OpenTableGrbit.None))
ConfigColumns = Api.GetColumnDictionary(session, config);
}
finally
{
if (Equals(dbid, JET_DBID.Nil) == false)
Api.JetCloseDatabase(session, dbid, CloseDatabaseGrbit.None);
}
}
}
示例12: Update
public void Update(Session session, JET_DBID dbid)
{
using (var tx = new Transaction(session))
{
using (var files = new Table(session, dbid, "files", OpenTableGrbit.None))
{
const string indexDef = "+etag\0\0";
Api.JetCreateIndex(session, files, "by_etag", CreateIndexGrbit.IndexDisallowNull, indexDef, indexDef.Length,
100);
using (var details = new Table(session, dbid, "details", OpenTableGrbit.None))
{
Api.JetMove(session, details, JET_Move.First, MoveGrbit.None);
var columnids = Api.GetColumnDictionary(session, details);
using (var update = new Update(session, details, JET_prep.Replace))
{
Api.SetColumn(session, details, columnids["schema_version"], "2.7", Encoding.Unicode);
update.Save();
}
}
}
tx.Commit(CommitTransactionGrbit.None);
}
}
示例13: Update
public void Update(Session session, JET_DBID dbid, Action<string> output)
{
using (var tbl = new Table(session, dbid, "tasks", OpenTableGrbit.None))
{
int rows = 0;
if (Api.TryMoveFirst(session, tbl))
{
var taskTypeColumnId = Api.GetTableColumnid(session, tbl, "task_type");
do
{
using (var update = new Update(session, tbl, JET_prep.Replace))
{
var taskType = Api.RetrieveColumnAsString(session, tbl, taskTypeColumnId, Encoding.Unicode);
Api.SetColumn(session, tbl, taskTypeColumnId, taskType, Encoding.ASCII);
update.Save();
}
if (rows++ % 10000 == 0)
{
output("Processed " + (rows) + " rows in tasks");
Api.JetCommitTransaction(session, CommitTransactionGrbit.LazyFlush);
Api.JetBeginTransaction2(session, BeginTransactionGrbit.None);
}
} while (Api.TryMoveNext(session, tbl));
}
SchemaCreator.UpdateVersion(session, dbid, "5.3");
}
}
示例14: Update
public void Update(Session session, JET_DBID dbid, Action<string> output)
{
using (var tbl = new Table(session, dbid, "lists", OpenTableGrbit.None))
{
JET_COLUMNID columnid;
Api.JetAddColumn(session, tbl, "created_at", new JET_COLUMNDEF
{
coltyp = JET_coltyp.DateTime,
grbit = ColumndefGrbit.ColumnMaybeNull,
}, null, 0, out columnid);
if (Api.TryMoveFirst(session, tbl))
{
do
{
using (var update = new Update(session, tbl, JET_prep.Replace))
{
var createdAt = Api.GetTableColumnid(session, tbl, "created_at");
Api.SetColumn(session, tbl, createdAt, SystemTime.UtcNow);
update.Save();
}
} while (Api.TryMoveNext(session, tbl));
}
SchemaCreator.CreateIndexes(session, tbl, new JET_INDEXCREATE
{
szIndexName = "by_name_and_created_at",
szKey = "+name\0+created_at\0\0",
grbit = CreateIndexGrbit.IndexDisallowNull
});
SchemaCreator.UpdateVersion(session, dbid, "5.1");
}
}
示例15: OpenDatabase
public static void OpenDatabase(string jetDatabase, Instance jetInstance, bool readOnly)
{
using (var jetSession = new Session(jetInstance))
{
var attachGrbit = AttachDatabaseGrbit.None;
if (readOnly)
attachGrbit |= AttachDatabaseGrbit.ReadOnly;
if (EsentVersion.SupportsWindows7Features)
attachGrbit |= Windows7Grbits.EnableAttachDbBackgroundMaintenance;
Api.JetAttachDatabase(jetSession, jetDatabase, attachGrbit);
var success = false;
try
{
using (var cursor = new EsentChainStateCursor(jetDatabase, jetInstance))
{
// reset flush column
using (var jetUpdate = cursor.jetSession.BeginUpdate(cursor.flushTableId, JET_prep.Replace))
{
Api.SetColumn(cursor.jetSession, cursor.flushTableId, cursor.flushColumnId, 0);
jetUpdate.Save();
}
}
success = true;
}
finally
{
if (!success)
Api.JetDetachDatabase(jetSession, jetDatabase);
}
}
}