/// <summary> /// This method is called when the ticket query has completed. /// </summary> private void OnTicketReply(KcdQuery query) { if (Status != VncSessionStatus.Ticket) { return; } TicketQuery = null; try { AnpMsg m = query.Res; if (m.Type == KAnp.KANP_RES_VNC_START_TICKET || m.Type == KAnp.KANP_RES_VNC_CONNECT_TICKET) { Ticket = m.Elements[0].Bin; HandleNextSessionStep(); } else { throw EAnpException.FromKAnpReply(m); } } catch (Exception ex) { HandleSessionTrouble(ex); } }
/// <summary> /// Called when the login reply is received. /// </summary> private void HandleConnectKwsReply(KcdQuery query) { KLogging.Log("Got login reply, kws " + m_kws.InternalID + ", status " + m_kws.Cd.MainStatus); Debug.Assert(m_ks.LoginStatus == KwsLoginStatus.LoggingIn); // This is the standard login reply. if (query.Res.Type == KAnp.KANP_RES_KWS_CONNECT_KWS) { // Get the provided information. KwsConnectRes r = new KwsConnectRes(query.Res); KLogging.Log(m_currentStep + " login step: " + r.ErrMsg); // Dispatch. if (r.Code == KAnp.KANP_KWS_LOGIN_OK) { HandleConnectKwsSuccess(r); } else if (r.Code == KAnp.KANP_KWS_LOGIN_BAD_PWD_OR_TICKET) { HandleBadPwdOrTicket(r); } else { HandleLoginFailure(TranslateKcdLoginStatusCode(r.Code), new Exception(r.ErrMsg)); } } // This is an unexpected reply. else { HandleLoginFailure(KwsLoginResult.MiscKcdError, EAnpException.FromKAnpReply(query.Res)); } }
/// <summary> /// Format the reply if the operation failed. /// </summary> protected virtual void FormatFailureReply(AnpMsg m) { m.Type = (UInt32)EAnpRes.Failure; EAnpException castedEx = EAnpException.FromException(ErrorEx); castedEx.Serialize(m); }
/// <summary> /// This method should be called when an error occurs in the session. /// This is a no-op if the session has completed. 'ex' can be null if /// the session ended normally. /// </summary> public void HandleSessionTrouble(Exception ex) { if (Status == VncSessionStatus.Completed) { return; } // Determine whether we were starting the session. bool startFlag = (Status != VncSessionStatus.Started); // Convert the exception to an EAnp exception as needed. If we // failed to start, we always need an exception. EAnpException castedEx = null; if (ex != null) { castedEx = EAnpException.FromException(ex); } if (castedEx == null && startFlag) { castedEx = new EAnpExInterrupted(); } // Terminate this session. Terminate(); // Notify listeners. There are three cases: // - The session failed to start. // - The session ended normally. // - The session eneded abnormally. PostLocalVncSessionEvent(startFlag, castedEx); Kws.OnStateChange(WmStateChange.Transient); }
/// <summary> /// Handle the result of the commands. /// </summary> protected virtual void HandleCmdResult(AnpMsg res) { if (res.Type != KAnp.KANP_RES_OK) { throw EAnpException.FromKAnpReply(res); } }
/// <summary> /// Post a LocalVncSession event. /// </summary> private void PostLocalVncSessionEvent(bool startFlag, EAnpException ex) { AnpMsg m = Kws.MakeTransientEAnpEvent(EAnpEvt.LocalVncSession); m.AddBin(SessionUuid); m.AddUInt64(SessionID); m.AddUInt32(Convert.ToUInt32(ServerSessionFlag)); m.AddUInt32(Convert.ToUInt32(startFlag)); m.AddUInt32(Convert.ToUInt32(ex != null)); if (ex != null) { ex.Serialize(m); } Kws.PostTransientEAnpEvent(m); }
/// <summary> /// Negociate the role. /// </summary> private void NegociateRole() { AnpMsg m = CreateAnpMsg(KAnp.KANP_CMD_MGT_SELECT_ROLE); m.AddUInt32(KAnp.KANP_KCD_ROLE_APP_SHARE); SendAnpMsg(m); m = GetAnpMsg(); if (m.Type == KAnp.KANP_RES_FAIL) { throw EAnpException.FromKAnpReply(m); } if (m.Type != KAnp.KANP_RES_OK) { throw new Exception("expected RES_OK in role negociation"); } }
public override KwsAnpEventStatus HandleAnpEvent(AnpMsg evt) { if (evt.Type == KAnp.KANP_EVT_VNC_START) { UInt64 date = evt.Elements[1].UInt64; UInt32 userID = evt.Elements[2].UInt32; UInt64 sessionID = evt.Elements[3].UInt64; String subject = evt.Elements[4].String; AnpMsg etEvt = Kws.MakePermEAnpEvent(EAnpEvt.VncSessionStarted, date, userID); etEvt.AddUInt64(sessionID); etEvt.AddString(subject); Kws.PostPermEAnpEvent(etEvt); return(KwsAnpEventStatus.Processed); } else if (evt.Type == KAnp.KANP_EVT_VNC_END) { UInt64 date = evt.Elements[1].UInt64; UInt32 userID = evt.Elements[2].UInt32; UInt64 sessionID = evt.Elements[3].UInt64; AnpMsg etEvt = Kws.MakePermEAnpEvent(EAnpEvt.VncSessionEnded, date, userID); etEvt.AddUInt64(sessionID); Kws.PostPermEAnpEvent(etEvt); // If we have a local session, notify it about the event. if (LocalSession != null) { EAnpException ex = null; if (evt.Minor >= 5) { ex = EAnpException.FromKAnpFailure(evt, 4); } else { ex = new EAnpExGeneric("session closed"); } LocalSession.OnSessionEndEventReceived(sessionID, ex); } return(KwsAnpEventStatus.Processed); } return(KwsAnpEventStatus.Unprocessed); }
/// <summary> /// Called when the create workspace command reply is received. /// </summary> private void HandleCreateKwsCmdResult(KcdQuery query) { if (m_kcdQuery != query) { return; } m_kcdQuery = null; Debug.Assert(m_step == OpStep.CreateReply); try { AnpMsg res = query.Res; // Failure. if (res.Type != KAnp.KANP_RES_MGT_KWS_CREATED) { throw EAnpException.FromKAnpReply(res); } // Parse the reply. UInt64 externalID = res.Elements[0].UInt64; String emailID = res.Elements[1].String; // Validate that the KCD is not screwing with us. This can // happen if the KCD state has been reverted. if (Wm.GetKwsByExternalID(Kws.Kcd.KcdID, externalID) != null) { throw new Exception("duplicate " + KwmStrings.Kws + " external ID"); } // Update the workspace credentials. Creds.ExternalID = externalID; Creds.EmailID = emailID; // Wait for login. m_step = OpStep.LoggingIn; Kws.Sm.SetLoginType(KwsLoginType.Cached); Kws.Sm.SetSpawnStep(KwsSpawnTaskStep.Login); } catch (Exception ex) { HandleFailure(ex); } }
protected override void HandleCmdResult(AnpMsg res) { if (res.Type != KAnp.KANP_RES_KWS_INVITE_KWS) { throw EAnpException.FromKAnpReply(res); } int i = 0; Wleu = res.Elements[i++].String; i++; foreach (User u in UserList) { u.EmailID = res.Elements[i++].String; u.Url = res.Elements[i++].String; u.Error = res.Elements[i++].String; } }
/// <summary> /// This method should be called when a "VNC session end" event is /// received from the KCD. /// </summary> public void OnSessionEndEventReceived(UInt64 sessionID, EAnpException ex) { if (Status == VncSessionStatus.Completed) { return; } // Check if the local session is being ended. else if (Status == VncSessionStatus.Started) { if (sessionID == SessionID) { HandleSessionTrouble(ex); } } // Cache the session ID. else { SessionIDTree[sessionID] = sessionID; } }
/// <summary> /// Negociate the session. /// </summary> private void NegociateSession() { AnpMsg m = null; if (m_session.ServerSessionFlag) { m = CreateAnpMsg(KAnp.KANP_CMD_VNC_START_SESSION); m.AddBin(m_session.Ticket); m.AddString(m_session.Subject); } else { m = CreateAnpMsg(KAnp.KANP_CMD_VNC_CONNECT_SESSION); m.AddBin(m_session.Ticket); } SendAnpMsg(m); m = GetAnpMsg(); if (m_session.ServerSessionFlag) { if (m.Type != KAnp.KANP_RES_VNC_START_SESSION) { throw EAnpException.FromKAnpReply(m); } m_session.SessionID = m.Elements[0].UInt64; } else { if (m.Type != KAnp.KANP_RES_OK) { throw EAnpException.FromKAnpReply(m); } } }
/// <summary> /// Called when an incoming query is received. /// </summary> public void HandleIncomingQuery(Object sender, EAnpIncomingQueryEventArgs args) { // Get the query. EAnpIncomingQuery query = args.Query; if (!query.IsPending()) { return; } // Create the result message. AnpMsg res = new AnpMsg(); res.Type = (uint)EAnpRes.OK; // Dispatch. WmCoreOp coreOp = null; try { AnpMsg cmd = query.Cmd; EAnpCmd t = (EAnpCmd)cmd.Type; // Commands with core operations. if (t == EAnpCmd.RegisterKps) { coreOp = MakeCoreOpFromCmd(new WmCoreOpRegisterKps(), cmd); } else if (t == EAnpCmd.SetKwsTask) { coreOp = MakeCoreOpFromCmd(new KwsCoreOpSetKwsTask(), cmd); } else if (t == EAnpCmd.SetLoginPwd) { coreOp = MakeCoreOpFromCmd(new KwsCoreOpSetLoginPwd(), cmd); } else if (t == EAnpCmd.CreateKws) { coreOp = MakeCoreOpFromCmd(new KwsCoreOpCreateKws(), cmd); } else if (t == EAnpCmd.InviteKws) { coreOp = MakeCoreOpFromCmd(new KwsCoreOpInviteKws(), cmd); } else if (t == EAnpCmd.LookupRecAddr) { coreOp = MakeCoreOpFromCmd(new WmCoreOpLookupRecAddr(), cmd); } else if (t == EAnpCmd.ChatPostMsg) { coreOp = MakeCoreOpFromCmd(new KwsCoreOpChatPostMsg(), cmd); } else if (t == EAnpCmd.PbAcceptChat) { coreOp = MakeCoreOpFromCmd(new KwsCoreOpPbAcceptChat(), cmd); } // Commands without core operations. else if (t == EAnpCmd.ExportKws) { HandleExportKws(cmd, res); } else if (t == EAnpCmd.ImportKws) { HandleImportKws(cmd, res); } else if (t == EAnpCmd.VncCreateSession) { HandleVncCreateSession(cmd, res); } else if (t == EAnpCmd.VncJoinSession) { HandleVncJoinSession(cmd, res); } else if (t == EAnpCmd.CheckEventUuid) { HandleCheckEventUuid(cmd, res); } else if (t == EAnpCmd.FetchEvent) { HandleFetchEvent(cmd, res); } else if (t == EAnpCmd.FetchState) { HandleFetchState(cmd, res); } // Eeep! else { res.Type = (UInt32)EAnpRes.Failure; (new EAnpExGeneric("invalid EAnp command type")).Serialize(res); } } catch (Exception ex) { res.Type = (UInt32)EAnpRes.Failure; res.ClearPayload(); EAnpException castedEx = EAnpException.FromException(ex); castedEx.Serialize(res); } if (!query.IsPending()) { return; } // We got a core operation. Start it. if (coreOp != null) { try { WmEAnpQueryCoreOp qco = new WmEAnpQueryCoreOp(query, coreOp, res); qco.Start(); } catch (Exception ex) { KBase.HandleException(ex, true); } } // Reply to the query right away. else { query.Reply(res); } }