示例#1
0
        public static (double, double) GetRate(TicketClientSettingsData clientData, int expire = 10000)//10 сек на случай зависона
        {
            string bin = Environment.CurrentDirectory + "/" + clientData.path;

            string[] path = clientData.path.Split('/');
            if (path.Count() > 0)
            {
                path = path.Take(path.Count() - 1).ToArray();
            }
            string dir        = Environment.CurrentDirectory + "/" + String.Join("/", path) + "/";
            string clientName = clientData
                                .path
                                .Split('/')
                                .Last()
                                .Replace(".exe", "");

            string response = Exec(clientName, bin, dir, "--rate", 100, expire);

            if (response == null || response == "expire")
            {
                return(0, 0);
            }

            RateParsedData model = JsonConvert.DeserializeObject <RateParsedData>(response);

            if (clientData.demping_percent > 0)
            {
                model.rate = model.rate - (model.rate / 100 * clientData.demping_percent);
            }

            return(model.rate, model.balance);
        }
示例#2
0
        public RateParsedData GetMinimal()
        {
            ParseRatesBestchange beschangeRate = new ParseRatesBestchange()
            {
                bestchange = new Bestchange()
            };

            if (!beschangeRate.LoadFiles())
            {
                return(new RateParsedData());
            }

            RateParsedData data = null;

            List <RateParsedData> list = new List <RateParsedData>();

            foreach (TicketClientSettingsData client in App.settings.data.ticket_clients)
            {
                try
                {
                    //rate, balance
                    (double, double)rateItem = client.rate_path == "on_client" ?
                                               host_exchage_cs.Components.TicketClient.TicketClient.GetRate(client) :
                                               beschangeRate.GetRateBalance(client, false);

                    var bullet = new RateParsedData()
                    {
                        client = client
                    };
                    bullet.rate    = rateItem.Item2 >= App.settings.data.allow_min_balance_on_client ? rateItem.Item1 : 0;
                    bullet.balance = rateItem.Item2 >= App.settings.data.allow_min_balance_on_client ? rateItem.Item2 : 0;

                    Program.informer(new InformerMessage(InformerMessageWindow.balances, bullet.GetClientNameOnPath() + ": " + bullet.rate + ", " + bullet.balance));
                    //Console.WriteLine(bullet.GetClientNameOnPath() + ": " + bullet.rate + ", " + bullet.balance);

                    if (bullet.rate > 0)
                    {
                        list.Add(bullet);
                    }
                }
                catch (Exception ex) {
                    Program.informer(new InformerMessage(InformerMessageWindow.balances, "crash load balance: " + ex.Message));
                    //Console.WriteLine("crash load balance: " + ex.Message);
                }
            }

            double minRate = double.MaxValue;

            foreach (RateParsedData item in list)
            {
                if (item.rate < minRate && item.rate > 0)
                {
                    minRate = item.rate;
                    data    = item;
                }
            }

            data.clients = list;
            return(data);
        }