Esempio n. 1
0
        private static void ShowConnectingDialogError(Form owner, IXenConnection connection, Exception error)
        {
            if (error is ExpressRestriction e)
            {
                Program.Invoke(Program.MainWindow, delegate()
                {
                    new LicenseWarningDialog(e.HostName, e.ExistingHostName).ShowDialog(owner);
                });
                return;
            }

            if (error is Failure f)
            {
                if (f.ErrorDescription[0] == Failure.HOST_IS_SLAVE)
                {
                    string oldHost        = connection.Name;
                    string poolMasterName = f.ErrorDescription[1];

                    string pool_name = XenConnection.ConnectedElsewhere(poolMasterName);
                    if (pool_name != null)
                    {
                        if (!Program.RunInAutomatedTestMode)
                        {
                            if (pool_name == oldHost)
                            {
                                using (var dlg = new InformationDialog(string.Format(Messages.OLD_CONNECTION_ALREADY_CONNECTED, pool_name))
                                {
                                    WindowTitle = Messages.ADD_NEW_CONNECT_TO
                                })
                                {
                                    dlg.ShowDialog(owner);
                                }
                            }
                            else
                            {
                                using (var dlg = new InformationDialog(string.Format(Messages.SLAVE_ALREADY_CONNECTED, oldHost, pool_name))
                                {
                                    WindowTitle = Messages.ADD_NEW_CONNECT_TO
                                })
                                {
                                    dlg.ShowDialog(owner);
                                }
                            }
                        }
                    }
                    else
                    {
                        DialogResult dialogResult;
                        using (var dlg = new WarningDialog(string.Format(Messages.SLAVE_CONNECTION_ERROR, oldHost, poolMasterName),
                                                           ThreeButtonDialog.ButtonYes,
                                                           ThreeButtonDialog.ButtonNo)
                        {
                            WindowTitle = Messages.CONNECT_TO_SERVER
                        })
                        {
                            dialogResult = dlg.ShowDialog(owner);
                        }
                        if (DialogResult.Yes == dialogResult)
                        {
                            ((XenConnection)connection).Hostname = poolMasterName;
                            BeginConnect(connection, true, owner, false);
                        }
                    }
                }
                else if (f.ErrorDescription[0] == Failure.RBAC_PERMISSION_DENIED)
                {
                    AddError(owner, connection, Messages.ERROR_NO_PERMISSION, Messages.SOLUTION_NO_PERMISSION);
                }
                else if (f.ErrorDescription[0] == XenAPI.Failure.SESSION_AUTHENTICATION_FAILED)
                {
                    AddError(owner, connection, Messages.ERROR_AUTHENTICATION, Messages.SOLUTION_AUTHENTICATION);
                }
                else if (f.ErrorDescription[0] == Failure.HOST_STILL_BOOTING)
                {
                    AddError(owner, connection, Messages.ERROR_HOST_STILL_BOOTING, Messages.SOLUTION_HOST_STILL_BOOTING);
                }
                else
                {
                    AddError(owner, connection, string.IsNullOrEmpty(f.Message) ? Messages.ERROR_UNKNOWN : f.Message, string.Empty);
                }
            }
            else if (error is WebException w)
            {
                if (((XenConnection)connection).SuppressErrors)
                {
                    return;
                }

                var solutionCheckXenServer =
                    Properties.Settings.Default.ProxySetting != (int)HTTPHelper.ProxyStyle.DirectConnection ? Messages.SOLUTION_CHECK_XENSERVER_WITH_PROXY : Messages.SOLUTION_CHECK_XENSERVER;

                switch (w.Status)
                {
                case WebExceptionStatus.ConnectionClosed:
                    AddError(owner, connection, Messages.CONNECTION_CLOSED_BY_SERVER, string.Format(solutionCheckXenServer, ((XenConnection)connection).Hostname));
                    break;

                case WebExceptionStatus.ConnectFailure:
                    AddError(owner, connection, Messages.CONNECTION_REFUSED, string.Format(solutionCheckXenServer, ((XenConnection)connection).Hostname));
                    break;

                case WebExceptionStatus.ProtocolError:
                    if (w.Message != null && w.Message.Contains("(404)"))
                    {
                        AddError(owner, connection, string.Format(Messages.ERROR_NO_XENSERVER, ((XenConnection)connection).Hostname), string.Format(solutionCheckXenServer, ((XenConnection)connection).Hostname));
                    }
                    else if (w.Message != null && w.Message.Contains("(407)"))
                    {
                        string proxyAddress = Properties.Settings.Default.ProxyAddress;
                        AddError(owner, connection, string.Format(Messages.ERROR_PROXY_AUTHENTICATION, proxyAddress), string.Format(Messages.SOLUTION_CHECK_PROXY, proxyAddress));
                    }
                    else
                    {
                        AddError(owner, connection, Messages.ERROR_UNKNOWN, Messages.SOLUTION_UNKNOWN);
                    }
                    break;

                case WebExceptionStatus.NameResolutionFailure:
                    AddError(owner, connection, string.Format(Messages.ERROR_NOT_FOUND, ((XenConnection)connection).Hostname), Messages.SOLUTION_NOT_FOUND);
                    break;

                case WebExceptionStatus.ReceiveFailure:
                case WebExceptionStatus.SendFailure:
                    AddError(owner, connection, string.Format(Messages.ERROR_NO_XENSERVER, ((XenConnection)connection).Hostname), string.Format(solutionCheckXenServer, ((XenConnection)connection).Hostname));
                    break;

                case WebExceptionStatus.SecureChannelFailure:
                    AddError(owner, connection, string.Format(Messages.ERROR_SECURE_CHANNEL_FAILURE, ((XenConnection)connection).Hostname), Messages.SOLUTION_UNKNOWN);
                    break;

                default:
                    AddError(owner, connection, Messages.ERROR_UNKNOWN, Messages.SOLUTION_UNKNOWN);
                    break;
                }
            }
            else if (error is UriFormatException)
            {
                AddError(owner, connection, string.Format(Messages.ERROR_INVALID_URI, connection.Name), Messages.SOLUTION_NOT_FOUND);
            }
            else if (error is FileNotFoundException)
            {
                // If you're using the DbProxy
                AddError(owner, connection, string.Format(string.Format(Messages.ERROR_FILE_NOT_FOUND, ((XenConnection)connection).Hostname), connection.Name), Messages.SOLUTION_UNKNOWN);
            }
            else if (error is ConnectionExists c)
            {
                ConnectionsManager.ClearCacheAndRemoveConnection(connection);

                if (!Program.RunInAutomatedTestMode)
                {
                    using (var dlg = new InformationDialog(c.GetDialogMessage(connection)))
                        dlg.ShowDialog(owner);
                }
            }
            else if (error is ArgumentException)
            {
                // This happens if the server API is incompatible with our bindings.  This should
                // never happen in production, but will happen during development if a field
                // changes type, for example.
                AddError(owner, connection, Messages.SERVER_API_INCOMPATIBLE, Messages.SOLUTION_UNKNOWN);
            }
            else if (error is ServerNotSupported)
            {
                // Server version is too old for this version of XenCenter
                AddError(owner, connection, string.Format(Messages.SERVER_TOO_OLD, BrandManager.ProductVersion70),
                         Messages.SERVER_TOO_OLD_SOLUTION);
            }
            else
            {
                if (((XenConnection)connection).SuppressErrors)
                {
                    return;
                }

                AddError(owner, connection, string.Format(Messages.ERROR_UNKNOWN, ((XenConnection)connection).Hostname), Messages.SOLUTION_UNKNOWN);
            }
        }
