private void EditWebServerCommand(object parameter) { if (!(parameter is TreeNodeViewModel treeNode)) { return; } if (!(treeNode.NodePayload is WebServer server)) { return; } // make copy of server settings to rollback changes if needed WebServer serverCopy = server.Copy(); // edit server settings WebServerFormWindow form = new WebServerFormWindow(serverCopy); if (!form.ShowDialog().Value) { return; } if (string.IsNullOrWhiteSpace(serverCopy.Name)) { _ = MessageBox.Show("Не указано имя web сервера!", "DaJet", MessageBoxButton.OK, MessageBoxImage.Error); return; } if (string.IsNullOrWhiteSpace(serverCopy.Address)) { _ = MessageBox.Show("Не указан адрес web сервера!", "DaJet", MessageBoxButton.OK, MessageBoxImage.Error); return; } // check if new server address already exists if (serverCopy.Address != server.Address) { if (WebServerAddressExists(serverCopy)) { _ = MessageBox.Show($"Web сервер \"{serverCopy.Address}\" уже добавлен!", "DaJet", MessageBoxButton.OK, MessageBoxImage.Warning); return; } } // persist server settings changes serverCopy.CopyTo(server); SaveWebSettings(); // show server name and address changes in UI treeNode.NodeText = server.Name; treeNode.NodeToolTip = server.Address; }
private void AddWebServerCommand(object node) { if (!(node is TreeNodeViewModel treeNode)) { return; } if (treeNode.NodeText != HTTP_SERVICES_NODE_NAME) { return; } WebServerFormWindow form = new WebServerFormWindow(); if (!form.ShowDialog().Value) { return; } WebServer server = form.Result; if (string.IsNullOrWhiteSpace(server.Name)) { _ = MessageBox.Show("Не указано имя web сервера!", "DaJet", MessageBoxButton.OK, MessageBoxImage.Error); return; } if (string.IsNullOrWhiteSpace(server.Address)) { _ = MessageBox.Show("Не указан адрес web сервера!", "DaJet", MessageBoxButton.OK, MessageBoxImage.Error); return; } if (WebServerAddressExists(server)) { _ = MessageBox.Show($"Web сервер \"{server.Address}\" уже добавлен!", "DaJet", MessageBoxButton.OK, MessageBoxImage.Warning); return; } WebSettings.WebServers.Add(server); SaveWebSettings(); TreeNodeViewModel serverNode = CreateWebServerNode(treeNode, server); treeNode.TreeNodes.Add(serverNode); treeNode.IsExpanded = true; serverNode.IsSelected = true; }