private void BtnMoreClick(object sender, RoutedEventArgs e) { string[] ipInfo = null; string fileName = ""; OpenFileDialog fileDialog = new OpenFileDialog { Filter = "json (*.json)|*.json|All files (*.*)|*.*", Title = "Select file", }; if (fileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { if (Regex.IsMatch(fileDialog.SafeFileName, @"w?.json") || Regex.IsMatch(fileDialog.SafeFileName, @"w?.xml")) { fileName = fileDialog.SafeFileName; ipInfo = GlobalProp.GetByFileName(fileDialog.FileName); } } if (ipInfo != null) { if (GetInformation(ipInfo[1], ipInfo[0])) { Regex rx = new Regex(@"([0-9]{1,3}[\.]){3}[0-9]{1,3}"); Match match = rx.Match(fileName); sourceTbox.Text = match.Value; } } }
async private void StartAsync() { string[] file = GlobalProp.IsFileExist() ? await Task.Factory.StartNew(() => GlobalProp.GetFileLocal()) : await Task.Factory.StartNew(() => GetInfoByNet()); if (!(file == null)) { GetInformation(file[0], file[1]); } }
private string[] GetInfoByNet() { string url; if (StartupConfig.cboxCheckedAPI == null) { url = $"https://free.ipwhois.io/json/{GlobalProp.Ip_address}"; } else { url = GlobalProp.LongUrl; } string file = ""; WebRequest request = WebRequest.Create(url); try { using (WebResponse response = request.GetResponse()) { using (Stream stream = response.GetResponseStream()) { using (StreamReader reader = new StreamReader(stream)) { file = reader.ReadToEnd(); } } } if (StartupConfig.isSaveFile) { GlobalProp.SaveFileAsync(GlobalProp.Ip_address, file); } return(new string[] { file, GlobalProp.FileMark }); } catch (WebException) { System.Windows.Forms.MessageBox.Show("Error connection", "Error"); return(null); } }