Beispiel #1
0
        /// <summary>
        /// Load data from database
        /// </summary>
        /// <param name="parameter">Not used, only for GUI binding</param>
        private void LoadData(object parameter)
        {
            try
            {
                // Single CM is updated, only update that one CM
                if (parameter is VibesCm cmChanged)
                {
                    using (DataContext context = new DataContext())
                    {
                        VibesCm newCm = context.HostCms.Where(c => c.Id == cmChanged.Id).Include(c => c.DeploymentProperties).Include(c => c.VibesHost).FirstOrDefault().DeepCopy();
                        newCm.CmStatus = CmStates.Updated;

                        if (CmsDisplayCommOne.Contains(cmChanged))
                        {
                            CmsDisplayCommOne.Remove(CmsDisplayCommOne.Single(c => c.Id == cmChanged.Id));
                            CmsDisplayCommOne.Add(newCm);
                            SelectedCmCommOne = newCm;
                        }
                        if (CmsDisplayCommTwo.Contains(cmChanged))
                        {
                            CmsDisplayCommTwo.Remove(CmsDisplayCommTwo.Single(c => c.Id == cmChanged.Id));
                            CmsDisplayCommTwo.Add(newCm);
                            SelectedCmCommTwo = newCm;
                        }
                        return;
                    }
                }

                // Comm1
                CmsDisplayCommOne.Clear();
                LoadCmForSwap(CmsDisplayCommOne, HostTypes.COMM1);
                SelectedCmCommOne = CmsDisplayCommOne.FirstOrDefault();
                // Comm2
                CmsDisplayCommTwo.Clear();
                LoadCmForSwap(CmsDisplayCommTwo, HostTypes.COMM2);
                SelectedCmCommTwo = CmsDisplayCommTwo.FirstOrDefault();
            }
            catch (Exception ex)
            {
                LogAndReportException(ex, "Error loading data to GUI", true);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Event handler for a completed SSH command
        /// Will update GUI for the CM changed
        /// </summary>
        /// <param name="sender">Sender of event, expected to be null</param>
        /// <param name="e">CmHelperEventArgs with relevant details</param>
        private void OnCmCommandComplete(object sender, CmHelperEventArgs e)
        {
            try
            {
                // This VM is not the sender, return
                if (e.SubscriberHashCode != GetHashCode())
                {
                    return;
                }

                // Set CM Status
                if (CmsDisplayCommOne.Contains(e.CmChanged))
                {
                    switch (e.CmStatus)
                    {
                    case HttpStatusCode.OK:
                        CmsDisplayCommOne.Single(c => c.Id == e.CmChanged.Id).CmStatus = CmStates.Alive;
                        break;

                    case HttpStatusCode.ServiceUnavailable:
                        CmsDisplayCommOne.Single(c => c.Id == e.CmChanged.Id).CmStatus = CmStates.Offline;
                        break;

                    case HttpStatusCode.NoContent:
                        CmsDisplayCommOne.Single(c => c.Id == e.CmChanged.Id).CmStatus = CmStates.Altered;
                        break;

                    case HttpStatusCode.Continue:
                        CmsDisplayCommOne.Single(c => c.Id == e.CmChanged.Id).CmStatus = CmStates.Updated;
                        break;

                    default:
                        CmsDisplayCommOne.Single(c => c.Id == e.CmChanged.Id).CmStatus = CmStates.Unchecked;
                        PollCmAsync(CmsDisplayCommOne.Single(c => c.Id == e.CmChanged.Id));
                        break;
                    }
                }
                else if (CmsDisplayCommTwo.Contains(e.CmChanged))
                {
                    switch (e.CmStatus)
                    {
                    case HttpStatusCode.OK:
                        CmsDisplayCommTwo.Single(c => c.Id == e.CmChanged.Id).CmStatus = CmStates.Alive;
                        break;

                    case HttpStatusCode.ServiceUnavailable:
                        CmsDisplayCommTwo.Single(c => c.Id == e.CmChanged.Id).CmStatus = CmStates.Offline;
                        break;

                    case HttpStatusCode.NoContent:
                        CmsDisplayCommTwo.Single(c => c.Id == e.CmChanged.Id).CmStatus = CmStates.Altered;
                        break;

                    case HttpStatusCode.Continue:
                        CmsDisplayCommTwo.Single(c => c.Id == e.CmChanged.Id).CmStatus = CmStates.Updated;
                        break;

                    default:
                        CmsDisplayCommTwo.Single(c => c.Id == e.CmChanged.Id).CmStatus = CmStates.Unchecked;
                        PollCmAsync(CmsDisplayCommTwo.Single(c => c.Id == e.CmChanged.Id));
                        break;
                    }
                }

                // Update properties
                if (e.DeploymentProperties != null && (e.Host.HostType == HostTypes.COMM1 || e.Host.HostType == HostTypes.COMM2))
                {
                    StoreDeploymentProperties(e.CmChanged, e.DeploymentProperties);
                    Application.Current.Dispatcher.Invoke(delegate
                    {
                        LoadData(e.CmChanged);
                    });
                }

                // Popup hosts
                if (e.HostsFile != null && e.Host != null && (e.Host.HostType == HostTypes.COMM1 || e.Host.HostType == HostTypes.COMM2))
                {
                    PopupHostsFile(e);
                }
            }
            catch (Exception ex)
            {
                LogAndReportException(ex, $"Error updating EC Swap GUI with CM changes: {ex.Message}", false);
            }
        }