141 lines
4.0 KiB
C#
141 lines
4.0 KiB
C#
//----------------------------------------------------------------------------
|
|
//
|
|
// Copyright © 2006-2011, Intel Corporation. All rights reserved.
|
|
//
|
|
// File: CountDownTimer.cs
|
|
//
|
|
//----------------------------------------------------------------------------
|
|
|
|
using System;
|
|
using System.Windows.Forms;
|
|
using System.Runtime.InteropServices;
|
|
using UCT.Utils;
|
|
|
|
namespace UCT.Forms
|
|
{
|
|
/// <summary>
|
|
/// The timer control (count down timer for 15 min.)
|
|
/// </summary>
|
|
public partial class CountDownTimer : UserControl
|
|
{
|
|
#region - Members -
|
|
|
|
private string time = String.Empty;
|
|
private long StartTime = 0;
|
|
public static bool consentTimer = false;
|
|
|
|
#endregion
|
|
|
|
#region - Constructors -
|
|
|
|
public CountDownTimer()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region - Methods -
|
|
|
|
#region - Private Methods -
|
|
|
|
/// <summary>
|
|
/// Convert the long string to time
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
private long ConvertSetTime()
|
|
{
|
|
long seconds = 0;
|
|
if (time.Trim().Substring(0, 1) == ":") // if leftmost colon, take it off
|
|
time = time.Substring(1);
|
|
string[] vals = time.Split(new char[] { ':', ' ', '.', '/' });
|
|
for (int i = 0; i < vals.Length; i++)
|
|
{
|
|
seconds += Convert.ToInt32(vals[i]) * (long)Math.Pow((double)60, (double)(vals.Length - (1 + i)));
|
|
}
|
|
|
|
return seconds;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tick event (update the string time)
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void timer_Tick_1(object sender, EventArgs e)
|
|
{
|
|
StartTime--;
|
|
Invalidate();
|
|
lblTimer.Text = ConvertToTime(StartTime);
|
|
if (StartTime <= 0 && consentTimer)
|
|
{
|
|
consentTimer = false;
|
|
DialogResult result = new DialogResult();
|
|
result = AMT_SW_GUI.MessageManager.ShowMessage("User consent expired.To renew and restart the expiration timer, click on StartConsent button.", "Expired consent");
|
|
timer.Stop();
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Convert the tick time to string
|
|
/// </summary>
|
|
/// <param name="tickCount"></param>
|
|
/// <returns></returns>
|
|
private string ConvertToTime(long tickCount)
|
|
{
|
|
// tickcount is in milliseconds, convert to minutes and seconds
|
|
long seconds = tickCount;
|
|
string val = (seconds / 60).ToString("00") + ":" + (seconds % 60).ToString("00");
|
|
return val;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region - Public Methods -
|
|
|
|
/// <summary>
|
|
/// Set the timer time (e.g. for how long the timer will run)
|
|
/// </summary>
|
|
/// <param name="time"></param>
|
|
public void SetTimer(uint Time)
|
|
{
|
|
string timeString = ConvertToTime(Time);
|
|
timer.Stop();
|
|
lblTimer.Text = timeString;
|
|
if (Time <= 0 && consentTimer)
|
|
{
|
|
consentTimer = false;
|
|
DialogResult result = new DialogResult();
|
|
result = AMT_SW_GUI.MessageManager.ShowMessage("User consent expired.To renew and restart the expiration timer, click on StartConsent button.", "Expired consent");
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// String the timer
|
|
/// </summary>
|
|
/// <param name="time"></param>
|
|
public void StartTimer(string Time)
|
|
{
|
|
this.time = Time;
|
|
StartTime = ConvertSetTime();
|
|
timer.Enabled = true;
|
|
consentTimer = true;
|
|
timer.Start();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Cancle the consentTimer
|
|
/// </summary>
|
|
public void CancleConsentTimer()
|
|
{
|
|
consentTimer = false;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
}
|
|
}
|