private void LoginToLCSMenuItem_Click(object sender, EventArgs e) { WebBrowserHelper.FixBrowserVersion(); using (var form = new Login()) { form.ShowDialog(); if (form.Cancelled) { return; } _cookies = GetUriCookieContainer(); if (_cookies == null) { return; } _httpClientHelper = new HttpClientHelper(_cookies) { LcsUrl = _lcsUrl, LcsUpdateUrl = _lcsUpdateUrl }; if (_selectedProject != null) { _httpClientHelper.ChangeLcsProjectId(_selectedProject.Id.ToString()); } changeProjectMenuItem.Enabled = true; cheInstanceContextMenu.Enabled = true; saasInstanceContextMenu.Enabled = true; logoutToolStripMenuItem.Enabled = true; loginToLcsMenuItem.Enabled = false; ChangeProjectMenuItem_Click(null, null); } }
private void MainForm_Load(object sender, EventArgs e) { SetInitialGridSettings(); Instances = JsonConvert.DeserializeObject <List <ProjectInstance> >(Properties.Settings.Default.instances) ?? new List <ProjectInstance>(); Projects = JsonConvert.DeserializeObject <List <LcsProject> >(Properties.Settings.Default.projects) ?? new List <LcsProject>(); if (!string.IsNullOrEmpty(Properties.Settings.Default.cookie)) { _cookies = new CookieContainer(); _cookies.SetCookies(new Uri(_lcsUrl), Properties.Settings.Default.cookie); _cookies.SetCookies(new Uri(_lcsUpdateUrl), Properties.Settings.Default.cookie); _httpClientHelper = new HttpClientHelper(_cookies) { LcsUrl = _lcsUrl, LcsUpdateUrl = _lcsUpdateUrl }; changeProjectMenuItem.Enabled = true; cheInstanceContextMenu.Enabled = true; saasInstanceContextMenu.Enabled = true; loginToLcsMenuItem.Enabled = false; logoutToolStripMenuItem.Enabled = true; _selectedProject = GetLcsProjectFromCookie(); if (_selectedProject != null) { SetLcsProjectText(); refreshMenuItem.Enabled = true; _httpClientHelper.ChangeLcsProjectId(_selectedProject.Id.ToString()); var projectInstance = Instances.FirstOrDefault(x => x.LcsProjectId.Equals(_selectedProject.Id)); if (projectInstance != null) { if (projectInstance.CheInstances != null) { _cheInstancesSource.DataSource = _cheInstancesList = projectInstance.CheInstances; } if (projectInstance.SaasInstances != null) { _saasInstancesSource.DataSource = _saasInstancesList = projectInstance.SaasInstances; } } } } CreateCustomLinksMenuItems(); }
private void ChangeProjectMenuItem_Click(object sender, EventArgs e) { Cursor = Cursors.WaitCursor; using (var form = new ChooseProject()) { form.HttpClientHelper = _httpClientHelper; form.ShowDialog(); if (!form.Cancelled && (form.LcsProject != null)) { Projects = form.Projects; if (_selectedProject == null || form.LcsProject.Id != _selectedProject.Id) { _cheInstancesSource.DataSource = null; _cheInstancesSource.ResetBindings(false); _saasInstancesSource.DataSource = null; _saasInstancesSource.ResetBindings(false); _selectedProject = form.LcsProject; if (!Instances.Exists(x => x.LcsProjectId == _selectedProject.Id)) { var instance = new ProjectInstance() { LcsProjectId = _selectedProject.Id, }; Instances.Add(instance); } } refreshMenuItem.Enabled = true; _httpClientHelper.ChangeLcsProjectId(_selectedProject.Id.ToString()); _cookies = _httpClientHelper.CookieContainer; GetLcsProjectFromCookie(); SetLcsProjectText(); RefreshChe(false); RefreshSaas(false); } } Cursor = Cursors.Default; }
private void OnWorkerDoWork(object sender, DoWorkEventArgs e) { worker.ReportProgress(25, "Initializing LCS connections"); CookieContainer cookies = MainForm.GetUriCookieContainer(); if (cookies == null) { return; } HttpClientHelper httpClientHelper = new HttpClientHelper(cookies) { LcsUrl = URIHandler.LCS_URL, LcsUpdateUrl = URIHandler.LCS_UPDATE_URL, LcsDiagUrl = URIHandler.LCS_DIAG_URL }; if (rdpData.Command.ToLower() == "connectrdp") { worker.ReportProgress(20, "Loading project"); httpClientHelper.ChangeLcsProjectId(rdpData.ProjectId); ProjectData project = httpClientHelper.GetProject(rdpData.ProjectId); projectNameLabel.Invoke(new MethodInvoker(delegate { projectNameLabel.Text = project.Name; })); worker.ReportProgress(50, "Loading cloud-hosted instances"); CloudHostedInstance chInstance = httpClientHelper.GetCheInstances().FirstOrDefault(e => e.DisplayName == rdpData.Environment); if (chInstance != null) { if (chInstance.CanShowRdp) { worker.ReportProgress(80, "Loading connection details"); var rdpList = httpClientHelper.GetRdpConnectionDetails(chInstance); RDPConnectionDetails rdpEntry = null; if (rdpList != null && rdpList.Count > 0) { if (rdpList.Count > 1) { rdpEntry = MainForm.ChooseRdpLogonUser(rdpList); } else { rdpEntry = rdpList.First(); } if (rdpEntry != null) { using (new RdpCredentials(rdpEntry.Address, $"{rdpEntry.Domain}\\{rdpEntry.Username}", rdpEntry.Password)) { var rdcProcess = new Process { StartInfo = { FileName = Environment.ExpandEnvironmentVariables(@"%SystemRoot%\system32\mstsc.exe"), Arguments = "/v " + $"{rdpEntry.Address}:{rdpEntry.Port}" } }; worker.ReportProgress(95, "Starting connection.."); rdcProcess.Start(); } } else { MessageBox.Show($"Operation cancelled", "Operation failed", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show($"Cannot retrieve RDP connection details. This instance is not accessible through RDP or you do not have access to see those details. Check if you have Environment Manager role.", "Operation failed", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show($"Cannot retrieve RDP connection details. This instance is not accessible through RDP or you do not have access to see those details. Check if you have Environment Manager role.", "Operation failed", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show($"Cannot find cloud-hosted instance with ID {rdpData.Environment} on project {project.Name}", "Operation failed", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("Unsupported operation", "Operation failed", MessageBoxButtons.OK, MessageBoxIcon.Error); } }