Ran code maid against this code.

This commit is contained in:
Lars Brubaker 2015-04-08 15:20:10 -07:00
parent 1445945d9c
commit 591528ee91
309 changed files with 139399 additions and 140129 deletions

View file

@ -3,13 +3,13 @@ Copyright (c) 2014, Kevin Pope
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
list of conditions and the following disclaimer.
2. 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.
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
@ -23,330 +23,267 @@ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The views and conclusions contained in the software and documentation are those
of the authors and should not be interpreted as representing official policies,
of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the FreeBSD Project.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Diagnostics;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.DataStorage
{
public class Entity
{
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
public class Entity
{
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
protected bool isSaved;
protected int hashCode = 0;
public event PropertyChangedEventHandler PropertyChanged;
IEnumerable<PropertyInfo> properties;
protected bool isSaved;
protected int hashCode = 0;
public event PropertyChangedEventHandler PropertyChanged;
public Entity()
{
isSaved = false;
}
private IEnumerable<PropertyInfo> properties;
static readonly int maxRetries = 20;
int retryCount = 0;
private void TryHandleInsert()
{
retryCount++;
try
{
if (retryCount < maxRetries)
{
Datastore.Instance.dbSQLite.Insert(this);
}
}
catch (Exception)
{
Thread.Sleep(100);
this.TryHandleInsert();
}
public Entity()
{
isSaved = false;
}
retryCount = 0;
}
private static readonly int maxRetries = 20;
private int retryCount = 0;
private void TryHandleUpdate()
{
retryCount++;
try
{
if (retryCount < maxRetries)
{
Datastore.Instance.dbSQLite.Update(this);
}
}
catch (Exception)
{
Thread.Sleep(100);
this.TryHandleUpdate();
}
private void TryHandleInsert()
{
retryCount++;
try
{
if (retryCount < maxRetries)
{
Datastore.Instance.dbSQLite.Insert(this);
}
}
catch (Exception)
{
Thread.Sleep(100);
this.TryHandleInsert();
}
retryCount = 0;
}
retryCount = 0;
}
public virtual void Commit()
{
//Assumes that autoincremented ids start with 1
if (this.Id == 0)
{
TryHandleInsert();
}
else
{
TryHandleUpdate();
}
}
private void TryHandleUpdate()
{
retryCount++;
try
{
if (retryCount < maxRetries)
{
Datastore.Instance.dbSQLite.Update(this);
}
}
catch (Exception)
{
Thread.Sleep(100);
this.TryHandleUpdate();
}
public void Delete()
{
Datastore.Instance.dbSQLite.Delete(this);
}
retryCount = 0;
}
protected void OnPropertyChanged(string name)
{
PropertyChangedEventHandler handler = PropertyChanged;
this.hashCode = 0;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(name));
}
}
public virtual void Commit()
{
//Assumes that autoincremented ids start with 1
if (this.Id == 0)
{
TryHandleInsert();
}
else
{
TryHandleUpdate();
}
}
public override int GetHashCode()
{
StringBuilder bigStringForHashCode = new StringBuilder();
public void Delete()
{
Datastore.Instance.dbSQLite.Delete(this);
}
if (this.hashCode == 0)
{
properties = this.GetType()
.GetProperties(BindingFlags.Instance |
BindingFlags.Public)
// Ignore non-string properties
.Where(prop => prop.PropertyType == typeof(string) || prop.PropertyType == typeof(int))
// Ignore indexers
.Where(prop => prop.GetIndexParameters().Length == 0)
// Must be both readable and writable
.Where(prop => prop.CanWrite && prop.CanRead);
protected void OnPropertyChanged(string name)
{
PropertyChangedEventHandler handler = PropertyChanged;
this.hashCode = 0;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(name));
}
}
foreach (PropertyInfo prop in properties)
{
object objectHoldingValue = prop.GetValue(this, null);
if (objectHoldingValue != null)
{
string value = objectHoldingValue.ToString();
if (value != null)
{
bigStringForHashCode.Append(prop.Name);
bigStringForHashCode.Append(value);
}
}
}
this.hashCode = bigStringForHashCode.ToString().GetHashCode();
}
public override int GetHashCode()
{
StringBuilder bigStringForHashCode = new StringBuilder();
return this.hashCode;
}
}
if (this.hashCode == 0)
{
properties = this.GetType()
.GetProperties(BindingFlags.Instance |
BindingFlags.Public)
// Ignore non-string properties
.Where(prop => prop.PropertyType == typeof(string) || prop.PropertyType == typeof(int))
// Ignore indexers
.Where(prop => prop.GetIndexParameters().Length == 0)
// Must be both readable and writable
.Where(prop => prop.CanWrite && prop.CanRead);
public class ApplicationSession : Entity
{
public DateTime SessionStart { get; set; }
public DateTime SessionEnd { get; set; }
public int PrintCount { get; set; }
foreach (PropertyInfo prop in properties)
{
object objectHoldingValue = prop.GetValue(this, null);
if (objectHoldingValue != null)
{
string value = objectHoldingValue.ToString();
if (value != null)
{
bigStringForHashCode.Append(prop.Name);
bigStringForHashCode.Append(value);
}
}
}
this.hashCode = bigStringForHashCode.ToString().GetHashCode();
}
public ApplicationSession()
: base()
{
SessionStart = DateTime.Now;
PrintCount = 0;
}
}
return this.hashCode;
}
}
public class PrintItemCollection : Entity
{
public string Name { get; set; }
}
public class ApplicationSession : Entity
{
public DateTime SessionStart { get; set; }
public class PrintItem : Entity
{
[Indexed]
public int PrintItemCollectionID { get; set; }
public string Name { get; set; }
public string FileLocation { get; set; }
public DateTime DateAdded { get; set; }
public int PrintCount { get; set; }
public DateTime SessionEnd { get; set; }
public PrintItem()
: this("", "")
{
}
public int PrintCount { get; set; }
public PrintItem(string name, string fileLocation)
{
this.Name = name;
this.FileLocation = fileLocation;
public ApplicationSession()
: base()
{
SessionStart = DateTime.Now;
PrintCount = 0;
}
}
DateAdded = DateTime.Now;
PrintCount = 0;
}
}
public class PrintItemCollection : Entity
{
public string Name { get; set; }
}
public class SliceSettingsCollection : Entity
{
public string Name { get; set; }
public string Tag { get; set; } //ex. 'material' or 'quality'
public int PrinterId { get; set; }
}
public class PrintItem : Entity
{
[Indexed]
public int PrintItemCollectionID { get; set; }
public class SliceSetting : Entity
{
[Indexed]
public int SettingsCollectionId { get; set; }
public string Name { get; set; }
public string Value { get; set; }
public string Name { get; set; }
public SliceSetting()
: base()
{
}
}
public string FileLocation { get; set; }
public class PrintTask : Entity
{
[Indexed]
public int PrinterId { get; set; }
[Indexed]
public int PrintItemId { get; set; }
public string PrintName { get; set; }
public DateTime PrintStart { get; set; }
public DateTime PrintEnd { get; set; }
public int PrintTimeSeconds { get; set; }
public bool PrintComplete { get; set; }
public DateTime DateAdded { get; set; }
public PrintTask()
: base()
{
PrintStart = DateTime.Now;
}
public int PrintCount { get; set; }
public int PrintTimeMinutes
{
get
{
TimeSpan printTimeSpan = PrintEnd.Subtract(PrintStart);
public PrintItem()
: this("", "")
{
}
return (int)(printTimeSpan.TotalMinutes + .5);
}
}
public PrintItem(string name, string fileLocation)
{
this.Name = name;
this.FileLocation = fileLocation;
public override void Commit()
{
if (this.PrintEnd != DateTime.MinValue)
{
TimeSpan printTimeSpan = PrintEnd.Subtract(PrintStart);
PrintTimeSeconds = (int)printTimeSpan.TotalSeconds;
}
base.Commit();
}
}
DateAdded = DateTime.Now;
PrintCount = 0;
}
}
public class SystemSetting : Entity
{
[Indexed]
public string Name { get; set; }
public string Value { get; set; }
public DateTime DateLastModified { get; set; }
public class SliceSettingsCollection : Entity
{
public string Name { get; set; }
public override void Commit()
{
DateLastModified = DateTime.Now;
base.Commit();
}
}
public string Tag { get; set; } //ex. 'material' or 'quality'
public class UserSetting : Entity
{
[Indexed]
public string Name { get; set; }
public string Value { get; set; }
public DateTime DateLastModified { get; set; }
public int PrinterId { get; set; }
}
public override void Commit()
{
DateLastModified = DateTime.Now;
base.Commit();
}
}
public class SliceSetting : Entity
{
[Indexed]
public int SettingsCollectionId { get; set; }
public class CustomCommands : Entity
{
[Indexed]
public int PrinterId { get; set; }
public string Name { get; set; }
public string Value { get; set; }
public DateTime DateLastModified { get; set; }
public string Name { get; set; }
public override void Commit()
{
DateLastModified = DateTime.Now;
base.Commit();
}
}
public string Value { get; set; }
public class Printer : Entity
{
public int DefaultSettingsCollectionId { get; set; }
public string Name { get; set; }
public string Make { get; set; }
public string Model { get; set; }
public string ComPort { get; set; }
public string BaudRate { get; set; }
public bool AutoConnectFlag { get; set; } //Auto connect to printer (if available)
public string DeviceToken { get; set; }
public string DeviceType { get; set; }
// all the data about print leveling
public bool DoPrintLeveling { get; set; }
public string PrintLevelingJsonData { get; set; }
public string PrintLevelingProbePositions { get; set; } // this is depricated go through PrintLevelingData
public SliceSetting()
: base()
{
}
}
// features
public string _features { get; set; }
public string ManualMovementSpeeds { get; set; } // stored x,value,y,value,z,value,e1,value,e2,value,e3,value,...
public string CurrentSlicingEngine { get; set; }
public string MaterialCollectionIds { get; set; } // store id1,id2... (for N extruders)
public int QualityCollectionId { get; set; }
public Printer()
: base()
{
this.Make = "Unknown";
this.Model = "Unknown";
}
}
public class PrinterSetting : Entity
public class PrintTask : Entity
{
[Indexed]
public int PrinterId { get; set; }
[Indexed]
public int PrintItemId { get; set; }
public string PrintName { get; set; }
public DateTime PrintStart { get; set; }
public DateTime PrintEnd { get; set; }
public int PrintTimeSeconds { get; set; }
public bool PrintComplete { get; set; }
public PrintTask()
: base()
{
PrintStart = DateTime.Now;
}
public int PrintTimeMinutes
{
get
{
TimeSpan printTimeSpan = PrintEnd.Subtract(PrintStart);
return (int)(printTimeSpan.TotalMinutes + .5);
}
}
public override void Commit()
{
if (this.PrintEnd != DateTime.MinValue)
{
TimeSpan printTimeSpan = PrintEnd.Subtract(PrintStart);
PrintTimeSeconds = (int)printTimeSpan.TotalSeconds;
}
base.Commit();
}
}
public class SystemSetting : Entity
{
[Indexed]
public string Name { get; set; }
public string Value { get; set; }
public DateTime DateLastModified { get; set; }
public override void Commit()
@ -355,4 +292,102 @@ namespace MatterHackers.MatterControl.DataStorage
base.Commit();
}
}
}
public class UserSetting : Entity
{
[Indexed]
public string Name { get; set; }
public string Value { get; set; }
public DateTime DateLastModified { get; set; }
public override void Commit()
{
DateLastModified = DateTime.Now;
base.Commit();
}
}
public class CustomCommands : Entity
{
[Indexed]
public int PrinterId { get; set; }
public string Name { get; set; }
public string Value { get; set; }
public DateTime DateLastModified { get; set; }
public override void Commit()
{
DateLastModified = DateTime.Now;
base.Commit();
}
}
public class Printer : Entity
{
public int DefaultSettingsCollectionId { get; set; }
public string Name { get; set; }
public string Make { get; set; }
public string Model { get; set; }
public string ComPort { get; set; }
public string BaudRate { get; set; }
public bool AutoConnectFlag { get; set; } //Auto connect to printer (if available)
public string DeviceToken { get; set; }
public string DeviceType { get; set; }
// all the data about print leveling
public bool DoPrintLeveling { get; set; }
public string PrintLevelingJsonData { get; set; }
public string PrintLevelingProbePositions { get; set; } // this is depricated go through PrintLevelingData
// features
public string _features { get; set; }
public string ManualMovementSpeeds { get; set; } // stored x,value,y,value,z,value,e1,value,e2,value,e3,value,...
public string CurrentSlicingEngine { get; set; }
public string MaterialCollectionIds { get; set; } // store id1,id2... (for N extruders)
public int QualityCollectionId { get; set; }
public Printer()
: base()
{
this.Make = "Unknown";
this.Model = "Unknown";
}
}
public class PrinterSetting : Entity
{
[Indexed]
public int PrinterId { get; set; }
public string Name { get; set; }
public string Value { get; set; }
public DateTime DateLastModified { get; set; }
public override void Commit()
{
DateLastModified = DateTime.Now;
base.Commit();
}
}
}