xenadmin/XenAdmin/Wizards/GenericPages/TvmIpPage.cs
Mihaela Stoica bd36a85bff CP-4816: Initial commit to git repo
Signed-off-by: Mihaela Stoica <mihaela.stoica@citrix.com>
2013-06-24 12:41:48 +01:00

238 lines
6.9 KiB
C#

/* Copyright (c) Citrix Systems Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms,
* with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above
* copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using XenAdmin.Controls;
using XenAdmin.Controls.Common;
using XenAdmin.Core;
namespace XenAdmin.Wizards.GenericPages
{
/// <summary>
/// Class representing the page of the wizard where the user specifies the IP address to be used by the Transfer VM.
/// </summary>
public partial class TvmIpPage : XenTabPage
{
private bool m_buttonNextEnabled;
public TvmIpPage()
{
InitializeComponent();
m_ctrlError.HideError();
}
#region Base class (XenTabPage) overrides
/// <summary>
/// Gets the page's title (headline)
/// </summary>
public override string PageTitle { get { return Messages.TVM_PAGE_TITLE; } }
/// <summary>
/// Gets the page's label in the (left hand side) wizard progress panel
/// </summary>
public override string Text { get { return Messages.TVM_PAGE_TEXT; } }
protected override bool ImplementsIsDirty()
{
return true;
}
public override void PageLoaded(PageLoadedDirection direction)
{
base.PageLoaded(direction);//call first so the page gets populated
m_buttonNextEnabled = true;
OnPageUpdated();
}
public override void PageLeave(PageLoadedDirection direction, ref bool cancel)
{
if (direction == PageLoadedDirection.Forward && IsDirty)
{
if (!PerformCheck(CheckValidData))
cancel = true;
}
base.PageLeave(direction, ref cancel);
}
public override void PopulatePage()
{
autoHeightLabel1.Text = String.Format(Messages.TVM_PAGE_DESCRIPTION, IsExportMode ? Messages.EXPORT_LOWERCASE : Messages.IMPORT_LOWERCASE);
m_comboBoxNetwork.PopulateComboBox(Connection);
m_radioAutomatic.Checked = true;
}
public override bool EnableNext()
{
return m_buttonNextEnabled;
}
#endregion
#region Accessors
public bool IsExportMode { private get; set; }
public KeyValuePair<string, string> NetworkUuid
{
get { return m_comboBoxNetwork.SelectedNetworkUuid; }
}
public bool IsTvmIpStatic { get { return m_radioManual.Checked; } }
public string TvmIpAddress { get { return m_textBoxIP.Text; } }
public string TvmSubnetMask { get { return m_textBoxMask.Text; } }
public string TvmGateway { get { return m_textBoxGateway.Text; } }
#endregion
#region Private methods
/// <summary>
/// Performs certain checks on the pages's input data and shows/hides an error accordingly
/// </summary>
/// <param name="checks">The checks to perform</param>
private bool PerformCheck(params CheckDelegate[] checks)
{
m_buttonNextEnabled = m_ctrlError.PerformCheck(checks);
OnPageUpdated();
return m_buttonNextEnabled;
}
private bool CheckRequiredFieldsCompleted(out string error)
{
error = string.Empty;
if (m_radioManual.Checked && (string.IsNullOrEmpty(m_textBoxIP.Text) || string.IsNullOrEmpty(m_textBoxMask.Text) || string.IsNullOrEmpty(m_textBoxGateway.Text)))
return false;
return true;
}
private bool CheckValidData(out string error)
{
error = string.Empty;
if (m_radioManual.Checked)
{
if (!StringUtility.IsIPAddress(m_textBoxIP.Text))
{
error = Messages.ERROR_INVALID_IP;
return false;
}
if (!StringUtility.IsIPAddress(m_textBoxMask.Text))
{
error = Messages.ERROR_INVALID_MASK;
return false;
}
if (!StringUtility.IsIPAddress(m_textBoxGateway.Text))
{
error = Messages.ERROR_INVALID_GATEWAY;
return false;
}
}
return true;
}
private void ToggleRadioManualCheckedState()
{
if (m_radioManual.Checked)
return;
if (!String.IsNullOrEmpty(m_textBoxIP.Text) || !String.IsNullOrEmpty(m_textBoxMask.Text) || !String.IsNullOrEmpty(m_textBoxGateway.Text))
m_radioManual.Checked = true;
}
#endregion
#region Control event handlers
private void m_radioAutomatic_CheckedChanged(object sender, EventArgs e)
{
//only examine the Checked case to avoid cyclical calls between the radion button handlers
if (m_radioAutomatic.Checked)
{
m_radioManual.Checked = false;
PerformCheck(CheckRequiredFieldsCompleted);
IsDirty = true;
}
}
private void m_radioManual_CheckedChanged(object sender, EventArgs e)
{
//only examine the Checked case to avoid cyclical calls between the radion button handlers
if (m_radioManual.Checked)
{
m_radioAutomatic.Checked = false;
PerformCheck(CheckRequiredFieldsCompleted);
IsDirty = true;
}
}
private void m_textBoxIP_TextChanged(object sender, EventArgs e)
{
ToggleRadioManualCheckedState();
PerformCheck(CheckRequiredFieldsCompleted);
IsDirty = true;
}
private void m_textBoxMask_TextChanged(object sender, EventArgs e)
{
ToggleRadioManualCheckedState();
PerformCheck(CheckRequiredFieldsCompleted);
IsDirty = true;
}
private void m_textBoxGateway_TextChanged(object sender, EventArgs e)
{
ToggleRadioManualCheckedState();
PerformCheck(CheckRequiredFieldsCompleted);
IsDirty = true;
}
private void m_comboBoxNetwork_SelectedIndexChanged(object sender, EventArgs e)
{
IsDirty = true;
}
#endregion
}
}