This commit is contained in:
Wiesław Šoltés 2022-02-04 22:46:11 +01:00
Родитель 57de07eab5
Коммит 29ecba8fef
13 изменённых файлов: 210 добавлений и 135 удалений

Просмотреть файл

@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.28315.86
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PackageReferenceEditor.Avalonia", "src\PackageReferenceEditor.Avalonia\PackageReferenceEditor.Avalonia.csproj", "{C53DAAF8-7153-4B1D-8B68-A16F91AAB835}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PackageReferenceEditor.Base", "src\PackageReferenceEditor.Base\PackageReferenceEditor.Base.csproj", "{C53DAAF8-7153-4B1D-8B68-A16F91AAB835}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PackageReferenceEditor", "src\PackageReferenceEditor\PackageReferenceEditor.csproj", "{71EE73A0-FE62-4978-8F0D-140A8A72A1F1}"
EndProject
@ -56,6 +56,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{38368485
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PackageReferenceEditor.UnitTests", "tests\PackageReferenceEditor.UnitTests\PackageReferenceEditor.UnitTests.csproj", "{FCEA0F49-77EE-408F-A319-EFDDD3F9A9DD}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PackageReferenceEditor.Desktop", "src\PackageReferenceEditor.Desktop\PackageReferenceEditor.Desktop.csproj", "{C86BF319-6F07-4ADD-B912-AF96267A8491}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -78,6 +80,10 @@ Global
{FCEA0F49-77EE-408F-A319-EFDDD3F9A9DD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FCEA0F49-77EE-408F-A319-EFDDD3F9A9DD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FCEA0F49-77EE-408F-A319-EFDDD3F9A9DD}.Release|Any CPU.Build.0 = Release|Any CPU
{C86BF319-6F07-4ADD-B912-AF96267A8491}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C86BF319-6F07-4ADD-B912-AF96267A8491}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C86BF319-6F07-4ADD-B912-AF96267A8491}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C86BF319-6F07-4ADD-B912-AF96267A8491}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -90,6 +96,7 @@ Global
{B8ACA4FA-8593-4605-AE54-E047FB91C176} = {49F71003-4C84-42F3-A10A-6E2CA97DA1DB}
{41CB9D2A-BCCC-4227-A9B9-6757FDD0E0B6} = {49F71003-4C84-42F3-A10A-6E2CA97DA1DB}
{FCEA0F49-77EE-408F-A319-EFDDD3F9A9DD} = {38368485-AFBE-481D-9D39-CF7319AD5934}
{C86BF319-6F07-4ADD-B912-AF96267A8491} = {5B7FC42E-07EA-474F-8B8C-DAD199066922}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {33B60D57-896D-43D2-A23B-244BADB28D81}

Просмотреть файл

@ -12,7 +12,7 @@ variables:
BuildConfiguration: 'Release'
BuildPlatform: 'Any CPU'
PublishFramework: 'net6.0'
PublishProject: 'PackageReferenceEditor.Avalonia'
PublishProject: 'PackageReferenceEditor.Desktop'
PublishRuntime: ''
jobs:

Просмотреть файл

