Compare commits

..

3 Commits

Author SHA1 Message Date
David Štaleker
1dc48d2d85 login 2024-08-02 11:13:53 +02:00
David Štaleker
1459205ef3 verzija 2024-08-02 11:09:49 +02:00
David Štaleker
ca229fbd89 nove verzije 2024-08-02 11:00:59 +02:00
8 changed files with 525 additions and 158 deletions

View File

@@ -1,4 +1,5 @@
using System;
using InfosysPublisher.Classes;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
@@ -7,6 +8,8 @@ using System.Reflection;
using System.Threading.Tasks;
using System.Windows;
//[assembly: AssemblyVersion("2024.08.02.0")]
//Publish location:InfosysPublisher
namespace InfosysPublisher
{
/// <summary>
@@ -14,5 +17,38 @@ namespace InfosysPublisher
/// </summary>
public partial class App : Application
{
internal static string SqlConnectionString = @"Server=192.168.111.99\INFOSYS;Database=IsStoritve;User Id=infosys;Password=is2005is;MultipleActiveResultSets=True;Encrypt=false";
internal static Settings.Application? _application;
internal static User User;
internal static Version CurrentVersion;
protected override void OnStartup(StartupEventArgs e)
{
// On start stuff here
//base.OnStartup(e);
_application = WinSettings.GetSettings();
CurrentVersion = typeof(App).Assembly.GetName().Version;
if (_application == null)
{
OpenSettings();
return;
}
var win = new WinLogin();
win.ShowDialog();
}
internal static void OpenSettings()
{
var win = new WinSettings();
win.ShowDialog();
if (win.DialogResult != null && (bool)win.DialogResult)
{
_application = WinSettings.GetSettings();
}
}
}
}

View File

@@ -102,5 +102,32 @@ namespace ResevalnaScanner.Classes
return Encoding.UTF8.GetString(plainTextBytes, 0, byteCount).Trim();
}
public const int SALT_SIZE = 24; // size in bytes
public const int HASH_SIZE = 256; // size in bytes
public const int ITERATIONS = 20000; // number of pbkdf2 iterations
public static (byte[] Hash, byte[] Salt) CreatePasswordHash(string iText, byte[]? iSalt = null)
{
byte[] salt;
if (iSalt == null)
{
salt = new byte[SALT_SIZE];
using var rng = RandomNumberGenerator.Create();
rng.GetBytes(salt);
}
else
{
salt = iSalt;
}
var pbkdf2 = new Rfc2898DeriveBytes(iText, salt, ITERATIONS, HashAlgorithmName.SHA256);
return (pbkdf2.GetBytes(HASH_SIZE), salt);
}
public static bool CompareByteArrays(byte[] iArray, byte[] iArrayToCompare)
{
return iArray.Length == iArrayToCompare.Length && !iArray.Where((t, i) => t != iArrayToCompare[i]).ToList().Any();
}
}
}

View File

@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace InfosysPublisher.Classes
{
internal class User
{
public int Id { get; set; }
public string Name { get; set; }
public string Surname { get; set; }
public string Username { get; set; }
}
}

View File

@@ -2,10 +2,10 @@
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<TargetFramework>net8.0-windows7.0</TargetFramework>
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
<AssemblyVersion>1.0.1.0</AssemblyVersion>
<AssemblyVersion>2024.08.02.0</AssemblyVersion>
<ApplicationIcon>infosysPublisher.ico</ApplicationIcon>
</PropertyGroup>
@@ -14,6 +14,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.2.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="SSH.NET" Version="2020.0.2" />
</ItemGroup>

View File

