Skip to content

Commit

Permalink
Merge branch 'develop' into feature/redesign-tiles
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitry-kulak committed Jan 24, 2022
2 parents 8b69362 + 339614f commit ec47211
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 45 deletions.
2 changes: 1 addition & 1 deletion common/ASC.Common/Caching/KafkaCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ void action()

private string GetChannelName(CacheNotifyAction cacheNotifyAction)
{
return $"asc:channel:{cacheNotifyAction}:{typeof(T).FullName}".ToLower();
return $"ascchannel{cacheNotifyAction}{typeof(T).FullName}".ToLower();
}

public void Unsubscribe(CacheNotifyAction action)
Expand Down
12 changes: 10 additions & 2 deletions common/services/ASC.Data.Backup/Program.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
var builder = WebApplication.CreateBuilder(args);
using Microsoft.Extensions.Hosting.WindowsServices;

var options = new WebApplicationOptions
{
Args = args,
ContentRootPath = WindowsServiceHelpers.IsWindowsService() ? AppContext.BaseDirectory : default
};

var builder = WebApplication.CreateBuilder(options);

builder.Host.UseSystemd();
builder.Host.UseWindowsService();
builder.Host.UseSystemd();
builder.Host.UseServiceProviderFactory(new AutofacServiceProviderFactory());

builder.WebHost.ConfigureKestrel((hostingContext, serverOptions) =>
Expand Down
93 changes: 51 additions & 42 deletions products/ASC.CRM/Server/Utils/CurrencyProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,39 +46,48 @@ namespace ASC.Web.CRM.Classes
[Scope]
public class CurrencyProvider
{
private readonly ILog _log;
private readonly ILog _logger;
private readonly object _syncRoot = new object();
private readonly Dictionary<String, CurrencyInfo> _currencies;
private Dictionary<string, decimal> _exchangeRates;
private readonly IConfiguration _configuration;
private readonly SettingsManager _settingsManager;
private Dictionary<string, decimal> _exchangeRates;
private DateTime _publisherDate;
private const String _formatDate = "yyyy-MM-ddTHH:mm:ss.fffffffK";
private Dictionary<String, CurrencyInfo> _currencies;
private readonly DaoFactory _daoFactory;

public CurrencyProvider(IOptionsMonitor<ILog> logger,
IConfiguration configuration,
SettingsManager settingsManager,
DaoFactory daoFactory)
IConfiguration configuration,
DaoFactory daoFactory,
SettingsManager settingsManager)
{
_log = logger.Get("ASC");
Configuration = configuration;
SettingsManager = settingsManager;

var daocur = daoFactory.GetCurrencyInfoDao();
var currencies = daocur.GetAll();

if (currencies == null || currencies.Count == 0)
{
currencies = new List<CurrencyInfo>
{
new CurrencyInfo("Currency_UnitedStatesDollar", "USD", "$", "US", true, true)
};
}

_currencies = currencies.ToDictionary(c => c.Abbreviation);

}

public IConfiguration Configuration { get; }
public SettingsManager SettingsManager { get; }
_logger = logger.Get("ASC");
_daoFactory = daoFactory;
_configuration = configuration;
_settingsManager = settingsManager;
}

public Dictionary<String, CurrencyInfo> Currencies
{
get
{
if (_currencies != null) return _currencies;

var currencies = _daoFactory.GetCurrencyInfoDao().GetAll();

if (currencies == null || currencies.Count == 0)
{
currencies = new List<CurrencyInfo>
{
new CurrencyInfo("Currency_UnitedStatesDollar", "USD", "$", "US", true, true)
};
}

_currencies = currencies.ToDictionary(c => c.Abbreviation);

return _currencies;
}
}

