Пример #1
0
    private bool alreadyDownloaded(ArtMetaData meta)
    {
        Debug.Log("Checking if " + meta.AbsolutePath + " already exists");
        if (!Util.IsFile(meta.AbsolutePath))
        {
            return(false);
        }
        Checksum hash = Checksum.Compute(meta.AbsolutePath, meta.Type);

        return(meta.Checksum.Equals(hash));
    }
Пример #2
0
 public ArtMetaData(string title, string artist, string absolutePath, ArtType type) :
     this(title, artist, absolutePath, type, Checksum.Compute(absolutePath, type))
 {
 }
Пример #3
0
        /// <summary>
        /// <para>
        /// Add an image set to the server's central database.
        /// The image set is specified as a <see cref="ImageSetBlob"/> instance which provides a
        /// way to retrieve the binary data for the images and the GUID that uniquely identifies
        /// the image set.
        /// </para><para>
        /// This method will first invoke the <see cref="GetId"/> method to determine if an image
        /// set with the GUID in the <code>ImageSetBlob</code> already exists in the central
        /// database.
        /// If it exists, the database's ID for the image set will be returned and the upload of
        /// the binary data will not be done.
        /// If it doesn't exist, the upload will proceed.
        /// The binary data for the images is large, so there is no need to upload it if the image
        /// set is already present in the database.
        /// </para>
        /// </summary>
        /// <param name="imageSet">an <see cref="ImageSetBlob"/> instance that contains the image
        ///		set to add</param>
        /// <returns>a long containing the ID of the image set on the server</returns>
        /// <exception cref="HttpInvocationException">thrown when any HTTP status code other than
        ///		200 is returned by the server; fields in the exception hold the status code and
        ///		error message returned</exception>
        /// <exception cref="InvocationException">thrown when an error occurs invoking the service
        ///		on the server, prior to the service running</exception>
        /// <exception cref="MalformedUriException">thrown when a valid URI cannot be constructed
        ///		from the base URI and additional relative path</exception>
        public long Add(ImageSetBlob imageSet)
        {
            // See if the image set is already on the server. Exception will result if it isn't.
            try
            {
                return(GetId(imageSet.Guid));
            }
            catch (HttpInvocationException e)
            {
                // If any exception except "not found" occurred, re-throw it. Otherwise, continue below.
                if (e.StatusCode != HttpStatusCode.NotFound)
                {
                    throw;
                }
            }

            // Get here if the image set isn't on the server. Get the stream for reading the image set
            // and build the request. A checksum is computed over the image set data and provided as a
            // parameter along with the GUID.
            Stream         imageStream = imageSet.GetReadStream();
            HttpWebRequest request     = GetRequest("POST", string.Format("/guid={0}/checksum={1}", imageSet.Guid, Checksum.Compute(imageStream)));

            // Checksum calculation read the stream. Seek back to the beginning to send it.
            imageStream.Seek(0, SeekOrigin.Begin);

            try
            {
                // Configure request with data size and type.
                request.ContentLength = imageStream.Length;
                request.ContentType   = "application/octet-stream";

                // Send the image set data by copying it to the request's stream.
                using (Stream requestStream = request.GetRequestStream())
                    imageStream.CopyTo(requestStream);

                // Get the server's response and return it.
                return(GetResponse(request, GetResponse <long>));
            }
            catch (InvocationException)
            {
                // Any InvocationException exception is just re-thrown.
                throw;
            }
            catch (Exception e)
            {
                // Most likely I/O error. All others are programming issues.
                if (Log.IsDebugEnabled)
                {
                    Log.Debug(string.Format("Error writing request Content: {0}, POST method, likely I/O error", request.RequestUri), e);
                }

                throw new InvocationException("Request transmission error", e);
            }
        }