Skip to content

Commit

Permalink
Merge pull request #1 from dills122/speedImprovements
Browse files Browse the repository at this point in the history
Speed improvements
  • Loading branch information
dills122 authored Sep 21, 2018
2 parents a3f1da5 + 92dae57 commit fe15a61
Show file tree
Hide file tree
Showing 7 changed files with 165 additions and 163 deletions.
15 changes: 15 additions & 0 deletions Build/Build.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FlubuCore" Version="2.12.0" />
</ItemGroup>


<ItemGroup>
<DotNetCliToolReference Include="dotnet-flubu" Version="1.7.0" />
</ItemGroup>
</Project>
25 changes: 25 additions & 0 deletions Build/BuildScript.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using FlubuCore.Context;
using FlubuCore.Scripting;
using System;
using System.Collections.Generic;
using System.Text;

namespace Build
{
class BuildScript : DefaultBuildScript
{
protected override void ConfigureBuildProperties(IBuildPropertiesContext context)
{
context.Properties.Set(BuildProps.CompanyName, "Flubu");
context.Properties.Set(BuildProps.CompanyCopyright, "Copyright (C) 2010-2016 Flubu");
context.Properties.Set(BuildProps.ProductId, "FlubuCoreExample");
context.Properties.Set(BuildProps.ProductName, "FlubuCoreExample");
}
protected override void ConfigureTargets(ITaskContext session)
{
var compile = session.CreateTarget("compile")
.SetDescription("Compiles the solution.")
.AddCoreTask(x => x.Build("..\\ShamWow.sln"));
}
}
}
6 changes: 6 additions & 0 deletions ShamWow.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ShamWow", "ShamWow\ShamWow.
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ShamWowTests", "ShamWowTests\ShamWowTests.csproj", "{983583D1-7EF3-4815-AB95-72D5BE576B50}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Build", "Build\Build.csproj", "{B1E7D303-15FC-4464-BC6D-15537EB68C25}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -27,6 +29,10 @@ Global
{983583D1-7EF3-4815-AB95-72D5BE576B50}.Debug|Any CPU.Build.0 = Debug|Any CPU
{983583D1-7EF3-4815-AB95-72D5BE576B50}.Release|Any CPU.ActiveCfg = Release|Any CPU
{983583D1-7EF3-4815-AB95-72D5BE576B50}.Release|Any CPU.Build.0 = Release|Any CPU
{B1E7D303-15FC-4464-BC6D-15537EB68C25}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B1E7D303-15FC-4464-BC6D-15537EB68C25}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B1E7D303-15FC-4464-BC6D-15537EB68C25}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B1E7D303-15FC-4464-BC6D-15537EB68C25}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
11 changes: 0 additions & 11 deletions ShamWow/Documents.cs

This file was deleted.

216 changes: 117 additions & 99 deletions ShamWow/Processor/ProcessDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Threading.Tasks;
using ShamWow.Constants;
using ShamWow.Attributes;
using System.Linq;

namespace ShamWow.Processor
{
Expand All @@ -27,6 +28,7 @@ public ProcessDocument(object dirtyDataInstance, ScrubTypes scrubType)
//Sets all the intial information
_type = dirtyDataInstance.GetType();
_dataInstance = dirtyDataInstance;
_scrubType = scrubType;
_manifest = new DocumentManifest();
}

Expand Down Expand Up @@ -57,102 +59,159 @@ public DocumentManifest GetManifest()

public ProcessDocument Scrub()
{
var IsFiltered =
_scrubType == ScrubTypes.Marked ? true : false;

//Iterates through all properties of the source type
foreach (var property in _type.GetProperties())
{
RouteMajorPropertyType(property);
}
ScrubCollections(GetCollections(IsFiltered));

ScrubClasses(GetClasses(IsFiltered));

ScrubBaseTypes(GetBaseTypes(IsFiltered));

_IsScrubbed = true;

return this;
}

public bool CheckManifest()
private void ScrubCollections(List<PropertyInfo> properties)
{
if (_IsScrubbed)
foreach (var prop in properties)
{
foreach(var item in _manifest.documentManifestInfos)
{
if(String.Equals(item.cleanDataHash,item.dirtyDataHash))
{
return false;
}
}
return true;
ScrubListItems(prop);
}
return false;
}

private void RouteMajorPropertyType(PropertyInfo property)
private void ScrubClasses(List<PropertyInfo> properties)
{
if (ToScrub(property))
foreach (var prop in properties)
{
//Checks if the property is a class
if (!property.PropertyType.Namespace.Contains("System"))
{
var manifestItems = ScrubClass(property).Result;
//Adds manifest items from inner class
if (manifestItems.Count > 0)
{
_manifest.documentManifestInfos.AddRange(manifestItems);
}
}
else if (property.PropertyType.Namespace.Contains("Collections"))
ScrubClass(prop);
}
}

