Ejemplo n.º 1
0
        /// <summary>
        /// Validates Json Web Token.
        /// </summary>
        /// <param name="jsonWebToken">Json Web Token</param>
        /// <returns></returns>
        public bool CheckJsonWebToken(string jsonWebToken)
        {
            var client   = new ServerClient();
            var response = client.GetFromServer(_url, "api/checkAccess", jsonWebToken);

            LocalLogger.Log(response.Content.ReadAsStringAsync().Result);
            return(response.Content.ReadAsAsync <bool>().Result);
        }
Ejemplo n.º 2
0
 public static bool RunApp(string executable, string arguments = null)
 {
     try
     {
         Process.Start(executable, arguments);
         return(false);
     }
     catch (Exception e)
     {
         LocalLogger.Log(nameof(RunApp), e);
         return(true);
     }
 }
Ejemplo n.º 3
0
 public static string PngFileToBase64(string filepath)
 {
     try
     {
         var img    = Image.FromFile(filepath);
         var result = ImageToBase64(img, ImageFormat.Png);
         return(result);
     }
     catch (Exception e)
     {
         LocalLogger.Log(nameof(PngFileToBase64), e);
         return(null);
     }
 }
Ejemplo n.º 4
0
 // Saves object as a json file on disk.
 public static void SerializeToJsonFile(string path, object obj)
 {
     lock (obj)
     {
         var jsonFile = JsonConvert.SerializeObject(obj, Formatting.Indented);
         try
         {
             using (var streamWriter = new StreamWriter(path, false))
             {
                 streamWriter.WriteLine(jsonFile);
             }
         }
         catch (Exception e)
         {
             LocalLogger.Log(nameof(SerializeToJsonFile), e);
         }
     }
 }
Ejemplo n.º 5
0
        public HttpResponseMessage PostToServer(string url, string route, object model, string bearerToken = "")
        {
            try
            {
                using (var client = new HttpClient())
                {
                    if (bearerToken != "")
                    {
                        client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", bearerToken);
                    }

                    var response = client.PostAsJsonAsync($"{url}/{route}", model).Result;
                    return(response);
                }
            }
            catch (Exception e)
            {
                LocalLogger.Log(nameof(PostToServer), e);
                return(null);
            }
        }
Ejemplo n.º 6
0
        public static TokenResponse RenewBearerToken(string url, string username, string password)
        {
            var body = new StringContent($"username={username}&password={password}&grant_type=password");

            try
            {
                using (var client = new HttpClient())
                {
                    LocalLogger.Log("Authorization started");
                    var response = client.PostAsync(url + "token", body).Result;
                    var content  = response.Content.ReadAsAsync <TokenResponse>().Result;
                    LocalLogger.Log("Token: " + content.AccessToken);
                    return(content);
                }
            }
            catch (Exception e)
            {
                LocalLogger.Log("Authorization", e);
                return(null);
            }
        }
Ejemplo n.º 7
0
        public static ProcessDetails GetProcessDetails(int processId)
        {
            var process = Process.GetProcessById(processId);

            try
            {
                return(new ProcessDetails()
                {
                    WindowTitle = process.MainWindowTitle,
                    ProcessId = processId,
                    Description = Process.GetProcessById(processId).MainModule.FileVersionInfo.FileDescription,
                    FileName = Process.GetProcessById(processId).MainModule.FileName,
                    LegalCopyright = Process.GetProcessById(processId).MainModule.FileVersionInfo.LegalCopyright
                });
            }
            catch (Exception e)
            {
                LocalLogger.Log(nameof(GetProcessDetails), e);
                return(new ProcessDetails());
            }
        }
Ejemplo n.º 8
0
        public static void Speak(string text, string languageCodeOrVoiceName = "en-US")
        {
            // Initialize a new instance of the SpeechSynthesizer.
            var voice = Voices.FirstOrDefault(v => v.VoiceInfo.Name == languageCodeOrVoiceName) ?? Voices.FirstOrDefault(v => v.VoiceInfo.Culture.Name == languageCodeOrVoiceName);

            if (voice != null)
            {
                Synth.SelectVoice(voice.VoiceInfo.Name);
            }
            // Configure the audio output.
            Synth.SetOutputToDefaultAudioDevice();
            LocalLogger.Log($"Speaking: {text} using voice: {Synth.Voice.Name}");
            // Speak a string.
            Synth.SpeakAsync(text);
            //try
            //{
            //    TestActions(text);
            //}
            //catch (Exception e)
            //{
            //    LocalLogger.Log(nameof(TestActions), e);
            //}
        }
 public static void Sleep()
 {
     LocalLogger.Log($"Method {nameof(Sleep)} called!");
     SetSuspendState(false, true, true);
 }
Ejemplo n.º 10
0
 public static void Hibernate()
 {
     LocalLogger.Log($"Method {nameof(Hibernate)} called!");
     SetSuspendState(true, true, true);
 }
Ejemplo n.º 11
0
 public static void Lock()
 {
     LocalLogger.Log($"Method {nameof(Lock)} called!");
     LockWorkStation();
 }
Ejemplo n.º 12
0
 public static void LogOut()
 {
     LocalLogger.Log($"Method {nameof(LogOut)} called!");
     ExitWindowsEx(0, 0);
 }
Ejemplo n.º 13
0
 public static void Restart(int seconds = 1)
 {
     LocalLogger.Log($"Method {nameof(Restart)} called!");
     Process.Start("shutdown", $"/r /f /t {seconds}");
 }