Esempio n. 1
0
        private async void BtnApply_Click(object sender, RoutedEventArgs e)
        {
            if (isProxy)
            {
                string networkName = NetworkName.Text;
                if (networkName == null || networkName.Equals(""))
                {
                    networkName = "Network";
                }

                //TODO replace this with int value verifier
                int minRam, maxRam;
                if (!int.TryParse(NetworkMaxRam.Text, out maxRam))
                {
                    maxRam = 1024;
                }

                if (!int.TryParse(NetworkMinRam.Text, out minRam))
                {
                    minRam = 512;
                }

                JavaSettings javaSettings = new JavaSettings {
                    MinRam = minRam, MaxRam = maxRam
                };
                bool createNetworkSuccess = await ServerManager.Instance.CreateNetworkAsync(networkName, proxyType, javaSettings);
            }
            else
            {
                ServerVersion selectedVersion = (ServerVersion)versionComboBox.SelectedValue;
                //TODO check if inputs are valid / server not existing

                string serverName = ServerName.Text;
                if (serverName == null || serverName.Equals(""))
                {
                    serverName = "Server";
                }

                string worldPath = null;
                if (lastPath != null)
                {
                    WorldValidationInfo valInfo = DirectoryValidator.ValidateWorldDirectory(new DirectoryInfo(lastPath));
                    if (valInfo.IsValid)
                    {
                        worldPath = lastPath;
                    }
                }
                bool createServerSuccess = await ServerManager.Instance.CreateServerAsync(serverName, selectedVersion, viewModel.ServerSettings, new JavaSettings(), worldPath);
            }
            viewModel.GenerateNewSettings();

            //TODO Do something if creating fails
        }
Esempio n. 2
0
        private async void BtnApply_Click(object sender, RoutedEventArgs e)
        {
            CreateBtn.IsEnabled = false;
            char[] illegalDirChars = Path.GetInvalidFileNameChars();
            if (isProxy)
            {
                string networkName        = NetworkName.Text;
                string refinedNetworkName = networkName;
                foreach (char c in networkName)
                {
                    if (illegalDirChars.Contains(c))
                    {
                        refinedNetworkName = refinedNetworkName.Replace(c + "", "");
                    }
                }
                if (refinedNetworkName.Equals(""))
                {
                    refinedNetworkName = "Network";
                }

                //TODO replace this with int value verifier
                int maxRam;
                if (!int.TryParse(NetworkMaxRam.Text, out maxRam))
                {
                    maxRam = 1024;
                }

                JavaSettings javaSettings = new JavaSettings {
                    MaxRam = maxRam
                };
                bool createNetworkSuccess = await ServerManager.Instance.CreateNetworkAsync(refinedNetworkName, proxyType, javaSettings);
            }
            else
            {
                ServerVersion selectedVersion = (ServerVersion)versionComboBox.SelectedValue;
                //TODO check if inputs are valid / server not existing

                string serverName        = ServerName.Text;
                string refinedServerName = serverName;
                foreach (char c in serverName)
                {
                    if (illegalDirChars.Contains(c))
                    {
                        refinedServerName = refinedServerName.Replace(c + "", "");
                    }
                }
                if (refinedServerName.Equals(""))
                {
                    refinedServerName = "Server";
                }

                string worldPath = null;
                if (lastPath != null)
                {
                    WorldValidationInfo valInfo = DirectoryValidator.ValidateWorldDirectory(new DirectoryInfo(lastPath));
                    if (valInfo.IsValid)
                    {
                        worldPath = lastPath;
                    }
                }
                bool createServerSuccess = await ServerManager.Instance.CreateServerAsync(refinedServerName, selectedVersion, viewModel.ServerSettings, new JavaSettings(), worldPath);
            }
            viewModel.GenerateNewSettings();
            CreateBtn.IsEnabled = true;

            //TODO Do something if creating fails
        }