Esempio n. 2
0
        internal static void ShowConnectingDialogError_(Form owner, IXenConnection connection, Exception error)
        {
            if (error is ExpressRestriction)
            {
                ExpressRestriction e = (ExpressRestriction)error;
                Program.Invoke(Program.MainWindow, delegate()
                {
                    new LicenseWarningDialog(e.HostName, e.ExistingHostName).ShowDialog(owner);
                });
                return;
            }

            if (error is Failure)
            {
                Failure f = (Failure)error;
                if (f.ErrorDescription[0] == Failure.HOST_IS_SLAVE)
                {
                    string oldHost        = connection.Name;
                    string poolMasterName = f.ErrorDescription[1];

                    string pool_name = XenConnection.ConnectedElsewhere(poolMasterName);
                    if (pool_name != null)
                    {
                        if (!Program.RunInAutomatedTestMode)
                        {
                            if (pool_name == oldHost)
                            {
                                new ThreeButtonDialog(
                                    new ThreeButtonDialog.Details(
                                        SystemIcons.Information,
                                        string.Format(Messages.OLD_CONNECTION_ALREADY_CONNECTED, pool_name),
                                        Messages.ADD_NEW_CONNECT_TO)).ShowDialog(owner);
                            }
                            else
                            {
                                new ThreeButtonDialog(
                                    new ThreeButtonDialog.Details(
                                        SystemIcons.Information,
                                        string.Format(Messages.SLAVE_ALREADY_CONNECTED, oldHost, pool_name),
                                        Messages.ADD_NEW_CONNECT_TO)).ShowDialog(owner);
                            }
                        }
                    }
                    else
                    {
                        if (DialogResult.Yes ==
                            new ThreeButtonDialog(
                                new ThreeButtonDialog.Details(
                                    SystemIcons.Warning,
                                    String.Format(Messages.SLAVE_CONNECTION_ERROR, oldHost, poolMasterName),
                                    Messages.CONNECT_TO_SERVER),
                                ThreeButtonDialog.ButtonYes,
                                ThreeButtonDialog.ButtonNo).ShowDialog(owner))
                        {
                            ((XenConnection)connection).Hostname = poolMasterName;
                            BeginConnect(connection, true, owner, false);
                        }
                    }
                }
                else if (f.ErrorDescription[0] == Failure.RBAC_PERMISSION_DENIED)
                {
                    AddError(owner, connection, Messages.ERROR_NO_PERMISSION, Messages.SOLUTION_NO_PERMISSION);
                }
                else if (f.ErrorDescription[0] == XenAPI.Failure.SESSION_AUTHENTICATION_FAILED)
                {
                    AddError(owner, connection, Messages.ERROR_AUTHENTICATION, Messages.SOLUTION_AUTHENTICATION);
                }
                else if (f.ErrorDescription[0] == Failure.HOST_STILL_BOOTING)
                {
                    AddError(owner, connection, Messages.ERROR_HOST_STILL_BOOTING, Messages.SOLUTION_HOST_STILL_BOOTING);
                }
                else
                {
                    AddError(owner, connection, string.IsNullOrEmpty(f.Message) ? Messages.ERROR_UNKNOWN : f.Message, string.Empty);
                }
            }
            else if (error is WebException)
            {
                if (((XenConnection)connection).SupressErrors)
                {
                    return;
                }

                WebException w = (WebException)error;
                switch (w.Status)
                {
                case WebExceptionStatus.ConnectionClosed:
                    AddError(owner, connection, Messages.CONNECTION_CLOSED_BY_SERVER, string.Format(Messages.SOLUTION_CHECK_XENSERVER, ((XenConnection)connection).Hostname));
                    break;

                case WebExceptionStatus.ConnectFailure:
                    AddError(owner, connection, Messages.CONNECTION_REFUSED, string.Format(Messages.SOLUTION_CHECK_XENSERVER, ((XenConnection)connection).Hostname));
                    break;

                case WebExceptionStatus.ProtocolError:
                    if (w.Message != null && w.Message.Contains("(404)"))
                    {
                        AddError(owner, connection, string.Format(Messages.ERROR_NO_XENSERVER, ((XenConnection)connection).Hostname), string.Format(Messages.SOLUTION_CHECK_XENSERVER, ((XenConnection)connection).Hostname));
                    }
                    else
                    {
                        AddError(owner, connection, Messages.ERROR_UNKNOWN, Messages.SOLUTION_UNKNOWN);
                    }
                    break;

                case WebExceptionStatus.NameResolutionFailure:
                    AddError(owner, connection, string.Format(Messages.ERROR_NOT_FOUND, ((XenConnection)connection).Hostname), Messages.SOLUTION_NOT_FOUND);
                    break;

                case WebExceptionStatus.ReceiveFailure:
                case WebExceptionStatus.SendFailure:
                    AddError(owner, connection, string.Format(Messages.ERROR_NO_XENSERVER, ((XenConnection)connection).Hostname), string.Format(Messages.SOLUTION_CHECK_XENSERVER, ((XenConnection)connection).Hostname));
                    break;

                default:
                    AddError(owner, connection, Messages.ERROR_UNKNOWN, Messages.SOLUTION_UNKNOWN);
                    break;
                }
            }
            else if (error is UriFormatException)
            {
                AddError(owner, connection, string.Format(Messages.ERROR_INVALID_URI, connection.Name), Messages.SOLUTION_NOT_FOUND);
            }
            else if (error is FileNotFoundException)
            {
                // If you're using the DbProxy
                AddError(owner, connection, string.Format(string.Format(Messages.ERROR_FILE_NOT_FOUND, ((XenConnection)connection).Hostname), connection.Name), Messages.SOLUTION_UNKNOWN);
            }
            else if (error is ConnectionExists)
            {
                ConnectionsManager.ClearCacheAndRemoveConnection(connection);

                if (!Program.RunInAutomatedTestMode)
                {
                    ConnectionExists c = error as ConnectionExists;

                    new ThreeButtonDialog(
                        new ThreeButtonDialog.Details(
                            SystemIcons.Information,
                            c.GetDialogMessage(connection),
                            Messages.XENCENTER)).ShowDialog(owner);
                }
            }
            else if (error is ArgumentException)
            {
                // This happens if the server API is incompatible with our bindings.  This should
                // never happen in production, but will happen during development if a field
                // changes type, for example.
                AddError(owner, connection, Messages.SERVER_API_INCOMPATIBLE, Messages.SOLUTION_UNKNOWN);
            }
            else if (error is ServerNotSupported)
            {
                // Server version is too old for this version of XenCenter
                AddError(owner, connection, Messages.SERVER_TOO_OLD, Messages.SERVER_TOO_OLD_SOLUTION);
            }
            else
            {
                if (((XenConnection)connection).SupressErrors)
                {
                    return;
                }

                AddError(owner, connection, string.Format(Messages.ERROR_UNKNOWN, ((XenConnection)connection).Hostname), Messages.SOLUTION_UNKNOWN);
            }
        }