Ejemplo n.º 1
0
        public void ExtentEqualsTest()
        {
            Extent e = new Extent(4, 6, 9, 10);

            // ReSharper disable EqualExpressionComparison
            Assert.IsTrue(e.Equals(e), "e.Equals(e)");
#pragma warning disable CS1718 // Comparison made to same variable
            Assert.IsTrue(e == e, "e == e");
#pragma warning restore CS1718 // Comparison made to same variable

            // ReSharper restore EqualExpressionComparison
            object e2 = new Coordinate(10, 23);
            Assert.IsFalse(e.Equals(e2), "e.Equals(e2)");

            Extent e3 = new Extent(4, 6, 9, 10);
            Assert.IsTrue(e.Equals(e3), "e.Equals(e3)");
            Assert.IsTrue(e == e3, "e == e3");

            Extent e4 = new Extent(4, 7, 9, 10);
            Assert.IsFalse(e.Equals(e4), "e.Equals(e4)");
            Assert.IsFalse(e == e4, "e == e4");

            Extent e5 = null;
            Assert.IsFalse(e5 == e4, "e5 == e4");
            Assert.IsTrue(e5 == null, "e5 == null");
        }
Ejemplo n.º 2
0
 public bool Equals(GridInfo other)
 {
     if (other == null)
     {
         return(false);
     }
     return(Extent.Equals(other.Extent) &&
            Step.Equals(other.Step));
 }
Ejemplo n.º 3
0
        public override bool Equals(object obj)
        {
            Collapsible other = obj as Collapsible;

            if (other != null)
            {
                return(Tag.Equals(other.Tag) &&
                       Extent.Equals(other.Extent) &&
                       IsCollapsed == other.IsCollapsed);
            }

            return(false);
        }
