SendErrorEmail() public static method

public static SendErrorEmail ( string body ) : void
body string
return void
Exemplo n.º 1
0
        uint GetProductId(string product, uint memberId)
        {
            if (product.Length > 128)
            {
                product = product.Substring(0, 128);
            }

            if (!mProductIDs.ContainsKey(product))
            {
                string sql = "INSERT INTO products (product_name, member) VALUES ('" + product + "', '" + memberId + "')";
                try
                {
                    MySqlCommand cmd = new MySqlCommand(sql, mSql);
                    cmd.ExecuteNonQuery();

                    // Now querry the database for the index
                    sql = "SELECT * FROM products WHERE product_name='" + product + "'";
                    cmd = new MySqlCommand(sql, mSql);
                    MySqlDataReader r = cmd.ExecuteReader();
                    r.Read();
                    uint ID = (uint)r[0];
                    r.Close();
                    mProductIDs[product] = ID;
                }
                catch (Exception ex)
                {
                    Email.SendErrorEmail(sql + "\n\n" + ex.ToString());
                }
            }

            return(mProductIDs[product]);
        }
Exemplo n.º 2
0
        uint GetMemberId(string memberName)
        {
            if (memberName.Length > 64)
            {
                memberName = memberName.Substring(0, 64);
            }

            if (!mMemberIDs.ContainsKey(memberName))
            {
                string sql = "INSERT INTO members (member_name) VALUES ('" + memberName + "')";
                try
                {
                    MySqlCommand cmd = new MySqlCommand(sql, mSql);
                    cmd.ExecuteNonQuery();

                    // Now querry the database for the index
                    sql = "SELECT * FROM members WHERE member_name='" + memberName + "'";
                    cmd = new MySqlCommand(sql, mSql);
                    MySqlDataReader r = cmd.ExecuteReader();
                    r.Read();
                    uint ID = (uint)r[0];
                    r.Close();

                    mMemberIDs[memberName] = ID;
                }
                catch (Exception ex)
                {
                    Email.SendErrorEmail(sql + "\n\n" + ex.ToString());
                }
            }

            return(mMemberIDs[memberName]);
        }
Exemplo n.º 3
0
        void Update()
        {
            while (true)
            {
                DateTime start = DateTime.Now;

                // Copy the events list locally
                mEventQueueLock.WaitOne();
                List <EventInfo> events = mEventQueue;
                mEventQueue = new List <EventInfo>();
                mEventQueueLock.ReleaseMutex();

                // Send data to database
                string sql = "";
                try
                {
                    foreach (EventInfo e in events)
                    {
                        sql = string.Format("INSERT INTO events (timestamp, type, event) VALUES ('{0}', '{1}', '{2}')", e.mTime.ToString("yyyy-MM-dd HH:mm:ss"), (int)e.mType, e.mEventData);
                        MySqlCommand cmd = new MySqlCommand(sql, mSql);
                        cmd.ExecuteNonQuery();
                    }
                }
                catch (Exception ex)
                {
                    Email.SendErrorEmail(sql + "\n\n" + ex.ToString());
                }

                // Copy the client work list
                mClientWorkQueueLock.WaitOne();
                List <ClientWork> cw = mClientWorkQueue;
                mClientWorkQueue = new List <ClientWork>();
                TimeSpan interval = DateTime.Now - mIntervalStart;
                mIntervalStart = DateTime.Now;
                mClientWorkQueueLock.ReleaseMutex();

                try
                {
                    // Collect information into products
                    Dictionary <string, Product> products = new Dictionary <string, Product>();
                    foreach (ClientWork w in cw)
                    {
                        if (!products.ContainsKey(w.mProductName))
                        {
                            // Add this product
                            Product p = new Product();
                            p.mMember  = GetMemberId(w.mMemberName);
                            p.mProduct = GetProductId(w.mProductName, p.mMember);
                            p.mHashes  = 0;
                            products[w.mProductName] = p;
                        }

                        Product prod = products[w.mProductName];
                        prod.mHashes            += w.mHashes;
                        products[w.mProductName] = prod;
                    }

                    // Write entries into the database for each prodcut
                    string timeString = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss");
                    foreach (KeyValuePair <string, Product> kv in products)
                    {
                        ulong hashrate = (ulong)(kv.Value.mHashes / interval.TotalSeconds);
                        sql = string.Format("INSERT INTO workdata (member_id, product_id, hashrate, timestamp) VALUES ('{0}', '{1}', '{2}', '{3}')", kv.Value.mMember, kv.Value.mProduct, hashrate, timeString);
                        MySqlCommand cmd = new MySqlCommand(sql, mSql);
                        cmd.ExecuteNonQuery();
                    }
                }
                catch (Exception ex)
                {
                    Email.SendErrorEmail(sql + "\n\n" + ex.ToString());
                }

                TimeSpan duration         = DateTime.Now - start;
                double   secondsRemaining = 60 - duration.TotalSeconds;

                if (secondsRemaining < 0)
                {
                    Console.WriteLine("Log thread took {0} seconds, yeilding and going again", (int)duration.TotalSeconds);
                    Thread.Sleep(10);
                }
                else
                {
                    Console.WriteLine("Log Thread sleeping for {0} seconds", (int)secondsRemaining);
                    Thread.Sleep((int)secondsRemaining * 1000);
                }
            }
        }