Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: асинхронная работа с меню #4

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions RXInstanceManager/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public static class InstanceStatus
public const string Stopped = "Stopped";
public const string NeedInstall = "NeedInstall";
public const string NotInstalled = "Not installed";
public const string Update = "Update";
}

public static class EditEmptyValue
Expand Down
4 changes: 2 additions & 2 deletions RXInstanceManager/Dialogs/Dialogs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ public static string ShowEnterValueDialog(string emptyValue, string defaultValue
return dialog.Value;
}

public static void ShowInformationDialog(string information)
public static void ShowInformation(string information)
{
var dialog = new InformationDialog();
dialog.Value = information;
dialog.ShowDialog();
dialog.Show();
}
public static void ShowFileContentDialog(string path)
{
Expand Down
18 changes: 12 additions & 6 deletions RXInstanceManager/Entities/Controllers/Instances.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,29 @@ public static void Add(string instancePath)
{
if (!Instances.instancesFolders.Where(i => i == instancePath).Any())
{
Instances.instances.Add(new Instance(instancePath));
Instances.instancesFolders.Add(instancePath);
UpdateYaml();
}
}

public static List<Instance> Get()
{
Instances.instances = new List<Instance>();
foreach (var folder in Instances.instancesFolders)
Instances.instances.Add(new Instance(folder));
return Instances.instances;
if (instances == null)
{
instances = new List<Instance>();
foreach (var folder in instancesFolders)
instances.Add(new Instance(folder));
}

return instances;
}

public static void Delete(Instance instance)
{
var idx = Instances.instancesFolders.FindIndex(i => i == instance.InstancePath);
Instances.instancesFolders.RemoveAt(idx);
var index = Instances.instancesFolders.FindIndex(i => i == instance.InstancePath);
Instances.instances.RemoveAt(index);
Instances.instancesFolders.RemoveAt(index);
UpdateYaml();
}

Expand Down
12 changes: 6 additions & 6 deletions RXInstanceManager/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal" Height="40" Grid.Row="0">
<Button x:Name="ButtonAdd" Content="Добавить" Style="{DynamicResource RecordActionButton}" Margin="10,5,5,5" Background="SkyBlue" Click="ButtonAdd_Click" />
<Button x:Name="ButtonStart" Content="do all up" Style="{DynamicResource RecordActionButton}" Background="SteelBlue" Click="ButtonStart_Click" />
<Button x:Name="ButtonStop" Content="do all down" Style="{DynamicResource RecordActionButton}" Background="SteelBlue" Click="ButtonStop_Click" />
<Button x:Name="ButtonStart" Content="do all up" Style="{DynamicResource RecordActionButton}" Background="SteelBlue" Click="ButtonStart_ClickAsync" />
<Button x:Name="ButtonStop" Content="do all down" Style="{DynamicResource RecordActionButton}" Background="SteelBlue" Click="ButtonStop_ClickAsync" />
<Button x:Name="ButtonDDSStart" Content="Development Studio" Style="{DynamicResource RecordActionButton}" Background="GreenYellow" Click="ButtonDDSStart_Click" />
<Button x:Name="ButtonRXStart" Content="Веб-клиент" Style="{DynamicResource RecordActionButton}" Background="Violet" Click="ButtonRXStart_Click" />
<Button x:Name="ButtonLogViewer" Content="Directum LogViewer" Style="{DynamicResource RecordActionButton}" Background="Gray" Click="RunDirectumLogViewer_Click" />
Expand All @@ -57,22 +57,22 @@
</DataGrid.Columns>
<DataGrid.ContextMenu>
<ContextMenu x:Name="InstancesContextMenu">
<MenuItem x:Name="ChangeProject" Header="Сменить проект" Click="ChangeProject_Click" />
<MenuItem x:Name="CreateProject" Header="Создать проект" Click="CreateProject_Click" />
<MenuItem x:Name="ChangeProject" Header="Сменить проект" Click="ChangeProject_ClickAsync" />
<MenuItem x:Name="CreateProject" Header="Создать проект" Click="CreateProject_ClickAsync" />
<MenuItem x:Name="CloneProject" Header="Создать копию текущего проекта" Click="CloneProject_Click" />
<MenuItem x:Name="UpdateConfig" Header="Пропатчить config.yml" Click="UpdateConfig_Click" />
<MenuItem x:Name="CheckServices" Header="Проверить сервисы" Click="CheckServices_Click" />
<MenuItem x:Name="RunDDSWithOutDeploy" Header="Открыть DDS без deploy" Click="RunDDSWithOutDeploy_Click" />
<MenuItem x:Name="InfoContext" Header="Сводка по инстансу" Click="InfoContext_Click" />
<MenuItem x:Name="CmdAdminContext" Header="Запустить cmd (от администратора)" Click="CmdAdminContext_Click" />
<MenuItem x:Name="CmdAdminContext" Header="Запустить cmd (от администратора)" Icon="🖥️" Click="CmdAdminContext_Click" />
<MenuItem x:Name="ClearLogContext" Header="Очистить логи текущего экземпляра RX" Click="ClearLogContext_Click" />
<MenuItem x:Name="ClearLogAllInstancesContext" Header="Очистить логи всех экземпляров RX" Click="ClearLogAllInstancesContext_Click" />
<MenuItem x:Name="ConfigContext" Header="Открыть config.yml" Click="ConfigContext_Click" />
<MenuItem x:Name="ProjectConfigContext" Header="Открыть конфиг проекта" Click="ProjectConfigContext_Click" />
<MenuItem x:Name="ConvertDBsContext" Header="Конвертировать БД проектов" Click="ConvertDBsContext_Click" />
<MenuItem x:Name="RemoveProjectDataContext" Header="Удалить БД и домашний каталог выбранного проекта" Click="RemoveProjectDataContext_Click" />
<MenuItem x:Name="RemoveInstance" Header="Убрать экземпляр RX из списка" Click="RemoveInstance_Click" />
<MenuItem x:Name="OpenRXFolder" Header="Открыть папку экземпляра RX" Click="OpenRXFolder_Click" />
<MenuItem x:Name="OpenRXFolder" Header="Открыть папку экземпляра RX" Icon="📁" Click="OpenRXFolder_Click" />
<MenuItem x:Name="OpenLogFolder" Header="Открыть папку логов" Click="OpenLogFolder_Click" />
</ContextMenu>
</DataGrid.ContextMenu>
Expand Down
104 changes: 69 additions & 35 deletions RXInstanceManager/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,19 @@ public MainWindow()
LoadConfig();
LoadInstances();
ActionButtonVisibleChanging();
StartAsyncHandlers();
m_notifyIcon = new System.Windows.Forms.NotifyIcon();
m_notifyIcon.BalloonTipText = "The app has been minimised. Click the tray icon to show.";
m_notifyIcon.BalloonTipTitle = "RXInstanceManager";
m_notifyIcon.Text = "RXInstanceManager";
m_notifyIcon.Icon = new System.Drawing.Icon("App.ico");
m_notifyIcon.Click += new EventHandler(m_notifyIcon_Click);
TrayStatus();
Loaded += MainWindow_Loaded;
}

