internal void Start(Business.Server server, SetStatusLabelDelegate setStatusLabelDelegate) { string userName = null; string password = null; if (server.UseImpersonation == true) { userName = server.UserName; password = Encryption.Decrypt(server.Password); } List <WmiService> services = WmiService.GetAllServices(server.ServerName, userName, password, "Name = '" + this.ServiceName + "'"); foreach (WmiService service in services) { setStatusLabelDelegate("Starting " + service.DisplayName); ReturnValue returnValue; if (service.State != State.Running && service.State != State.StartPending) { if ((returnValue = WmiService.Start(server.ServerName, userName, password, service.Name)) != ReturnValue.Success) { throw new Exception("Couldn't start service: " + service.DisplayName + ", the result was: " + returnValue); } } } setStatusLabelDelegate("Ready."); }
private void tsmiRestartService_Click(object sender, EventArgs e) { if (tvManager.SelectedNode == null || tvManager.SelectedNode.Tag is Business.Instance == false) { return; } Business.Instance instance = (Business.Instance)tvManager.SelectedNode.Tag; Business.Server server = (Business.Server)tvManager.SelectedNode.Parent.Tag; if (MessageBox.Show("Would you like to start the service?", "Are you sure?", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { Cursor = Cursors.WaitCursor; try { instance.Stop(server, SetStatusLabel); Thread.Sleep(1000); instance.Start(server, SetStatusLabel); _instanceMonitor.RefreshServerStatistics(); } finally { Cursor = Cursors.Default; } ResetInstanceMonitor(); } }
private void tsmiRedeployUpdate_Click(object sender, EventArgs e) { if (tvManager.SelectedNode == null || tvManager.SelectedNode.Tag is Business.Server == false) { return; } Business.Server server = (Business.Server)tvManager.SelectedNode.Tag; if (MessageBox.Show("Would you like to update " + server.ServerName + " with your copy of MemCacheD?\n(This will restart all currently running instances of MemCacheD on this server.)", "Update MemCacheD", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { Cursor = Cursors.WaitCursor; try { foreach (Business.Instance instance in server.Instances) { SetStatusLabel("Stopping instance: " + instance.DisplayName + " on server: " + server.ServerName); instance.Stop(server, SetStatusLabel); } List <string> pushedImages = new List <string>(); foreach (Business.Instance instance in server.Instances) { if (pushedImages.Contains(instance.ImageBasePath) == false) { SetStatusLabel("Sending new software version to server: " + server.ServerName); server.EnsureExecutableIsAvailabeOnServer(instance.ImageBasePath, true); pushedImages.Add(instance.ImageBasePath); } } foreach (Business.Instance instance in server.Instances) { SetStatusLabel("Starting instance: " + instance.DisplayName + " on server: " + server.ServerName); instance.Start(server, SetStatusLabel); } ResetInstanceMonitor(); SetStatusLabel("Refreshing stats."); _instanceMonitor.RefreshServerStatistics(); } finally { SetStatusLabel("Ready."); Cursor = Cursors.Default; } } }
internal void RemoveFromServer(Business.Server server, SetStatusLabelDelegate setStatusLabelDelegate) { string userName = null; string password = null; if (server.UseImpersonation == true) { userName = server.UserName; password = Encryption.Decrypt(server.Password); } List <WmiService> services = WmiService.GetAllServices(server.ServerName, userName, password, "Name = '" + this.ServiceName + "'"); // Saftey in case we get too many services back, we don't want to delete them all... if (services.Count > 20) { StringBuilder servicesToRemove = new StringBuilder("This action will remove the following services, are you sure?\n"); foreach (WmiService service in services) { servicesToRemove.AppendFormat("\n{0}", service.DisplayName); } if (MessageBox.Show(servicesToRemove.ToString(), "Are you sure?", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel) { return; } } foreach (WmiService service in services) { setStatusLabelDelegate("Removing " + service.DisplayName); ReturnValue returnValue; if (service.State != State.Stopped) { if ((returnValue = WmiService.Stop(server.ServerName, userName, password, service.Name)) != ReturnValue.Success) { throw new Exception("Couldn't stop service: " + service.DisplayName + ", the result was: " + returnValue); } } if ((returnValue = WmiService.Delete(server.ServerName, userName, password, service.Name)) != ReturnValue.Success) { throw new Exception("Couldn't remove service: " + service.DisplayName + ", the result was: " + returnValue); } } setStatusLabelDelegate("Ready."); }
public void Edit(MemCacheDManager.Business.EditableEntityBase entityToEdit, MemCacheDManager.Business.EditableEntityBase parentEntity) { _instance = (Business.Instance)entityToEdit; _server = (Business.Server)parentEntity; txtInstanceName.Text = _instance.DisplayName; txtChunkSizeGrowthFactor.Text = _instance.ChunkSizeGrowthFactor.ToString(); txtDefaultKeySize.Text = _instance.DefaultKeySize.ToString(); chkMaximizeCoreFile.Checked = _instance.MaximizeCoreFile; txtMaximumConnections.Text = _instance.MaximumConnections.ToString(); txtMemoryLimit.Text = _instance.MemoryLimit.ToString(); txtTcpPort.Text = _instance.TcpPort.ToString(); if (_instance.IpAddress != null && _instance.IpAddress != String.Empty) { chkUseSpecificIPAddress.Checked = true; txtIpAddress.Text = _instance.IpAddress; } else { chkUseSpecificIPAddress.Checked = false; txtIpAddress.Text = ""; } if (_instance.UdpPort > 0) { chkUseUDP.Checked = true; txtUdpPort.Text = _instance.UdpPort.ToString(); } else { chkUseUDP.Checked = false; txtUdpPort.Text = String.Empty; } chkUseManagedInstance.Checked = _instance.UseManagedInstance; btnApply.Enabled = false; if (_instance != null) { btnCancel.Enabled = false; } else { btnCancel.Enabled = true; } }
void OnServerDetailsSave(Business.Server server) { LoadUI(); foreach (TreeNode node in tvManager.Nodes) { if (node.Tag == server) { tvManager.SelectedNode = node; break; } } tvManager.Focus(); }
public void CreateNew(Business.EditableEntityBase parent) { _instance = null; _server = (Business.Server)parent; txtInstanceName.Text = ""; int newTcpPort = 11211; foreach (Business.Instance instance in _server.Instances) { if (instance.TcpPort >= newTcpPort) newTcpPort = instance.TcpPort + 1; } txtTcpPort.Text = newTcpPort.ToString(); btnApply.Enabled = false; }
public void CreateNew(Business.EditableEntityBase parent) { _instance = null; _server = (Business.Server)parent; txtInstanceName.Text = ""; int newTcpPort = 11211; foreach (Business.Instance instance in _server.Instances) { if (instance.TcpPort >= newTcpPort) { newTcpPort = instance.TcpPort + 1; } } txtTcpPort.Text = newTcpPort.ToString(); btnApply.Enabled = false; }
private void deleteInstanceToolStripMenuItem_Click(object sender, EventArgs e) { if (MessageBox.Show("Are you sure you wish to remove " + tvManager.SelectedNode.Text + " from this server?", "Are you sure?", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { try { this.Cursor = Cursors.WaitCursor; Business.Instance instance = (Business.Instance)tvManager.SelectedNode.Tag; Business.Server server = (Business.Server)tvManager.SelectedNode.Parent.Tag; instance.RemoveFromServer(server, SetStatusLabel); server.Instances.Remove(instance); _serverConfiguration.Save(Configuration.Default.LastConfigFile); LoadUI(); } finally { this.Cursor = Cursors.Default; } } }
public void Edit(Business.EditableEntityBase entityToEdit, Business.EditableEntityBase parentEntity) { Business.Server server = (Business.Server)entityToEdit; txtServerName.Text = server.ServerName; chkUseImpersonation.Checked = server.UseImpersonation; txtUserName.Text = server.UserName; if (server.BinaryPath != null && server.BinaryPath != String.Empty) { txtBinaryPath.Text = server.BinaryPath; } if (server.Password.Length > 0) { txtPassword.Text = Encryption.Decrypt(server.Password); } else { txtPassword.Text = ""; } _server = server; btnApply.Enabled = false; if (_server == null) { btnCancel.Enabled = true; btnAddInstance.Enabled = false; } else { btnCancel.Enabled = false; btnAddInstance.Enabled = true; } }
private void refreshToolStripMenuItem_Click(object sender, EventArgs e) { if (tvManager.SelectedNode == null || tvManager.SelectedNode.Tag is Business.Server == false) { return; } Business.Server server = (Business.Server)tvManager.SelectedNode.Tag; tvManager.SelectedNode.Nodes.Clear(); try { server.ReadInstancesFromServer(); _serverConfiguration.Save(Configuration.Default.LastConfigFile); } catch (Exception ex) { MessageBox.Show("There was an error reading the MemCacheD instances from the server.\n\n" + ex.Message); } LoadUI(); }
public void Edit(MemCacheDManager.Business.EditableEntityBase entityToEdit, MemCacheDManager.Business.EditableEntityBase parentEntity) { _instance = (Business.Instance)entityToEdit; _server = (Business.Server)parentEntity; txtInstanceName.Text = _instance.DisplayName; txtChunkSizeGrowthFactor.Text = _instance.ChunkSizeGrowthFactor.ToString(); txtDefaultKeySize.Text = _instance.DefaultKeySize.ToString(); chkMaximizeCoreFile.Checked = _instance.MaximizeCoreFile; txtMaximumConnections.Text = _instance.MaximumConnections.ToString(); txtMemoryLimit.Text = _instance.MemoryLimit.ToString(); txtTcpPort.Text = _instance.TcpPort.ToString(); if (_instance.IpAddress != null && _instance.IpAddress != String.Empty) { chkUseSpecificIPAddress.Checked = true; txtIpAddress.Text = _instance.IpAddress; } else { chkUseSpecificIPAddress.Checked = false; txtIpAddress.Text = ""; } if (_instance.UdpPort > 0) { chkUseUDP.Checked = true; txtUdpPort.Text = _instance.UdpPort.ToString(); } else { chkUseUDP.Checked = false; txtUdpPort.Text = String.Empty; } chkUseManagedInstance.Checked = _instance.UseManagedInstance; btnApply.Enabled = false; if(_instance != null) btnCancel.Enabled = false; else btnCancel.Enabled = true; }
//private string _serviceUserName; //private string _servicePassword; internal void UpdateInstanceOnServer(Business.Server server, SetStatusLabelDelegate setStatusLabelDelegate) { //ImpersonateUser impersonateUser = null; try { //if (server.UseImpersonation == true) //{ // setStatusLabelDelegate("Impersonating user: "******"Checking MemCacheD.exe on remote server."); string binaryPath = server.EnsureExecutableIsAvailabeOnServer(false); string userName = null; string password = null; if (server.UseImpersonation == true) { userName = server.UserName; password = Encryption.Decrypt(server.Password); } setStatusLabelDelegate("Updating service on remote server."); WmiService.CreateOrUpdate(server.ServerName, userName, password, this.ServiceName, this.DisplayName, this.CreateImagePath(), StartMode.Auto, null, null); } finally { //if (impersonateUser != null && impersonateUser.IsImpersonating == true) // impersonateUser.Undo(); } /* * string description = Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Services\" + _serviceController.ServiceName).GetValue("Description").ToString(); * string imagePath = Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Services\" + _serviceController.ServiceName).GetValue("ImagePath").ToString(); * string newImagePath = imagePath.Substring(0, imagePath.LastIndexOf("memcached.exe") + ((string)("memcached.exe")).Length); * * int tcpPort; * if (int.TryParse(txtTcpPort.Text, out tcpPort) == true) * newImagePath += " -p " + tcpPort; * * int udpPort; * if (int.TryParse(txtUdpPort.Text, out udpPort) == true) * newImagePath += " -U " + udpPort; * * if (chkMaximizeCoreFile.Checked == true) * newImagePath += " -r"; * * int maxMemory; * if (int.TryParse(txtMemoryLimit.Text, out maxMemory) == true) * newImagePath += " -m " + maxMemory; * * Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Services\" + _serviceController.ServiceName, true).SetValue("ImagePath", newImagePath); * * Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Services\" + _serviceController.ServiceName, true).SetValue("DisplayName", txtInstanceName.Text); * * bool requiresRestart = false; * if (_serviceController.Status == ServiceControllerStatus.Running) * { * requiresRestart = true; * lblStatus.Text = "Stopping " + txtInstanceName.Text; * Refresh(); * * _serviceController.Stop(); * } * * lblStatus.Text = "Removing " + _serviceController.DisplayName; * Refresh(); * ServiceUtility.UninstallService(_serviceController.ServiceName); * * lblStatus.Text = "Reinstalling " + txtInstanceName.Text; * Refresh(); * ServiceUtility.InstallService(_serviceController.ServiceName, txtInstanceName.Text, description, newImagePath); * * if (requiresRestart == true) * { * lblStatus.Text = "Starting " + txtInstanceName.Text; * Refresh(); * _serviceController.Start(); * } * * lblStatus.Text = "Ready."; * */ }
private void EditServer(Business.Server server) { TryToChangeView(server, null, _serverDetails); }