Ejemplo n.º 4
0
        public bool Equals(Location other)
        {
            if (ReferenceEquals(null, other))
            {
                return(false);
            }

            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return(Extent.Equals(other.Extent) &&
                   StartLinePosition.Equals(other.StartLinePosition) &&
                   EndLinePosition.Equals(other.EndLinePosition) &&
                   string.Equals(NormalizedFilePath, other.NormalizedFilePath));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Updates an object in the cloud.
        /// </summary>
        /// <param name="id">The ID of the object to update</param>
        /// <param name="acl">Access control list for the new object. Optional, set to NULL to leave the ACL unchanged.</param>
        /// <param name="metadata">Metadata list for the new object.  Optional, set to NULL for no changes to the metadata.</param>
        /// <param name="extent">portion of the object to update.  May be null to indicate the whole object is to be replaced.  If not null, the extent size must match the data size.</param>
        /// <param name="data">The initial contents of the object.  Note that we only read 'streamLength' bytes from the stream and do not close the stream.</param>
        /// <param name="streamLength">The number of bytes to read from the stream.  Must be &lt;= the actual stream length.</param>
        /// <param name="mimeType">the MIME type of the content.  Optional, may be null.  If data is non-null and mimeType is null, the MIME type will default to application/octet-stream.</param>
        /// <param name="checksum">the checksum object to use to compute checksums.  If you're doing incremental updates after the create, include the same object in subsequent calls.  Can be null to omit checksums.</param>
        public void UpdateObjectFromStream(Identifier id, Acl acl, MetadataList metadata, Extent extent, Stream data, long streamLength, string mimeType, Checksum checksum)
        {
            HttpWebResponse resp = null;
            try
            {
                string resource = getResourcePath(context, id);
                Uri u = buildUrl(resource);
                HttpWebRequest con = createWebRequest(u);

                // Build headers
                Dictionary<string, string> headers = new Dictionary<string, string>();

                // Figure out the mimetype
                if (mimeType == null)
                {
                    mimeType = "application/octet-stream";
                }

                headers.Add("Content-Type", mimeType);
                headers.Add("x-emc-uid", uid);
                if (id is ObjectKey) {
                    headers.Add("x-emc-pool", (id as ObjectKey).pool);
                }

                //Add extent if needed
                if (extent != null && !extent.Equals(Extent.ALL_CONTENT))
                {
                    long end = extent.Offset + (extent.Size - 1);
                    headers.Add("Range", "Bytes=" + extent.Offset + "-" + end);
                }

                // Process metadata
                if (metadata != null)
                {
                    processMetadata(metadata, headers);
                }

                // Add acl
                if (acl != null)
                {
                    processAcl(acl, headers);
                }

                // Add date
                addDateHeader(headers);

                // Checksum if required
                if (checksum != null)
                {
                    if (!data.CanSeek)
                    {
                        throw new EsuException("Cannot checksum a stream that does not support seeking");
                    }
                    long current = data.Position;
                    byte[] buffer = new byte[64 * 1024];
                    for (long i = 0; i < streamLength; i += buffer.Length)
                    {
                        if (i + buffer.Length > streamLength)
                        {
                            int bytesToRead = (int)(streamLength - i);
                            int count = data.Read(buffer, 0, bytesToRead);
                            checksum.Update(new ArraySegment<byte>(buffer, 0, count));
                        }
                        else
                        {
                            int count = data.Read(buffer, 0, buffer.Length);
                            checksum.Update(new ArraySegment<byte>(buffer, 0, count));
                        }
                    }
                    data.Seek(current, SeekOrigin.Begin);

                    //Checksum ckcopy = checksum.Clone();
                    headers.Add("x-emc-wschecksum", checksum.ToString());
                }

                // Sign request
                signRequest(con, "PUT", resource, headers);

                // post data
                writeRequestBodyFromStream(con, data, streamLength);

                // Check response
                resp = (HttpWebResponse)con.GetResponse();
                int statInt = (int)resp.StatusCode;
                if (statInt > 299)
                {
                    handleError(resp);
                }

            }
            catch (UriFormatException e)
            {
                throw new EsuException("Invalid URL", e);
            }
            catch (IOException e)
            {
                throw new EsuException("Error connecting to server", e);
            }
            catch (WebException e)
            {
                if (e.Response != null)
                {
                    handleError((HttpWebResponse)e.Response);
                }
                else
                {
                    throw new EsuException("Error executing request: " + e.Message, e);
                }
            }
            finally
            {
                if (resp != null)
                {
                    resp.Close();
                }
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Updates an object in the cloud.
        /// </summary>
        /// <param name="id">The ID of the object to update</param>
        /// <param name="acl">Access control list for the new object. Optional, set to NULL to leave the ACL unchanged.</param>
        /// <param name="metadata">Metadata list for the new object.  Optional, set to NULL for no changes to the metadata.</param>
        /// <param name="extent">portion of the object to update.  May be null to indicate the whole object is to be replaced.  If not null, the extent size must match the data size.</param>
        /// <param name="data">The new contents of the object.  May be appended to later. Optional, set to null for no content changes.</param>
        /// <param name="mimeType">the MIME type of the content.  Optional, may be null.  If data is non-null and mimeType is null, the MIME type will default to application/octet-stream.</param>
        /// <param name="checksum">the checksum object to use to compute checksums.  If you're doing incremental updates after the create, include the same object in subsequent calls.  Can be null to omit checksums.</param>
        public void UpdateObjectFromSegment(Identifier id, Acl acl, MetadataList metadata, Extent extent, ArraySegment<byte> data, string mimeType, Checksum checksum)
        {
            HttpWebResponse resp = null;
            try {
                string resource = getResourcePath(context, id);
                Uri u = buildUrl( resource );
                HttpWebRequest con = createWebRequest(u);

                // Build headers
                Dictionary<string, string> headers = new Dictionary<string, string>();

                // Figure out the mimetype
                if( mimeType == null ) {
                    mimeType = "application/octet-stream";
                }

                headers.Add( "Content-Type", mimeType );
                headers.Add( "x-emc-uid", uid );
                if (id is ObjectKey) {
                    headers.Add( "x-emc-pool", (id as ObjectKey).pool );
                }

                //Add extent if needed
                if( extent != null && !extent.Equals( Extent.ALL_CONTENT ) ) {
                    long end = extent.Offset + (extent.Size - 1);
                    headers.Add( "Range", "Bytes=" + extent.Offset + "-" + end );
                }

                // Process metadata
                if( metadata != null ) {
                    processMetadata( metadata, headers );
                }

                // Add acl
                if( acl != null ) {
                    processAcl( acl, headers );
                }

                // Add date
                addDateHeader(headers);

                // Checksum if required
                if (checksum != null)
                {
                    checksum.Update(data);
                    headers.Add("x-emc-wschecksum", checksum.ToString());
                }

                // Sign request
                signRequest( con, "PUT", resource, headers );

                // post data
                Stream s = null;
                try {
                    s = con.GetRequestStream();
                    s.Write( data.Array, data.Offset, data.Count );
                    s.Close();
                } catch( IOException e ) {
                    s.Close();
                    throw new EsuException( "Error posting data", e );
                }

                // Check response
                resp = (HttpWebResponse)con.GetResponse();
                int statInt = (int)resp.StatusCode;
                if( statInt > 299 ) {
                    handleError( resp );
                }

            } catch( UriFormatException e ) {
                throw new EsuException( "Invalid URL", e );
            } catch( IOException e ) {
                throw new EsuException( "Error connecting to server", e );
            } catch( WebException e ) {
                if (e.Response != null)
                {
                    handleError((HttpWebResponse)e.Response);
                }
                else
                {
                    throw new EsuException("Error executing request: " + e.Message, e);
                }
            }
            finally
            {
                if( resp != null ) {
                    resp.Close();
                }
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Fetches object content as a stream
        /// </summary>
        /// <param name="id">the identifier of the object whose content to read.</param>
        /// <param name="extent">the portion of the object data to read.  Optional.  If null, the entire object will be read.</param>
        /// <returns></returns>
        public ReadObjectStreamResponse ReadObjectStream(Identifier id, Extent extent)
        {
            HttpWebResponse resp = null;
            try
            {
                string resource = getResourcePath(context, id);
                Uri u = buildUrl(resource);
                HttpWebRequest con = createWebRequest(u);

                // Build headers
                Dictionary<string, string> headers = new Dictionary<string, string>();

                headers.Add("x-emc-uid", uid);
                if (id is ObjectKey) {
                    headers.Add("x-emc-pool", (id as ObjectKey).pool);
                }

                //Add extent if needed
                if (extent != null && !extent.Equals(Extent.ALL_CONTENT))
                {
                    long end = extent.Offset + (extent.Size - 1);
                    headers.Add("Range", "Bytes=" + extent.Offset + "-" + end);
                }

                // Add date
                addDateHeader(headers);

                // Sign request
                signRequest(con, "GET", resource, headers);

                // Check response
                resp = (HttpWebResponse)con.GetResponse();
                int statInt = (int)resp.StatusCode;
                if (statInt > 299)
                {
                    handleError(resp);
                }

                string contentChecksum = resp.Headers["x-emc-wschecksum"];

                // Parse return headers.  Regular metadata is in x-emc-meta and
                // listable metadata is in x-emc-listable-meta
                MetadataList meta = new MetadataList();
                readMetadata(meta, resp.Headers["x-emc-meta"], false);
                readMetadata(meta, resp.Headers["x-emc-listable-meta"], true);

                // Parse return headers.  User grants are in x-emc-useracl and
                // group grants are in x-emc-groupacl
                Acl acl = new Acl();
                readAcl(acl, resp.Headers["x-emc-useracl"], Grantee.GRANTEE_TYPE.USER);
                readAcl(acl, resp.Headers["x-emc-groupacl"], Grantee.GRANTEE_TYPE.GROUP);

                long streamLength = resp.ContentLength;

                return new ReadObjectStreamResponse(resp.GetResponseStream(), resp.ContentType,
                    streamLength, meta, acl, extent, resp, contentChecksum);
            }
            catch (UriFormatException e)
            {
                throw new EsuException("Invalid URL", e);
            }
            catch (IOException e)
            {
                if (resp != null)
                {
                    resp.Close();
                }
                throw new EsuException("Error connecting to server", e);
            }
            catch (WebException e)
            {
                if (e.Response != null)
                {
                    handleError((HttpWebResponse)e.Response);
                    if (resp != null)
                    {
                        resp.Close();
                    }
                }
                else
                {
                    throw new EsuException("Error executing request: " + e.Message, e);
                }
            }

            return null;
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Reads an object's content.
        /// </summary>
        /// <param name="id">the identifier of the object whose content to read.</param>
        /// <param name="extent">the portion of the object data to read.  Optional.  If null, the entire object will be read.</param>
        /// <param name="buffer">the buffer to use to read the extent.  Must be large enough to read the response or an error will be thrown.  If null, a buffer will be allocated to hold the response data.  If you pass a buffer that is larger than the extent, only extent.getSize() bytes will be valid.</param>
        /// <param name="checksum">checksum if not null, the given checksum object will be used
        /// to verify checksums during the read operation.  Note that only erasure coded objects 
        /// will return checksums *and* if you're reading the object in chunks, you'll have to 
        /// read the data back sequentially to keep the checksum consistent.  If the read operation 
        /// does not return a checksum from the server, the checksum operation will be skipped.</param>
        /// <returns>A byte array containing the requested content.</returns>
        public byte[] ReadObject( Identifier id, Extent extent, byte[] buffer, Checksum checksum )
        {
            HttpWebResponse resp = null;
            try {
                string resource = getResourcePath(context, id);
                Uri u = buildUrl( resource );
                HttpWebRequest con = createWebRequest(u);

                // Build headers
                Dictionary<string, string> headers = new Dictionary<string, string>();

                headers.Add( "x-emc-uid", uid );
                if (id is ObjectKey) {
                    headers.Add("x-emc-pool", (id as ObjectKey).pool);
                }

                //Add extent if needed
                if( extent != null && !extent.Equals( Extent.ALL_CONTENT ) ) {
                    long end = extent.Offset + (extent.Size - 1);
                    headers.Add( "Range", "Bytes=" + extent.Offset + "-" + end );
                }

                // Add date
                addDateHeader(headers);

                // Sign request
                signRequest( con, "GET", resource, headers );

                // Check response
                resp = (HttpWebResponse)con.GetResponse();
                int statInt = (int)resp.StatusCode;
                if( statInt > 299 ) {
                    handleError( resp );
                }

                byte[] responseBuffer = readResponse( resp, buffer, extent );

                if (checksum != null && resp.Headers["x-emc-wschecksum"] != null)
                {
                    // Update checksum
                    int contentLength = (int)resp.ContentLength;
                    checksum.ExpectedValue = resp.Headers["x-emc-wschecksum"];
                    if (contentLength == -1 && extent == null)
                    {
                        // Use buffer size
                        checksum.Update(new ArraySegment<byte>(responseBuffer, 0, responseBuffer.Length));
                    }
                    else if (contentLength == -1 && extent != null)
                    {
                        // Use extent size
                        checksum.Update(new ArraySegment<byte>(responseBuffer, 0, (int)extent.Size));
                    }
                    else
                    {
                        checksum.Update(new ArraySegment<byte>(responseBuffer, 0, contentLength));
                    }
                }

                resp.Close();
                return responseBuffer;

            } catch( UriFormatException e ) {
                throw new EsuException( "Invalid URL", e );
            } catch( IOException e ) {
                throw new EsuException( "Error connecting to server", e );
            } catch( WebException e ) {
                if (e.Response != null)
                {
                    handleError((HttpWebResponse)e.Response);
                }
                else
                {
                    throw new EsuException("Error executing request: " + e.Message, e);
                }
            }
            finally
            {
                if( resp != null ) {
                    resp.Close();
                }
            }
            return null;
        }
Ejemplo n.º 9
0
 public bool Equals(ClassifiedExtent other)
 {
     return(Extent.Equals(other.Extent) && Classification == other.Classification);
 }