96 lines
3.0 KiB
C#
96 lines
3.0 KiB
C#
using Microsoft.Azure.CosmosDB.Table;
|
|
using Microsoft.Azure.Storage;
|
|
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Configuration;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using taloyhtio.idp.parser.common.model;
|
|
using unesMdb.model;
|
|
|
|
namespace unesMdb
|
|
{
|
|
class Program
|
|
{
|
|
private static CloudTableClient tableClient;
|
|
private static List<UserData> users;
|
|
private static List<FlatData> flats;
|
|
private static CondoMapping condo;
|
|
|
|
private const string CONDONAME = "itapuisto7";
|
|
|
|
static void Main(string[] args)
|
|
{
|
|
DbUtils.ConnectionString = $"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={args[0]}\\Kirjos.mdb";
|
|
users = DbUtils.CollectUsers();
|
|
flats = DbUtils.CollectFlats(users);
|
|
InitClient();
|
|
condo = GetCondo(CONDONAME)[0];
|
|
if (condo == null)
|
|
{
|
|
return;
|
|
}
|
|
SaveFlats();
|
|
}
|
|
|
|
private static void InitClient()
|
|
{
|
|
var storageAccount = CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings[Constants.KEY_AZURE_STORAGE].ConnectionString);
|
|
tableClient = storageAccount.CreateCloudTableClient(
|
|
new TableConnectionPolicy()
|
|
{
|
|
UseDirectMode = false
|
|
});
|
|
}
|
|
|
|
private static List<CondoMapping> GetCondo(string condoName)
|
|
{
|
|
var table = tableClient.GetTableReference("mdbCondoMappings");
|
|
table.CreateIfNotExists();
|
|
|
|
var allCondos = table.CreateQuery<CondoMapping>().ToList();
|
|
|
|
if (condoName != null)
|
|
{
|
|
return allCondos.Where(x => condoName.Contains(x.PMSCondoName)).ToList();
|
|
}
|
|
return allCondos;
|
|
}
|
|
|
|
static void SaveFlats()
|
|
{
|
|
var table = tableClient.GetTableReference("mdbFlats");
|
|
table.CreateIfNotExists();
|
|
|
|
flats.ForEach(f =>
|
|
{
|
|
var id = Guid.NewGuid();
|
|
var flat = new Flat
|
|
{
|
|
PartitionKey = condo.TaloyhtioPMCId.ToString(),
|
|
Id = id,
|
|
RowKey = id.ToString(),
|
|
CondoPMS = condo.PMSCondoName,
|
|
FlatTitle = f.Title,
|
|
PMCTaloyhtioId = condo.TaloyhtioPMCId,
|
|
FlatUsers = JsonConvert.SerializeObject(
|
|
f.Users.ConvertAll(p =>
|
|
{
|
|
return new FlatUser
|
|
{
|
|
DisplayName = p.Name,
|
|
PIN = p.Pin
|
|
};
|
|
})
|
|
)
|
|
};
|
|
|
|
var result = table.Execute(TableOperation.InsertOrReplace(flat));
|
|
Console.WriteLine(result.HttpStatusCode);
|
|
});
|
|
}
|
|
}
|
|
}
|