Ejemplo n.º 1
0
        /// <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);
        }
Ejemplo n.º 2
0
Archivo: Vnc.cs Proyecto: tmbx/kwm-ng
        /// <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);
        }
Ejemplo n.º 3
0
        /// <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);
            }
        }