Пример #1
0
        /// <summary>
        /// Uploads the Image to SmugMug using HTTP Post.
        /// </summary>
        /// <param name="path">The full path to the image on disk.</param>
        /// <param name="AlbumID">The AlbumID for the Image to be added.</param>
        /// <returns>Throws an <see cref="SmugMugUploadException"/>
        /// if an error occurs trying to upload the Image.</remarks>
        public int Upload(string path, int AlbumID)
        {
            FileInfo file = new FileInfo(path);

            if (file.Exists == false)
            {
                throw new ArgumentException("Image does not exist: " + file.FullName);
            }

//			int byteCount = Convert.ToInt32(file.Length);
//			string md5sum = null;
//
//			using (FileStream fs = new FileStream(file.FullName, FileMode.Open, FileAccess.Read))
//			{
//
//				MD5 md5 = new MD5CryptoServiceProvider();
//				byte[] hash = md5.ComputeHash(fs);
//
//				StringBuilder buff = new StringBuilder();
//				foreach (byte hashByte in hash)
//				{
//					buff.Append(String.Format("{0:X1}", hashByte));
//				}
//				md5sum = buff.ToString();
//			}

            try
            {
                WebClient client = new WebClient();
                client.BaseAddress = "http://upload.smugmug.com";
                client.Headers.Add("Cookie:SMSESS=" + this.credentials.SessionID);

                NameValueCollection queryStringCollection = new NameValueCollection();
                queryStringCollection.Add("AlbumID", AlbumID.ToString());
                queryStringCollection.Add("Version", SMUGMUG_API_DEFAULT_VERSION);
//				queryStringCollection.Add("APIKey", SMUGMUG_API_KEY);
//				queryStringCollection.Add("ByteCount", byteCount.ToString());
//				queryStringCollection.Add("MD5Sum", md5sum);
                client.QueryString = queryStringCollection;

                byte[] responseArray = client.UploadFile("http://upload.smugmug.com/photos/xmladd.mg", "POST", file.FullName);
                string response      = Encoding.ASCII.GetString(responseArray);

                XmlRpcSerializer ser = new XmlRpcSerializer();
                XmlDocument      doc = new XmlDocument();
                doc.LoadXml(response);
                XmlRpcResponse rpcResponse = ser.DeserializeResponse(doc, typeof(XmlRpcInt));
                XmlRpcInt      imageID     = (XmlRpcInt)rpcResponse.retVal;
                return((int)imageID);
            }
            catch (Exception ex)
            {
                throw new SmugMugUploadException("Error uploading image: " + file.FullName, ex.InnerException);
            }
        }
Пример #2
0
        public override bool Equals(
            object o)
        {
            if (o == null || !(o is XmlRpcInt))
            {
                return(false);
            }
            XmlRpcInt dbl = o as XmlRpcInt;

            return(dbl._value == _value);
        }