当前位置: 首页>>代码示例>>C#>>正文


C# IDocumentSession.Dispose方法代码示例

本文整理汇总了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();
        }
开发者ID:synhershko,项目名称:Orev,代码行数:9,代码来源:RavenCorpusReader.cs

示例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;
            };
        }
开发者ID:justinfinch,项目名称:Automate,代码行数:52,代码来源:DeviceModule.cs

示例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"));
        }
开发者ID:simoraman,项目名称:SimpleBoard,代码行数:19,代码来源:TaskRepositoryTests.cs

示例4: SaveAndCloseSession

 internal static void SaveAndCloseSession(IDocumentSession session)
 {
     session.SaveChanges();
     session.Dispose();
 }
开发者ID:lukemerrett,项目名称:RavenDBSample,代码行数:5,代码来源:RavenSession.cs

示例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();
			}
		}
开发者ID:myarichuk,项目名称:SubscriptionsDemo.Chat,代码行数:45,代码来源:ChatClient.cs

示例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;
        }
开发者ID:henrikrtfm,项目名称:Seerefine,代码行数:48,代码来源:EventsDispatcher.cs


注:本文中的IDocumentSession.Dispose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。