Fix line endings (to Windows)

This commit is contained in:
Mihaela Stoica 2015-07-01 15:58:58 +01:00
parent 987a27613c
commit ea786180fc
4 changed files with 600 additions and 600 deletions

View File

@ -1,101 +1,101 @@
/* 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.Windows.Forms;
using XenAdmin.Actions;
using XenAPI;
namespace XenAdmin.Dialogs.CallHome
{
public partial class CallHomeEnrollNowDialog : XenDialogBase
{
private readonly Pool pool;
private bool authenticated;
public CallHomeEnrollNowDialog(Pool pool)
{
this.pool = pool;
InitializeComponent();
InitializeControls();
UpdateButtons();
}
private void InitializeControls()
{
authenticated = false;
Text = String.Format(Messages.CALLHOME_ENROLLMENT_TITLE, pool.Name);
authenticationRubricLabel.Text = Messages.CALLHOME_AUTHENTICATION_RUBRIC_NO_TOKEN;
callHomeAuthenticationPanel1.Pool = pool;
}
private void UpdateButtons()
{
okButton.Enabled = authenticated;
okButton.Text = !authenticated
? Messages.OK
: Messages.CALLHOME_ENROLLMENT_CONFIRMATION_BUTTON_LABEL;
}
private void okButton_Click(object sender, EventArgs e)
{
var newCallHomeSettings = pool.CallHomeSettings;
newCallHomeSettings.Status = CallHomeStatus.Enabled;
/* 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.Windows.Forms;
using XenAdmin.Actions;
using XenAPI;
namespace XenAdmin.Dialogs.CallHome
{
public partial class CallHomeEnrollNowDialog : XenDialogBase
{
private readonly Pool pool;
private bool authenticated;
public CallHomeEnrollNowDialog(Pool pool)
{
this.pool = pool;
InitializeComponent();
InitializeControls();
UpdateButtons();
}
private void InitializeControls()
{
authenticated = false;
Text = String.Format(Messages.CALLHOME_ENROLLMENT_TITLE, pool.Name);
authenticationRubricLabel.Text = Messages.CALLHOME_AUTHENTICATION_RUBRIC_NO_TOKEN;
callHomeAuthenticationPanel1.Pool = pool;
}
private void UpdateButtons()
{
okButton.Enabled = authenticated;
okButton.Text = !authenticated
? Messages.OK
: Messages.CALLHOME_ENROLLMENT_CONFIRMATION_BUTTON_LABEL;
}
private void okButton_Click(object sender, EventArgs e)
{
var newCallHomeSettings = pool.CallHomeSettings;
newCallHomeSettings.Status = CallHomeStatus.Enabled;
var token = newCallHomeSettings.GetSecretyInfo(pool.Connection, CallHomeSettings.UPLOAD_TOKEN_SECRET);
var user = newCallHomeSettings.GetSecretyInfo(pool.Connection, CallHomeSettings.UPLOAD_CREDENTIAL_USER_SECRET);
var password = newCallHomeSettings.GetSecretyInfo(pool.Connection, CallHomeSettings.UPLOAD_CREDENTIAL_PASSWORD_SECRET);
new SaveCallHomeSettingsAction(pool, newCallHomeSettings, token, user, password, false).RunAsync();
new TransferCallHomeSettingsAction(pool, newCallHomeSettings, user, password, true).RunAsync();
DialogResult = DialogResult.OK;
Close();
}
private void cancelButton_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
private void callHomeAuthenticationPanel1_AuthenticationChanged(object sender, EventArgs e)
{
Program.Invoke(this, delegate
{
if (callHomeAuthenticationPanel1.Authenticated)
{
authenticated = true;
}
UpdateButtons();
});
}
}
new TransferCallHomeSettingsAction(pool, newCallHomeSettings, user, password, true).RunAsync();
DialogResult = DialogResult.OK;
Close();
}
private void cancelButton_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
private void callHomeAuthenticationPanel1_AuthenticationChanged(object sender, EventArgs e)
{
Program.Invoke(this, delegate
{
if (callHomeAuthenticationPanel1.Authenticated)
{
authenticated = true;
}
UpdateButtons();
});
}
}
}

View File

@ -1,321 +1,321 @@
/* 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.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Windows.Forms;
using XenAdmin.Actions;
using XenAdmin.Core;
using XenAdmin.Dialogs.VMProtectionRecovery;
using XenAdmin.Network;
using XenAPI;
using XenCenterLib;
namespace XenAdmin.Dialogs.CallHome
{
public partial class CallHomeOverviewDialog : XenDialogBase
{
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
public CallHomeOverviewDialog()
{
InitializeComponent();
}
private Pool currentSelected = null;
void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
if (e.Error != null)
{
log.Error(e.Error);
return;
}
Program.Invoke(this, () => RefreshGrid((List<DataGridViewRow>)e.Result));
}
private void RefreshGrid(List<DataGridViewRow> rows)
{
Program.AssertOnEventThread();
var selectedPool = currentSelected;
poolsDataGridView.SuspendLayout();
try
{
poolsDataGridView.Rows.Clear();
foreach (var row in rows)
{
if (poolsDataGridView.ColumnCount > 0)
{
poolsDataGridView.Rows.Add(row);
}
}
RefreshButtons();
RefreshDetailsPanel();
if (selectedPool != null)
{
foreach (DataGridViewRow row in poolsDataGridView.Rows)
{
if (row is PoolRow &&
(row as PoolRow).Pool.uuid == selectedPool.uuid)
{
poolsDataGridView.ClearSelection();
row.Selected = true;
break;
}
}
}
}
finally
{
poolsDataGridView.ResumeLayout();
}
}
object worker_DoWork(object sender, object argument)
{
var list = new List<DataGridViewRow>();
foreach (IXenConnection xenConnection in ConnectionsManager.XenConnectionsCopy)
{
if (!xenConnection.IsConnected || Helpers.FeatureForbidden(xenConnection, Host.RestrictHealthCheck))
continue;
var pool = Helpers.GetPoolOfOne(xenConnection);
if (pool != null)
{
var poolRow = new PoolRow(pool);
list.Add(poolRow);
}
}
return list;
}
void Pool_BatchCollectionChanged(object sender, EventArgs e)
{
LoadPools();
}
QueuedBackgroundWorker worker = new QueuedBackgroundWorker();
private void LoadPools()
{
worker.RunWorkerAsync(worker_DoWork, worker_RunWorkerCompleted);
}
#region PoolRow
private class PoolRow : DataGridViewRow
{
private DataGridViewTextAndImageCell _nameCell = new DataGridViewTextAndImageCell();
private DataGridViewTextAndImageCell _statusCell = new DataGridViewTextAndImageCell();
public readonly Pool Pool;
public PoolRow(Pool pool)
{
Cells.Add(_nameCell);
Cells.Add(_statusCell);
Pool = pool;
RefreshRow();
}
public void RefreshRow()
{
_nameCell.Value = Pool.Name;
_nameCell.Image = null;
_statusCell.Value = Pool.CallHomeSettings.StatusDescription;
_statusCell.Image = Pool.CallHomeSettings.Status != CallHomeStatus.Enabled
? Properties.Resources._000_error_h32bit_16
: Properties.Resources._000_Alert2_h32bit_16;
}
}
#endregion
private void RefreshButtons()
{
if (poolsDataGridView.SelectedRows.Count == 1 && poolsDataGridView.SelectedRows[0] is PoolRow)
{
currentSelected = (Pool)((PoolRow)poolsDataGridView.SelectedRows[0]).Pool;
}
else
{
if (poolsDataGridView.SelectedRows.Count == 0)
currentSelected = null;
}
poolDetailsPanel.Visible = (currentSelected != null);
}
private void RefreshDetailsPanel()
{
if (poolsDataGridView.SelectedRows.Count != 1 || !(poolsDataGridView.SelectedRows[0] is PoolRow))
{
poolNameLabel.Text = "";
return;
}
var poolRow = (PoolRow)poolsDataGridView.SelectedRows[0];
poolNameLabel.Text = poolRow.Pool.Name.Ellipsise(120);
scheduleLabel.Text = GetScheduleDescription(poolRow.Pool.CallHomeSettings);
healthCheckStatusPanel.Visible = poolRow.Pool.CallHomeSettings.Status == CallHomeStatus.Enabled;
notEnrolledPanel.Visible = poolRow.Pool.CallHomeSettings.Status != CallHomeStatus.Enabled;
UpdateUploadRequestDescription(poolRow.Pool.CallHomeSettings);
}
public string GetScheduleDescription(CallHomeSettings callHomeSettings)
{
{
var time = new DateTime(1900, 1, 1, callHomeSettings.TimeOfDay, 0, 0);
return callHomeSettings.Status == CallHomeStatus.Enabled
? string.Format(Messages.CALLHOME_SCHEDULE_DESCRIPTION, callHomeSettings.IntervalInWeeks,
callHomeSettings.DayOfWeek, HelpersGUI.DateTimeToString(time, Messages.DATEFORMAT_HM, true))
: string.Empty;
}
}
public void UpdateUploadRequestDescription(CallHomeSettings callHomeSettings)
{
{
double uploadRequest;
if (!callHomeSettings.CanRequestNewUpload && double.TryParse(callHomeSettings.NewUploadRequest, out uploadRequest))
{
uploadRequestLinkLabel.Text = string.Format(Messages.HEALTHCHECK_ON_DEMAND_REQUESTED_AT,
HelpersGUI.DateTimeToString(Util.FromUnixTime(uploadRequest), Messages.DATEFORMAT_HM, true));
uploadRequestLinkLabel.LinkArea = new LinkArea(0, 0);
return;
}
uploadRequestLinkLabel.Text = Messages.HEALTHCHECK_ON_DEMAND_REQUEST;
uploadRequestLinkLabel.LinkArea = new LinkArea(0, uploadRequestLinkLabel.Text.Length);
}
}
private void CallHomeOverview_Load(object sender, EventArgs e)
{
LoadPools();
foreach (IXenConnection xenConnection in ConnectionsManager.XenConnectionsCopy)
{
xenConnection.Cache.RegisterBatchCollectionChanged<Pool>(Pool_BatchCollectionChanged);
}
}
private void dataGridView1_SelectionChanged(object sender, EventArgs e)
{
RefreshButtons();
RefreshDetailsPanel();
}
private void CallHomeOverviewDialog_FormClosed(object sender, FormClosedEventArgs e)
{
foreach (IXenConnection xenConnection in ConnectionsManager.XenConnectionsCopy)
{
xenConnection.Cache.DeregisterBatchCollectionChanged<Pool>(Pool_BatchCollectionChanged);
}
}
private void buttonCancel_Click(object sender, EventArgs e)
{
Close();
}
private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
if (poolsDataGridView.SelectedRows.Count != 1 || !(poolsDataGridView.SelectedRows[0] is PoolRow))
return;
var poolRow = (PoolRow)poolsDataGridView.SelectedRows[0];
new CallHomeSettingsDialog(poolRow.Pool).ShowDialog(this);
}
public DialogResult ShowDialog(IWin32Window parent, List<IXenObject> selectedItems)
{
SelectPool(selectedItems);
return ShowDialog(parent);
}
public void RefreshView(List<IXenObject> selectedItems)
{
SelectPool(selectedItems);
LoadPools();
}
private void SelectPool(List<IXenObject> selectedItems)
{
IXenObject xo = selectedItems.Count > 0 ? selectedItems.FirstOrDefault() : null;
if (xo is Pool)
currentSelected = xo as Pool;
}
private void enrollNowLinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
if (poolsDataGridView.SelectedRows.Count != 1 || !(poolsDataGridView.SelectedRows[0] is PoolRow))
return;
var poolRow = (PoolRow)poolsDataGridView.SelectedRows[0];
var callHomeSettings = poolRow.Pool.CallHomeSettings;
if (callHomeSettings.Status != CallHomeStatus.Enabled)
{
// try to enroll into call home with the default settings, if authentication is not required
/* 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.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Windows.Forms;
using XenAdmin.Actions;
using XenAdmin.Core;
using XenAdmin.Dialogs.VMProtectionRecovery;
using XenAdmin.Network;
using XenAPI;
using XenCenterLib;
namespace XenAdmin.Dialogs.CallHome
{
public partial class CallHomeOverviewDialog : XenDialogBase
{
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
public CallHomeOverviewDialog()
{
InitializeComponent();
}
private Pool currentSelected = null;
void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
if (e.Error != null)
{
log.Error(e.Error);
return;
}
Program.Invoke(this, () => RefreshGrid((List<DataGridViewRow>)e.Result));
}
private void RefreshGrid(List<DataGridViewRow> rows)
{
Program.AssertOnEventThread();
var selectedPool = currentSelected;
poolsDataGridView.SuspendLayout();
try
{
poolsDataGridView.Rows.Clear();
foreach (var row in rows)
{
if (poolsDataGridView.ColumnCount > 0)
{
poolsDataGridView.Rows.Add(row);
}
}
RefreshButtons();
RefreshDetailsPanel();
if (selectedPool != null)
{
foreach (DataGridViewRow row in poolsDataGridView.Rows)
{
if (row is PoolRow &&
(row as PoolRow).Pool.uuid == selectedPool.uuid)
{
poolsDataGridView.ClearSelection();
row.Selected = true;
break;
}
}
}
}
finally
{
poolsDataGridView.ResumeLayout();
}
}
object worker_DoWork(object sender, object argument)
{
var list = new List<DataGridViewRow>();
foreach (IXenConnection xenConnection in ConnectionsManager.XenConnectionsCopy)
{
if (!xenConnection.IsConnected || Helpers.FeatureForbidden(xenConnection, Host.RestrictHealthCheck))
continue;
var pool = Helpers.GetPoolOfOne(xenConnection);
if (pool != null)
{
var poolRow = new PoolRow(pool);
list.Add(poolRow);
}
}
return list;
}
void Pool_BatchCollectionChanged(object sender, EventArgs e)
{
LoadPools();
}
QueuedBackgroundWorker worker = new QueuedBackgroundWorker();
private void LoadPools()
{
worker.RunWorkerAsync(worker_DoWork, worker_RunWorkerCompleted);
}
#region PoolRow
private class PoolRow : DataGridViewRow
{
private DataGridViewTextAndImageCell _nameCell = new DataGridViewTextAndImageCell();
private DataGridViewTextAndImageCell _statusCell = new DataGridViewTextAndImageCell();
public readonly Pool Pool;
public PoolRow(Pool pool)
{
Cells.Add(_nameCell);
Cells.Add(_statusCell);
Pool = pool;
RefreshRow();
}
public void RefreshRow()
{
_nameCell.Value = Pool.Name;
_nameCell.Image = null;
_statusCell.Value = Pool.CallHomeSettings.StatusDescription;
_statusCell.Image = Pool.CallHomeSettings.Status != CallHomeStatus.Enabled
? Properties.Resources._000_error_h32bit_16
: Properties.Resources._000_Alert2_h32bit_16;
}
}
#endregion
private void RefreshButtons()
{
if (poolsDataGridView.SelectedRows.Count == 1 && poolsDataGridView.SelectedRows[0] is PoolRow)
{
currentSelected = (Pool)((PoolRow)poolsDataGridView.SelectedRows[0]).Pool;
}
else
{
if (poolsDataGridView.SelectedRows.Count == 0)
currentSelected = null;
}
poolDetailsPanel.Visible = (currentSelected != null);
}
private void RefreshDetailsPanel()
{
if (poolsDataGridView.SelectedRows.Count != 1 || !(poolsDataGridView.SelectedRows[0] is PoolRow))
{
poolNameLabel.Text = "";
return;
}
var poolRow = (PoolRow)poolsDataGridView.SelectedRows[0];
poolNameLabel.Text = poolRow.Pool.Name.Ellipsise(120);
scheduleLabel.Text = GetScheduleDescription(poolRow.Pool.CallHomeSettings);
healthCheckStatusPanel.Visible = poolRow.Pool.CallHomeSettings.Status == CallHomeStatus.Enabled;
notEnrolledPanel.Visible = poolRow.Pool.CallHomeSettings.Status != CallHomeStatus.Enabled;
UpdateUploadRequestDescription(poolRow.Pool.CallHomeSettings);
}
public string GetScheduleDescription(CallHomeSettings callHomeSettings)
{
{
var time = new DateTime(1900, 1, 1, callHomeSettings.TimeOfDay, 0, 0);
return callHomeSettings.Status == CallHomeStatus.Enabled
? string.Format(Messages.CALLHOME_SCHEDULE_DESCRIPTION, callHomeSettings.IntervalInWeeks,
callHomeSettings.DayOfWeek, HelpersGUI.DateTimeToString(time, Messages.DATEFORMAT_HM, true))
: string.Empty;
}
}
public void UpdateUploadRequestDescription(CallHomeSettings callHomeSettings)
{
{
double uploadRequest;
if (!callHomeSettings.CanRequestNewUpload && double.TryParse(callHomeSettings.NewUploadRequest, out uploadRequest))
{
uploadRequestLinkLabel.Text = string.Format(Messages.HEALTHCHECK_ON_DEMAND_REQUESTED_AT,
HelpersGUI.DateTimeToString(Util.FromUnixTime(uploadRequest), Messages.DATEFORMAT_HM, true));
uploadRequestLinkLabel.LinkArea = new LinkArea(0, 0);
return;
}
uploadRequestLinkLabel.Text = Messages.HEALTHCHECK_ON_DEMAND_REQUEST;
uploadRequestLinkLabel.LinkArea = new LinkArea(0, uploadRequestLinkLabel.Text.Length);
}
}
private void CallHomeOverview_Load(object sender, EventArgs e)
{
LoadPools();
foreach (IXenConnection xenConnection in ConnectionsManager.XenConnectionsCopy)
{
xenConnection.Cache.RegisterBatchCollectionChanged<Pool>(Pool_BatchCollectionChanged);
}
}
private void dataGridView1_SelectionChanged(object sender, EventArgs e)
{
RefreshButtons();
RefreshDetailsPanel();
}
private void CallHomeOverviewDialog_FormClosed(object sender, FormClosedEventArgs e)
{
foreach (IXenConnection xenConnection in ConnectionsManager.XenConnectionsCopy)
{
xenConnection.Cache.DeregisterBatchCollectionChanged<Pool>(Pool_BatchCollectionChanged);
}
}
private void buttonCancel_Click(object sender, EventArgs e)
{
Close();
}
private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
if (poolsDataGridView.SelectedRows.Count != 1 || !(poolsDataGridView.SelectedRows[0] is PoolRow))
return;
var poolRow = (PoolRow)poolsDataGridView.SelectedRows[0];
new CallHomeSettingsDialog(poolRow.Pool).ShowDialog(this);
}
public DialogResult ShowDialog(IWin32Window parent, List<IXenObject> selectedItems)
{
SelectPool(selectedItems);
return ShowDialog(parent);
}
public void RefreshView(List<IXenObject> selectedItems)
{
SelectPool(selectedItems);
LoadPools();
}
private void SelectPool(List<IXenObject> selectedItems)
{
IXenObject xo = selectedItems.Count > 0 ? selectedItems.FirstOrDefault() : null;
if (xo is Pool)
currentSelected = xo as Pool;
}
private void enrollNowLinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
if (poolsDataGridView.SelectedRows.Count != 1 || !(poolsDataGridView.SelectedRows[0] is PoolRow))
return;
var poolRow = (PoolRow)poolsDataGridView.SelectedRows[0];
var callHomeSettings = poolRow.Pool.CallHomeSettings;
if (callHomeSettings.Status != CallHomeStatus.Enabled)
{
// try to enroll into call home with the default settings, if authentication is not required
var token = callHomeSettings.GetSecretyInfo(poolRow.Pool.Connection, CallHomeSettings.UPLOAD_TOKEN_SECRET);
var user = callHomeSettings.GetSecretyInfo(poolRow.Pool.Connection, CallHomeSettings.UPLOAD_CREDENTIAL_USER_SECRET);
var password = callHomeSettings.GetSecretyInfo(poolRow.Pool.Connection, CallHomeSettings.UPLOAD_CREDENTIAL_PASSWORD_SECRET);
if (!string.IsNullOrEmpty(token) && !string.IsNullOrEmpty(user) && !string.IsNullOrEmpty(password))
{
if (!string.IsNullOrEmpty(token) && !string.IsNullOrEmpty(user) && !string.IsNullOrEmpty(password))
{
callHomeSettings.Status = CallHomeStatus.Enabled;
new SaveCallHomeSettingsAction(poolRow.Pool, callHomeSettings, token, user, password, false).RunAsync();
new TransferCallHomeSettingsAction(poolRow.Pool, callHomeSettings, user, password, true).RunAsync();
return;
}
new CallHomeEnrollNowDialog(poolRow.Pool).ShowDialog(this);
return;
}
new CallHomeSettingsDialog(poolRow.Pool).ShowDialog(this);
}
private void uploadRequestLinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
if (poolsDataGridView.SelectedRows.Count != 1 || !(poolsDataGridView.SelectedRows[0] is PoolRow))
return;
var poolRow = (PoolRow)poolsDataGridView.SelectedRows[0];
var callHomeSettings = poolRow.Pool.CallHomeSettings;
if (callHomeSettings.CanRequestNewUpload)
new TransferCallHomeSettingsAction(poolRow.Pool, callHomeSettings, user, password, true).RunAsync();
return;
}
new CallHomeEnrollNowDialog(poolRow.Pool).ShowDialog(this);
return;
}
new CallHomeSettingsDialog(poolRow.Pool).ShowDialog(this);
}
private void uploadRequestLinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
if (poolsDataGridView.SelectedRows.Count != 1 || !(poolsDataGridView.SelectedRows[0] is PoolRow))
return;
var poolRow = (PoolRow)poolsDataGridView.SelectedRows[0];
var callHomeSettings = poolRow.Pool.CallHomeSettings;
if (callHomeSettings.CanRequestNewUpload)
{
callHomeSettings.NewUploadRequest = DateTime.UtcNow.ToString();
new SaveCallHomeSettingsAction(poolRow.Pool, callHomeSettings, null, null, null, false).RunAsync();
}
}
}
}
callHomeSettings.NewUploadRequest = DateTime.UtcNow.ToString();
new SaveCallHomeSettingsAction(poolRow.Pool, callHomeSettings, null, null, null, false).RunAsync();
}
}
}
}

View File

@ -1,200 +1,200 @@
/* 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.Windows.Forms;
using XenAdmin.Actions;
using XenAdmin.Core;
using XenAPI;
namespace XenAdmin.Dialogs.CallHome
{
public partial class CallHomeSettingsDialog : XenDialogBase
{
private readonly Pool pool;
private CallHomeSettings callHomeSettings;
private bool authenticationRequired;
private bool authenticated;
private string authenticationToken;
/* 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.Windows.Forms;
using XenAdmin.Actions;
using XenAdmin.Core;
using XenAPI;
namespace XenAdmin.Dialogs.CallHome
{
public partial class CallHomeSettingsDialog : XenDialogBase
{
private readonly Pool pool;
private CallHomeSettings callHomeSettings;
private bool authenticationRequired;
private bool authenticated;
private string authenticationToken;
private string usetName;
private string password;
public CallHomeSettingsDialog(Pool pool)
{
this.pool = pool;
private string password;
public CallHomeSettingsDialog(Pool pool)
{
this.pool = pool;
callHomeSettings = pool.CallHomeSettings;
authenticationToken = callHomeSettings.GetExistingSecretyInfo(pool.Connection, CallHomeSettings.UPLOAD_TOKEN_SECRET);
usetName = callHomeSettings.GetSecretyInfo(pool.Connection, CallHomeSettings.UPLOAD_CREDENTIAL_USER_SECRET);
password = callHomeSettings.GetSecretyInfo(pool.Connection, CallHomeSettings.UPLOAD_CREDENTIAL_PASSWORD_SECRET);
InitializeComponent();
PopulateControls();
InitializeControls();
UpdateButtons();
}
private void PopulateControls()
{
var list = BuildDays();
var ds = new BindingSource(list, null);
dayOfWeekComboBox.DataSource = ds;
dayOfWeekComboBox.ValueMember = "key";
dayOfWeekComboBox.DisplayMember = "value";
var list1 = BuildHours();
var ds1 = new BindingSource(list1, null);
timeOfDayComboBox.DataSource = ds1;
timeOfDayComboBox.ValueMember = "key";
timeOfDayComboBox.DisplayMember = "value";
}
private Dictionary<int, string> BuildDays()
{
Dictionary<int, string> days = new Dictionary<int, string>();
foreach (var dayOfWeek in Enum.GetValues(typeof(DayOfWeek)))
{
days.Add((int)dayOfWeek, dayOfWeek.ToString());
}
return days;
}
private SortedDictionary<int, string> BuildHours()
{
SortedDictionary<int, string> hours = new SortedDictionary<int, string>();
for (int hour = 0; hour <= 23; hour++)
{
DateTime time = new DateTime(1900, 1, 1, hour, 0, 0);
hours.Add(hour, HelpersGUI.DateTimeToString(time, Messages.DATEFORMAT_HM, true));
}
return hours;
}
private void InitializeControls()
{
authenticationRequired = string.IsNullOrEmpty(authenticationToken);
authenticated = !authenticationRequired;
Text = String.Format(Messages.CALLHOME_ENROLLMENT_TITLE, pool.Name);
authenticationRubricLabel.Text = authenticationRequired
? Messages.CALLHOME_AUTHENTICATION_RUBRIC_NO_TOKEN
: Messages.CALLHOME_AUTHENTICATION_RUBRIC_EXISTING_TOKEN;
enrollmentCheckBox.Checked = callHomeSettings.Status != CallHomeStatus.Disabled;
frequencyNumericBox.Value = callHomeSettings.IntervalInWeeks;
dayOfWeekComboBox.SelectedValue = (int)callHomeSettings.DayOfWeek;
timeOfDayComboBox.SelectedValue = callHomeSettings.TimeOfDay;
existingAuthenticationRadioButton.Enabled = existingAuthenticationRadioButton.Checked = !authenticationRequired;
newAuthenticationRadioButton.Checked = authenticationRequired;
callHomeAuthenticationPanel1.Enabled = newAuthenticationRadioButton.Checked;
callHomeAuthenticationPanel1.Pool = pool;
}
private bool ChangesMade()
{
if (enrollmentCheckBox.Checked && callHomeSettings.Status != CallHomeStatus.Enabled)
return true;
if (!enrollmentCheckBox.Checked && callHomeSettings.Status != CallHomeStatus.Disabled)
return true;
if (frequencyNumericBox.Value != callHomeSettings.IntervalInWeeks)
return true;
if (dayOfWeekComboBox.SelectedIndex != (int)callHomeSettings.DayOfWeek)
return true;
if (timeOfDayComboBox.SelectedIndex != callHomeSettings.TimeOfDay)
return true;
password = callHomeSettings.GetSecretyInfo(pool.Connection, CallHomeSettings.UPLOAD_CREDENTIAL_PASSWORD_SECRET);
InitializeComponent();
PopulateControls();
InitializeControls();
UpdateButtons();
}
private void PopulateControls()
{
var list = BuildDays();
var ds = new BindingSource(list, null);
dayOfWeekComboBox.DataSource = ds;
dayOfWeekComboBox.ValueMember = "key";
dayOfWeekComboBox.DisplayMember = "value";
var list1 = BuildHours();
var ds1 = new BindingSource(list1, null);
timeOfDayComboBox.DataSource = ds1;
timeOfDayComboBox.ValueMember = "key";
timeOfDayComboBox.DisplayMember = "value";
}
private Dictionary<int, string> BuildDays()
{
Dictionary<int, string> days = new Dictionary<int, string>();
foreach (var dayOfWeek in Enum.GetValues(typeof(DayOfWeek)))
{
days.Add((int)dayOfWeek, dayOfWeek.ToString());
}
return days;
}
private SortedDictionary<int, string> BuildHours()
{
SortedDictionary<int, string> hours = new SortedDictionary<int, string>();
for (int hour = 0; hour <= 23; hour++)
{
DateTime time = new DateTime(1900, 1, 1, hour, 0, 0);
hours.Add(hour, HelpersGUI.DateTimeToString(time, Messages.DATEFORMAT_HM, true));
}
return hours;
}
private void InitializeControls()
{
authenticationRequired = string.IsNullOrEmpty(authenticationToken);
authenticated = !authenticationRequired;
Text = String.Format(Messages.CALLHOME_ENROLLMENT_TITLE, pool.Name);
authenticationRubricLabel.Text = authenticationRequired
? Messages.CALLHOME_AUTHENTICATION_RUBRIC_NO_TOKEN
: Messages.CALLHOME_AUTHENTICATION_RUBRIC_EXISTING_TOKEN;
enrollmentCheckBox.Checked = callHomeSettings.Status != CallHomeStatus.Disabled;
frequencyNumericBox.Value = callHomeSettings.IntervalInWeeks;
dayOfWeekComboBox.SelectedValue = (int)callHomeSettings.DayOfWeek;
timeOfDayComboBox.SelectedValue = callHomeSettings.TimeOfDay;
existingAuthenticationRadioButton.Enabled = existingAuthenticationRadioButton.Checked = !authenticationRequired;
newAuthenticationRadioButton.Checked = authenticationRequired;
callHomeAuthenticationPanel1.Enabled = newAuthenticationRadioButton.Checked;
callHomeAuthenticationPanel1.Pool = pool;
}
private bool ChangesMade()
{
if (enrollmentCheckBox.Checked && callHomeSettings.Status != CallHomeStatus.Enabled)
return true;
if (!enrollmentCheckBox.Checked && callHomeSettings.Status != CallHomeStatus.Disabled)
return true;
if (frequencyNumericBox.Value != callHomeSettings.IntervalInWeeks)
return true;
if (dayOfWeekComboBox.SelectedIndex != (int)callHomeSettings.DayOfWeek)
return true;
if (timeOfDayComboBox.SelectedIndex != callHomeSettings.TimeOfDay)
return true;
if (authenticationToken != callHomeSettings.GetSecretyInfo(pool.Connection, CallHomeSettings.UPLOAD_TOKEN_SECRET))
return true;
if (usetName != callHomeSettings.GetSecretyInfo(pool.Connection, CallHomeSettings.UPLOAD_CREDENTIAL_USER_SECRET))
return true;
if (password != callHomeSettings.GetSecretyInfo(pool.Connection, CallHomeSettings.UPLOAD_CREDENTIAL_PASSWORD_SECRET))
return true;
return false;
}
private void UpdateButtons()
{
okButton.Enabled = !enrollmentCheckBox.Checked || authenticated;
okButton.Text = callHomeSettings.Status == CallHomeStatus.Enabled || !enrollmentCheckBox.Checked
? Messages.OK
: Messages.CALLHOME_ENROLLMENT_CONFIRMATION_BUTTON_LABEL;
}
private void okButton_Click(object sender, EventArgs e)
{
if (ChangesMade())
{
var newCallHomeSettings = new CallHomeSettings(
enrollmentCheckBox.Checked ? CallHomeStatus.Enabled : CallHomeStatus.Disabled,
(int) (frequencyNumericBox.Value * 7),
(DayOfWeek) dayOfWeekComboBox.SelectedValue,
(int) timeOfDayComboBox.SelectedValue,
if (password != callHomeSettings.GetSecretyInfo(pool.Connection, CallHomeSettings.UPLOAD_CREDENTIAL_PASSWORD_SECRET))
return true;
return false;
}
private void UpdateButtons()
{
okButton.Enabled = !enrollmentCheckBox.Checked || authenticated;
okButton.Text = callHomeSettings.Status == CallHomeStatus.Enabled || !enrollmentCheckBox.Checked
? Messages.OK
: Messages.CALLHOME_ENROLLMENT_CONFIRMATION_BUTTON_LABEL;
}
private void okButton_Click(object sender, EventArgs e)
{
if (ChangesMade())
{
var newCallHomeSettings = new CallHomeSettings(
enrollmentCheckBox.Checked ? CallHomeStatus.Enabled : CallHomeStatus.Disabled,
(int) (frequencyNumericBox.Value * 7),
(DayOfWeek) dayOfWeekComboBox.SelectedValue,
(int) timeOfDayComboBox.SelectedValue,
CallHomeSettings.DefaultRetryInterval);
new SaveCallHomeSettingsAction(pool, newCallHomeSettings, authenticationToken, usetName, password, false).RunAsync();
new TransferCallHomeSettingsAction(pool, newCallHomeSettings, usetName, password, true).RunAsync();
}
DialogResult = DialogResult.OK;
Close();
}
private void cancelButton_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
private void enrollmentCheckBox_CheckedChanged(object sender, EventArgs e)
{
UpdateButtons();
}
private void callHomeAuthenticationPanel1_AuthenticationChanged(object sender, EventArgs e)
{
Program.Invoke(this, delegate
{
if (callHomeAuthenticationPanel1.Authenticated)
{
new TransferCallHomeSettingsAction(pool, newCallHomeSettings, usetName, password, true).RunAsync();
}
DialogResult = DialogResult.OK;
Close();
}
private void cancelButton_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
private void enrollmentCheckBox_CheckedChanged(object sender, EventArgs e)
{
UpdateButtons();
}
private void callHomeAuthenticationPanel1_AuthenticationChanged(object sender, EventArgs e)
{
Program.Invoke(this, delegate
{
if (callHomeAuthenticationPanel1.Authenticated)
{
authenticated = true;
authenticationToken = pool.CallHomeSettings.GetExistingSecretyInfo(pool.Connection, CallHomeSettings.UPLOAD_TOKEN_SECRET);
}
UpdateButtons();
});
}
private void newAuthenticationRadioButton_CheckedChanged(object sender, EventArgs e)
{
callHomeAuthenticationPanel1.Enabled = newAuthenticationRadioButton.Checked;
authenticated = existingAuthenticationRadioButton.Checked || callHomeAuthenticationPanel1.Authenticated;
UpdateButtons();
}
}
authenticationToken = pool.CallHomeSettings.GetExistingSecretyInfo(pool.Connection, CallHomeSettings.UPLOAD_TOKEN_SECRET);
}
UpdateButtons();
});
}
private void newAuthenticationRadioButton_CheckedChanged(object sender, EventArgs e)
{
callHomeAuthenticationPanel1.Enabled = newAuthenticationRadioButton.Checked;
authenticated = existingAuthenticationRadioButton.Checked || callHomeAuthenticationPanel1.Authenticated;
UpdateButtons();
}
}
}

View File

@ -132,7 +132,7 @@ namespace XenServerHealthCheck
session.login_with_password(server.UserName, server.Password);
connectionInfo.LoadCache(session);
if (RequestUploadTask.Request(connectionInfo, session) || RequestUploadTask.OnDemandRequest(connectionInfo, session))
{
{
// Create a task to collect server status report and upload to CIS server
log.InfoFormat("Start to upload server status report for XenServer {0}", connectionInfo.Hostname);
@ -142,7 +142,7 @@ namespace XenServerHealthCheck
upload.runUpload();
};
System.Threading.Tasks.Task task = new System.Threading.Tasks.Task(uploadAction);
task.Start();
task.Start();
}
session.logout();
session = null;