public DateTime GetPublisherDate
{
Expand All @@ -91,31 +100,31 @@ public DateTime GetPublisherDate

public CurrencyInfo Get(string currencyAbbreviation)
{
if (!_currencies.ContainsKey(currencyAbbreviation))
if (!Currencies.ContainsKey(currencyAbbreviation))
return null;

return _currencies[currencyAbbreviation];
return Currencies[currencyAbbreviation];
}

public List<CurrencyInfo> GetAll()
{
return _currencies.Values.OrderBy(v => v.Abbreviation).ToList();
return Currencies.Values.OrderBy(v => v.Abbreviation).ToList();
}

public List<CurrencyInfo> GetBasic()
{
return _currencies.Values.Where(c => c.IsBasic).OrderBy(v => v.Abbreviation).ToList();
return Currencies.Values.Where(c => c.IsBasic).OrderBy(v => v.Abbreviation).ToList();
}

public List<CurrencyInfo> GetOther()
{
return _currencies.Values.Where(c => !c.IsBasic).OrderBy(v => v.Abbreviation).ToList();
return Currencies.Values.Where(c => !c.IsBasic).OrderBy(v => v.Abbreviation).ToList();
}

public Dictionary<CurrencyInfo, Decimal> MoneyConvert(CurrencyInfo baseCurrency)
{
if (baseCurrency == null) throw new ArgumentNullException("baseCurrency");
if (!_currencies.ContainsKey(baseCurrency.Abbreviation)) throw new ArgumentOutOfRangeException("baseCurrency", "Not found.");
if (!Currencies.ContainsKey(baseCurrency.Abbreviation)) throw new ArgumentOutOfRangeException("baseCurrency", "Not found.");

var result = new Dictionary<CurrencyInfo, Decimal>();
var rates = GetExchangeRates();
Expand All @@ -142,12 +151,12 @@ public Dictionary<CurrencyInfo, Decimal> MoneyConvert(CurrencyInfo baseCurrency)

public bool IsConvertable(String abbreviation)
{
var findedItem = _currencies.Keys.ToList().Find(item => String.Compare(abbreviation, item) == 0);
var findedItem = Currencies.Keys.ToList().Find(item => String.Compare(abbreviation, item) == 0);

if (findedItem == null)
throw new ArgumentException(abbreviation);

return _currencies[findedItem].IsConvertable;
return Currencies[findedItem].IsConvertable;
}

public Decimal MoneyConvert(decimal amount, string from, string to)
Expand All @@ -166,7 +175,7 @@ public Decimal MoneyConvert(decimal amount, string from, string to)
public decimal MoneyConvertToDefaultCurrency(decimal amount, string from)
{

var crmSettings = SettingsManager.Load<CrmSettings>();
var crmSettings = _settingsManager.Load<CrmSettings>();
var defaultCurrency = Get(crmSettings.DefaultCurrency);

return MoneyConvert(amount, from, defaultCurrency.Abbreviation);
Expand Down Expand Up @@ -202,10 +211,10 @@ private Dictionary<String, Decimal> GetExchangeRates()



var updateEnable = Configuration["crm:update:currency:info:enable"] != "false";
var updateEnable = _configuration["crm:update:currency:info:enable"] != "false";
var ratesUpdatedFlag = false;

foreach (var ci in _currencies.Values.Where(c => c.IsConvertable))
foreach (var ci in Currencies.Values.Where(c => c.IsConvertable))
{
var filepath = Path.Combine(tmppath, ci.Abbreviation + ".html");

Expand Down Expand Up @@ -242,7 +251,7 @@ private Dictionary<String, Decimal> GetExchangeRates()
}
catch (Exception error)
{
_log.Error(error);
_logger.Error(error);
_publisherDate = DateTime.UtcNow;
}
}
Expand Down Expand Up @@ -297,7 +306,7 @@ private void TryToReadPublisherDate(string tmppath)
}
catch (Exception err)
{
_log.Error(err);
_logger.Error(err);
}
}
}
Expand All @@ -311,7 +320,7 @@ private void WritePublisherDate(string tmppath)
}
catch (Exception err)
{
_log.Error(err);
_logger.Error(err);
}
}

Expand Down Expand Up @@ -350,7 +359,7 @@ private void DownloadCurrencyPage(string currency, string filepath)
}
catch (Exception error)
{
_log.Error(error);
_logger.Error(error);
}
}

Expand Down

0 comments on commit ec47211

Please sign in to comment.