Skip to content

Commit

Permalink
Merge pull request #3 from dills122/release100
Browse files Browse the repository at this point in the history
Release100
  • Loading branch information
dills122 authored Oct 19, 2018
2 parents 2296364 + 1dd3dd4 commit 0714260
Show file tree
Hide file tree
Showing 20 changed files with 80 additions and 150 deletions.
14 changes: 2 additions & 12 deletions ShamWow/Attributes/DecimalAtr.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,15 @@
using ShamWow.Constants;
using System;
using System.Collections.Generic;
using System.Text;

namespace ShamWow.Attributes
{
class DecimalAtr : Attribute
{
public DecimalType scrubType { get; private set; }

public string scrubType { get; private set; }

public DecimalAtr(string scrubType)
public DecimalAtr(DecimalType scrubType)
{
DecimalTypes type;
Enum.TryParse(scrubType, out type);
this.scrubType = scrubType;
if (!Enum.IsDefined(typeof(DecimalTypes), scrubType))
{
//Not the best fit, but good for now
throw new InvalidOperationException("Not Valid Scrub Type");
}
}
}
}
12 changes: 2 additions & 10 deletions ShamWow/Attributes/DoubleAtr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,11 @@ namespace ShamWow.Attributes
{
public class DoubleAtr : Attribute
{
public DoubleType scrubType { get; private set; }

public string scrubType { get; private set; }

public DoubleAtr(string scrubType)
public DoubleAtr(DoubleType scrubType)
{
DoubleTypes type;
Enum.TryParse(scrubType, out type);
this.scrubType = scrubType;
if (!Enum.IsDefined(typeof(DoubleTypes), scrubType))
{
//Not the best fit, but good for now
throw new InvalidOperationException("Not Valid Scrub Type");
}
}
}
}
11 changes: 2 additions & 9 deletions ShamWow/Attributes/IntAtr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,11 @@ namespace ShamWow.Attributes
public class IntAtr : Attribute
{

public string scrubType { get; private set; }
public IntType scrubType { get; private set; }

public IntAtr(string scrubType)
public IntAtr(IntType scrubType)
{
IntTypes type;
Enum.TryParse(scrubType, out type);
this.scrubType = scrubType;
if (!Enum.IsDefined(typeof(IntTypes), scrubType))
{
//Not the best fit, but good for now
throw new InvalidOperationException("Not Valid Scrub Type");
}
}
}
}
4 changes: 1 addition & 3 deletions ShamWow/Attributes/Scrub.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace ShamWow.Attributes
{

public class Scrub : Attribute
{

Expand Down
28 changes: 5 additions & 23 deletions ShamWow/Attributes/StringAtr.cs
Original file line number Diff line number Diff line change
@@ -1,43 +1,25 @@
using ShamWow.Constants;
using System;
using System.Collections.Generic;
using System.Text;

namespace ShamWow.Attributes
{
public class StringAtr : Attribute
{
public string scrubType { get; private set; }
public StringType scrubType { get; private set; }
public int length { get; private set; }

public StringAtr(string scrubType)
public StringAtr(StringType scrubType)
{
if (CheckAttr(scrubType))
{
this.scrubType = scrubType;
}
this.scrubType = scrubType;
}

public StringAtr(string scrubType, int length)
public StringAtr(StringType scrubType, int length)
{
if (CheckAttr(scrubType) && length > 0)
if (length > 0)
{
this.scrubType = scrubType;
this.length = length;
}
}

private bool CheckAttr(string scrubType)
{
StringTypes type;
Enum.TryParse(scrubType, out type);

if (!Enum.IsDefined(typeof(StringTypes), scrubType))
{
//Not the best fit, but good for now
throw new InvalidOperationException("Not Valid Scrub Type");
}
return true;
}
}
}
20 changes: 8 additions & 12 deletions ShamWow/Constants/ScrubbingType.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace ShamWow.Constants
namespace ShamWow.Constants
{
public enum ScrubTypes
public enum ScrubType
{
Full,
Marked
}

public enum StringTypes
public enum StringType
{
Address,
AddressTwo,
Expand All @@ -25,24 +21,24 @@ public enum StringTypes
LastName,
FirstName,
MiddleName,
UserName
UserName,
Lorem
}

public enum IntTypes
public enum IntType
{
Phone,
Zip,
VIN,
PIN,

}

public enum DoubleTypes
public enum DoubleType
{

}

public enum DecimalTypes
public enum DecimalType
{

}
Expand Down
7 changes: 1 addition & 6 deletions ShamWow/Exceptions/NotSupportedTypeException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@ namespace ShamWow.Exceptions
{
public class NotSupportedTypeException : Exception
{
string message = "Type not supported by scrubber yet";

public NotSupportedTypeException()
{

}
public NotSupportedTypeException() : base("Type not supported by scrubber") { }

public NotSupportedTypeException(string message) : base(message) { }
}
Expand Down
6 changes: 3 additions & 3 deletions ShamWow/Processor/Factory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ namespace ShamWow.Processor
{
public class Factory
{
private Func<Object, ScrubTypes, ProcessDocument> _ctorCaller;
private Func<Object, ScrubType, ProcessDocument> _ctorCaller;

public Factory (Func<Object, ScrubTypes, ProcessDocument> ctorCaller)
public Factory (Func<Object, ScrubType, ProcessDocument> ctorCaller)
{
_ctorCaller = ctorCaller;
}

public ProcessDocument Create(object unScrubbedData, ScrubTypes scrubType)
public ProcessDocument Create(object unScrubbedData, ScrubType scrubType)
{
if(unScrubbedData != null)
{
Expand Down
1 change: 0 additions & 1 deletion ShamWow/Processor/ManifestBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Data.HashFunction;
using System.Data.HashFunction.xxHash;
using System.Reflection;
using System.Text;

namespace ShamWow.Processor
{
Expand Down
7 changes: 3 additions & 4 deletions ShamWow/Processor/ProcessDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using ShamWow.Constants;
using ShamWow.Attributes;
Expand All @@ -16,9 +15,9 @@ public class ProcessDocument : Router, IProcessDocument
private object _dataInstance;
private DocumentManifest _manifest;
private bool _IsScrubbed = false;
private ScrubTypes _scrubType;
private ScrubType _scrubType;

private ProcessDocument(object dirtyDataInstance, ScrubTypes scrubType)
private ProcessDocument(object dirtyDataInstance, ScrubType scrubType)
{
if (dirtyDataInstance == null)
{
Expand Down Expand Up @@ -73,7 +72,7 @@ public DocumentManifest GetManifest()
public ProcessDocument Scrub()
{
var IsFiltered =
_scrubType == ScrubTypes.Marked ? true : false;
_scrubType == ScrubType.Marked ? true : false;

ScrubCollections(GetCollections(IsFiltered));

Expand Down
52 changes: 26 additions & 26 deletions ShamWow/Processor/RouteScrubber.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ private void CleanUp()
}


public DocumentManifestInfo RouteType(PropertyInfo property, ref object dataInstance, ref ScrubTypes scrubType)
public DocumentManifestInfo RouteType(PropertyInfo property, ref object dataInstance, ref ScrubType scrubType)
{
if (Equals(property.PropertyType, typeof(System.Int32)))
{
Expand Down Expand Up @@ -52,58 +52,61 @@ public DocumentManifestInfo RouteType(PropertyInfo property, ref object dataInst
}

//Implement the rest of the Attributes
private object RouteStringType(PropertyInfo property, ref object cleanDataInstance, ScrubTypes scrubType)
private object RouteStringType(PropertyInfo property, ref object cleanDataInstance, ScrubType scrubType)
{
_dirtyData = property.GetValue(cleanDataInstance, null);

var data = property.GetCustomAttribute(typeof(StringAtr));
if (data != null)
{
StringAtr atr = data as StringAtr;
string attrScrubType = atr.scrubType;
StringType attrScrubType = atr.scrubType;

switch (attrScrubType)
{
case "SSN":
case StringType.SSN:
property.SetValue(cleanDataInstance, ScrubBasicTypes.ScrubSSN());
break;
case "Phone":
case StringType.Phone:
property.SetValue(cleanDataInstance, Faker.Phone.Number());
break;
case "Email":
case StringType.Email:
property.SetValue(cleanDataInstance, Faker.Internet.Email());
break;
case "Address":
case StringType.Address:
property.SetValue(cleanDataInstance, Faker.Address.StreetAddress());
break;
case "AddressTwo":
case StringType.AddressTwo:
property.SetValue(cleanDataInstance, Faker.Address.SecondaryAddress());
break;
case "City":
case StringType.City:
property.SetValue(cleanDataInstance, Faker.Address.City());
break;
case "State":
case StringType.State:
property.SetValue(cleanDataInstance, Faker.Address.UsState());
break;
case "Zip":
case StringType.Zip:
property.SetValue(cleanDataInstance, Faker.Address.ZipCode());
break;
case "FullName":
case StringType.FullName:
property.SetValue(cleanDataInstance, Faker.Name.FullName());
break;
case "FirstName":
case StringType.FirstName:
property.SetValue(cleanDataInstance, Faker.Name.First());
break;
case "LastName":
case StringType.LastName:
property.SetValue(cleanDataInstance, Faker.Name.Last());
break;
case "MiddleName":
case StringType.MiddleName:
//Two First Names
property.SetValue(cleanDataInstance, Faker.Name.First());
break;
case "UserName":
case StringType.UserName:
property.SetValue(cleanDataInstance, Faker.Internet.UserName());
break;
case StringType.Lorem:
property.SetValue(cleanDataInstance, Faker.Lorem.Sentence(atr.length));
break;
default:
//TODO Update to lorem
property.SetValue(cleanDataInstance, Faker.Lorem.Sentence());
Expand All @@ -112,7 +115,7 @@ private object RouteStringType(PropertyInfo property, ref object cleanDataInstan

_cleanData = property.GetValue(cleanDataInstance, null);
}
else if (scrubType == ScrubTypes.Full)
else if (scrubType == ScrubType.Full)
{
property.SetValue(cleanDataInstance, Faker.Lorem.Sentence());

Expand All @@ -131,39 +134,36 @@ private void CreateManifestoItem(PropertyInfo property)
}


private object RouteDoubleType(PropertyInfo property, ref object cleanDataInstance, ScrubTypes scrubType)
private object RouteDoubleType(PropertyInfo property, ref object cleanDataInstance, ScrubType scrubType)
{
_dirtyData = property.GetValue(cleanDataInstance, null);

return cleanDataInstance;
}

private object RouteDecimalType(PropertyInfo property, ref object cleanDataInstance, ScrubTypes scrubType)
private object RouteDecimalType(PropertyInfo property, ref object cleanDataInstance, ScrubType scrubType)
{
_dirtyData = property.GetValue(cleanDataInstance, null);

return cleanDataInstance;
}

private object RouteIntegerType(PropertyInfo property, ref object cleanDataInstance, ScrubTypes scrubType)
private object RouteIntegerType(PropertyInfo property, ref object cleanDataInstance, ScrubType scrubType)
{
_dirtyData = property.GetValue(cleanDataInstance, null);

var data = property.GetCustomAttribute(typeof(IntAtr));
if (data != null)
{
IntAtr atr = data as IntAtr;
string attrScrubType = atr.scrubType;
IntType attrScrubType = atr.scrubType;

switch (attrScrubType)
{
case "Zip":
case IntType.Zip:
property.SetValue(cleanDataInstance, Convert.ToInt32(Faker.Address.ZipCode().Replace("-", string.Empty)));
break;
case "Phone":
//property.SetValue(cleanDataInstance, Convert.ToInt32(Faker.Phone.Number().Replace("-", string.Empty)));
break;
case "VIN":
case IntType.VIN:
//TODO improve
property.SetValue(cleanDataInstance, Faker.RandomNumber.Next(10000000, 99999999));
break;
Expand Down
1 change: 1 addition & 0 deletions ShamWow/ShamWow.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<Description>A class srubber that can be used for removing personally identifiable information.</Description>
<RepositoryUrl>https://github.com/dills122/ShamWow</RepositoryUrl>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageLicenseUrl>https://github.com/dills122/ShamWow/blob/master/LICENSE</PackageLicenseUrl>
</PropertyGroup>

<ItemGroup>
Expand Down
Loading

0 comments on commit 0714260

Please sign in to comment.