@@ -0,0 +1,50 @@
<Window x:Class="InfosysPublisher.WinLogin"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:InfosysPublisher"
mc:Ignorable="d"
WindowStartupLocation="CenterScreen"
Title="WinLogin" Height="350" Width="500">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="50"/>
<RowDefinition Height="20"/>
<RowDefinition Height="30"/>
<RowDefinition Height="25"/>
<RowDefinition Height="25"/>
<RowDefinition Height="25"/>
<RowDefinition Height="25"/>
<RowDefinition Height="*"/>
<RowDefinition Height="40"/>
<RowDefinition Height="10"/>
</Grid.RowDefinitions>
<Viewbox Grid.Row="1">
<TextBlock>Infosys-Publisher</TextBlock></Viewbox>
<Viewbox Grid.Row="2">
<TextBlock Name="tblVersion">Version: xxxx-xx-xx-xx</TextBlock>
</Viewbox>
<Viewbox Grid.Row="4">
<TextBlock>Username:</TextBlock>
</Viewbox>
<Viewbox Grid.Row="5">
<TextBox Name="tbUsername" Width="300"></TextBox>
</Viewbox>
<Viewbox Grid.Row="6">
<TextBlock>Password:</TextBlock>
</Viewbox>
<Viewbox Grid.Row="7">
<PasswordBox Name="tbPassword" Width="300"></PasswordBox>
</Viewbox>
<Button Grid.Row="9" Width="300" Click="Login_OnClick">
<Viewbox>
<TextBlock>Login</TextBlock>
</Viewbox>
</Button>
</Grid>
</Window>

View File

@@ -0,0 +1,123 @@
using Renci.SshNet;
using ResevalnaScanner.Classes;
using System;
using System.Collections.Generic;
using System.Data;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using InfosysPublisher.Classes;
using Microsoft.Data.SqlClient;
namespace InfosysPublisher
{
/// <summary>
/// Interaction logic for WinLogin.xaml
/// </summary>
public partial class WinLogin : Window
{
public WinLogin()
{
InitializeComponent();
tbUsername.KeyDown += (sender, args) =>
{
if (args.Key != Key.Enter) return;
tbPassword.Focus();
};
tbPassword.KeyDown += (sender, args) =>
{
if (args.Key != Key.Enter) return;
Login();
};
tblVersion.Text = $"Version: {App.CurrentVersion}";
tbUsername.Focus();
}
private void Login_OnClick(object sender, RoutedEventArgs e)
{
Login();
}
private async void Login()
{
var succeeded = false;
var isLockedOut = false;
var username = tbUsername.Text;
var password = tbPassword.Password;
tbPassword.Password = "";
User user = null;
await Task.Run(() =>
{
using var sqlConnection = new SqlConnection(App.SqlConnectionString);
sqlConnection.Open();
var sqlCommandString = @"
SELECT ID_Uporabnik,
UporabniskoIme,
Ime,
Priimek,
GesloBytes,
SaltBytes,
Aktiven
FROM Uporabnik
WHERE UporabniskoIme = @uporabniskoIme
AND GesloBytes IS NOT NULL
AND SaltBytes IS NOT NULL"
;
using var sqlCommand = new SqlCommand(sqlCommandString, sqlConnection);
sqlCommand.Parameters.AddWithValue("uporabniskoIme", username);
using var sqlDataReader = sqlCommand.ExecuteReader();
if (sqlDataReader.Read())
{
if (sqlDataReader.GetString("UporabniskoIme") == username
&& Encryption.CompareByteArrays(Encryption.CreatePasswordHash(password, (byte[])sqlDataReader.GetValue("SaltBytes")).Hash, (byte[])sqlDataReader.GetValue("GesloBytes")))
{
if (sqlDataReader.GetBoolean("Aktiven"))
{
user = new User
{
Id = sqlDataReader.GetInt32(sqlDataReader.GetOrdinal("ID_Uporabnik")),
Name = sqlDataReader.GetString(sqlDataReader.GetOrdinal("Ime")),
Surname = sqlDataReader.GetString(sqlDataReader.GetOrdinal("Priimek")),
Username = sqlDataReader.GetString(sqlDataReader.GetOrdinal("UporabniskoIme")),
};
succeeded = true;
}
else
{
isLockedOut = true;
}
}
}
else
{
//zato da ne takoj konca
Encryption.CompareByteArrays(Encryption.CreatePasswordHash(password).Hash, new byte[4] { 0, 1, 0, 1 });
}
});
tbPassword.Password = "";
if (!succeeded)
{
MessageBox.Show("Wrong login data!", "Login", MessageBoxButton.OK, MessageBoxImage.Stop);
return;
}
App.User = user;
this.Hide();
var win = new WinMain();
win.ShowDialog();
this.Show();
this.Close();
}
}
}

