From 101d6f0a006e2e74b3ed7ff516941853d2603593 Mon Sep 17 00:00:00 2001 From: Danilo Del Busso Date: Mon, 24 Jan 2022 10:07:10 +0000 Subject: [PATCH] CP-36392: Use `value` in empty setters Mostly to remove warning from SonarQube, so exception is only thrown in DEBUG mode Address code surrounding previously emptied setters Avoids throwing exceptions when not needed Move default `VerticalTabs` fields outside of constructor Signed-off-by: Danilo Del Busso --- XenAdmin/Controls/VerticalTabs.cs | 18 +++--------- XenAdmin/Wizards/NewSRWizard.cs | 3 +- .../NewSRWizard_Pages/ChooseSrTypePage.cs | 8 ++++- .../Wizards/NewSRWizard_Pages/SrWizardType.cs | 29 +++++++++++++++---- XenCenterLib/BasicXMLResolver.cs | 3 +- 5 files changed, 38 insertions(+), 23 deletions(-) diff --git a/XenAdmin/Controls/VerticalTabs.cs b/XenAdmin/Controls/VerticalTabs.cs index 9e97c3e1b..732c09bba 100644 --- a/XenAdmin/Controls/VerticalTabs.cs +++ b/XenAdmin/Controls/VerticalTabs.cs @@ -33,6 +33,7 @@ using System; using System.Windows.Forms; using System.Drawing; using System.Drawing.Drawing2D; +using System.Reflection; using XenAdmin.Core; @@ -46,24 +47,13 @@ namespace XenAdmin.Controls string SubText { get; } Image Image { get; } } - public VerticalTabs() { - base.ItemHeight = 40; - IntegralHeight = false; - DrawMode = DrawMode.OwnerDrawFixed; + IntegralHeight = false; } - public override int ItemHeight - { - get - { - return base.ItemHeight; - } - set - { - } - } + public override int ItemHeight => 40; + public override DrawMode DrawMode => DrawMode.OwnerDrawFixed; public Func AdjustItemTextBounds; diff --git a/XenAdmin/Wizards/NewSRWizard.cs b/XenAdmin/Wizards/NewSRWizard.cs index 1ea431d0c..cc25554ae 100644 --- a/XenAdmin/Wizards/NewSRWizard.cs +++ b/XenAdmin/Wizards/NewSRWizard.cs @@ -222,8 +222,7 @@ namespace XenAdmin.Wizards xenTabPageLvmoHbaSummary.SuccessfullyCreatedSRs.Clear(); xenTabPageLvmoHbaSummary.FailedToCreateSRs.Clear(); - bool closeWizard; - RunFinalAction(out closeWizard); + RunFinalAction(out var closeWizard); return closeWizard; } diff --git a/XenAdmin/Wizards/NewSRWizard_Pages/ChooseSrTypePage.cs b/XenAdmin/Wizards/NewSRWizard_Pages/ChooseSrTypePage.cs index e00a747f2..240b8d5e4 100644 --- a/XenAdmin/Wizards/NewSRWizard_Pages/ChooseSrTypePage.cs +++ b/XenAdmin/Wizards/NewSRWizard_Pages/ChooseSrTypePage.cs @@ -105,7 +105,13 @@ namespace XenAdmin.Wizards.NewSRWizard_Pages { var frontend = (SrWizardType)radioButton.Tag; frontend.ResetSrName(Connection); - frontend.AllowToCreateNewSr = SrToReattach == null && !DisasterRecoveryTask; + + // these SR types have a blocked setter + if (!(frontend is SrWizardType_Cslg || frontend is SrWizardType_CifsIso || frontend is SrWizardType_NfsIso || frontend is SrWizardType_Cifs)) + { + frontend.AllowToCreateNewSr = SrToReattach == null && !DisasterRecoveryTask; + } + frontend.DisasterRecoveryTask = DisasterRecoveryTask; frontend.SrToReattach = SrToReattach; } diff --git a/XenAdmin/Wizards/NewSRWizard_Pages/SrWizardType.cs b/XenAdmin/Wizards/NewSRWizard_Pages/SrWizardType.cs index a87c76778..727c261c9 100644 --- a/XenAdmin/Wizards/NewSRWizard_Pages/SrWizardType.cs +++ b/XenAdmin/Wizards/NewSRWizard_Pages/SrWizardType.cs @@ -31,6 +31,7 @@ using System; using System.Collections.Generic; +using System.Reflection; using XenAdmin.Actions; using XenAdmin.Core; using XenAdmin.Network; @@ -157,7 +158,10 @@ namespace XenAdmin.Wizards.NewSRWizard_Pages public abstract bool ShowIntroducePrompt { get; } public abstract bool ShowReattachWarning { get; } public abstract bool AllowToCreateNewSr { get; set; } - public virtual bool IsGfs2 { get { return false; } set { } } + public virtual bool IsGfs2 { + get => false; + set => throw new NotSupportedException($"Invalid set call for '{MethodBase.GetCurrentMethod()?.Name}', value: '{value}'"); + } public string SrName { @@ -256,7 +260,11 @@ namespace XenAdmin.Wizards.NewSRWizard_Pages public override string ContentType { get { return SR.Content_Type_ISO; } } public override bool ShowIntroducePrompt { get { return false; } } public override bool ShowReattachWarning { get { return false; } } - public override bool AllowToCreateNewSr { get { return true; } set { } } + public override bool AllowToCreateNewSr + { + get => true; + set => throw new NotSupportedException($"Invalid set call for '{MethodBase.GetCurrentMethod()?.Name}', value: '{value}'"); + } public override void ResetSrName(IXenConnection connection) { @@ -340,7 +348,11 @@ namespace XenAdmin.Wizards.NewSRWizard_Pages public override string ContentType { get { return SR.Content_Type_ISO; } } public override bool ShowIntroducePrompt { get { return false; } } public override bool ShowReattachWarning { get { return false; } } - public override bool AllowToCreateNewSr { get { return true; } set { } } + public override bool AllowToCreateNewSr + { + get => true; + set => throw new NotSupportedException($"Invalid set call for '{MethodBase.GetCurrentMethod()?.Name}', value: '{value}'"); + } public override void ResetSrName(IXenConnection connection) { @@ -362,7 +374,10 @@ namespace XenAdmin.Wizards.NewSRWizard_Pages public override string ContentType { get { return ""; } } public override bool ShowIntroducePrompt { get { return false; } } public override bool ShowReattachWarning { get { return false; } } - public override bool AllowToCreateNewSr { get { return true; } set { } } + public override bool AllowToCreateNewSr { + get => true; + set => throw new NotSupportedException($"Invalid set call for '{MethodBase.GetCurrentMethod()?.Name}', value: '{value}'"); + } public override void ResetSrName(IXenConnection connection) { @@ -379,7 +394,11 @@ namespace XenAdmin.Wizards.NewSRWizard_Pages public override string ContentType { get { return ""; } } public override bool ShowIntroducePrompt { get { return true; } } public override bool ShowReattachWarning { get { return true; } } - public override bool AllowToCreateNewSr { get { return true; } set { } } + public override bool AllowToCreateNewSr + { + get => true; + set => throw new NotSupportedException($"Invalid set call for '{MethodBase.GetCurrentMethod()?.Name}', value: '{value}'"); + } public SrWizardType_NetApp ToNetApp() { diff --git a/XenCenterLib/BasicXMLResolver.cs b/XenCenterLib/BasicXMLResolver.cs index 315c5fd94..e55351810 100644 --- a/XenCenterLib/BasicXMLResolver.cs +++ b/XenCenterLib/BasicXMLResolver.cs @@ -32,6 +32,7 @@ using System; using System.IO; using System.Net; +using System.Reflection; using System.Xml; namespace XenCenterLib @@ -40,7 +41,7 @@ namespace XenCenterLib { public override ICredentials Credentials { - set { } + set => throw new NotSupportedException($"Invalid set call for '{MethodBase.GetCurrentMethod()?.Name}', value: '{value}'"); } public override object GetEntity(Uri absoluteUri, string role, Type ofObjectToReturn)