Skip to content

Commit

Permalink
revert arkovean's changes on Microdot
Browse files Browse the repository at this point in the history
  • Loading branch information
arkovean authored and David Bronshtein committed Jul 15, 2018
1 parent edbad14 commit 503e21b
Show file tree
Hide file tree
Showing 18 changed files with 236 additions and 640 deletions.
7 changes: 0 additions & 7 deletions .paket/install.bat

This file was deleted.

1 change: 0 additions & 1 deletion Gigya.Microdot.Hosting/Gigya.Microdot.Hosting.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@
<Compile Include="HttpService\ServiceMethodResolver.cs" />
<Compile Include="Metrics\MetricsConfiguration.cs" />
<Compile Include="Metrics\MetricsInitializer.cs" />
<Compile Include="Validators\SensitivityAttributesValidator.cs" />
<Compile Include="Service\ServiceHostBase.cs" />
<Compile Include="Service\HostExtensionMethods.cs" />
<Compile Include="HttpService\Endpoints\HealthStatusResult.cs" />
Expand Down
24 changes: 1 addition & 23 deletions Gigya.Microdot.Hosting/Validators/LogFieldAttributeValidator.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,4 @@
#region Copyright
// Copyright 2017 Gigya Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
#endregion

using System;
using System;
using System.Linq;
using System.Reflection;
using Gigya.Common.Contracts.Exceptions;
Expand Down

This file was deleted.

53 changes: 27 additions & 26 deletions Gigya.Microdot.SharedLogic/Events/MetadataPropertiesCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ namespace Gigya.Microdot.SharedLogic.Events

public class ReflectionMetadataInfo
{
public string Name { get; set; }
public string PropertyName { get; set; }
public Func<object, object> ValueExtractor { get; set; }

public Sensitivity? Sensitivity { get; set; }
}

Expand Down Expand Up @@ -76,7 +77,7 @@ public IEnumerable<MetadataCacheParam> ParseIntoParams(object instance)

private IEnumerable<MetadataCacheParam> ExtracParams(object instance, Type type)
{
var propertyMetadata = _propertyMetadataCache.GetOrAdd(type, x => ExtracMemberMetadata(instance, type).ToArray());
var propertyMetadata = _propertyMetadataCache.GetOrAdd(type, x => ExtracPropertiesMetadata(instance, type).ToArray());

foreach (var item in propertyMetadata)
{
Expand All @@ -88,52 +89,52 @@ private IEnumerable<MetadataCacheParam> ExtracParams(object instance, Type type)
}
catch (Exception ex)
{
_log.Warn("This property is invalid", unencryptedTags: new { propertyName = item.Name }, exception: ex);
_log.Warn("This property is invalid",unencryptedTags:new { propertyName= item.PropertyName},exception: ex);
continue;
}

yield return new MetadataCacheParam
{
Name = item.Name,
Name = item.PropertyName,
Value = value,
Sensitivity = item.Sensitivity
};
}
}

