/// <summary>
        /// Call API and retrieve a list of miner configurations used to start mining
        /// </summary>
        /// <returns></returns>
        private static List <MinerConfigResponse> GetMinerConfigurations()
        {
            // Build the Request to call the API and retrieve the miner config strings
            List <AccountWallet> accountWalletList             = new List <AccountWallet>();
            ObservableCollection <GPUSettings> gpuSettingsList = new ObservableCollection <GPUSettings>();
            Region region = Region.UNDEFINED;

            // Get configurations needed for building API request from Application settings
            accountWalletList = (List <AccountWallet>)Application.Current.Properties["AccountWalletList"];
            gpuSettingsList   = (ObservableCollection <GPUSettings>)Application.Current.Properties["GPUSettingsList"];
            region            = (Region)Application.Current.Properties["Region"];

            // Build actual Request object
            MinerConfigRequest minerConfigRequest = new MinerConfigRequest();

            minerConfigRequest.Region            = region;
            minerConfigRequest.AccountWalletList = accountWalletList;
            minerConfigRequest.GPUSettingsList   = gpuSettingsList.ToList();

            // Call the web API the get a response with a list of miner config strings used
            // to start one or more mining sessions based on the current miners configurations
            MinerConfigStringAPI       minerConfigStringAPI    = new MinerConfigStringAPI();
            List <MinerConfigResponse> minerConfigResponseList = minerConfigStringAPI.GetMinerConfigResponses(minerConfigRequest);

            return(minerConfigResponseList);
        }
Exemple #2
0
        /// <summary>
        /// Call API and retrieve a list of miner configurations used to start mining
        /// </summary>
        /// <returns></returns>
        private static List <MinerConfigResponse> GetMinerConfigurations(MinerAccount minerAccount)
        {
            // Build api Request object
            MinerConfigRequest minerConfigRequest = new MinerConfigRequest();

            minerConfigRequest.Region            = minerAccount.Region;
            minerConfigRequest.AccountWalletList = minerAccount.AccountWalletList;
            minerConfigRequest.GPUSettingsList   = minerAccount.GPUSettingsList.ToList();

            // Call the web API the get a response with a list of miner config strings used
            // to start one or more mining sessions based on the current miners configurations
            MinerConfigStringAPI       minerConfigStringAPI    = new MinerConfigStringAPI();
            List <MinerConfigResponse> minerConfigResponseList = minerConfigStringAPI.GetMinerConfigResponses(minerConfigRequest);

            return(minerConfigResponseList);
        }
        /// <summary>
        /// Send Miner Config string request and get responses for all miners that we need to start
        /// </summary>
        /// <returns></returns>
        public List <MinerConfigResponse> GetMinerConfigResponses(MinerConfigRequest minerConfigRequest)
        {
            try
            {
                string apiURL = APIConstants.APIURL + APIEndpoints.GetMinerConfigString;
                List <MinerConfigResponse> minerConfigResponseList = new List <MinerConfigResponse>();

                // Serialize our concrete class into a JSON String
                var stringPayload = JsonConvert.SerializeObject(minerConfigRequest);

                // Wrap our JSON inside a StringContent which then can be used by the HttpClient class
                var httpContent = new StringContent(stringPayload, Encoding.UTF8, "application/json");

                using (var httpClient = new HttpClient())
                {
                    // Do the actual request and await the response
                    var httpResponse = httpClient.PostAsync(apiURL, httpContent).Result;

                    // If the response contains content we want to read it!
                    if (httpResponse.Content != null)
                    {
                        // Read response and remove extra formatting
                        var responseContent = httpResponse.Content.ReadAsStringAsync().Result.Replace("\\", "").Trim(new char[1] {
                            '"'
                        });
                        logger.Info(responseContent);
                        minerConfigResponseList = JsonConvert.DeserializeObject <List <MinerConfigResponse> >(responseContent);
                    }
                }

                return(minerConfigResponseList);
            }
            catch (Exception e)
            {
                logger.Error(e, "Error retrieving miner coniguration from API.");
                return(new List <MinerConfigResponse>()); //return empty list
            }
        }