Esempio n. 1
0
        public TickTrayForm()
        {
            this.Visible = false;
            this.Icon    = resources.stock_lock_32;

            trayMenu = new ContextMenu();
            trayMenu.MenuItems.Add("Neustarten", OnReload);
            trayMenu.MenuItems.Add("Zeitbegrenzung einrichten...", OnEdit);
            trayMenu.MenuItems.Add("Aktuellen Verbrauch anzeigen...", OnView);
            trayMenu.MenuItems.Add("-");
            trayMenu.MenuItems.Add("Beenden", OnExit);

            trayIcon             = new NotifyIcon();
            trayIcon.Icon        = resources.stock_lock_16;
            trayIcon.MouseClick += ShowBallonInfo;
            //trayIcon.MouseMove += ShowBallonInfo;
            trayIcon.ContextMenu = trayMenu;
            trayIcon.Visible     = true;

            configuration = TickConfiguration.Instance;
            dataFile      = new TickDataFile(configuration.DataFile);

            timer          = new Timer();
            timer.Enabled  = true;
            timer.Interval = TIMER_INTERVAL;
            timer.Tick    += HandleTimerTick;
        }
Esempio n. 2
0
        private void runShutdownCommand()
        {
            TickConfiguration configuration     = TickConfiguration.Instance;
            string            shutdownCommand   = configuration.ShutdownCommand;
            string            shutdownArguments = configuration.ShutdownArguments;

            Process.Start(shutdownCommand, shutdownArguments);
        }
Esempio n. 3
0
        public Editor(TickConfiguration configuration)
        {
            this.configuration = configuration;
            this.Icon          = resources.stock_lock_32;
            this.Size          = new Size(700, 400);
            this.MinimumSize   = new Size(400, 300);
            this.Text          = "Zeitbegrenzung";
            this.Closing      += OnFormClosing;

            createUI();
            loadData();
        }
Esempio n. 4
0
 private void OnEdit(object sender, EventArgs e)
 {
     try {
         Editor editor = new Editor(configuration);
         editor.ShowDialog();
     } catch (Exception ex) {
         MessageBox.Show(ex.Message, "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Error);
     } finally {
         configuration = TickConfiguration.Instance;
         HandleTimerTick(null, null);
     }
 }
Esempio n. 5
0
        public Viewer(TickConfiguration configuration, TickDataFile dataFile)
        {
            this.configuration = configuration;
            this.dataFile      = dataFile;
            this.Icon          = resources.stock_lock_32;
            this.Size          = new Size(600, 400);
            this.MinimumSize   = new Size(400, 300);
            this.Text          = "Zeitbegrenzung";

            createUI();
            loadData();
        }
Esempio n. 6
0
 private void loadConfig()
 {
     try {
         TickConfiguration config = TickConfiguration.Instance;
         interval     = config.TickInterval;
         dataFileName = config.DataFile;
     }
     catch (Exception ex) {
         Console.WriteLine(ex.Message);
         if (ex.InnerException != null)
         {
             Console.WriteLine(ex.InnerException.Message);
         }
         interval     = DEFAULT_INTERVAL;
         dataFileName = getDefaultDataFileName();
     }
 }
Esempio n. 7
0
        public void tick(object stateObject)
        {
            dataFile.load();
            List <string>     loggedInUsers = GetLoggedInUsers();
            DateTime          today         = DateTime.Now.Date;
            TickConfiguration configuration = TickConfiguration.Instance;

            foreach (var user in loggedInUsers)
            {
                var configUser = configuration.Users[user] as TickUserElement;
                if (configUser != null)
                {
                    int dayOfWeek = (int)today.DayOfWeek;
                    if (dayOfWeek == 0)
                    {
                        dayOfWeek = 7;
                    }
                    int maxMinutes = configUser[dayOfWeek];
                    if (configUser.Exceptions != null)
                    {
                        if (configUser.Exceptions[today] != null)
                        {
                            maxMinutes = configUser.Exceptions[today].Minutes;
                        }
                    }
                    var userRecord = dataFile.findUserRecord(user, today);
                    if (userRecord == null)
                    {
                        userRecord = dataFile.createTickRecord(user, today);
                    }
                    userRecord.Minutes += interval;
                    Console.WriteLine(String.Format("Benutzer {0}: {1} Minuten von {2} sind vorbei", user, userRecord.Minutes, maxMinutes));
                    if (userRecord.Minutes > maxMinutes)
                    {
                        runShutdownCommand();
                    }
                }
            }
            dataFile.save();
        }
Esempio n. 8
0
 private void OnReload(object sender, EventArgs e)
 {
     configuration = TickConfiguration.Instance;
     HandleTimerTick(null, null);
 }