private void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
StartAsyncHandlers();
}

private void GridInstances_SelectionChanged(object sender, SelectionChangedEventArgs e)
Expand All @@ -95,41 +100,53 @@ private void GridInstances_SelectionChanged(object sender, SelectionChangedEvent

#region ActionHandlers

private void ButtonStart_Click(object sender, RoutedEventArgs e)
private async void ButtonStart_ClickAsync(object sender, RoutedEventArgs e)
{
AppHandlers.InfoHandler(_instance, MethodBase.GetCurrentMethod().Name);
var instance = _instance;
AppHandlers.InfoHandler(instance, MethodBase.GetCurrentMethod().Name);

if (_instance == null)
if (instance == null)
return;

try
{
var serviceStatus = AppHandlers.GetServiceStatus(_instance);
var serviceStatus = AppHandlers.GetServiceStatus(instance);
if (serviceStatus == Constants.InstanceStatus.Stopped)
AppHandlers.LaunchProcess(AppHelper.GetDoPath(_instance.InstancePath), "all up", true, true);
{
ChangeGridStatus(instance, Constants.InstanceStatus.Update);
await Task.Run(() => AppHandlers.LaunchProcess(AppHelper.GetDoPath(instance.InstancePath), "all up", true, true));
ChangeGridStatus(instance, Constants.InstanceStatus.Working);
}
}
catch (Exception ex)
{
AppHandlers.ErrorHandler(_instance, ex);
ChangeGridStatus(instance, Constants.InstanceStatus.Stopped);
AppHandlers.ErrorHandler(instance, ex);
}
}

private void ButtonStop_Click(object sender, RoutedEventArgs e)
private async void ButtonStop_ClickAsync(object sender, RoutedEventArgs e)
{
AppHandlers.InfoHandler(_instance, MethodBase.GetCurrentMethod().Name);
var instance = _instance;
AppHandlers.InfoHandler(instance, MethodBase.GetCurrentMethod().Name);

if (_instance == null || _instance.Status != Constants.InstanceStatus.Working)
if (instance == null || instance.Status != Constants.InstanceStatus.Working)
return;

try
{
var serviceStatus = AppHandlers.GetServiceStatus(_instance);
var serviceStatus = AppHandlers.GetServiceStatus(instance);
if (serviceStatus == Constants.InstanceStatus.Working)
AppHandlers.LaunchProcess(AppHelper.GetDoPath(_instance.InstancePath), "all down", true, true);
{
ChangeGridStatus(instance, Constants.InstanceStatus.Update);
await Task.Run(() => AppHandlers.LaunchProcess(AppHelper.GetDoPath(instance.InstancePath), "all down", true, true));
ChangeGridStatus(instance, Constants.InstanceStatus.Stopped);
}
}
catch (Exception ex)
{
AppHandlers.ErrorHandler(_instance, ex);
ChangeGridStatus(instance, Constants.InstanceStatus.Stopped);
AppHandlers.ErrorHandler(instance, ex);
}
}

Expand Down Expand Up @@ -222,14 +239,15 @@ private void ProjectConfigContext_Click(object sender, RoutedEventArgs e)
}
}

