Skip to content

Commit

Permalink
新增 情景终止
Browse files Browse the repository at this point in the history
新增 搜索框添加便签
  • Loading branch information
MakesYT committed Oct 11, 2023
1 parent d7bbb63 commit 617cf46
Show file tree
Hide file tree
Showing 9 changed files with 156 additions and 20 deletions.
69 changes: 50 additions & 19 deletions Core/SDKs/CustomScenario/CustomScenario.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ [JsonIgnore] [ObservableProperty] [NotifyPropertyChangedRecipients]
[JsonIgnore] [ObservableProperty] [NotifyPropertyChangedRecipients]
private List<CustomScenarioInvoke> _autoTriggerType = new();

private readonly Dictionary<PointItem, Task?> _tasks = new();
private readonly Dictionary<PointItem, Thread?> _tasks = new();

public void Run(bool realTime = false)
{
Expand All @@ -80,8 +80,7 @@ private void StartRun(bool notRealTime)

foreach (var task in _tasks)
{
//TODO:
//task.Dispose();
task.Value?.Interrupt();
}

_tasks.Clear();
Expand Down Expand Up @@ -148,7 +147,12 @@ private void StartRun(bool notRealTime)
var f = true;
foreach (var (_, value) in _tasks)
{
if (value is not { IsCompleted: false })
if (value is null)
{
continue;
}
if (!value.IsAlive)
{
continue;
}
Expand All @@ -174,16 +178,15 @@ public void Stop()
{
foreach (var task in _tasks)
{
//TODO:
//task.Value.
task.Value?.Interrupt();
}
}

private void ParsePointItem(PointItem nowPointItem, bool onlyForward, bool notRealTime)
{
Log.Debug($"解析节点:{nowPointItem.Title}");
var valid = true;
List<Task> sourceDataTask = new();
List<Thread> sourceDataTask = new();

foreach (var connectorItem in nowPointItem.Input)
{
Expand Down Expand Up @@ -225,7 +228,7 @@ private void ParsePointItem(PointItem nowPointItem, bool onlyForward, bool notRe
}
else
{
var task = new Task(() =>
var task = new Thread(() =>
{
ParsePointItem(sourceSource, true, notRealTime);
});
Expand All @@ -239,7 +242,10 @@ private void ParsePointItem(PointItem nowPointItem, bool onlyForward, bool notRe
}
//源数据全部生成

Task.WaitAll(sourceDataTask.ToArray());
foreach (var thread in sourceDataTask)
{
thread.Join();
}
//这是连接当前节点的节点

foreach (var connectorItem in nowPointItem.Input)
Expand Down Expand Up @@ -360,9 +366,6 @@ private void ParsePointItem(PointItem nowPointItem, bool onlyForward, bool notRe
var index = 1;
foreach (var parameterInfo in methodInfo.GetParameters())
{
var inputObject = nowPointItem.Input[index].InputObject ??
throw new NullReferenceException("nowPointItem.Input[index].InputObject");

if (parameterInfo.ParameterType.GetCustomAttribute(typeof(AutoUnbox)) is not null)
{
var autoUnboxIndex = nowPointItem.Input[index].AutoUnboxIndex;
Expand All @@ -371,18 +374,46 @@ private void ParsePointItem(PointItem nowPointItem, bool onlyForward, bool notRe
while (nowPointItem.Input.Count >= index &&
nowPointItem.Input[index].AutoUnboxIndex == autoUnboxIndex)
{
parameterList.Add(inputObject);
parameterTypesList.Add(inputObject.GetType());
var item = nowPointItem.Input[index].InputObject;
if (item != null)
{
parameterList.Add(item);
parameterTypesList.Add(item.GetType());
}
else
{
valid = false;
goto finnish;
}

index++;
}

var instance = parameterInfo.ParameterType.GetConstructor(parameterTypesList.ToArray())!
.Invoke(parameterList.ToArray());
list.Add(instance);
var instance = parameterInfo.ParameterType.GetConstructor(parameterTypesList.ToArray())
?.Invoke(parameterList.ToArray());
if (instance != null)
{
list.Add(instance);
}
else
{
valid = false;
goto finnish;
}

continue;
}

list.Add(inputObject);
var inputObject = nowPointItem.Input[index].InputObject;
if (inputObject != null)
{
list.Add(inputObject);
}
else
{
valid = false;
goto finnish;
}

index++;
}
Expand Down Expand Up @@ -452,7 +483,7 @@ private void ParsePointItem(PointItem nowPointItem, bool onlyForward, bool notRe
return;
}

var task = new Task(() =>
var task = new Thread(() =>
{
ParsePointItem(nextPointItem, false, notRealTime);
});
Expand Down
1 change: 1 addition & 0 deletions Core/SDKs/SearchViewItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,6 @@ public enum FileType
数学运算,
UWP应用,
自定义情景,
便签,
None
}
7 changes: 7 additions & 0 deletions Core/SDKs/Services/ILabelWindowService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Core.SDKs.Services;

public interface ILabelWindowService
{
public void Show();
public void Show(string content);
}
8 changes: 8 additions & 0 deletions Core/ViewModel/Pages/LabelWindowViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using CommunityToolkit.Mvvm.ComponentModel;

namespace Core.ViewModel.Pages;

public partial class LabelWindowViewModel : ObservableObject
{
[ObservableProperty] private int _fontSize = 16;
}
14 changes: 14 additions & 0 deletions Core/ViewModel/SearchWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,16 @@ partial void OnSearchChanged(string? value)
}
}
var searchViewItem3 = new SearchViewItem()
{
FileName = "将内容添加至便签" + value,
FileType = FileType.便签,
OnlyKey = value,
Icon = null,
IconSymbol = 0xF6EC,
IsVisible = true
};
Items.Add(searchViewItem3);
var searchViewItem = new SearchViewItem()
{
Url = "https://www.bing.com/search?q=" + value,
Expand Down Expand Up @@ -686,6 +696,10 @@ await Task.Run(() =>
case FileType.自定义情景:
CustomScenarioManger.CustomScenarios.First((e) => e.UUID == item.OnlyKey).Run();
break;
case FileType.便签:
((ILabelWindowService)ServiceManager.Services.GetService(typeof(ILabelWindowService))!)
.Show(item.OnlyKey);
break;
default:
Shell32.ShellExecute(IntPtr.Zero, "open", item.OnlyKey, "", "",
ShowWindowCommand.SW_NORMAL);
Expand Down
5 changes: 4 additions & 1 deletion uToolkitopia/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ private static IServiceProvider ConfigureServices()
services.AddTransient<IToastService, ToastService>();
services.AddSingleton<INavigationService, NavigationService>();
services.AddTransient<INavigationPageService, NavigationPageService>();
services.AddTransient<ILabelWindowService, LabelWindowService>();
services.AddTransient<IClipboardService, ClipboardService>();
services.AddTransient<ITaskEditorOpenService, TaskEditorOpenService>();
services.AddTransient<IContentDialog, ContentDialogService>();
Expand All @@ -333,7 +334,9 @@ private static IServiceProvider ConfigureServices()
{ IsActive = true });
services.AddTransient<CustomScenariosManagerPage>(e => new CustomScenariosManagerPage
{ DataContext = e.GetService<CustomScenariosManagerPageViewModel>() });

services.AddTransient<LabelWindowViewModel>(e => new LabelWindowViewModel());
services.AddTransient<LabelWindow>(e => new LabelWindow()
{ DataContext = e.GetService<LabelWindowViewModel>() });
return services.BuildServiceProvider();
}

Expand Down
23 changes: 23 additions & 0 deletions uToolkitopia/Services/LabelWindowService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.Windows;
using Core.SDKs.Services;
using Kitopia.View;

namespace Kitopia.Services;

public class LabelWindowService : ILabelWindowService
{
public void Show()
{
throw new System.NotImplementedException();
}

public void Show(string content)
{
Application.Current.Dispatcher.BeginInvoke(() =>
{
var labelWindow = ((LabelWindow)ServiceManager.Services!.GetService(typeof(LabelWindow))!);
labelWindow.Show();
labelWindow.RichTextBox.Text = (content);
});
}
}
38 changes: 38 additions & 0 deletions uToolkitopia/View/LabelWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<ui:FluentWindow x:Class="Kitopia.View.LabelWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
xmlns:pages="clr-namespace:Core.ViewModel.Pages;assembly=Core"
mc:Ignorable="d"
ExtendsContentIntoTitleBar="True"
WindowBackdropType="Acrylic" d:DataContext="{d:DesignInstance pages:LabelWindowViewModel}"
Title="LabelWindow" Height="300" Width="300">

<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="30" />
<RowDefinition Height="*" />
<RowDefinition Height="50" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<ui:TitleBar Grid.ColumnSpan="2" CanMaximize="False" ShowMaximize="False" ShowMinimize="False" />

<ui:TextBox Grid.Row="1" Grid.ColumnSpan="2" Grid.RowSpan="2" x:Name="RichTextBox" FontSize="{Binding FontSize}">
<ui:TextBox.Background>
<SolidColorBrush Color="LightGoldenrodYellow" Opacity="0.7" />
</ui:TextBox.Background>
</ui:TextBox>
<ui:NumberBox ClearButtonEnabled="False" Grid.Row="2" Grid.Column="0" Value="{Binding FontSize,Mode=TwoWay}" MaxDecimalPlaces="0">
<ui:NumberBox.Background>
<SolidColorBrush Color="AliceBlue" />
</ui:NumberBox.Background>
</ui:NumberBox>


</Grid>
</ui:FluentWindow>
11 changes: 11 additions & 0 deletions uToolkitopia/View/LabelWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Wpf.Ui.Controls;

namespace Kitopia.View;

public partial class LabelWindow : FluentWindow
{
public LabelWindow()
{
InitializeComponent();
}
}

0 comments on commit 617cf46

Please sign in to comment.