예제 #1
0
 /// <summary>
 /// Validates the attachment.
 /// </summary>
 private DimeAttachment CheckAttachment(DimeAttachment attachment)
 {
     Debug.Assert(attachment != null);
     if (attachment.Type == null || attachment.Stream == null || !attachment.Stream.CanRead)
     {
         throw new Exception("DimeAttachment requires a valid type and a readable stream");
     }
     return(attachment);
 }
예제 #2
0
        // Lookup the referenced attachment in the attachment table by id
        // and copy over the additional attachment data.
        private void CopyFieldsFromInputAttachment(DimeAttachment attachment)
        {
            if (attachment == null)
            {
                return;
            }

            DimeAttachment fromAttachment = (DimeAttachment)inputAttachments[attachment.Id];

            attachment.Type       = fromAttachment.Type;
            attachment.TypeFormat = fromAttachment.TypeFormat;
            attachment.Stream     = fromAttachment.Stream;
        }
예제 #3
0
 void AddAttachmentValue(Type t, object o)
 {
     if (t.IsArray)
     {
         DimeAttachment[] atts = (DimeAttachment[])o;
         for (int i = 0; i < atts.Length; i++)
         {
             CheckAttachment(atts[i]);
             outputAttachments.Add(atts[i]);
         }
     }
     else
     {
         DimeAttachment a = (DimeAttachment)o;
         CheckAttachment(a);
         outputAttachments.Add(a);
     }
 }
예제 #4
0
        /// <summary>
        /// Encapsulates the SOAP message into a DIME message.  The stored attachments are added as DIME records.
        /// If an exception has been thrown, the soap message containing the exception is
        /// not encapsulated.
        /// </summary>
        private void AfterSerialize(SoapMessage message)
        {
            newStream.Position = 0;
            //if response only, then not on request
            if (dimeDir != DimeDir.Response && message.Exception == null)
            {
                DimeWriter dw            = new DimeWriter(networkStream);
                int        contentLength = (newStream.CanSeek && newStream.Length <= DefaultBufferSize) ? (int)newStream.Length : -1;
                DimeRecord record        = null;
                if (outputAttachments.Count > 0)
                {
                    record = dw.NewRecord(id, SoapContentType, TypeFormatEnum.AbsoluteUri, contentLength);
                }
                else
                {
                    record = dw.LastRecord(id, SoapContentType, TypeFormatEnum.AbsoluteUri, contentLength);
                }
                BinaryCopy(newStream, record.BodyStream);

                //add attachments
                for (int i = 0; i < outputAttachments.Count; i++)
                {
                    DimeAttachment attachment = (DimeAttachment)outputAttachments[i];
                    contentLength = attachment.Stream.CanSeek ? (int)attachment.Stream.Length : -1;
                    if (i == (outputAttachments.Count - 1))
                    {
                        record = dw.LastRecord(attachment.Id, attachment.Type, attachment.TypeFormat, contentLength);
                    }
                    else
                    {
                        record = dw.NewRecord(attachment.Id, attachment.Type, attachment.TypeFormat, contentLength);
                    }
                    BinaryCopy(attachment.Stream, record.BodyStream);
                }
                dw.Close();
            }
            else
            {
                BinaryCopy(newStream, networkStream);
            }
        }
예제 #5
0
        /// <summary>
        /// Retrieves the SOAP message from the DIME message.  DIME attachments
        /// are removed from the stream and stored for future use by the AfterDeserialize
        /// method.
        /// </summary>
        private void BeforeDeserialize(SoapMessage message)
        {
            if (message.ContentType == DimeContentType)
            {
                contentType      = message.ContentType;
                inputAttachments = new Hashtable();

                DimeReader dr     = new DimeReader(networkStream);
                DimeRecord record = dr.ReadRecord();
                if (record.Type != SoapContentType)
                {
                    throw new Exception(String.Format("Expected content type '{0}' in record containing SOAP payload.", SoapContentType));
                }
                message.ContentType = "text/xml";
                BinaryCopy(record.BodyStream, newStream);
                record.Close();

                //get attachments
                while ((record = dr.ReadRecord()) != null)
                {
                    //OutOfMemoryException
                    Stream stream = new MemoryStream(record.Chunked ? DefaultBufferSize : record.ContentLength);
                    BinaryCopy(record.BodyStream, stream);
                    stream.Position = 0;
                    DimeAttachment attachment = new DimeAttachment(record.Id.ToString(), record.Type, record.TypeFormat, stream);
                    inputAttachments.Add(attachment.Id, attachment);
                    record.Close();
                }
                dr.Close();
            }
            else
            {
                BinaryCopy(networkStream, newStream);
            }
            newStream.Position = 0;
        }
