Exemplo n.º 1
0
        private void Calculon()
        {
            bool domouse = true;

            pGina.Plugin.pgSMB2.Roaming ro = new pGina.Plugin.pgSMB2.Roaming();
            long trigger          = 500 * TimeSpan.TicksPerMillisecond;
            long poll             = 60 * 1000 * TimeSpan.TicksPerMillisecond;
            long lastrun          = -1;
            int  sleep_write_lock = Convert.ToInt32(sleep_timer / 10);
            long timer            = 0;

            while (true)
            {
                Thread.Sleep(sleep_timer);

                try
                {
                    if (mouseoverlock.TryEnterReadLock(-1))
                    {
                        if (mouseover)
                        {
                            domouse   = true;
                            mouseover = false;
                        }
                    }
                }
                catch { }
                finally
                {
                    mouseoverlock.ExitReadLock();
                }

                try
                {
                    if (LastEventTriggered_lock.TryEnterWriteLock(sleep_write_lock))
                    {
                        long nowticks = DateTime.UtcNow.Ticks;
                        if (!domouse) // mouseover always force a recalculation
                        {
                            //Program.Log(String.Format("{0} == {1}", LastEventTriggered, lastrun), EventLogEntryType.Information);
                            if (LastEventTriggered == lastrun) // nothing happend
                            {
                                continue;
                            }
                            // es ist was pasiert
                            //Program.Log(String.Format("{0} > {1}", trigger, nowticks - LastEventTriggered), EventLogEntryType.Information);
                            if (trigger > nowticks - LastEventTriggered) // less than 500 ms have passed since the last event
                            {
                                if (timer == 0)                          // set timer to current time
                                {
                                    timer = nowticks;
                                }

                                //Program.Log(String.Format("{0} > {1}", nowticks - timer, poll), EventLogEntryType.Information);
                                if (nowticks - timer < poll) // less than 60 sec have passed since we wait for events to no longer occur
                                {
                                    continue;
                                }
                            }
                        }
                    }
                    else
                    {
                        continue;
                    }
                }
                catch { }
                finally
                {
                    if (LastEventTriggered_lock.IsWriteLockHeld)
                    {
                        LastEventTriggered_lock.ExitWriteLock();
                    }
                }

                if (domouse)
                {
                    try
                    {
                        if (BallonTip_Lock.TryEnterReadLock(0))
                        {
                            notifyIcon1.ShowBalloonTip(1000, "", String.Format("{0}\n{1}", over_max_userprofile, over_max_calculate_text), ToolTipIcon.Info);
                        }
                    }
                    catch { }
                    finally
                    {
                        if (BallonTip_Lock.IsReadLockHeld)
                        {
                            BallonTip_Lock.ExitReadLock();
                        }
                    }
                }
                //Program.Log(String.Format("Calculon lastrun = {0}", lastrun), EventLogEntryType.Information);
                lastrun = LastEventTriggered;
                timer   = 0;

                try
                {
                    if (Calculon_Lock.TryEnterWriteLock(-1))
                    {
                        long uPath_size = ro.GetDirectorySize(proquota.Program.uPath, exclude_dir);
                        if (uPath_size == 0)
                        {
                            continue;
                        }
                        uPath_size = Convert.ToInt64(uPath_size / 1024);
                        bool?over_max_old = over_max;
                        uPath_rest = Program.uPath_size_max - uPath_size;

                        if (uPath_size < Program.uPath_size_max - (Convert.ToInt64(Program.uPath_size_max / 20))) //fits
                        {
                            over_max = null;
                        }
                        else //fits barely
                        {
                            if (uPath_size > Program.uPath_size_max) //oversized
                            {
                                over_max = true;
                            }
                            else
                            {
                                over_max = false;
                            }
                        }

                        if (over_max != over_max_old)
                        {
                            switch (over_max)
                            {
                            case null:
                                notifyIcon1.Icon = new Icon(Properties.Resources._1, 16, 16);
                                notifyIcon1.ShowBalloonTip(1000, "", String.Format("{0}\n{1} {2} {3:0.00} {4} {5}", over_max_userprofile, uPath_rest.ToString(), "KBytes", (double)uPath_rest / 1024, "MBytes", over_max_free), ToolTipIcon.Info);
                                if (msg.IsAlive)
                                {
                                    top.Close();
                                }
                                break;

                            case false:
                                notifyIcon1.Icon = new Icon(Properties.Resources._2, 16, 16);
                                notifyIcon1.ShowBalloonTip(1000, "", String.Format("{0}\n{1} {2} {3:0.00} {4} {5}", over_max_warning_title, uPath_rest.ToString(), "KBytes", (double)uPath_rest / 1024, "MBytes", over_max_free), ToolTipIcon.Info);
                                if (msg.IsAlive)
                                {
                                    top.Close();
                                }
                                break;

                            case true:
                                notifyIcon1.Icon = new Icon(Properties.Resources._3, 16, 16);
                                notifyIcon1.ShowBalloonTip(1000, "", String.Format("{0}\n{1} {2} {3:0.00} {4} {5}", over_max_error_title, uPath_rest.ToString(), "KBytes", (double)uPath_rest / 1024, "MBytes", over_max_exceeded), ToolTipIcon.Info);
                                if (!msg.IsAlive)
                                {
                                    msg = new Thread(() => MsgBox(over_max_error_text.Replace("\\n", System.Environment.NewLine), over_max_error_title));
                                    msg.Start();
                                }
                                break;
                            }
                            domouse = false;
                        }
                        else
                        {
                            if (domouse)
                            {
                                //Program.Log("mouseover", EventLogEntryType.Information);
                                switch (over_max)
                                {
                                case null:
                                    notifyIcon1.ShowBalloonTip(1000, "", String.Format("{0}\n{1} {2} {3:0.00} {4} {5}", over_max_userprofile, uPath_rest.ToString(), "KBytes", (double)uPath_rest / 1024, "MBytes", over_max_free), ToolTipIcon.Info);
                                    break;

                                case false:
                                    notifyIcon1.ShowBalloonTip(1000, "", String.Format("{0}\n{1} {2} {3:0.00} {4} {5}", over_max_warning_title, uPath_rest.ToString(), "KBytes", (double)uPath_rest / 1024, "MBytes", over_max_free), ToolTipIcon.Info);
                                    break;

                                case true:
                                    notifyIcon1.ShowBalloonTip(1000, "", String.Format("{0}\n{1} {2} {3:0.00} {4} {5}", over_max_error_title, uPath_rest.ToString(), "KBytes", (double)uPath_rest / 1024, "MBytes", over_max_exceeded), ToolTipIcon.Info);
                                    break;
                                }
                                domouse = false;
                            }
                        }
                    }
                }
                catch { }
                finally
                {
                    Calculon_Lock.ExitWriteLock();
                }
            }
        }
