本文整理汇总了C#中Context.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# Context.Dispose方法的具体用法?C# Context.Dispose怎么用?C# Context.Dispose使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Context
的用法示例。
在下文中一共展示了Context.Dispose方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
// Create an IOG context in memory which has the data model of IDataModel type
Context ctx = new Context(typeof(IDataModel));
// Open workspace for writing
using (var workspace = ctx.OpenWorkspace<IDataModel>(IsolationLevel.Exclusive))
{
// Access the data model via the current workspace
IDataModel data = workspace.Data;
// Set the value in data model
data.StringValue = "Hello world!";
// Commit the change
workspace.Commit();
}
// Open workspace for reading
using (var workspace = ctx.OpenWorkspace<IDataModel>(IsolationLevel.ReadOnly))
{
// Access the data model via the current workspace
IDataModel data = workspace.Data;
// Display the message
Console.Write(data.StringValue);
}
// Dispose the context
ctx.Dispose();
}
示例2: UT_Context_Dispose_Async
public async Task UT_Context_Dispose_Async(Context context)
{
var ctx = new Context(context.GetConnectionMultiplexer().Configuration, context.GetSerializer());
await ctx.Cache.SetObjectAsync("key", "value");
ctx.Dispose();
await context.Cache.RemoveAsync("key");
Assert.ThrowsAsync<ObjectDisposedException>(async () => await ctx.Cache.SetObjectAsync("key", "value2"));
}
示例3: TestSnapshotExclusiveCanOpen2
public void TestSnapshotExclusiveCanOpen2()
{
Context ctx = new Context(typeof(IDatabase));
var workspaceSnap = ctx.OpenWorkspace<IDatabase>(IsolationLevel.Snapshot);
var workspaceEx = ctx.OpenWorkspace<IDatabase>(IsolationLevel.Exclusive);
ctx.Dispose();
}
示例4: CreateDatFile
private void CreateDatFile()
{
FileStream file = new FileStream("data.dat", FileMode.Create);
IndexedFileStorage storage = new IndexedFileStorage(file, 256, true);
Context ctx = new Context(typeof(IDataModel), null, storage);
using (var ws = ctx.OpenWorkspace<IDataModel>(IsolationLevel.Exclusive))
{
IDataModel database = ws.Data;
ws.Commit();
}
ctx.Dispose();
storage.Dispose();
file.Close();
}
示例5: TestEnumInRoot
public void TestEnumInRoot()
{
FileStream file = new FileStream("data.dat", FileMode.Create);
IndexedFileStorage storage = new IndexedFileStorage(file, 256, true);
Context ctx = new Context(typeof(IDataEnumModel), null, storage);
using (var ws = ctx.OpenWorkspace<IDataEnumModel>(IsolationLevel.Exclusive))
{
IDataEnumModel database = ws.Data;
ws.Data.firstEnum = EnumsEnglish.FirstValue;
ws.Data.secondEnum = EnumsSrpski.DrugaVrednost;
ws.Data.intNumber = 100;
ws.Commit();
}
ctx.Dispose();
storage.Dispose();
file.Close();
file = new FileStream("data.dat", FileMode.Open);
storage = new IndexedFileStorage(file, 256, true);
TypesVisualisationService service = new TypesVisualisationService(storage);
string content = service.GetGraphVizContentFromStorage(storage);
System.IO.File.WriteAllText("TestEnumInRoot.gv", content);
storage.Dispose();
file.Close();
}
示例6: UT_Context_Dispose
public void UT_Context_Dispose(Context context)
{
var ctx = new Context(context.GetConnectionMultiplexer().Configuration, context.GetSerializer());
ctx.Cache.SetObject("key", "value");
ctx.Dispose();
context.Cache.Remove("key");
Assert.Throws<ObjectDisposedException>(() => ctx.Cache.SetObject("key", "value2"));
}
示例7: TestParentNodesIndexStorage
public void TestParentNodesIndexStorage()
{
var file = new FileStream("data.dat", FileMode.Create);
var storage = new IndexedFileStorage(file, 256, true);
Context ctx = new Context(typeof(IDatabase), null, storage);
using (var ws = ctx.OpenWorkspace<IDatabase>(IsolationLevel.Exclusive))
{
IDatabase database = ws.Data;
var person = ws.New<IPerson>();
person.Name = "John Connor";
var car = ws.New<ICar>();
car.Model = "Renault";
person.Car = car;
car = ws.New<ICar>();
car.Model = "Renault with parent";
person.CarWithParent = car;
database.Person = person;
Assert.AreEqual("John Connor", database.Person.Name);
Assert.AreEqual("Renault", database.Person.Car.Model);
Assert.AreEqual("Renault with parent", database.Person.CarWithParent.Model);
Assert.AreEqual(0, ws.ParentNodes(database.Person.Car).Count);
Assert.AreEqual(0, ws.ParentNodes(database.Person.CarWithParent).Count);
ws.Commit();
}
using (var ws = ctx.OpenWorkspace<IDatabase>(IsolationLevel.Exclusive))
{
IDatabase database = ws.Data;
Assert.AreEqual("John Connor", database.Person.Name);
Assert.AreEqual("Renault", database.Person.Car.Model);
Assert.AreEqual("Renault with parent", database.Person.CarWithParent.Model);
Assert.AreEqual(0, ws.ParentNodes(database.Person.Car).Count);
Assert.AreEqual(1, ws.ParentNodes(database.Person.CarWithParent).Count);
Assert.AreEqual("John Connor", (ws.ParentNodes(database.Person.CarWithParent).ElementAt(0) as IPerson).Name);
}
ctx.Dispose();
storage.Dispose();
file.Close();
file = new FileStream("data.dat", FileMode.Open);
storage = new IndexedFileStorage(file, 256, true);
ctx = new Context(typeof(IDatabase), null, storage);
using (var ws = ctx.OpenWorkspace<IDatabase>(IsolationLevel.Exclusive))
{
IDatabase database = ws.Data;
Assert.AreEqual("John Connor", database.Person.Name);
Assert.AreEqual("Renault", database.Person.Car.Model);
Assert.AreEqual("Renault with parent", database.Person.CarWithParent.Model);
Assert.AreEqual(0, ws.ParentNodes(database.Person.Car).Count);
Assert.AreEqual(1, ws.ParentNodes(database.Person.CarWithParent).Count);
Assert.AreEqual("John Connor", (ws.ParentNodes(database.Person.CarWithParent).ElementAt(0) as IPerson).Name);
}
}
示例8: simple_example
/* @name Examples
*/
/*!
\brief "Hello world" example: create a Z3 logical context, and delete it.
*/
public void simple_example()
{
Console.WriteLine("simple_example");
Dictionary<string, string> cfg = new Dictionary<string, string>();
Context z3 = new Context(cfg);
/* do something with the context */
/* be kind to dispose manually and not wait for the GC. */
z3.Dispose();
}
示例9: TestSnapshotExclusiveThreads
public void TestSnapshotExclusiveThreads()
{
Context ctx = new Context(typeof(IDatabase));
using (var ws = ctx.OpenWorkspace<IDatabase>(IsolationLevel.Exclusive))
{
ws.Data.Data = "Initial";
ws.Commit();
}
var workspaceEx = ctx.OpenWorkspace<IDatabase>(IsolationLevel.Exclusive);
Thread t = new Thread(() =>
{
using (var ws = ctx.OpenWorkspace<IDatabase>(IsolationLevel.Snapshot))
{
ws.Data.Data = "Snapshot";
ws.Commit();
}
});
t.Start();
Thread.Sleep(500);
using (var ws = ctx.OpenWorkspace<IDatabase>(IsolationLevel.ReadOnly))
{
Assert.AreEqual("Initial", ws.Data.Data);
}
workspaceEx.Data.Data = "Exclusive";
workspaceEx.Commit();
using (var ws = ctx.OpenWorkspace<IDatabase>(IsolationLevel.ReadOnly))
{
Assert.AreEqual("Exclusive", ws.Data.Data);
}
workspaceEx.Dispose();
Thread.Sleep(500);
using (var ws = ctx.OpenWorkspace<IDatabase>(IsolationLevel.ReadOnly))
{
Assert.AreEqual("Snapshot", ws.Data.Data);
}
ctx.Dispose();
}
示例10: Main
static void Main(string[] args)
{
Console.WriteLine("Items,Inserts per second,Reads per second,Updates per second, Memory(MB)");
var fs = new FileStream("data.dat", FileMode.Create);
Context ctx = new Context(typeof(IDataModel), null, new IndexedFileStorage(fs, 512, true));
//Context<IDataModel> ctx = new Context<IDataModel>(new Type[] { typeof(IDataModel) });
using (var ws = ctx.OpenWorkspace<IDataModel>(IsolationLevel.Exclusive))
{
if (ws.Data.PersonCollection == null)
{
ws.Data.PersonCollection = ws.New<IIndexedCollection<IPerson>>();
ws.Commit();
}
}
Stopwatch sw = new Stopwatch();
sw.Start();
double sumInsertMs = 0;
double sumReadMs = 0;
double sumUpdateMs = 0;
for (int iter = 0; iter < maxElements / batchSize; iter++)
{
sumInsertMs += TestInsert(sw, ctx);
sumReadMs += TestRead(sw, ctx);
sumUpdateMs += TestUpdate(sw, ctx);
long memoryStatus = GC.GetTotalMemory(false) - startMemory;
if ((iter) % reportingFrequency == 0)
{
Console.WriteLine((Program.ID).ToString()
+ "," + (1000 / (sumInsertMs / reportingFrequency))
+ "," + (1000 / (sumReadMs / reportingFrequency))
+ "," + (1000 / (sumUpdateMs / reportingFrequency))
+ "," + memoryStatus / 1024 / 1024
);
sumInsertMs = 0;
sumReadMs = 0;
sumUpdateMs = 0;
ctx.Cleanup();
}
}
ctx.Dispose();
}