Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@
<Compile Include="..\CoreHelpers.WindowsAzure.Storage.Table\Attributes\PartitionKeyAttribute.cs">
<Link>Attributes\PartitionKeyAttribute.cs</Link>
</Compile>
<Compile Include="..\CoreHelpers.WindowsAzure.Storage.Table\Attributes\RelatedTableAttribute.cs">
<Link>Attributes\RelatedTableAttribute.cs</Link>
</Compile>
<Compile Include="..\CoreHelpers.WindowsAzure.Storage.Table\Attributes\RowKeyAttribute.cs">
<Link>Attributes\RowKeyAttribute.cs</Link>
</Compile>
Expand All @@ -101,6 +104,9 @@
<Compile Include="..\CoreHelpers.WindowsAzure.Storage.Table\Attributes\VirtualTypeAttribute.cs">
<Link>Attributes\VirtualTypeAttribute.cs</Link>
</Compile>
<Compile Include="..\CoreHelpers.WindowsAzure.Storage.Table\DynamicLazy.cs">
<Link>DynamicLazy.cs</Link>
</Compile>
<Compile Include="..\CoreHelpers.WindowsAzure.Storage.Table\DynamicTableEntity.cs">
<Link>DynamicTableEntity.cs</Link>
</Compile>
Expand All @@ -116,9 +122,15 @@
<Compile Include="..\CoreHelpers.WindowsAzure.Storage.Table\Extensions\PropertyInfoSetValueFromEntityProperty.cs">
<Link>Extensions\PropertyInfoSetValueFromEntityProperty.cs</Link>
</Compile>
<Compile Include="..\CoreHelpers.WindowsAzure.Storage.Table\Extensions\TableQueryEx.cs">
<Link>Extensions\TableQueryEx.cs</Link>
</Compile>
<Compile Include="..\CoreHelpers.WindowsAzure.Storage.Table\PagedTableEntityWriter.cs">
<Link>PagedTableEntityWriter.cs</Link>
</Compile>
<Compile Include="..\CoreHelpers.WindowsAzure.Storage.Table\RelatedTableItem.cs">
<Link>RelatedTableItem.cs</Link>
</Compile>
<Compile Include="..\CoreHelpers.WindowsAzure.Storage.Table\StorageContext.cs">
<Link>StorageContext.cs</Link>
</Compile>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace CoreHelpers.WindowsAzure.Storage.Table.Attributes
{
public class RelatedTableAttribute : Attribute
{
/// <summary>
/// The partitionkey of the related table, if this is the name of a property on the model the property value will be used.
/// </summary>
public string PartitionKey { get; set; }

/// <summary>
/// The rowkey of the related table, if this is a property on the model, the property value will be loaded, if it is empty this will default to the name of the type.
/// </summary>
public string RowKey { get; set; }

/// <summary>
///
/// </summary>
/// <param name="partitionKey">The partitionkey of the related table, if this is the name of a property on the model the property value will be used.</param>
public RelatedTableAttribute(string partitionKey)
{
PartitionKey = partitionKey;
}

/// <summary>
///
/// </summary>
/// <param name="partitionKey">The partitionkey of the related table, if this is the name of a property on the model the property value will be used.</param>
/// <param name="rowKey">The rowkey of the related table, if this is a property on the model, the property value will be loaded, if it is empty this will default to the name of the type.</param>
public RelatedTableAttribute(string partitionKey, string rowKey)
{
PartitionKey = partitionKey;
RowKey = rowKey;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
<PackageReference Include="Handlebars.Net" Version="1.9.0" />
</ItemGroup>
<ItemGroup>
<Folder Include="Attributes\" />
<Folder Include="Extensions\" />
<Folder Include="Delegates\" />
</ItemGroup>
</Project>
15 changes: 15 additions & 0 deletions CoreHelpers.WindowsAzure.Storage.Table/DynamicLazy.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace CoreHelpers.WindowsAzure.Storage.Table
{
internal class DynamicLazy<T> : Lazy<T>
{
public DynamicLazy(Func<object> factory) : base(() => (T)factory())
{

}

}
}
11 changes: 9 additions & 2 deletions CoreHelpers.WindowsAzure.Storage.Table/DynamicTableEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,16 @@ internal static bool ShouldSkipProperty(PropertyInfo property, OperationContext
{
// Logger.LogInformational(operationContext, SR.TraceIgnoreAttribute, property.Name);
return true;
}
}

// properties with [RelatedTable]
if (property.GetCustomAttribute(typeof(RelatedTableAttribute)) != null)
{
// Logger.LogInformational(operationContext, SR.TraceIgnoreAttribute, property.Name);
return true;
}

return false;
return false;
}

private static IDictionary<string, EntityProperty> ReflectionWrite(object entity, OperationContext operationContext)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,19 @@ public static void SetOrAddValue(this PropertyInfo propertyInfo, object obj, obj
} else
propertyInfo.SetValue(obj, val, null);
}
}

public static bool IsGenericOfType(this Type toCheck, Type generic)
{
while (toCheck != null && toCheck != typeof(object))
{
var cur = toCheck.GetTypeInfo().IsGenericType ? toCheck.GetGenericTypeDefinition() : toCheck;
if (generic == cur)
{
return true;
}
toCheck = toCheck.GetTypeInfo().BaseType;
}
return false;
}
}
}
26 changes: 26 additions & 0 deletions CoreHelpers.WindowsAzure.Storage.Table/Extensions/TableQueryEx.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Microsoft.WindowsAzure.Storage.Table;
using System;
using System.Collections.Generic;
using System.Text;

namespace CoreHelpers.WindowsAzure.Storage.Table.Extensions
{
public class TableQueryEx
{
public static string CheckAndCombineFilters(string filterA, string operatorString, string filterB)
{
if (string.IsNullOrWhiteSpace(filterA))
return filterB;

return TableQuery.CombineFilters(filterA, operatorString, filterB);
}

public static string CombineFilters(IEnumerable<string> filters, string operatorString)
{
return string.Join(
" " + operatorString + " ",
filters
);
}
}
}
17 changes: 17 additions & 0 deletions CoreHelpers.WindowsAzure.Storage.Table/RelatedTableItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;

namespace CoreHelpers.WindowsAzure.Storage.Table
{
internal class RelatedTableItem<T> where T : new()
{
public string RowKey { get; set; }
public string PartitionKey { get; set; }

public DynamicTableEntity<T> Model { get; set; }

public PropertyInfo Property { get; set; }
}
}
Loading