Exemplo n.º 2
0
        private void Calculon()
        {
            bool domouse = true;
            pGina.Plugin.pgSMB2.Roaming ro = new pGina.Plugin.pgSMB2.Roaming();
            long trigger = 500 * TimeSpan.TicksPerMillisecond;
            long poll = 60 * 1000 * TimeSpan.TicksPerMillisecond;
            long lastrun = -1;
            int sleep_write_lock = Convert.ToInt32(sleep_timer/10);
            long timer = 0;

            while (true)
            {
                Thread.Sleep(sleep_timer);

                try
                {
                    if (mouseoverlock.TryEnterReadLock(-1))
                    {
                        if (mouseover)
                        {
                            domouse = true;
                            mouseover = false;
                        }
                    }
                }
                catch { }
                finally
                {
                    mouseoverlock.ExitReadLock();
                }

                try
                {
                    if (LastEventTriggered_lock.TryEnterWriteLock(sleep_write_lock))
                    {
                        long nowticks = DateTime.UtcNow.Ticks;
                        if (!domouse) // mouseover always force a recalculation
                        {
                            //Program.Log(String.Format("{0} == {1}", LastEventTriggered, lastrun), EventLogEntryType.Information);
                            if (LastEventTriggered == lastrun) // nothing happend
                            {
                                continue;
                            }
                            // es ist was pasiert
                            //Program.Log(String.Format("{0} > {1}", trigger, nowticks - LastEventTriggered), EventLogEntryType.Information);
                            if (trigger > nowticks - LastEventTriggered) // less than 500 ms have passed since the last event
                            {
                                if (timer == 0) // set timer to current time
                                {
                                    timer = nowticks;
                                }

                                //Program.Log(String.Format("{0} > {1}", nowticks - timer, poll), EventLogEntryType.Information);
                                if (nowticks - timer < poll) // less than 60 sec have passed since we wait for events to no longer occur
                                {
                                    continue;
                                }
                            }
                        }
                    }
                    else
                    {
                        continue;
                    }
                }
                catch { }
                finally
                {
                    if (LastEventTriggered_lock.IsWriteLockHeld)
                    {
                        LastEventTriggered_lock.ExitWriteLock();
                    }
                }

                if (domouse)
                {
                    try
                    {
                        if (BallonTip_Lock.TryEnterReadLock(0))
                        {
                            notifyIcon1.ShowBalloonTip(1000, "", String.Format("{0}\n{1}", over_max_userprofile, over_max_calculate_text), ToolTipIcon.Info);
                        }
                    }
                    catch { }
                    finally
                    {
                        if (BallonTip_Lock.IsReadLockHeld)
                        {
                            BallonTip_Lock.ExitReadLock();
                        }
                    }
                }
                //Program.Log(String.Format("Calculon lastrun = {0}", lastrun), EventLogEntryType.Information);
                lastrun = LastEventTriggered;
                timer = 0;

                try
                {
                    if (Calculon_Lock.TryEnterWriteLock(-1))
                    {
                        long uPath_size = ro.GetDirectorySize(proquota.Program.uPath, exclude_dir);
                        if (uPath_size == 0)
                        {
                            continue;
                        }
                        uPath_size = Convert.ToInt64(uPath_size / 1024);
                        bool? over_max_old = over_max;
                        uPath_rest = Program.uPath_size_max - uPath_size;

                        if (uPath_size < Program.uPath_size_max - (Convert.ToInt64(Program.uPath_size_max / 20))) //fits
                        {
                            over_max = null;
                        }
                        else //fits barely
                        {
                            if (uPath_size > Program.uPath_size_max) //oversized
                            {
                                over_max = true;
                            }
                            else
                            {
                                over_max = false;
                            }
                        }

                        if (over_max != over_max_old)
                        {
                            switch (over_max)
                            {
                                case null:
                                    notifyIcon1.Icon = new Icon(Properties.Resources._1, 16, 16);
                                    notifyIcon1.ShowBalloonTip(1000, "", String.Format("{0}\n{1} {2} {3:0.00} {4} {5}", over_max_userprofile, uPath_rest.ToString(), "KBytes", (double)uPath_rest / 1024, "MBytes", over_max_free), ToolTipIcon.Info);
                                    if (msg.IsAlive)
                                    {
                                        top.Close();
                                    }
                                    break;
                                case false:
                                    notifyIcon1.Icon = new Icon(Properties.Resources._2, 16, 16);
                                    notifyIcon1.ShowBalloonTip(1000, "", String.Format("{0}\n{1} {2} {3:0.00} {4} {5}", over_max_warning_title, uPath_rest.ToString(), "KBytes", (double)uPath_rest / 1024, "MBytes", over_max_free), ToolTipIcon.Info);
                                    if (msg.IsAlive)
                                    {
                                        top.Close();
                                    }
                                    break;
                                case true:
                                    notifyIcon1.Icon = new Icon(Properties.Resources._3, 16, 16);
                                    notifyIcon1.ShowBalloonTip(1000, "", String.Format("{0}\n{1} {2} {3:0.00} {4} {5}", over_max_error_title, uPath_rest.ToString(), "KBytes", (double)uPath_rest / 1024, "MBytes", over_max_exceeded), ToolTipIcon.Info);
                                    if (!msg.IsAlive)
                                    {
                                        msg = new Thread(() => MsgBox(over_max_error_text.Replace("\\n", System.Environment.NewLine), over_max_error_title));
                                        msg.Start();
                                    }
                                    break;
                            }
                            domouse = false;
                        }
                        else
                        {
                            if (domouse)
                            {
                                //Program.Log("mouseover", EventLogEntryType.Information);
                                switch (over_max)
                                {
                                    case null:
                                        notifyIcon1.ShowBalloonTip(1000, "", String.Format("{0}\n{1} {2} {3:0.00} {4} {5}", over_max_userprofile, uPath_rest.ToString(), "KBytes", (double)uPath_rest / 1024, "MBytes", over_max_free), ToolTipIcon.Info);
                                        break;
                                    case false:
                                        notifyIcon1.ShowBalloonTip(1000, "", String.Format("{0}\n{1} {2} {3:0.00} {4} {5}", over_max_warning_title, uPath_rest.ToString(), "KBytes", (double)uPath_rest / 1024, "MBytes", over_max_free), ToolTipIcon.Info);
                                        break;
                                    case true:
                                        notifyIcon1.ShowBalloonTip(1000, "", String.Format("{0}\n{1} {2} {3:0.00} {4} {5}", over_max_error_title, uPath_rest.ToString(), "KBytes", (double)uPath_rest / 1024, "MBytes", over_max_exceeded), ToolTipIcon.Info);
                                        break;
                                }
                                domouse = false;
                            }
                        }
                    }
                }
                catch { }
                finally
                {
                    Calculon_Lock.ExitWriteLock();
                }
            }
        }