private ClientConfigDTO loadJsonConfig(string configPath)
        {
            ClientConfigDTO clientConfig;

            if (File.Exists(configPath))
            {
                using (StreamReader r = new StreamReader(configPath))
                {
                    string  jsonString = r.ReadToEnd();
                    dynamic json_      = JsonConvert.DeserializeObject <dynamic>(jsonString);
                    clientConfig = new ClientConfigDTO(json_?.ClientsConfig);
                    Console.WriteLine(jsonString);
                }
            }
            else
            {
                throw new Exception($"{configPath} does not exist, must supply config file.");
            }

            return(clientConfig);
        }
        public void startTest(string configPath, string inputFile)
        {
            Credentials     test_credentials = new Credentials("test");
            ClientConfigDTO config_test      = loadJsonConfig(configPath);

            StateManager.Init(test_credentials, config_test);
            m_pMonitor = new ProcessMonitor();

            // if there is no input file it is data collection active run
            if (String.IsNullOrEmpty(inputFile))
            {
                //data collection
                Console.WriteLine("Running in data collection mode");
                run();
            }
            else
            {
                // data analyzer
                Console.WriteLine($"Running in data analyze mode, on file {inputFile}");
                analyze(inputFile);
            }
        }
示例#3
0
        public static string Authenticate(Credentials credentials)
        {
            JObject o    = new JObject();
            string  res_ = "Failed creating session: ";

            try
            {
                o["username"]      = credentials.username;
                o["clientVersion"] = MainWindow.m_sCurrentVersion;
                var     httpContent = new StringContent(o.ToString(), Encoding.UTF8, "application/json");
                string  res         = sendPost(BackendURL + m_Const_startSession, httpContent).Result;
                dynamic response    = null;
                if (res != null)
                {
                    response = JsonConvert.DeserializeObject(res);
                }
                ;
                if (response != null && (bool)response.success)
                {
                    // call
                    credentials.sessionKey = (string)response.data.SessionKey;
                    ClientConfigDTO config       = new ClientConfigDTO(response.data.ClientConfig);
                    bool            versionValid = validateVersion(config.NewestClientVersion);
                    StateManager.Init(credentials, config);
                    var g_config = Utils.getLocalConfig();
                    if (g_config != null)
                    {
                        string webhookUrl = g_config["WebHookURL"];
                        string email      = g_config["Email"];

                        //register local webhhok
                        if (!String.IsNullOrWhiteSpace(webhookUrl))
                        {
                            JObject u = new JObject();
                            u["WebHookURL"]  = webhookUrl;
                            u["SessionName"] = credentials.username;
                            u["SessionKey"]  = credentials.sessionKey;
                            var webHookContent = new StringContent(u.ToString(), Encoding.UTF8, "application/json");
                            sendPost(BackendURL + m_Const_addWebHook, webHookContent);
                        }
                        // register local email
                        if (!String.IsNullOrWhiteSpace(email))
                        {
                            JObject u = new JObject();
                            u["Email"]       = email;
                            u["SessionName"] = credentials.username;
                            u["SessionKey"]  = credentials.sessionKey;
                            var emailContent = new StringContent(u.ToString(), Encoding.UTF8, "application/json");
                            sendPost(BackendURL + m_Const_registerEmail, emailContent);
                        }
                    }
                    res_ = "";
                }
                else if (response != null)
                {
                    res_ += response.message;
                }
                else
                {
                    res_ += "Failed connecting to server";
                }
            }
            catch (Exception exc)
            {
                res_ += "Exception occured.";
                Log.Write("Error occured when trying to authenticate \n " + exc.Message);
                Log.Write(exc.StackTrace);
            }


            return(res_);
        }
示例#4
0
 public static void Init(Credentials creds, ClientConfigDTO config)
 {
     // init
     m_creds  = creds;
     m_config = config;
 }