public static void Run()
        {
            LocalLogger.Log($"{nameof(TimeLimitsManager)} is running");

            try
            {
                var computer = JsonLocalDatabase.Instance.Computer;

                var userName = SessionManager.GetActive();
                if (string.IsNullOrWhiteSpace(userName))
                {
                    LocalLogger.Log($"User {userName} not found");
                    return;
                }

                var curerentUser = computer.ComputerUsers.FirstOrDefault(u => u.Name == userName);
                var limit        = curerentUser?.DailyTimeLimits?.FirstOrDefault(l => l.Active);
                if (limit == null)
                {
                    LocalLogger.Log($"Time limit for user {userName} not found");
                    return;
                }

                var totalTime        = new TimeSpan();
                var today            = DateTime.Today;
                var logTimeIntervals = computer.LogTimeIntervals
                                       .Where(l => l.ComputerUser == userName && l.StartTime.Date == today);

                totalTime = logTimeIntervals.Aggregate(totalTime, (duration, log) => duration + log.Duration);

                var timeLeft = limit.TimeAmount - totalTime;
                LocalLogger.Log($"User {userName} has limit set to {limit.TimeAmount}, Time used: {totalTime} Time left: {timeLeft}");
                HubService.LogOnPage($"Current user {userName} has limit set to {limit.TimeAmount}, Time used: {totalTime} Time left: {timeLeft}");
                if (timeLeft.Hours == 0 && timeLeft.Minutes == 30)
                {
                    TextToSpeechHelper.Speak($"Because of the time limit set to {limit.TimeAmount.Hours} hours and {limit.TimeAmount.Minutes} minutes, You have {(int)timeLeft.TotalMinutes}  {(timeLeft.Minutes == 1 ? "minute" : "minutes")} left of using the computer today!");
                }
                var reminederMinutes = new[] { 20, 10, 5, 2, 1 };
                if (timeLeft.Hours == 0 && reminederMinutes.Contains(timeLeft.Minutes))
                {
                    TextToSpeechHelper.Speak($"You have {timeLeft.Minutes} {(timeLeft.Minutes == 1 ? "minute":"minutes")} left!");
                }
                if (!(timeLeft.TotalSeconds < 0))
                {
                    return;
                }
                LocalLogger.Log($"Logging off user {userName}");
                TextToSpeechHelper.Speak("End of time, logging off!");
                HubService.LogOnPage($"Logging off..");
                SessionManager.LogOutCurrentUser();
                HubService.LogOnPage($"User {userName} has been logged of");
            }
            catch (Exception e)
            {
                LocalLogger.Log(nameof(TimeLimitsManager), e);
            }
        }
Example #2
0
    private void ConvertTextToSpeech(Activity message)
    {
        Activity initialMessage = message;

        try
        {
            if (message.Type == ActivityTypes.Message)
            {
                if (string.IsNullOrEmpty(message.Speak))
                {
                    if (string.IsNullOrEmpty(message.Text))
                    {
                        if (message.Attachments[0].Content is HeroCard attachment)
                        {
                            message.Speak = TextToSpeechHelper.ConvertTextToSpeechText(attachment.Text);
                        }
                    }
                    else
                    {
                        message.Speak = TextToSpeechHelper.ConvertTextToSpeechText(message.Text);
                    }

                    message.Speak = message.Speak.Trim();

                    if (ignoreList.Where(i => message.Speak.ToLower().StartsWith(i.ToLower())).Count() != 0)
                    {
                        message.Speak = null;
                        ignoredSpeak  = true;
                    }
                }
                else if (string.IsNullOrWhiteSpace(message.Speak))
                {
                    message.Speak = null;
                }

                if ((!string.IsNullOrEmpty(message.Speak) && (message.Speak.EndsWith("?") || message.Speak.StartsWith("Is this correct?"))) ||
                    (!string.IsNullOrEmpty(message.Text) && message.Text.EndsWith("?")))
                {
                    message.InputHint = InputHints.ExpectingInput;
                }

                // IOs won't work with expecting input
                if (message.Recipient.Name.EndsWith(":ios"))
                {
                    message.InputHint = InputHints.AcceptingInput;
                }
            }
        }
        catch (Exception)
        {
            message = initialMessage;
        }
    }
