Temporary repo to track my changes on LTS functions app porting
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
2.6 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CDP
{
public class GroupsDocument
{
public string id
{
get
{
return GenPartitionKey(AppKey, UserId, Index);
}
}
public string AppKey { get; set; }
public string UserId { get; set; }
public int Index { get; set; }
public List<GroupsRecord> Records { get; set; }
public GroupsDocument()
{
Index = 0;
Records = new List<GroupsRecord>();
}
public static string GenRootPartitionKey(string id, DateTime dt)
{
return string.Format($"{id}-{dt.Year}-{dt.DayOfYear}");
}
public static string GenPartitionKey(string appKey, string userId, int index = 0)
{
return string.Format($"{appKey}-{userId}-{index}");
}
}
public class GroupsRecord
{
public string id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public List<ContactRecord> Contacts { get; set; }
public DateTime EventTime { get; set; }
public GroupsRecord()
{
EventTime = DateTime.UtcNow;
}
public GroupsRecord(string name, string description, List<ContactRecord> contacts)
{
id = Guid.NewGuid().ToString();
Name = name;
Description = description;
Contacts = contacts != null ? contacts : new List<ContactRecord>();
EventTime = DateTime.UtcNow;
}
public int CalculateRecordSize()
{
int size = 0;
size += 8800; // sizeof(DateTime); 175*50 = 8750 bytes to support at max 50 contacts in a group
size += Encoding.UTF8.GetByteCount(Name) == 0 ? 20 : Encoding.UTF8.GetByteCount(Name); // UserId
size += sizeof(int);
return size;
}
}
public class MetadataDocumentGroups
{
public string id { get; set; }
public List<string> PartitionKeys { get; set; }
public MetadataDocumentGroups()
{
PartitionKeys = new List<string>();
id = id + "-meta";
}
public string GetLatestKey(string appKey, string userId)
{
PartitionKeys.Sort();
if (PartitionKeys.Count == 0)
return GroupsDocument.GenPartitionKey(appKey, userId);
return PartitionKeys.Last();
}
}
}