public override void Parse(AnpMsg cmd) { int i = 0; KwsID = cmd.Elements[i++].UInt64; Pwd = cmd.Elements[i++].String; }
public override void Parse(AnpMsg cmd) { int i = 0; KwsID = cmd.Elements[i++].UInt64; Task = (KwsTask)cmd.Elements[i++].UInt32; }
public override void Parse(AnpMsg cmd) { int i = 0; Creds.KwsName = cmd.Elements[i++].String; Creds.Flags = cmd.Elements[i++].UInt32; }
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); } }
/// <summary> /// Handle a message received from a KCD. /// </summary> private void ProcessIncomingKcdMessage(KcdThreadHost k, AnpMsg msg) { if (k.ConnStatus == KcdThreadConnStatus.RoleReply) { if (msg.Type == KAnp.KANP_RES_FAIL_MUST_UPGRADE) { throw new EAnpExUpgradeKwm(); } else if (msg.Type != KAnp.KANP_RES_OK) { throw new Exception(msg.Elements[1].String); } else if (msg.Minor < KAnp.LastCompMinor) { throw new Exception("The KCD at " + k.KcdID.Host + " is too old and needs to be upgraded."); } else { HandleConnectedKcd(k, Math.Min(msg.Minor, KAnp.Minor)); } } else { m_toWmAnpMsgList.Add(new KcdAnpMsg(msg, k.KcdID)); } }
/// <summary> /// Handle a message received from a KAS. /// </summary> private void ProcessIncomingAppServerMessage(TbxAppServer k, AnpMsg msg) { if (k.ConnStatus == TcmAppServerConStatus.RoleReply) { if (msg.Type == KAnpType.KANP_RES_FAIL_MUST_UPGRADE) { throw new Exception("The KWM is too old, it needs to be upgraded to communicate with " + k.KasID.Host + " which has protocol version " + msg.Minor); } else if (msg.Type != KAnpType.KANP_RES_OK) { throw new Exception(msg.Elements[1].String); } else if (msg.Minor < KAnp.LastCompMinor) { throw new Exception("The KCD at " + k.KasID.Host + " is too old and needs to be upgraded."); } else { HandleConnectedAppServer(k, Math.Min(msg.Minor, KAnp.Minor)); } } else { m_toWmAnpMsgList.Add(new TcmAnpMsg(msg, k.KasID)); } }
public KasQuery(AnpMsg cmd, Object[] metaData, KasQueryDelegate callback) { Debug.Assert(cmd.ID != 0); Cmd = cmd; MetaData = metaData; Callback = callback; }
/// <summary> /// Handle an ANP event. /// </summary> public KwsAnpEventStatus HandleAnpEvent(AnpMsg msg) { // Dispatch. UInt32 type = msg.Type; if (type == KAnp.KANP_EVT_KWS_CREATED) { return(HandleKwsCreatedEvent(msg)); } else if (type == KAnp.KANP_EVT_KWS_INVITED) { return(HandleKwsInvitationEvent(msg)); } else if (type == KAnp.KANP_EVT_KWS_USER_REGISTERED) { return(HandleUserRegisteredEvent(msg)); } else if (type == KAnp.KANP_EVT_KWS_DELETED) { return(HandleKwsDeletedEvent()); } else if (type == KAnp.KANP_EVT_KWS_LOG_OUT) { return(HandleKwsLogOut(msg)); } else if (type == KAnp.KANP_EVT_KWS_PROP_CHANGE) { return(HandleKwsPropChange(msg)); } else { return(KwsAnpEventStatus.Unprocessed); } }
private KwsAnpEventStatus HandleKwsCreatedEvent(AnpMsg msg) { KwsCredentials creds = m_kws.Cd.Credentials; // Add the creator to the user list. KwsUser user = new KwsUser(); user.UserID = msg.Elements[2].UInt32; user.InvitationDate = msg.Elements[1].UInt64; user.AdminName = msg.Elements[3].String; user.EmailAddress = msg.Elements[4].String; user.OrgName = msg.Elements[msg.Minor <= 2 ? 7 : 5].String; user.AdminFlag = true; user.ManagerFlag = true; user.RegisterFlag = true; m_kws.Cd.UserInfo.UserTree[user.UserID] = user; // Update the workspace data. if (msg.Minor <= 2) { creds.SecureFlag = true; } if (msg.Minor >= 3) { creds.KwsName = msg.Elements[6].String; creds.Flags = msg.Elements[7].UInt32; creds.KwmoAddress = msg.Elements[8].String; } m_kws.OnStateChange(WmStateChange.Permanent); return(KwsAnpEventStatus.Processed); }
/// <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> /// Send a transient event to all open channels. /// </summary> public static void SendTransientEvent(AnpMsg evt) { foreach (WmEAnpChannel wc in GetChannelArray()) { wc.Channel.SendEvt(evt); } }
/// <summary> /// Create a new KCD ANP command message having the minor version and /// type specified and a unique ID. The workspace ID is inserted as the /// first element of the command. /// </summary> public AnpMsg NewKcdCmd(UInt32 type) { AnpMsg msg = Wm.NewKcdCmd(Kcd.MinorVersion, type); msg.AddUInt64(Cd.Credentials.ExternalID); return(msg); }
/// <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> /// Parse the binary ticket specified. The base 64 ticket field is not /// modified. /// </summary> public void FromBinaryTicket(byte[] binaryTicket) { BinaryTicket = binaryTicket; if (BinaryTicket.Length < 38) { throw new Exception("invalid ticket length"); } int payloadLength = BinaryTicket[37]; payloadLength |= (BinaryTicket[36] << 8); payloadLength |= (BinaryTicket[35] << 16); payloadLength |= (BinaryTicket[34] << 24); byte[] strippedTicket = new byte[payloadLength]; for (int i = 0; i < payloadLength; i++) { strippedTicket[i] = BinaryTicket[i + 38]; } AnpTicket = new AnpMsg(); AnpTicket.Elements = AnpMsg.ParsePayload(strippedTicket); UserName = AnpTicket.Elements[0].String; EmailAddr = AnpTicket.Elements[1].String; KcdAddr = AnpTicket.Elements[2].String; KcdPort = (UInt16)AnpTicket.Elements[3].UInt32; KpsKeyID = AnpTicket.Elements[4].UInt64; }
/// <summary> /// Post a KCD command. /// </summary> public KcdQuery PostKcdCmd(AnpMsg cmd, KcdQueryDelegate callback) { KcdQuery query = new KcdQuery(cmd, callback, Kcd, this); Wm.PostKcdQuery(query); return(query); }
protected override void PrepareCmd(AnpMsg cmd) { cmd.Type = (uint)KAnp.KANP_CMD_PB_ACCEPT_CHAT; cmd.AddUInt64(RequestID); cmd.AddUInt32(UserID); cmd.AddUInt32(UserID); }
/// <summary> /// Handle an ANP event received from the KCD. /// </summary> public void HandleKcdEvent(AnpMsg msg) { KLogging.Log("HandleAnpEvent() in kws " + m_kws.InternalID + ", status " + m_cd.MainStatus); // This is a permanent event. if (msg.ID > 0) { // Logic problem detected. if (msg.ID < m_ks.LastReceivedEventId) { BlameKcd(new Exception("received ANP event with bogus ID")); return; } // Store the event in the database. Mark it as unprocessed. m_kws.StoreKAnpEventInDb(msg, KwsAnpEventStatus.Unprocessed); // Update the information about the events. m_ks.NbUnprocessedEvent++; m_ks.LastReceivedEventId = msg.ID; m_kws.OnStateChange(WmStateChange.Permanent); } // If this is a transient event or the only unprocessed event, // dispatch it right away if possible. This is done so that single // incoming events are processed very quickly instead of waiting // for a future workspace state machine run. if (msg.ID == 0 || (m_ks.NbUnprocessedEvent == 1 && !WmKcdState.QuenchFlag && m_kws.IsOfflineCapable())) { DispatchKcdEvent(msg); } }
/// <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); } }
public override void Parse(AnpMsg cmd) { int i = 0; KwsId = cmd.Elements[i++].UInt64; UserID = cmd.Elements[i++].UInt32; RequestID = cmd.Elements[i++].UInt64; }
/// <summary> /// Create an ANP message that can be sent to the server in VNC mode. /// </summary> public AnpMsg CreateAnpMsg(UInt32 type) { AnpMsg m = new AnpMsg(); m.Minor = KAnp.Minor; m.Type = type; return(m); }
/// <summary> /// Get an AnpMsg. /// </summary> public AnpMsg GetMsg() { Debug.Assert(transport.DoneReceiving); AnpMsg msg = transport.GetRecv(); transport.BeginRecv(); return(msg); }
public KcdQuery(AnpMsg cmd, KcdQueryDelegate callback, WmKcd kcd, Workspace kws) { Debug.Assert(cmd.ID != 0); Cmd = cmd; Callback = callback; Kcd = kcd; Kws = kws; }
/////////////////////// // Command handlers. // /////////////////////// /// <summary> /// Export workspaces. /// </summary> private void HandleExportKws(AnpMsg cmd, AnpMsg res) { int i = 0; UInt64 kwsID = cmd.Elements[i++].UInt64; String destPath = cmd.Elements[i++].String; WmKwsImportExport.ExportKws(destPath, kwsID); }
private KwsAnpEventStatus HandleKwsLogOut(AnpMsg msg) { m_kws.Cd.KcdState.LoginResult = m_kws.KcdLoginHandler.TranslateKcdLoginStatusCode(msg.Elements[2].UInt32); m_kws.Cd.KcdState.LoginResultString = msg.Elements[3].String; m_kws.OnStateChange(WmStateChange.Permanent); m_kws.Sm.RequestTaskSwitch(KwsTask.WorkOffline); return(KwsAnpEventStatus.Processed); }
public override void Parse(AnpMsg cmd) { int i = 0; KwsId = cmd.Elements[i++].UInt64; ChannelID = cmd.Elements[i++].UInt32; Msg = cmd.Elements[i++].String; }
public override void Parse(AnpMsg cmd) { int i = 0; FreemiumFlag = cmd.Elements[i++].UInt32 > 0; KpsAddr = cmd.Elements[i++].String; KpsUserName = cmd.Elements[i++].String; KpsUserPwd = cmd.Elements[i++].String; }
/// <summary> /// Dispatch an ANP event to the appropriate handler. /// </summary> private KwsAnpEventStatus DispatchAnpEventToHandler(AnpMsg msg) { // If this event version is not supported, disable the workspace. if (msg.Minor > KAnp.Minor) { RequestTaskSwitch(KwsTask.Stop, new EAnpExUpgradeKwm()); return(KwsAnpEventStatus.Unprocessed); } // Dispatch to the appropriate handler. try { UInt32 ns = KAnp.GetNsFromType(msg.Type); KwsAnpEventStatus status = KwsAnpEventStatus.Unprocessed; // Non-application-specific event. if (ns == KAnp.KANP_NS_KWS) { status = m_kws.KcdEventHandler.HandleAnpEvent(msg); } // Application-specific event. else { // Trivially process whiteboard events. if (ns == KAnp.KANP_NS_WB) { return(KwsAnpEventStatus.Processed); } // Locate the application. KwsApp app = m_kws.GetApp(ns); if (app == null) { throw new Exception("unknown application of type " + ns); } // Dispatch. status = app.HandleAnpEvent(msg); } // Throw an exception if we cannot process an event that we // should have been able to process. if (status == KwsAnpEventStatus.Unprocessed && m_kws.IsOfflineCapable()) { throw new Exception("failed to process KCD event"); } return(status); } catch (Exception ex) { HandleMiscFailure(ex); return(KwsAnpEventStatus.Unprocessed); } }
/// <summary> /// Import workspaces. /// </summary> private void HandleImportKws(AnpMsg cmd, AnpMsg res) { int i = 0; String credString = cmd.Elements[i++].String; XmlDocument doc = new XmlDocument(); doc.LoadXml(credString); WmKwsImportExport.ImportKwsListFromXmlDoc(doc); }
/// <summary> /// Create a new KCD ANP command message having the minor version and /// type specified and a unique ID. /// </summary> public static AnpMsg NewKcdCmd(UInt32 minorVersion, UInt32 type) { AnpMsg msg = new AnpMsg(); msg.Major = KAnp.Major; msg.Minor = minorVersion; msg.Type = type; msg.ID = WmKcdState.NextKcdCmdID++; return(msg); }
public override void Parse(AnpMsg cmd) { int i = 0; UInt32 nbRec = cmd.Elements[i++].UInt32; for (UInt32 j = 0; j < nbRec; j++) { EmailList.Add(cmd.Elements[i++].String); } }