Example #3
0
 public AppCoordinator(AppForm appForm)
 {
     _appForm = appForm;
     keyboardMouseSimulator   = new KeyboardMouseSimulator(this);
     cursorIconManager        = new CursorIconManager(this);
     xmlModifier              = new XMLModifier(this);
     hexListener              = new HexListener(this);
     userCommandsListener     = new UserCommandsListener(this);
     mouseEventListener       = new MouseEventListener(this);
     mouseCoordinator         = new MouseCoordinator();
     recordWindowErrorHandler = new RecordWindowErrorHandler(this);
     this.textToSpeech        = new TextToSpeechHelper();
     javaKiller = new JavaKiller();
     hexWindow  = new HexWindow(this);
 }
Example #4
0
 private static void Speak(string text)
 {
     LogOnPage($"Voice message received: \"{text.Split('|').FirstOrDefault()}\"");
     TextToSpeechHelper.Speak(text.Split('|').FirstOrDefault(), text.Split('|').ElementAtOrDefault(1));
 }
Example #5
0
        //private static void CaptureScreen()
        //{
        //    SessionManager.CaptureScreenOfCurrentUser();
        //    var base64Image = Base64Converter.PngFileToBase64(Path.Combine(SessionManager.CurrentUserAppDataFolder, "ss.an"));
        //    SendImage(base64Image);
        //}

        //private static void SendImage(string base64Image)
        //{
        //    if (HubConnection.State != ConnectionState.Connected) return;

        //    try
        //    {
        //        var computer = JsonLocalDatabase.Instance.Computer;
        //        if (computer.ComputerId != 0)
        //        {
        //            _myHubProxy.Invoke("SendImageToPage", computer.ComputerId, base64Image).ContinueWith(task =>
        //            {
        //                if (!task.IsFaulted) return;
        //                if (task.Exception != null)
        //                    LocalLogger.Log("SendImage", task.Exception);
        //            }).Wait();
        //        }
        //    }
        //    catch (Exception e)
        //    {
        //        LocalLogger.Log(nameof(SendImage), e);
        //    }
        //}

        private static void GetInstalledVoicesList()
        {
            try
            {
                LocalLogger.Log("Return installed voices");
                _myHubProxy.Invoke("ShowIntalledVoices", JsonLocalDatabase.Instance.Computer.ComputerId, TextToSpeechHelper.GetInstalledVoicesList())
                .ContinueWith(
                    task =>
                {
                    if (!task.IsFaulted)
                    {
                        return;
                    }
                    if (task.Exception != null)
                    {
                        LocalLogger.Log(nameof(GetInstalledVoicesList), task.Exception);
                    }
                });
            }
            catch (Exception e)
            {
                LocalLogger.Log(nameof(GetInstalledVoicesList), e);
            }
        }
Example #6
0
    private void ConvertTextToSpeech(Activity message)
    {
        Activity initialMessage = message;

        try
        {
            if (message.Type == ActivityTypes.Message)
            {
                bool ignoredSpeak = false;
                if (string.IsNullOrEmpty(message.Speak))
                {
                    if (string.IsNullOrEmpty(message.Text))
                    {
                        if (message.Attachments[0].Content is HeroCard attachment)
                        {
                            message.Speak = TextToSpeechHelper.ConvertTextToSpeechText(attachment.Text);
                        }
                    }
                    else
                    {
                        message.Speak = TextToSpeechHelper.ConvertTextToSpeechText(message.Text);
                    }

                    message.Speak = message.Speak.Trim();

                    if (ignoreList.Where(i => message.Speak.ToLower().StartsWith(i.ToLower())).Count() != 0)
                    {
                        message.Speak = null;
                        ignoredSpeak  = true;
                    }
                }
                else if (string.IsNullOrWhiteSpace(message.Speak))
                {
                    message.Speak = " ";
                }

                if ((!string.IsNullOrEmpty(message.Speak) && (message.Speak.EndsWith("?") || message.Speak.StartsWith("Is this correct?"))) ||
                    (!string.IsNullOrEmpty(message.Text) && message.Text.EndsWith("?")) ||
                    ignoredSpeak)
                {
                    message.InputHint = InputHints.ExpectingInput;
                }

                // IOs won't work with expecting input
                if (message.Recipient.Name.EndsWith(":ios"))
                {
                    message.InputHint = InputHints.AcceptingInput;
                }
            }

            // Logic needed to increase speech speed.
            // if (!string.IsNullOrEmpty(message.Speak))
            // {
            //    message.Speak = @"<speak version='1.0' " + "xmlns='http://www.w3.org/2001/10/synthesis' xml:lang='en-GB'><prosody rate=\"1.5\">" + message.Speak + "</prosody></speak>";
            // }
        }
        catch (Exception)
        {
            message = initialMessage;
        }
    }