예제 #6
0
        /// <summary>
        /// Sets the method's DimeAttachment parameters and return value to the stored values.
        /// </summary>
        private void AfterDeSerialize(SoapMessage message)
        {
            if (contentType == DimeContentType)
            {
                if (message.GetType() != typeof(SoapClientMessage))
                {
                    throw new Exception("DIME library not for server side processing");

                    /*
                     * // check for unreferenced attachments in the container
                     * IDimeAttachmentContainer container = ((SoapServerMessage)message).Server as IDimeAttachmentContainer;
                     * if (container != null)
                     * {
                     *      if (container.RequestAttachments == null)
                     *              throw new InvalidOperationException("The IDimeAttachmentContainer.RequestAttachments property must not be null.");
                     *      container.RequestAttachments.AddRange(inputAttachments.Values);
                     * }
                     * else
                     * {
                     *      // check for referenced attachments in the parameter list
                     *      ParameterInfo[] parameters = message.MethodInfo.InParameters;
                     *      for (int i = 0; i < parameters.Length; i++)
                     *      {
                     *              Type type = parameters[i].ParameterType;
                     *              if (type == typeof(DimeAttachment))
                     *              {
                     *                      // only the id is in the SOAP body so copy over other attachment fields into
                     *                      // the DimeAttachment object created during deserialization
                     *                      CopyFieldsFromInputAttachment((DimeAttachment)message.GetInParameterValue(i));
                     *              }
                     *              else if (type == typeof(DimeAttachment[]))
                     *              {
                     *                      CopyFieldsFromInputAttachment((DimeAttachment[])message.GetInParameterValue(i));
                     *              }
                     *      }
                     * }
                     */
                }
                else                 //client side
                {
                    // check for unreferenced attachments in the container
                    IDimeAttachmentContainer container = ((SoapClientMessage)message).Client as IDimeAttachmentContainer;
                    if (container != null)
                    {
                        if (container.ResponseAttachments == null)
                        {
                            throw new InvalidOperationException("The IDimeAttachmentContainer.ResponseAttachments property must not be null.");
                        }
                        container.ResponseAttachments.AddRange(inputAttachments.Values);
                    }
                    else
                    {
                        // check for referenced attachments in the out parameter list
                        ParameterInfo[] parameters = message.MethodInfo.OutParameters;
                        for (int i = 0; i < parameters.Length; i++)
                        {
                            // Note, using the as operator to test the type since out params have a unique type
                            object         outValue = message.GetOutParameterValue(i);
                            DimeAttachment a        = outValue as DimeAttachment;
                            if (a != null)
                            {
                                CopyFieldsFromInputAttachment(a);
                            }
                            else
                            {
                                DimeAttachment[] aa = outValue as DimeAttachment[];
                                if (aa != null)
                                {
                                    CopyFieldsFromInputAttachment(aa);
                                }
                            }
                        }
                        Type returnType = message.MethodInfo.ReturnType;
                        if (returnType == typeof(DimeAttachment))
                        {
                            CopyFieldsFromInputAttachment((DimeAttachment)message.GetReturnValue());
                        }
                        else if (returnType == typeof(DimeAttachment[]))
                        {
                            CopyFieldsFromInputAttachment((DimeAttachment[])message.GetReturnValue());
                        }
                    }
                }
            }
        }
 public int IndexOf(DimeAttachment attachment)
 {
     return(List.IndexOf(attachment));
 }
 public void Remove(DimeAttachment attachment)
 {
     List.Remove(attachment);
 }
 public void Add(DimeAttachment attachment)
 {
     List.Add(attachment);
 }
 public void Remove(DimeAttachment attachment) {
     List.Remove(attachment);
 }
 public int IndexOf(DimeAttachment attachment) {
     return List.IndexOf(attachment);
 }
 public void CopyTo(DimeAttachment[] attachments, int index) {
     List.CopyTo(attachments, index);
 }        
 public void Add(DimeAttachment attachment) {
     List.Add(attachment);            
 }