/// <summary> /// Writes results to the cache. /// </summary> /// <param name="result">The result to be cached.</param> private void CacheResult(PiosResult result) { // Cache the result. var writeCache = _redis.Db0.AddAsync <PiosResult>(result.Domain.Name, result, TimeSpan.FromSeconds(_cache_ttl)); // Wait for it to finish. writeCache.Wait(); }
/// <summary> /// Parse the results returned from the Registry. /// </summary> /// <param name="domain">The domain to which the results refer.</param> /// <param name="result">The raw registry query results.</param> /// <returns></returns> private PiosResult ParsePios(string domain, string result) { // Split the result into fields. var fields = result.Split('\n'); // Fill in the basics. var parsed = new PiosResult(domain, fields.Length > 2); // If it is not registered, just return what we got so far. if (!parsed.IsRegistered) { return(parsed); } // OK, we got so far, so this domain is registered. Gather // all the key-value pairs into a List. var pairs = new List <string[]>(); foreach (var field in fields) { // Split the pair. var pair = field.Split(':'); // Get the key. var key = pair[0]; // Initialize the value. var value = String.Empty; // The URL field gets split more than once, thus we need to // take extra care of the value field. if (pair.Length == 2) { value = pair[1]; } else if (pair.Length == 3) { value = $"{pair[1]}:{pair[2]}"; } // Check if there is anything in there. if (key.Length == 0) { continue; } // Add it to the pile of pairs. pairs.Add(new string[2] { key, value }); } // For this first version we assume that the order of fields // is always the same in the response. var cult = new CultureInfo("el-GR"); /* Domain */ parsed.Domain.Handle = pairs[1][1]; parsed.Domain.ProtocolNumber = pairs[2][1]; parsed.Domain.CreationDate = DateTime.Parse(pairs[3][1], cult); parsed.Domain.ExpirationDate = DateTime.Parse(pairs[4][1], cult); parsed.Domain.LastUpdate = DateTime.Parse(pairs[5][1], cult); /* Current Registrar */ parsed.Registrar.Name = pairs[6][1]; parsed.Registrar.Url = pairs[7][1]; parsed.Registrar.Email = pairs[8][1]; parsed.Registrar.Phone = pairs[9][1]; /* Name Servers */ for (var i = 12; i < pairs.Count; i++) { // Create the name server. var ns = new NameServer(); // Fill it. ns.Name = pairs[i][1]; // Add it to the list. parsed.NameServers.Add(ns); } // We are done here. return(parsed); }