@ -1,124 +0,0 @@
using System;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Xml;
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;
using Newtonsoft.Json;
namespace PackageReferenceEditor.Avalonia
{
public class App : Application
{
static void Main(string[] args)
{
BuildAvaloniaApp().StartWithClassicDesktopLifetime(args);
}
public static AppBuilder BuildAvaloniaApp()
=> AppBuilder.Configure<App>()
.UsePlatformDetect()
.LogToTrace();
public override void Initialize()
{
AvaloniaXamlLoader.Load(this);
}
public override void OnFrameworkInitializationCompleted()
{
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktopLifetime)
{
var jsonSettings = new JsonSerializerSettings()
{
PreserveReferencesHandling = PreserveReferencesHandling.Objects
};
string settingPath = "settings.json";
ReferenceEditor? editor = default;
try
{
if (File.Exists(settingPath))
{
string json = File.ReadAllText(settingPath);
editor = JsonConvert.DeserializeObject<ReferenceEditor>(json, jsonSettings);
}
}
catch (Exception ex)
{
Logger.Log(ex.Message);
if (ex.StackTrace != null)
{
Logger.Log(ex.StackTrace);
}
}
if (editor == null)
{
var feeds = new ObservableCollection<Feed>
{
new Feed("api.nuget.org", "https://api.nuget.org/v3/index.json"),
new Feed("dotnet-core", "https://dotnet.myget.org/F/dotnet-core/api/v3/index.json"),
new Feed("avalonia-ci", "https://www.myget.org/F/avalonia-ci/api/v3/index.json"),
new Feed("avalonia-prs", "https://www.myget.org/F/avalonia-prs/api/v3/index.json"),
new Feed("xamlbehaviors-nightly", "https://www.myget.org/F/xamlbehaviors-nightly/api/v3/index.json"),
new Feed("panandzoom-nightly", "https://www.myget.org/F/panandzoom-nightly/api/v3/index.json"),
new Feed("dock-nightly", "https://www.myget.org/F/dock-nightly/api/v3/index.json"),
new Feed("portable-xaml", "https://ci.appveyor.com/nuget/portable-xaml")
};
var patterns = new ObservableCollection<string>
{
"*.props",
"*.csproj"
};
editor = new ReferenceEditor()
{
Feeds = feeds,
CurrentFeed = feeds.FirstOrDefault(),
SearchPath = @"C:\DOWNLOADS\GitHub",
SearchPatterns = patterns,
SearchPattern = patterns.FirstOrDefault(),
AlwaysUpdate = false
};
}
editor.Result = new UpdaterResult()
{
Documents = new ObservableCollection<XmlDocument>(),
References = new ObservableCollection<PackageReference>()
};
desktopLifetime.MainWindow = new MainWindow()
{
DataContext = editor
};
desktopLifetime.Exit += (sennder, e) =>
{
try
{
var json = JsonConvert.SerializeObject(editor, Newtonsoft.Json.Formatting.Indented, jsonSettings);
File.WriteAllText(settingPath, json);
}
catch (Exception ex)
{
Logger.Log(ex.Message);
if (ex.StackTrace != null)
{
Logger.Log(ex.StackTrace);
}
}
};
}
else if (ApplicationLifetime is ISingleViewApplicationLifetime singleViewLifetime)
{
//singleViewLifetime.MainView = new MainView();
}
base.OnFrameworkInitializationCompleted();
}
}
}

Просмотреть файл

@ -0,0 +1,132 @@
using System;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Xml;
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;
using Newtonsoft.Json;
using PackageReferenceEditor.Avalonia.Views;
namespace PackageReferenceEditor.Avalonia
{
public class App : Application
{
private readonly string _settingPath = "settings.json";
private readonly JsonSerializerSettings _jsonSettings = new()
{
PreserveReferencesHandling = PreserveReferencesHandling.Objects
};
public override void Initialize()
{
AvaloniaXamlLoader.Load(this);
}
public override void OnFrameworkInitializationCompleted()
{
var editor = Open();
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktopLifetime)
{
desktopLifetime.MainWindow = new MainWindow
{
DataContext = editor
};
desktopLifetime.Exit += (_, _) =>
{
Save(editor);
};
}
else if (ApplicationLifetime is ISingleViewApplicationLifetime singleViewLifetime)
{
singleViewLifetime.MainView = new MainView
{
DataContext = editor
};
}
base.OnFrameworkInitializationCompleted();
}
private ReferenceEditor Open()
{
ReferenceEditor? editor = default;
try
{
if (File.Exists(_settingPath))
{
string json = File.ReadAllText(_settingPath);
editor = JsonConvert.DeserializeObject<ReferenceEditor>(json, _jsonSettings);
}
}
catch (Exception ex)
{
Logger.Log(ex.Message);
if (ex.StackTrace != null)
{
Logger.Log(ex.StackTrace);
}
}
if (editor == null)
{
var feeds = new ObservableCollection<Feed>
{
new Feed("api.nuget.org", "https://api.nuget.org/v3/index.json"),
new Feed("dotnet-core", "https://dotnet.myget.org/F/dotnet-core/api/v3/index.json"),
new Feed("avalonia-ci", "https://www.myget.org/F/avalonia-ci/api/v3/index.json"),
new Feed("avalonia-prs", "https://www.myget.org/F/avalonia-prs/api/v3/index.json"),
new Feed("xamlbehaviors-nightly", "https://www.myget.org/F/xamlbehaviors-nightly/api/v3/index.json"),
new Feed("panandzoom-nightly", "https://www.myget.org/F/panandzoom-nightly/api/v3/index.json"),
new Feed("dock-nightly", "https://www.myget.org/F/dock-nightly/api/v3/index.json"),
new Feed("portable-xaml", "https://ci.appveyor.com/nuget/portable-xaml")
};
var patterns = new ObservableCollection<string>
{
"*.props",
"*.csproj"
};
editor = new ReferenceEditor()
{
Feeds = feeds,
CurrentFeed = feeds.FirstOrDefault(),
SearchPath = @"C:\DOWNLOADS\GitHub",
SearchPatterns = patterns,
SearchPattern = patterns.FirstOrDefault(),
AlwaysUpdate = false
};
}
editor.Result = new UpdaterResult()
{
Documents = new ObservableCollection<XmlDocument>(),
References = new ObservableCollection<PackageReference>()
};
return editor;
}
private void Save(ReferenceEditor editor)
{
try
{
var json = JsonConvert.SerializeObject(editor, Newtonsoft.Json.Formatting.Indented, _jsonSettings);
File.WriteAllText(_settingPath, json);
}
catch (Exception ex)
{
Logger.Log(ex.Message);
if (ex.StackTrace != null)
{
Logger.Log(ex.StackTrace);
}
}
}
}
}

