private void Sync(object _)
        {
            try
            {
                var tenant = CoreContext.TenantManager.GetTenants().OrderByDescending(t => t.Version).FirstOrDefault();
                if (tenant != null)
                {
                    using (var wcfClient = new TariffSyncClient())
                    {
                        var quotaService = new DbQuotaService(ConfigurationManager.ConnectionStrings[config.ConnectionStringName]);

                        var oldtariffs = quotaService.GetTenantQuotas().ToDictionary(t => t.Id);
                        // save new
                        foreach (var tariff in wcfClient.GetTariffs(tenant.Version, CoreContext.Configuration.GetKey(tenant.TenantId)))
                        {
                            quotaService.SaveTenantQuota(tariff);
                            oldtariffs.Remove(tariff.Id);
                        }

                        // remove old
                        foreach (var tariff in oldtariffs.Values)
                        {
                            tariff.Visible = false;
                            quotaService.SaveTenantQuota(tariff);
                        }
                    }
                }
            }
            catch (Exception error)
            {
                log.Error(error);
            }
        }
Example #2
0
 // server part of service
 public IEnumerable <TenantQuota> GetTariffs(int version, string key)
 {
     lock (quotaServices)
     {
         if (!quotaServices.ContainsKey(version))
         {
             var cs = Configuration.GetConnectionStrings(config.ConnectionStringName + version) ??
                      Configuration.GetConnectionStrings(config.ConnectionStringName);
             quotaServices[version] = DbQuotaService.GetTenantQuotas();
         }
         return(quotaServices[version]);
     }
 }