/// <summary> /// Helper method to start a session. /// </summary> private byte[] StartSession(bool serverSessionFlag, bool supportFlag, int windowHandle, String subject, UInt64 sessionID) { // Throw if we cannot open the session. if (AppVnc.SessionPresentFlag) { throw new Exception("a screen sharing session is already running"); } if (!IsOnlineCapable()) { throw new Exception("the " + KwmStrings.Kws + " is not connected to the server"); } // Remember that we have started a session. SessionPresentFlag = true; // Create the local session object. LocalSession = new VncLocalSession(this); LocalSession.ServerSessionFlag = serverSessionFlag; LocalSession.SupportSessionFlag = supportFlag; LocalSession.WindowHandle = windowHandle; LocalSession.Subject = subject; LocalSession.SessionID = sessionID; // Asynchronously start the session. KBase.ExecInUI(LocalSession.HandleNextSessionStep); Kws.OnStateChange(WmStateChange.Transient); return(LocalSession.SessionUuid); }
/// <summary> /// Complete the operation if we are ready to. /// </summary> private void CompleteIfNeeded() { if (DoneFlag || m_step != OpStep.LoggingIn || Kws.Cd.KcdState.LoginStatus != KwsLoginStatus.LoggedIn || Kws.Cd.MainStatus != KwsMainStatus.NotYetSpawned || Kws.Cd.CurrentTask != KwsTask.Spawn) { return; } // Update the main status of the workspace. Kws.Cd.MainStatus = KwsMainStatus.Good; Kws.OnStateChange(WmStateChange.Permanent); // Ask the state machine to work online. Kws.Sm.RequestTaskSwitch(KwsTask.WorkOnline); // Serialize the KWM so we don't lose the workspace if the KWM // crashes. Wm.Serialize(); // We're done. Complete(); }
public override void Start() { try { // Prepare to start. PrepareStart(); // Register to the workspace. RegisterToKws(); // Make sure the workspace is logged in. if (Kws.Cd.KcdState.LoginStatus != KwsLoginStatus.LoggedIn) { throw new EAnpExInterrupted(); } // Post the command. AnpMsg cmd = Kws.NewKcdCmd(0); PrepareCmd(cmd); m_kcdQuery = Kws.PostKcdCmd(cmd, OnKcdQueryResult); } catch (Exception ex) { HandleFailure(ex); } }
private KwsAnpEventStatus HandleTriggerKwsEvent(AnpMsg evt) { UInt64 date = evt.Elements[1].UInt64; UInt32 userID = evt.Elements[3].UInt32; String subject = evt.Elements[4].String; AnpMsg etEvt = Kws.MakePermEAnpEvent(EAnpEvt.PbKwsRequested, date, userID); etEvt.AddString(subject); Kws.PostPermEAnpEvent(etEvt); return(KwsAnpEventStatus.Processed); }
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); }
public override KwsAnpEventStatus HandleAnpEvent(AnpMsg evt) { // Incoming chat message. if (evt.Type == KAnp.KANP_EVT_CHAT_MSG) { UInt64 date = evt.Elements[1].UInt64; UInt32 userID = evt.Elements[3].UInt32; String userMsg = evt.Elements[4].String; AnpMsg etEvt = Kws.MakePermEAnpEvent(EAnpEvt.ChatMsgReceived, date, userID); etEvt.AddString(userMsg); Kws.PostPermEAnpEvent(etEvt); return(KwsAnpEventStatus.Processed); } return(KwsAnpEventStatus.Unprocessed); }
/// <summary> /// Send the workspace creation command if we are ready to. /// </summary> private void SendCreateKwsCmdIfNeeded() { if (DoneFlag || m_step != OpStep.Connecting || Kws.Kcd.ConnStatus != KcdConnStatus.Connected) { return; } m_step = OpStep.CreateReply; AnpMsg cmd = Wm.NewKcdCmd(Kws.Kcd.MinorVersion, KAnp.KANP_CMD_MGT_CREATE_KWS); cmd.AddString(Creds.KwsName); cmd.AddBin(Creds.Ticket); cmd.AddUInt32(Convert.ToUInt32(Creds.PublicFlag)); cmd.AddUInt32(Convert.ToUInt32(Creds.SecureFlag)); if (cmd.Minor >= 4) { cmd.AddUInt32(Convert.ToUInt32(Creds.ThinKfsFlag)); } m_kcdQuery = Kws.PostKcdCmd(cmd, HandleCreateKwsCmdResult); }