2024-11-13 23:42:28 +03:00
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
using Microsoft.Win32;
|
2023-03-28 07:25:10 +03:00
|
|
|
|
using System.IO;
|
|
|
|
|
|
2023-04-01 15:24:04 +03:00
|
|
|
|
namespace RhSolutions.Services;
|
|
|
|
|
|
2023-11-12 16:31:26 +03:00
|
|
|
|
public class AddInConfiguration : IAddInConfiguration
|
2023-03-28 07:25:10 +03:00
|
|
|
|
{
|
2024-11-13 23:42:28 +03:00
|
|
|
|
private IConfiguration _configuration;
|
|
|
|
|
private RegistryKey _rootKey;
|
|
|
|
|
private string _priceListPath;
|
|
|
|
|
private Dictionary<string, string> settingsValues;
|
|
|
|
|
|
|
|
|
|
public string this[string key]
|
|
|
|
|
{
|
|
|
|
|
get => _configuration[key];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public event IAddInConfiguration.SettingsHandler OnSettingsChange;
|
|
|
|
|
|
|
|
|
|
public AddInConfiguration()
|
|
|
|
|
{
|
|
|
|
|
// EmbeddedFileProvider embeddedProvider = new (typeof(RhSolutionsAddIn).Assembly);
|
|
|
|
|
// using Stream stream = embeddedProvider.GetFileInfo("appsettings.json").CreateReadStream();
|
|
|
|
|
|
|
|
|
|
_configuration = new ConfigurationBuilder()
|
|
|
|
|
.AddUserSecrets<RhSolutionsAddIn>()
|
|
|
|
|
// .AddJsonStream(stream)
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
_rootKey = Registry.CurrentUser.CreateSubKey(@"SOFTWARE\RhSolutions\RhSolutions-AddIn");
|
|
|
|
|
_priceListPath = (string)_rootKey.GetValue("PriceListPath");
|
|
|
|
|
settingsValues = new()
|
|
|
|
|
{
|
|
|
|
|
["Amount"] = "Кол-во",
|
|
|
|
|
["OldSku"] = "Прежний материал",
|
|
|
|
|
["Sku"] = "Актуальный материал",
|
|
|
|
|
["ProductLine"] = "Программа",
|
|
|
|
|
["Name"] = "Наименование",
|
|
|
|
|
["Measure"] = "Ед. изм."
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string GetPriceListFileName() => Path.GetFileName(_priceListPath);
|
|
|
|
|
public Dictionary<string, string> GetPriceListHeaders() => settingsValues;
|
|
|
|
|
public string GetPriceListPath() => _priceListPath;
|
|
|
|
|
|
|
|
|
|
public void SaveSettings()
|
|
|
|
|
{
|
|
|
|
|
_rootKey.SetValue("PriceListPath", _priceListPath);
|
|
|
|
|
OnSettingsChange.Invoke();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetPriceListPath(string value)
|
|
|
|
|
{
|
|
|
|
|
_priceListPath = value;
|
|
|
|
|
}
|
2023-11-12 16:31:26 +03:00
|
|
|
|
}
|