Skip to content
Merged
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
71 changes: 36 additions & 35 deletions MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,21 @@
using System.Runtime.InteropServices;
using System.Management.Automation;
using System.Management.Automation.Runspaces;
using System.Management.Automation.Remoting;

namespace AutoDeployTool
{
public partial class MainWindow : Window, INotifyPropertyChanged
{
#region 绑定属性
private string _serverAddress = "localhost";
private string _username;
private SecureString _password;
private string _targetDirectory;
private string _sourceDirectory;
private string? _username;
private SecureString? _password;
private string? _targetDirectory;
private string? _sourceDirectory;
private bool _includeSubdirectories = true;
private string _iisSiteName;
private string _dbConnectionString;
private string? _iisSiteName;
private string? _dbConnectionString;
private SqlExecutionOrder _sqlExecutionOrder = SqlExecutionOrder.Sequential;
private bool _performFileDeployment = true;
private bool _performSqlExecution = true;
Expand All @@ -59,25 +60,25 @@
set { _serverAddress = value; OnPropertyChanged(); }
}

public string Username
public string? Username
{
get => _username;
set { _username = value; OnPropertyChanged(); }
}

public SecureString Password
public SecureString? Password
{
get => _password;
set { _password = value; OnPropertyChanged(); }
}

public string TargetDirectory
public string? TargetDirectory
{
get => _targetDirectory;
set { _targetDirectory = value; OnPropertyChanged(); }
}

public string SourceDirectory
public string? SourceDirectory
{
get => _sourceDirectory;
set { _sourceDirectory = value; OnPropertyChanged(); }
Expand All @@ -89,13 +90,13 @@
set { _includeSubdirectories = value; OnPropertyChanged(); }
}

public string IisSiteName
public string? IisSiteName
{
get => _iisSiteName;
set { _iisSiteName = value; OnPropertyChanged(); }
}

public string DbConnectionString
public string? DbConnectionString
{
get => _dbConnectionString;
set { _dbConnectionString = value; OnPropertyChanged(); }
Expand Down Expand Up @@ -186,7 +187,7 @@
}
#endregion

public MainWindow()

Check warning on line 190 in MainWindow.xaml.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field '_cancellationTokenSource' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.

Check warning on line 190 in MainWindow.xaml.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field '_cancellationTokenSource' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.
{
InitializeComponent();
DataContext = this;
Expand All @@ -198,7 +199,7 @@
#region 事件处理
private void PasswordBox_PasswordChanged(object sender, RoutedEventArgs e)
{
Password = (sender as System.Windows.Controls.PasswordBox).SecurePassword;

Check warning on line 202 in MainWindow.xaml.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.

Check warning on line 202 in MainWindow.xaml.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.
}

private void BrowseTargetDirectory_Click(object sender, RoutedEventArgs e)
Expand Down Expand Up @@ -1413,7 +1414,7 @@
}
}

private string SecureStringToString(SecureString secureString)
private string? SecureStringToString(SecureString? secureString)
{
if (secureString == null) return null;

Expand All @@ -1429,7 +1430,7 @@
}
}

private SecureString StringToSecureString(string plainString)
private SecureString? StringToSecureString(string? plainString)
{
if (string.IsNullOrWhiteSpace(plainString)) return null;

Expand Down Expand Up @@ -1486,9 +1487,9 @@
new PSCredential(Username, Password)
);

// 设置连接超时和操作超时
connectionInfo.OperationTimeout = TimeSpan.FromMinutes(2);
connectionInfo.OpenTimeout = TimeSpan.FromSeconds(30);
// 设置连接超时和操作超时 (以毫秒为单位)
connectionInfo.OperationTimeout = (int)TimeSpan.FromMinutes(2).TotalMilliseconds;
connectionInfo.OpenTimeout = (int)TimeSpan.FromSeconds(30).TotalMilliseconds;

