本文整理汇总了C#中IDocumentSession.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# IDocumentSession.Dispose方法的具体用法?C# IDocumentSession.Dispose怎么用?C# IDocumentSession.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDocumentSession
的用法示例。
在下文中一共展示了IDocumentSession.Dispose方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Read
public void Read()
{
_reader.OnDocument += _reader_OnDocument;
_session = MvcApplication.DocumentStore.OpenSession();
_reader.Read();
_session.SaveChanges();
_session.Dispose();
}
示例2: DeviceModule
public DeviceModule(ILogger logger, IDeviceRepository deviceRepository, IDocumentSession documentSession)
: base("/devices")
{
Get["/"] = p =>
{
var registeredDevices = deviceRepository.GetAll();
var registeredDeviceDtos = Mapper.Map<IEnumerable<RegisteredDeviceDto>>(registeredDevices);
return Response.AsJson(registeredDeviceDtos);
};
Post["/"] = p =>
{
var newDeviceRequest = this.Bind<DeviceSetupRequest>();
var registeredDevice = new RegisteredDevice(newDeviceRequest.DeviceName, newDeviceRequest.DeviceType, newDeviceRequest.IpAddress);
deviceRepository.Add(registeredDevice);
documentSession.SaveChanges();
documentSession.Dispose();
return HttpStatusCode.OK;
};
Post["/{name}/{commandRoute}"] = p =>
{
Response response = HttpStatusCode.NotFound;
//Lookup IP address and device type from device
//TODO: Implement singleton DeviceMap object to cache and return this data
var device = deviceRepository.FindByName(p.name);
if (device != null)
{
var commandRoute = String.Format("/{0}/{1}", device.Type, p.commandRoute);
response = new Response();
response.Headers.Add("cmd-route", commandRoute);
response.Headers.Add("cmd-ip", device.IpAddress);
response.StatusCode = HttpStatusCode.OK;
logger.Info(String.Format("Recievied the {0} command for the {1}. Routing it to {2}", p.commandRoute, p.device, commandRoute));
}
return response;
};
Delete["/{name}"] = p =>
{
Response response = HttpStatusCode.NotFound;
return response;
};
}
示例3: CanUpdateTasks
public void CanUpdateTasks()
{
Task task = new Task { Description = "kuvaus", Status = "ToDo" };
taskRepository.Save(task);
session.Dispose();
session = documentStore.OpenSession();
taskRepository=new TaskRepository(session);
var updateTask = taskRepository.Find().First();
updateTask.Status = "Done";
taskRepository.Update(updateTask);
session.Dispose();
session = documentStore.OpenSession();
taskRepository = new TaskRepository(session);
var result = taskRepository.Find().First();
Assert.That(result.Status,Is.EqualTo("Done"));
}
示例4: SaveAndCloseSession
internal static void SaveAndCloseSession(IDocumentSession session)
{
session.SaveChanges();
session.Dispose();
}
示例5: Leave
public void Leave(string roomName, IDocumentSession session = null)
{
//using (var session = store.OpenSession())
var isExternalSession = session == null;
if (session == null)
session = store.OpenSession();
try
{
if (!joinedRooms.Any(r => r.Name.Equals(roomName, StringComparison.InvariantCultureIgnoreCase)))
{
Console.WriteLine("Cannot leave because not joined..");
return;
}
var roomToLeave = session.Load<Room>($"rooms/{roomName}");
if (roomToLeave != null)
{
roomToLeave.Users.Remove($"users/{username}");
if (roomToLeave.Users.Count == 0) //room is empty - no need to keep it
{
var idsToDelete = new List<string>();
using (var stream = session.Advanced.Stream(
session.Query<Message, MessagesByRoomIndex>()))
{
do
{
if(stream.Current != null)
session.Delete(stream.Current.Key);
} while (stream.MoveNext());
}
session.Delete(roomToLeave);
}
}
joinedRooms.RemoveAt(joinedRooms.FindIndex(r => r.Id == roomToLeave.Id));
session.SaveChanges();
Console.WriteLine($"Left room {roomName}");
}
finally
{
if (isExternalSession)
session.Dispose();
}
}
示例6: ConsumeEvents
private IEnumerable<EventBase> ConsumeEvents(IEnumerable<EventBase> events, IDocumentSession session)
{
var concurrencyExceptions = new List<EventBase>();
foreach (var @event in events)
{
var interfaceType = typeof (IConsumerOf<>).MakeGenericType(@event.GetType());
if (_eventConsumers.ContainsKey(interfaceType) == false)
continue;
var consumers = _eventConsumers[interfaceType];
foreach (var consumer in consumers)
{
var instance = Activator.CreateInstance(consumer);
instance.GetType().GetProperty("Session").SetValue(instance, session);
if (instance is INeedClientSettings)
{
((INeedClientSettings) instance).ClientSettings = _clientSettings;
}
try
{
instance.GetType().GetMethod("Consume", new[] { @event.GetType() }).Invoke(instance, new[] { @event });
}
catch (Exception exception)
{
throw new MessageConsumeException(exception, interfaceType, instance.GetType().Name);
}
}
try
{
if(session.Advanced.HasChanges)
session.SaveChanges();
}
catch (ConcurrencyException)
{
concurrencyExceptions.Add(@event);
}
finally
{
session.Dispose();
}
}
return concurrencyExceptions;
}