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.

99 lines
2.9 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CDP
{
public class ContactsDocument
{
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<ContactRecord> Records { get; set; }
public ContactsDocument()
{
Index = 0;
Records = new List<ContactRecord>();
}
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 ContactRecord
{
public string Name { get; set; }
public string Email { get; set; }
public string Phone { get; set; }
public string Address { get; set; }
public string Company { get; set; }
public DateTime EventTime { get; set; }
public ContactRecord()
{
EventTime = DateTime.UtcNow;
}
public ContactRecord(string name, string email, string phone, string address, string company)
{
Name = name;
Email = email;
Phone = phone;
Address = address;
Company = company;
EventTime = DateTime.UtcNow;
}
public int CalculateRecordSize()
{
int size = 0;
size += 16; // sizeof(DateTime); // EventTime
size += Encoding.UTF8.GetByteCount(Name) == 0 ? 20 : Encoding.UTF8.GetByteCount(Name); // UserId
size += Encoding.UTF8.GetByteCount(Email) == 0 ? 50 : Encoding.UTF8.GetByteCount(Email);
size += Encoding.UTF8.GetByteCount(Phone) == 0 ? 15 : Encoding.UTF8.GetByteCount(Phone);
size += Encoding.UTF8.GetByteCount(Address) == 0 ? 70 : Encoding.UTF8.GetByteCount(Address);
size += Encoding.UTF8.GetByteCount(Company) == 0 ? 20 : Encoding.UTF8.GetByteCount(Company);
size += sizeof(int);
return size;
}
}
public class MetadataDocumentContact
{
public string id { get; set; }
public List<string> PartitionKeys { get; set; }
public MetadataDocumentContact()
{
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();
}
}
}