/// <summary>
        /// Registers a type into provider
        /// </summary>
        public void Register(Type type)
        {
            ModelTypeAttribute attribute = type.GetCustomAttribute <ModelTypeAttribute>(false);
            string             code      = attribute != null ? attribute.TypeCode : type.Name;

            _typeCodes.Add(type, code);
            _codeTypes.Add(code, type);
        }
Esempio n. 2
0
        private WindsorModelBinderProvider InstanceModelBinderProvider(IKernel kernel)
        {
            IDictionary <Type, Type> modelBinderTypes = new Dictionary <Type, Type>();

            IHandler[] handlers = kernel.GetAssignableHandlers(typeof(IModelBinder));
            foreach (IHandler handler in handlers)
            {
                Type modelBinderType = handler.ComponentModel.Implementation;
                if (modelBinderType.IsAbstract || !modelBinderType.IsClass)
                {
                    continue;
                }
                ModelTypeAttribute modelTypeAttribute = modelBinderType.GetAttribute <ModelTypeAttribute>();
                if (modelTypeAttribute == null)
                {
                    throw new ArgumentException(Resources.Error.ModelTypeAttributeMissing.FormatWith(modelBinderType.FullName));
                }
                modelBinderTypes.Add(modelTypeAttribute.ModelType, modelBinderType);
            }
            return(new WindsorModelBinderProvider(kernel, modelBinderTypes));
        }
        /// <summary>
        /// Creates new websocket message and writes the model
        /// </summary>
        public WebSocketMessage Write(object model)
        {
            Type   type = model.GetType();
            string code;

            if (_typeCodes.ContainsKey(type))
            {
                code = _typeCodes[type];
            }
            else
            {
                ModelTypeAttribute attr = type.GetCustomAttribute <ModelTypeAttribute>();
                code = attr == null ? type.Name : attr.TypeCode;

                _typeCodes.Add(type, code);
                _codeTypes.Add(code, type);
            }

            string content = code + "|" + Serializer.Serialize(model);

            return(WebSocketMessage.FromString(content));
        }