Esempio n. 1
0
        private static bool EndpointIsMiner(IPEndPoint ipEndpoint)
        {
            bool endpointIsMiner = false;

            ApiContext context = new ApiContext(ipEndpoint.Port, ipEndpoint.Address.ToString());

            string response = null;
            try
            {
                //give the call more time than default (500 ms)
                //we want to minimize removing valid endpoints due to
                //device resource limitations
                const int TimeoutMs = 3000;
                response = context.GetResponse(ApiVerb.Version, TimeoutMs);
            }
            catch (Exception)
            {
                response = null;
            }

            if (!String.IsNullOrEmpty(response) && response.Contains("VERSION"))
                endpointIsMiner = true;

            return endpointIsMiner;
        }
Esempio n. 2
0
        private static bool EndpointIsMiner(IPEndPoint ipEndpoint)
        {
            bool endpointIsMiner = false;

            ApiContext context = new ApiContext(ipEndpoint.Port, ipEndpoint.Address.ToString());

            string response = null;
            try
            {
                response = context.GetResponse(ApiVerb.Version);
            }
            catch (Exception ex)
            {
                response = null;
            }

            if (!String.IsNullOrEmpty(response) && response.Contains("VERSION"))
                endpointIsMiner = true;

            return endpointIsMiner;
        }
        private bool ToggleNetworkDevicePools(DeviceViewModel networkDevice, bool enabled)
        {
            // networkDevicePools is keyed by IP:port, use .Path
            List<PoolInformation> poolInformation = GetCachedPoolInfoFromAddress(networkDevice.Path);

            if (poolInformation == null)
                //RPC API call timed out
                return false;

            Uri uri = new Uri("http://" + networkDevice.Path);
            ApiContext apiContext = new ApiContext(uri.Port, uri.Host);

            //setup logging
            apiContext.LogEvent -= LogApiEvent;
            apiContext.LogEvent += LogApiEvent;

            string verb = enabled ? "enablepool" : "disablepool";

            for (int i = 0; i < poolInformation.Count; i++)
            {
                string response = apiContext.GetResponse(String.Format("{0}|{1}", verb, i));
                if (!response.ToLower().Contains("STATUS=S".ToLower()))
                    return false;
            }

            //remove cached data for pools
            NetworkDevicePools.Remove(networkDevice.Path);

            return true;
        }