Exemple #1
0
		/// <summary>
		/// Don't call this directly - it should only be called from Room.UnRegister
		/// </summary>
		/// <param name="room"></param>
		public void RemoveRoom(ChatRoom room)
		{
			if (rooms.ContainsKey(room.RoomGuid))
			{
				lock (rooms)
				{
					rooms.Remove(room.RoomGuid);
				}
			}
		}
Exemple #2
0
		/// <summary>
		/// Gets the latest items in the cache, up to [latestItemGuid].
		/// If we specify [roomToReturnInFullAndExclude], we first append all items from that room, and exclude items from that room in the cache items
		/// </summary>
		public string GetItems(Guid latestItemGuid, ref Guid newestItemGuid, ChatRoom roomToReturnInFullAndExclude)
		{
			Status("User.GetItems", false);

			bool excludeRoom = roomToReturnInFullAndExclude != null;

			lastRequest = DateTime.Now;

			string output = string.Empty;
			lock (responseBuilder)
			{
				//clear the response builder
				responseBuilder.Length = 0;

				if (roomToReturnInFullAndExclude != null)
				{
					Guid g = Guid.Empty;
					roomToReturnInFullAndExclude.AppendItems(true, Guid.Empty, ref g, ChatServer.GlobalMaxItems, responseBuilder);
				}

				lock (itemCache)
				{
					if (itemCache.Count > 0)
					{
						//set the latest message id to pass back by ref
						newestItemGuid = itemCache[itemCache.Count - 1].UniqueItemGuid;

						int i = 0;

						if (latestItemGuid != Guid.Empty)
						{
							i = itemCache.Count - 1;

							//find the value of i to start building from
							while (i >= 0 && itemCache[i].UniqueItemGuid != latestItemGuid)
							{
								i--;
							}

							//increment i because we already have the message at position i
							i++;
						}

						//build the response from the remaining items
						for (; i < itemCache.Count; i++)
						{
							if (itemCache[i].Disabled)
								continue;

							if (excludeRoom && itemCache[i].RoomGuid == roomToReturnInFullAndExclude.RoomGuid)
								continue;

							if (responseBuilder.Length > 0)
								responseBuilder.Append(",");

							responseBuilder.Append(itemCache[i].Item);
						}

						output = responseBuilder.ToString();

						//clear the response builder
						responseBuilder.Length = 0;

					}
				}
			}

			return output;
		}
Exemple #3
0
		/// <summary>
		/// Don't call this directly - it should only be called from Room.Register
		/// </summary>
		/// <param name="room"></param>
		public void AddRoom(ChatRoom room)
		{
			lock (rooms)
			{
				if (rooms.ContainsKey(room.RoomGuid))
					return;

				rooms.Add(room.RoomGuid, room);
			}
		}