mirror of
https://github.com/wagesj45/butterflow-ui.git
synced 2024-12-22 01:02:43 -06:00
IsRunning Added
This commit is contained in:
parent
13f2caa6fc
commit
980cb790d4
4 changed files with 103 additions and 13 deletions
|
@ -24,6 +24,8 @@ namespace butterflow_ui
|
|||
private Lazy<string> executablePath = new Lazy<string>(() => Path.Combine(Directory.GetCurrentDirectory(), "ThirdPartyCompiled", "butterflow.exe"));
|
||||
/// <summary> The console output from butterflow. </summary>
|
||||
private string consoleOutput = string.Empty;
|
||||
/// <summary> True if butterflow is running, false if not. </summary>
|
||||
private bool isRunning;
|
||||
/// <summary> Event queue for all listeners interested in ParsedConsoleOutputRecieved events. </summary>
|
||||
public event EventHandler<ButterflowOutputArgs> ParsedConsoleOutputRecieved;
|
||||
|
||||
|
@ -46,6 +48,21 @@ namespace butterflow_ui
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary> Gets or sets a value indicating whether butterflow is currently running. </summary>
|
||||
/// <value> True if butterflow is running, false if not. </value>
|
||||
public bool IsRunning
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.isRunning;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.isRunning = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
@ -71,20 +88,34 @@ namespace butterflow_ui
|
|||
/// <param name="arguments"> Options for controlling the operation. </param>
|
||||
private void Run(string arguments)
|
||||
{
|
||||
var process = new Process();
|
||||
process.StartInfo = new ProcessStartInfo(executablePath.Value, arguments);
|
||||
if (!this.IsRunning)
|
||||
{
|
||||
var process = new Process();
|
||||
process.StartInfo = new ProcessStartInfo(executablePath.Value, arguments);
|
||||
|
||||
process.StartInfo.CreateNoWindow = true;
|
||||
process.StartInfo.UseShellExecute = false;
|
||||
process.StartInfo.RedirectStandardOutput = true;
|
||||
process.StartInfo.RedirectStandardError = true;
|
||||
process.EnableRaisingEvents = true;
|
||||
process.OutputDataReceived += Process_OutputDataReceived;
|
||||
process.ErrorDataReceived += Process_OutputDataReceived;
|
||||
process.StartInfo.CreateNoWindow = true;
|
||||
process.StartInfo.UseShellExecute = false;
|
||||
process.StartInfo.RedirectStandardOutput = true;
|
||||
process.StartInfo.RedirectStandardError = true;
|
||||
process.EnableRaisingEvents = true;
|
||||
process.OutputDataReceived += Process_OutputDataReceived;
|
||||
process.ErrorDataReceived += Process_OutputDataReceived;
|
||||
process.Exited += Process_Exited;
|
||||
|
||||
process.Start();
|
||||
process.BeginOutputReadLine();
|
||||
process.BeginErrorReadLine();
|
||||
process.Start();
|
||||
process.BeginOutputReadLine();
|
||||
process.BeginErrorReadLine();
|
||||
|
||||
this.IsRunning = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary> Event handler. Called by Process for exited events. </summary>
|
||||
/// <param name="sender"> Source of the event. </param>
|
||||
/// <param name="e"> Event information. </param>
|
||||
private void Process_Exited(object sender, EventArgs e)
|
||||
{
|
||||
this.IsRunning = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
57
butterflow-ui/InverseBoolConverter.cs
Normal file
57
butterflow-ui/InverseBoolConverter.cs
Normal file
|
@ -0,0 +1,57 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace butterflow_ui
|
||||
{
|
||||
/// <summary> An inverse boolean converter. </summary>
|
||||
[ValueConversion(typeof(bool), typeof(bool))]
|
||||
public class InverseBoolConverter : IValueConverter
|
||||
{
|
||||
/// <summary> Converts a boolean to its inverse. </summary>
|
||||
/// <exception cref="InvalidCastException"> Thrown when an object cannot be cast to a required
|
||||
/// type. </exception>
|
||||
/// <param name="value"> The value produced by the binding source. </param>
|
||||
/// <param name="targetType"> The type of the binding target property. </param>
|
||||
/// <param name="parameter"> The converter parameter to use. </param>
|
||||
/// <param name="culture"> The culture to use in the converter. </param>
|
||||
/// <returns>
|
||||
/// A converted value. If the method returns <see langword="null" />, the valid null value is
|
||||
/// used.
|
||||
/// </returns>
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if(targetType == typeof(bool))
|
||||
{
|
||||
return !(bool)value;
|
||||
}
|
||||
|
||||
throw new InvalidCastException(string.Format("Cannot convert type {0} to boolean.", targetType.Name));
|
||||
}
|
||||
|
||||
/// <summary> Converts an inverse boolean back to its original state. </summary>
|
||||
/// <exception cref="InvalidCastException"> Thrown when an object cannot be cast to a required
|
||||
/// type. </exception>
|
||||
/// <param name="value"> The value that is produced by the binding target. </param>
|
||||
/// <param name="targetType"> The type to convert to. </param>
|
||||
/// <param name="parameter"> The converter parameter to use. </param>
|
||||
/// <param name="culture"> The culture to use in the converter. </param>
|
||||
/// <returns>
|
||||
/// A converted value. If the method returns <see langword="null" />, the valid null value is
|
||||
/// used.
|
||||
/// </returns>
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (targetType == typeof(bool))
|
||||
{
|
||||
return !(bool)value;
|
||||
}
|
||||
|
||||
throw new InvalidCastException(string.Format("Cannot convert type {0} to boolean.", targetType.Name));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -23,6 +23,7 @@
|
|||
<x:Type TypeName="butterflow_ui:FlowFilterType"/>
|
||||
</ObjectDataProvider.MethodParameters>
|
||||
</ObjectDataProvider>
|
||||
<butterflow_ui:InverseBoolConverter x:Key="InverseBoolConverter" />
|
||||
</Window.Resources>
|
||||
<DockPanel>
|
||||
<Menu DockPanel.Dock="Top">
|
||||
|
@ -102,7 +103,7 @@
|
|||
</Grid>
|
||||
</GroupBox>
|
||||
</StackPanel>
|
||||
<Button Grid.Column="4" Grid.Row="0" Name="btnProcess" ToolTip="{x:Static loc:Localization.ProcessTooltip}" Click="btnProcess_Click">
|
||||
<Button Grid.Column="4" Grid.Row="0" Name="btnProcess" ToolTip="{x:Static loc:Localization.ProcessTooltip}" IsEnabled="{Binding ButterflowWrapper.IsRunning, Mode=OneWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type butterflow_ui:MainWindow}}, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource InverseBoolConverter}}" Click="btnProcess_Click">
|
||||
<StackPanel>
|
||||
<ContentControl MaxWidth="32" HorizontalAlignment="Center" Name="btnRun" Template="{StaticResource RadarIcon}" />
|
||||
<Label Content="{x:Static loc:Localization.ProcessLabel}" />
|
||||
|
|
|
@ -61,6 +61,7 @@
|
|||
<SubType>Designer</SubType>
|
||||
</ApplicationDefinition>
|
||||
<Compile Include="FlowFilterType.cs" />
|
||||
<Compile Include="InverseBoolConverter.cs" />
|
||||
<Compile Include="PropertyChangedAlerter.cs" />
|
||||
<Compile Include="RegionType.cs" />
|
||||
<Page Include="Icons.xaml">
|
||||
|
|
Loading…
Reference in a new issue