prvi
This commit is contained in:
25
InfosysPublisher.sln
Normal file
25
InfosysPublisher.sln
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio Version 17
|
||||||
|
VisualStudioVersion = 17.6.33815.320
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "InfosysPublisher", "InfosysPublisher\InfosysPublisher.csproj", "{96AECF20-EE37-45E8-BEA1-4C221E1E0BC7}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{96AECF20-EE37-45E8-BEA1-4C221E1E0BC7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{96AECF20-EE37-45E8-BEA1-4C221E1E0BC7}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{96AECF20-EE37-45E8-BEA1-4C221E1E0BC7}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{96AECF20-EE37-45E8-BEA1-4C221E1E0BC7}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {EA731043-FAF1-479E-8787-1E45190E5DC9}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
||||||
9
InfosysPublisher/App.xaml
Normal file
9
InfosysPublisher/App.xaml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
<Application x:Class="InfosysPublisher.App"
|
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:local="clr-namespace:InfosysPublisher"
|
||||||
|
StartupUri="WinMain.xaml">
|
||||||
|
<Application.Resources>
|
||||||
|
|
||||||
|
</Application.Resources>
|
||||||
|
</Application>
|
||||||
18
InfosysPublisher/App.xaml.cs
Normal file
18
InfosysPublisher/App.xaml.cs
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Configuration;
|
||||||
|
using System.Data;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows;
|
||||||
|
|
||||||
|
namespace InfosysPublisher
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Interaction logic for App.xaml
|
||||||
|
/// </summary>
|
||||||
|
public partial class App : Application
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
10
InfosysPublisher/AssemblyInfo.cs
Normal file
10
InfosysPublisher/AssemblyInfo.cs
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
using System.Windows;
|
||||||
|
|
||||||
|
[assembly: ThemeInfo(
|
||||||
|
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
|
||||||
|
//(used if a resource is not found in the page,
|
||||||
|
// or application resource dictionaries)
|
||||||
|
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
|
||||||
|
//(used if a resource is not found in the page,
|
||||||
|
// app, or any theme specific resource dictionaries)
|
||||||
|
)]
|
||||||
106
InfosysPublisher/Classes/Encryption.cs
Normal file
106
InfosysPublisher/Classes/Encryption.cs
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ResevalnaScanner.Classes
|
||||||
|
{
|
||||||
|
internal static class Encryption
|
||||||
|
{
|
||||||
|
public enum Type
|
||||||
|
{
|
||||||
|
General,
|
||||||
|
Licence,
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string AesEncrypt(this string iPlain, Type iType = Type.General, string iKey = "", string iSalt = "")
|
||||||
|
{
|
||||||
|
if (iPlain.Length > 16 && iPlain.Length % 16 != 0)
|
||||||
|
{
|
||||||
|
var size = ((iPlain.Length / 16) + 1) * 16;
|
||||||
|
iPlain += new string(' ', size - iPlain.Length);
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (iType)
|
||||||
|
{
|
||||||
|
case Type.General:
|
||||||
|
iKey = "DEWSCYUSBP2AQ6JnMc_InfosysPublisher_S9Gj3GU4hchg7J38zZ";
|
||||||
|
iSalt = "P4TqMkZ3FZd6Y5K5uNykmngCATDpP7PrxnACj2sFkfc6";
|
||||||
|
break;
|
||||||
|
case Type.Licence:
|
||||||
|
iKey = "2D849KZ6RjpQCG_ResevalnaLicense_crKwBTjnskwycCvy7N";
|
||||||
|
iSalt = "kUt7E6ngrYqA7watQ8YMPYNdzYFgLcCpuuchS96SZwC6";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(iPlain))
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
var saltByes = Encoding.ASCII.GetBytes(iSalt);
|
||||||
|
var key = new Rfc2898DeriveBytes(iKey, saltByes);
|
||||||
|
|
||||||
|
var aesAlgorithm = Aes.Create();
|
||||||
|
aesAlgorithm.KeySize = 256;
|
||||||
|
aesAlgorithm.Key = key.GetBytes(aesAlgorithm.KeySize / 8);
|
||||||
|
aesAlgorithm.IV = key.GetBytes(aesAlgorithm.BlockSize / 8);
|
||||||
|
|
||||||
|
var msEncrypt = new MemoryStream();
|
||||||
|
using (var encrypt = aesAlgorithm.CreateEncryptor(aesAlgorithm.Key, aesAlgorithm.IV))
|
||||||
|
using (var csEncrypt = new CryptoStream(msEncrypt, encrypt, CryptoStreamMode.Write))
|
||||||
|
{
|
||||||
|
using (var swEncrypt = new StreamWriter(csEncrypt))
|
||||||
|
{
|
||||||
|
swEncrypt.Write(iPlain);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Convert.ToBase64String(msEncrypt.ToArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string AesDecrypt(this string iCipherText, Type iType = Type.General, string iKey = "", string iSalt = "")
|
||||||
|
{
|
||||||
|
switch (iType)
|
||||||
|
{
|
||||||
|
case Type.General:
|
||||||
|
iKey = "DEWSCYUSBP2AQ6JnMc_InfosysPublisher_S9Gj3GU4hchg7J38zZ";
|
||||||
|
iSalt = "P4TqMkZ3FZd6Y5K5uNykmngCATDpP7PrxnACj2sFkfc6";
|
||||||
|
break;
|
||||||
|
case Type.Licence:
|
||||||
|
iKey = "2D849KZ6RjpQCG_ResevalnaLicense_crKwBTjnskwycCvy7N";
|
||||||
|
iSalt = "kUt7E6ngrYqA7watQ8YMPYNdzYFgLcCpuuchS96SZwC6";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(iCipherText))
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
var saltByes = Encoding.ASCII.GetBytes(iSalt);
|
||||||
|
var key = new Rfc2898DeriveBytes(iKey, saltByes);
|
||||||
|
|
||||||
|
var aesAlgorithm = Aes.Create();
|
||||||
|
aesAlgorithm.KeySize = 256;
|
||||||
|
aesAlgorithm.Key = key.GetBytes(aesAlgorithm.KeySize / 8);
|
||||||
|
aesAlgorithm.IV = key.GetBytes(aesAlgorithm.BlockSize / 8);
|
||||||
|
|
||||||
|
var cipherTextBytes = Convert.FromBase64String(iCipherText);
|
||||||
|
var plainTextBytes = new byte[iCipherText.Length];
|
||||||
|
var byteCount = 0;
|
||||||
|
|
||||||
|
using (var decrypt = aesAlgorithm.CreateDecryptor(aesAlgorithm.Key, aesAlgorithm.IV))
|
||||||
|
using (var msDecrypt = new MemoryStream(cipherTextBytes))
|
||||||
|
using (var csDecrypt = new CryptoStream(msDecrypt, decrypt, CryptoStreamMode.Read))
|
||||||
|
{
|
||||||
|
byteCount = csDecrypt.Read(plainTextBytes, 0, plainTextBytes.Length);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Encoding.UTF8.GetString(plainTextBytes, 0, byteCount).Trim();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
54
InfosysPublisher/Classes/Settings.cs
Normal file
54
InfosysPublisher/Classes/Settings.cs
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
using Newtonsoft.Json;
|
||||||
|
using ResevalnaScanner.Classes;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace InfosysPublisher.Classes
|
||||||
|
{
|
||||||
|
internal class Settings
|
||||||
|
{
|
||||||
|
public class Application
|
||||||
|
{
|
||||||
|
//SQL strežniki
|
||||||
|
//Privatna polja
|
||||||
|
[JsonProperty] private string _sftpUsername;
|
||||||
|
[JsonProperty] private string _sftpPassword;
|
||||||
|
|
||||||
|
//Javna polja
|
||||||
|
public string SftpServerAddress { get; set; }
|
||||||
|
public int SftpPort { get; set; }
|
||||||
|
public int BuildSeconds { get; set; }
|
||||||
|
public string LastFolder { get; set; }
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
|
public string SftpUsername
|
||||||
|
{
|
||||||
|
get => _sftpUsername.AesDecrypt();
|
||||||
|
set => _sftpUsername = value.AesEncrypt();
|
||||||
|
}
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
|
public string SftpPassword
|
||||||
|
{
|
||||||
|
get => _sftpPassword.AesDecrypt();
|
||||||
|
set => _sftpPassword = value.AesEncrypt();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Save(string iPath)
|
||||||
|
{
|
||||||
|
var json = JsonConvert.SerializeObject(this);
|
||||||
|
|
||||||
|
if (!Directory.Exists(Path.GetDirectoryName(iPath)))
|
||||||
|
{
|
||||||
|
Directory.CreateDirectory(Path.GetDirectoryName(iPath));
|
||||||
|
}
|
||||||
|
|
||||||
|
File.WriteAllText(iPath, json);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
27
InfosysPublisher/InfosysPublisher.csproj
Normal file
27
InfosysPublisher/InfosysPublisher.csproj
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>WinExe</OutputType>
|
||||||
|
<TargetFramework>net6.0-windows</TargetFramework>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<UseWPF>true</UseWPF>
|
||||||
|
<AssemblyVersion>1.0.1.0</AssemblyVersion>
|
||||||
|
<ApplicationIcon>infosysPublisher.ico</ApplicationIcon>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Remove="infosysPublisher.ico" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
|
<PackageReference Include="SSH.NET" Version="2020.0.2" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Resource Include="infosysPublisher.ico">
|
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
</Resource>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
54
InfosysPublisher/WinMain.xaml
Normal file
54
InfosysPublisher/WinMain.xaml
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
<Window x:Class="InfosysPublisher.MainWindow"
|
||||||
|
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"
|
||||||
|
Icon="infosysPublisher.ico"
|
||||||
|
Title="Infosys-Publisher" Height="445" Width="580">
|
||||||
|
<Grid Margin="10, 0, 10, 10">
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition Height="25"/>
|
||||||
|
<RowDefinition Height="25"/>
|
||||||
|
<RowDefinition Height="25"/>
|
||||||
|
<RowDefinition Height="25"/>
|
||||||
|
<RowDefinition Height="25"/>
|
||||||
|
<RowDefinition Height="*"/>
|
||||||
|
<RowDefinition Height="25"/>
|
||||||
|
<RowDefinition Height="*"/>
|
||||||
|
<RowDefinition Height="30"/>
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
<Label Grid.Row="0">Mapa projektov:</Label>
|
||||||
|
<TextBox Grid.Row="1" Name="TbProjectsPath"></TextBox>
|
||||||
|
<Label Grid.Row="2">Projekt:</Label>
|
||||||
|
<ComboBox Grid.Row="3" Name="CbProjects" DisplayMemberPath="Name"></ComboBox>
|
||||||
|
<Label Grid.Row="4" Name="LblProjectInfo">Verzija:</Label>
|
||||||
|
<Grid Grid.Row="5" Name="GridProgress" Visibility="Hidden">
|
||||||
|
<Grid.ColumnDefinitions>
|
||||||
|
<ColumnDefinition Width="20" />
|
||||||
|
<ColumnDefinition Width="*" />
|
||||||
|
<ColumnDefinition Width="20" />
|
||||||
|
</Grid.ColumnDefinitions>
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition Height="*"/>
|
||||||
|
<RowDefinition Height="30"/>
|
||||||
|
<RowDefinition Height="50"/>
|
||||||
|
<RowDefinition Height="*"/>
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
<ProgressBar x:Name="PbLoading" Grid.Row="1" Grid.Column="1" IsIndeterminate="True"/>
|
||||||
|
<Label x:Name="LblLoading" Grid.Row="2" Grid.Column="1" Content="Priprava podatkov" HorizontalAlignment="Center"/>
|
||||||
|
</Grid>
|
||||||
|
<Label Grid.Row="6">Output:</Label>
|
||||||
|
<TextBox Grid.Row="7" Name="TbOutput" VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Auto" IsReadOnly="True"></TextBox>
|
||||||
|
<Grid Grid.Row="8" Margin="3">
|
||||||
|
<Grid.ColumnDefinitions>
|
||||||
|
<ColumnDefinition Width="*"/>
|
||||||
|
<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>
|
||||||
|
<Button Grid.Column="1" Name="BtnPublish" Width="80" HorizontalAlignment="Right">Potrdi</Button>
|
||||||
|
</Grid>
|
||||||
|
</Grid>
|
||||||
|
</Window>
|
||||||
388
InfosysPublisher/WinMain.xaml.cs
Normal file
388
InfosysPublisher/WinMain.xaml.cs
Normal file
@@ -0,0 +1,388 @@
|
|||||||
|
using InfosysPublisher.Classes;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Renci.SshNet;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.IO;
|
||||||
|
using System.IO.Compression;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Runtime.InteropServices.ComTypes;
|
||||||
|
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;
|
||||||
|
using System.Windows.Navigation;
|
||||||
|
using System.Windows.Shapes;
|
||||||
|
using System.Xml;
|
||||||
|
using Path = System.IO.Path;
|
||||||
|
|
||||||
|
namespace InfosysPublisher
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Interaction logic for MainWindow.xaml
|
||||||
|
/// </summary>
|
||||||
|
public partial class MainWindow : Window
|
||||||
|
{
|
||||||
|
#region Classes
|
||||||
|
|
||||||
|
public class Project
|
||||||
|
{
|
||||||
|
public string Name { get; set; }
|
||||||
|
public string Path { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
private Settings.Application? _application;
|
||||||
|
|
||||||
|
|
||||||
|
private string _projectPath;
|
||||||
|
private List<Project> _projects;
|
||||||
|
private Project? _selectedProject = null;
|
||||||
|
private string _selectedProjectSubPath = "";
|
||||||
|
private string _selectedProjectPublishLocation = "";
|
||||||
|
private string _selectedProjectVersion = "";
|
||||||
|
|
||||||
|
private const string SftpArchivePath = "Archive";
|
||||||
|
public MainWindow()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
|
||||||
|
var version = typeof(App).Assembly.GetName().Version;
|
||||||
|
this.Title += " " + version;
|
||||||
|
|
||||||
|
_application = WinSettings.GetSettings();
|
||||||
|
|
||||||
|
TbProjectsPath.LostFocus += TbProjectsPath_LostFocus;
|
||||||
|
CbProjects.SelectionChanged += CbProjects_SelectionChanged;
|
||||||
|
|
||||||
|
BtnPublish.Click += BtnPublish_Click;
|
||||||
|
BtnSettings.Click += BtnSettings_Click;
|
||||||
|
|
||||||
|
Closing += MainWindow_Closing;
|
||||||
|
|
||||||
|
if (_application == null)
|
||||||
|
{
|
||||||
|
OpenSettings();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
TbProjectsPath.Text = _application.LastFolder;
|
||||||
|
LoadProjects();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void BtnSettings_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
OpenSettings();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void MainWindow_Closing(object? sender, System.ComponentModel.CancelEventArgs e)
|
||||||
|
{
|
||||||
|
var settings = WinSettings.GetSettings();
|
||||||
|
if (settings == null)
|
||||||
|
return;
|
||||||
|
settings.LastFolder = TbProjectsPath.Text;
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
_selectedProject = (Project)CbProjects.SelectedItem;
|
||||||
|
LoadProject();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void TbProjectsPath_LostFocus(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
LoadProjects();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LoadProjects()
|
||||||
|
{
|
||||||
|
_projectPath = TbProjectsPath.Text;
|
||||||
|
|
||||||
|
if (!Directory.Exists(_projectPath))
|
||||||
|
{
|
||||||
|
MessageBox.Show($"Pot {_projectPath} ne obstaja!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_projects = new List<Project>();
|
||||||
|
var dirInfo = new DirectoryInfo(_projectPath);
|
||||||
|
|
||||||
|
dirInfo.GetDirectories()
|
||||||
|
.ToList()
|
||||||
|
.ForEach(directoryInfo => directoryInfo.GetFiles("*.sln")
|
||||||
|
.ToList()
|
||||||
|
.ForEach(x => _projects.Add(new Project
|
||||||
|
{
|
||||||
|
Name = $"{directoryInfo.Name}/{x.Name}",
|
||||||
|
Path = x.FullName
|
||||||
|
})));
|
||||||
|
|
||||||
|
CbProjects.ItemsSource = _projects;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LoadProject()
|
||||||
|
{
|
||||||
|
TbOutput.Text = "";
|
||||||
|
LblProjectInfo.Content = "";
|
||||||
|
BtnPublish.IsEnabled = false;
|
||||||
|
if (_selectedProject == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
_selectedProjectVersion = "";
|
||||||
|
_selectedProjectSubPath = "";
|
||||||
|
_selectedProjectPublishLocation = "";
|
||||||
|
|
||||||
|
var lines = File.ReadLines(_selectedProject.Path);
|
||||||
|
lines.Where(line => line.StartsWith("Project"))
|
||||||
|
.ToList()
|
||||||
|
.ForEach(line =>
|
||||||
|
{
|
||||||
|
var projectTitle = line.Split(",")[1].Replace(" ", "").Replace("\"", "").Split(@"\")[0];
|
||||||
|
var projectSubPath = Path.Combine(new FileInfo(_selectedProject.Path)?.DirectoryName ?? "", projectTitle);
|
||||||
|
var projectFileInfos = new DirectoryInfo(projectSubPath)
|
||||||
|
.GetFiles("*.cs")
|
||||||
|
.Where(x => x.Name is "App.xaml.cs" or "Program.cs")
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
if (projectFileInfos.Count <= 0) return;
|
||||||
|
|
||||||
|
var csLines = File.ReadLines(projectFileInfos[0].FullName).ToList();
|
||||||
|
|
||||||
|
csLines.Where(csLine => csLine.StartsWith("[assembly: AssemblyVersion("))
|
||||||
|
.ToList()
|
||||||
|
.ForEach(csLine =>
|
||||||
|
{
|
||||||
|
_selectedProjectVersion = csLine.Replace("[assembly: AssemblyVersion(\"", "").Replace("\")]", "");
|
||||||
|
_selectedProjectSubPath = projectSubPath;
|
||||||
|
|
||||||
|
System.Diagnostics.Debug.WriteLine(_selectedProjectVersion);
|
||||||
|
});
|
||||||
|
if (_selectedProjectSubPath != "")
|
||||||
|
{
|
||||||
|
csLines.Where(csLine => csLine.StartsWith("//Publish location:"))
|
||||||
|
.ToList()
|
||||||
|
.ForEach(csLine =>
|
||||||
|
{
|
||||||
|
_selectedProjectPublishLocation = csLine.Replace("//Publish location:", "");
|
||||||
|
|
||||||
|
System.Diagnostics.Debug.WriteLine(_selectedProjectPublishLocation);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (_selectedProjectVersion == "" || _selectedProjectSubPath == "" || _selectedProjectPublishLocation == "")
|
||||||
|
return;
|
||||||
|
|
||||||
|
LblProjectInfo.Content = $"Verzija: {_selectedProjectVersion} Pot: {_selectedProjectPublishLocation}";
|
||||||
|
|
||||||
|
BtnPublish.IsEnabled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void BtnPublish_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
if (_selectedProject == null || _application == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var releaseFolder = Path.Combine(_selectedProjectSubPath, @"bin\Release");
|
||||||
|
if (!Directory.Exists(releaseFolder))
|
||||||
|
{
|
||||||
|
MessageBox.Show($"Mapa {releaseFolder} ne obstaja!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
GridProgress.Visibility = Visibility.Visible;
|
||||||
|
LblLoading.Content = $"Čiščenje mape {releaseFolder}";
|
||||||
|
await Task.Run(() =>
|
||||||
|
{
|
||||||
|
var diReleaseFolder = new DirectoryInfo(releaseFolder);
|
||||||
|
|
||||||
|
foreach (var file in diReleaseFolder.GetFiles())
|
||||||
|
{
|
||||||
|
file.Delete();
|
||||||
|
}
|
||||||
|
foreach (var dir in diReleaseFolder.GetDirectories())
|
||||||
|
{
|
||||||
|
dir.Delete(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
LblLoading.Content = $"Rebuild {_selectedProject.Path}";
|
||||||
|
var output = "";
|
||||||
|
await Task.Run(() =>
|
||||||
|
{
|
||||||
|
var command = $"devenv {_selectedProject.Path} /Rebuild \"Release\"";
|
||||||
|
var cmd = new Process();
|
||||||
|
cmd.StartInfo.FileName = "cmd.exe";
|
||||||
|
cmd.StartInfo.RedirectStandardInput = true;
|
||||||
|
cmd.StartInfo.RedirectStandardOutput = true;
|
||||||
|
cmd.StartInfo.CreateNoWindow = true;
|
||||||
|
cmd.StartInfo.UseShellExecute = false;
|
||||||
|
cmd.Start();
|
||||||
|
|
||||||
|
cmd.StandardInput.WriteLine(command);
|
||||||
|
//cmd.StandardInput.WriteLine("echo Oscar");
|
||||||
|
cmd.StandardInput.Flush();
|
||||||
|
cmd.StandardInput.Close();
|
||||||
|
cmd.WaitForExit(_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;
|
||||||
|
|
||||||
|
var zipDirectory = new DirectoryInfo(releaseFolder).Parent?.FullName ?? "";
|
||||||
|
var zipPath = Path.Combine(zipDirectory, "Package.zip");
|
||||||
|
LblLoading.Content = $"Zip {zipPath}";
|
||||||
|
if (File.Exists(zipPath))
|
||||||
|
File.Delete(zipPath);
|
||||||
|
|
||||||
|
await Task.Run(() =>
|
||||||
|
{
|
||||||
|
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();
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
GridProgress.Visibility = Visibility.Hidden;
|
||||||
|
LblLoading.Content = "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
37
InfosysPublisher/WinSettings.xaml
Normal file
37
InfosysPublisher/WinSettings.xaml
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
<Window x:Class="InfosysPublisher.WinSettings"
|
||||||
|
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"
|
||||||
|
Icon="infosysPublisher.ico"
|
||||||
|
Title="WinSettings" Height="355" Width="355">
|
||||||
|
<Grid Margin="5">
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition Height="25"/>
|
||||||
|
<RowDefinition Height="25"/>
|
||||||
|
<RowDefinition Height="25"/>
|
||||||
|
<RowDefinition Height="25"/>
|
||||||
|
<RowDefinition Height="25"/>
|
||||||
|
<RowDefinition Height="25"/>
|
||||||
|
<RowDefinition Height="25"/>
|
||||||
|
<RowDefinition Height="25"/>
|
||||||
|
<RowDefinition Height="25"/>
|
||||||
|
<RowDefinition Height="25"/>
|
||||||
|
<RowDefinition Height="*"/>
|
||||||
|
<RowDefinition Height="25"/>
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
<Label Grid.Row="0">SFTP strežnik:</Label>
|
||||||
|
<TextBox Grid.Row="1" Name="TbSftpServer"></TextBox>
|
||||||
|
<Label Grid.Row="2">SFTP port:</Label>
|
||||||
|
<TextBox Grid.Row="3" Name="TbSftpPort"></TextBox>
|
||||||
|
<Label Grid.Row="4">SFTP uporabniško ime:</Label>
|
||||||
|
<TextBox Grid.Row="5" Name="TbSftpUsername"></TextBox>
|
||||||
|
<Label Grid.Row="6">SFTP geslo:</Label>
|
||||||
|
<TextBox Grid.Row="7" Name="TbSftpPassword"></TextBox>
|
||||||
|
<Label Grid.Row="8">Trajanje build:</Label>
|
||||||
|
<TextBox Grid.Row="9" Name="TbBuildDuration"></TextBox>
|
||||||
|
<Button Name="BtnSave" Grid.Row="20" Width="80" HorizontalAlignment="Right">Shrani</Button>
|
||||||
|
</Grid>
|
||||||
|
</Window>
|
||||||
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
InfosysPublisher/infosysPublisher.ico
Normal file
BIN
InfosysPublisher/infosysPublisher.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 66 KiB |
Reference in New Issue
Block a user