Rev 2 Rev 8
Line 1... Line 1...
1 using System; 1 using System;
2 using System.Collections.Generic; 2 using System.Collections.Generic;
3 using System.ComponentModel; 3 using System.ComponentModel;
4 using System.Data; -  
5 using System.Drawing; -  
6 using System.Linq; 4 using System.Linq;
7 using System.Text; -  
8 using System.Windows.Forms; 5 using System.Windows.Forms;
9 using clempaul; 6 using clempaul;
10 using clempaul.Dreamhost.ResponseData; 7 using clempaul.Dreamhost.ResponseData;
11   8  
12 namespace DNS_Manager 9 namespace DNS_Manager
Line 54... Line 51...
54             } 51             }
55         } 52         }
56   53  
57         void DeleteRecord_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) 54         void DeleteRecord_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
58         { 55         {
-   56             if (e.Error == null)
-   57             {
59             MessageBox.Show("Record Deleted", "DNS Manager", MessageBoxButtons.OK, MessageBoxIcon.Information); 58                 MessageBox.Show("Record Deleted!", "DNS Manager", MessageBoxButtons.OK, MessageBoxIcon.Information);
60             this.LoadRecords(); 59                 this.LoadRecords();
-   60             }
-   61             else
-   62             {
-   63                 if (e.Error.Message.Contains("no_such"))
-   64                 {
-   65                     MessageBox.Show("Record not found.\nTry refreshing the record list to make sure it's not been deleted already.", "DNS Manager", MessageBoxButtons.OK, MessageBoxIcon.Error);
-   66                 }
-   67                 else if (e.Error.Message.Contains("internal_error"))
-   68                 {
-   69                     if (MessageBox.Show("An internal error has occurred", "DNS Manager", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error) == DialogResult.Retry)
-   70                     {
-   71                         this.DeleteRecord.RunWorkerAsync((DNSRecord)this.dataGridView.SelectedRows[0].DataBoundItem);
-   72                         return;
-   73                     }
-   74                 }
-   75                 else
-   76                 {
-   77                     if (MessageBox.Show(e.Error.Message, "DNS Manager", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error) == DialogResult.Retry)
-   78                     {
-   79                         this.DeleteRecord.RunWorkerAsync((DNSRecord)this.dataGridView.SelectedRows[0].DataBoundItem);
-   80                         return;
-   81                     }
-   82                 }
-   83             }
61         } 84         }
62   85  
63         void DeleteRecord_DoWork(object sender, DoWorkEventArgs e) 86         void DeleteRecord_DoWork(object sender, DoWorkEventArgs e)
64         { 87         {
65             if (e.Argument.GetType() != typeof(DNSRecord)) 88             if (e.Argument.GetType() != typeof(DNSRecord))
Line 71... Line 94...
71             System.Threading.Thread.Sleep(3000); 94             System.Threading.Thread.Sleep(3000);
72         } 95         }
73   96  
74         void GetRecords_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) 97         void GetRecords_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
75         { 98         {
-   99             if (e.Error != null)
-   100             {
76             string zone = this.toolStripComboBoxDomains.Text ?? string.Empty; 101                 string zone = this.toolStripComboBoxZones.Text ?? string.Empty;
77   102  
78             this.toolStripComboBoxDomains.Items.Clear(); 103                 this.toolStripComboBoxZones.Items.Clear();
79   104  
80             foreach (DNSRecord d in this.DNSRecords) 105                 foreach (DNSRecord d in this.DNSRecords)
81             { -  
82                 if (!this.toolStripComboBoxDomains.Items.Contains(d.zone)) -  
83                 { 106                 {
-   107                     if (!this.toolStripComboBoxZones.Items.Contains(d.zone))
-   108                     {
84                     this.toolStripComboBoxDomains.Items.Add(d.zone); 109                         this.toolStripComboBoxZones.Items.Add(d.zone);
-   110                     }
85                 } 111                 }
86             } -  
87   112  
88             this.toolStripStatusLabel.Text = string.Empty; 113                 this.toolStripStatusLabel.Text = string.Empty;
89   114  
90             this.toolStripComboBoxDomains.Text = zone; 115                 this.toolStripComboBoxZones.Text = zone;
91             this.SetZone(); 116                 this.SetZone();
-   117             }
-   118             else
-   119             {
-   120                 this.toolStripStatusLabel.Text = "Unable to load records... Please try again. (" + e.Error.Message + ")";
-   121             }
92         } 122         }
93   123  
94         void GetRecords_DoWork(object sender, DoWorkEventArgs e) 124         void GetRecords_DoWork(object sender, DoWorkEventArgs e)
95         { 125         {
96             this.DNSRecords = this.API.DNS.ListRecords(); 126             this.DNSRecords = this.API.DNS.ListRecords();
97   -  
98             if (e.Argument != null) -  
99             { -  
100                 e.Result = true; -  
101             } -  
102             else -  
103             { -  
104                 e.Result = false; -  
105             } -  
106         } 127         }
107   128  
108         private void aboutToolStripMenuItem_Click(object sender, EventArgs e) 129         private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
109         { 130         {
110             new About().ShowDialog(); 131             new About().ShowDialog();
111         } 132         }
112   133  
113         private void visitWebsiteToolStripMenuItem_Click(object sender, EventArgs e) 134         private void visitWebsiteToolStripMenuItem_Click(object sender, EventArgs e)
114         { 135         {
-   136             try
-   137             {
115             System.Diagnostics.Process.Start("http://software.clempaul.me.uk/"); 138                 System.Diagnostics.Process.Start("http://software.clempaul.me.uk/");
-   139             }
-   140             catch (Exception x)
-   141             {
-   142                 MessageBox.Show(x.Message, "DNS Manager", MessageBoxButtons.OK, MessageBoxIcon.Error);
-   143             }
116         } 144         }
117   145  
118         private void toolStripButtonSettings_Click(object sender, EventArgs e) 146         private void toolStripButtonSettings_Click(object sender, EventArgs e)
119         { 147         {
120             new Settings().ShowDialog(); 148             new Settings().ShowDialog();
Line 128... Line 156...
128         private void toolStripButtonSelectDomain_Click(object sender, EventArgs e) 156         private void toolStripButtonSelectDomain_Click(object sender, EventArgs e)
129         { 157         {
130             this.SetZone(); 158             this.SetZone();
131         } 159         }
132   160  
133         private void toolStripButton3_Click(object sender, EventArgs e) 161         private void toolStripButtonDelete_Click(object sender, EventArgs e)
134         { 162         {
135             if (this.dataGridView.SelectedRows.Count == 1) 163             if (this.dataGridView.SelectedRows.Count == 1 && !this.DeleteRecord.IsBusy)
136             { 164             {
137                 DNSRecord record = (DNSRecord)this.dataGridView.SelectedRows[0].DataBoundItem; 165                 DNSRecord record = (DNSRecord)this.dataGridView.SelectedRows[0].DataBoundItem;
138   166  
139                 if (!record.editable) 167                 if (!record.editable)
140                 { 168                 {
Line 154... Line 182...
154             { 182             {
155                 this.LoadRecords(); 183                 this.LoadRecords();
156             } 184             }
157         } 185         }
158   186  
159         private void toolStripButton2_Click(object sender, EventArgs e) 187         private void toolStripButtonEdit_Click(object sender, EventArgs e)
160         { 188         {
161             if (this.dataGridView.SelectedRows.Count == 1) 189             if (this.dataGridView.SelectedRows.Count == 1)
162             { 190             {
163                 DNSRecord record = (DNSRecord)this.dataGridView.SelectedRows[0].DataBoundItem; 191                 DNSRecord record = (DNSRecord)this.dataGridView.SelectedRows[0].DataBoundItem;
164   192  
Line 176... Line 204...
176             } 204             }
177         } 205         }
178   206  
179         private void SetZone() 207         private void SetZone()
180         { 208         {
181             string zoneValue = this.toolStripComboBoxDomains.Text ?? string.Empty; 209             string zoneValue = this.toolStripComboBoxZones.Text ?? string.Empty;
182   210  
183             this.dataGridView.DataSource = (from d in this.DNSRecords 211             this.dataGridView.DataSource = (from d in this.DNSRecords
184                                             where d.zone == zoneValue 212                                             where d.zone == zoneValue
185                                             select d).ToList(); 213                                             select d).ToList();
186         } 214         }