public override void PostPicture(PicturePostObject postData) { #region Argument check //Check for empty path if (string.IsNullOrEmpty(postData.Filename)) { OnErrorOccured(new PictureServiceEventArgs(PictureServiceErrorLevel.Failed,string.Empty , API_ERROR_UPLOAD)); } //Check for empty credentials if (string.IsNullOrEmpty(postData.Username) || string.IsNullOrEmpty(postData.Password)) { OnErrorOccured(new PictureServiceEventArgs(PictureServiceErrorLevel.Failed, string.Empty, API_ERROR_UPLOAD)); } #endregion using (FileStream file = new FileStream(postData.Filename, FileMode.Open, FileAccess.Read)) { try { //Load the picture data byte[] incoming = new byte[file.Length]; file.Read(incoming, 0, incoming.Length); if (postData.UseAsync) { workerPPO = (PicturePostObject)postData.Clone(); workerPPO.PictureData = incoming; if (workerThread == null) { workerThread = new System.Threading.Thread(new System.Threading.ThreadStart(ProcessUpload)); workerThread.Name = "PictureUpload"; workerThread.Start(); } else { OnErrorOccured(new PictureServiceEventArgs(PictureServiceErrorLevel.NotReady, string.Empty, API_ERROR_NOTREADY)); } } else { //use sync. postData.PictureData = incoming; XmlDocument uploadResult; if (string.IsNullOrEmpty(postData.Message)) { uploadResult = UploadPicture(postData); } else { uploadResult = UploadPictureAndPost(postData); } if (uploadResult.SelectSingleNode("pikchur/error") == null) { XmlNode UrlKeyNode = uploadResult.SelectSingleNode("pikchur/post/url"); string URL = UrlKeyNode.InnerText; URL = URL.Replace("\n",""); OnUploadFinish(new PictureServiceEventArgs(PictureServiceErrorLevel.OK, URL, string.Empty, postData.Filename)); } else { OnErrorOccured(new PictureServiceEventArgs(PictureServiceErrorLevel.Failed, string.Empty, API_ERROR_UPLOAD)); } } } catch (Exception) { OnErrorOccured(new PictureServiceEventArgs(PictureServiceErrorLevel.Failed, string.Empty, API_ERROR_UPLOAD)); } } }
/// <summary> /// Post a picture. /// </summary> /// <param name="postData"></param> public override void PostPicture(PicturePostObject postData) { #region Argument check //Check for empty path if (string.IsNullOrEmpty(postData.Filename)) { OnErrorOccured(new PictureServiceEventArgs(PictureServiceErrorLevel.Failed, "",API_ERROR_UPLOAD)); } //Check for empty credentials if (string.IsNullOrEmpty(postData.Username) || string.IsNullOrEmpty(postData.Password) ) { OnErrorOccured(new PictureServiceEventArgs(PictureServiceErrorLevel.Failed, "", API_ERROR_UPLOAD)); } #endregion using (System.IO.FileStream file = new FileStream(postData.Filename, FileMode.Open, FileAccess.Read)) { try { //Load the picture data byte[] incoming = new byte[file.Length]; file.Read(incoming, 0, incoming.Length); if (postData.UseAsync) { workerPPO = (PicturePostObject) postData.Clone(); workerPPO.PictureData = incoming; if (workerThread == null) { workerThread = new System.Threading.Thread(new System.Threading.ThreadStart(ProcessUpload)); workerThread.Name = "PictureUpload"; workerThread.Start(); } else { OnErrorOccured(new PictureServiceEventArgs(PictureServiceErrorLevel.NotReady, "", API_ERROR_NOTREADY)); } } else { //use sync. postData.PictureData = incoming; XmlDocument uploadResult = UploadPicture(API_UPLOAD, postData); if (uploadResult == null) { return; } if (uploadResult.SelectSingleNode("rsp").Attributes["status"].Value == "fail") { string ErrorText = uploadResult.SelectSingleNode("//err").Attributes["msg"].Value; OnErrorOccured(new PictureServiceEventArgs(PictureServiceErrorLevel.Failed, string.Empty, ErrorText)); } else { string URL = uploadResult.SelectSingleNode("//mediaurl").InnerText; OnUploadFinish(new PictureServiceEventArgs(PictureServiceErrorLevel.OK, URL, string.Empty, postData.Filename)); } } } catch (Exception) { OnErrorOccured(new PictureServiceEventArgs(PictureServiceErrorLevel.Failed, string.Empty, API_ERROR_UPLOAD)); } } }