Ejemplo n.º 1
0
        private void SetText(Dictionary <string, string> clients)
        {
            // InvokeRequired required compares the thread ID of the
            // calling thread to the thread ID of the creating thread.
            // If these threads are different, it returns true.
            if (this.listBoxClients.InvokeRequired)
            {
                DictArgReturningVoidDelegate d = new DictArgReturningVoidDelegate(SetText);
                this.Invoke(d, new object[] { clients });
            }
            else
            {
                int rateSum = 0;

                for (int i = 0; i < this.clients.Count; i++)
                {
                    int clientRate = int.Parse(this.clients[this.clients.Keys.ElementAt(i)].Split(' ')[0]);
                    rateSum += clientRate;

                    Control item = new ClientInstance(this.clients.Keys.ElementAt(i), clientRate);

                    foreach (Control cntrl in listBoxClients.Controls)
                    {
                        if (cntrl.Name == item.Name)
                        {
                            item = cntrl;
                            break;
                        }
                    }

                    if (listBoxClients.Controls.Contains(item))
                    {
                        ((ClientInstance)listBoxClients.Controls[listBoxClients.Controls.GetChildIndex(item)]).ClientName = item.Name;
                        ((ClientInstance)listBoxClients.Controls[listBoxClients.Controls.GetChildIndex(item)]).HashRate   = int.Parse(this.clients[this.clients.Keys.ElementAt(i)].Split(' ')[0]);
                    }
                    else
                    {
                        this.listBoxClients.Controls.Add(item);
                    }

                    listBoxClients.Update();
                }

                HashRates.Add(rateSum);
                while (HashRates.Count > 100)
                {
                    HashRates.RemoveAt(0);
                }

                averageHashRate.Text = String.Format("{0} H/s", HashRates.Sum() / HashRates.Count);
                numberOfClients.Text = this.clients.Count.ToString();
            }
        }
Ejemplo n.º 2
0
        private void SetText(SortedDictionary <string, string[]> clients)
        {
            // InvokeRequired required compares the thread ID of the
            // calling thread to the thread ID of the creating thread.
            // If these threads are different, it returns true.
            if (this.listBoxClients.InvokeRequired)
            {
                DictArgReturningVoidDelegate d = new DictArgReturningVoidDelegate(SetText);
                this.Invoke(d, new object[] { clients });
            }
            else
            {
                lock (listBoxClients)
                {
                    int      rateSum   = 0;
                    int      threadSum = 0;
                    int[]    arf       = { 0, 0, 0 };
                    string[] keys      = this.clients.Keys.ToArray();
                    groupClients.SuspendLayout();

                    for (int i = 0; i < keys.Length; i++)
                    {
                        string clientName = keys[i];

                        if (clientName == null)
                        {
                            continue;
                        }

                        try
                        {
                            ClientInstance item = null;

                            foreach (ClientInstance cntrl in listBoxClients.Controls)
                            {
                                if (cntrl.Name == clientName)
                                {
                                    item = cntrl;
                                    break;
                                }
                            }

                            if (item == null)
                            {
                                item = new ClientInstance(clientName, this.clients[keys[i]]);
                            }

                            if (listBoxClients.Controls.Contains(item))
                            {
                                item.SetAllFields(this.clients[keys[i]]);
                            }
                            else
                            {
                                this.listBoxClients.Controls.Add(item, 0, clients.Keys.ToList().IndexOf(item.Name));
                            }

                            rateSum   += item.GetHashRate();
                            threadSum += item.GetThreads();
                            var temp = item.GetARF();
                            arf = new int[] { arf[0] + temp[0], arf[1] + temp[1], arf[2] + temp[2] };
                        }
                        catch (KeyNotFoundException e)
                        {
                            e.Equals(e);
                            listBoxClients.Controls.RemoveByKey(clientName);
                            continue;
                        }
                        catch
                        {
                            continue;
                        }
                    }

                    if (this.clients.Count < listBoxClients.Controls.Count)
                    {
                        ClientInstance client = null;
                        foreach (ClientInstance instance in listBoxClients.Controls)
                        {
                            if (!this.clients.ContainsKey(instance.Name))
                            {
                                client = instance;
                                break;
                            }
                        }

                        if (client != null)
                        {
                            listBoxClients.Controls.Remove(client);
                        }
                    }

                    if (rateSum > 0)
                    {
                        HashRates.Add(rateSum);
                    }

                    statusBar.Threads               = threadSum.ToString();
                    statusBar.HashRate              = GetAverageHashRate().ToString();
                    statusBar.ARF                   = new string[] { arf[0].ToString(), arf[1].ToString(), arf[2].ToString() };
                    statusBar.ClientName            = String.Format("Clients: {0}", this.clients.Count.ToString());
                    groupClients.AutoScrollPosition = scrollPos;
                    groupClients.ResumeLayout();
                }
            }
        }