View File

@@ -1,4 +1,4 @@
<Window x:Class="InfosysPublisher.MainWindow"
<Window x:Class="InfosysPublisher.WinMain"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
@@ -6,6 +6,7 @@
xmlns:local="clr-namespace:InfosysPublisher"
mc:Ignorable="d"
Icon="infosysPublisher.ico"
WindowStartupLocation="CenterScreen"
Title="Infosys-Publisher" Height="445" Width="580">
<Grid Margin="10, 0, 10, 10">
<Grid.RowDefinitions>
@@ -47,7 +48,7 @@
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Button Grid.Column="0" Name="BtnSettings" Width="80" HorizontalAlignment="Left">Nastavitve</Button>
<CheckBox Grid.Column="1" Name="ChbPripraviSamoZip" Width="180" HorizontalAlignment="Left" VerticalAlignment="Center">Pripravi samo zip</CheckBox>
<CheckBox Grid.Column="1" Name="ChbCreateOnlyZip" Width="180" HorizontalAlignment="Left" VerticalAlignment="Center">Pripravi samo zip</CheckBox>
<Button Grid.Column="1" Name="BtnPublish" Width="80" HorizontalAlignment="Right">Potrdi</Button>
</Grid>
</Grid>

View File

@@ -21,6 +21,7 @@ using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Xml;
using Microsoft.Data.SqlClient;
using Path = System.IO.Path;
namespace InfosysPublisher
@@ -28,7 +29,7 @@ namespace InfosysPublisher
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
public partial class WinMain : Window
{
#region Classes
@@ -39,8 +40,6 @@ namespace InfosysPublisher
}
#endregion
private Settings.Application? _application;
private string _projectPath;
private List<Project> _projects;
@@ -48,16 +47,17 @@ namespace InfosysPublisher
private string _selectedProjectSubPath = "";
private string _selectedProjectPublishLocation = "";
private string _selectedProjectVersion = "";
private string _selectedProjectGuid = "";
private const string SftpArchivePath = "Archive";
public MainWindow()
public WinMain()
{
InitializeComponent();
var version = typeof(App).Assembly.GetName().Version;
this.Title += " " + version;
_application = WinSettings.GetSettings();
App._application = WinSettings.GetSettings();
TbProjectsPath.LostFocus += TbProjectsPath_LostFocus;
CbProjects.SelectionChanged += CbProjects_SelectionChanged;
@@ -67,19 +67,13 @@ namespace InfosysPublisher
Closing += MainWindow_Closing;
if (_application == null)
{
OpenSettings();
return;
}
TbProjectsPath.Text = _application.LastFolder;
TbProjectsPath.Text = App._application.LastFolder;
LoadProjects();
}
private void BtnSettings_Click(object sender, RoutedEventArgs e)
{
OpenSettings();
App.OpenSettings();
}
private void MainWindow_Closing(object? sender, System.ComponentModel.CancelEventArgs e)
@@ -91,15 +85,7 @@ namespace InfosysPublisher
WinSettings.SaveSettings(settings);
}
private void OpenSettings()
{
var win = new WinSettings();
win.ShowDialog();
if (win.DialogResult != null && (bool)win.DialogResult)
{
_application = WinSettings.GetSettings();
}
}
private void CbProjects_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
@@ -162,43 +148,105 @@ namespace InfosysPublisher
.Where(x => x.Name is "App.xaml.cs" or "Program.cs")
.ToList();
if (projectFileInfos.Count <= 0)
{
projectFileInfos = new DirectoryInfo(projectSubPath)
.GetDirectories("Properties")
.SelectMany(x => x.GetFiles("AssemblyInfo.cs"))
.ToList();
};
if (projectFileInfos.Count <= 0) return;
var csLines = File.ReadLines(projectFileInfos[0].FullName).ToList();
var tmpSelectedProjectVersion = "";
var tmpSelectedProjectSubPath = "";
var tmpSelectedProjectPublishLocation = "";
var tmpSelectedProjectGuid = "";
csLines.Where(csLine => csLine.StartsWith("[assembly: AssemblyVersion("))
.ToList()
.ForEach(csLine =>
{
_selectedProjectVersion = csLine.Replace("[assembly: AssemblyVersion(\"", "").Replace("\")]", "");
_selectedProjectSubPath = projectSubPath;
tmpSelectedProjectVersion = csLine.Replace("[assembly: AssemblyVersion(\"", "").Replace("\")]", "");
tmpSelectedProjectSubPath = projectSubPath;
System.Diagnostics.Debug.WriteLine(_selectedProjectVersion);
System.Diagnostics.Debug.WriteLine(tmpSelectedProjectVersion);
});
if (_selectedProjectSubPath != "")
if (tmpSelectedProjectSubPath != "")
{
csLines.Where(csLine => csLine.StartsWith("//Publish location:"))
.ToList()
.ForEach(csLine =>
{
_selectedProjectPublishLocation = csLine.Replace("//Publish location:", "");
tmpSelectedProjectPublishLocation = csLine.Replace("//Publish location:", "");
System.Diagnostics.Debug.WriteLine(_selectedProjectPublishLocation);
System.Diagnostics.Debug.WriteLine(tmpSelectedProjectPublishLocation);
});
//Guid za paket vnos dela, tiste ko ga imajo v program cd
csLines.Where(csLine => csLine.Contains("public static string GuidAplikacije"))
.ToList()
.ForEach(csLine =>
{
tmpSelectedProjectGuid = csLine.Split('"')[1];
System.Diagnostics.Debug.WriteLine(tmpSelectedProjectGuid);
});
}
if (tmpSelectedProjectVersion == ""
|| tmpSelectedProjectSubPath == ""
|| tmpSelectedProjectPublishLocation == "") return;
//ce se ni guidja pogledam v nlog
if (tmpSelectedProjectGuid == "")
{
var projectNlogConfig= new DirectoryInfo(projectSubPath)
.GetFiles("NLog.config")
.ToList();
if (projectFileInfos.Count <= 0) return;
try
{
var xmlDocument = new XmlDocument();
xmlDocument.Load(projectNlogConfig[0].FullName);
var node = xmlDocument
.GetElementsByTagName("variable")
.Cast<XmlNode>()
.FirstOrDefault(x => x.Attributes != null
&& x.Attributes.Cast<XmlAttribute>().Any(y => y.Name == "name" && y.Value == "AplikacijaGuid"));
if (node != null)
tmpSelectedProjectGuid = node.Attributes["value"].Value;
}
catch (Exception exception)
{
MessageBox.Show(exception.ToString());
}
}
if (tmpSelectedProjectGuid == "") return;
_selectedProjectVersion = tmpSelectedProjectVersion;
_selectedProjectSubPath = tmpSelectedProjectSubPath;
_selectedProjectPublishLocation = tmpSelectedProjectPublishLocation;
_selectedProjectGuid = tmpSelectedProjectGuid;
});
if (_selectedProjectVersion == "" || _selectedProjectSubPath == "" || _selectedProjectPublishLocation == "")
if (_selectedProjectVersion == "" || _selectedProjectSubPath == "" || _selectedProjectPublishLocation == "" || _selectedProjectGuid == "")
return;
LblProjectInfo.Content = $"Verzija: {_selectedProjectVersion} Pot: {_selectedProjectPublishLocation}";
LblProjectInfo.Content = $"Verzija: {_selectedProjectVersion} Pot: {_selectedProjectPublishLocation} Guid: {_selectedProjectGuid}";
BtnPublish.IsEnabled = true;
}
private async void BtnPublish_Click(object sender, RoutedEventArgs e)
{
if (_selectedProject == null || _application == null)
if (_selectedProject == null || App._application == null)
return;
var releaseFolder = Path.Combine(_selectedProjectSubPath, @"bin\Release");
@@ -208,6 +256,9 @@ namespace InfosysPublisher
return;
}
TbOutput.Text = $"Publish start {DateTime.Now:dd.MM.yyyy HH:mm:ss}";
TbOutput.Text += $"\nClean {DateTime.Now:dd.MM.yyyy HH:mm:ss}";
GridProgress.Visibility = Visibility.Visible;
LblLoading.Content = $"Čiščenje mape {releaseFolder}";
await Task.Run(() =>
@@ -225,6 +276,7 @@ namespace InfosysPublisher
});
LblLoading.Content = $"Rebuild {_selectedProject.Path}";
TbOutput.Text += $"\nRebuild {_selectedProject.Path} {DateTime.Now:dd.MM.yyyy HH:mm:ss}";
var output = "";
await Task.Run(() =>
{
@@ -241,17 +293,18 @@ namespace InfosysPublisher
//cmd.StandardInput.WriteLine("echo Oscar");
cmd.StandardInput.Flush();
cmd.StandardInput.Close();
cmd.WaitForExit(_application.BuildSeconds * 1000);
cmd.WaitForExit(App._application.BuildSeconds * 1000);
output = cmd.StandardOutput.ReadToEnd();
Debug.WriteLine("\n\n\n\n");
Debug.WriteLine(output);
//System.Diagnostics.Process.Start("CMD.exe", "");
});
TbOutput.Text = output;
TbOutput.Text += "\n" + output;
var zipDirectory = new DirectoryInfo(releaseFolder).Parent?.FullName ?? "";
var zipPath = Path.Combine(zipDirectory, "Package.zip");
LblLoading.Content = $"Zip {zipPath}";
TbOutput.Text += $"\nZip {zipPath} {DateTime.Now:dd.MM.yyyy HH:mm:ss}";
if (File.Exists(zipPath))
File.Delete(zipPath);
@@ -260,129 +313,189 @@ namespace InfosysPublisher
ZipFile.CreateFromDirectory(releaseFolder, zipPath, CompressionLevel.Optimal, false);
});
if (ChbPripraviSamoZip.IsChecked != null && (bool) ChbPripraviSamoZip.IsChecked)
{
Process.Start("explorer.exe", zipDirectory);
}
else
{
//InfosysUpdate
//v&H6c$wTbTkgSgdWvL*8k$st3#z5X
LblLoading.Content = $"Upload to SFTP";
var error = "";
await Task.Run(() =>
{
try
{
using var sftpClient = new SftpClient(_application.SftpServerAddress, _application.SftpPort,
_application.SftpUsername, _application.SftpPassword);
sftpClient.Connect();
UploadSftp(zipDirectory, zipPath);
if (!sftpClient.Exists(_selectedProjectPublishLocation))
sftpClient.CreateDirectory(_selectedProjectPublishLocation);
if (!sftpClient.Exists(SftpArchivePath))
sftpClient.CreateDirectory(SftpArchivePath);
var files = sftpClient.ListDirectory(_selectedProjectPublishLocation).ToList();
var xmlVersion = "";
//arhiv
foreach (var file in files)
{
if (!file.Name.ToLower().EndsWith(".xml"))
continue;
var tmpXmlFile = Path.GetTempFileName();
using (var tmpFile = File.OpenWrite(tmpXmlFile))
{
sftpClient.DownloadFile(file.FullName, tmpFile);
}
try
{
var xmlContent = File.ReadAllText(tmpXmlFile);
if (!string.IsNullOrEmpty(xmlContent))
{
//Oddaljena verzije
var xmlDocument = new XmlDocument();
xmlDocument.LoadXml(xmlContent);
var xmlNode = xmlDocument.SelectSingleNode("/Update");
xmlVersion = xmlNode["Version"].InnerText;
}
}
catch (Exception exception)
{
error += "\n\n";
error += exception.ToString();
}
File.Delete(tmpXmlFile);
}
if (xmlVersion != "")
{
var projectArchive = SftpArchivePath + "/" + _selectedProjectPublishLocation;
if (!sftpClient.Exists(projectArchive))
sftpClient.CreateDirectory(projectArchive);
var archiveFolderWithoutIndex = projectArchive + "/" + xmlVersion.Replace(".", "_");
var archiveFolder = archiveFolderWithoutIndex;
var index = 1;
while (sftpClient.Exists(archiveFolder))
{
archiveFolder = archiveFolderWithoutIndex + "_" + index;
index++;
}
sftpClient.CreateDirectory(archiveFolder);
foreach (var file in files)
{
if (!file.IsRegularFile)
continue;
sftpClient.Get(file.FullName).MoveTo(archiveFolder + "/" + file.Name);
}
}
//Upload
var tmpXmlFileUpload = Path.GetTempFileName();
string xml = $@"<?xml version=""1.0""?>
<Update>
<Version>{_selectedProjectVersion}</Version>
</Update>";
File.WriteAllText(tmpXmlFileUpload, xml);
using (var fileStream = new FileStream(tmpXmlFileUpload, FileMode.Open))
{
sftpClient.UploadFile(fileStream, _selectedProjectPublishLocation + "/" + "Update.xml",
true);
}
using (var fileStream = new FileStream(zipPath, FileMode.Open))
{
sftpClient.UploadFile(fileStream, _selectedProjectPublishLocation + "/" + "Package.zip",
true);
}
File.Delete(tmpXmlFileUpload);
sftpClient.Disconnect();
}
catch (Exception ex)
{
error += "\n\n";
error += ex.ToString();
}
});
if (error != "")
{
MessageBox.Show(error);
}
}
TbOutput.Text += $"\nVersion {_selectedProjectVersion} {DateTime.Now:dd.MM.yyyy HH:mm:ss}";
WriteVersion();
GridProgress.Visibility = Visibility.Hidden;
LblLoading.Content = "";
TbOutput.Text += $"\nEnd {DateTime.Now:dd.MM.yyyy HH:mm:ss}";
}
private async void UploadSftp(string zipDirectory, string zipPath)
{
if (ChbCreateOnlyZip.IsChecked != null && (bool)ChbCreateOnlyZip.IsChecked)
{
Process.Start("explorer.exe", zipDirectory);
return;
}
//InfosysUpdate
//v&H6c$wTbTkgSgdWvL*8k$st3#z5X
LblLoading.Content = $"Upload to SFTP";
TbOutput.Text += $"\nUpload to SFTP {DateTime.Now:dd.MM.yyyy HH:mm:ss}";
var error = "";
await Task.Run(() =>
{
try
{
using var sftpClient = new SftpClient(App._application.SftpServerAddress, App._application.SftpPort,
App._application.SftpUsername, App._application.SftpPassword);
sftpClient.Connect();
if (!sftpClient.Exists(_selectedProjectPublishLocation))
sftpClient.CreateDirectory(_selectedProjectPublishLocation);
if (!sftpClient.Exists(SftpArchivePath))
sftpClient.CreateDirectory(SftpArchivePath);
var files = sftpClient.ListDirectory(_selectedProjectPublishLocation).ToList();
var xmlVersion = "";
//arhiv
foreach (var file in files)
{
if (!file.Name.ToLower().EndsWith(".xml"))
continue;
var tmpXmlFile = Path.GetTempFileName();
using (var tmpFile = File.OpenWrite(tmpXmlFile))
{
sftpClient.DownloadFile(file.FullName, tmpFile);
}
try
{
var xmlContent = File.ReadAllText(tmpXmlFile);
if (!string.IsNullOrEmpty(xmlContent))
{
//Oddaljena verzije
var xmlDocument = new XmlDocument();
xmlDocument.LoadXml(xmlContent);
var xmlNode = xmlDocument.SelectSingleNode("/Update");
xmlVersion = xmlNode["Version"].InnerText;
}
}
catch (Exception exception)
{
error += "\n\n";
error += exception.ToString();
}
File.Delete(tmpXmlFile);
}
if (xmlVersion != "")
{
var projectArchive = SftpArchivePath + "/" + _selectedProjectPublishLocation;
if (!sftpClient.Exists(projectArchive))
sftpClient.CreateDirectory(projectArchive);
var archiveFolderWithoutIndex = projectArchive + "/" + xmlVersion.Replace(".", "_");
var archiveFolder = archiveFolderWithoutIndex;
var index = 1;
while (sftpClient.Exists(archiveFolder))
{
archiveFolder = archiveFolderWithoutIndex + "_" + index;
index++;
}
sftpClient.CreateDirectory(archiveFolder);
foreach (var file in files)
{
if (!file.IsRegularFile)
continue;
sftpClient.Get(file.FullName).MoveTo(archiveFolder + "/" + file.Name);
}
}
//Upload
var tmpXmlFileUpload = Path.GetTempFileName();
string xml = $@"<?xml version=""1.0""?>
<Update>
<Version>{_selectedProjectVersion}</Version>
</Update>";
File.WriteAllText(tmpXmlFileUpload, xml);
using (var fileStream = new FileStream(tmpXmlFileUpload, FileMode.Open))
{
sftpClient.UploadFile(fileStream, _selectedProjectPublishLocation + "/" + "Update.xml",
true);
}
using (var fileStream = new FileStream(zipPath, FileMode.Open))
{
sftpClient.UploadFile(fileStream, _selectedProjectPublishLocation + "/" + "Package.zip",
true);
}
var sftpDirVersion = _selectedProjectPublishLocation + "/" + _selectedProjectVersion;
if (!sftpClient.Exists(sftpDirVersion))
sftpClient.CreateDirectory(sftpDirVersion);
using (var fileStream = new FileStream(zipPath, FileMode.Open))
{
sftpClient.UploadFile(fileStream, sftpDirVersion + "/" + "Package.zip",
true);
}
File.Delete(tmpXmlFileUpload);
sftpClient.Disconnect();
}
catch (Exception ex)
{
error += "\n\n";
error += ex.ToString();
}
});
if (error != "")
{
MessageBox.Show(error);
return;
}
}
private void WriteVersion()
{
using var sqlConnection = new SqlConnection(App.SqlConnectionString);
sqlConnection.Open();
var sqlCommandString = @"
DECLARE @idVerzija INT = NULL
SELECT TOP 1 @idVerzija = ID_Verzija
FROM AplikacijaVerzija
WHERE GUID_Aplikacija_FK = @guid
AND Verzija = @verzija
IF @idVerzija IS NULL
BEGIN
CREATE TABLE #tmpId(
ID INT
);
INSERT INTO AplikacijaVerzija (GUID_Aplikacija_FK, Verzija)
OUTPUT inserted.ID_Verzija INTO #tmpId
VALUES (@guid, @verzija)
SELECT TOP 1 @idVerzija = Id FROM #tmpId
END
INSERT INTO AplikacijaVerzijaRevizija (ID_AplikacijaVerzija_FK, ID_Uporabnik_FK)
VALUES (@idVerzija, @idUporabnik);";
using var sqlCommand = new SqlCommand(sqlCommandString, sqlConnection);
sqlCommand.Parameters.AddWithValue("guid", _selectedProjectGuid);
sqlCommand.Parameters.AddWithValue("verzija", _selectedProjectVersion);
sqlCommand.Parameters.AddWithValue("idUporabnik", App.User.Id);
sqlCommand.ExecuteNonQuery();
}
}
}