/// <summary> /// Initializes this client using config file, if config doesn't exist or is invalid default values are used /// </summary> private void InitializeUsingConfigFile() { // Get directory in appdata var directory = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "//Testinator//"; var ip = default(IPAddress); var port = 0; try { // Try to read data from file var fileContent = File.ReadAllText(directory + "ipconfig.txt").Trim(); var separatorIndex = fileContent.IndexOf(';'); if (separatorIndex == -1) { throw new Exception(); } var ipString = fileContent.Substring(0, separatorIndex); var portString = fileContent.Substring(separatorIndex + 1); ip = IPAddress.Parse(ipString); if (!NetworkHelpers.IsPortCorrect(portString)) { throw new Exception(); } port = int.Parse(portString); Initialize(ip, port); } catch { // No need to do anything as network is already loaded with default values } }
/// <summary> /// Starts the server /// </summary> private void StartServer() { // If port is not valid, dont start the server if (!NetworkHelpers.IsPortCorrect(ServerPort)) { // Show a message box with info about it DI.UI.ShowMessage(new MessageBoxDialogViewModel { Title = "Niepoprawne dane!", Message = "Niepoprawny port.", OkText = "Ok" }); return; } // Set network data mServerNetwork.Port = int.Parse(ServerPort); // Start the server mServerNetwork.Start(); UpdateView(); }