Ejemplo n.º 1
0
        public void RegisterSubclass(Type type)
        {
            TypeInfo typeInfo = type.GetTypeInfo();

            if (!typeof(IAVIMMessage).GetTypeInfo().IsAssignableFrom(typeInfo))
            {
                throw new ArgumentException("Cannot register a type that is not a implementation of IAVIMMessage");
            }
            var className = GetClassName(type);
            var typeInt   = GetTypeInt(type);

            try
            {
                mutex.EnterWriteLock();
                ConstructorInfo constructor = type.FindConstructor();
                if (constructor == null)
                {
                    throw new ArgumentException("Cannot register a type that does not implement the default constructor!");
                }
                var classInfo = new FreeStyleMessageClassInfo(type, constructor);
                if (typeInt != 0)
                {
                    classInfo.TypeInt = typeInt;
                }
                registeredInterfaces[className] = classInfo;
            }
            finally
            {
                mutex.ExitWriteLock();
            }
        }
        public IAVIMMessage Instantiate(string msgStr, IDictionary <string, object> buildInData)
        {
            FreeStyleMessageClassInfo info = null;

            mutex.EnterReadLock();
            var reverse = registeredInterfaces.Values.Reverse();

            foreach (var subInterface in reverse)
            {
                if (subInterface.Validate(msgStr))
                {
                    info = subInterface;
                    break;
                }
            }
            mutex.ExitReadLock();
            var rtn = info != null?info.Instantiate(msgStr) : new AVIMMessage();

            if (buildInData.ContainsKey("timestamp"))
            {
                long timestamp = 0;
                if (long.TryParse(buildInData["timestamp"].ToString(), out timestamp))
                {
                    rtn.ServerTimestamp = timestamp;
                }
            }
            if (buildInData.ContainsKey("ackAt"))
            {
                long ackAt = 0;
                if (long.TryParse(buildInData["ackAt"].ToString(), out ackAt))
                {
                    rtn.RcpTimestamp = ackAt;
                }
            }
            if (buildInData.ContainsKey("from"))
            {
                rtn.FromClientId = buildInData["from"].ToString();
            }
            if (buildInData.ContainsKey("msgId"))
            {
                rtn.Id = buildInData["msgId"].ToString();
            }
            if (buildInData.ContainsKey("cid"))
            {
                rtn.ConversationId = buildInData["cid"].ToString();
            }
            if (buildInData.ContainsKey("fromPeerId"))
            {
                rtn.FromClientId = buildInData["fromPeerId"].ToString();
            }
            if (buildInData.ContainsKey("id"))
            {
                rtn.Id = buildInData["id"].ToString();
            }
            rtn.Deserialize(msgStr);
            return(rtn);
        }
Ejemplo n.º 3
0
        public IDictionary <String, String> GetPropertyMappings(String className)
        {
            FreeStyleMessageClassInfo info = null;

            mutex.EnterReadLock();
            registeredInterfaces.TryGetValue(className, out info);
            if (info == null)
            {
                registeredInterfaces.TryGetValue(messageClassName, out info);
            }
            mutex.ExitReadLock();

            return(info.PropertyMappings);
        }
Ejemplo n.º 4
0
        public IAVIMMessage Instantiate(string msgStr, IDictionary <string, object> buildInData)
        {
            FreeStyleMessageClassInfo info = null;

            mutex.EnterReadLock();
            bool bin = false;

            if (buildInData.ContainsKey("bin"))
            {
                bool.TryParse(buildInData["bin"].ToString(), out bin);
            }

            if (bin)
            {
                var binMessage = new AVIMBinaryMessage();
                this.DecodeProperties(binMessage, buildInData);
                return(binMessage);
            }

            var reverse = registeredInterfaces.Values.Reverse();

            foreach (var subInterface in reverse)
            {
                if (subInterface.Validate(msgStr))
                {
                    info = subInterface;
                    break;
                }
            }

            mutex.ExitReadLock();

            var message = info != null?info.Instantiate(msgStr) : new AVIMMessage();

            this.DecodeProperties(message, buildInData);

            message.Deserialize(msgStr);

            return(message);
        }
Ejemplo n.º 5
0
 public int GetTypeInt(Type type)
 {
     return(type == typeof(AVIMTypedMessage) ? 0 : FreeStyleMessageClassInfo.GetTypedInteger(type.GetTypeInfo()));
 }
Ejemplo n.º 6
0
 public String GetClassName(Type type)
 {
     return(type == typeof(IAVIMMessage)
       ? messageClassName
       : FreeStyleMessageClassInfo.GetMessageClassName(type.GetTypeInfo()));
 }
Ejemplo n.º 7
0
        public IAVIMMessage Instantiate(string msgStr, IDictionary <string, object> buildInData)
        {
            FreeStyleMessageClassInfo info = null;

            mutex.EnterReadLock();
            var reverse = registeredInterfaces.Values.Reverse();

            foreach (var subInterface in reverse)
            {
                if (subInterface.Validate(msgStr))
                {
                    info = subInterface;
                    break;
                }
            }
            mutex.ExitReadLock();

            var message = info != null?info.Instantiate(msgStr) : new AVIMMessage();

            long timestamp;

            if (buildInData.ContainsKey("timestamp"))
            {
                if (long.TryParse(buildInData["timestamp"].ToString(), out timestamp))
                {
                    message.ServerTimestamp = timestamp;
                }
            }
            long ackAt;

            if (buildInData.ContainsKey("ackAt"))
            {
                if (long.TryParse(buildInData["ackAt"].ToString(), out ackAt))
                {
                    message.RcpTimestamp = ackAt;
                }
            }

            if (buildInData.ContainsKey("from"))
            {
                message.FromClientId = buildInData["from"].ToString();
            }
            if (buildInData.ContainsKey("msgId"))
            {
                message.Id = buildInData["msgId"].ToString();
            }
            if (buildInData.ContainsKey("cid"))
            {
                message.ConversationId = buildInData["cid"].ToString();
            }
            if (buildInData.ContainsKey("fromPeerId"))
            {
                message.FromClientId = buildInData["fromPeerId"].ToString();
            }
            if (buildInData.ContainsKey("id"))
            {
                message.Id = buildInData["id"].ToString();
            }

            if (buildInData.ContainsKey("mentionPids"))
            {
                message.MentionList = AVDecoder.Instance.DecodeList <string>(buildInData["mentionPids"]);
            }

            bool mentionAll;

            if (buildInData.ContainsKey("mentionAll"))
            {
                if (bool.TryParse(buildInData["mentionAll"].ToString(), out mentionAll))
                {
                    message.MentionAll = mentionAll;
                }
            }

            message.Deserialize(msgStr);
            return(message);
        }