using (var runspace = RunspaceFactory.CreateRunspace(connectionInfo))
{
Expand Down Expand Up @@ -1544,9 +1545,9 @@
#endregion

#region INotifyPropertyChanged 实现
public event PropertyChangedEventHandler PropertyChanged;
public event PropertyChangedEventHandler? PropertyChanged;

protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
Expand All @@ -1556,35 +1557,35 @@
#region 数据模型
public class FileReplaceRule : INotifyPropertyChanged
{
private string _sourcePattern;
private string _targetPath;
private string? _sourcePattern;
private string? _targetPath;

public string SourcePattern
public string? SourcePattern
{
get => _sourcePattern;
set { _sourcePattern = value; OnPropertyChanged(); }
}

public string TargetPath
public string? TargetPath
{
get => _targetPath;
set { _targetPath = value; OnPropertyChanged(); }
}

public event PropertyChangedEventHandler PropertyChanged;
public event PropertyChangedEventHandler? PropertyChanged;

protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}

public class SqlScript : INotifyPropertyChanged
{
private string _scriptPath;
private string? _scriptPath;
private bool _continueOnError = true;

public string ScriptPath
public string? ScriptPath
{
get => _scriptPath;
set { _scriptPath = value; OnPropertyChanged(); }
Expand All @@ -1596,29 +1597,29 @@
set { _continueOnError = value; OnPropertyChanged(); }
}

public event PropertyChangedEventHandler PropertyChanged;
public event PropertyChangedEventHandler? PropertyChanged;

protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}

public class WindowsService : INotifyPropertyChanged
{
private string _serviceName;
private string _servicePath;
private string? _serviceName;
private string? _servicePath;
private bool _stopBeforeDeploy = true;
private bool _startAfterDeploy = true;
private bool _updateService = true;

public string ServiceName
public string? ServiceName
{
get => _serviceName;
set { _serviceName = value; OnPropertyChanged(); }
}

public string ServicePath
public string? ServicePath
{
get => _servicePath;
set { _servicePath = value; OnPropertyChanged(); }
Expand All @@ -1642,9 +1643,9 @@
set { _updateService = value; OnPropertyChanged(); }
}

public event PropertyChangedEventHandler PropertyChanged;
public event PropertyChangedEventHandler? PropertyChanged;

protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
Expand All @@ -1653,14 +1654,14 @@
[XmlRoot("DeploymentConfiguration")]
public class DeploymentConfiguration
{
public string ServerAddress { get; set; }

Check warning on line 1657 in MainWindow.xaml.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'ServerAddress' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 1657 in MainWindow.xaml.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'ServerAddress' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
public string Username { get; set; }

Check warning on line 1658 in MainWindow.xaml.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Username' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 1658 in MainWindow.xaml.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Username' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
public string Password { get; set; }

Check warning on line 1659 in MainWindow.xaml.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Password' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 1659 in MainWindow.xaml.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Password' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
public string TargetDirectory { get; set; }

Check warning on line 1660 in MainWindow.xaml.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'TargetDirectory' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 1660 in MainWindow.xaml.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'TargetDirectory' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
public string SourceDirectory { get; set; }

Check warning on line 1661 in MainWindow.xaml.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'SourceDirectory' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 1661 in MainWindow.xaml.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'SourceDirectory' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
public bool IncludeSubdirectories { get; set; }
public string IisSiteName { get; set; }

Check warning on line 1663 in MainWindow.xaml.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'IisSiteName' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 1663 in MainWindow.xaml.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'IisSiteName' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
public string DbConnectionString { get; set; }

Check warning on line 1664 in MainWindow.xaml.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'DbConnectionString' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 1664 in MainWindow.xaml.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'DbConnectionString' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
public SqlExecutionOrder SqlExecutionOrder { get; set; }
public bool PerformFileDeployment { get; set; }
public bool PerformSqlExecution { get; set; }
Expand Down Expand Up @@ -1693,7 +1694,7 @@

public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return (bool)value ? Enum.Parse(targetType, parameter?.ToString()) : System.Windows.Data.Binding.DoNothing;

Check warning on line 1697 in MainWindow.xaml.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'value' in 'object Enum.Parse(Type enumType, string value)'.

Check warning on line 1697 in MainWindow.xaml.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'value' in 'object Enum.Parse(Type enumType, string value)'.
}
}
#endregion
Expand Down
Loading