using System;
using System.Text;
using System.IO.Compression;
using System.IO;
using System.Globalization;
using System.Linq;
using Microsoft.Win32;
using System.Diagnostics;
using System.Collections.Generic;
using Navigator.MarketDataModel;
using Xamarin.Forms;
using System.Runtime.CompilerServices;
using System.Runtime.ConstrainedExecution;

namespace Navigator.Utils
{
  public class IPCache
  {
    private static string pathFileName= Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "ipcache.txt");
    private IPCache()
    {
    }

    /// <summary>
    /// SaveIPAddress
    /// </summary>
    /// <param name="ipAddress">The ipaddress. Example 10.0.0.201  diversfified-software.com</param>
    public static void SaveIPAddress(String ipAddress)
    {
      StreamWriter streamWriter=File.AppendText(pathFileName);
      streamWriter.WriteLine(ipAddress);
      streamWriter.Flush();
      streamWriter.Close();
      streamWriter.Dispose();
    }
    public static string GetIPAddress()
    {
      if(!File.Exists(pathFileName))return null;
      string[] ipAddresses = File.ReadAllLines(pathFileName);
      if(null==ipAddresses || 0==ipAddresses.Length)return null;
      return ipAddresses[ipAddresses.Length-1];
    }
  }
}