private void ChangeProject_Click(object sender, RoutedEventArgs e)
private async void ChangeProject_ClickAsync(object sender, RoutedEventArgs e)
{
AppHandlers.InfoHandler(_instance, MethodBase.GetCurrentMethod().Name);
var instance = _instance;
AppHandlers.InfoHandler(instance, MethodBase.GetCurrentMethod().Name);
using (System.Windows.Forms.OpenFileDialog openFileDialog = new System.Windows.Forms.OpenFileDialog())
{
var filter = string.Format("configs for {0}|{0}_*.yml;{0}_*.yaml|YAML-файлы|*.yml;*.yaml|All files (*.*)|*.*", _instance.Code);
if (!string.IsNullOrEmpty(_instance.ProjectConfigPath))
openFileDialog.InitialDirectory = Path.GetDirectoryName(_instance.ProjectConfigPath);
var filter = string.Format("configs for {0}|{0}_*.yml;{0}_*.yaml|YAML-файлы|*.yml;*.yaml|All files (*.*)|*.*", instance.Code);
if (!string.IsNullOrEmpty(instance.ProjectConfigPath))
openFileDialog.InitialDirectory = Path.GetDirectoryName(instance.ProjectConfigPath);
openFileDialog.Filter = filter;
openFileDialog.FilterIndex = 1;
openFileDialog.RestoreDirectory = true;
Expand All @@ -242,24 +260,33 @@ private void ChangeProject_Click(object sender, RoutedEventArgs e)
string needCheck = "False";
if (_configRxInstMan.NeedCheckAfterSet)
needCheck = "True";
AppHandlers.LaunchProcess(AppHelper.GetDoPath(_instance.InstancePath), string.Format("map set {0} -rundds=False -need_pause -need_check={1}", config_filename, needCheck), true, true);

var lastStatus = instance.Status;
ChangeGridStatus(instance, Constants.InstanceStatus.Update);
await Task.Run(() => AppHandlers.LaunchProcess(AppHelper.GetDoPath(instance.InstancePath),
string.Format("map set {0} -rundds=False -need_pause -need_check={1}", config_filename, needCheck),
true,
true));
ChangeGridStatus(instance, lastStatus);
}
catch (Exception ex)
{
AppHandlers.ErrorHandler(_instance, ex);
ChangeGridStatus(instance, Constants.InstanceStatus.Stopped);
AppHandlers.ErrorHandler(instance, ex);
}

}
}
}

