Inheritance: System.Windows.Forms.Form
Esempio n. 1
0
        private string GetFileInfos(Uri adr)
        {
            string filesBuffer = string.Empty;

            if (!string.IsNullOrEmpty(Properties.Settings.Default.UserName))
            {
                service.Credentials = new NetworkCredential(Properties.Settings.Default.UserName, Properties.Settings.Default.Password.Unprotect());
            }

            while (true)
            {
                try
                {
                    filesBuffer = service.DownloadString(adr);
                    return(filesBuffer);
                }
                catch (WebException ex)
                {
                    if (ex.Response is HttpWebResponse)
                    {
                        var resp = (HttpWebResponse)ex.Response;
                        switch (resp.StatusCode)
                        {
                        case HttpStatusCode.Unauthorized:
                            PasswordDialog dlg = new PasswordDialog();
                            dlg.ShowDialog();
                            service.Credentials = new NetworkCredential(dlg.UserName, dlg.Password);
                            continue;

                        case HttpStatusCode.NotFound:
                            SetStatus("Invalid URL");
                            Properties.Settings.Default.Address = string.Empty;
                            Properties.Settings.Default.Save();
                            return(null);

                        default:
                            SetStatus(string.Format("Unknown Error ({0})", resp.StatusCode));
                            Properties.Settings.Default.Address = string.Empty;
                            Properties.Settings.Default.Save();
                            return(null);
                        }
                    }
                    else
                    {
                        SetStatus(Properties.Resources.ConnectionError + ": " + ex.Message);
                        Properties.Settings.Default.Address = string.Empty;
                        Properties.Settings.Default.Save();
                        return(null);
                    }
                }
            }
        }
Esempio n. 2
0
        private string GetFileInfos(Uri adr)
        {
            string filesBuffer = string.Empty;

            if (!string.IsNullOrEmpty(Properties.Settings.Default.UserName))
            {
                service.Credentials = new NetworkCredential(Properties.Settings.Default.UserName, Properties.Settings.Default.Password.Unprotect());
            }

            while (true)
            {
                try
                {
                    filesBuffer = service.DownloadString(adr);
                    return filesBuffer;
                }
                catch (WebException ex)
                {
                    if (ex.Response is HttpWebResponse)
                    {
                        var resp = (HttpWebResponse)ex.Response;
                        switch (resp.StatusCode)
                        {
                            case HttpStatusCode.Unauthorized:
                                PasswordDialog dlg = new PasswordDialog();
                                dlg.ShowDialog();
                                service.Credentials = new NetworkCredential(dlg.UserName, dlg.Password);
                                continue;
                            case HttpStatusCode.NotFound:
                                SetStatus("Invalid URL");
                                Properties.Settings.Default.Address = string.Empty;
                                Properties.Settings.Default.Save();
                                return null;
                            default:
                                SetStatus(string.Format("Unknown Error ({0})", resp.StatusCode));
                                Properties.Settings.Default.Address = string.Empty;
                                Properties.Settings.Default.Save();
                                return null;
                        }
                    }
                    else
                    {
                        SetStatus(Properties.Resources.ConnectionError + ": " + ex.Message);
                        Properties.Settings.Default.Address = string.Empty;
                        Properties.Settings.Default.Save();
                        return null;
                    }
                }
            }
        }