protected async void AddRecord(object param)
{
RecordSet rs = new RecordSet("global");
string typeString = param.ToString();
InputDialog dlg;
switch (typeString)
{
case "A":
dlg = new InputDialog("Add A record", "Enter the 'name' of the record", "@");
if (dlg.ShowDialog() == true)
{
rs.Name = dlg.Value;
} else
{
return;
}
dlg = new InputDialog("Add A record", "Enter the 'target' for the record", "127.0.0.1");
if (dlg.ShowDialog() == true)
{
rs.Properties = new RecordSetProperties
{
Ttl = 600,
ARecords = new List<ARecord> { new ARecord(dlg.Value) }
};
}
else
{
return;
}
rs.Type = "Microsoft.Network/dnszones/A";
break;
case "AAAA":
dlg = new InputDialog("Add AAAA record", "Enter the 'name' of the record", "@");
if (dlg.ShowDialog() == true)
{
rs.Name = dlg.Value;
}
else
{
return;
}
dlg = new InputDialog("Add AAAA record", "Enter the 'target' for the record", "::1");
if (dlg.ShowDialog() == true)
{
rs.Properties = new RecordSetProperties
{
Ttl = 600,
AaaaRecords = new List<AaaaRecord> { new AaaaRecord(dlg.Value) }
};
}
else
{
return;
}
rs.Type = "Microsoft.Network/dnszones/AAAA";
break;
case "CNAME":
dlg = new InputDialog("Add CNAME record", "Enter the 'name' of the record", "@");
if (dlg.ShowDialog() == true)
{
rs.Name = dlg.Value;
}
else
{
return;
}
dlg = new InputDialog("Add CNAME record", "Enter the 'target' for the record", ActiveZone.Name);
if (dlg.ShowDialog() == true)
{
rs.Properties = new RecordSetProperties
{
Ttl = 600,
CnameRecord = new CnameRecord(dlg.Value)
};
}
else
{
return;
}
rs.Type = "Microsoft.Network/dnszones/CNAME";
break;
case "MX":
rs.Name = "@";
dlg = new InputDialog("Add MX record", "Enter the 'preference / priority' of the record", "10");
rs.Properties = new RecordSetProperties()
{
Ttl = 600,
MxRecords = new List<MxRecord> { new MxRecord() }
};
if (dlg.ShowDialog() == true)
{
rs.Properties.MxRecords[0].Preference = ushort.Parse(dlg.Value);
}
else
{
return;
}
dlg = new InputDialog("Add MX record", "Enter the 'target / exchange' for the record", "mx1." + ActiveZone.Name);
if (dlg.ShowDialog() == true)
{
rs.Properties.MxRecords[0].Exchange = dlg.Value;
}
else
{
return;
}
rs.Type = "Microsoft.Network/dnszones/MX";
break;
case "SRV":
dlg = new InputDialog("Add SRV record", "Enter the 'name/origin' of the record", "@");
if (dlg.ShowDialog() == true)
{
rs.Name = dlg.Value;
}
else
{
return;
}
rs.Properties = new RecordSetProperties
{
Ttl = 600,
SrvRecords = new List<SrvRecord>
{
new SrvRecord()
}
};
dlg = new InputDialog("Add SRV record", "Enter the 'priority' for the record", "100");
if (dlg.ShowDialog() == true)
{
rs.Properties.SrvRecords[0].Priority = ushort.Parse(dlg.Value);
}
else
{
return;
}
dlg = new InputDialog("Add SRV record", "Enter the 'weight' for the record", "1");
if (dlg.ShowDialog() == true)
{
rs.Properties.SrvRecords[0].Weight = ushort.Parse(dlg.Value);
}
else
{
return;
}
dlg = new InputDialog("Add SRV record", "Enter the 'port' for the record", "443");
if (dlg.ShowDialog() == true)
{
rs.Properties.SrvRecords[0].Port = ushort.Parse(dlg.Value);
}
else
{
return;
}
dlg = new InputDialog("Add SRV record", "Enter the 'target' for the record", ActiveZone.Name);
if (dlg.ShowDialog() == true)
{
rs.Properties.SrvRecords[0].Target = dlg.Value;
}
else
{
return;
}
rs.Type = "Microsoft.Network/dnszones/SRV";
break;
case "TXT":
dlg = new InputDialog("Add TXT record", "Enter the 'name/origin' of the record", "@");
if (dlg.ShowDialog() == true)
{
rs.Name = dlg.Value;
}
else
{
return;
}
dlg = new InputDialog("Add TXT record", "Enter the 'target/value' for the record", ActiveZone.Name);
if (dlg.ShowDialog() == true)
{
rs.Properties = new RecordSetProperties
{
Ttl = 600,
TxtRecords = new List<TxtRecord>
{
new TxtRecord(new List<string>() { dlg.Value })
}
};
}
else
{
return;
}
rs.Type = "Microsoft.Network/dnszones/TXT";
break;
default:
return;
}
try
{
await _dnsManagementClient.RecordSets.CreateOrUpdateAsync(ActiveResourceGroup.Name, ActiveZone.Name, rs.Name, GetRecordType(rs.Type), new RecordSetCreateOrUpdateParameters(rs), null, null);
ReloadRecords();
}
catch(Exception ex)
{
MessageBox.Show("Failed to add new record. " + ex.Message);
}
}