Exemplo n.º 1
0
        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;
        }
Exemplo n.º 2
0
Arquivo: WmKcd.cs Projeto: tmbx/kwm-ng
 public KcdQuery(AnpMsg cmd, KcdQueryDelegate callback, WmKcd kcd, Workspace kws)
 {
     Debug.Assert(cmd.ID != 0);
     Cmd = cmd;
     Callback = callback;
     Kcd = kcd;
     Kws = kws;
 }
Exemplo n.º 3
0
        public void HandleIncomingQuery(Object sender, EAnpIncomingQueryEventArgs args)
        {
            Tell("Incoming query received");
            EAnpIncomingQuery q = args.Query;
            if (!q.IsPending()) return;
            q.OnCancellation += new EventHandler(OnQueryCancellation);

            AnpMsg m = new AnpMsg();
            m.Type = (uint)EAnpRes.OK;
            q.Reply(m);
        }
Exemplo n.º 4
0
 /// <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;
 }
Exemplo n.º 5
0
Arquivo: Chat.cs Projeto: tmbx/kwm-ng
        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;
        }
Exemplo n.º 6
0
 public override void Parse(AnpMsg cmd)
 {
     int i = 0;
     KwsID = cmd.Elements[i++].UInt64;
     Task = (KwsTask)cmd.Elements[i++].UInt32;
 }
Exemplo n.º 7
0
 public override void Parse(AnpMsg cmd)
 {
     int i = 0;
     KwsId = cmd.Elements[i++].UInt64;
     UserID = cmd.Elements[i++].UInt32;
     RequestID = cmd.Elements[i++].UInt64;
 }
Exemplo n.º 8
0
 /// <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);
 }
Exemplo n.º 9
0
        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;
            }
        }
Exemplo n.º 10
0
 public override void Parse(AnpMsg cmd)
 {
     int i = 0;
     KwsId = cmd.Elements[i++].UInt64;
     KcdSendEmailFlag = cmd.Elements[i++].UInt32 > 0;
     InvitationMsg = cmd.Elements[i++].String;
     UInt32 nbUser = cmd.Elements[i++].UInt32;
     for (UInt32 j = 0; j < nbUser; j++)
     {
         User u = new User();
         UserList.Add(u);
         u.UserName = cmd.Elements[i++].String;
         u.EmailAddress = cmd.Elements[i++].String;
         u.KeyID = cmd.Elements[i++].UInt64;
         u.OrgName = cmd.Elements[i++].String;
         u.Pwd = cmd.Elements[i++].String;
     }
 }
Exemplo n.º 11
0
 public override void Parse(AnpMsg cmd)
 {
     int i = 0;
     Creds.KwsName = cmd.Elements[i++].String;
     Creds.Flags = cmd.Elements[i++].UInt32;
 }
Exemplo n.º 12
0
        /// <summary>
        /// Store the KAnp event specified with the status specified.
        /// </summary>
        public void StoreKAnpEvent(UInt64 kwsID, AnpMsg msg, KwsAnpEventStatus status)
        {
            try
            {
                DbCommand cmd = m_db.GetCmd("INSERT INTO kanp_events (kws_id, evt_id, evt_data, status) VALUES (?, ?, ?, ?);");
                m_db.AddParamToCmd(cmd, kwsID);
                m_db.AddParamToCmd(cmd, msg.ID);
                m_db.AddParamToCmd(cmd, msg.ToByteArray(true));
                m_db.AddParamToCmd(cmd, status);
                cmd.ExecuteNonQuery();
            }

            catch (Exception ex)
            {
                KBase.HandleException(ex, true);
            }
        }
Exemplo n.º 13
0
 /// <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;
 }
Exemplo n.º 14
0
        /// <summary>
        /// Dispatch an KCD event and update the state as needed.
        /// </summary>
        private void DispatchKcdEvent(AnpMsg msg)
        {
            // Dispatch the event to the appropriate handler.
            KwsAnpEventStatus newStatus = DispatchAnpEventToHandler(msg);

            // For quenching purposes we assume the event was processed.
            WmSm.HandleKcdEventProcessed();

            // If the ANP event has been processed, update its entry in the
            // database and the catch up state as required.
            if (newStatus == KwsAnpEventStatus.Processed)
            {
                if (msg.ID > 0)
                {
                    Debug.Assert(m_ks.NbUnprocessedEvent > 0);
                    m_kws.UpdateKAnpEventStatusInDb(msg.ID, KwsAnpEventStatus.Processed);
                    m_ks.NbUnprocessedEvent--;
                    UpdateKcdEventUpToDateState();
                    m_kws.OnStateChange(WmStateChange.Permanent);
                }
            }
        }
