static string serializeStateStub(StateStub state) { string XmlizedString = null; MemoryStream memoryStream = new MemoryStream(); XmlSerializer xs = new XmlSerializer(typeof(StateStub)); XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8); xs.Serialize(xmlTextWriter, state); memoryStream = (MemoryStream)xmlTextWriter.BaseStream; UTF8Encoding encoding = new UTF8Encoding(); XmlizedString = encoding.GetString(memoryStream.ToArray()); return XmlizedString; }
public ServerClass(Controller controller, int sessionID, string lastActionTicks, StateStub[] controllerRoomState) { SessionID = sessionID; LastActionTicks = lastActionTicks; LastItemGuid = ""; RequestIndex = 0; Controller = controller; criticalRequestQueue = new Queue(); criticalRequestInProgress = false; periodicBackgroundRefreshInProgress = false; cancelCurrentPeriodicBackgroundRefresh = false; periodicBackgroundRefreshIsPaused = false; roomState = controllerRoomState; }
public RefreshStub Star(string clientID, string roomGuid, bool starred, string lastItemGuidString, int sessionID, string lastActionTicks, string pageUrl, StateStub[] roomState) { WaitIfDevEnv(); Guid guid = roomGuid.UnPackGuid(); Chat.RoomSpec spec = Chat.RoomSpec.FromGuid(guid); if (Usr.Current == null || Usr.Current.IsSkeleton || Usr.Current.Banned) throw new LoginPermissionException(); if (spec == null) throw new InvalidRoomException(); if (!spec.IsStarrable) throw new Exception("This room is not starrable"); StateStub state = null; foreach (StateStub ss in roomState) { if (ss.guid == roomGuid) { state = ss; break; } } #region Store the star room in the database, or delete the pin record. try { RoomPin rp = new RoomPin(Usr.Current.K, guid); rp.Starred = starred; rp.Update(); } catch (BobNotFound) { if (!spec.IsDefaultRoom || spec.IsStarredByDefault != starred) { RoomPin rp = new RoomPin(); rp.UsrK = Usr.Current.K; rp.RoomGuid = guid; rp.ListOrder = state != null ? state.listOrder : 0; rp.Pinned = true; rp.Starred = starred; rp.DateTime = DateTime.Now; rp.Update(); } } #endregion storeRoomState(roomState, Usr.Current.K); lastActionTicks = resetLastActionAndSessionID(sessionID); Guid lastItemGuidReturned = Guid.Empty; Guid lastItemGuid = lastItemGuidString.Length == 0 ? Guid.Empty : lastItemGuidString.UnPackGuid(); ChatLibrary.ChatServerInterface cs = (ChatLibrary.ChatServerInterface)Activator.GetObject(typeof(ChatLibrary.ChatServerInterface), Bobs.Vars.ChatServerAddress); string chatItems = cs.GetLatest(Usr.Current.K, sessionID, false, lastItemGuid, ref lastItemGuidReturned); RefreshStub rs = new RefreshStub(); rs.itemsJson = chatItems; rs.lastActionTicks = lastActionTicks; rs.lastItemGuidReturned = lastItemGuidReturned.Pack(); return rs; }
public UnPinStub UnPin(string clientID, string roomGuid, string lastItemGuidString, int sessionID, string lastActionTicks, string pageUrl, StateStub[] roomState) { WaitIfDevEnv(); Guid guid = roomGuid.UnPackGuid(); Chat.RoomSpec spec = Chat.RoomSpec.FromGuid(guid); if (Usr.Current == null || Usr.Current.IsSkeleton || Usr.Current.Banned) throw new LoginPermissionException(); if (spec == null) throw new InvalidRoomException(); StateStub state = null; foreach (StateStub ss in roomState) { if (ss.guid == roomGuid) { state = ss; break; } } #region Exit room on chat server only if we need to //For thread chat and PersistantAlertsRooms, we don't want to exit the room on the chat server. if (spec.RoomType == RoomType.Normal && (spec.ObjectType == Model.Entities.ObjectType.Thread || (spec.ObjectBob != null && spec.ObjectBob is IHasPrimaryThread && ((IHasPrimaryThread)spec.ObjectBob).ThreadK.IsNotNullOrZero()))) { //don't exit the room if we're watching the topic bool exitRoom = true; int threadK = spec.ObjectType == Model.Entities.ObjectType.Thread ? spec.ObjectK : ((IHasPrimaryThread)spec.ObjectBob).ThreadK.Value; try { Thread t = new Thread(threadK); ThreadUsr tu = t.GetThreadUsr(Usr.Current); if (tu != null && tu.IsWatching) exitRoom = false; } catch { } if (exitRoom) Chat.ExitRoom(guid, Usr.Current.K); } else if (!spec.IsPersistantAlertsRoom) { Chat.ExitRoom(guid, Usr.Current.K); } #endregion #region Store the un-pinned room in the database, or delete the pin record. try { RoomPin rp = new RoomPin(Usr.Current.K, guid); if (spec.IsDefaultRoom) { rp.Pinned = false; rp.Update(); } else { rp.Delete(); } } catch (BobNotFound) { if (spec.IsDefaultRoom) { RoomPin rp = new RoomPin(); rp.UsrK = Usr.Current.K; rp.RoomGuid = guid; rp.ListOrder = state != null ? state.listOrder : 0; rp.Pinned = false; rp.Starred = spec.IsStarredByDefault; rp.DateTime = DateTime.Now; rp.Update(); } } #endregion storeRoomState(roomState, Usr.Current.K); lastActionTicks = resetLastActionAndSessionID(sessionID); Guid lastItemGuidReturned = Guid.Empty; Guid lastItemGuid = lastItemGuidString.Length == 0 ? Guid.Empty : lastItemGuidString.UnPackGuid(); ChatLibrary.ChatServerInterface cs = (ChatLibrary.ChatServerInterface)Activator.GetObject(typeof(ChatLibrary.ChatServerInterface), Bobs.Vars.ChatServerAddress); string chatItems = cs.GetLatest(Usr.Current.K, sessionID, false, lastItemGuid, ref lastItemGuidReturned); UnPinStub ups = new UnPinStub(); ups.roomGuid = roomGuid; ups.itemsJson = chatItems; ups.lastActionTicks = lastActionTicks; ups.lastItemGuidReturned = lastItemGuidReturned.Pack(); return ups; }
public void InitialiseFromStub(RoomStub roomStub, DOMElement roomList, StateStub[] controllerStateStore) { stub = roomStub; Guid = stub.guid; Name = stub.name; Url = stub.url; Pinable = stub.pinable; pinned = stub.pinned; starred = stub.starred; Starrable = stub.starrable; isStarredByDefault = stub.isStarredByDefault; ReadOnly = stub.readOnly; IsPhotoChatRoom = stub.isPhotoChatRoom; IsPrivateChatRoom = stub.isPrivateChatRoom; IsNewPhotoAlertsRoom = stub.isNewPhotoAlertsRoom; Presence = stub.presence; tokenDateTimeTicks = stub.tokenDateTimeTicks; token = stub.token; hasArchive = stub.hasArchive; state = new StateStub(); state.Initialise( stub.guid, stub.selected, stub.guest, stub.newMessages, stub.totalMessages, stub.latestItem, stub.latestItemSeen, stub.latestItemOld, stub.listOrder, stub.tokenDateTimeTicks, stub.token); addToStateStoreIfNotAlreadyThere(controllerStateStore, state); html = new RoomHtml(stub, LoggedIn); string outerClientID = roomStub.parentClientID + "_Room_" + Guid + "_Outer"; DOMElement newNode = Document.CreateElement("span"); newNode.ID = outerClientID; newNode.InnerHTML = html.ToHtml(); roomList.AppendChild(newNode.FirstChild); InitialiseElements(outerClientID); genericInitialise(); }
public void UpdateStatsAfterUnPause(StateStub ss) { LatestItemOld = ss.latestItemOld; LatestItemSeen = ss.latestItemSeen; NewMessages = ss.newMessages; TotalMessages = ss.totalMessages; updateUI(); }
public StoreRoomStateAsync(StateStub[] state, int usrK, Guid dsiGuid) { List<SerializedStateStubHolder> goodStates = new List<SerializedStateStubHolder>(); foreach (StateStub ss in state) { try { if (ss != null) { Guid g = ss.guid.UnPackGuid(); Chat.RoomSpec spec = Chat.RoomSpec.FromGuid(g); if (spec != null) goodStates.Add(new SerializedStateStubHolder(g, SerializeStateStub(ss))); } } catch { } } State = goodStates.ToArray(); UsrK = usrK; DsiGuid = dsiGuid; }
public static StateStub[] GetStateFromCacheOrDatabase(Guid[] roomGuids, int usrK, Guid dsiGuid, RoomPinSet roomPinSet) { try { Dictionary<Guid, RoomPin> roomPins = new Dictionary<Guid, RoomPin>(); if (roomPinSet != null) roomPinSet.ToList().ForEach((rp) => { if (!roomPins.ContainsKey(rp.RoomGuid)) roomPins.Add(rp.RoomGuid, rp); }); string[] serializedStatesFromCache = null; if (usrK > 0) serializedStatesFromCache = Caching.Instances.Main.MultiGet<string>(roomGuids.ConvertAll(g => Chat.GetRoomStateCacheHolderKey(usrK, g).ToString())); else serializedStatesFromCache = Caching.Instances.Main.MultiGet<string>(roomGuids.ConvertAll(g => Chat.GetRoomStateCacheHolderKey(dsiGuid, g).ToString())); if (serializedStatesFromCache.Length == 0) return null; Dictionary<Guid, StateStub> states = new Dictionary<Guid, StateStub>(); foreach (string serializedState in serializedStatesFromCache) { if (serializedState != null && serializedState.Length > 0) { try { StateStub s = deSerializeStateStub(serializedState); if (s != null && s.guid.Length > 0) states.Add(s.guid.UnPackGuid(), s); } catch { } } } if (roomPins.Count > 0) { foreach (Guid g in roomGuids) { if (!states.ContainsKey(g) && roomPins.ContainsKey(g) && roomPins[g].StateStub != null && roomPins[g].StateStub.Length > 0) { try { StateStub ss = Chat.deSerializeStateStub(roomPins[g].StateStub); if (ss != null && ss.guid.Length > 0) states.Add(g, ss); } catch { } } } } if (states.Count == 0) return null; else { StateStub[] ssArray = new StateStub[states.Count]; states.Values.CopyTo(ssArray, 0); return ssArray; } } catch { return null; } }
RefreshStub refreshPrivate(bool isFirstRequest, string lastItemGuidString, int sessionID, string lastActionTicks, string pageUrl, int usrK, StateStub[] roomState) { Guid lastItemGuidReturned = Guid.Empty; Guid lastItemGuid = lastItemGuidString.Length == 0 ? Guid.Empty : lastItemGuidString.UnPackGuid(); if (usrK == 0) sessionID = 0; ChatLibrary.ChatServerInterface cs = (ChatLibrary.ChatServerInterface)Activator.GetObject(typeof(ChatLibrary.ChatServerInterface), Bobs.Vars.ChatServerAddress); string chatItems = cs.GetLatest(usrK, sessionID, isFirstRequest, lastItemGuid, ref lastItemGuidReturned); if (chatItems == "wrong session") throw new WrongSessionException(); List<GuestRefreshStub> guestStubs = new List<GuestRefreshStub>(); if (roomState != null) { foreach (StateStub ss in roomState) { if (ss.guest) { Guid g = ss.guid.UnPackGuid(); Chat.RoomSpec spec = Chat.RoomSpec.FromGuid(g); if (!spec.MightFailReadPermissionCheck || Chat.Authenticate(ss.token, ss.tokenDateTimeTicks, g)) { Guid guestLastItemGuidReturned = Guid.Empty; Guid guestLastItemGuid = ss.latestItem.Length == 0 ? Guid.Empty : ss.latestItem.UnPackGuid(); string guestChatItems = cs.GetLatestGuest(usrK, isFirstRequest, guestLastItemGuid, ref guestLastItemGuidReturned, ss.guid.UnPackGuid()); if (guestChatItems.Length > 0) { GuestRefreshStub guestStub = new GuestRefreshStub(); guestStub.roomGuid = ss.guid; guestStub.itemsJson = guestChatItems; guestStub.lastItemGuidReturned = guestLastItemGuidReturned.Pack(); guestStubs.Add(guestStub); } } } } } DateTime lastAction = new DateTime(long.Parse(lastActionTicks)); if (lastAction < DateTime.Now.AddMinutes(-5)) throw new TimeoutException(); RefreshStub r = new RefreshStub(); r.guestRefreshStubs = guestStubs.Count == 0 ? null : guestStubs.ToArray(); r.itemsJson = chatItems; r.lastActionTicks = lastActionTicks; r.lastItemGuidReturned = lastItemGuidReturned.Pack(); return r; }
public RefreshStub Refresh(bool isFirstRequest, string lastItemGuidString, int sessionID, string lastActionTicks, string pageUrl, StateStub[] roomState) { WaitIfDevEnv(); int usrK = Chat.GetUsrKWithoutTouchingDatabase(); storeRoomState(roomState, usrK); return refreshPrivate(isFirstRequest, lastItemGuidString, sessionID, lastActionTicks, pageUrl, usrK, roomState); }
void storeRoomState(StateStub[] roomState, int usrK) { Guid dsiGuid = usrK > 0 ? Guid.Empty : Chat.GetDsiGuidWithoutTouchingDatabase(); Chat.StoreStateInCache(roomState, usrK, dsiGuid); }
public DeleteArchiveStub DeleteArchive(string roomGuid, string lastItemGuidString, int sessionID, string lastActionTicks, string pageUrl, StateStub[] roomState) { WaitIfDevEnv(); Guid guid = roomGuid.UnPackGuid(); Chat.RoomSpec spec = Chat.RoomSpec.FromGuid(guid); if (Usr.Current == null || Usr.Current.IsSkeleton || Usr.Current.Banned) throw new LoginPermissionException(); if (spec == null) throw new InvalidRoomException(); if (!spec.IsPrivateChatRoom) throw new InvalidRoomException(); if (!spec.CheckPermission(Usr.Current, true)) throw new WritePermissionException(); storeRoomState(roomState, Usr.Current.K); lastActionTicks = resetLastActionAndSessionID(sessionID); //delete archive... spec.DeleteArchive(); DeleteArchiveStub das = new DeleteArchiveStub(); das.roomGuid = roomGuid; RefreshStub r = refreshPrivate(false, lastItemGuidString, sessionID, lastActionTicks, pageUrl, Usr.Current.K, roomState); das.guestRefreshStubs = r.guestRefreshStubs; das.itemsJson = r.itemsJson; das.lastActionTicks = r.lastActionTicks; das.lastItemGuidReturned = r.lastItemGuidReturned; return das; }
public GetStateStub ResetSessionAndGetState(bool isFirstRequest, string lastItemGuidString, int sessionID, string lastActionTicks, string pageUrl, StateStub[] roomState) { WaitIfDevEnv(); int usrK = Chat.GetUsrKWithoutTouchingDatabase(); Guid dsiGuid = usrK == 0 ? Guid.Empty : Chat.GetDsiGuidWithoutTouchingDatabase(); RoomPinSet rps = null; string newLastActionTicks = ""; if (usrK > 0 && Usr.Current != null) { newLastActionTicks = resetLastActionAndSessionID(sessionID); Query q = new Query(); q.QueryCondition = new Q(RoomPin.Columns.UsrK, usrK); q.Columns = new ColumnSet(RoomPin.Columns.RoomGuid, RoomPin.Columns.StateStub); rps = new RoomPinSet(q); } else newLastActionTicks = DateTime.Now.Ticks.ToString(); GetStateStub gs = new GetStateStub(); gs.roomState = Chat.GetStateFromCacheOrDatabase(roomState.ConvertAll(s => s.guid.UnPackGuid()).ToArray<Guid>(), usrK, dsiGuid, rps); RefreshStub r = refreshPrivate(isFirstRequest, lastItemGuidString, sessionID, newLastActionTicks, pageUrl, usrK, null); gs.guestRefreshStubs = r.guestRefreshStubs; gs.itemsJson = r.itemsJson; gs.lastActionTicks = r.lastActionTicks; gs.lastItemGuidReturned = r.lastItemGuidReturned; return gs; }
public RefreshStub StoreUpdatedRoomListOrder(string lastItemGuidString, int sessionID, string lastActionTicks, string pageUrl, StateStub[] roomState) { WaitIfDevEnv(); if (Usr.Current == null || Usr.Current.IsSkeleton || Usr.Current.Banned) throw new LoginPermissionException(); storeRoomState(roomState, Usr.Current.K); foreach (StateStub ss in roomState) { try { RoomPin rp = new RoomPin(Usr.Current.K, ss.guid.UnPackGuid()); if (rp.ListOrder != ss.listOrder) { rp.ListOrder = ss.listOrder; rp.Update(); } } catch(BobNotFound) { Chat.RoomSpec spec = Chat.RoomSpec.FromGuid(ss.guid.UnPackGuid()); RoomPin rp = new RoomPin(); rp.DateTime = DateTime.Now; rp.ListOrder = ss.listOrder; rp.Pinned = true; rp.RoomGuid = spec.Guid; rp.Starred = spec.IsStarredByDefault; rp.UsrK = Usr.Current.K; rp.Update(); } } return refreshPrivate(false, lastItemGuidString, sessionID, lastActionTicks, pageUrl, Usr.Current.K, roomState); }
public RefreshStub Send(string message, string roomGuidString, string lastItemGuidString, int sessionID, string pageUrl, StateStub[] roomState) { WaitIfDevEnv(); if (Usr.Current == null || Usr.Current.IsSkeleton || Usr.Current.Banned) throw new LoginPermissionException(); Guid guid = roomGuidString.UnPackGuid(); Chat.RoomSpec spec = Chat.RoomSpec.FromGuid(guid); Guid chatItemGuid = Guid.NewGuid(); if (spec == null) throw new InvalidRoomException(); if (!spec.CheckPermission(Usr.Current, true)) throw new WritePermissionException(); storeRoomState(roomState, Usr.Current.K); string txt = Chat.GetMessageFromChatBox(message); #region Create a ChatMessage database entry if (!spec.IsThreadRoom) { ChatMessage c = new ChatMessage(); c.ChatItemGuid = chatItemGuid; c.DateTime = DateTime.Now; c.UsrK = Usr.Current.K; c.Text = txt; c.RoomGuid = spec.Guid; c.Update(); } #endregion Usr.Current.ChatMessageCount++; Usr.Current.DateTimeLastChatMessage = DateTime.Now; string lastActionTicks = resetLastActionAndSessionID(sessionID); //will also fire Usr.Current.Update() MessageStub m; if (spec.IsPrivateChatRoom) { #region Private chat message int recipientUsrK = Usr.Current.K == spec.ObjectK ? spec.SecondObjectK : spec.ObjectK; bool isBuddy; try { Buddy b = new Buddy(recipientUsrK, Usr.Current.K); isBuddy = true; } catch { isBuddy = false; } m = new PrivateStub( chatItemGuid.Pack(), ItemType.PrivateChatMessage, lastActionTicks, roomGuidString.UnPackGuid().Pack(), Usr.Current.NickName, Usr.Current.StmuParams, Usr.Current.K, Usr.Current.HasPic ? Usr.Current.PicOrFacebookUID : "0", Usr.Current.HasChatPic ? Usr.Current.ChatPic.Value.ToString() : "0", txt, "", isBuddy); Chat.SendJsonChatItem(m, new int[]{Usr.Current.K, recipientUsrK}); #endregion } else if (spec.IsThreadRoom || spec.IsHasPrimaryThreadObject) { #region Thread rooms Thread t = null; bool alreadyCreatedComment = false; bool createNewThread = false; if (spec.IsHasPrimaryThreadObject) { //if the object doesn't have a primary thread... IHasPrimaryThread primaryThreadObject = (IHasPrimaryThread)spec.ObjectBob; if (primaryThreadObject.ThreadK.IsNullOrZero()) { createNewThread = true; } else { try { t = new Thread(primaryThreadObject.ThreadK.Value); } catch (BobNotFound) { createNewThread = true; } } if (createNewThread) { Thread.MakerReturn threadMakerReturn = Thread.CreatePublicThread((IDiscussable)spec.ObjectBob, Guid.NewGuid(), txt, false, null, true); alreadyCreatedComment = true; if (threadMakerReturn.Success || threadMakerReturn.Duplicate) t = threadMakerReturn.Thread; else throw new Exception("Couldn't create new thread!"); } } else { t = new Thread(spec.ObjectK); } string subject = t.Subject.TruncateWithDots(30); int threadK = t.K; bool isPublic = !t.Private && !t.PrivateGroup && !t.GroupPrivate; string url = ""; if (createNewThread) { url = t.UrlRefresher() + "#Comments"; } else { if (t.LastPage == 1) url = t.UrlRefresher() + "#Comments"; else url = t.UrlRefresher("c", t.LastPage.ToString()) + "#Comments"; try { if (t.TotalComments % 20 == 0) url = t.UrlRefresher("c", (t.LastPage + 1).ToString()) + "#Comments"; else if (t.LastComment != null) url = t.LastComment.UrlRefresherAnchorAfter(); } catch { } } m = new CommentMessageStub( chatItemGuid.Pack(), ItemType.CommentChatMessage, lastActionTicks, roomGuidString.UnPackGuid().Pack(), Usr.Current.NickName, Usr.Current.StmuParams, Usr.Current.K, Usr.Current.HasPic ? Usr.Current.PicOrFacebookUID : "0", Usr.Current.HasChatPic ? Usr.Current.ChatPic.Value.ToString() : "0", txt, "", url, subject); List<int> usrKs = Thread.GetAllLoggedInParticipants(t).ToList().ConvertAll(u => u.K); try { usrKs.Add(Usr.Current.K); } catch { } Chat.SendJsonChatItem(m, usrKs.ToArray()); if (isPublic && threadK > 0) { m.guid = Guid.NewGuid().Pack(); m.roomGuid = new Chat.RoomSpec(RoomType.RandomChat).Guid.Pack(); m.pinRoomGuid = t.GetRoomSpec().Guid.Pack(); Chat.SendJsonChatItem(m); } if (!alreadyCreatedComment) { AddCommentJob job = new AddCommentJob(t.K, txt, Usr.Current.K, chatItemGuid); job.ExecuteAsynchronously(); } #endregion } else { #region Public chat rooms m = new MessageStub( chatItemGuid.Pack(), ItemType.PublicChatMessage, lastActionTicks, roomGuidString.UnPackGuid().Pack(), Usr.Current.NickName, Usr.Current.StmuParams, Usr.Current.K, Usr.Current.HasPic ? Usr.Current.PicOrFacebookUID : "0", Usr.Current.HasChatPic ? Usr.Current.ChatPic.ToString() : "0", txt, ""); Chat.SendJsonChatItem(m, Usr.Current.K); #endregion } SendStub s = new SendStub(); s.itemGuid = chatItemGuid.Pack(); RefreshStub r = refreshPrivate(false, lastItemGuidString, sessionID, lastActionTicks, pageUrl, Usr.Current.K, roomState); s.guestRefreshStubs = r.guestRefreshStubs; s.itemsJson = r.itemsJson; s.lastActionTicks = r.lastActionTicks; s.lastItemGuidReturned = r.lastItemGuidReturned; return s; }
public bool StoreState(StateStub[] roomState) { WaitIfDevEnv(); int usrK = Chat.GetUsrKWithoutTouchingDatabase(); storeRoomState(roomState, usrK); return true; }
public MoreInfoStub MoreInfo(string roomGuid, string lastItemGuidString, int sessionID, string lastActionTicks, string pageUrl, StateStub[] roomState) { WaitIfDevEnv(); Guid guid = roomGuid.UnPackGuid(); Chat.RoomSpec spec = Chat.RoomSpec.FromGuid(guid); int usrK = Usr.Current == null ? 0 : Usr.Current.K; if (spec == null) throw new InvalidRoomException(); if (!spec.CheckPermission(Usr.Current, false)) throw new ReadPermissionException(); storeRoomState(roomState, usrK); lastActionTicks = resetLastActionAndSessionID(sessionID); MoreInfoStub ms = new MoreInfoStub(); ms.roomGuid = roomGuid; ms.moreInfoHtml = spec.GetMoreInfoHtml(); RefreshStub r = refreshPrivate(false, lastItemGuidString, sessionID, lastActionTicks, pageUrl, usrK, roomState); ms.guestRefreshStubs = r.guestRefreshStubs; ms.itemsJson = r.itemsJson; ms.lastActionTicks = r.lastActionTicks; ms.lastItemGuidReturned = r.lastItemGuidReturned; return ms; }
public static void StoreStateInCache(StateStub[] roomState, int usrK, Guid dsiGuid) { StoreRoomStateAsync job = new StoreRoomStateAsync(roomState, usrK, dsiGuid); System.Threading.Thread thread = Utilities.GetSafeThread(() => job.Execute()); thread.Start(); }
public PinStub Pin(string clientID, string roomGuid, string lastItemGuidString, int sessionID, string lastActionTicks, string pageUrl, StateStub[] roomState) { WaitIfDevEnv(); Guid guid = roomGuid.UnPackGuid(); Chat.RoomSpec spec = Chat.RoomSpec.FromGuid(guid); if (Usr.Current == null || Usr.Current.IsSkeleton || Usr.Current.Banned) throw new LoginPermissionException(); if (spec == null) throw new InvalidRoomException(); if (!spec.CheckPermission(Usr.Current, false)) throw new ReadPermissionException(); storeRoomState(roomState, Usr.Current.K); RoomStub r; if (spec.RoomType == RoomType.BuddyAlerts && spec.ObjectK > 0) { if (spec.ObjectK == Usr.Current.K) throw new SelfPrivateChatRoomException(); spec = new Chat.RoomSpec(spec.ObjectK, Usr.Current.K); guid = spec.Guid; } if (spec.RoomType == RoomType.PrivateChat && spec.ObjectK > 0 && spec.SecondObjectK == 0) { if (spec.ObjectK == Usr.Current.K) throw new SelfPrivateChatRoomException(); spec = new Chat.RoomSpec(spec.ObjectK, Usr.Current.K); guid = spec.Guid; } if (!spec.CheckPermission(Usr.Current, false)) throw new ReadPermissionException(); lastActionTicks = resetLastActionAndSessionID(sessionID); RoomPin p = getOrCreateRoomPin(guid, null, Usr.Current.K); r = new RoomStub( clientID, guid.Pack(), spec.GetName(Usr.Current), spec.GetUrl(Usr.Current), true, spec.IsStarredByDefault, spec.IsStarredByDefault, true, spec.IsStarrable, false, false, 0, 0, "", "", "", spec.IsReadOnly, p.ListOrder, spec.IsPhotoChatRoom, spec.IsPrivateChatRoom, spec.IsNewPhotoAlertsRoom, spec.GetPrivateChatRoomPresence(Usr.Current), spec.Icon, "", "", spec.HasArchive, spec.HiddenFromRoomList, spec.IsStreamRoom); Guid lastItemGuidReturned = Guid.Empty; Guid lastItemGuid = lastItemGuidString.Length == 0 ? Guid.Empty : lastItemGuidString.UnPackGuid(); ChatLibrary.ChatServerInterface cs = (ChatLibrary.ChatServerInterface)Activator.GetObject(typeof(ChatLibrary.ChatServerInterface), Bobs.Vars.ChatServerAddress); string chatItems = cs.PinRoom(Usr.Current.K, sessionID, lastItemGuid, ref lastItemGuidReturned, guid); PinStub ps = new PinStub(); ps.roomStub = r; ps.itemsJson = chatItems; ps.lastActionTicks = lastActionTicks; ps.lastItemGuidReturned = lastItemGuidReturned.Pack(); return ps; }
public RoomStateCacheHolder(StateStub state) { State = state; }
public PinStub SwitchPhotoRoom(string clientID, string roomGuid, string lastItemGuidString, int sessionID, string lastActionTicks, string pageUrl, StateStub[] roomState) { WaitIfDevEnv(); Guid guid = roomGuid.UnPackGuid(); Chat.RoomSpec spec = Chat.RoomSpec.FromGuid(guid); int usrK = Usr.Current == null ? 0 : Usr.Current.K; if (spec == null) throw new InvalidRoomException(); if (!spec.CheckPermission(Usr.Current, false)) throw new ReadPermissionException(); storeRoomState(roomState, usrK); RoomStub r; string tokenDateTime = DateTime.Now.Ticks.ToString(); string token = Chat.GetToken(guid, tokenDateTime); //we should add the new guest room to the state stubs... StateStub ss = new StateStub(); ss.guid = roomGuid; ss.guest = true; ss.listOrder = -1; ss.tokenDateTimeTicks = tokenDateTime; ss.token = token; List<StateStub> roomStateList = roomState.ToList(); roomStateList.Add(ss); roomState = roomStateList.ToArray(); lastActionTicks = resetLastActionAndSessionID(sessionID); r = new RoomStub( clientID, guid.Pack(), spec.GetName(Usr.Current), spec.GetUrl(Usr.Current), false, spec.IsStarredByDefault, spec.IsStarredByDefault, true, spec.IsStarrable, false, true, 0, 0, "", "", "", spec.IsReadOnly, -1, spec.IsPhotoChatRoom, spec.IsPrivateChatRoom, spec.IsNewPhotoAlertsRoom, spec.GetPrivateChatRoomPresence(Usr.Current), spec.Icon, tokenDateTime, token, spec.HasArchive, spec.HiddenFromRoomList, spec.IsStreamRoom); Guid lastItemGuidReturned = Guid.Empty; Guid lastItemGuid = lastItemGuidString.Length == 0 ? Guid.Empty : lastItemGuidString.UnPackGuid(); ChatLibrary.ChatServerInterface cs = (ChatLibrary.ChatServerInterface)Activator.GetObject(typeof(ChatLibrary.ChatServerInterface), Bobs.Vars.ChatServerAddress); string chatItems = cs.GetLatest(usrK, sessionID, false, lastItemGuid, ref lastItemGuidReturned); PinStub ps = new PinStub(); ps.roomStub = r; ps.itemsJson = chatItems; ps.lastActionTicks = lastActionTicks; ps.lastItemGuidReturned = lastItemGuidReturned.Pack(); return ps; }
public void InitialiseFromElement(DOMElement e, StateStub[] controllerStateStore) { Guid = e.Attributes.GetNamedItem("roomGuid").Value; Name = e.Attributes.GetNamedItem("roomName").Value; Url = e.Attributes.GetNamedItem("roomUrl").Value; Pinable = bool.Parse(e.Attributes.GetNamedItem("roomPinable").Value); pinned = bool.Parse(e.Attributes.GetNamedItem("roomPinned").Value); starred = bool.Parse(e.Attributes.GetNamedItem("roomStarred").Value); Starrable = bool.Parse(e.Attributes.GetNamedItem("roomStarrable").Value); isStarredByDefault = bool.Parse(e.Attributes.GetNamedItem("roomIsStarredByDefault").Value); ReadOnly = bool.Parse(e.Attributes.GetNamedItem("roomReadOnly").Value); IsPhotoChatRoom = bool.Parse(e.Attributes.GetNamedItem("roomIsPhotoChatRoom").Value); IsPrivateChatRoom = bool.Parse(e.Attributes.GetNamedItem("roomIsPrivateChatRoom").Value); IsNewPhotoAlertsRoom = bool.Parse(e.Attributes.GetNamedItem("roomIsNewPhotoAlertsRoom").Value); Presence = (PresenceState)int.ParseInvariant(e.Attributes.GetNamedItem("roomPresence").Value); Icon = e.Attributes.GetNamedItem("roomIcon").Value; tokenDateTimeTicks = e.Attributes.GetNamedItem("roomTokenDateTimeTicks").Value; token = e.Attributes.GetNamedItem("roomToken").Value; hasArchive = bool.Parse(e.Attributes.GetNamedItem("roomHasArchive").Value); hiddenFromRoomList = bool.Parse(e.Attributes.GetNamedItem("roomHiddenFromRoomList").Value); isStreamRoom = bool.Parse(e.Attributes.GetNamedItem("roomisStreamRoom").Value); state = new StateStub(); state.Initialise( Guid, bool.Parse(e.Attributes.GetNamedItem("roomSelected").Value), bool.Parse(e.Attributes.GetNamedItem("roomGuest").Value), int.ParseInvariant(e.Attributes.GetNamedItem("roomNewMessages").Value), int.ParseInvariant(e.Attributes.GetNamedItem("roomTotalMessages").Value), e.Attributes.GetNamedItem("roomLatestItem").Value, e.Attributes.GetNamedItem("roomLatestItemSeen").Value, e.Attributes.GetNamedItem("roomLatestItemOld").Value, int.ParseInvariant(e.Attributes.GetNamedItem("roomListOrder").Value), tokenDateTimeTicks, token); addToStateStoreIfNotAlreadyThere(controllerStateStore, state); stub = new RoomStub( Parent.ClientID, Guid, Name, Url, Pinned, Starred, isStarredByDefault, Pinable, Starrable, Selected, Guest, NewMessages, TotalMessages, LatestItem, LatestItemSeen, LatestItemOld, ReadOnly, state.listOrder, IsPhotoChatRoom, IsPrivateChatRoom, IsNewPhotoAlertsRoom, Presence, Icon, tokenDateTimeTicks, token, hasArchive, hiddenFromRoomList, isStreamRoom); html = new RoomHtml(stub, LoggedIn); InitialiseElements(""); genericInitialise(); }
public RefreshStub RePin(string clientID, string roomGuid, string lastItemGuidString, int sessionID, string lastActionTicks, string pageUrl, StateStub[] roomState) { WaitIfDevEnv(); Guid guid = roomGuid.UnPackGuid(); Chat.RoomSpec spec = Chat.RoomSpec.FromGuid(guid); if (Usr.Current == null || Usr.Current.IsSkeleton || Usr.Current.Banned) throw new LoginPermissionException(); if (spec == null) throw new InvalidRoomException(); if (!spec.CheckPermission(Usr.Current, false)) throw new ReadPermissionException(); StateStub state = null; foreach (StateStub ss in roomState) { if (ss.guid == roomGuid) { state = ss; break; } } storeRoomState(roomState, Usr.Current.K); lastActionTicks = resetLastActionAndSessionID(sessionID); RoomPin p = getOrCreateRoomPin(guid, state != null ? (int?)state.listOrder : null, Usr.Current.K); Guid lastItemGuidReturned = Guid.Empty; Guid lastItemGuid = lastItemGuidString.Length == 0 ? Guid.Empty : lastItemGuidString.UnPackGuid(); ChatLibrary.ChatServerInterface cs = (ChatLibrary.ChatServerInterface)Activator.GetObject(typeof(ChatLibrary.ChatServerInterface), Bobs.Vars.ChatServerAddress); string chatItems = cs.PinRoom(Usr.Current.K, sessionID, lastItemGuid, ref lastItemGuidReturned, guid); RefreshStub rs = new RefreshStub(); rs.itemsJson = chatItems; rs.lastActionTicks = lastActionTicks; rs.lastItemGuidReturned = lastItemGuidReturned.Pack(); return rs; }
void addToStateStoreIfNotAlreadyThere(StateStub[] stateStore, StateStub state) { for (int k = 0; k < stateStore.Length; k++) { StateStub ss = (StateStub)stateStore[k]; if (ss.guid == state.guid) return; } stateStore[stateStore.Length] = state; }
public GotRoomStateEventArgs(StateStub[] roomState) { RoomState = roomState; }