Example #1
0
        public static void AddMultipleRigs(string[] addresses, out List <string> notAdded, out int added)
        {
            notAdded = new List <string>();
            added    = 0;
            foreach (var rig in addresses)
            {
                if (APIComm.Rigs.ContainsKey(rig))
                {
                    //already in Rigs, just deal with new
                    //var last = APIComm.Rigs[rig];
                    //var rigResponse = GetRigStatus(last.Port, last.RigName, last.IP).Result;
                }
                else
                {
                    try
                    {
                        var rigstatus = APIComm.GetRigStatus("5777", "", rig, saveToFile: false).Result;

                        //we hafe fresh stats
                        if (rigstatus != null)
                        {
                            added++;
                            //method GetRigStatus added to Rigs collection
                        }
                        else
                        {
                            notAdded.Add(rig);
                        }
                    }
                    catch { notAdded.Add(rig); }
                }
            }

            APIComm.SaveRigsToFile();
        }
Example #2
0
        public static async Task <RigStatus> GetRigStatus(string port, string name, string ip, bool saveToFile = true)
        {
            var request = new HttpRequestMessage(HttpMethod.Get, $"http://{ip}:{port}/api/status");

            try
            {
                var response = await client.SendAsync(request);

                if (response.IsSuccessStatusCode)
                {
                    SimpleStatus s = await response.Content.ReadAsAsync <SimpleStatus>();

                    RigStatus r = new RigStatus()
                    {
                        LastComm = DateTime.Now, Port = port, RigName = name, Status = s, IP = ip
                    };
                    APIComm.Rigs[ip.ToString()] = r;
                    if (saveToFile)
                    {
                        APIComm.SaveRigsToFile();
                    }
                    return(r);
                }
                else
                {
                    return(null);
                }
            }
            catch
            { return(null); }
        }
Example #3
0
 public static void Main(string[] args)
 {
     APIComm.Rigs = new ConcurrentDictionary <string, RigStatus>();
     APIComm.Init();
     //DirComm.Start();
     CreateWebHostBuilder(args).Build().Run();
 }
Example #4
0
        public static void RefreshRigs()
        {
            Task.Delay(TimeSpan.FromMinutes(1)).Wait();

            while (true)
            {
                var keys = Rigs.Keys.ToList();

                foreach (var key in keys)
                {
                    var last      = APIComm.Rigs[key];
                    var rigstatus = APIComm.GetRigStatus(last.Port, last.RigName, last.IP).Result;
                    APIComm.Rigs[key] = rigstatus;
                }

                Task.Delay(TimeSpan.FromMinutes(1)).Wait();
            }
        }