Exemplo n.º 15
0
        /// <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;
            }
        }
Exemplo n.º 16
0
 public override void Parse(AnpMsg cmd)
 {
     int i = 0;
     KwsId = cmd.Elements[i++].UInt64;
     ChannelID = cmd.Elements[i++].UInt32;
     Msg = cmd.Elements[i++].String;
 }
Exemplo n.º 17
0
 protected override void PrepareCmd(AnpMsg cmd)
 {
     cmd.Type = (uint)KAnp.KANP_CMD_CHAT_MSG;
     cmd.AddUInt32(ChannelID);
     cmd.AddString(Msg);
 }
Exemplo n.º 18
0
 /// <summary>
 /// Helper method for queries fetching an event.
 /// </summary>
 private AnpMsg GetEventFromQuery(String s)
 {
     Object res = m_db.GetCmd(s).ExecuteScalar();
     if (res == null) return null;
     AnpMsg m = new AnpMsg();
     m.FromByteArray((byte[])res, true);
     return m;
 }
Exemplo n.º 19
0
 protected override void FormatSuccessReply(AnpMsg m)
 {
     m.Type = (uint)EAnpRes.CreateKws;
     m.AddUInt64(Kws.InternalID);
 }
Exemplo n.º 20
0
 /// <summary>
 /// Fetch at most 'limit' EAnp events from the database, starting at 
 /// evtID.
 /// </summary>
 public List<AnpMsg> FetchEAnpEvents(UInt64 kwsID, UInt64 evtID, UInt32 limit)
 {
     String s = "SELECT evt_data FROM eanp_events WHERE kws_id = " + kwsID +
                " AND evt_id > " + evtID + " ORDER BY evt_id LIMIT " + limit + ";";
     List<AnpMsg> res = new List<AnpMsg>();
     DbDataReader reader = m_db.GetCmd(s).ExecuteReader();
     while (reader.Read())
     {
         AnpMsg m = new AnpMsg();
         m.FromByteArray((byte[])reader.GetValue(0), true);
         res.Add(m);
     }
     return res;
 }
Exemplo n.º 21
0
 protected override void FormatSuccessReply(AnpMsg m)
 {
     m.Type = (uint)EAnpRes.InviteKws;
     m.AddString(Wleu);
     m.AddUInt32((uint)UserList.Count);
     foreach (User u in UserList)
     {
         m.AddString(u.EmailAddress);
         m.AddString(u.Url);
         m.AddString(u.Error);
     }
 }
Exemplo n.º 22
0
Arquivo: EAnp.cs Projeto: tmbx/etkwm
        /// <summary>
        /// Convert the EAnp elements specified to a EAnp exception. This is
        /// used to deserialize EAnp exceptions stored in an ANP message.
        /// </summary>
        public static EAnpException FromEAnpMsg(AnpMsg m, int offset)
        {
            try
            {
                EAnpFailType t = (EAnpFailType)m.Elements[offset++].UInt32;
                String s = m.Elements[offset++].String;

                if (t == EAnpFailType.Generic) return new EAnpExGeneric(s);
                else if (t == EAnpFailType.Cancelled) return new EAnpExCancelled();
                else if (t == EAnpFailType.Interrupted) return new EAnpExInterrupted();
                else if (t == EAnpFailType.Concurrent) return new EAnpExConcurrent();
                else if (t == EAnpFailType.KcdConn) return new EAnpExKcdConn();
                else if (t == EAnpFailType.EAnpConn) return new EAnpExEAnpConn();
                else if (t == EAnpFailType.InvalidKpsConfig) return new EAnpExInvalidKpsConfig();
                else if (t == EAnpFailType.InvalidKwsLoginPwd) return new EAnpExInvalidKwsLoginPwd();
                else if (t == EAnpFailType.PermDenied) return new EAnpExPermDenied(s);
                else if (t == EAnpFailType.QuotaExceeded)
                {
                    EAnpQuotaType qt = (EAnpQuotaType)m.Elements[offset++].UInt32;
                    return new EAnpExQuotaExceeded(qt, s);
                }
                else if (t == EAnpFailType.UpgradeKwm) return new EAnpExUpgradeKwm();
                else return new EAnpExGeneric("unmapped exception");
            }

            catch (Exception)
            {
                return new EAnpExGeneric("ill formated exception message");
            }
        }