private void ScrubBaseTypes(List<PropertyInfo> properties)
{
foreach (var prop in properties)
{
var manifestInfo = RouteType(prop, ref _dataInstance, ref _scrubType);
if (manifestInfo != null)
{
ScrubListItems(property).Wait();
_manifest.documentManifestInfos.Add(manifestInfo);
}
else
{
//var dirtyValue = GetPropertyValue(property);
}
}

ScrubProperty(property);
private List<PropertyInfo> GetCollections(bool IsFiltered)
{
var collection = _type.GetProperties().Where(p => IsCollection(p))
.Where(p => GetPropertyValue(p) != null)
.ToList();

//var cleanValue = GetPropertyValue(property);
if (IsFiltered)
{
return FilterProperties(collection);
}
else
{
return collection;
}
}

private List<PropertyInfo> GetClasses(bool IsFiltered)
{
var collection = _type.GetProperties().Where(p => IsClass(p))
.Where(p => GetPropertyValue(p) != null)
.ToList();

//Cant filter classes since they are not required to be marked for inner properties to be scrubbed
return collection;
}

private List<PropertyInfo> GetBaseTypes(bool IsFiltered)
{
var collection = _type.GetProperties().Where(p => !IsClass(p) && !IsCollection(p))
.Where(p => GetPropertyValue(p) != null)
.ToList();

if (IsFiltered)
{
return FilterProperties(collection);
}
else
{
return collection;
}
}

private List<PropertyInfo> FilterProperties(List<PropertyInfo> properties)
{
return properties.Where(p => ProcessingHelper.GetCustomAttributes(p, typeof(Scrub))).ToList();
}

private bool IsCollection(PropertyInfo property)
{
return property.PropertyType.Namespace.Contains("Collections");
}

// _manifest.documentManifestInfos.Add(ManifestBuilder.CreateManifestInfo(property, dirtyValue, cleanValue));
private bool IsClass(PropertyInfo property)
{
return !property.PropertyType.Namespace.Contains("System");
}

public bool CheckManifest()
{
if (_IsScrubbed)
{
foreach (var item in _manifest.documentManifestInfos)
{
if (String.Equals(item.cleanDataHash, item.dirtyDataHash))
{
return false;
}
}
return true;
}
return false;
}

/// <summary>
/// Sets the class values
/// </summary>
/// <param name="property"></param>
/// <returns></returns>
private Task<List<DocumentManifestInfo>> ScrubClass(PropertyInfo property)
private Task ScrubClass(PropertyInfo property)
{
var obj = property.GetValue(_dataInstance);
if (obj != null)
{
ProcessDocument process = new ProcessDocument(obj, _scrubType)
.Scrub();
ProcessDocument process = new ProcessDocument(property.GetValue(_dataInstance), _scrubType)
.Scrub();

property.SetValue(_dataInstance, process.CleanData());

ProcessManifestItems(process.GetManifest().documentManifestInfos);

return Task.CompletedTask;
}

property.SetValue(_dataInstance, process.CleanData());
return Task.FromResult(process.GetManifest().documentManifestInfos);
private void ProcessManifestItems(List<DocumentManifestInfo> manifestInfos)
{
if (manifestInfos.Count > 0)
{
_manifest.documentManifestInfos.AddRange(manifestInfos);
}
return Task.FromResult(new List<DocumentManifestInfo>());
}

/// <summary>
/// Class scrubbing for List items
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
private Task<Tuple<object,List<DocumentManifestInfo>>> ScrubClass(object obj)
private Task<object> ScrubClass(object obj)
{
object cleanedClass = null;
ProcessDocument process = new ProcessDocument(obj, _scrubType)
.Scrub();

if (obj != null)
{
ProcessDocument process = new ProcessDocument(obj, _scrubType)
.Scrub();
cleanedClass = process.CleanData();
return Task.FromResult(new Tuple<object, List<DocumentManifestInfo>>(cleanedClass, process._manifest.documentManifestInfos));
}
ProcessManifestItems(process.GetManifest().documentManifestInfos);

return Task.FromResult(new Tuple<object, List<DocumentManifestInfo>>(cleanedClass, new List<DocumentManifestInfo>()));
return Task.FromResult(process.CleanData());
}

/// <summary>
Expand All @@ -168,58 +227,17 @@ private Task ScrubListItems(PropertyInfo property)
{
for (int i = 0; i < ilist.Count; i++)
{
var tup = ScrubClass(ilist[i]).Result;
if (tup.Item1 != null)
{
//Sets the new object value
ilist[i] = tup.Item1;
}
var obj = ScrubClass(ilist[i]).Result;

if(tup.Item2.Count > 0)
{
_manifest.documentManifestInfos.AddRange(tup.Item2);
}
//Sets the new object value
ilist[i] = obj;
}

property.SetValue(_dataInstance, ilist);
}
return Task.CompletedTask;
}

private void ScrubProperty(PropertyInfo property)
{
var manifestInfo = RouteType(property, ref _dataInstance, ref _scrubType);
if(manifestInfo != null)
{
_manifest.documentManifestInfos.Add(manifestInfo);
}
}

/// <summary>
/// Checks if the property should be scrubbed
/// </summary>
/// <param name="property"></param>
/// <returns></returns>
private bool ToScrub(PropertyInfo property)
{
if (_scrubType == ScrubTypes.Full)
{
return true;
}
else if (_scrubType == ScrubTypes.Marked)
{
if (ProcessingHelper.GetCustomAttributes(property, typeof(Scrub)) && GetPropertyValue(property) != null)
{
return true;
}
}
else
{
return false;
}
return false;
}

/// <summary>
/// Gets the value from the property
/// </summary>
Expand Down
Loading

0 comments on commit fe15a61

Please sign in to comment.