internal static IEnumerable<ReflectionMetadataInfo> ExtracMemberMetadata(object instance, Type type)
internal static IEnumerable<ReflectionMetadataInfo> ExtracPropertiesMetadata(object instance, Type type)
{
var list = new List<ReflectionMetadataInfo>();
var members = type.FindMembers(MemberTypes.Property | MemberTypes.Field,
BindingFlags.Public | BindingFlags.Instance, null, null)
.Where(x => x is FieldInfo || ((x is PropertyInfo propertyInfo) && propertyInfo.CanRead));

foreach (var member in members)
{
var instanceParameter = Expression.Parameter(typeof(object), "target");
MemberExpression memberExpression = null;
var getters = type.GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(p => p.CanRead)
.Select(x => new
{
Getter = x.GetGetMethod(),
PropertyName = x.Name,
Sensitivity = ExtractSensitivity(x) // nullable
});

if (member.MemberType == MemberTypes.Property)
memberExpression = Expression.Property(Expression.Convert(instanceParameter, member.DeclaringType), (PropertyInfo)member);
else if (member.MemberType == MemberTypes.Field)
memberExpression = Expression.Field(Expression.Convert(instanceParameter, member.DeclaringType), (FieldInfo)member);
var metadatas = new List<ReflectionMetadataInfo>();

var converter = Expression.Convert(memberExpression, typeof(object));
var lambda = Expression.Lambda<Func<object, object>>(converter, instanceParameter);
foreach (var getter in getters)
{
var entity = Expression.Parameter(typeof(object));
var getterCall = Expression.Call(Expression.Convert(entity, type), getter.Getter);
var castToObject = Expression.Convert(getterCall, typeof(object));
var lambda = Expression.Lambda<Func<object, object>>(castToObject, entity);

list.Add(new ReflectionMetadataInfo
metadatas.Add(new ReflectionMetadataInfo
{
Name = member.Name,
PropertyName = getter.PropertyName,
ValueExtractor = lambda.Compile(),
Sensitivity = ExtractSensitivity(member)
Sensitivity = getter.Sensitivity
});
}
return list;

return metadatas;
}

internal static Sensitivity? ExtractSensitivity(MemberInfo memberInfo)
internal static Sensitivity? ExtractSensitivity(PropertyInfo propertyInfo)
{
var attribute = memberInfo.GetCustomAttributes()
var attribute = propertyInfo.GetCustomAttributes()
.FirstOrDefault(x => x is SensitiveAttribute || x is NonSensitiveAttribute);

if (attribute != null)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Gigya.Microdot.SharedLogic.Events;
Expand All @@ -9,9 +8,18 @@ namespace Gigya.Microdot.Testing.Shared.Helpers
{
public static class DissectPropertyInfoMetadata
{
public static Sensitivity? ExtractSensitivityFromPropertyInfo(MemberInfo memberInfo)
public static IEnumerable<(PropertyInfo PropertyInfo, Sensitivity Sensitivity)> DissectPropertis<TType>(TType instance, Sensitivity defualtSensitivity = Sensitivity.Sensitive) where TType : class
{
var attribute = memberInfo.GetCustomAttributes()
foreach (var propertyInfo in instance.GetType().GetProperties())
{
var sensitivity = ExtractSensitivityFromPropertyInfo(propertyInfo) ?? defualtSensitivity;
yield return (propertyInfo, sensitivity);
}
}

public static Sensitivity? ExtractSensitivityFromPropertyInfo(PropertyInfo propertyInfo)
{
var attribute = propertyInfo.GetCustomAttributes()
.FirstOrDefault(x => x is SensitiveAttribute || x is NonSensitiveAttribute);

if (attribute != null)
Expand All @@ -32,48 +40,5 @@ public static class DissectPropertyInfoMetadata

return null;
}


public static IEnumerable<(object Value, MemberTypes MemberType, string Name, Sensitivity? Sensitivity, bool WithException, MemberInfo Member)> GetMemberWithSensitivity<TInstance>(TInstance instance, Sensitivity defualtSensitivity = Sensitivity.Sensitive) where TInstance : class
{
var members = GetMembers(instance).ToArray();

foreach (var member in members)
{
var sensitivity = ExtractSensitivityFromPropertyInfo(member.Member);
yield return (member.Value, member.MemberType, member.Name, sensitivity, member.WithException, member.Member);
}
}

public static IEnumerable<(object Value, MemberTypes MemberType, string Name, bool WithException, MemberInfo Member)> GetMembers<TInstance>(TInstance instance) where TInstance : class
{
var members = instance.GetType().FindMembers(MemberTypes.Property | MemberTypes.Field, BindingFlags.Public | BindingFlags.Instance, null, null)
.Where(x => (x is FieldInfo) || ((x is PropertyInfo propertyInfo) && propertyInfo.CanRead));

foreach (var member in members)
{
var withException = false;
if (member.MemberType == MemberTypes.Property)
{
object value = null;

try
{
value = ((PropertyInfo)member).GetValue(instance);
}
catch (Exception)
{
withException = true;
}

yield return (value, MemberTypes.Property, member.Name, withException, member);
}
else
{
if (member.MemberType == MemberTypes.Field)
yield return (((FieldInfo)member).GetValue(instance), MemberTypes.Field, member.Name, withException, member);
}
}
}
}
}
Binary file modified Gigya.ServiceContract/.paket/paket.exe
Binary file not shown.
1 change: 0 additions & 1 deletion Gigya.ServiceContract/Attributes/HttpServiceAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public HttpServiceAttribute(int basePort)
{
BasePort = basePort;
}

public string Name { get; set; }
}
}
7 changes: 3 additions & 4 deletions Gigya.ServiceContract/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,9 @@
[assembly: AssemblyTrademark("")]


[assembly: AssemblyInformationalVersion("2.5.7")]// if pre-release should be in the format of "2.4.11-pre01".
[assembly: AssemblyVersion("2.5.7")]
[assembly: AssemblyFileVersion("2.5.7")]

[assembly: AssemblyInformationalVersion("2.5.6")]// if pre-release should be in the format of "2.4.11-pre01".
[assembly: AssemblyVersion("2.5.6")]
[assembly: AssemblyFileVersion("2.5.6")]


[assembly: AssemblyDescription("")]
Expand Down
3 changes: 1 addition & 2 deletions Microdot.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ VisualStudioVersion = 15.0.27130.2027
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".paket", ".paket", "{0F8FE343-E0B1-4762-AF4F-1BD949761AA1}"
ProjectSection(SolutionItems) = preProject
.paket\install.bat = .paket\install.bat
paket.dependencies = paket.dependencies
paket.lock = paket.lock
.paket\restore.bat = .paket\restore.bat
Expand Down Expand Up @@ -176,7 +175,7 @@ Global
{10E10FDE-8A2C-4D5D-8FC1-15FACF844E80} = {79538186-DFAD-463C-B4D1-CD0917CF5954}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {8A847321-B6B0-4BA9-9AC3-0DB91FA99B90}
EnterpriseLibraryConfigurationToolBinariesPathV6 = packages\EnterpriseLibrary.TransientFaultHandling.6.0.1304.0\lib\portable-net45+win+wp8
SolutionGuid = {8A847321-B6B0-4BA9-9AC3-0DB91FA99B90}
EndGlobalSection
EndGlobal
6 changes: 3 additions & 3 deletions SolutionVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
[assembly: AssemblyCopyright("© 2018 Gigya Inc.")]
[assembly: AssemblyDescription("Microdot Framework")]

[assembly: AssemblyVersion("1.10.6.0")]
[assembly: AssemblyFileVersion("1.10.6.0")]
[assembly: AssemblyInformationalVersion("1.10.6.0")]
[assembly: AssemblyVersion("1.10.5.0")]
[assembly: AssemblyFileVersion("1.10.5.0")]
[assembly: AssemblyInformationalVersion("1.10.5.0")]


// Setting ComVisible to false makes the types in this assembly not visible
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,24 +408,9 @@ public class InnerCarMockClass
[Serializable]
public class Teacher : Person
{

[NonSensitive]
public string FieldNonSensitive = "FieldName";


[Sensitive(Secretive = false)]

public string FieldSensitive = "FieldSensitive";

[Sensitive(Secretive = true)]

public string FieldCryptic = "FieldCryptic";


[NonSensitive]
public string School { get; set; } = "Busmat";
}

#endregion
}
}
Loading

0 comments on commit 503e21b

Please sign in to comment.