Esempio n. 1
0
        private void DelayLoadedGridComboBoxItem_ReasonChanged(DelayLoadingOptionComboBoxItem item)
        {
            if (item == null)
            {
                throw new NullReferenceException("Trying to update delay loaded reason but failed to extract reason");
            }

            var cb = item.ParentComboBox as DataGridViewEnableableComboBoxCell;

            if (cb == null)
            {
                return;
            }

            Program.Invoke(this, () =>
            {
                try
                {
                    var selectedValue = cb.Value;
                    cb.DataGridView.RefreshEdit();
                    if (item.Enabled && item.PreferAsSelectedItem)
                    {
                        cb.Value = item;
                    }
                    else
                    {
                        cb.Value = selectedValue;
                    }
                }
                finally
                {
                    item.ReasonUpdated -= DelayLoadedGridComboBoxItem_ReasonChanged;
                }
            });
        }
Esempio n. 2
0
 public void CopyFrom(DelayLoadingOptionComboBoxItem toCopy)
 {
     xenObject            = toCopy.xenObject;
     failureReason        = toCopy.FailureReason;
     Enabled              = toCopy.Enabled;
     PreferAsSelectedItem = toCopy.PreferAsSelectedItem;
 }
 public void CopyFrom(DelayLoadingOptionComboBoxItem toCopy)
 {
     xenObject = toCopy.xenObject;
     failureReason = toCopy.FailureReason;
     Enabled = toCopy.Enabled;
     PreferAsSelectedItem = toCopy.PreferAsSelectedItem;
 }
        private void DelayLoadedComboBoxItem_ReasonChanged(object sender, EventArgs e)
        {
            DelayLoadingOptionComboBoxItem item = sender as DelayLoadingOptionComboBoxItem;

            if (item == null)
            {
                throw new NullReferenceException("Trying to update delay loaded reason but failed to extract reason");
            }

            int index = m_comboBoxConnection.Items.IndexOf(item);

            if (index > -1)
            {
                Program.Invoke(Program.MainWindow, delegate()
                {
                    int selectedIndex = m_comboBoxConnection.SelectedIndex;


                    if (index > m_comboBoxConnection.Items.Count)
                    {
                        return;
                    }

                    if (updatingDestinationCombobox || updatingHomeServerList)
                    {
                        return;
                    }

                    DelayLoadingOptionComboBoxItem tempItem =
                        m_comboBoxConnection.Items[index] as DelayLoadingOptionComboBoxItem;
                    if (tempItem == null)
                    {
                        throw new NullReferenceException("Trying to update delay loaded reason but failed to extract reason");
                    }
                    tempItem.CopyFrom(item);
                    m_comboBoxConnection.BeginUpdate();
                    m_comboBoxConnection.Items.RemoveAt(index);

                    if (updatingDestinationCombobox || updatingHomeServerList)
                    {
                        m_comboBoxConnection.EndUpdate();
                        return;
                    }

                    m_comboBoxConnection.Items.Insert(index, tempItem);
                    m_comboBoxConnection.SelectedIndex = selectedIndex;
                    m_comboBoxConnection.EndUpdate();

                    if (tempItem.PreferAsSelectedItem)
                    {
                        m_comboBoxConnection.SelectedItem = tempItem;
                    }

                    item.ReasonUpdated -= DelayLoadedComboBoxItem_ReasonChanged;
                });
            }
        }
        private void PopulateComboBox()
        {
            Program.AssertOnEventThread();

            ClearDataGridView();

            updatingDestinationCombobox = true;
            ClearComboBox();

            var targetConnections = ConnectionsManager.XenConnectionsCopy.Where(con => con.IsConnected).Except(ignoredConnections).ToList();

            foreach (var xenConnection in targetConnections)
            {
                DelayLoadingOptionComboBoxItem item = null;

                Pool pool = Helpers.GetPool(xenConnection);

                if (pool == null)
                {
                    Host host = Helpers.GetMaster(xenConnection);

                    if (host != null)
                    {
                        item = CreateDelayLoadingOptionComboBoxItem(host);
                        m_comboBoxConnection.Items.Add(item);
                        item.ReasonUpdated += DelayLoadedComboBoxItem_ReasonChanged;
                        item.LoadAsync();
                        host.PropertyChanged -= PropertyChanged;
                        host.PropertyChanged += PropertyChanged;
                    }
                }
                else
                {
                    item = CreateDelayLoadingOptionComboBoxItem(pool);
                    m_comboBoxConnection.Items.Add(item);
                    item.ReasonUpdated += DelayLoadedComboBoxItem_ReasonChanged;
                    item.LoadAsync();
                    pool.PropertyChanged -= PropertyChanged;
                    pool.PropertyChanged += PropertyChanged;
                }

                if (item != null && m_selectedObject != null && item.Item.Connection == m_selectedObject.Connection)
                {
                    item.PreferAsSelectedItem = true;
                }

                xenConnection.ConnectionStateChanged -= xenConnection_ConnectionStateChanged;
                xenConnection.ConnectionStateChanged += xenConnection_ConnectionStateChanged;
                xenConnection.CachePopulated         -= xenConnection_CachePopulated;
                xenConnection.CachePopulated         += xenConnection_CachePopulated;
                xenConnection.Cache.RegisterCollectionChanged <Host>(Host_CollectionChangedWithInvoke);
            }

            m_comboBoxConnection.Items.Add(new AddHostExecutingComboBoxItem());
            updatingDestinationCombobox = false;
        }
        private void DelayLoadedComboBoxItem_ReasonChanged(DelayLoadingOptionComboBoxItem item)
        {
            if (item == null)
            {
                throw new NullReferenceException("Trying to update delay loaded reason but failed to extract reason");
            }

            Program.Invoke(this, () =>
            {
                int index = m_comboBoxConnection.Items.IndexOf(item);
                if (index < 0 || index >= m_comboBoxConnection.Items.Count)
                {
                    return;
                }

                if (updatingDestinationCombobox || updatingHomeServerList)
                {
                    return;
                }

                int selectedIndex = m_comboBoxConnection.SelectedIndex;

                var tempItem = m_comboBoxConnection.Items[index] as DelayLoadingOptionComboBoxItem;
                if (tempItem == null)
                {
                    throw new NullReferenceException("Trying to update delay loaded reason but failed to extract reason");
                }

                tempItem.CopyFrom(item);

                try
                {
                    m_comboBoxConnection.BeginUpdate();
                    m_comboBoxConnection.Items.RemoveAt(index);

                    if (updatingDestinationCombobox || updatingHomeServerList)
                    {
                        return;
                    }

                    m_comboBoxConnection.Items.Insert(index, tempItem);
                    m_comboBoxConnection.SelectedIndex = selectedIndex;

                    if (tempItem.PreferAsSelectedItem)
                    {
                        m_comboBoxConnection.SelectedItem = tempItem;
                    }
                }
                finally
                {
                    m_comboBoxConnection.EndUpdate();
                    item.ReasonUpdated -= DelayLoadedComboBoxItem_ReasonChanged;
                }
            });
        }
 private void CancelFilters()
 {
     foreach (var item in m_comboBoxConnection.Items)
     {
         DelayLoadingOptionComboBoxItem comboBoxItem = item as DelayLoadingOptionComboBoxItem;
         if (comboBoxItem != null)
         {
             comboBoxItem.CancelFilters();
         }
     }
 }
        private void ClearComboBox()
        {
            Program.AssertOnEventThread();

            foreach (var item in m_comboBoxConnection.Items)
            {
                DelayLoadingOptionComboBoxItem tempItem = item as DelayLoadingOptionComboBoxItem;
                if (tempItem != null)
                {
                    tempItem.ReasonUpdated -= DelayLoadedComboBoxItem_ReasonChanged;
                }
            }
            m_comboBoxConnection.Items.Clear();
        }
        private void PopulateDataGridView(IEnableableXenObjectComboBoxItem selectedItem)
        {
            Program.AssertOnEventThread();

            updatingHomeServerList = true;
            try
            {
                var target = m_comboBoxConnection.SelectedItem as DelayLoadingOptionComboBoxItem;

                m_dataGridView.SuspendLayout();

                ClearDataGridView();

                var hasPoolSharedStorage = target != null && HasPoolSharedStorage(target.Item.Connection);

                foreach (var kvp in m_vmMappings)
                {
                    var tb = new DataGridViewTextBoxCell {
                        Value = kvp.Value.VmNameLabel, Tag = kvp.Key
                    };
                    var cb = new DataGridViewEnableableComboBoxCell {
                        FlatStyle = FlatStyle.Flat
                    };
                    var homeserverFilters = CreateTargetServerFilterList(selectedItem, new List <string> {
                        kvp.Key
                    });

                    if (target != null)
                    {
                        if (hasPoolSharedStorage)
                        {
                            foreach (var pool in target.Item.Connection.Cache.Pools)
                            {
                                var item = new NoTargetServerPoolItem(pool);
                                cb.Items.Add(item);

                                if ((m_selectedObject != null && m_selectedObject.opaque_ref == pool.opaque_ref) ||
                                    (target.Item.opaque_ref == pool.opaque_ref))
                                {
                                    cb.Value = item;
                                }

                                break; //there exists one pool per connection
                            }
                        }

                        var sortedHosts = new List <Host>(target.Item.Connection.Cache.Hosts);
                        sortedHosts.Sort();

                        foreach (var host in sortedHosts)
                        {
                            var item = new DelayLoadingOptionComboBoxItem(host, homeserverFilters);
                            item.LoadSync();
                            cb.Items.Add(item);
                            if (item.Enabled && ((m_selectedObject != null && m_selectedObject.opaque_ref == host.opaque_ref) ||
                                                 (target.Item.opaque_ref == host.opaque_ref)))
                            {
                                cb.Value = item;
                            }
                        }
                    }

                    SetComboBoxPreSelection(cb);

                    var row = new DataGridViewRow();
                    row.Cells.AddRange(tb, cb);
                    m_dataGridView.Rows.Add(row);
                }

                HelpersGUI.ResizeGridViewColumnToAllCells(m_colTarget); //set properly the width of the last column

                if (restoreGridHomeServerSelection)
                {
                    RestoreGridHomeServerSelectionFromMapping();
                    restoreGridHomeServerSelection = false;
                }
            }
            finally
            {
                updatingHomeServerList = false;
                m_dataGridView.ResumeLayout();
            }
        }
        private void PopulateDataGridView(List <ReasoningFilter> homeserverFilters)
        {
            Program.AssertOnEventThread();

            updatingHomeServerList = true;
            try
            {
                Connection = null;

                var target = m_comboBoxConnection.SelectedItem as DelayLoadingOptionComboBoxItem;

                if (target != null)
                {
                    Connection = target.Item.Connection;
                }

                ClearDataGridView();

                SetButtonNextEnabled(true);
                var hasPoolSharedStorage = HasPoolSharedStorage();

                foreach (var kvp in m_vmMappings)
                {
                    var tb = new DataGridViewTextBoxCell {
                        Value = kvp.Value.VmNameLabel, Tag = kvp.Key
                    };
                    var cb = new DataGridViewEnableableComboBoxCell {
                        FlatStyle = FlatStyle.Flat
                    };

                    if (Connection != null)
                    {
                        if (hasPoolSharedStorage)
                        {
                            foreach (var pool in Connection.Cache.Pools)
                            {
                                var item = new NoTargetServerPoolItem(pool);
                                cb.Items.Add(item);

                                if ((m_selectedObject != null && m_selectedObject.opaque_ref == pool.opaque_ref) ||
                                    (target != null && target.Item.opaque_ref == pool.opaque_ref))
                                {
                                    cb.Value = item;
                                }

                                break; //there exists one pool per connection
                            }
                        }

                        foreach (var host in Connection.Cache.Hosts)
                        {
                            var item = new DelayLoadingOptionComboBoxItem(host, homeserverFilters);
                            item.LoadAndWait();
                            cb.Items.Add(item);

                            if ((m_selectedObject != null && m_selectedObject.opaque_ref == host.opaque_ref) ||
                                (target != null && target.Item.opaque_ref == host.opaque_ref))
                            {
                                cb.Value = item;
                            }
                        }
                    }

                    SetComboBoxPreSelection(cb);

                    var row = new DataGridViewRow();
                    row.Cells.AddRange(tb, cb);
                    m_dataGridView.Rows.Add(row);
                }

                HelpersGUI.ResizeLastGridViewColumn(m_colTarget); //set properly the width of the last column

                if (restoreGridHomeServerSelection)
                {
                    RestoreGridHomeServerSelectionFromMapping();
                    restoreGridHomeServerSelection = false;
                }
            }
            finally
            {
                updatingHomeServerList = false;
            }
        }
        private void PopulateDataGridView(List<ReasoningFilter> homeserverFilters)
        {
            Program.AssertOnEventThread();

            updatingHomeServerList = true;
            try
            {
                Connection = null;

                var target = m_comboBoxConnection.SelectedItem as DelayLoadingOptionComboBoxItem;

                if (target != null)
                    Connection = target.Item.Connection;

                ClearDataGridView();

                SetButtonNextEnabled(true);
                var hasPoolSharedStorage = HasPoolSharedStorage();

                foreach (var kvp in m_vmMappings)
                {
                    var tb = new DataGridViewTextBoxCell {Value = kvp.Value.VmNameLabel, Tag = kvp.Key};
                    var cb = new DataGridViewEnableableComboBoxCell{FlatStyle = FlatStyle.Flat};

                    if (Connection != null)
                    {
                        if (hasPoolSharedStorage)
                        {
                            foreach (var pool in Connection.Cache.Pools)
                            {
                                var item = new NoTargetServerPoolItem(pool);
                                cb.Items.Add(item);

                                if ((m_selectedObject != null && m_selectedObject.opaque_ref == pool.opaque_ref) ||
                                    (target != null && target.Item.opaque_ref == pool.opaque_ref))
                                    cb.Value = item;

                                break; //there exists one pool per connection
                            }
                        }

                        foreach (var host in Connection.Cache.Hosts)
                        {
                            var item = new DelayLoadingOptionComboBoxItem(host, homeserverFilters);
                            item.LoadAndWait();
                            cb.Items.Add(item);

                            if ((m_selectedObject != null && m_selectedObject.opaque_ref == host.opaque_ref) ||
                                (target != null && target.Item.opaque_ref == host.opaque_ref))
                                cb.Value = item;
                        }
                    }

                    SetComboBoxPreSelection(cb);

                    var row = new DataGridViewRow();
                    row.Cells.AddRange(tb, cb);
                    m_dataGridView.Rows.Add(row);
                }

                HelpersGUI.ResizeLastGridViewColumn(m_colTarget); //set properly the width of the last column

                if (restoreGridHomeServerSelection)
                {
                    RestoreGridHomeServerSelectionFromMapping();
                    restoreGridHomeServerSelection = false;
                }
            }
            finally
            {
                updatingHomeServerList = false;
            }
        }