Files
win8phoneApp/CampusAppWP8/CampusAppWP8/File/Exams/ExamFile.cs
2013-09-12 16:02:00 +02:00

115 lines
3.4 KiB
C#

//-----------------------------------------------------------------------
// <copyright file="ExamFile.cs" company="BTU/IIT">
// Company copyright tag.
// </copyright>
// <author>stubbfel</author>
// <sience>03.09.2013</sience>
//----------------------------------------------------------------------
namespace CampusAppWP8.File.Exams
{
using System.IO;
using CampusAppWP8.Model;
using Windows.Storage;
/// <summary>Exam file.</summary>
/// <remarks>Stubbfel, 03.09.2013.</remarks>
public class ExamFile : BinaryModel
{
#region Member
/// <summary>The storage file.</summary>
private StorageFile storageFile;
#endregion
#region Constructor
/// <summary>Initializes a new instance of the ExamFile class.</summary>
/// <remarks>Stubbfel, 03.09.2013.</remarks>
/// <param name="fileName">Filename of the file.</param>
/// <param name="url"> URL of the document.</param>
public ExamFile(string fileName, string url)
: base(ModelType.FileAndFeed, fileName, url)
{
this.IsFileUpToDateOnLoad += new IsFileUpToDate(this.CheckIsFileUpToDate);
this.IsModelUpToDateOnLoad += new IsModelUpToDate(this.CheckIsModelUpToDate);
this.IsFileUpToDateOnSave += new IsFileUpToDate(this.CheckIsFileUpToDate);
}
#endregion
#region Method
#region public
/// <summary>Executes the file operation.</summary>
/// <remarks>Stubbfel, 03.09.2013.</remarks>
public async void LaunchFile()
{
if (this.storageFile == null)
{
this.storageFile = await this.file.AsStorageFile();
}
if (this.storageFile != null)
{
var options = new Windows.System.LauncherOptions();
Windows.System.Launcher.LaunchFileAsync(this.storageFile);
}
}
#endregion
/// <summary>Saves the and launch file.</summary>
/// <remarks>Stubbfel, 03.09.2013.</remarks>
public void SaveAndLaunchFile()
{
if (this.file.Exist())
{
this.LaunchFile();
}
else
{
this.OnSaved += new ExamFile.OnIO(this.LaunchFile);
this.SaveData();
}
}
#region private
/// <summary>Check is model up to date.</summary>
/// <remarks>Stubbfel, 03.09.2013.</remarks>
/// <param name="model">The model.</param>
/// <returns>true if it succeeds, false if it fails.</returns>
private bool CheckIsModelUpToDate(byte[] model)
{
if (model == null)
{
return false;
}
return true;
}
/// <summary>Check is file up to date.</summary>
/// <remarks>Stubbfel, 03.09.2013.</remarks>
/// <param name="model"> The model.</param>
/// <param name="fileInfo">Information describing the file.</param>
/// <returns>true if it succeeds, false if it fails.</returns>
private bool CheckIsFileUpToDate(byte[] model, FileInfo fileInfo)
{
if (fileInfo == null || !fileInfo.Exists || fileInfo.Length < 1 || model != null)
{
return false;
}
return true;
}
#endregion
#endregion
}
}