/// <summary>
        /// Reads to the next node in the XML document, and updates the context accordingly.
        /// If node is RequestId, reads the contents and stores in RequestId property.
        /// </summary>
        /// <returns>
        /// True if a node was read, false if there are no more elements to read./
        /// </returns>
        public override bool Read()
        {
            bool result = base.Read();

            if (this.ResponseData.StatusCode == System.Net.HttpStatusCode.OK &&
                !_checkedForErrorResponse)
            {
                // Check for top level XML element "Error".
                // Few S3 operations like CopyObject, CopyPart and CompleteMultipartUpload
                // can return an HTTP 200 response with an error element.
                if (this.IsStartElement)
                {
                    if (this.TestExpression("Error", 1))
                    {
                        var errorResponse = new Amazon.S3.Model.Internal.MarshallTransformations.S3ErrorResponseUnmarshaller().Unmarshall(this);

                        var s3Exception = new Amazon.S3.AmazonS3Exception(
                            errorResponse.Message, null, errorResponse.Type, errorResponse.Code,
                            errorResponse.RequestId, this.ResponseData.StatusCode, errorResponse.Id2, errorResponse.AmzCfId);
                        s3Exception.Region = errorResponse.Region;

                        throw s3Exception;
                    }
                    _checkedForErrorResponse = true;
                }
            }
            return(result);
        }
示例#2
0
        public List <IFileEntry> List()
        {
            try
            {
                List <IFileEntry> lst = Connection.ListBucket(m_bucket, m_prefix);
                for (int i = 0; i < lst.Count; i++)
                {
                    ((FileEntry)lst[i]).Name = lst[i].Name.Substring(m_prefix.Length);

                    //Fix for a bug in Duplicati 1.0 beta 3 and earlier, where filenames are incorrectly prefixed with a slash
                    if (lst[i].Name.StartsWith("/") && !m_prefix.StartsWith("/"))
                    {
                        ((FileEntry)lst[i]).Name = lst[i].Name.Substring(1);
                    }
                }
                return(lst);
            }
            catch (Exception ex)
            {
                //Catch "non-existing" buckets
                Amazon.S3.AmazonS3Exception s3ex = ex as Amazon.S3.AmazonS3Exception;
                if (s3ex != null && (s3ex.StatusCode == System.Net.HttpStatusCode.NotFound || "NoSuchBucket".Equals(s3ex.ErrorCode)))
                {
                    throw new Interface.FolderMissingException(ex);
                }

                throw;
            }
        }
示例#3
0
        /// <summary>
        /// Reads to the next node in the XML document, and updates the context accordingly.
        /// If node is RequestId, reads the contents and stores in RequestId property.
        /// </summary>
        /// <returns>
        /// True if a node was read, false if there are no more elements to read./
        /// </returns>
        public override bool Read()
        {
            bool result = base.Read();
            if (this.ResponseData.StatusCode == System.Net.HttpStatusCode.OK &&
                !_checkedForErrorResponse)
            {
                // Check for top level XML element "Error".
                // Few S3 operations like CopyObject, CopyPart and CompleteMultipartUpload
                // can return an HTTP 200 response with an error element.
                if (this.IsStartElement)
                {
                    if (this.TestExpression("Error", 1))
                    {
                        var errorResponse = new Amazon.S3.Model.Internal.MarshallTransformations.S3ErrorResponseUnmarshaller().Unmarshall(this);

                        var s3Exception = new Amazon.S3.AmazonS3Exception(
                            errorResponse.Message, null, errorResponse.Type, errorResponse.Code,
                            errorResponse.RequestId, this.ResponseData.StatusCode, errorResponse.Id2, errorResponse.AmzCfId);
                        s3Exception.Region = errorResponse.Region;

                        throw s3Exception;
                    }
                    _checkedForErrorResponse = true;
                }
            }
            return result;
        }
        public override AmazonServiceException UnmarshallException(XmlUnmarshallerContext context, Exception innerException, HttpStatusCode statusCode)
        {
            var errorResponse = Amazon.S3.Model.Internal.MarshallTransformations.S3ErrorResponseUnmarshaller.Instance.Unmarshall(context);
            var s3Exception   = new Amazon.S3.AmazonS3Exception(errorResponse.Message, innerException, errorResponse.Type, errorResponse.Code, errorResponse.RequestId, statusCode, errorResponse.Id2);

            if (errorResponse.ParsingException != null)
            {
                var body = context.ResponseBody;
                if (!string.IsNullOrEmpty(body))
                {
                    s3Exception.ResponseBody = body;
                }
            }

            return(s3Exception);
        }
        public override AmazonServiceException UnmarshallException(XmlUnmarshallerContext context, Exception innerException, HttpStatusCode statusCode)
        {
            var errorResponse = Amazon.S3.Model.Internal.MarshallTransformations.S3ErrorResponseUnmarshaller.Instance.Unmarshall(context);
            var s3Exception = new Amazon.S3.AmazonS3Exception(errorResponse.Message, innerException, errorResponse.Type, errorResponse.Code, errorResponse.RequestId, statusCode, errorResponse.Id2);

            if (errorResponse.ParsingException != null)
            {
                var body = context.ResponseBody;
                if (!string.IsNullOrEmpty(body))
                {
                    s3Exception.ResponseBody = body;
                }
            }

            return s3Exception;
        }
示例#6
0
        public void Put(string remotename, System.IO.Stream input)
        {
            try
            {
                Connection.AddFileStream(m_bucket, GetFullKey(remotename), input);
            }
            catch (Exception ex)
            {
                //Catch "non-existing" buckets
                Amazon.S3.AmazonS3Exception s3ex = ex as Amazon.S3.AmazonS3Exception;
                if (s3ex != null && (s3ex.StatusCode == System.Net.HttpStatusCode.NotFound || "NoSuchBucket".Equals(s3ex.ErrorCode)))
                    throw new Interface.FolderMissingException(ex);

                throw;
            }
        }
示例#7
0
        public IEnumerable<IFileEntry> List()
        {
            try
            {
                return ListWithouExceptionCatch();
            }
            catch (Exception ex)
            {
                //Catch "non-existing" buckets
                Amazon.S3.AmazonS3Exception s3ex = ex as Amazon.S3.AmazonS3Exception;
                if (s3ex != null && (s3ex.StatusCode == System.Net.HttpStatusCode.NotFound || "NoSuchBucket".Equals(s3ex.ErrorCode)))
                    throw new Interface.FolderMissingException(ex);

                throw;
            }
        }
示例#8
0
        public async Task PutAsync(string remotename, Stream input, CancellationToken cancelToken)
        {
            try
            {
                await Connection.AddFileStreamAsync(m_bucket, GetFullKey(remotename), input, cancelToken);
            }
            catch (Exception ex)
            {
                //Catch "non-existing" buckets
                Amazon.S3.AmazonS3Exception s3ex = ex as Amazon.S3.AmazonS3Exception;
                if (s3ex != null && (s3ex.StatusCode == System.Net.HttpStatusCode.NotFound || "NoSuchBucket".Equals(s3ex.ErrorCode)))
                {
                    throw new FolderMissingException(ex);
                }

                throw;
            }
        }