private void CreateProject_Click(object sender, RoutedEventArgs e)
private async void CreateProject_ClickAsync(object sender, RoutedEventArgs e)
{
AppHandlers.InfoHandler(_instance, MethodBase.GetCurrentMethod().Name);
var instance = _instance;
AppHandlers.InfoHandler(instance, MethodBase.GetCurrentMethod().Name);
using (System.Windows.Forms.OpenFileDialog openFileDialog = new System.Windows.Forms.OpenFileDialog())
{
var filter = string.Format("configs for {0}|{0}_*.yml;{0}_*.yaml|YAML-файлы|*.yml;*.yaml|All files (*.*)|*.*", _instance.Code);
openFileDialog.InitialDirectory = string.IsNullOrEmpty(_instance.ProjectConfigPath) ? "C:\\" : Path.GetDirectoryName(_instance.ProjectConfigPath);
var filter = string.Format("configs for {0}|{0}_*.yml;{0}_*.yaml|YAML-файлы|*.yml;*.yaml|All files (*.*)|*.*", instance.Code);
openFileDialog.InitialDirectory = string.IsNullOrEmpty(instance.ProjectConfigPath) ? "C:\\" : Path.GetDirectoryName(_instance.ProjectConfigPath);
openFileDialog.Filter = filter;
openFileDialog.FilterIndex = 1;
openFileDialog.RestoreDirectory = true;
Expand All @@ -269,14 +296,17 @@ private void CreateProject_Click(object sender, RoutedEventArgs e)
var config_filename = openFileDialog.FileName;
try
{
AppHandlers.LaunchProcess("cmd",
string.Format("cmd /K {1} map create_project {0} -rundds=False -need_pause",
config_filename, AppHelper.GetDoPath(_instance.InstancePath)),
true, true);
ChangeGridStatus(instance, Constants.InstanceStatus.Update);
await Task.Run(() => AppHandlers.LaunchProcess("cmd",
string.Format("cmd /K {1} map create_project {0} -rundds=False -need_pause",
config_filename, AppHelper.GetDoPath(instance.InstancePath)),
true, true));
ChangeGridStatus(instance, Constants.InstanceStatus.Working);
}
catch (Exception ex)
{
AppHandlers.ErrorHandler(_instance, ex);
ChangeGridStatus(instance, Constants.InstanceStatus.Stopped);
AppHandlers.ErrorHandler(instance, ex);
}

}
Expand Down Expand Up @@ -377,18 +407,15 @@ private void InfoContext_Click(object sender, RoutedEventArgs e)
if (_instance == null)
return;

Dialogs.ShowInformationDialog(_instance.ToString());
Dialogs.ShowInformation(_instance.ToString());
}

#endregion

private void StartAsyncHandlers()
{
#pragma warning disable CS4014
// Так как этот вызов не ожидается, выполнение существующего метода продолжается до тех пор, пока вызов не будет завершен
UpdateInstanceGridAsync();
UpdateInstanceDataAsync();
#pragma warning restore CS4014
_ = UpdateInstanceGridAsync();
_ = UpdateInstanceDataAsync();
}

private void HiddenButton_Click(object sender, RoutedEventArgs e)
Expand Down Expand Up @@ -636,5 +663,12 @@ private void OpenLogFolder_Click(object sender, RoutedEventArgs e)
else
System.Windows.MessageBox.Show($"Папка {_instance.LogFolder} не существует.", "", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error);
}

private void ChangeGridStatus(Instance instance, string status)
{
instance.Status = status;
ActionButtonVisibleChanging(instance: instance);
LoadInstances(instance.InstancePath);
}
}
}
12 changes: 10 additions & 2 deletions RXInstanceManager/MainWindowAsyncHandlers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,15 @@ private async Task UpdateInstanceGridAsync()
{
if (!string.IsNullOrEmpty(instance.Code))
{
if (instance.Status == Constants.InstanceStatus.Update)
continue;

var status = AppHandlers.GetServiceStatus(instance);
if (status != instance.Status)
LoadInstances(_instance.InstancePath);
{
instance.Status = status;
LoadInstances(instance.InstancePath);
}
}
}
}
Expand Down Expand Up @@ -92,7 +98,9 @@ private async Task UpdateInstanceDataAsync()
}
}
}
instance.Status = AppHandlers.GetServiceStatus(instance);
if (instance.Status != Constants.InstanceStatus.Update)
instance.Status = AppHandlers.GetServiceStatus(instance);

instance.ConfigChanged = changeTime;

LoadInstances(_instance.InstancePath);
Expand Down
Loading