private void FirstAppLaunch() { try { Directory.CreateDirectory(DEFAULT_DIRECTORY_PATH); IniSettingsInitializationForFirstLaunch(); //Создание файла конфигурации using (FileStream fstream = new FileStream(IniSettings.GetValue("PathToIniFile"), FileMode.OpenOrCreate)) { string contains = "[Main]\n" + "UrlController = " + IniSettings.GetValue("UrlController") + "\n" + "UrlProcedure = " + IniSettings.GetValue("UrlProcedure") + "\n" + "ListenAddress = " + IniSettings.GetValue("ListenAddress") + "\n" + "ListenPort = " + IniSettings.GetValue("ListenPort") + "\n" + "PathToIniFile = " + IniSettings.GetValue("PathToIniFile") + "\n" + "PathToLogFile = " + IniSettings.GetValue("PathToLogFile") + "\n" + "PathToUDPOutputFile = " + IniSettings.GetValue("PathToUDPOutputFile"); byte[] array = Encoding.Default.GetBytes(contains); fstream.Write(array, 0, array.Length); } FillSettingsTextBoxes(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> /// Запуск парсера /// </summary> private void ParserLaunchBtn_Click(object sender, RoutedEventArgs e) { ParserSystem ParserSystem = new ParserSystem(IniSettings.GetValue("UrlController"), IniSettings.GetValue("UrlProcedure")); CancelTokenSourceParser = new CancellationTokenSource(); TokenParser = CancelTokenSourceParser.Token; // Создание задачи для запуска HTTP клиента bool IsDemo = (bool)DemoParserCB.IsChecked; Task HTTPClientTask = new Task(() => ParserSystem.Start(TokenParser, IsDemo)); try { //Запуск HTTP клиента HTTPClientTask.Start(); ParserLaunchBtn.IsEnabled = false; ParserStopBtn.IsEnabled = true; } catch (Exception ex) { Logger.Log(HTTPClientTask.Exception.InnerException.Message, RecordType.ERROR, Source.Parser); } }
/// <summary> /// Запуск UDP клиента /// </summary> private void UDPLaunchBtn_Click(object sender, RoutedEventArgs e) { //ParserSystem ParserSystem = new ParserSystem(IniSettings.GetValue("UrlController"), IniSettings.GetValue("UrlProcedure")); UdpClient UDPClient = new UdpClient(IniSettings.GetValue("ListenAddress"), Convert.ToInt32(IniSettings.GetValue("ListenPort"))); CancelTokenSourceUdp = new CancellationTokenSource(); TokenUdp = CancelTokenSourceUdp.Token; bool IsDemo = (bool)DemoUDPCB.IsChecked; // Создание задачи для запуска HTTP клиента Task UDPClientTask = new Task(() => UDPClient.Start(TokenUdp, IsDemo)); try { //Запуск HTTP клиента UDPClientTask.Start(); UDPLaunchBtn.IsEnabled = false; UDPStopBtn.IsEnabled = true; } catch (Exception ex) { Logger.Log(UDPClientTask.Exception.InnerException.Message, RecordType.ERROR, Source.UDP); } }
private void FillSettingsTextBoxes() { UrlControllerTbx.Text = IniSettings.GetValue("UrlController"); UrlProcedureTbx.Text = IniSettings.GetValue("UrlProcedure"); ListenningAddressTbx.Text = IniSettings.GetValue("ListenAddress"); ListenningPortTbx.Text = IniSettings.GetValue("ListenPort"); PathToLogFileTbx.Text = IniSettings.GetValue("PathToLogFile"); PathToUDPOutputFileTbx.Text = IniSettings.GetValue("PathToUDPOutputFile"); }
public static TwitterApi Login(IniSettings setting, string section) { TwitterApi api = new TwitterApi { setting = setting, section = section }; string consumerKey = Convert.ToString(setting.GetValue(section, "ConsumerKey", string.Empty)); string consumerSecret = Convert.ToString(setting.GetValue(section, "ConsumerSecret", string.Empty)); string accessToken = Convert.ToString(setting.GetValue(section, "AccessToken", string.Empty)); string accessSecret = Convert.ToString(setting.GetValue(section, "AccessSecret", string.Empty)); if (string.IsNullOrWhiteSpace(consumerKey) || string.IsNullOrWhiteSpace(consumerSecret)) { setting.Save(); api.Status = UserStatus.NO_APIKEY; return(api); } if (string.IsNullOrWhiteSpace(accessToken) || string.IsNullOrWhiteSpace(accessSecret)) { api.OAuth = new TwitterOAuth(consumerKey, consumerSecret); TwitterOAuth.TokenPair tokens = api.OAuth.RequestToken(); if (tokens == null) { api.Status = UserStatus.NO_APIKEY; return(api); } api.OAuth.User.Token = tokens.Token; api.OAuth.User.Secret = tokens.Secret; api.Status = UserStatus.LOGIN_REQUESTED; return(api); } api.OAuth = new TwitterOAuth(consumerKey, consumerSecret, accessToken, accessSecret); api.MyUserInfo = api.getMyUserInfo(); api.Status = api.MyUserInfo == null ? UserStatus.INVALID_CREDITIONAL : UserStatus.LOGIN_SUCCESS; return(api); }
/// <summary> /// Изменение общих настроек программы /// </summary> private void ApplyConfBtn_Click(object sender, RoutedEventArgs e) { try { IniSettings.Edit("PathToLogFile", PathToLogFileTbx.Text); IniData["Main"]["PathToLogFile"] = IniSettings.GetValue("PathToLogFile"); IniParser.WriteFile(DEFAULT_SETTINGS_PATH, IniData); } catch (Exception ex) { Logger.Log(ex.Message, RecordType.ERROR, Source.System); } }
/// <summary> /// Изменение настроек парсера /// </summary> private void ApplyParserConfBtn_Click(object sender, RoutedEventArgs e) { try { IniSettings.Edit("UrlController", UrlControllerTbx.Text); IniSettings.Edit("UrlProcedure", UrlProcedureTbx.Text); IniData["Main"]["UrlController"] = IniSettings.GetValue("UrlController"); IniData["Main"]["UrlProcedure"] = IniSettings.GetValue("UrlProcedure"); IniParser.WriteFile(DEFAULT_SETTINGS_PATH, IniData); } catch (Exception ex) { Logger.Log(ex.Message, RecordType.ERROR, Source.Parser); } }
/// <summary> /// Изменение настроек UDP прослушивателя /// </summary> private void ApplyUDPConfBtn_Click(object sender, RoutedEventArgs e) { try { IniSettings.Edit("ListenAddress", ListenningAddressTbx.Text); IniSettings.Edit("ListenPort", ListenningPortTbx.Text); IniSettings.Edit("PathToUDPOutputFile", PathToUDPOutputFileTbx.Text); IniData["Main"]["ListenAddress"] = IniSettings.GetValue("ListenAddress"); IniData["Main"]["ListenPort"] = IniSettings.GetValue("ListenPort"); IniData["Main"]["PathToUDPOutputFile"] = IniSettings.GetValue("PathToUDPOutputFile"); IniParser.WriteFile(DEFAULT_SETTINGS_PATH, IniData); } catch (Exception ex) { Logger.Log(ex.Message, RecordType.ERROR, Source.UDP); } }