mirror of
https://github.com/Nathanwoodburn/FireWallet.git
synced 2024-11-24 08:08:14 +11:00
batchForm.cs: Added try-catch block to handle file in use exceptions
- Added try-catch block to handle exceptions when importing batch - Displayed error message and notification form if an exception occurs
This commit is contained in:
parent
c3abd0b4de
commit
404a47ec79
@ -638,17 +638,45 @@ namespace FireWallet
|
|||||||
openFileDialog.Title = "Open Batch";
|
openFileDialog.Title = "Open Batch";
|
||||||
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
||||||
{
|
{
|
||||||
StreamReader sr = new StreamReader(openFileDialog.FileName);
|
try
|
||||||
string line;
|
|
||||||
string[] domains = new string[0];
|
|
||||||
while ((line = sr.ReadLine()) != null)
|
|
||||||
{
|
{
|
||||||
string[] split = line.Split(',');
|
StreamReader sr = new StreamReader(openFileDialog.FileName);
|
||||||
try
|
string line;
|
||||||
|
string[] domains = new string[0];
|
||||||
|
while ((line = sr.ReadLine()) != null)
|
||||||
{
|
{
|
||||||
if (split.Length > 2)
|
string[] split = line.Split(',');
|
||||||
|
try
|
||||||
{
|
{
|
||||||
if (split[1] == "UPDATE")
|
if (split.Length > 2)
|
||||||
|
{
|
||||||
|
if (split[1] == "UPDATE")
|
||||||
|
{
|
||||||
|
// Select operation and import domains
|
||||||
|
string[] newDomains = new string[domains.Length + 1];
|
||||||
|
for (int i = 0; i < domains.Length; i++)
|
||||||
|
{
|
||||||
|
newDomains[i] = domains[i];
|
||||||
|
}
|
||||||
|
newDomains[domains.Length] = split[0];
|
||||||
|
domains = newDomains;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (split.Length == 2)
|
||||||
|
{
|
||||||
|
AddBatch(split[0], split[1]);
|
||||||
|
}
|
||||||
|
else if (split.Length == 3)
|
||||||
|
{
|
||||||
|
AddBatch(split[0], split[1], split[2]);
|
||||||
|
}
|
||||||
|
else if (split.Length == 4)
|
||||||
|
{
|
||||||
|
AddBatch(split[0], split[1], Convert.ToDecimal(split[2]), Convert.ToDecimal(split[3]));
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
// Select operation and import domains
|
// Select operation and import domains
|
||||||
string[] newDomains = new string[domains.Length + 1];
|
string[] newDomains = new string[domains.Length + 1];
|
||||||
@ -656,68 +684,49 @@ namespace FireWallet
|
|||||||
{
|
{
|
||||||
newDomains[i] = domains[i];
|
newDomains[i] = domains[i];
|
||||||
}
|
}
|
||||||
newDomains[domains.Length] = split[0];
|
newDomains[domains.Length] = line.Trim();
|
||||||
domains = newDomains;
|
domains = newDomains;
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (Exception ex)
|
||||||
if (split.Length == 2)
|
|
||||||
{
|
{
|
||||||
AddBatch(split[0], split[1]);
|
AddLog("Error importing batch: " + ex.Message);
|
||||||
}
|
NotifyForm notifyForm = new NotifyForm("Error importing batch");
|
||||||
else if (split.Length == 3)
|
notifyForm.ShowDialog();
|
||||||
{
|
notifyForm.Dispose();
|
||||||
AddBatch(split[0], split[1], split[2]);
|
|
||||||
}
|
|
||||||
else if (split.Length == 4)
|
|
||||||
{
|
|
||||||
AddBatch(split[0], split[1], Convert.ToDecimal(split[2]), Convert.ToDecimal(split[3]));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Select operation and import domains
|
|
||||||
string[] newDomains = new string[domains.Length + 1];
|
|
||||||
for (int i = 0; i < domains.Length; i++)
|
|
||||||
{
|
|
||||||
newDomains[i] = domains[i];
|
|
||||||
}
|
|
||||||
newDomains[domains.Length] = line.Trim();
|
|
||||||
domains = newDomains;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
if (domains.Length > 0)
|
||||||
{
|
{
|
||||||
AddLog("Error importing batch: " + ex.Message);
|
BatchImportForm batchImportForm = new BatchImportForm(domains);
|
||||||
NotifyForm notifyForm = new NotifyForm("Error importing batch");
|
batchImportForm.ShowDialog();
|
||||||
notifyForm.ShowDialog();
|
if (batchImportForm.batches != null)
|
||||||
notifyForm.Dispose();
|
{
|
||||||
|
foreach (Batch b in batchImportForm.batches)
|
||||||
|
{
|
||||||
|
if (b.method == "BID")
|
||||||
|
{
|
||||||
|
AddBatch(b.domain, b.method, b.bid, b.lockup);
|
||||||
|
}
|
||||||
|
else if (b.method == "TRANSFER")
|
||||||
|
{
|
||||||
|
AddBatch(b.domain, b.method, b.toAddress);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
AddBatch(b.domain, b.method);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
sr.Dispose();
|
||||||
if (domains.Length > 0)
|
} catch (Exception ex)
|
||||||
{
|
{
|
||||||
BatchImportForm batchImportForm = new BatchImportForm(domains);
|
AddLog("Error importing batch: " + ex.Message);
|
||||||
batchImportForm.ShowDialog();
|
NotifyForm notifyForm = new NotifyForm("Error importing batch\nMake sure the file is in not in use");
|
||||||
if (batchImportForm.batches != null)
|
notifyForm.ShowDialog();
|
||||||
{
|
notifyForm.Dispose();
|
||||||
foreach (Batch b in batchImportForm.batches)
|
|
||||||
{
|
|
||||||
if (b.method == "BID")
|
|
||||||
{
|
|
||||||
AddBatch(b.domain, b.method, b.bid, b.lockup);
|
|
||||||
}
|
|
||||||
else if (b.method == "TRANSFER")
|
|
||||||
{
|
|
||||||
AddBatch(b.domain, b.method, b.toAddress);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
AddBatch(b.domain, b.method);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
sr.Dispose();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user