2017-05-15 07:30:27 +01:00
//
// Author:
// Natalia Portillo claunia@claunia.com
//
// Copyright (c) 2017, © Claunia.com
//
// 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.
// * Neither the name of the [ORGANIZATION] nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
//
// 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 OWNER 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.
//
2017-12-30 00:32:21 +00:00
2017-05-15 07:30:27 +01:00
using System ;
using Eto.Forms ;
using Eto.Serialization.Xaml ;
2017-05-15 07:33:13 +01:00
using Schemas ;
2017-05-15 07:30:27 +01:00
2018-02-23 02:14:58 +00:00
namespace apprepodbmgr.Eto
2017-05-15 07:30:27 +01:00
{
2017-05-15 07:33:13 +01:00
public class dlgFilesystem : Dialog
2017-05-15 07:30:27 +01:00
{
2017-05-15 07:33:13 +01:00
public FileSystemType Metadata ;
2017-12-30 00:32:21 +00:00
public bool Modified ;
2017-05-15 07:33:13 +01:00
2017-05-15 07:30:27 +01:00
public dlgFilesystem ( )
{
XamlReader . Load ( this ) ;
2017-05-15 07:33:13 +01:00
Modified = false ;
}
2017-12-30 00:32:21 +00:00
2017-05-15 07:33:13 +01:00
public void FillFields ( )
{
2020-08-22 21:37:02 +01:00
if ( Metadata = = null )
return ;
if ( Metadata . Type ! = null )
txtType . Text = Metadata . Type ;
2017-05-15 07:33:13 +01:00
if ( Metadata . CreationDateSpecified )
{
chkCreationDate . Checked = true ;
cldCreationDate . Enabled = true ;
2017-12-30 00:32:21 +00:00
cldCreationDate . Value = Metadata . CreationDate ;
2017-05-15 07:33:13 +01:00
}
2017-12-30 00:32:21 +00:00
2017-05-15 07:33:13 +01:00
if ( Metadata . ModificationDateSpecified )
{
chkModificationDate . Checked = true ;
cldModificationDate . Enabled = true ;
2017-12-30 00:32:21 +00:00
cldModificationDate . Value = Metadata . ModificationDate ;
2017-05-15 07:33:13 +01:00
}
2017-12-30 00:32:21 +00:00
2017-05-15 07:33:13 +01:00
if ( Metadata . BackupDateSpecified )
{
chkBackupDate . Checked = true ;
cldBackupDate . Enabled = true ;
2017-12-30 00:32:21 +00:00
cldBackupDate . Value = Metadata . BackupDate ;
2017-05-15 07:33:13 +01:00
}
2017-12-30 00:32:21 +00:00
2020-08-22 21:37:02 +01:00
spClusterSize . Value = Metadata . ClusterSize ;
txtClusters . Text = Metadata . Clusters . ToString ( ) ;
if ( Metadata . FilesSpecified )
txtFiles . Text = Metadata . Files . ToString ( ) ;
chkBootable . Checked = Metadata . Bootable ;
if ( Metadata . VolumeSerial ! = null )
txtSerial . Text = Metadata . VolumeSerial ;
if ( Metadata . VolumeName ! = null )
txtLabel . Text = Metadata . VolumeName ;
if ( Metadata . FreeClustersSpecified )
txtFreeClusters . Text = Metadata . FreeClusters . ToString ( ) ;
chkDirty . Checked = Metadata . Dirty ;
2017-05-15 07:33:13 +01:00
if ( Metadata . ExpirationDateSpecified )
{
chkExpirationDate . Checked = true ;
cldExpirationDate . Enabled = true ;
2017-12-30 00:32:21 +00:00
cldExpirationDate . Value = Metadata . ExpirationDate ;
2017-05-15 07:33:13 +01:00
}
2017-12-30 00:32:21 +00:00
2017-05-15 07:33:13 +01:00
if ( Metadata . EffectiveDateSpecified )
{
chkEffectiveDate . Checked = true ;
cldEffectiveDate . Enabled = true ;
2017-12-30 00:32:21 +00:00
cldEffectiveDate . Value = Metadata . EffectiveDate ;
2017-05-15 07:33:13 +01:00
}
2017-12-30 00:32:21 +00:00
2020-08-22 21:37:02 +01:00
if ( Metadata . SystemIdentifier ! = null )
txtSysId . Text = Metadata . SystemIdentifier ;
if ( Metadata . VolumeSetIdentifier ! = null )
txtVolId . Text = Metadata . VolumeSetIdentifier ;
if ( Metadata . PublisherIdentifier ! = null )
txtPubId . Text = Metadata . PublisherIdentifier ;
if ( Metadata . DataPreparerIdentifier ! = null )
txtDataId . Text = Metadata . DataPreparerIdentifier ;
if ( Metadata . ApplicationIdentifier ! = null )
txtAppId . Text = Metadata . ApplicationIdentifier ;
2017-05-15 07:33:13 +01:00
}
2020-08-22 21:37:02 +01:00
protected void OnChkCreationDateToggled ( object sender , EventArgs e ) = >
2017-05-15 07:33:13 +01:00
cldCreationDate . Enabled = chkCreationDate . Checked . Value ;
2020-08-22 21:37:02 +01:00
protected void OnChkModificationDateToggled ( object sender , EventArgs e ) = >
2017-05-15 07:33:13 +01:00
cldModificationDate . Enabled = chkModificationDate . Checked . Value ;
2020-08-22 21:37:02 +01:00
protected void OnChkEffectiveDateToggled ( object sender , EventArgs e ) = >
2017-05-15 07:33:13 +01:00
cldEffectiveDate . Enabled = chkEffectiveDate . Checked . Value ;
2020-08-22 21:37:02 +01:00
protected void OnChkExpirationDateToggled ( object sender , EventArgs e ) = >
2017-05-15 07:33:13 +01:00
cldExpirationDate . Enabled = chkExpirationDate . Checked . Value ;
2020-08-22 21:37:02 +01:00
protected void OnChkBackupDateToggled ( object sender , EventArgs e ) = >
2017-05-15 07:33:13 +01:00
cldBackupDate . Enabled = chkBackupDate . Checked . Value ;
protected void OnBtnCancelClicked ( object sender , EventArgs e )
{
Modified = false ;
Close ( ) ;
}
protected void OnBtnSaveClicked ( object sender , EventArgs e )
{
if ( string . IsNullOrWhiteSpace ( txtType . Text ) )
MessageBox . Show ( "Filesystem type cannot be empty" , MessageBoxType . Error ) ;
2020-08-22 21:37:02 +01:00
if ( spClusterSize . Value < 1 )
MessageBox . Show ( "Clusters must be bigger than 0 bytes" , MessageBoxType . Error ) ;
2017-05-15 07:33:13 +01:00
2017-12-30 00:32:21 +00:00
if ( ! long . TryParse ( txtClusters . Text , out long temp ) )
2017-05-15 07:33:13 +01:00
MessageBox . Show ( "Clusters must be a number" , MessageBoxType . Error ) ;
2020-08-22 21:37:02 +01:00
if ( temp < 1 )
MessageBox . Show ( "Filesystem must have more than 0 clusters" , MessageBoxType . Error ) ;
2017-05-15 07:33:13 +01:00
2020-08-22 21:37:02 +01:00
if ( ! string . IsNullOrWhiteSpace ( txtFiles . Text ) & &
! long . TryParse ( txtFiles . Text , out temp ) )
2017-05-15 07:33:13 +01:00
MessageBox . Show ( "Files must be a number, or empty for unknown" , MessageBoxType . Error ) ;
2020-08-22 21:37:02 +01:00
if ( ! string . IsNullOrWhiteSpace ( txtFiles . Text ) & &
temp < 0 )
2017-05-15 07:33:13 +01:00
MessageBox . Show ( "Files must be positive" , MessageBoxType . Error ) ;
2020-08-22 21:37:02 +01:00
if ( ! string . IsNullOrWhiteSpace ( txtFreeClusters . Text ) & &
! long . TryParse ( txtFreeClusters . Text , out temp ) )
2017-05-15 07:33:13 +01:00
MessageBox . Show ( "Free clusters must be a number or empty for unknown" , MessageBoxType . Error ) ;
2020-08-22 21:37:02 +01:00
if ( ! string . IsNullOrWhiteSpace ( txtFreeClusters . Text ) & &
temp < 0 )
2017-05-15 07:33:13 +01:00
MessageBox . Show ( "Free clusters must be positive" , MessageBoxType . Error ) ;
2020-08-22 21:37:02 +01:00
Metadata = new FileSystemType
{
Type = txtType . Text
} ;
2017-05-15 07:33:13 +01:00
if ( chkCreationDate . Checked . Value )
{
Metadata . CreationDateSpecified = true ;
2017-12-30 00:32:21 +00:00
Metadata . CreationDate = cldCreationDate . Value . Value ;
2017-05-15 07:33:13 +01:00
}
2017-12-30 00:32:21 +00:00
2017-05-15 07:33:13 +01:00
if ( chkModificationDate . Checked . Value )
{
Metadata . ModificationDateSpecified = true ;
2017-12-30 00:32:21 +00:00
Metadata . ModificationDate = cldModificationDate . Value . Value ;
2017-05-15 07:33:13 +01:00
}
2017-12-30 00:32:21 +00:00
2017-05-15 07:33:13 +01:00
if ( chkBackupDate . Checked . Value )
{
Metadata . BackupDateSpecified = true ;
2017-12-30 00:32:21 +00:00
Metadata . BackupDate = cldBackupDate . Value . Value ;
2017-05-15 07:33:13 +01:00
}
2017-12-30 00:32:21 +00:00
2017-05-15 07:33:13 +01:00
Metadata . ClusterSize = ( int ) spClusterSize . Value ;
2017-12-30 00:32:21 +00:00
Metadata . Clusters = long . Parse ( txtClusters . Text ) ;
2020-08-22 21:37:02 +01:00
2017-05-15 07:33:13 +01:00
if ( ! string . IsNullOrWhiteSpace ( txtFiles . Text ) )
{
Metadata . FilesSpecified = true ;
2017-12-30 00:32:21 +00:00
Metadata . Files = long . Parse ( txtFiles . Text ) ;
2017-05-15 07:33:13 +01:00
}
2017-12-30 00:32:21 +00:00
2020-08-22 21:37:02 +01:00
Metadata . Bootable = chkBootable . Checked . Value ;
if ( ! string . IsNullOrWhiteSpace ( txtSerial . Text ) )
Metadata . VolumeSerial = txtSerial . Text ;
if ( ! string . IsNullOrWhiteSpace ( txtLabel . Text ) )
Metadata . VolumeName = txtLabel . Text ;
2017-05-15 07:33:13 +01:00
if ( ! string . IsNullOrWhiteSpace ( txtFreeClusters . Text ) )
{
Metadata . FreeClustersSpecified = true ;
2017-12-30 00:32:21 +00:00
Metadata . FreeClusters = long . Parse ( txtFreeClusters . Text ) ;
2017-05-15 07:33:13 +01:00
}
2017-12-30 00:32:21 +00:00
2017-05-15 07:33:13 +01:00
Metadata . Dirty = chkDirty . Checked . Value ;
2020-08-22 21:37:02 +01:00
2017-05-15 07:33:13 +01:00
if ( chkExpirationDate . Checked . Value )
{
Metadata . ExpirationDateSpecified = true ;
2017-12-30 00:32:21 +00:00
Metadata . ExpirationDate = cldExpirationDate . Value . Value ;
2017-05-15 07:33:13 +01:00
}
2017-12-30 00:32:21 +00:00
2017-05-15 07:33:13 +01:00
if ( chkEffectiveDate . Checked . Value )
{
Metadata . EffectiveDateSpecified = true ;
2017-12-30 00:32:21 +00:00
Metadata . EffectiveDate = cldEffectiveDate . Value . Value ;
2017-05-15 07:33:13 +01:00
}
2017-12-30 00:32:21 +00:00
2020-08-22 21:37:02 +01:00
if ( ! string . IsNullOrWhiteSpace ( txtSysId . Text ) )
Metadata . SystemIdentifier = txtSysId . Text ;
if ( ! string . IsNullOrWhiteSpace ( txtVolId . Text ) )
Metadata . VolumeSetIdentifier = txtVolId . Text ;
if ( ! string . IsNullOrWhiteSpace ( txtPubId . Text ) )
Metadata . PublisherIdentifier = txtPubId . Text ;
if ( ! string . IsNullOrWhiteSpace ( txtDataId . Text ) )
Metadata . DataPreparerIdentifier = txtDataId . Text ;
if ( ! string . IsNullOrWhiteSpace ( txtAppId . Text ) )
Metadata . ApplicationIdentifier = txtAppId . Text ;
2017-05-15 07:33:13 +01:00
Modified = true ;
Close ( ) ;
2017-05-15 07:30:27 +01:00
}
2017-12-30 00:32:21 +00:00
#region XAML UI elements
#pragma warning disable 0649
TextBox txtType ;
TextBox txtFiles ;
CheckBox chkBootable ;
CheckBox chkDirty ;
NumericUpDown spClusterSize ;
TextBox txtClusters ;
TextBox txtFreeClusters ;
CheckBox chkCreationDate ;
DateTimePicker cldCreationDate ;
CheckBox chkModificationDate ;
DateTimePicker cldModificationDate ;
CheckBox chkEffectiveDate ;
DateTimePicker cldEffectiveDate ;
CheckBox chkExpirationDate ;
DateTimePicker cldExpirationDate ;
CheckBox chkBackupDate ;
DateTimePicker cldBackupDate ;
TextBox txtLabel ;
TextBox txtSerial ;
TextBox txtSysId ;
TextBox txtVolId ;
TextBox txtPubId ;
TextBox txtDataId ;
TextBox txtAppId ;
#pragma warning restore 0649
#endregion XAML UI elements
2017-05-15 07:30:27 +01:00
}
2017-05-15 07:33:13 +01:00
}