Exemple #1
0
		public static void RemoveChatRequest(ChatRequest req)
		{
			// Load the provider
			LoadProvider();

			_provider.RemoveChatRequest(req);
		}
Exemple #2
0
		public static bool ProcessInvite(ChatRequest req, bool accept)
		{
			LoadProvider();

			return accept ?
				_provider.AcceptInvite(req) :
				_provider.RejectInvite(req);
		}
Exemple #3
0
		public override Guid RequestChat(ChatRequest request)
		{
			using (LCSKDbDataContext db = new LCSKDbDataContext(connectionString))
			{
                if (request.Department == null)
                    request.Department = "";

				var existing = db.LiveChat_ChatRequests.SingleOrDefault(x =>
					x.VisitorIP == request.VisitorIp &&
					x.OperatorID == -1);
				if (existing != null)
					return existing.ChatID;

				// Get the less busy operator
				int operatorId = -1;

				var results = from o in db.LiveChat_Operators
							  join c in db.LiveChat_ChatRequests on o.OperatorID equals c.OperatorID into req
							  from r in req.DefaultIfEmpty()
							  where o.IsOnline && o.Department.Contains(request.Department)
							  group o by o.OperatorID into g
							  select new { Id = g.Key, Count = g.Count() };

				if (results != null && results.Count() > 0)
					operatorId = results.OrderBy(x => x.Count).First().Id;
				else
				{
					// WTH
					operatorId = db.LiveChat_Operators.First(x => x.IsOnline).OperatorID;
				}

				LiveChat_ChatRequest entity = new LiveChat_ChatRequest();
				entity.ChatID = request.ChatId;
				entity.Department = request.Department;
				entity.OperatorID = operatorId;
				entity.RequestDate = DateTime.Now;
				entity.VisitorEmail = request.VisitorEmail;
				entity.VisitorIP = request.VisitorIp;
				entity.VisitorName = request.VisitorName;
				entity.VisitorUserAgent = request.VisitorUserAgent.Length > 100 ? request.VisitorUserAgent.Substring(0, 100) : request.VisitorUserAgent;

				db.LiveChat_ChatRequests.InsertOnSubmit(entity);
				db.SubmitChanges();
				return entity.ChatID;
			}
		}
Exemple #4
0
		public override void RemoveChatRequest(ChatRequest req)
		{
			using (LCSKDbDataContext db = new LCSKDbDataContext(connectionString))
			{
				db.LiveChat_ChatRequests.DeleteAllOnSubmit(db.LiveChat_ChatRequests.Where(x =>
					x.ChatID == req.ChatId));
				db.SubmitChanges();
			}
		}
Exemple #5
0
		public void RemoveChatRequest(Guid key, ChatRequest req)
		{
			if (!IsAuthenticated(key))
				throw new Exception("The key is not authenticated");
			ChatService.RemoveChatRequest(req);
		}
Exemple #6
0
		public void TransferChat(ChatRequest chatRequest)
		{
			ChatService.RequestChat(chatRequest);
		}
Exemple #7
0
		public abstract void RemoveChatRequest(ChatRequest req);
Exemple #8
0
		public abstract Guid RequestChat(ChatRequest request);
		public override ChatRequest InviteVisitor(int operatorId, string visitorIp, string prompt)
		{
			using (LCSKDbDataContext db = new LCSKDbDataContext(connectionString))
			{
				LiveChat_ChatRequest invite = new LiveChat_ChatRequest();
				invite.AcceptDate = null;
				invite.ChatID = Guid.NewGuid();
				invite.ClosedDate = null;
				//HACK: this will serve as an indicator when visitor display chat button
				invite.Department = "op-invite";
				invite.OperatorID = operatorId;
				invite.RequestDate = DateTime.Now;
				invite.VisitorEmail = "";
				invite.VisitorIP = visitorIp;
				invite.VisitorName = "Me";
				invite.VisitorUserAgent = "";

				db.LiveChat_ChatRequests.InsertOnSubmit(invite);
				try
				{
					db.SubmitChanges();

					ChatRequest req = new ChatRequest();
					req.Accepted = null;
					req.ChatId = invite.ChatID;
					req.Closed = null;
					req.Department = invite.Department;
					req.OperatorId = invite.OperatorID;
					req.Requested = invite.RequestDate;
					req.VisitorEmail = invite.VisitorEmail;
					req.VisitorIp = invite.VisitorIP;
					req.VisitorName = invite.VisitorName;
					req.VisitorUserAgent = invite.VisitorUserAgent;
					req.WasAccepted = false;

					return req;
				}
				catch
				{
					throw;
				}
			}
		}
Exemple #10
0
		public abstract bool RejectInvite(ChatRequest req);
Exemple #11
0
		public abstract bool AcceptInvite(ChatRequest req);
		public VisitorInitViewModel()
		{
			NewChatRequest = new ChatRequest();
		}
 public VisitorInitViewModel()
 {
     NewChatRequest = new ChatRequest();
 }
		public override bool RejectInvite(ChatRequest req)
		{
			using (LCSKDbDataContext db = new LCSKDbDataContext(connectionString))
			{
				var entity = db.LiveChat_ChatRequests.SingleOrDefault(x => x.ChatID == req.ChatId);
				if (entity != null)
				{
					entity.ClosedDate = DateTime.Now;
					entity.Department = "visitor-rejected";

					db.SubmitChanges();
					return true;
				}
				return false;
			}
		}
		public override ChatRequest CheckForInvites(string visitorIp)
		{
			using (LCSKDbDataContext db = new LCSKDbDataContext(connectionString))
			{
				var invites = db.LiveChat_ChatRequests.OrderByDescending(x => x.RequestDate).Where(x =>
					x.VisitorIP == visitorIp && x.Department == "op-invite" && x.AcceptDate == null && x.ClosedDate == null).ToList();

				if(invites != null && invites.Count() > 0)
				{
					// do they have more than 1 invite
					var invite = invites.First();
					if (invites.Count() > 1)
					{
						invites.Remove(invite);

						foreach (var inv in invites)
						{
							inv.ClosedDate = DateTime.Now;
							inv.Department = "Visitor had more than 1 invite pending...";
						}

						db.SubmitChanges();
					}

					ChatRequest req = new ChatRequest();
					req.Accepted = null;
					req.ChatId = invite.ChatID;
					req.Closed = null;
					req.Department = invite.Department;
					req.OperatorId = invite.OperatorID;
					req.Requested = invite.RequestDate;
					req.VisitorEmail = invite.VisitorEmail;
					req.VisitorIp = invite.VisitorIP;
					req.VisitorName = invite.VisitorName;
					req.VisitorUserAgent = invite.VisitorUserAgent;
					req.WasAccepted = false;

					return req;
				}
				return null;
			}
		}