Permalink
Browse files

debugged hard delete

  • Loading branch information...
JeffHughes committed Jan 11, 2016
1 parent 7973738 commit 4a82b9df7aaecf70a159f6245aa473c5dafdcb95
@@ -18,8 +18,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{B645DC20-2
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tools", "tools", "{FB93FB18-8CD0-4D5B-9105-8C617B42A03A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AzureTableFramework.Core.Tests", "test\AzureTableFramework.Core.Tests\AzureTableFramework.Core.Tests.csproj", "{BFB2EC5F-F266-4AF5-8558-1445C26AA0CC}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{4CA2E1FC-CB44-40CC-9AC2-8EEBADB71DDE}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Samples.Empty", "samples\AzureTableFramework.WebApp\Samples.Empty.xproj", "{1AD5127B-CB60-48CB-AD61-3D59DD68F38E}"
@@ -72,6 +70,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "AzureSearch", "AzureSearch"
docs\azuresearch\index.rst = docs\azuresearch\index.rst
EndProjectSection
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "CoreTests", "test\CoreTests\CoreTests.xproj", "{650A5A85-5956-491E-9312-5E25A27D1108}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -100,22 +100,6 @@ Global
{95640DD8-CF12-4881-9D61-6146EE5ABDEB}.Release|x64.Build.0 = Release|Any CPU
{95640DD8-CF12-4881-9D61-6146EE5ABDEB}.Release|x86.ActiveCfg = Release|Any CPU
{95640DD8-CF12-4881-9D61-6146EE5ABDEB}.Release|x86.Build.0 = Release|Any CPU
{BFB2EC5F-F266-4AF5-8558-1445C26AA0CC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BFB2EC5F-F266-4AF5-8558-1445C26AA0CC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BFB2EC5F-F266-4AF5-8558-1445C26AA0CC}.Debug|ARM.ActiveCfg = Debug|Any CPU
{BFB2EC5F-F266-4AF5-8558-1445C26AA0CC}.Debug|ARM.Build.0 = Debug|Any CPU
{BFB2EC5F-F266-4AF5-8558-1445C26AA0CC}.Debug|x64.ActiveCfg = Debug|Any CPU
{BFB2EC5F-F266-4AF5-8558-1445C26AA0CC}.Debug|x64.Build.0 = Debug|Any CPU
{BFB2EC5F-F266-4AF5-8558-1445C26AA0CC}.Debug|x86.ActiveCfg = Debug|Any CPU
{BFB2EC5F-F266-4AF5-8558-1445C26AA0CC}.Debug|x86.Build.0 = Debug|Any CPU
{BFB2EC5F-F266-4AF5-8558-1445C26AA0CC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BFB2EC5F-F266-4AF5-8558-1445C26AA0CC}.Release|Any CPU.Build.0 = Release|Any CPU
{BFB2EC5F-F266-4AF5-8558-1445C26AA0CC}.Release|ARM.ActiveCfg = Release|Any CPU
{BFB2EC5F-F266-4AF5-8558-1445C26AA0CC}.Release|ARM.Build.0 = Release|Any CPU
{BFB2EC5F-F266-4AF5-8558-1445C26AA0CC}.Release|x64.ActiveCfg = Release|Any CPU
{BFB2EC5F-F266-4AF5-8558-1445C26AA0CC}.Release|x64.Build.0 = Release|Any CPU
{BFB2EC5F-F266-4AF5-8558-1445C26AA0CC}.Release|x86.ActiveCfg = Release|Any CPU
{BFB2EC5F-F266-4AF5-8558-1445C26AA0CC}.Release|x86.Build.0 = Release|Any CPU
{1AD5127B-CB60-48CB-AD61-3D59DD68F38E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1AD5127B-CB60-48CB-AD61-3D59DD68F38E}.Debug|ARM.ActiveCfg = Debug|Any CPU
{1AD5127B-CB60-48CB-AD61-3D59DD68F38E}.Debug|ARM.Build.0 = Debug|Any CPU
@@ -178,13 +162,28 @@ Global
{2AB6BBE6-524A-455B-9126-4226C70B7BE3}.Release|x64.Build.0 = Release|Any CPU
{2AB6BBE6-524A-455B-9126-4226C70B7BE3}.Release|x86.ActiveCfg = Release|Any CPU
{2AB6BBE6-524A-455B-9126-4226C70B7BE3}.Release|x86.Build.0 = Release|Any CPU
{650A5A85-5956-491E-9312-5E25A27D1108}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{650A5A85-5956-491E-9312-5E25A27D1108}.Debug|Any CPU.Build.0 = Debug|Any CPU
{650A5A85-5956-491E-9312-5E25A27D1108}.Debug|ARM.ActiveCfg = Debug|Any CPU
{650A5A85-5956-491E-9312-5E25A27D1108}.Debug|ARM.Build.0 = Debug|Any CPU
{650A5A85-5956-491E-9312-5E25A27D1108}.Debug|x64.ActiveCfg = Debug|Any CPU
{650A5A85-5956-491E-9312-5E25A27D1108}.Debug|x64.Build.0 = Debug|Any CPU
{650A5A85-5956-491E-9312-5E25A27D1108}.Debug|x86.ActiveCfg = Debug|Any CPU
{650A5A85-5956-491E-9312-5E25A27D1108}.Debug|x86.Build.0 = Debug|Any CPU
{650A5A85-5956-491E-9312-5E25A27D1108}.Release|Any CPU.ActiveCfg = Release|Any CPU
{650A5A85-5956-491E-9312-5E25A27D1108}.Release|Any CPU.Build.0 = Release|Any CPU
{650A5A85-5956-491E-9312-5E25A27D1108}.Release|ARM.ActiveCfg = Release|Any CPU
{650A5A85-5956-491E-9312-5E25A27D1108}.Release|ARM.Build.0 = Release|Any CPU
{650A5A85-5956-491E-9312-5E25A27D1108}.Release|x64.ActiveCfg = Release|Any CPU
{650A5A85-5956-491E-9312-5E25A27D1108}.Release|x64.Build.0 = Release|Any CPU
{650A5A85-5956-491E-9312-5E25A27D1108}.Release|x86.ActiveCfg = Release|Any CPU
{650A5A85-5956-491E-9312-5E25A27D1108}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{95640DD8-CF12-4881-9D61-6146EE5ABDEB} = {4C45D2AB-0A22-4730-9C2B-D74946C8F4A7}
{BFB2EC5F-F266-4AF5-8558-1445C26AA0CC} = {B645DC20-23C3-4FB5-A9C7-60F6606CC2EF}
{1AD5127B-CB60-48CB-AD61-3D59DD68F38E} = {4CA2E1FC-CB44-40CC-9AC2-8EEBADB71DDE}
{2C740B4B-3C26-4A68-8453-1E70905DC0E8} = {4CA2E1FC-CB44-40CC-9AC2-8EEBADB71DDE}
{A5EB9091-C7F8-41FA-8E91-988FEF2CFC71} = {4CA2E1FC-CB44-40CC-9AC2-8EEBADB71DDE}
@@ -196,5 +195,6 @@ Global
{F9A67AC5-A532-487E-8DB7-CA03359706C7} = {5CFA3354-F374-4E75-84A0-034B3FE43AD0}
{08068159-DC42-4091-81B1-B20EE2940BF7} = {5CFA3354-F374-4E75-84A0-034B3FE43AD0}
{EB6CA5DF-6E41-4FB4-A6FD-EF7AACE96704} = {5CFA3354-F374-4E75-84A0-034B3FE43AD0}
{650A5A85-5956-491E-9312-5E25A27D1108} = {B645DC20-23C3-4FB5-A9C7-60F6606CC2EF}
EndGlobalSection
EndGlobal
@@ -1,5 +1,5 @@
{
"projects": [ "src", "test" ],
{
"projects": [ "src", "test", "samples" ],
"sdk": {
"version": "1.0.0-rc1-update1"
}
@@ -1,5 +1,6 @@
using AzureTableFramework.Core;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Samples.Common
{
@@ -18,7 +18,7 @@ public partial class AzureTableDictionary<T>
public AzureTableDictionary(AzureTablesContext context)
{
_AzureTablesContext = context;
Debug.WriteLine("instantiated w " + context.PrimaryStorageAccountKey);
//Debug.WriteLine("AzureTableDictionary instantiated for " + typeof(T).Name);
}

public Dictionary<string, T> Items { get; set; } = new Dictionary<string, T>();
@@ -51,6 +51,8 @@ public T Add(T item)
if (string.IsNullOrEmpty(key))
throw new Exception("There is a problem w the RowKey for " + item.GetType().Name);

if (Items.ContainsKey(key)) Items.Remove(key);

Items.Add(key, item);
return item;
}
@@ -73,42 +75,13 @@ public T New(params object[] args)
return o;
}

/// <summary>
/// Items that will be inserted or updated on "SaveChanges"
/// </summary>
/// <returns></returns>
public List<T> Upserts()
{
var list = new List<T>();

foreach (var item in Items.Values)
{
var deleted = (bool)Utils.GetVal(item, "_DeleteWithBatch");
if (!deleted) list.Add(item);
}
return list;
}

/// <summary>
/// Items that will be deleted on "SaveChanges"
/// </summary>
/// <returns></returns>
public List<T> Deletes()
{
var list = new List<T>();
foreach (var item in Items.Values)
if ((bool)Utils.GetVal(item, "_DeleteWithBatch"))
list.Add(item);
return list;
}

/// <summary>
/// Returns the values of Items as a list
/// </summary>
/// <returns></returns>
public List<T> ToList()
{
return (List<T>)Convert.ChangeType(Items.Values, typeof(List<>).MakeGenericType(new[] { typeof(T) }));
return (List<T>)Convert.ChangeType(Items.Values.ToList(), typeof(List<>).MakeGenericType(new[] { typeof(T) }));
}

/// <summary>
@@ -11,35 +11,43 @@

namespace AzureTableFramework.Core
{
public partial class AzureTableDictionary<T>
public partial class AzureTableDictionary<T> : IDisposable
{
public async Task<T> GetByIDAsync(string ID)
{
var q = Utils.FilterString("RowKey", QueryComparisons.Equal, ID);
var tq = new TableQuery { FilterString = q }.Take(1);
var data = await QueryAsync(tq, null);
return Add(data.Results.FirstOrDefault());

if (data.Results.Any())
return Add(data.Results.FirstOrDefault());

return default(T);
}

public async Task<List<T>> GetLastUpdated(DateTime updatedAfterUTC)
{
var q = Utils.FilterString("LastUpdated", QueryComparisons.LessThanOrEqual, updatedAfterUTC);
var tq = new TableQuery { FilterString = q };
var data = await QueryAsync(tq, null);
return Add(data.Results);
}

public async Task<AzureTableQueryResults<T>> ComplexIndexedQuery()
{
//((LastUpdated ge datetime'2016-01-09T20:00:00.0000000Z') and (LastUpdated ge datetime'2016-01-09T20:00:00.0000000Z')) and (LastUpdated ge datetime'2016-01-09T20:00:00.0000000Z')

//var expressions = Regex.Split(tableQuery.FilterString, " and ");
if (data.Results.Any())
return Add(data.Results);

//foreach (var filter in expressions)
//{
return null;
}

//public async Task<AzureTableQueryResults<T>> ComplexIndexedQuery()
//{
// //((LastUpdated ge datetime'2016-01-09T20:00:00.0000000Z') and (LastUpdated ge datetime'2016-01-09T20:00:00.0000000Z')) and (LastUpdated ge datetime'2016-01-09T20:00:00.0000000Z')

// //var expressions = Regex.Split(tableQuery.FilterString, " and ");

// //foreach (var filter in expressions)
// //{
// return null;
//}

public async Task<AzureTableQueryResults<T>> QueryAsync(TableQuery tableQuery, TableContinuationToken token)
{
var table = await Utils.GetCloudTableAsync(typeof(T).Name, _AzureTablesContext.PrimaryStorageAccount(), false);
@@ -55,27 +63,27 @@ public async Task<AzureTableQueryResults<T>> QueryAsync(TableQuery tableQuery, T
table = await Utils.GetCloudTableAsync(Utils.GetIndexTableName(typeof(T).Name, indexedProp.Name), _AzureTablesContext.IndexStorageAccount(), false);
tableQuery.FilterString = tableQuery.FilterString.Replace(indexedProp.Name, "PartitionKey");

if (indexedProp.Name.Equals("LastUpdated")) UpdateFilterForLastUpdated(tableQuery);
if (indexedProp.Name.Equals("LastUpdated")) UpdateFilterForLastUpdatedIndexCall(tableQuery);
}

if (!startingFilterString.Equals(tableQuery.FilterString))
Debug.WriteLine("Executing FilterString: " + tableQuery.FilterString);
}
else
{
//return ComplexIndexedQuery();
}
//else
//{
//return ComplexIndexedQuery();
//}

var tqs = await table.ExecuteQuerySegmentedAsync(tableQuery, token);

return new AzureTableQueryResults<T>()
{
DynamicTableEntities = (List<DynamicTableEntity>)tqs.Results,
Results = Utils.DynamicResultsToTypedList<T, DynamicTableEntity>(tqs.Results.ToList()),
token = tqs.ContinuationToken
};
}

private static void UpdateFilterForLastUpdated(TableQuery tableQuery)
private static void UpdateFilterForLastUpdatedIndexCall(TableQuery tableQuery)
{
if (tableQuery.FilterString.Contains("datetime'"))
{
@@ -84,10 +92,9 @@ private static void UpdateFilterForLastUpdated(TableQuery tableQuery)
try
{
var part = filterparts.Last();
var dateTime = Convert.ToDateTime(part).ToUniversalTime();
var dateTime = new DateTime(Convert.ToDateTime(part).Ticks, DateTimeKind.Utc);
var val = Utils.TicksFromMax(dateTime);

//Debug.WriteLine("Query part: " + part + " = " + val + " = " + Utils.UTCDateTimeFromTicksFromMax(val));
tableQuery.FilterString = tableQuery.FilterString.Replace(part, val).Replace("datetime", "");
}
catch (Exception ex)
@@ -143,5 +150,9 @@ public async Task<AzureTableQueryResults<T>> QueryAllAsync(string filterString,
token = segment.token
};
}

public void Dispose()
{
}
}
}
@@ -10,32 +10,5 @@ public class AzureTableQueryResults<T>
public List<T> Results { get; set; }

public TableContinuationToken token { get; set; }

public List<DynamicTableEntity> DynamicTableEntities
{
set
{
Mapper.CreateMap<DynamicTableEntity, T>();

var PartitionKeyPropertyName = Utils.GetPartitionKeyPropertyName(typeof(T));
var RowKeyPropertyName = Utils.GetRowKeyPropertyName(typeof(T));

Results = new List<T>();
foreach (var item in value)
{
var obj = Mapper.Map<DynamicTableEntity, T>(item);

if (!(Utils.GetVal(obj, RowKeyPropertyName) == null))
Utils.SetVal(obj, RowKeyPropertyName, Utils.GetVal(obj, "RowKey"));

if (!(Utils.GetVal(obj, PartitionKeyPropertyName) == null))
Utils.SetVal(obj, PartitionKeyPropertyName, Utils.GetVal(obj, "PartitionKey"));

//TODO: Decryption

Results.Add(obj);
}
}
}
}
}
Oops, something went wrong.

0 comments on commit 4a82b9d

Please sign in to comment.