Esempio n. 1
0
 /// <summary>
 /// This is the default construct that sets or creates the policy object depending on whether it is passed in to the constructor.
 /// </summary>
 /// <param name="policy">The optional policy class.</param>
 /// <param name="name">The optional name for the component.</param>
 public ServiceHandlerContainer(Policy policy = null, string name = null) : base(policy, name)
 {
     Authentication = new ServiceHandlerCollection <IServiceHandlerAuthentication>(OnAuthenticationAdd);
     Compression    = new ServiceHandlerCollection <IServiceHandlerCompression>();
     Encryption     = new ServiceHandlerCollection <IServiceHandlerEncryption>();
     Serialization  = new ServiceHandlerCollection <IServiceHandlerSerialization>();
 }
        /// <summary>
        /// Tries to compress the outgoing holder.
        /// </summary>
        /// <param name="collection">The collection.</param>
        /// <param name="blob">The binary array.</param>
        /// <returns>Returns true if the Content is serialized correctly to a binary blob.</returns>
        public static O DeserializeToObject <O>(this ServiceHandlerCollection <IServiceHandlerSerialization> collection, byte[] blob)
        {
            ServiceHandlerContext context = blob;

            if (collection.TryDeserialize(context))
            {
                return((O)context.Object);
            }

            throw new PayloadDeserializationException();
        }
        /// <summary>
        /// Tries to compress the outgoing holder.
        /// </summary>
        /// <param name="collection">The collection.</param>
        /// <param name="item">The item.</param>
        /// <returns>Returns true if the Content is serialized correctly to a binary blob.</returns>
        public static byte[] SerializeToBlob(this ServiceHandlerCollection <IServiceHandlerSerialization> collection, object item)
        {
            var context = ServiceHandlerContext.CreateWithObject(item);

            //context.ContentType = collection.
            if (collection.TrySerialize(context))
            {
                return(context.Blob);
            }

            throw new PayloadSerializationException();
        }
        /// <summary>
        /// Tries to compress the outgoing holder.
        /// </summary>
        /// <param name="collection">The collection.</param>
        /// <param name="holder">The holder.</param>
        /// <returns>Returns true if the Content is serialized correctly to a binary blob.</returns>
        public static bool TrySerialize(this ServiceHandlerCollection <IServiceHandlerSerialization> collection, ServiceHandlerContext holder)
        {
            string id;

            if (!ServiceHandlerContainer.ExtractContentType(holder, out id))
            {
                return(false);
            }

            IServiceHandlerSerialization sr = null;

            if (!collection.TryGet(id, out sr))
            {
                return(false);
            }

            return(sr.TrySerialize(holder));
        }
 /// <summary>
 /// Checks that a specific serializer is supported.
 /// </summary>
 /// <param name="collection">The collection.</param>
 /// <param name="holder">The holder.</param>
 /// <returns>Returns true when the holder ContentType is supported.</returns>
 public static bool SupportsSerializer(this ServiceHandlerCollection <IServiceHandlerSerialization> collection, ServiceHandlerContext holder)
 {
     return(collection.Contains(holder.ContentType));
 }
 /// <summary>
 /// Checks that a specific serializer is supported.
 /// </summary>
 /// <param name="collection">The collection.</param>
 /// <param name="mimetype">The mime type identifier for the serializer.</param>
 /// <returns>Returns true if the serializer is supported.</returns>
 public static bool SupportsSerializer(this ServiceHandlerCollection <IServiceHandlerSerialization> collection, string mimetype)
 {
     return(collection.Contains(mimetype));
 }