示例#1
0
        // Called as part of setActivity()
        private async static void getActivity(string _user)
        {
            FileLogger.Log("Calling httpHandler", 3);
            try
            {
                var response = await httpHandler.getActivityFromTimeServer(_user);

                Duration data = await response.Content.ReadAsAsync <Duration>();

                FileLogger.Log("Server Response to getActivity: " + response.StatusCode, 2);
                FileLogger.Log("Server response: " + JsonSerializer.Serialize(data), 1);
                TimeSpan duration;
                TimeSpan timeTilBreak;
                string   trayString = "";


                if (data.nextBreak != -1)
                {
                    // break early warning
                    if (data.freeTimeLeft < 300000 && !breakNotification)
                    {
                        MessageBox.Show("5 minutes before break", "Prompt", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
                        breakNotification = true;
                    }
                    else if (data.freeTimeLeft >= 300000 && breakNotification)
                    {
                        breakNotification = false;
                    }
                    timeTilBreak = TimeSpan.FromMilliseconds(data.freeTimeLeft);
                    trayString  += "Next Break: " + timeTilBreak.ToString() + "\r\n";
                }
                else
                {
                    timeTilBreak = TimeSpan.Zero;
                    FileLogger.Log("No break cofigured", 2);
                }

                // Check if data coming in is negative, in the case of time limits, rather than counters from server
                if (data.total <= 0)
                {
                    duration = TimeSpan.FromMilliseconds(data.total * -1);
                    FileLogger.Log("getActivity data: " + duration.ToString(), 1);
                    trayString += "Total: -" + duration.ToString();
                    LockWorkStation();
                }
                else
                {
                    duration = TimeSpan.FromMilliseconds(data.total);
                    FileLogger.Log("getActivity data: " + duration.ToString(), 1);
                    trayString += "Total: " + duration.ToString();
                }
                MyCustomApplicationContext.setTooltip(trayString);
            } catch (Exception e) {
                FileLogger.Log(e.Message, 1);
            }
        }
示例#2
0
        // Every interval, if system is not idle, post interval time to the server.
        private static void OnTimer(object source, System.Timers.ElapsedEventArgs arg)
        {
            if (!sessionLocked)
            {
                long   idleTime = 0;
                string userName = Environment.UserName;
                //string userName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
                string hostName = Environment.MachineName;

                // Get duration where user has no input (idle time)
                try
                {
                    idleTime = IdleTime.IdleTime.GetIdleTime();
                }
                catch (Exception e)
                {
                    FileLogger.Log(e.Message, 1);
                }

                // Check if any audio is playing, which is used to indicate user is consuming media
                // In that case, poll the server with idle value 0, because we assume the user is not idle.
                if (IsAudioPlaying(GetDefaultRenderDevice()))
                {
                    FileLogger.Log("User is active with audio stream. Polling to server", 1);
                    Activity thisActivity = new Activity(userName, hostName, DateTime.Now, Activity.activityType.idle, interval);
                    try
                    {
                        sendActivity(thisActivity);
                        MyCustomApplicationContext.noError();
                    }
                    catch
                    {
                        MyCustomApplicationContext.setError();
                    }
                }
                // If the idle time is more than the interval, then we can assume that the user is not active
                else if (idleTime < interval)
                // Poll only if idle time is less than the defined poll interval
                {
                    Activity thisActivity = new Activity(userName, hostName, DateTime.Now, Activity.activityType.idle, interval);
                    try
                    {
                        sendActivity(thisActivity);
                        MyCustomApplicationContext.noError();
                    }
                    catch
                    {
                        MyCustomApplicationContext.setError();
                    }
                }
                else
                // No need to send a poll if we are idle > 2x polling interval
                {
                    FileLogger.Log("Ignoring poll, idleTime: " + idleTime, 1);
                }
            }
            else
            {
                FileLogger.Log("Session is locked, skipped polling", 1);
            }
        }