Просмотреть файл

@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<OutputType>Library</OutputType>
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
<IsPackable>False</IsPackable>
<Nullable>enable</Nullable>
<RootNamespace>PackageReferenceEditor.Avalonia</RootNamespace>
</PropertyGroup>
<PropertyGroup>
<Description>MSBuild, csproj and props package reference editor.</Description>
</PropertyGroup>
<Import Project="..\..\build\Base.props" />
<Import Project="..\..\build\ReferenceAssemblies.props" />
<Import Project="..\..\build\Avalonia.props" />
<Import Project="..\..\build\Avalonia.Diagnostics.props" />
<Import Project="..\..\build\Avalonia.Desktop.props" />
<Import Project="..\..\build\Newtonsoft.Json.props" />
<ItemGroup>
<ProjectReference Include="..\PackageReferenceEditor\PackageReferenceEditor.csproj" />
</ItemGroup>
</Project>

Просмотреть файл

@ -0,0 +1,17 @@
using Avalonia;
namespace PackageReferenceEditor.Avalonia
{
class Program
{
static void Main(string[] args)
{
BuildAvaloniaApp().StartWithClassicDesktopLifetime(args);
}
public static AppBuilder BuildAvaloniaApp()
=> AppBuilder.Configure<App>()
.UsePlatformDetect()
.LogToTrace();
}
}

Просмотреть файл

@ -1,7 +1,7 @@
<Window x:Class="PackageReferenceEditor.Avalonia.MainWindow"
<Window x:Class="PackageReferenceEditor.Avalonia.Views.MainWindow"
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:views="clr-namespace:PackageReferenceEditor.Avalonia.Views;assembly=PackageReferenceEditor.Avalonia"
xmlns:views="clr-namespace:PackageReferenceEditor.Avalonia.Views;assembly=PackageReferenceEditor.Base"
UseLayoutRounding="True" RenderOptions.BitmapInterpolationMode="HighQuality"
WindowState="Normal" WindowStartupLocation="CenterScreen"
Title="PackageReferenceEditor" Height="600" Width="800">

Просмотреть файл

@ -2,14 +2,16 @@
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
namespace PackageReferenceEditor.Avalonia
namespace PackageReferenceEditor.Avalonia.Views
{
public partial class MainWindow : Window
{
public MainWindow()
{
this.InitializeComponent();
#if DEBUG
this.AttachDevTools();
#endif
}
private void InitializeComponent()

Просмотреть файл

@ -4,9 +4,9 @@
<TargetFramework>net6.0</TargetFramework>
<OutputType>WinExe</OutputType>
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
<EnableDefaultCompileItems>False</EnableDefaultCompileItems>
<IsPackable>False</IsPackable>
<Nullable>enable</Nullable>
<RootNamespace>PackageReferenceEditor.Desktop</RootNamespace>
</PropertyGroup>
<PropertyGroup>
@ -24,13 +24,9 @@
<Import Project="..\..\build\Avalonia.props" />
<Import Project="..\..\build\Avalonia.Diagnostics.props" />
<Import Project="..\..\build\Avalonia.Desktop.props" />
<Import Project="..\..\build\Newtonsoft.Json.props" />
<ItemGroup>
<Compile Include="**\*.cs" Exclude="obj\**" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\PackageReferenceEditor.Base\PackageReferenceEditor.Base.csproj" />
<ProjectReference Include="..\PackageReferenceEditor\PackageReferenceEditor.csproj" />
</ItemGroup>

Просмотреть файл

@ -0,0 +1,18 @@
using Avalonia;
using PackageReferenceEditor.Avalonia;
namespace PackageReferenceEditor.Desktop
{
class Program
{
static void Main(string[] args)
{
BuildAvaloniaApp().StartWithClassicDesktopLifetime(args);
}
public static AppBuilder BuildAvaloniaApp()
=> AppBuilder.Configure<App>()
.UsePlatformDetect()
.LogToTrace();
}
}