using Microsoft.Azure.CosmosDB.Table; using Microsoft.Azure.Storage; using System; using System.Collections.Generic; using System.Configuration; using System.Linq; using taloyhtio.idp.parser.common.model; using unesMdb.model; namespace unesMdb { class Program { private static CloudTableClient tableClient; private static List users; private static List flats; private static Dictionary flatsAzure; 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); DbUtils.CollectLinks(users); DbUtils.CollectFees(users); InitClient(); condo = GetCondo(CONDONAME)[0]; if (condo == null) { return; } flatsAzure = GetFlats(condo.TaloyhtioPMCId, CONDONAME).ToDictionary(x => x.FlatTitle, x => x.Id); SaveFees(); } 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 GetCondo(string condoName) { var table = tableClient.GetTableReference("mdbCondoMappings"); table.CreateIfNotExists(); var allCondos = table.CreateQuery().ToList(); if (condoName != null) { return allCondos.Where(x => condoName.Contains(x.PMSCondoName)).ToList(); } return allCondos; } private static List GetFlats(Guid taloyhtioPMCId, string pmsCondoName) { if (Guid.Empty.Equals(taloyhtioPMCId) || string.IsNullOrEmpty(pmsCondoName)) { return null; } var table = tableClient.GetTableReference("mdbFlats"); table.CreateIfNotExists(); var query = table.CreateQuery() .Where(d => d.PMCTaloyhtioId == taloyhtioPMCId && d.CondoPMS == pmsCondoName) .ToArray() .OrderBy(o => o.FlatTitle); return query.ToList(); } private static void SaveFees() { var table = tableClient.GetTableReference("mdbMaintenanceFees"); table.CreateIfNotExists(); flats.Where(flat => flatsAzure.ContainsKey(flat.Title)).ToList().ForEach(flat => { flat.Users.ForEach(user => { user.Fees.ForEach(feeRec => { var fee = new MaintenanceFee(Guid.NewGuid()) { Payer = user.Name, FlatTitle = flat.Title, FlatId = flatsAzure[flat.Title], PaymentType = feeRec.Name, PMSCondoName = condo.PMSCondoName, PMCTaloyhtioId = condo.TaloyhtioPMCId, PeriodOfTime = "201911", Fee = Convert.ToDouble(feeRec.Amount), PartitionKey = user.Name, }; var result = table.Execute(TableOperation.InsertOrReplace(fee)); Console.WriteLine(result.HttpStatusCode); }); }); }); } } }