示例#1
0
        private string GetBrowsCap()
        {
            string jsonpath = localappdata + "\\logextractor\\browscap.json";

            if (File.Exists(jsonpath))
            {
                try
                {
                    string json = File.ReadAllText(jsonpath);
                    return(json);
                }
                catch (Exception e) {
                    MessageBag msgbag = new MessageBag();
                    msgbag.AddError(e.Message);
                    msgbag.PrintErrors();
                }
                return(null);
            }
            else
            {
                if (!local_access)
                {
                    return(null);
                }

                try
                {
                    HttpClient client = new HttpClient();
                    System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
                    client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
                    var response = client.GetAsync("https://10.19.214.112/browscap.json").Result;
                    if (response.IsSuccessStatusCode)
                    {
                        string json = response.Content.ReadAsStringAsync().Result;
                        if (json != null)
                        {
                            DirectoryInfo dir = Directory.CreateDirectory(localappdata + "\\logextractor");
                            if (dir.Exists)
                            {
                                File.AppendAllText(jsonpath, json);
                                return(json);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    MessageBag msgbag = new MessageBag();
                    msgbag.AddError(e.Message);
                    msgbag.PrintErrors();
                }
                return(null);
            }
        }
示例#2
0
 public void LogLine(string line)
 {
     try
     {
         File.AppendAllText(logpath, line + Environment.NewLine);
     }
     catch (Exception e)
     {
         MessageBag msgbag = new MessageBag();
         msgbag.AddError(e.Message);
         msgbag.PrintErrors();
     }
 }