/// <summary> /// Reads the DNS entry's from the JSON stored file. /// </summary> public void LoadDomainNameTable() { //get the DNS records from a JSON file and put the data into the local DNS root record. DNSRecord _root = JsonStorageHelper.GetStorageFileContents <DNSRecord>(RootDNSFileStorageName); if (_root == null) { CreateDNSStructureFile(); LoadDomainNameTable(); return; } else if (_root.HasSubDomains()) { Root.SubDomains = _root.SubDomains; } }
/// <summary> /// Generates the DNS File structure and stores it in the JSON file. /// </summary> public void CreateDNSStructureFile() { DNSRecord record = new DNSRecord { Domain = "Root" }; DNSRecord com = new DNSRecord { Domain = "com" }; com.SubDomains.Add(new DNSRecord { Address = "127.0.0.1", Domain = "example" }); DNSRecord arpa = new DNSRecord { Domain = "arpa" }; DNSRecord arpaIpv4 = new DNSRecord { Domain = "ipv4" }; arpaIpv4.SubDomains.Add(new DNSRecord { Domain = "127", SubDomains = new List <DNSRecord> { new DNSRecord { Domain = "0", SubDomains = new List <DNSRecord> { new DNSRecord { Domain = "0", SubDomains = new List <DNSRecord> { new DNSRecord { Domain = "1", SubDomains = new List <DNSRecord> { new DNSRecord { Domain = "example.com" } } } } } } } } }); arpa.SubDomains.Add(arpaIpv4); record.SubDomains.Add(com); record.SubDomains.Add(arpa); JsonStorageHelper.SaveStorageFile(record, RootDNSFileStorageName); }
/// <summary> /// Saves the current DNS table into the JSON file. /// </summary> public void SaveDomainNameTable() { JsonStorageHelper.SaveStorageFile(Root, RootDNSFileStorageName); }