Skip to content

Commit

Permalink
2.4.0.0 - Do not load screenshots if exceed configured maximum number…
Browse files Browse the repository at this point in the history
… allowed in load.
  • Loading branch information
gavinkendall committed Jan 31, 2022
1 parent b27c49d commit d67c0ce
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 9 deletions.
2 changes: 1 addition & 1 deletion interface/main/FormMain-Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ private void LoadSettings()
_screenshotCollection.LoadXmlFile(_config);

// Encryptor / Decryptor
_formEncryptorDecryptor = new FormEncryptorDecryptor(_log, _security, _fileSystem, _screenshotCollection);
_formEncryptorDecryptor = new FormEncryptorDecryptor(_log, _config, _security, _fileSystem, _screenshotCollection);
_formEncryptorDecryptor.screenshotsEncrypted += ScreenshotsEncrypted;
_formEncryptorDecryptor.screenshotsDecrypted += ScreenshotsDecrypted;

Expand Down
51 changes: 46 additions & 5 deletions interface/tools/FormEncryptorDecryptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ namespace AutoScreenCapture
/// </summary>
public partial class FormEncryptorDecryptor : Form
{
private const int MAX_SCREENSHOTS_TO_LOAD = 5000;

private Log _log;
private Security _security;
private FileSystem _fileSystem;
Expand All @@ -46,6 +44,9 @@ public partial class FormEncryptorDecryptor : Form
private delegate void RunScreenshotsEncryptionDelegate();
private delegate void RunScreenshotsDecryptionDelegate();

private int _totalNodeLoadCount;
private int _screenshotsLoadLimit;

/// <summary>
/// When the "Encryptor / Decryptor" tool has finished encrypting screenshots.
/// </summary>
Expand All @@ -60,13 +61,16 @@ public partial class FormEncryptorDecryptor : Form
/// Constructor.
/// </summary>
/// <param name="log">The logging class.</param>
/// <param name="config">Configuration.</param>
/// <param name="security">Security.</param>
/// <param name="fileSystem">File system.</param>
/// <param name="screenshotCollection">Screenshot collection.</param>
public FormEncryptorDecryptor(Log log, Security security, FileSystem fileSystem, ScreenshotCollection screenshotCollection)
public FormEncryptorDecryptor(Log log, Config config, Security security, FileSystem fileSystem, ScreenshotCollection screenshotCollection)
{
InitializeComponent();

_screenshotsLoadLimit = Convert.ToInt32(config.Settings.Application.GetByKey("ScreenshotsLoadLimit", config.Settings.DefaultSettings.ScreenshotsLoadLimit).Value);

_log = log;
_security = security;
_fileSystem = fileSystem;
Expand Down Expand Up @@ -140,6 +144,8 @@ private void FormEncryptorDecryptor_FormClosing(object sender, FormClosingEventA
/// </summary>
private void LoadScreenshots()
{
_totalNodeLoadCount = 0;

toolStripStatusLabel.Text = "Loading screenshots between " + dateTimePickerScreenshotsStartDateRange.Value.Date.ToString("yyyy-MM-dd") + " and " + dateTimePickerScreenshotsEndDateRange.Value.Date.ToString("yyyy-MM-dd");

if (!runScreenshotLoad.IsBusy)
Expand All @@ -155,6 +161,11 @@ private void LoadScreenshots()
/// <param name="e"></param>
private void buttonEncryptScreenshots_Click(object sender, EventArgs e)
{
if (dataGridViewScreenshots.Rows.Count == 0)
{
return;
}

if (!runScreenshotsEncryption.IsBusy)
{
buttonEncryptScreenshots.Enabled = false;
Expand All @@ -172,6 +183,11 @@ private void buttonEncryptScreenshots_Click(object sender, EventArgs e)
/// <param name="e"></param>
private void buttonDecryptScreenshots_Click(object sender, EventArgs e)
{
if (dataGridViewScreenshots.Rows.Count == 0)
{
return;
}

if (!runScreenshotsDecryption.IsBusy)
{
buttonDecryptScreenshots.Enabled = false;
Expand Down Expand Up @@ -255,7 +271,23 @@ private void RunScreenshotLoad()
{
foreach (string dateStr in _screenshotCollection.GetDatesByFilter(comboBoxFilterType.Text, comboBoxFilterValue.Text))
{
_screenshotCollection.LoadXmlFileAndAddScreenshots(dateStr, MAX_SCREENSHOTS_TO_LOAD, out int errorCode);
if (DateTime.Parse(dateStr) >= dateTimePickerScreenshotsStartDateRange.Value &&
DateTime.Parse(dateStr) <= dateTimePickerScreenshotsEndDateRange.Value)
{
_screenshotCollection.LoadXmlFileAndAddScreenshots(dateStr, _screenshotsLoadLimit, out int nodeLoadCount, out int errorCode);

_totalNodeLoadCount += nodeLoadCount;

if (_totalNodeLoadCount >= _screenshotsLoadLimit)
{
return;
}

if (errorCode == 2)
{
return;
}
}
}

if (_screenshotCollection.Count == 0)
Expand Down Expand Up @@ -439,7 +471,16 @@ private void UpdateScreenshotCollection(Screenshot screenshot)
/// <param name="e"></param>
protected void OnScreenshotLoadCompleted(object sender, EventArgs e)
{
toolStripStatusLabel.Text = dataGridViewScreenshots.Rows.Count + " screenshots loaded";
if (_totalNodeLoadCount >= _screenshotsLoadLimit)
{
dataGridViewScreenshots.DataSource = null;

toolStripStatusLabel.Text = "Total number of screenshots to be loaded exceeded configured maximum number allowed in load. Please reduce date range or filter appropriately";
}
else
{
toolStripStatusLabel.Text = dataGridViewScreenshots.Rows.Count + " screenshots loaded";
}
}

/// <summary>
Expand Down
17 changes: 14 additions & 3 deletions modules/screenshots/ScreenshotCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ public List<Slide> GetSlides(string filterType, string filterValue, string date,

int screenshotsLoadLimit = Convert.ToInt32(config.Settings.Application.GetByKey("ScreenshotsLoadLimit", config.Settings.DefaultSettings.ScreenshotsLoadLimit).Value);

LoadXmlFileAndAddScreenshots(date, screenshotsLoadLimit, out int errorCode);
LoadXmlFileAndAddScreenshots(date, screenshotsLoadLimit, out int nodeLoadCount, out int errorCode);

if (errorCode == 1)
{
Expand Down Expand Up @@ -810,11 +810,14 @@ private List<string> LoadXmlFileAndReturnNodeValues(string nodeName, string node
/// </summary>
/// <param name="date">The date to load screenshots from.</param>
/// <param name="screenshotsLoadLimit">The maximum number of screenshots that can be loaded.</param>
/// <param name="nodeLoadCount">The number of nodes loaded.</param>
/// <param name="errorCode">The error code that is returned based on what type of error is encountered.</param>
public void LoadXmlFileAndAddScreenshots(string date, int screenshotsLoadLimit, out int errorCode)
public void LoadXmlFileAndAddScreenshots(string date, int screenshotsLoadLimit, out int nodeLoadCount, out int errorCode)
{
try
{
nodeLoadCount = 0;

errorCode = 0;

_mutexWriteFile.WaitOne();
Expand All @@ -824,6 +827,8 @@ public void LoadXmlFileAndAddScreenshots(string date, int screenshotsLoadLimit,
if (string.IsNullOrEmpty(date))
{
errorCode = 1;

return;
}

if (xDoc != null)
Expand All @@ -834,16 +839,20 @@ public void LoadXmlFileAndAddScreenshots(string date, int screenshotsLoadLimit,
AppCodename = xDoc.SelectSingleNode("/autoscreen").Attributes["app:codename"]?.Value;

_log.WriteDebugMessage("Loading screenshots taken on " + date + " from \"" + _fileSystem.ScreenshotsFile + "\" using XPath query \"" + SCREENSHOT_XPATH + "[date='" + date + "']" + "\"");

xScreenshots = xDoc.SelectNodes(SCREENSHOT_XPATH + "[date='" + date + "']");

if (xScreenshots != null)
{
_log.WriteDebugMessage("Loading " + xScreenshots.Count + " screenshots taken on " + date);

nodeLoadCount = xScreenshots.Count;

if (xScreenshots.Count >= screenshotsLoadLimit)
{
errorCode = 2;

return;
}

foreach (XmlNode xScreenshot in xScreenshots)
Expand Down Expand Up @@ -1107,6 +1116,8 @@ public void LoadXmlFileAndAddScreenshots(string date, int screenshotsLoadLimit,

_log.WriteExceptionMessage("ScreenshotCollection::LoadXmlFileAndAddScreenshots", ex);

nodeLoadCount = 0;

errorCode = -1;
}
finally
Expand Down

0 comments on commit d67c0ce

Please sign in to comment.