Exemplo n.º 23
0
 protected override void PrepareCmd(AnpMsg cmd)
 {
     cmd.Type = (uint)KAnp.KANP_CMD_KWS_INVITE_KWS;
     cmd.AddString(InvitationMsg);
     cmd.AddUInt32((UInt32)UserList.Count);
     foreach (User u in UserList)
     {
         cmd.AddString(u.UserName);
         cmd.AddString(u.EmailAddress);
         cmd.AddUInt64(u.KeyID);
         cmd.AddString(u.OrgName);
         cmd.AddString(u.Pwd);
         cmd.AddUInt32(Convert.ToUInt32(KcdSendEmailFlag));
     }
 }
Exemplo n.º 24
0
Arquivo: EAnp.cs Projeto: tmbx/etkwm
        /// <summary>
        /// Convert the KAnp elements specified to a EAnp exception.
        /// </summary>
        public static EAnpException FromKAnpFailure(AnpMsg m, int offset)
        {
            try
            {
                UInt32 t = m.Elements[offset++].UInt32;
                String s = m.Elements[offset++].String;

                if (t == KAnp.KANP_RES_FAIL_PERM_DENIED) return new EAnpExPermDenied(s);

                else if (t == KAnp.KANP_RES_FAIL_FILE_QUOTA_EXCEEDED)
                    return new EAnpExQuotaExceeded(EAnpQuotaType.PerKwsFileQuota, s);

                else if (t == KAnp.KANP_RES_FAIL_RESOURCE_QUOTA)
                {
                    EAnpQuotaType qt = EAnpQuotaType.Generic;
                    UInt32 u = m.Elements[offset++].UInt32;
                    if (u == KAnp.KANP_RESOURCE_QUOTA_NO_SECURE) qt = EAnpQuotaType.SecureKws;
                    return new EAnpExQuotaExceeded(qt, s);
                }

                else return new EAnpExGeneric(s);
            }

            catch (Exception)
            {
                return new EAnpExGeneric("ill formated failure message");
            }
        }
Exemplo n.º 25
0
 /// <summary>
 /// Prepare the command to send to the KCD.
 /// </summary>
 protected virtual void PrepareCmd(AnpMsg cmd)
 {
 }
Exemplo n.º 26
0
Arquivo: EAnp.cs Projeto: tmbx/etkwm
 /// <summary>
 /// Convert the KAnp reply specified to a EAnp exception.
 /// </summary>
 public static EAnpException FromKAnpReply(AnpMsg m)
 {
     if (m.Type != KAnp.KANP_RES_FAIL) return new EAnpExGeneric("unexpected server response");
     return FromKAnpFailure(m, 0);
 }
Exemplo n.º 27
0
 protected override void PrepareCmd(AnpMsg cmd)
 {
     cmd.Type = (uint)KAnp.KANP_CMD_PB_ACCEPT_CHAT;
     cmd.AddUInt64(RequestID);
     cmd.AddUInt32(UserID);
     cmd.AddUInt32(UserID);
 }
Exemplo n.º 28
0
Arquivo: EAnp.cs Projeto: tmbx/etkwm
 /// <summary>
 /// Add the content of this exception to the ANP message specified.
 /// This is used to serialize an EAnp exception to an ANP message.
 /// </summary>
 public virtual void Serialize(AnpMsg m)
 {
     m.AddUInt32((UInt32)FailType);
     m.AddString(Message);
 }
Exemplo n.º 29
0
 public override void Parse(AnpMsg cmd)
 {
     int i = 0;
     KwsID = cmd.Elements[i++].UInt64;
     Pwd = cmd.Elements[i++].String;
 }
Exemplo n.º 30
0
Arquivo: EAnp.cs Projeto: tmbx/etkwm
 public override void Serialize(AnpMsg m)
 {
     base.Serialize(m);
     m.AddUInt32((uint)QuotaType);
 }