Exemplo n.º 1
0
        private bool DoUpload(IUploadService Service, UploadAttachment a)
        {
            try
            {
                a.Status = UploadAttachment.AttachmentStatus.Uploading;
                a.UploadedUri = Service.UploadAttachment(a, Account);
                a.Status = UploadAttachment.AttachmentStatus.Complete;
                return true;
            }
            catch (WebException we)
            {
                if (we.Response is HttpWebResponse)
                {
                    using (HttpWebResponse response = we.Response as HttpWebResponse)
                    {
                        Localization.LocalizedMessageBox.Show(
                                string.Format(Localization.XmlBasedResourceManager.GetString("The media service encountered an error: {0} {1}"), response.StatusCode, response.StatusDescription)
                            );
                    }
                }
                else
                    Localization.LocalizedMessageBox.Show("An unknown error occurred while uploading.");
            }
            catch (System.Net.Sockets.SocketException se)
            {
                string LocalizedString = null;
                switch (se.NativeErrorCode)
                {
                    // Can't contact server
                    case 10050: // Netdown
                    case 10051: // Unreachable
                    case 10061: // Refused
                    case 10062: // Cannot translate name
                    case 10064: // Host down
                    case 10065: // No route to host
                    case 11001: // Hostname not found
                    case 11002: // Host temporarily not found
                    case 11003: // Non-recoverable host lookup error
                    case 11004: // No data record for name - IP address lookup failure
                        LocalizedString = string.Format(Localization.XmlBasedResourceManager.GetString("The media service can not be reached (Error {0})."), se.NativeErrorCode);
                        break;

                    // Interrupted connection
                    case 10004: // Airplane mode
                    case 10052: // Network Reset
                    case 10053: // Connection Aborted
                    case 10054: // Connection Reset
                        LocalizedString = Localization.XmlBasedResourceManager.GetString("Connection to service lost.");
                        break;

                    // Timeout
                    case 10060: // Timeout
                        LocalizedString = Localization.XmlBasedResourceManager.GetString("Connection timed out.");
                        break;

                    default:
                        LocalizedString = string.Format(Localization.XmlBasedResourceManager.GetString("The media service encountered an error: {0} {1}"), se.NativeErrorCode, se.Message);
                        break;
                }
                Localization.LocalizedMessageBox.Show(
                        LocalizedString
                    );
            }
            catch (InvalidOperationException)
            {
                Localization.LocalizedMessageBox.Show("An internal error occurred while uploading.");
            }
            catch (Exception)
            {
                Localization.LocalizedMessageBox.Show("An unknown error occurred while uploading.");
            }
            a.Status = UploadAttachment.AttachmentStatus.Error;
            return false;
        }