Skip to content

Commit

Permalink
0.9.12052023
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreyMas committed May 12, 2023
1 parent 6c09e40 commit 068c3b3
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 18 deletions.
27 changes: 25 additions & 2 deletions RXInstanceManager/AppHandlers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
using System.Security.Principal;
using System.Security.AccessControl;
using NLog;
using System.Linq.Expressions;
using static System.Net.Mime.MediaTypeNames;

namespace RXInstanceManager
{
Expand Down Expand Up @@ -111,9 +113,30 @@ public static string GetConfigStringValue(this Dictionary<string, string> values
return null;
}

public static void SetConfigStringValue(Config config, string key, string value)
public static void SetConfigStringValue(Config config, string instancePath, string key, string value)
{
YamlSimple.Parser.UpdateFileStringValue(config.Path, key, value);
var isKeyExists = YamlSimple.Parser.CheckFileKey(config.Path, key);
try
{
if (!isKeyExists)
{
ExecuteDoCommands(instancePath, "do all down");
YamlSimple.Parser.AddFileStringValue(config.Path, key, value);
}
else
YamlSimple.Parser.UpdateFileStringValue(config.Path, key, value);
}
catch (UnauthorizedAccessException aex)
{
ExecuteCmdCommand($"icacls {config.Path} /grant:r *S-1-1-0:F", true);
if (!isKeyExists)
{
ExecuteDoCommands(instancePath, "do all down");
YamlSimple.Parser.AddFileStringValue(config.Path, key, value);
}
else
YamlSimple.Parser.UpdateFileStringValue(config.Path, key, value);
}
}

#endregion
Expand Down
27 changes: 24 additions & 3 deletions RXInstanceManager/AppHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,22 @@ namespace RXInstanceManager
{
public static class AppHelper
{
public static bool PingURL(string url)
{
Uri uri = new Uri(url);
try
{
HttpWebRequest httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(uri);
HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
}
catch
{
return false;
}

return true;
}

public static string Base64EncodeFromUTF8(string plainText)
{
var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(plainText);
Expand Down Expand Up @@ -41,7 +57,7 @@ public static string Base64DecodeToASCII(string base64EncodedData)

public static bool ValidateInputCode(string code)
{
return code.Length > 3 && code.Length <= 10 && code.All(x => (x >= 'a' && x <= 'z') || (x >= '0' && x <= '9'));
return code.Length > 3 && code.Length <= 10 && code.All(x => (x >= 'a' && x <= 'z') || (x >= 'A' && x <= 'Z') || (x >= '0' && x <= '9'));
}

public static bool ValidateInputDBName(string name)
Expand Down Expand Up @@ -74,6 +90,11 @@ public static string GetBuildsPath(string instancePath)
return Path.Combine(instancePath, "etc", "_builds");
}

public static string GetBuildsBinPath(string instancePath)
{
return Path.Combine(instancePath, "etc", "_builds_bin");
}

public static string GetPlatformBuildsPath(string instancePath)
{
var path = Path.Combine(instancePath, "etc", "_builds", "PlatformBuilds");
Expand Down Expand Up @@ -102,14 +123,14 @@ public static string GetDBNameFromConnectionString(string engine, string connect
{
if (engine == "mssql")
{
var databaseNameParam = connectionString.Split(';').FirstOrDefault(x => x.Contains("initial catalog"));
var databaseNameParam = connectionString.Split(';').FirstOrDefault(x => x.ToLower().Contains("initial catalog"));
if (databaseNameParam != null)
return databaseNameParam.Split('=')[1];
}

if (engine == "postgres")
{
var databaseNameParam = connectionString.Split(';').FirstOrDefault(x => x.Contains("Database"));
var databaseNameParam = connectionString.Split(';').FirstOrDefault(x => x.ToLower().Contains("database"));
if (databaseNameParam != null)
return databaseNameParam.Split('=')[1];
}
Expand Down
2 changes: 1 addition & 1 deletion RXInstanceManager/Dialogs/Dialogs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public static class Dialogs
{
public static string ShowEnterValueDialog(string emptyValue, string defaultValue = null)
{
var dialog = new EnterValueDialog(defaultValue);
var dialog = new EnterValueDialog(emptyValue, defaultValue);

var dialogResult = dialog.ShowDialog();
if (!dialogResult.HasValue || !dialogResult.Value)
Expand Down
2 changes: 1 addition & 1 deletion RXInstanceManager/Dialogs/EnterValueDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<RowDefinition Height="*" />
<RowDefinition Height="20" />
</Grid.RowDefinitions>
<TextBox x:Name="Input" Grid.Row="1" Grid.Column="1" Width="400" KeyDown="Input_KeyDown" />
<TextBox x:Name="Input" Grid.Row="1" Grid.Column="1" Width="400" Style="{DynamicResource EditTextBoxEmpty}" KeyDown="Input_KeyDown" TextChanged="Input_TextChanged" GotFocus="Input_GotFocus" LostFocus="Input_LostFocus" />
<Button x:Name="ButtonSelect" Content="..." BorderThickness="1" Grid.Row="1" Grid.Column="1" Width="30" HorizontalAlignment="Right" Click="ButtonSelect_Click" />
<StackPanel Orientation="Horizontal" Grid.Row="2" Grid.Column="1" Height="25" Width="250">
<Button x:Name="ButtonOk" Content="Ок" Style="{DynamicResource SaveCancelButton}" Height="24" Width="125" Click="ButtonOk_Click" />
Expand Down
30 changes: 28 additions & 2 deletions RXInstanceManager/Dialogs/EnterValueDialog.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@
namespace RXInstanceManager
{
/// <summary>
/// Логика взаимодействия для Window1.xaml
/// Логика взаимодействия для EnterValueDialog.xaml
/// </summary>
public partial class EnterValueDialog : Window
{
public string Value { get; set; }
public string EmptyValue { get; set; }

public EnterValueDialog(string emptyValue, string value = null)
public EnterValueDialog(string emptyValue, string value)
{
InitializeComponent();

Expand All @@ -32,6 +33,7 @@ public EnterValueDialog(string emptyValue, string value = null)
}
else
{
this.EmptyValue = emptyValue;
Input.Text = emptyValue;
}
}
Expand All @@ -51,6 +53,23 @@ private void Input_KeyDown(object sender, KeyEventArgs e)
}
}

private void Input_TextChanged(object sender, TextChangedEventArgs e)
{
EditStyleChanging(Input, this.EmptyValue);
}

private void Input_GotFocus(object sender, RoutedEventArgs e)
{
if (Input.Text == this.EmptyValue)
Input.Text = string.Empty;
}

private void Input_LostFocus(object sender, RoutedEventArgs e)
{
if (string.IsNullOrEmpty(Input.Text))
Input.Text = this.EmptyValue;
}

private void ButtonOk_Click(object sender, RoutedEventArgs e)
{
if (!string.IsNullOrWhiteSpace(Input.Text))
Expand All @@ -73,5 +92,12 @@ private void ButtonSelect_Click(object sender, RoutedEventArgs e)
{
// TODO: Для реализации логики выбора.
}

private void EditStyleChanging(TextBox textBox, string emptyValue)
{
textBox.Style = (string.IsNullOrWhiteSpace(textBox.Text) || textBox.Text == emptyValue) ?
this.FindResource("EditTextBoxEmpty") as Style :
this.FindResource("EditTextBoxEdit") as Style;
}
}
}
23 changes: 15 additions & 8 deletions RXInstanceManager/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ private void ButtonAdd_Click(object sender, RoutedEventArgs e)
{
AppHandlers.InfoHandler(_instance, MethodBase.GetCurrentMethod().Name);

var instancePath = Dialogs.ShowEnterValueDialog("Укажите путь до инстанса");
var instancePath = Dialogs.ShowEnterValueDialog("Укажите путь до инстанса...");
if (instancePath == null)
return;

Expand All @@ -112,13 +112,13 @@ private void ButtonAdd_Click(object sender, RoutedEventArgs e)
var instanceCode = yamlValues.GetConfigStringValue("variables.instance_name");
if (string.IsNullOrEmpty(instanceCode))
{
instanceCode = Dialogs.ShowEnterValueDialog("Укажите код системы");
instanceCode = Dialogs.ShowEnterValueDialog("Укажите код системы... (до 10 символов английского алфавита и цифры)");
if (string.IsNullOrEmpty(instanceCode))
return;

if (!AppHelper.ValidateInputCode(instanceCode))
{
MessageBox.Show("Код должен быть более от 4 до 10 символов английского алфавита в нижнем регистре и цифр");
MessageBox.Show("Код должен быть более от 4 до 10 символов английского алфавита и цифр");
return;
}
}
Expand All @@ -131,7 +131,7 @@ private void ButtonAdd_Click(object sender, RoutedEventArgs e)
return;
}

AppHandlers.SetConfigStringValue(config, "variables.instance_name", instanceCode);
AppHandlers.SetConfigStringValue(config, instancePath, "variables.instance_name", instanceCode);

instance = new Instance();
instance.Code = instanceCode;
Expand Down Expand Up @@ -173,9 +173,16 @@ private void ButtonInstall_Click(object sender, RoutedEventArgs e)

try
{
var serviceStatus = AppHandlers.GetServiceStatus(_instance);
if (serviceStatus == Constants.InstanceStatus.NeedInstall)
AppHandlers.LaunchProcess(AppHelper.GetDirectumLauncherPath(_instance.InstancePath));
if (Directory.Exists(AppHelper.GetBuildsBinPath(_instance.InstancePath)))
{
AppHandlers.ExecuteDoCommands(_instance.InstancePath, "do iis configure", "do all up");
}
else
{
var serviceStatus = AppHandlers.GetServiceStatus(_instance);
if (serviceStatus == Constants.InstanceStatus.NeedInstall)
AppHandlers.LaunchProcess(AppHelper.GetDirectumLauncherPath(_instance.InstancePath));
}
}
catch (Exception ex)
{
Expand Down Expand Up @@ -416,7 +423,7 @@ private void HiddenButton_Click(object sender, RoutedEventArgs e)

//MessageBox.Show(AppHandlers.GetInstanceSolutionVersion(_instance.InstancePath));

AppHandlers.SetConfigStringValue(_instance.Config, "variables.instance_name", "test");
//AppHandlers.SetConfigStringValue(_instance.Config, "variables.instance_name", "test");
}


Expand Down
2 changes: 1 addition & 1 deletion RXInstanceManager/MainWindowHandlers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ private static bool ValidateBeforeInstallInstance(Dictionary<string, string> yam
}

var localProtocol = yamlValues.GetConfigStringValue("services_config.DevelopmentStudio.LOCAL_WEB_PROTOCOL");
if (!string.IsNullOrWhiteSpace(localProtocol) && localProtocol != "http")
if (!string.IsNullOrWhiteSpace(localProtocol) && localProtocol != "http" && localProtocol != "{{ protocol }}")
{
MessageBox.Show("Указан некорректный протокол в параметре \"services_config.DevelopmentStudio.LOCAL_WEB_PROTOCOL\" файла config.yml");
return false;
Expand Down
Binary file modified RXInstanceManager/YamlSimpleParser.dll
Binary file not shown.

0 comments on commit 068c3b3

Please sign in to comment.