prvi
This commit is contained in:
93
InfosysPublisher/WinSettings.xaml.cs
Normal file
93
InfosysPublisher/WinSettings.xaml.cs
Normal file
@@ -0,0 +1,93 @@
|
||||
using InfosysPublisher.Classes;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
|
||||
namespace InfosysPublisher
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for WinSettings.xaml
|
||||
/// </summary>
|
||||
public partial class WinSettings : Window
|
||||
{
|
||||
private static string _settingsPath;
|
||||
private static string _applicationPath;
|
||||
|
||||
public WinSettings()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
BtnSave.Click += BtnSave_Click;
|
||||
|
||||
LoadSettings();
|
||||
}
|
||||
|
||||
private void BtnSave_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
SaveSettings();
|
||||
}
|
||||
|
||||
private void SaveSettings()
|
||||
{
|
||||
var settings = new Settings.Application
|
||||
{
|
||||
SftpServerAddress = TbSftpServer.Text,
|
||||
SftpPort = Convert.ToInt32(TbSftpPort.Text),
|
||||
SftpUsername = TbSftpUsername.Text,
|
||||
SftpPassword = TbSftpPassword.Text,
|
||||
BuildSeconds = Convert.ToInt32(TbBuildDuration.Text)
|
||||
};
|
||||
|
||||
SaveSettings(settings);
|
||||
|
||||
this.DialogResult = true;
|
||||
}
|
||||
|
||||
private void LoadSettings()
|
||||
{
|
||||
var settings = GetSettings() ?? new Settings.Application();
|
||||
|
||||
TbSftpServer.Text = settings.SftpServerAddress;
|
||||
TbSftpPort.Text = settings.SftpPort.ToString();
|
||||
TbSftpUsername.Text = settings.SftpUsername;
|
||||
TbSftpPassword.Text = settings.SftpPassword;
|
||||
TbBuildDuration.Text = settings.BuildSeconds.ToString();
|
||||
}
|
||||
|
||||
private static void SetPaths()
|
||||
{
|
||||
_applicationPath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
|
||||
_settingsPath = _applicationPath + @"\InfosysPublisher.json";
|
||||
}
|
||||
|
||||
internal static Settings.Application? GetSettings()
|
||||
{
|
||||
SetPaths();
|
||||
|
||||
if (File.Exists(_settingsPath))
|
||||
{
|
||||
return JsonConvert.DeserializeObject<Settings.Application>(File.ReadAllText(_settingsPath)) ?? new Settings.Application();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
internal static void SaveSettings(Settings.Application iSettings)
|
||||
{
|
||||
SetPaths();
|
||||
iSettings.Save(_settingsPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user