├── .gitignore ├── Ads ├── 倍福.png └── 倍福配置.png ├── AutofacDemo ├── AutofacDemo.sln ├── AutofacDemo │ ├── App.config │ ├── AutofacDemo.csproj │ ├── MovieFinder │ │ ├── DBMovieFinder.cs │ │ ├── IMovieFinder.cs │ │ ├── ListMovieFinder.cs │ │ ├── MPGMovieLister.cs │ │ └── Movie.cs │ ├── Program.cs │ └── Properties │ │ └── AssemblyInfo.cs └── FakeAutofac │ ├── Container.cs │ ├── ContainerBuilder.cs │ ├── FakeAutofac.csproj │ ├── IContainer.cs │ ├── Properties │ └── AssemblyInfo.cs │ └── Resolver.cs ├── BSHMI ├── LinuxHMI │ ├── App.axaml │ ├── App.axaml.cs │ ├── LinuxHMI.csproj │ ├── MainWindow.axaml │ ├── MainWindow.axaml.cs │ ├── Program.cs │ └── app.manifest ├── Test.html └── TestHMI │ ├── Controllers │ └── WeatherForecastController.cs │ ├── Program.cs │ ├── Properties │ └── launchSettings.json │ ├── TestHMI.csproj │ ├── TestHMI.sln │ ├── WeatherForecast.cs │ ├── appsettings.Development.json │ └── appsettings.json ├── C#andCpp ├── CallNativeDllCSharp.sln ├── CallNativeDllCSharp │ ├── App.config │ ├── CallNativeDllCSharp.csproj │ ├── CallNativeDllCSharp.sln │ ├── Program.cs │ └── Properties │ │ └── AssemblyInfo.cs ├── CallNativeDllCpp │ ├── CallNativeDllCpp.vcxproj │ ├── CallNativeDllCpp.vcxproj.filters │ └── main.cpp ├── NativeDll │ ├── Native.cpp │ ├── Native.h │ ├── NativeDll.vcxproj │ └── NativeDll.vcxproj.filters ├── TestMemory │ ├── TestMemory.vcxproj │ ├── TestMemory.vcxproj.filters │ ├── dllmain.cpp │ ├── framework.h │ ├── pch.cpp │ └── pch.h ├── TestMemorySharp │ ├── Program.cs │ └── TestMemorySharp.csproj └── bin ├── CrossProcess ├── WinFormsApp1 │ ├── Form1.Designer.cs │ ├── Form1.cs │ ├── Form1.resx │ ├── Program.cs │ └── WinFormsApp1.csproj ├── WpfApp1.sln ├── WpfApp1 │ ├── App.xaml │ ├── App.xaml.cs │ ├── AssemblyInfo.cs │ ├── MainWindow.xaml │ ├── MainWindow.xaml.cs │ ├── MainWindowViewModel.cs │ ├── Win32API.cs │ ├── Window1.xaml │ ├── Window1.xaml.cs │ ├── Window2.xaml │ ├── Window2.xaml.cs │ ├── WpfApp1.csproj │ └── pack │ │ ├── System.Windows.Forms.dll │ │ └── WindowsFormsIntegration.dll ├── WpfApp2 │ ├── App.config │ ├── App.xaml │ ├── App.xaml.cs │ ├── MainWindow.xaml │ ├── MainWindow.xaml.cs │ ├── Properties │ │ ├── AssemblyInfo.cs │ │ ├── Resources.Designer.cs │ │ ├── Resources.resx │ │ ├── Settings.Designer.cs │ │ └── Settings.settings │ ├── Win32API.cs │ └── WpfApp2.csproj └── WpfApp3 │ ├── App.xaml │ ├── App.xaml.cs │ ├── AssemblyInfo.cs │ ├── MainWindow.xaml │ ├── MainWindow.xaml.cs │ ├── Win32API.cs │ └── WpfApp3.csproj ├── ElsaDemo └── ElsaDemo │ ├── ElsaDemo.csproj │ ├── ElsaDemo.sln │ └── Program.cs ├── NTP ├── In-Sight相机和服务器时间同步NTP设置的说明 v1.0-for WIN7 64.docx ├── Start NTP as client.bat ├── Start NTP as server.bat └── 客户端图片.png ├── Quartz ├── Quartz.sln ├── QuartzTest │ ├── App.config │ ├── JobLgoTask.cs │ ├── Program.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── QuartzTest.csproj │ └── packages.config └── Quartz用法学习.pdf ├── README.en.md ├── README.md ├── RuleEngine ├── NewRuleEngine │ ├── NewRuleEngine.csproj │ └── Program.cs └── RuleEngine │ ├── Program.cs │ ├── RuleEngine.csproj │ ├── RuleEngine.sln │ ├── Test2.cs │ ├── Test3.cs │ └── Test3.json ├── Test ├── Language │ ├── AddRoleLanguage.json │ ├── AddUserLanguage.json │ ├── ChartHistoryLanguage.json │ ├── ChartPageLanguage.json │ ├── ChartPageLanguage1.json │ ├── Data2CsvLanguage.json │ ├── EditRoleLanguage.json │ ├── EditUserLanguage.json │ ├── LoginLanguage.json │ ├── MainLanguage.json │ ├── MessageLanguage.json │ ├── SwichTheLanguage.json │ └── UserLanguage.json ├── WpfApp1 │ ├── App.xaml │ ├── App.xaml.cs │ ├── AssemblyInfo.cs │ ├── BoolToVisibilityConverter.cs │ ├── CustomFreezable.cs │ ├── Data2CsvLanguage.cs │ ├── MainViewModel.cs │ ├── MainWindow.xaml │ ├── MainWindow.xaml.cs │ ├── StringConcatConverter.cs │ ├── TestWindow.xaml │ ├── TestWindow.xaml.cs │ ├── TestWindowVM.cs │ ├── WpfApp1.csproj │ └── WpfApp1.sln └── functions │ ├── BoolToVisibilityConverter.cs │ ├── BridgeModule.cs │ ├── CustomFreezable.cs │ ├── Data2CsvLanguage.cs │ ├── StringConcatConverter.cs │ ├── TestView.xaml │ ├── TestView.xaml.cs │ ├── TestViewModel.cs │ ├── functions.csproj │ └── functions.dll ├── TestAvRegion ├── TestRegion.sln └── WpfApp1 │ ├── App.xaml │ ├── App.xaml.cs │ ├── AssemblyInfo.cs │ ├── MainWindow.xaml │ ├── MainWindow.xaml.cs │ ├── StackPanelRegionAdapter.cs │ ├── ViewModels │ ├── MainViewModel.cs │ └── TestRegionAViewModel.cs │ ├── Views │ ├── TestRegionAView.xaml │ └── TestRegionAView.xaml.cs │ └── WpfApp1.csproj ├── TestQueue ├── Program.cs └── TestQueue.csproj ├── ThreadTest ├── App.config ├── Channel │ ├── Channel.csproj │ └── Program.cs ├── PipeLine │ ├── PipeLine.csproj │ └── Program.cs ├── Program.cs ├── Properties │ └── AssemblyInfo.cs ├── Quarz │ ├── Program.cs │ ├── Quarz.csproj │ └── Quarz.sln ├── ThreadTest.csproj ├── ThreadTest.sln └── WorkFlow │ ├── Program.cs │ └── WorkFlow.csproj ├── WPFCustomChart ├── App.xaml ├── App.xaml.cs ├── AssemblyInfo.cs ├── MainWindow.xaml ├── MainWindow.xaml.cs ├── WPFCustomChart.csproj └── WPFCustomChart.sln └── dump └── TestDump ├── App.config ├── Form1.Designer.cs ├── Form1.cs ├── Form1.resx ├── MiniDump.cs ├── Program.cs ├── Properties ├── AssemblyInfo.cs ├── Resources.Designer.cs ├── Resources.resx ├── Settings.Designer.cs └── Settings.settings ├── TestDump.csproj └── TestDump.sln /Ads/倍福.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LessIsMoreInSZ/bilibiliDemo/c2ae5264474fc77e9db1003f0bbf54248900709c/Ads/倍福.png -------------------------------------------------------------------------------- /Ads/倍福配置.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LessIsMoreInSZ/bilibiliDemo/c2ae5264474fc77e9db1003f0bbf54248900709c/Ads/倍福配置.png -------------------------------------------------------------------------------- /AutofacDemo/AutofacDemo.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2012 4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutofacDemo", "AutofacDemo\AutofacDemo.csproj", "{ABFB664A-D279-4BDA-A884-739DEC1AC0B3}" 5 | EndProject 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FakeAutofac", "FakeAutofac\FakeAutofac.csproj", "{2776F4FA-23F6-4770-B657-D0709CD8BE3B}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {ABFB664A-D279-4BDA-A884-739DEC1AC0B3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {ABFB664A-D279-4BDA-A884-739DEC1AC0B3}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {ABFB664A-D279-4BDA-A884-739DEC1AC0B3}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {ABFB664A-D279-4BDA-A884-739DEC1AC0B3}.Release|Any CPU.Build.0 = Release|Any CPU 18 | {2776F4FA-23F6-4770-B657-D0709CD8BE3B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 19 | {2776F4FA-23F6-4770-B657-D0709CD8BE3B}.Debug|Any CPU.Build.0 = Debug|Any CPU 20 | {2776F4FA-23F6-4770-B657-D0709CD8BE3B}.Release|Any CPU.ActiveCfg = Release|Any CPU 21 | {2776F4FA-23F6-4770-B657-D0709CD8BE3B}.Release|Any CPU.Build.0 = Release|Any CPU 22 | EndGlobalSection 23 | GlobalSection(SolutionProperties) = preSolution 24 | HideSolutionNode = FALSE 25 | EndGlobalSection 26 | EndGlobal 27 | -------------------------------------------------------------------------------- /AutofacDemo/AutofacDemo/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /AutofacDemo/AutofacDemo/AutofacDemo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {ABFB664A-D279-4BDA-A884-739DEC1AC0B3} 8 | Exe 9 | Properties 10 | AutofacDemo 11 | AutofacDemo 12 | v4.8 13 | 512 14 | 15 | 16 | 17 | AnyCPU 18 | true 19 | full 20 | false 21 | bin\Debug\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | 26 | 27 | AnyCPU 28 | pdbonly 29 | true 30 | bin\Release\ 31 | TRACE 32 | prompt 33 | 4 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | {2776f4fa-23f6-4770-b657-d0709cd8be3b} 59 | FakeAutofac 60 | 61 | 62 | 63 | 70 | -------------------------------------------------------------------------------- /AutofacDemo/AutofacDemo/MovieFinder/DBMovieFinder.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace AutofacDemo.MovieFinder 4 | { 5 | public class DBMovieFinder : IMovieFinder 6 | { 7 | public List FindAll() 8 | { 9 | return new List 10 | { 11 | new Movie 12 | { 13 | Name = "Die Hard.wmv" 14 | }, 15 | new Movie 16 | { 17 | Name = "Resident Evil: Retribution.MPG" 18 | } 19 | }; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /AutofacDemo/AutofacDemo/MovieFinder/IMovieFinder.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace AutofacDemo.MovieFinder 4 | { 5 | public interface IMovieFinder 6 | { 7 | List FindAll(); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /AutofacDemo/AutofacDemo/MovieFinder/ListMovieFinder.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace AutofacDemo.MovieFinder 4 | { 5 | public class ListMovieFinder : IMovieFinder 6 | { 7 | public List FindAll() 8 | { 9 | return new List 10 | { 11 | new Movie 12 | { 13 | Name = "Die Hard.wmv" 14 | }, 15 | new Movie 16 | { 17 | Name = "My Name is John.MPG" 18 | } 19 | }; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /AutofacDemo/AutofacDemo/MovieFinder/MPGMovieLister.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | 3 | namespace AutofacDemo.MovieFinder 4 | { 5 | public class MPGMovieLister 6 | { 7 | private readonly IMovieFinder _movieFinder; 8 | public MPGMovieLister(IMovieFinder movieFinder) 9 | { 10 | _movieFinder = movieFinder; 11 | } 12 | 13 | public Movie[] GetMPG() 14 | { 15 | var allMovies = _movieFinder.FindAll(); 16 | return allMovies.Where(m => m.Name.EndsWith(".MPG")).ToArray(); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /AutofacDemo/AutofacDemo/MovieFinder/Movie.cs: -------------------------------------------------------------------------------- 1 | namespace AutofacDemo.MovieFinder 2 | { 3 | public class Movie 4 | { 5 | public string Name { get; set; } 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /AutofacDemo/AutofacDemo/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using AutofacDemo.MovieFinder; 3 | using FakeAutofac; 4 | 5 | namespace AutofacDemo 6 | { 7 | internal class Program 8 | { 9 | private static IContainer _container; 10 | private static void Main(string[] args) 11 | { 12 | InitIoC(); 13 | 14 | var lister = _container.Resolve(); 15 | 16 | foreach (var movie in lister.GetMPG()) 17 | { 18 | Console.WriteLine(movie.Name); 19 | } 20 | Console.Read(); 21 | } 22 | 23 | 24 | private static void InitIoC() 25 | { 26 | var builder = new ContainerBuilder(); 27 | builder.RegisterType().AsImplementedInterfaces(); 28 | builder.RegisterType().AsImplementedInterfaces(); 29 | builder.RegisterType(); 30 | _container = builder.Build(); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /AutofacDemo/AutofacDemo/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("AutofacDemo")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("AutofacDemo")] 13 | [assembly: AssemblyCopyright("Copyright © 2013")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("da5bcbb0-32de-4af4-b429-358f4d4f7b60")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /AutofacDemo/FakeAutofac/Container.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace FakeAutofac 5 | { 6 | public class Container : IContainer 7 | { 8 | //用来保存注册的类型 9 | private readonly Dictionary _typePool = new Dictionary(); 10 | 11 | public Container(Dictionary typePool) 12 | { 13 | _typePool = typePool; 14 | //给所有的Resolver指定GetParameterInstance委托, 这样当遇到构造函数需要参数的时候,还是交由Container来提供实例 15 | foreach (var resolver in typePool.Values) 16 | { 17 | resolver.GetParameterInstance = Resolve; 18 | } 19 | } 20 | 21 | //实现的接口方法 22 | public T Resolve() where T : class 23 | { 24 | //直接调用对应的REsolver的GetInstance方法获取实例 25 | return (T) _typePool[typeof (T)].GetInstance(); 26 | } 27 | 28 | private object Resolve(Type type) 29 | { 30 | return _typePool[type].GetInstance(); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /AutofacDemo/FakeAutofac/ContainerBuilder.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace FakeAutofac 5 | { 6 | public class ContainerBuilder 7 | { 8 | //用来保存注册的类型 9 | private readonly Dictionary _typePool = new Dictionary(); 10 | private Type _currentKey; 11 | 12 | public ContainerBuilder RegisterType () where T:class 13 | { 14 | _currentKey = typeof (T); 15 | var resolver = new Resolver { RealType = _currentKey }; 16 | _typePool[_currentKey] = resolver; 17 | 18 | return this; 19 | } 20 | 21 | 22 | public ContainerBuilder AsImplementedInterfaces() 23 | { 24 | //以接口为key, 对应Resolver 25 | var interfaces = _currentKey.GetInterfaces(); 26 | foreach (var @interface in interfaces) 27 | { 28 | _typePool[@interface] = _typePool[_currentKey]; 29 | } 30 | return this; 31 | } 32 | 33 | //创建Container 34 | public IContainer Build() 35 | { 36 | var container = new Container(_typePool); 37 | 38 | return container; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /AutofacDemo/FakeAutofac/FakeAutofac.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {2776F4FA-23F6-4770-B657-D0709CD8BE3B} 8 | Library 9 | Properties 10 | FakeAutofac 11 | FakeAutofac 12 | v4.8 13 | 512 14 | 15 | 16 | 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | pdbonly 27 | true 28 | bin\Release\ 29 | TRACE 30 | prompt 31 | 4 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 57 | -------------------------------------------------------------------------------- /AutofacDemo/FakeAutofac/IContainer.cs: -------------------------------------------------------------------------------- 1 | namespace FakeAutofac 2 | { 3 | public interface IContainer 4 | { 5 | T Resolve() where T: class; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /AutofacDemo/FakeAutofac/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("FakeAutofac")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("FakeAutofac")] 13 | [assembly: AssemblyCopyright("Copyright © 2013")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("1e2cb7da-e751-4229-a36a-22c377b29292")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /AutofacDemo/FakeAutofac/Resolver.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace FakeAutofac 5 | { 6 | public class Resolver 7 | { 8 | public Type RealType { get; set; } 9 | //用该委托来获取构造函数的参数实例 10 | public Func GetParameterInstance { get; set; } 11 | 12 | public object GetInstance() 13 | { 14 | //取得Type的构造函数, 这里为了简便,默认使用最后一个,实际的Autofac默认会使用参数最长的一个 15 | var constructors = RealType.GetConstructors(); 16 | var paramsInfos = constructors[constructors.Length - 1].GetParameters(); 17 | //准备构造函数的参数 18 | var @params = new List(); 19 | foreach (var parameterInfo in paramsInfos) 20 | { 21 | //根据类型,取的参数的实例 22 | var tempPara = GetParameterInstance(parameterInfo.ParameterType); 23 | @params.Add(tempPara); 24 | } 25 | 26 | //调用构造函数构造对象 27 | return constructors[0].Invoke(@params.ToArray()); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /BSHMI/LinuxHMI/App.axaml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /BSHMI/LinuxHMI/App.axaml.cs: -------------------------------------------------------------------------------- 1 | using Avalonia; 2 | using Avalonia.Controls.ApplicationLifetimes; 3 | using Avalonia.Markup.Xaml; 4 | 5 | namespace LinuxHMI 6 | { 7 | public partial class App : Application 8 | { 9 | public override void Initialize() 10 | { 11 | AvaloniaXamlLoader.Load(this); 12 | } 13 | 14 | public override void OnFrameworkInitializationCompleted() 15 | { 16 | if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) 17 | { 18 | desktop.MainWindow = new MainWindow(); 19 | } 20 | 21 | base.OnFrameworkInitializationCompleted(); 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /BSHMI/LinuxHMI/LinuxHMI.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | WinExe 4 | net8.0 5 | enable 6 | true 7 | app.manifest 8 | true 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | None 19 | All 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /BSHMI/LinuxHMI/MainWindow.axaml: -------------------------------------------------------------------------------- 1 | 13 | Welcome to Avalonia! 14 | 16 | 17 | 19 | 22 | 24 | 25 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /BSHMI/LinuxHMI/MainWindow.axaml.cs: -------------------------------------------------------------------------------- 1 | using Avalonia.Controls; 2 | 3 | namespace LinuxHMI 4 | { 5 | public partial class MainWindow : Window 6 | { 7 | public MainWindow() 8 | { 9 | InitializeComponent(); 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /BSHMI/LinuxHMI/Program.cs: -------------------------------------------------------------------------------- 1 | using Avalonia; 2 | using System; 3 | 4 | namespace LinuxHMI 5 | { 6 | internal class Program 7 | { 8 | // Initialization code. Don't use any Avalonia, third-party APIs or any 9 | // SynchronizationContext-reliant code before AppMain is called: things aren't initialized 10 | // yet and stuff might break. 11 | [STAThread] 12 | public static void Main(string[] args) => BuildAvaloniaApp() 13 | .StartWithClassicDesktopLifetime(args); 14 | 15 | // Avalonia configuration, don't remove; also used by visual designer. 16 | public static AppBuilder BuildAvaloniaApp() 17 | => AppBuilder.Configure() 18 | .UsePlatformDetect() 19 | .WithInterFont() 20 | .LogToTrace(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /BSHMI/LinuxHMI/app.manifest: -------------------------------------------------------------------------------- 1 |  2 | 3 | 6 | 7 | 8 | 9 | 10 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /BSHMI/TestHMI/Controllers/WeatherForecastController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | 3 | namespace TestHMI.Controllers 4 | { 5 | [ApiController] 6 | [Route("[controller]")] 7 | public class WeatherForecastController : ControllerBase 8 | { 9 | private static readonly string[] Summaries = new[] 10 | { 11 | "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" 12 | }; 13 | 14 | private readonly ILogger _logger; 15 | 16 | public WeatherForecastController(ILogger logger) 17 | { 18 | _logger = logger; 19 | } 20 | 21 | [HttpGet("Momentary")] 22 | public IEnumerable Get() 23 | { 24 | return Enumerable.Range(1, 5).Select(index => new WeatherForecast 25 | { 26 | Date = DateTime.Now.AddDays(index), 27 | TemperatureC = Random.Shared.Next(-20, 55), 28 | Summary = Summaries[Random.Shared.Next(Summaries.Length)] 29 | }) 30 | .ToArray(); 31 | } 32 | 33 | [HttpGet("Holdtrigger")] 34 | public IEnumerable GetHold() 35 | { 36 | return Enumerable.Range(1, 5).Select(index => new WeatherForecast 37 | { 38 | Date = DateTime.Now.AddDays(index), 39 | TemperatureC = Random.Shared.Next(-20, 55), 40 | Summary = Summaries[Random.Shared.Next(Summaries.Length)] 41 | }) 42 | .ToArray(); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /BSHMI/TestHMI/Program.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LessIsMoreInSZ/bilibiliDemo/c2ae5264474fc77e9db1003f0bbf54248900709c/BSHMI/TestHMI/Program.cs -------------------------------------------------------------------------------- /BSHMI/TestHMI/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json.schemastore.org/launchsettings.json", 3 | "iisSettings": { 4 | "windowsAuthentication": false, 5 | "anonymousAuthentication": true, 6 | "iisExpress": { 7 | "applicationUrl": "http://localhost:38717", 8 | "sslPort": 44381 9 | } 10 | }, 11 | "profiles": { 12 | "TestHMI": { 13 | "commandName": "Project", 14 | "dotnetRunMessages": true, 15 | "launchBrowser": true, 16 | "launchUrl": "swagger", 17 | "applicationUrl": "https://localhost:7105;http://localhost:5274", 18 | "environmentVariables": { 19 | "ASPNETCORE_ENVIRONMENT": "Development" 20 | } 21 | }, 22 | "IIS Express": { 23 | "commandName": "IISExpress", 24 | "launchBrowser": true, 25 | "launchUrl": "swagger", 26 | "environmentVariables": { 27 | "ASPNETCORE_ENVIRONMENT": "Development" 28 | } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /BSHMI/TestHMI/TestHMI.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /BSHMI/TestHMI/TestHMI.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.12.35707.178 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestHMI", "TestHMI.csproj", "{28934DBE-7F54-4A36-80FC-177A7972AF86}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LinuxHMI", "..\LinuxHMI\LinuxHMI.csproj", "{54A8072B-12E2-4F89-81AC-A7E7CE45F16C}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Release|Any CPU = Release|Any CPU 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {28934DBE-7F54-4A36-80FC-177A7972AF86}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {28934DBE-7F54-4A36-80FC-177A7972AF86}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {28934DBE-7F54-4A36-80FC-177A7972AF86}.Release|Any CPU.ActiveCfg = Release|Any CPU 19 | {28934DBE-7F54-4A36-80FC-177A7972AF86}.Release|Any CPU.Build.0 = Release|Any CPU 20 | {54A8072B-12E2-4F89-81AC-A7E7CE45F16C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {54A8072B-12E2-4F89-81AC-A7E7CE45F16C}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {54A8072B-12E2-4F89-81AC-A7E7CE45F16C}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {54A8072B-12E2-4F89-81AC-A7E7CE45F16C}.Release|Any CPU.Build.0 = Release|Any CPU 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | EndGlobal 29 | -------------------------------------------------------------------------------- /BSHMI/TestHMI/WeatherForecast.cs: -------------------------------------------------------------------------------- 1 | namespace TestHMI 2 | { 3 | public class WeatherForecast 4 | { 5 | public DateTime Date { get; set; } 6 | 7 | public int TemperatureC { get; set; } 8 | 9 | public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); 10 | 11 | public string? Summary { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /BSHMI/TestHMI/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /BSHMI/TestHMI/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | }, 8 | "AllowedHosts": "*" 9 | } 10 | -------------------------------------------------------------------------------- /C#andCpp/CallNativeDllCSharp/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /C#andCpp/CallNativeDllCSharp/CallNativeDllCSharp.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {CA59435A-0C25-4EF1-BB7E-3328F847BA08} 8 | Exe 9 | CallNativeDllCSharp 10 | CallNativeDllCSharp 11 | v4.6.1 12 | 512 13 | true 14 | true 15 | 16 | 17 | x64 18 | true 19 | full 20 | false 21 | ..\..\bin\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | false 26 | 27 | 28 | AnyCPU 29 | pdbonly 30 | true 31 | bin\Release\ 32 | TRACE 33 | prompt 34 | 4 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /C#andCpp/CallNativeDllCSharp/CallNativeDllCSharp.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28307.1401 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CallNativeDllCSharp", "CallNativeDllCSharp\CallNativeDllCSharp.csproj", "{CA59435A-0C25-4EF1-BB7E-3328F847BA08}" 7 | ProjectSection(ProjectDependencies) = postProject 8 | {42921FB8-466C-4D5E-AA63-4B3FE6D00DB2} = {42921FB8-466C-4D5E-AA63-4B3FE6D00DB2} 9 | EndProjectSection 10 | EndProject 11 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CallNativeDllCpp", "CallNativeDllCpp\CallNativeDllCpp.vcxproj", "{03BC7C92-81A9-4A63-95AC-2E499CEE5FBC}" 12 | ProjectSection(ProjectDependencies) = postProject 13 | {42921FB8-466C-4D5E-AA63-4B3FE6D00DB2} = {42921FB8-466C-4D5E-AA63-4B3FE6D00DB2} 14 | EndProjectSection 15 | EndProject 16 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "NativeDll", "NativeDll\NativeDll.vcxproj", "{42921FB8-466C-4D5E-AA63-4B3FE6D00DB2}" 17 | EndProject 18 | Global 19 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 20 | Debug|Any CPU = Debug|Any CPU 21 | Debug|x64 = Debug|x64 22 | Debug|x86 = Debug|x86 23 | Release|Any CPU = Release|Any CPU 24 | Release|x64 = Release|x64 25 | Release|x86 = Release|x86 26 | EndGlobalSection 27 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 28 | {CA59435A-0C25-4EF1-BB7E-3328F847BA08}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 29 | {CA59435A-0C25-4EF1-BB7E-3328F847BA08}.Debug|Any CPU.Build.0 = Debug|Any CPU 30 | {CA59435A-0C25-4EF1-BB7E-3328F847BA08}.Debug|x64.ActiveCfg = Debug|Any CPU 31 | {CA59435A-0C25-4EF1-BB7E-3328F847BA08}.Debug|x64.Build.0 = Debug|Any CPU 32 | {CA59435A-0C25-4EF1-BB7E-3328F847BA08}.Debug|x86.ActiveCfg = Debug|Any CPU 33 | {CA59435A-0C25-4EF1-BB7E-3328F847BA08}.Debug|x86.Build.0 = Debug|Any CPU 34 | {CA59435A-0C25-4EF1-BB7E-3328F847BA08}.Release|Any CPU.ActiveCfg = Release|Any CPU 35 | {CA59435A-0C25-4EF1-BB7E-3328F847BA08}.Release|Any CPU.Build.0 = Release|Any CPU 36 | {CA59435A-0C25-4EF1-BB7E-3328F847BA08}.Release|x64.ActiveCfg = Release|Any CPU 37 | {CA59435A-0C25-4EF1-BB7E-3328F847BA08}.Release|x64.Build.0 = Release|Any CPU 38 | {CA59435A-0C25-4EF1-BB7E-3328F847BA08}.Release|x86.ActiveCfg = Release|Any CPU 39 | {CA59435A-0C25-4EF1-BB7E-3328F847BA08}.Release|x86.Build.0 = Release|Any CPU 40 | {03BC7C92-81A9-4A63-95AC-2E499CEE5FBC}.Debug|Any CPU.ActiveCfg = Debug|Win32 41 | {03BC7C92-81A9-4A63-95AC-2E499CEE5FBC}.Debug|x64.ActiveCfg = Debug|x64 42 | {03BC7C92-81A9-4A63-95AC-2E499CEE5FBC}.Debug|x64.Build.0 = Debug|x64 43 | {03BC7C92-81A9-4A63-95AC-2E499CEE5FBC}.Debug|x86.ActiveCfg = Debug|Win32 44 | {03BC7C92-81A9-4A63-95AC-2E499CEE5FBC}.Debug|x86.Build.0 = Debug|Win32 45 | {03BC7C92-81A9-4A63-95AC-2E499CEE5FBC}.Release|Any CPU.ActiveCfg = Release|Win32 46 | {03BC7C92-81A9-4A63-95AC-2E499CEE5FBC}.Release|x64.ActiveCfg = Release|x64 47 | {03BC7C92-81A9-4A63-95AC-2E499CEE5FBC}.Release|x64.Build.0 = Release|x64 48 | {03BC7C92-81A9-4A63-95AC-2E499CEE5FBC}.Release|x86.ActiveCfg = Release|Win32 49 | {03BC7C92-81A9-4A63-95AC-2E499CEE5FBC}.Release|x86.Build.0 = Release|Win32 50 | {42921FB8-466C-4D5E-AA63-4B3FE6D00DB2}.Debug|Any CPU.ActiveCfg = Debug|Win32 51 | {42921FB8-466C-4D5E-AA63-4B3FE6D00DB2}.Debug|x64.ActiveCfg = Debug|x64 52 | {42921FB8-466C-4D5E-AA63-4B3FE6D00DB2}.Debug|x64.Build.0 = Debug|x64 53 | {42921FB8-466C-4D5E-AA63-4B3FE6D00DB2}.Debug|x86.ActiveCfg = Debug|Win32 54 | {42921FB8-466C-4D5E-AA63-4B3FE6D00DB2}.Debug|x86.Build.0 = Debug|Win32 55 | {42921FB8-466C-4D5E-AA63-4B3FE6D00DB2}.Release|Any CPU.ActiveCfg = Release|Win32 56 | {42921FB8-466C-4D5E-AA63-4B3FE6D00DB2}.Release|x64.ActiveCfg = Release|x64 57 | {42921FB8-466C-4D5E-AA63-4B3FE6D00DB2}.Release|x64.Build.0 = Release|x64 58 | {42921FB8-466C-4D5E-AA63-4B3FE6D00DB2}.Release|x86.ActiveCfg = Release|Win32 59 | {42921FB8-466C-4D5E-AA63-4B3FE6D00DB2}.Release|x86.Build.0 = Release|Win32 60 | EndGlobalSection 61 | GlobalSection(SolutionProperties) = preSolution 62 | HideSolutionNode = FALSE 63 | EndGlobalSection 64 | GlobalSection(ExtensibilityGlobals) = postSolution 65 | SolutionGuid = {3F4E9FC7-5E4E-409B-94F9-026A666FFC4A} 66 | EndGlobalSection 67 | EndGlobal 68 | -------------------------------------------------------------------------------- /C#andCpp/CallNativeDllCSharp/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Runtime.InteropServices; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace CallNativeDllCSharp 9 | { 10 | class Program 11 | { 12 | [DllImport("NativeDll.dll", CallingConvention = CallingConvention.Cdecl, SetLastError = false)] 13 | public static extern void Test1(); 14 | 15 | [DllImport("NativeDll.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, EntryPoint = "TestLog",ExactSpelling = false)] 16 | public static extern void TestLogNative(string log); 17 | 18 | [DllImport("NativeDll.dll", CallingConvention = CallingConvention.Cdecl)] 19 | public static extern void Test_BasicData(char d1, short d2, int d3, long d4, float d5, double d6); 20 | 21 | 22 | [DllImport("NativeDll.dll", CallingConvention = CallingConvention.Cdecl)] 23 | public static extern void Test_BasicDataRef(ref sbyte d1, ref short d2, ref int d3, ref long d4, ref float d5, ref double d6); 24 | 25 | [DllImport("NativeDll.dll", CallingConvention = CallingConvention.Cdecl)] 26 | public static extern void Test_BasicDataPointer(ref sbyte d1, ref short d2, ref int d3, ref long d4, ref float d5, ref double d6); 27 | 28 | [DllImport("NativeDll.dll", CallingConvention = CallingConvention.Cdecl)] 29 | public static extern float Test_Add(float num1, float num2); 30 | 31 | [DllImport("NativeDll.dll", CallingConvention = CallingConvention.Cdecl)] 32 | public static extern float Test_BasicDataArr(int[] arr1, float[] arr2); 33 | 34 | [DllImport("NativeDll.dll", CallingConvention = CallingConvention.Cdecl)] 35 | public static extern IntPtr Test_BasicDataRet(); 36 | 37 | [DllImport("NativeDll.dll", CallingConvention = CallingConvention.Cdecl)] 38 | public static extern void Test_BasicDataString(string str); 39 | 40 | [DllImport("NativeDll.dll", CallingConvention = CallingConvention.Cdecl)] 41 | //public static extern string Test_BasicDataChar(string str); 42 | public static extern IntPtr Test_BasicDataChar(string str); 43 | 44 | 45 | [DllImport("NativeDll.dll", CallingConvention = CallingConvention.Cdecl)] 46 | public static extern void Test_BasicDataByteArr(byte[] str); 47 | 48 | [StructLayout(LayoutKind.Sequential)] 49 | public struct ChildStruct 50 | { 51 | public int num; 52 | public double pi; 53 | }; 54 | [StructLayout(LayoutKind.Sequential)] 55 | public struct StructA 56 | { 57 | public short id; 58 | public ChildStruct cs; 59 | public IntPtr pcs; 60 | [MarshalAs(UnmanagedType.ByValArray, SizeConst =5)] 61 | public int[] nums; 62 | }; 63 | 64 | [DllImport("NativeDll.dll", CallingConvention = CallingConvention.Cdecl)] 65 | public static extern void Test_Struct(ref StructA param); 66 | 67 | [DllImport("NativeDll.dll", CallingConvention = CallingConvention.Cdecl)] 68 | public static extern IntPtr Test_StructRet(); 69 | 70 | [DllImport("NativeDll.dll", CallingConvention = CallingConvention.Cdecl)] 71 | public static extern IntPtr ConvertChildStruct(ref ChildStruct cs); 72 | 73 | [DllImport("NativeDll.dll", CallingConvention = CallingConvention.Cdecl)] 74 | public static extern float Sum(int length, __arglist); 75 | 76 | [UnmanagedFunctionPointer(CallingConvention.Cdecl)] 77 | public delegate int Log(int level, IntPtr ptr); 78 | 79 | [DllImport("NativeDll.dll", CallingConvention = CallingConvention.Cdecl)] 80 | public static extern void SetLogFuncPointer(Log logptr); 81 | 82 | public static Log logfuncptr = LogCallback; 83 | 84 | static int LogCallback(int level, IntPtr ptr) 85 | { 86 | 87 | return 0; 88 | } 89 | static void Main(string[] args) 90 | { 91 | 92 | //SetLogFuncPointer(logfuncptr); 93 | //Test_BasicDataString("Test"); 94 | IntPtr intPtr = Test_BasicDataChar("testchar"); 95 | string stringB = Marshal.PtrToStringAnsi(intPtr); 96 | float s = Test_Add(5, 6); 97 | Console.Read(); 98 | } 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /C#andCpp/CallNativeDllCSharp/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 有关程序集的一般信息由以下 6 | // 控制。更改这些特性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("CallNativeDllCSharp")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("CallNativeDllCSharp")] 13 | [assembly: AssemblyCopyright("Copyright © 2021")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // 将 ComVisible 设置为 false 会使此程序集中的类型 18 | //对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 19 | //请将此类型的 ComVisible 特性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID 23 | [assembly: Guid("ca59435a-0c25-4ef1-bb7e-3328f847ba08")] 24 | 25 | // 程序集的版本信息由下列四个值组成: 26 | // 27 | // 主版本 28 | // 次版本 29 | // 生成号 30 | // 修订号 31 | // 32 | // 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号 33 | // 方法是按如下所示使用“*”: : 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /C#andCpp/CallNativeDllCpp/CallNativeDllCpp.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /C#andCpp/CallNativeDllCpp/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #define DLL_IMPORT 4 | #include "../NativeDll/Native.h" 5 | #pragma comment(lib, "../../bin/NativeDll.lib") 6 | 7 | void test(int length, ...) 8 | { 9 | va_list ap; 10 | va_start(ap, length); 11 | 12 | 13 | int num1 = va_arg(ap, int); 14 | int num2 = va_arg(ap, int); 15 | double num3 = va_arg(ap, double); 16 | va_end(ap); 17 | } 18 | int main(int argc, char* argv[]) 19 | { 20 | test(3, 123, 456, 12.3); 21 | return 0; 22 | } -------------------------------------------------------------------------------- /C#andCpp/NativeDll/Native.cpp: -------------------------------------------------------------------------------- 1 | #include "Native.h" 2 | #include 3 | #include 4 | HEAD void CallingConvention Test1() 5 | { 6 | SetLastError(2); 7 | printf("call success\n"); 8 | } 9 | 10 | HEAD void CallingConvention TestLogA(const char *log) 11 | { 12 | printf("logA:%s\n", log); 13 | } 14 | 15 | HEAD void CallingConvention Test_BasicData(char d1, short d2, int d3, long long d4, float d5, double d6) 16 | { 17 | 18 | } 19 | 20 | HEAD void CallingConvention Test_BasicDataRef(char &d1, short &d2, int &d3, long long &d4, float &d5, double &d6) 21 | { 22 | d1 = 1; 23 | d2 = 2; 24 | d3 = 3; 25 | d4 = 4; 26 | d5 = 5.5f; 27 | d6 = 6.6; 28 | } 29 | 30 | HEAD void CallingConvention Test_BasicDataPointer(char *d1, short *d2, int *d3, long long *d4, float *d5, double *d6) 31 | { 32 | *d1 = 10; 33 | *d2 = 20; 34 | *d3 = 30; 35 | *d4 = 40; 36 | *d5 = 15.5f; 37 | *d6 = 16.6; 38 | } 39 | 40 | HEAD float CallingConvention Test_Add(float num1, float num2) 41 | { 42 | return num1 + num2; 43 | } 44 | 45 | HEAD void CallingConvention Test_BasicDataArr(int *arr1, float *arr2) 46 | { 47 | arr1[0] = 11; 48 | arr1[1] = 22; 49 | arr1[2] = 33; 50 | 51 | arr2[0] = 22.2f; 52 | arr2[1] = 22.2f; 53 | arr2[2] = 22.2f; 54 | arr2[3] = 22.2f; 55 | } 56 | 57 | int intarr[5] = {1,2,3,4,5}; 58 | HEAD void* CallingConvention Test_BasicDataRet() 59 | { 60 | return intarr; 61 | } 62 | 63 | HEAD void CallingConvention Test_BasicDataString(char *str) 64 | { 65 | printf("%s\n", str); 66 | } 67 | 68 | HEAD char* CallingConvention Test_BasicDataChar(char* str) 69 | { 70 | *str = '66'; 71 | printf("%s\n", str); 72 | //printf("666"); 73 | return str; 74 | } 75 | 76 | HEAD void CallingConvention Test_BasicDataByteArr(char *str) 77 | { 78 | printf("%s\n", str); 79 | } 80 | 81 | HEAD void CallingConvention Test_Struct(StructA param) 82 | { 83 | param.id = 123; 84 | } 85 | 86 | StructA structa; 87 | 88 | struct FrameInfo 89 | { 90 | char username[20]; 91 | double pts; 92 | }; 93 | 94 | struct Frame 95 | { 96 | int width; //0-4 97 | int height;//4-8 98 | int format;//8-12 99 | int linesize[4]; //12-28 100 | unsigned char* data[4];//32-64 101 | FrameInfo *info; //64-72 102 | }; 103 | Frame frame; 104 | FrameInfo info; 105 | HEAD void* CallingConvention Test_StructRet() 106 | { 107 | frame.width = 1920; 108 | frame.height = 1080; 109 | frame.format = 0; 110 | for (int i = 0; i < 4; i++) 111 | { 112 | frame.linesize[i] = 100 * i; 113 | frame.data[i] = new unsigned char[10]; 114 | for (int j = 0; j < 10; j++) 115 | { 116 | frame.data[i][j] = i; 117 | } 118 | } 119 | info.pts = 12.5; 120 | memset(info.username, 0, 20); 121 | memcpy(info.username, "hello world", strlen("hello world")); 122 | frame.info = &info; 123 | return &frame; 124 | } 125 | 126 | HEAD void* CallingConvention ConvertChildStruct(ChildStruct *cs) 127 | { 128 | return cs; 129 | } 130 | 131 | HEAD float CallingConvention Sum(int length, ...) 132 | { 133 | char* head = (char*)&length; 134 | int num1 = *(long long*)(head + 8); 135 | int num2 = *(long long*)(head + 16); 136 | int num3 = *(long long*)(head + 24); 137 | int num4 = *(long long*)(head + 32); 138 | double num5 = *(double*)(head + 40); 139 | 140 | return (num1 + num2 + num3 + num4 + num5) / length; 141 | } 142 | 143 | HEAD void CallingConvention SetLogFuncPointer(pfun p) 144 | { 145 | int ret = p(0, NULL); 146 | printf(""); 147 | } 148 | 149 | //HEAD void CallingConvention TestLog(const char *log) 150 | //{ 151 | // printf("log:%s\n", log); 152 | //} 153 | -------------------------------------------------------------------------------- /C#andCpp/NativeDll/Native.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef __cplusplus 4 | #define EXTERNC extern "C" 5 | #else 6 | #define EXTERNC 7 | #endif 8 | 9 | #ifdef DLL_IMPORT 10 | #define HEAD EXTERNC __declspec(dllimport) 11 | #else 12 | #define HEAD EXTERNC __declspec(dllexport) 13 | #endif 14 | #define CallingConvention _cdecl 15 | 16 | HEAD void CallingConvention Test1(); 17 | 18 | HEAD void CallingConvention TestLogA(const char *log); 19 | 20 | //HEAD void CallingConvention TestLog(const char *log); 21 | 22 | HEAD void CallingConvention Test_BasicData(char d1, short d2, int d3, long long d4, float d5, double d6); 23 | 24 | HEAD void CallingConvention Test_BasicDataRef(char &d1, short &d2, int &d3, long long &d4, float &d5, double &d6); 25 | 26 | HEAD void CallingConvention Test_BasicDataPointer(char *d1, short *d2, int *d3, long long *d4, float *d5, double *d6); 27 | 28 | HEAD float CallingConvention Test_Add(float num1, float num2); 29 | 30 | HEAD void CallingConvention Test_BasicDataArr(int *arr1, float *arr2); 31 | 32 | HEAD void* CallingConvention Test_BasicDataRet(); 33 | 34 | HEAD void CallingConvention Test_BasicDataString(char *str); 35 | 36 | HEAD char* CallingConvention Test_BasicDataChar(char* str); 37 | 38 | 39 | HEAD void CallingConvention Test_BasicDataByteArr(char *str); 40 | 41 | 42 | struct ChildStruct 43 | { 44 | int num; 45 | double pi; 46 | }; 47 | struct StructA 48 | { 49 | short id; 50 | ChildStruct cs; 51 | ChildStruct *pcs; 52 | int nums[5]; 53 | }; 54 | HEAD void CallingConvention Test_Struct(StructA param); 55 | 56 | HEAD void* CallingConvention Test_StructRet(); 57 | 58 | HEAD void* CallingConvention ConvertChildStruct(ChildStruct *cs); 59 | 60 | HEAD float CallingConvention Sum(int length, ...); 61 | 62 | //int Log(int level, IntPtr ptr) 63 | typedef int(*pfun)(int level, void* ptr); 64 | 65 | //void SetLogFuncPointer(Log logptr); 66 | 67 | HEAD void CallingConvention SetLogFuncPointer(pfun p); -------------------------------------------------------------------------------- /C#andCpp/NativeDll/NativeDll.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 头文件 20 | 21 | 22 | 23 | 24 | 源文件 25 | 26 | 27 | -------------------------------------------------------------------------------- /C#andCpp/TestMemory/TestMemory.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 头文件 20 | 21 | 22 | 头文件 23 | 24 | 25 | 26 | 27 | 源文件 28 | 29 | 30 | 源文件 31 | 32 | 33 | -------------------------------------------------------------------------------- /C#andCpp/TestMemory/dllmain.cpp: -------------------------------------------------------------------------------- 1 | // dllmain.cpp : 定义 DLL 应用程序的入口点。 2 | #include "pch.h" 3 | #include 4 | #include 5 | #define _CRTDBG_MAP_ALLOC 6 | #include 7 | 8 | BOOL APIENTRY DllMain( HMODULE hModule, 9 | DWORD ul_reason_for_call, 10 | LPVOID lpReserved 11 | ) 12 | { 13 | switch (ul_reason_for_call) 14 | { 15 | case DLL_PROCESS_ATTACH: 16 | case DLL_THREAD_ATTACH: 17 | case DLL_THREAD_DETACH: 18 | case DLL_PROCESS_DETACH: 19 | break; 20 | } 21 | return TRUE; 22 | } 23 | 24 | // 导出内存分配函数(无释放接口) 25 | extern "C" __declspec(dllexport) void* AllocateMemory(int size) { 26 | return malloc(size * 1024); // 分配1KB块(实际按需调整) 27 | } 28 | 29 | // 导出释放函数(C#中不会调用) 30 | extern "C" __declspec(dllexport) void FreeMemory(void* ptr) { 31 | free(ptr); 32 | } 33 | 34 | -------------------------------------------------------------------------------- /C#andCpp/TestMemory/framework.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define WIN32_LEAN_AND_MEAN // 从 Windows 头文件中排除极少使用的内容 4 | // Windows 头文件 5 | #include 6 | -------------------------------------------------------------------------------- /C#andCpp/TestMemory/pch.cpp: -------------------------------------------------------------------------------- 1 | // pch.cpp: 与预编译标头对应的源文件 2 | 3 | #include "pch.h" 4 | 5 | // 当使用预编译的头时,需要使用此源文件,编译才能成功。 6 | -------------------------------------------------------------------------------- /C#andCpp/TestMemory/pch.h: -------------------------------------------------------------------------------- 1 | // pch.h: 这是预编译标头文件。 2 | // 下方列出的文件仅编译一次,提高了将来生成的生成性能。 3 | // 这还将影响 IntelliSense 性能,包括代码完成和许多代码浏览功能。 4 | // 但是,如果此处列出的文件中的任何一个在生成之间有更新,它们全部都将被重新编译。 5 | // 请勿在此处添加要频繁更新的文件,这将使得性能优势无效。 6 | 7 | #ifndef PCH_H 8 | #define PCH_H 9 | 10 | // 添加要在此处预编译的标头 11 | #include "framework.h" 12 | 13 | #endif //PCH_H 14 | -------------------------------------------------------------------------------- /C#andCpp/TestMemorySharp/Program.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace TestMemorySharp 5 | { 6 | internal class Program 7 | { 8 | // C#端启用CRT调试 9 | [DllImport("msvcrtd.dll")] 10 | public static extern void _CrtSetDbgFlag(UInt32 flag); 11 | 12 | [DllImport("TestMemory.dll")] 13 | public static extern void FreeMemory(IntPtr ptr); 14 | 15 | [DllImport("TestMemory.dll")] 16 | public static extern IntPtr AllocateMemory(int size); 17 | 18 | static void Main(string[] args) 19 | { 20 | //_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); 21 | 22 | #region low逼版 23 | //Console.WriteLine("开始内存泄漏测试..."); 24 | 25 | //// 循环分配内存(但不释放) 26 | //for (int i = 0; i < 10000; i++) 27 | //{ 28 | // AllocateMemory(5000); // 分配1KB 29 | // Console.WriteLine($"分配第 {i + 1} 块内存"); 30 | //} 31 | //Console.WriteLine("\n测试结束 - 内存未释放!"); 32 | #endregion 33 | 34 | //改进版 35 | IntPtr[] handles = new IntPtr[10000]; 36 | for (int i = 0; i < 10000; i++) 37 | { 38 | handles[i] = AllocateMemory(5000); 39 | } 40 | Console.WriteLine($"分配完成,Private Bytes: {GetPrivateBytes()}"); 41 | 42 | 43 | // 正确释放内存 44 | //foreach (IntPtr ptr in handles) 45 | //{ 46 | // FreeMemory(ptr); 47 | //} 48 | 49 | // 释放内存 50 | for (int i = 0; i < handles.Length; i++) 51 | { 52 | FreeMemory(handles[i]); 53 | } 54 | Console.WriteLine($"释放完成,Private Bytes: {GetPrivateBytes()}"); 55 | 56 | Console.ReadLine(); 57 | } 58 | 59 | private static long GetPrivateBytes() 60 | { 61 | using (var process = Process.GetCurrentProcess()) 62 | { 63 | return process.PrivateMemorySize64 / 1024 / 1024; 64 | } 65 | 66 | } 67 | } 68 | 69 | public class SafeBuffer : IDisposable 70 | { 71 | [DllImport("TestMemory.dll")] 72 | public static extern void FreeMemory(IntPtr ptr); 73 | 74 | [DllImport("TestMemory.dll")] 75 | public static extern IntPtr AllocateMemory(int size); 76 | private IntPtr _handle; 77 | 78 | public SafeBuffer(int size) 79 | { 80 | _handle = AllocateMemory(size); 81 | } 82 | 83 | public void Dispose() 84 | { 85 | FreeMemory(_handle); 86 | GC.SuppressFinalize(this); 87 | } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /C#andCpp/TestMemorySharp/TestMemorySharp.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net6.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /C#andCpp/bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LessIsMoreInSZ/bilibiliDemo/c2ae5264474fc77e9db1003f0bbf54248900709c/C#andCpp/bin -------------------------------------------------------------------------------- /CrossProcess/WinFormsApp1/Form1.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace WinFormsApp1 2 | { 3 | partial class Form1 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | /// true if managed resources should be disposed; otherwise, false. 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Windows Form Designer generated code 24 | 25 | /// 26 | /// Required method for Designer support - do not modify 27 | /// the contents of this method with the code editor. 28 | /// 29 | private void InitializeComponent() 30 | { 31 | this.components = new System.ComponentModel.Container(); 32 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 33 | this.ClientSize = new System.Drawing.Size(800, 450); 34 | this.Text = "Form1"; 35 | } 36 | 37 | #endregion 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /CrossProcess/WinFormsApp1/Form1.cs: -------------------------------------------------------------------------------- 1 | namespace WinFormsApp1 2 | { 3 | public partial class Form1 : Form 4 | { 5 | public Form1() 6 | { 7 | InitializeComponent(); 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /CrossProcess/WinFormsApp1/Program.cs: -------------------------------------------------------------------------------- 1 | namespace WinFormsApp1 2 | { 3 | internal static class Program 4 | { 5 | /// 6 | /// The main entry point for the application. 7 | /// 8 | [STAThread] 9 | static void Main() 10 | { 11 | // To customize application configuration such as set high DPI settings or default font, 12 | // see https://aka.ms/applicationconfiguration. 13 | ApplicationConfiguration.Initialize(); 14 | Application.Run(new Form1()); 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /CrossProcess/WinFormsApp1/WinFormsApp1.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | WinExe 5 | net6.0-windows 6 | enable 7 | true 8 | enable 9 | 10 | 11 | -------------------------------------------------------------------------------- /CrossProcess/WpfApp1.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.8.34511.84 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WpfApp1", "WpfApp1\WpfApp1.csproj", "{C1E9F8FA-AEDD-4D53-9E14-EDFD3F1CF0D7}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WpfApp2", "WpfApp2\WpfApp2.csproj", "{A39D212B-CA42-4630-AAD4-90305078E5FC}" 9 | EndProject 10 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WpfApp3", "WpfApp3\WpfApp3.csproj", "{A3D3B0C3-49C4-45C2-A56F-9BE653099663}" 11 | EndProject 12 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinFormsApp1", "WinFormsApp1\WinFormsApp1.csproj", "{613D95A2-94F7-48E7-BA43-77F3716381D4}" 13 | EndProject 14 | Global 15 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 16 | Debug|Any CPU = Debug|Any CPU 17 | Release|Any CPU = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 20 | {C1E9F8FA-AEDD-4D53-9E14-EDFD3F1CF0D7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {C1E9F8FA-AEDD-4D53-9E14-EDFD3F1CF0D7}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {C1E9F8FA-AEDD-4D53-9E14-EDFD3F1CF0D7}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {C1E9F8FA-AEDD-4D53-9E14-EDFD3F1CF0D7}.Release|Any CPU.Build.0 = Release|Any CPU 24 | {A39D212B-CA42-4630-AAD4-90305078E5FC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 25 | {A39D212B-CA42-4630-AAD4-90305078E5FC}.Debug|Any CPU.Build.0 = Debug|Any CPU 26 | {A39D212B-CA42-4630-AAD4-90305078E5FC}.Release|Any CPU.ActiveCfg = Release|Any CPU 27 | {A39D212B-CA42-4630-AAD4-90305078E5FC}.Release|Any CPU.Build.0 = Release|Any CPU 28 | {A3D3B0C3-49C4-45C2-A56F-9BE653099663}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 29 | {A3D3B0C3-49C4-45C2-A56F-9BE653099663}.Debug|Any CPU.Build.0 = Debug|Any CPU 30 | {A3D3B0C3-49C4-45C2-A56F-9BE653099663}.Release|Any CPU.ActiveCfg = Release|Any CPU 31 | {A3D3B0C3-49C4-45C2-A56F-9BE653099663}.Release|Any CPU.Build.0 = Release|Any CPU 32 | {613D95A2-94F7-48E7-BA43-77F3716381D4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 33 | {613D95A2-94F7-48E7-BA43-77F3716381D4}.Debug|Any CPU.Build.0 = Debug|Any CPU 34 | {613D95A2-94F7-48E7-BA43-77F3716381D4}.Release|Any CPU.ActiveCfg = Release|Any CPU 35 | {613D95A2-94F7-48E7-BA43-77F3716381D4}.Release|Any CPU.Build.0 = Release|Any CPU 36 | EndGlobalSection 37 | GlobalSection(SolutionProperties) = preSolution 38 | HideSolutionNode = FALSE 39 | EndGlobalSection 40 | GlobalSection(ExtensibilityGlobals) = postSolution 41 | SolutionGuid = {C62C1A48-F556-4261-BC6E-F1B52FF25DBC} 42 | EndGlobalSection 43 | EndGlobal 44 | -------------------------------------------------------------------------------- /CrossProcess/WpfApp1/App.xaml: -------------------------------------------------------------------------------- 1 |  7 | 8 | 9 | -------------------------------------------------------------------------------- /CrossProcess/WpfApp1/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using System.Configuration; 2 | using System.Data; 3 | using System.Windows; 4 | 5 | namespace WpfApp1 6 | { 7 | /// 8 | /// Interaction logic for App.xaml 9 | /// 10 | public partial class App : System.Windows.Application 11 | { 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /CrossProcess/WpfApp1/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | 3 | [assembly: ThemeInfo( 4 | ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located 5 | //(used if a resource is not found in the page, 6 | // or application resource dictionaries) 7 | ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located 8 | //(used if a resource is not found in the page, 9 | // app, or any theme specific resource dictionaries) 10 | )] 11 | -------------------------------------------------------------------------------- /CrossProcess/WpfApp1/MainWindow.xaml.cs: -------------------------------------------------------------------------------- 1 | using System.Text; 2 | using System.Windows; 3 | using System.Windows.Controls; 4 | using System.Windows.Data; 5 | using System.Windows.Documents; 6 | using System.Windows.Input; 7 | using System.Windows.Media; 8 | using System.Windows.Media.Imaging; 9 | using System.Windows.Navigation; 10 | using System.Windows.Shapes; 11 | 12 | namespace WpfApp1 13 | { 14 | /// 15 | /// Interaction logic for MainWindow.xaml 16 | /// 17 | public partial class MainWindow : Window 18 | { 19 | public MainWindow() 20 | { 21 | InitializeComponent(); 22 | } 23 | 24 | private void Button_Click(object sender, RoutedEventArgs e) 25 | { 26 | //MessageBox.Show("777"); 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /CrossProcess/WpfApp1/MainWindowViewModel.cs: -------------------------------------------------------------------------------- 1 | using Prism.Commands; 2 | using Prism.Mvvm; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | using System.Windows; 9 | using System.Windows.Input; 10 | 11 | namespace WpfApp1 12 | { 13 | public class MainWindowViewModel: BindableBase 14 | { 15 | public ICommand TestCommand 16 | { 17 | get => new DelegateCommand(() => 18 | { 19 | //MessageBox.Show("666"); 20 | }); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /CrossProcess/WpfApp1/Win32API.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Runtime.InteropServices; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace WpfApp1 9 | { 10 | internal class Win32API 11 | { 12 | [DllImport("user32.dll", EntryPoint = "GetWindowThreadProcessId", SetLastError = true, 13 | CharSet = CharSet.Unicode, ExactSpelling = true, 14 | CallingConvention = CallingConvention.StdCall)] 15 | public static extern long GetWindowThreadProcessId(long hWnd, long lpdwProcessId); 16 | 17 | [DllImport("user32.dll", SetLastError = true)] 18 | public static extern IntPtr FindWindow(string lpClassName, string lpWindowName); 19 | 20 | [DllImport("user32.dll", SetLastError = true)] 21 | public static extern int SetParent(IntPtr hWndChild, IntPtr hWndNewParent); 22 | 23 | [DllImport("user32.dll", EntryPoint = "GetWindowLongA", SetLastError = true)] 24 | public static extern long GetWindowLong(IntPtr hwnd, int nIndex); 25 | 26 | public static IntPtr SetWindowLong(HandleRef hWnd, int nIndex, int dwNewLong) 27 | { 28 | if (IntPtr.Size == 4) 29 | { 30 | return SetWindowLongPtr32(hWnd, nIndex, dwNewLong); 31 | } 32 | return SetWindowLongPtr64(hWnd, nIndex, dwNewLong); 33 | } 34 | [DllImport("user32.dll", EntryPoint = "SetWindowLong", CharSet = CharSet.Auto)] 35 | public static extern IntPtr SetWindowLongPtr32(HandleRef hWnd, int nIndex, int dwNewLong); 36 | [DllImport("user32.dll", EntryPoint = "SetWindowLongPtr", CharSet = CharSet.Auto)] 37 | public static extern IntPtr SetWindowLongPtr64(HandleRef hWnd, int nIndex, int dwNewLong); 38 | 39 | [DllImport("user32.dll", SetLastError = true)] 40 | public static extern long SetWindowPos(IntPtr hwnd, long hWndInsertAfter, long x, long y, long cx, long cy, long wFlags); 41 | 42 | [DllImport("user32.dll", SetLastError = true)] 43 | public static extern bool MoveWindow(IntPtr hwnd, int x, int y, int cx, int cy, bool repaint); 44 | 45 | [DllImport("user32.dll", EntryPoint = "PostMessageA", SetLastError = true)] 46 | public static extern bool PostMessage(IntPtr hwnd, uint Msg, uint wParam, uint lParam); 47 | 48 | [System.Runtime.InteropServices.DllImport("Kernel32.dll")] 49 | public extern static int FormatMessage(int flag, ref IntPtr source, int msgid, int langid, ref string buf, int size, ref IntPtr args); 50 | 51 | 52 | [DllImport("user32.dll", SetLastError = true)] 53 | public static extern IntPtr GetParent(IntPtr hwnd); 54 | 55 | [DllImport("user32.dll", EntryPoint = "ShowWindow", SetLastError = true)] 56 | public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow); 57 | 58 | 59 | public const int SWP_NOOWNERZORDER = 0x200; 60 | public const int SWP_NOREDRAW = 0x8; 61 | public const int SWP_NOZORDER = 0x4; 62 | public const int SWP_SHOWWINDOW = 0x0040; 63 | public const int WS_EX_MDICHILD = 0x40; 64 | public const int SWP_FRAMECHANGED = 0x20; 65 | public const int SWP_NOACTIVATE = 0x10; 66 | public const int SWP_ASYNCWINDOWPOS = 0x4000; 67 | public const int SWP_NOMOVE = 0x2; 68 | public const int SWP_NOSIZE = 0x1; 69 | public const int GWL_STYLE = (-16); 70 | public const int WS_VISIBLE = 0x10000000; 71 | public const int WM_CLOSE = 0x10; 72 | public const int WS_CHILD = 0x40000000; 73 | 74 | public const int SW_HIDE = 0; //{隐藏, 并且任务栏也没有最小化图标} 75 | public const int SW_SHOWNORMAL = 1; //{用最近的大小和位置显示, 激活} 76 | public const int SW_NORMAL = 1; //{同 SW_SHOWNORMAL} 77 | public const int SW_SHOWMINIMIZED = 2; //{最小化, 激活} 78 | public const int SW_SHOWMAXIMIZED = 3; //{最大化, 激活} 79 | public const int SW_MAXIMIZE = 3; //{同 SW_SHOWMAXIMIZED} 80 | public const int SW_SHOWNOACTIVATE = 4; //{用最近的大小和位置显示, 不激活} 81 | public const int SW_SHOW = 5; //{同 SW_SHOWNORMAL} 82 | public const int SW_MINIMIZE = 6; //{最小化, 不激活} 83 | public const int SW_SHOWMINNOACTIVE = 7; //{同 SW_MINIMIZE} 84 | public const int SW_SHOWNA = 8; //{同 SW_SHOWNOACTIVATE} 85 | public const int SW_RESTORE = 9; //{同 SW_SHOWNORMAL} 86 | public const int SW_SHOWDEFAULT = 10; //{同 SW_SHOWNORMAL} 87 | public const int SW_MAX = 10; //{同 SW_SHOWNORMAL} 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /CrossProcess/WpfApp1/Window1.xaml: -------------------------------------------------------------------------------- 1 |  11 | 12 | 13 | 14 | 15 | 16 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /CrossProcess/WpfApp1/Window1.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Windows; 7 | using System.Windows.Controls; 8 | using System.Windows.Data; 9 | using System.Windows.Documents; 10 | using System.Windows.Input; 11 | using System.Windows.Media; 12 | using System.Windows.Media.Imaging; 13 | using System.Windows.Shapes; 14 | 15 | namespace WpfApp1 16 | { 17 | /// 18 | /// Window1.xaml 的交互逻辑 19 | /// 20 | public partial class Window1 : Window 21 | { 22 | public Window1() 23 | { 24 | //InitializeComponent(); 25 | 26 | //IntPtr hw = Win32API.FindWindow("Chrome_WidgetWin_0", "迅雷"); //第一参数是类名,第二个是窗口标题 27 | //Win32API.MoveWindow(hw, 0, 0, pannel_exe.Width, pannel_exe.Height, true); 28 | //Win32API.SetParent(hw, pannel_exe.Handle); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /CrossProcess/WpfApp1/Window2.xaml: -------------------------------------------------------------------------------- 1 |  12 | 13 | 14 | 15 | 16 | 17 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /CrossProcess/WpfApp1/Window2.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Windows; 7 | using System.Windows.Controls; 8 | using System.Windows.Data; 9 | using System.Windows.Documents; 10 | using System.Windows.Input; 11 | using System.Windows.Media; 12 | using System.Windows.Media.Imaging; 13 | using System.Windows.Shapes; 14 | 15 | namespace WpfApp1 16 | { 17 | /// 18 | /// Window2.xaml 的交互逻辑 19 | /// 20 | public partial class Window2 : Window 21 | { 22 | public Window2() 23 | { 24 | InitializeComponent(); 25 | 26 | 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /CrossProcess/WpfApp1/WpfApp1.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | WinExe 5 | net6.0-windows 6 | enable 7 | enable 8 | true 9 | true 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /CrossProcess/WpfApp1/pack/System.Windows.Forms.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LessIsMoreInSZ/bilibiliDemo/c2ae5264474fc77e9db1003f0bbf54248900709c/CrossProcess/WpfApp1/pack/System.Windows.Forms.dll -------------------------------------------------------------------------------- /CrossProcess/WpfApp1/pack/WindowsFormsIntegration.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LessIsMoreInSZ/bilibiliDemo/c2ae5264474fc77e9db1003f0bbf54248900709c/CrossProcess/WpfApp1/pack/WindowsFormsIntegration.dll -------------------------------------------------------------------------------- /CrossProcess/WpfApp2/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /CrossProcess/WpfApp2/App.xaml: -------------------------------------------------------------------------------- 1 |  6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /CrossProcess/WpfApp2/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Configuration; 4 | using System.Data; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | using System.Windows; 8 | 9 | namespace WpfApp2 10 | { 11 | /// 12 | /// App.xaml 的交互逻辑 13 | /// 14 | public partial class App : Application 15 | { 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /CrossProcess/WpfApp2/MainWindow.xaml: -------------------------------------------------------------------------------- 1 |  14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 26 | 27 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /CrossProcess/WpfApp2/MainWindow.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Windows; 7 | using System.Windows.Controls; 8 | using System.Windows.Data; 9 | using System.Windows.Documents; 10 | using System.Windows.Input; 11 | using System.Windows.Media; 12 | using System.Windows.Media.Imaging; 13 | using System.Windows.Navigation; 14 | using System.Windows.Shapes; 15 | 16 | namespace WpfApp2 17 | { 18 | /// 19 | /// MainWindow.xaml 的交互逻辑 20 | /// 21 | public partial class MainWindow : Window 22 | { 23 | public MainWindow() 24 | { 25 | InitializeComponent(); 26 | //IntPtr hw = Win32API.FindWindow("Chrome_WidgetWin_0", "迅雷"); //第一参数是类名,第二个是窗口标题 27 | IntPtr hw = Win32API.FindWindow(null, "无标题 - 记事本"); //第一参数是类名,第二个是窗口标题 28 | Win32API.MoveWindow(hw, 0, 0, pannel_exe.Width, pannel_exe.Height, true); 29 | Win32API.SetParent(hw, pannel_exe.Handle); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /CrossProcess/WpfApp2/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Resources; 3 | using System.Runtime.CompilerServices; 4 | using System.Runtime.InteropServices; 5 | using System.Windows; 6 | 7 | // 有关程序集的一般信息由以下 8 | // 控制。更改这些特性值可修改 9 | // 与程序集关联的信息。 10 | [assembly: AssemblyTitle("WpfApp2")] 11 | [assembly: AssemblyDescription("")] 12 | [assembly: AssemblyConfiguration("")] 13 | [assembly: AssemblyCompany("")] 14 | [assembly: AssemblyProduct("WpfApp2")] 15 | [assembly: AssemblyCopyright("Copyright © 2024")] 16 | [assembly: AssemblyTrademark("")] 17 | [assembly: AssemblyCulture("")] 18 | 19 | // 将 ComVisible 设置为 false 会使此程序集中的类型 20 | //对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 21 | //请将此类型的 ComVisible 特性设置为 true。 22 | [assembly: ComVisible(false)] 23 | 24 | //若要开始生成可本地化的应用程序,请设置 25 | //.csproj 文件中的 CultureYouAreCodingWith 26 | //在 中。例如,如果你使用的是美国英语。 27 | //使用的是美国英语,请将 设置为 en-US。 然后取消 28 | //对以下 NeutralResourceLanguage 特性的注释。 更新 29 | //以下行中的“en-US”以匹配项目文件中的 UICulture 设置。 30 | 31 | //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] 32 | 33 | 34 | [assembly: ThemeInfo( 35 | ResourceDictionaryLocation.None, //主题特定资源词典所处位置 36 | //(未在页面中找到资源时使用, 37 | //或应用程序资源字典中找到时使用) 38 | ResourceDictionaryLocation.SourceAssembly //常规资源词典所处位置 39 | //(未在页面中找到资源时使用, 40 | //、应用程序或任何主题专用资源字典中找到时使用) 41 | )] 42 | 43 | 44 | // 程序集的版本信息由下列四个值组成: 45 | // 46 | // 主版本 47 | // 次版本 48 | // 生成号 49 | // 修订号 50 | // 51 | //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值 52 | //通过使用 "*",如下所示: 53 | // [assembly: AssemblyVersion("1.0.*")] 54 | [assembly: AssemblyVersion("1.0.0.0")] 55 | [assembly: AssemblyFileVersion("1.0.0.0")] 56 | -------------------------------------------------------------------------------- /CrossProcess/WpfApp2/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // 此代码由工具生成。 4 | // 运行时版本: 4.0.30319.42000 5 | // 6 | // 对此文件的更改可能导致不正确的行为,如果 7 | // 重新生成代码,则所做更改将丢失。 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace WpfApp2.Properties 12 | { 13 | 14 | 15 | /// 16 | /// 强类型资源类,用于查找本地化字符串等。 17 | /// 18 | // 此类是由 StronglyTypedResourceBuilder 19 | // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 20 | // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen 21 | // (以 /str 作为命令选项),或重新生成 VS 项目。 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources 26 | { 27 | 28 | private static global::System.Resources.ResourceManager resourceMan; 29 | 30 | private static global::System.Globalization.CultureInfo resourceCulture; 31 | 32 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 33 | internal Resources() 34 | { 35 | } 36 | 37 | /// 38 | /// 返回此类使用的缓存 ResourceManager 实例。 39 | /// 40 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 41 | internal static global::System.Resources.ResourceManager ResourceManager 42 | { 43 | get 44 | { 45 | if ((resourceMan == null)) 46 | { 47 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("WpfApp2.Properties.Resources", typeof(Resources).Assembly); 48 | resourceMan = temp; 49 | } 50 | return resourceMan; 51 | } 52 | } 53 | 54 | /// 55 | /// 重写当前线程的 CurrentUICulture 属性,对 56 | /// 使用此强类型资源类的所有资源查找执行重写。 57 | /// 58 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 59 | internal static global::System.Globalization.CultureInfo Culture 60 | { 61 | get 62 | { 63 | return resourceCulture; 64 | } 65 | set 66 | { 67 | resourceCulture = value; 68 | } 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /CrossProcess/WpfApp2/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace WpfApp2.Properties 12 | { 13 | 14 | 15 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 16 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] 17 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase 18 | { 19 | 20 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 21 | 22 | public static Settings Default 23 | { 24 | get 25 | { 26 | return defaultInstance; 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /CrossProcess/WpfApp2/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /CrossProcess/WpfApp2/Win32API.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Runtime.InteropServices; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace WpfApp2 9 | { 10 | internal class Win32API 11 | { 12 | [DllImport("user32.dll", EntryPoint = "GetWindowThreadProcessId", SetLastError = true, 13 | CharSet = CharSet.Unicode, ExactSpelling = true, 14 | CallingConvention = CallingConvention.StdCall)] 15 | public static extern long GetWindowThreadProcessId(long hWnd, long lpdwProcessId); 16 | 17 | [DllImport("user32.dll", SetLastError = true)] 18 | public static extern IntPtr FindWindow(string lpClassName, string lpWindowName); 19 | 20 | [DllImport("user32.dll", SetLastError = true)] 21 | public static extern int SetParent(IntPtr hWndChild, IntPtr hWndNewParent); 22 | 23 | [DllImport("user32.dll", EntryPoint = "GetWindowLongA", SetLastError = true)] 24 | public static extern long GetWindowLong(IntPtr hwnd, int nIndex); 25 | 26 | public static IntPtr SetWindowLong(HandleRef hWnd, int nIndex, int dwNewLong) 27 | { 28 | if (IntPtr.Size == 4) 29 | { 30 | return SetWindowLongPtr32(hWnd, nIndex, dwNewLong); 31 | } 32 | return SetWindowLongPtr64(hWnd, nIndex, dwNewLong); 33 | } 34 | [DllImport("user32.dll", EntryPoint = "SetWindowLong", CharSet = CharSet.Auto)] 35 | public static extern IntPtr SetWindowLongPtr32(HandleRef hWnd, int nIndex, int dwNewLong); 36 | [DllImport("user32.dll", EntryPoint = "SetWindowLongPtr", CharSet = CharSet.Auto)] 37 | public static extern IntPtr SetWindowLongPtr64(HandleRef hWnd, int nIndex, int dwNewLong); 38 | 39 | [DllImport("user32.dll", SetLastError = true)] 40 | public static extern long SetWindowPos(IntPtr hwnd, long hWndInsertAfter, long x, long y, long cx, long cy, long wFlags); 41 | 42 | [DllImport("user32.dll", SetLastError = true)] 43 | public static extern bool MoveWindow(IntPtr hwnd, int x, int y, int cx, int cy, bool repaint); 44 | 45 | [DllImport("user32.dll", EntryPoint = "PostMessageA", SetLastError = true)] 46 | public static extern bool PostMessage(IntPtr hwnd, uint Msg, uint wParam, uint lParam); 47 | 48 | [System.Runtime.InteropServices.DllImport("Kernel32.dll")] 49 | public extern static int FormatMessage(int flag, ref IntPtr source, int msgid, int langid, ref string buf, int size, ref IntPtr args); 50 | 51 | 52 | [DllImport("user32.dll", SetLastError = true)] 53 | public static extern IntPtr GetParent(IntPtr hwnd); 54 | 55 | [DllImport("user32.dll", EntryPoint = "ShowWindow", SetLastError = true)] 56 | public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow); 57 | 58 | 59 | public const int SWP_NOOWNERZORDER = 0x200; 60 | public const int SWP_NOREDRAW = 0x8; 61 | public const int SWP_NOZORDER = 0x4; 62 | public const int SWP_SHOWWINDOW = 0x0040; 63 | public const int WS_EX_MDICHILD = 0x40; 64 | public const int SWP_FRAMECHANGED = 0x20; 65 | public const int SWP_NOACTIVATE = 0x10; 66 | public const int SWP_ASYNCWINDOWPOS = 0x4000; 67 | public const int SWP_NOMOVE = 0x2; 68 | public const int SWP_NOSIZE = 0x1; 69 | public const int GWL_STYLE = (-16); 70 | public const int WS_VISIBLE = 0x10000000; 71 | public const int WM_CLOSE = 0x10; 72 | public const int WS_CHILD = 0x40000000; 73 | 74 | public const int SW_HIDE = 0; //{隐藏, 并且任务栏也没有最小化图标} 75 | public const int SW_SHOWNORMAL = 1; //{用最近的大小和位置显示, 激活} 76 | public const int SW_NORMAL = 1; //{同 SW_SHOWNORMAL} 77 | public const int SW_SHOWMINIMIZED = 2; //{最小化, 激活} 78 | public const int SW_SHOWMAXIMIZED = 3; //{最大化, 激活} 79 | public const int SW_MAXIMIZE = 3; //{同 SW_SHOWMAXIMIZED} 80 | public const int SW_SHOWNOACTIVATE = 4; //{用最近的大小和位置显示, 不激活} 81 | public const int SW_SHOW = 5; //{同 SW_SHOWNORMAL} 82 | public const int SW_MINIMIZE = 6; //{最小化, 不激活} 83 | public const int SW_SHOWMINNOACTIVE = 7; //{同 SW_MINIMIZE} 84 | public const int SW_SHOWNA = 8; //{同 SW_SHOWNOACTIVATE} 85 | public const int SW_RESTORE = 9; //{同 SW_SHOWNORMAL} 86 | public const int SW_SHOWDEFAULT = 10; //{同 SW_SHOWNORMAL} 87 | public const int SW_MAX = 10; //{同 SW_SHOWNORMAL} 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /CrossProcess/WpfApp3/App.xaml: -------------------------------------------------------------------------------- 1 |  6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /CrossProcess/WpfApp3/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using System.Configuration; 2 | using System.Data; 3 | using System.Windows; 4 | 5 | namespace WpfApp3 6 | { 7 | /// 8 | /// Interaction logic for App.xaml 9 | /// 10 | public partial class App : System.Windows.Application 11 | { 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /CrossProcess/WpfApp3/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | 3 | [assembly: ThemeInfo( 4 | ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located 5 | //(used if a resource is not found in the page, 6 | // or application resource dictionaries) 7 | ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located 8 | //(used if a resource is not found in the page, 9 | // app, or any theme specific resource dictionaries) 10 | )] 11 | -------------------------------------------------------------------------------- /CrossProcess/WpfApp3/MainWindow.xaml: -------------------------------------------------------------------------------- 1 |  14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 26 | 27 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /CrossProcess/WpfApp3/Win32API.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Runtime.InteropServices; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace WpfApp3 9 | { 10 | internal class Win32API 11 | { 12 | [DllImport("user32.dll", EntryPoint = "GetWindowThreadProcessId", SetLastError = true, 13 | CharSet = CharSet.Unicode, ExactSpelling = true, 14 | CallingConvention = CallingConvention.StdCall)] 15 | public static extern long GetWindowThreadProcessId(long hWnd, long lpdwProcessId); 16 | 17 | [DllImport("user32.dll", SetLastError = true)] 18 | public static extern IntPtr FindWindow(string lpClassName, string lpWindowName); 19 | 20 | [DllImport("user32.dll", SetLastError = true)] 21 | public static extern int SetParent(IntPtr hWndChild, IntPtr hWndNewParent); 22 | 23 | [DllImport("user32.dll", EntryPoint = "GetWindowLongA", SetLastError = true)] 24 | public static extern long GetWindowLong(IntPtr hwnd, int nIndex); 25 | 26 | public static IntPtr SetWindowLong(HandleRef hWnd, int nIndex, int dwNewLong) 27 | { 28 | if (IntPtr.Size == 4) 29 | { 30 | return SetWindowLongPtr32(hWnd, nIndex, dwNewLong); 31 | } 32 | return SetWindowLongPtr64(hWnd, nIndex, dwNewLong); 33 | } 34 | [DllImport("user32.dll", EntryPoint = "SetWindowLong", CharSet = CharSet.Auto)] 35 | public static extern IntPtr SetWindowLongPtr32(HandleRef hWnd, int nIndex, int dwNewLong); 36 | [DllImport("user32.dll", EntryPoint = "SetWindowLongPtr", CharSet = CharSet.Auto)] 37 | public static extern IntPtr SetWindowLongPtr64(HandleRef hWnd, int nIndex, int dwNewLong); 38 | 39 | [DllImport("user32.dll", SetLastError = true)] 40 | public static extern long SetWindowPos(IntPtr hwnd, long hWndInsertAfter, long x, long y, long cx, long cy, long wFlags); 41 | 42 | [DllImport("user32.dll", SetLastError = true)] 43 | public static extern bool MoveWindow(IntPtr hwnd, int x, int y, int cx, int cy, bool repaint); 44 | 45 | [DllImport("user32.dll", EntryPoint = "PostMessageA", SetLastError = true)] 46 | public static extern bool PostMessage(IntPtr hwnd, uint Msg, uint wParam, uint lParam); 47 | 48 | [System.Runtime.InteropServices.DllImport("Kernel32.dll")] 49 | public extern static int FormatMessage(int flag, ref IntPtr source, int msgid, int langid, ref string buf, int size, ref IntPtr args); 50 | 51 | 52 | [DllImport("user32.dll", SetLastError = true)] 53 | public static extern IntPtr GetParent(IntPtr hwnd); 54 | 55 | [DllImport("user32.dll", EntryPoint = "ShowWindow", SetLastError = true)] 56 | public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow); 57 | 58 | 59 | public const int SWP_NOOWNERZORDER = 0x200; 60 | public const int SWP_NOREDRAW = 0x8; 61 | public const int SWP_NOZORDER = 0x4; 62 | public const int SWP_SHOWWINDOW = 0x0040; 63 | public const int WS_EX_MDICHILD = 0x40; 64 | public const int SWP_FRAMECHANGED = 0x20; 65 | public const int SWP_NOACTIVATE = 0x10; 66 | public const int SWP_ASYNCWINDOWPOS = 0x4000; 67 | public const int SWP_NOMOVE = 0x2; 68 | public const int SWP_NOSIZE = 0x1; 69 | public const int GWL_STYLE = (-16); 70 | public const int WS_VISIBLE = 0x10000000; 71 | public const int WM_CLOSE = 0x10; 72 | public const int WS_CHILD = 0x40000000; 73 | 74 | public const int SW_HIDE = 0; //{隐藏, 并且任务栏也没有最小化图标} 75 | public const int SW_SHOWNORMAL = 1; //{用最近的大小和位置显示, 激活} 76 | public const int SW_NORMAL = 1; //{同 SW_SHOWNORMAL} 77 | public const int SW_SHOWMINIMIZED = 2; //{最小化, 激活} 78 | public const int SW_SHOWMAXIMIZED = 3; //{最大化, 激活} 79 | public const int SW_MAXIMIZE = 3; //{同 SW_SHOWMAXIMIZED} 80 | public const int SW_SHOWNOACTIVATE = 4; //{用最近的大小和位置显示, 不激活} 81 | public const int SW_SHOW = 5; //{同 SW_SHOWNORMAL} 82 | public const int SW_MINIMIZE = 6; //{最小化, 不激活} 83 | public const int SW_SHOWMINNOACTIVE = 7; //{同 SW_MINIMIZE} 84 | public const int SW_SHOWNA = 8; //{同 SW_SHOWNOACTIVATE} 85 | public const int SW_RESTORE = 9; //{同 SW_SHOWNORMAL} 86 | public const int SW_SHOWDEFAULT = 10; //{同 SW_SHOWNORMAL} 87 | public const int SW_MAX = 10; //{同 SW_SHOWNORMAL} 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /CrossProcess/WpfApp3/WpfApp3.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | WinExe 5 | net6.0-windows 6 | enable 7 | enable 8 | true 9 | true 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /ElsaDemo/ElsaDemo/ElsaDemo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net6.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /ElsaDemo/ElsaDemo/ElsaDemo.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.12.35707.178 d17.12 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ElsaDemo", "ElsaDemo.csproj", "{D24BAD44-0A89-4D92-907B-0F14F9774FB7}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {D24BAD44-0A89-4D92-907B-0F14F9774FB7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {D24BAD44-0A89-4D92-907B-0F14F9774FB7}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {D24BAD44-0A89-4D92-907B-0F14F9774FB7}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {D24BAD44-0A89-4D92-907B-0F14F9774FB7}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /ElsaDemo/ElsaDemo/Program.cs: -------------------------------------------------------------------------------- 1 | namespace ElsaDemo 2 | { 3 | internal class Program 4 | { 5 | static void Main(string[] args) 6 | { 7 | Console.WriteLine("Hello, World!"); 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /NTP/In-Sight相机和服务器时间同步NTP设置的说明 v1.0-for WIN7 64.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LessIsMoreInSZ/bilibiliDemo/c2ae5264474fc77e9db1003f0bbf54248900709c/NTP/In-Sight相机和服务器时间同步NTP设置的说明 v1.0-for WIN7 64.docx -------------------------------------------------------------------------------- /NTP/Start NTP as client.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | :: 关闭Windows时间服务 4 | net stop w32time 5 | :: 启动Windows时间服务 6 | net start w32time 7 | 8 | :: 设置NTP服务器地址 9 | w32tm /config /manualpeerlist:"192.168.1.61" /syncfromflags:manual /reliable:YES /update 10 | 11 | :: 设置自动同步间隔为15min 12 | :: 注意:实际有效间隔可能受系统策略和Windows服务限制 13 | reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\TimeProviders\NtpClient" /v SpecialPollInterval /t REG_DWORD /d 900 /f 14 | 15 | :: 使更改生效 16 | w32tm /config /update 17 | 18 | :: 触发立即时间同步 19 | w32tm /resync 20 | pause -------------------------------------------------------------------------------- /NTP/Start NTP as server.bat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LessIsMoreInSZ/bilibiliDemo/c2ae5264474fc77e9db1003f0bbf54248900709c/NTP/Start NTP as server.bat -------------------------------------------------------------------------------- /NTP/客户端图片.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LessIsMoreInSZ/bilibiliDemo/c2ae5264474fc77e9db1003f0bbf54248900709c/NTP/客户端图片.png -------------------------------------------------------------------------------- /Quartz/Quartz.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.12.35707.178 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QuartzTest", "..\..\..\开源代码\Quartz-main\Quartz-main\QuartzTest\QuartzTest\QuartzTest.csproj", "{7C28E614-4BDF-41AA-A521-6FAE7FCEF53E}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {7C28E614-4BDF-41AA-A521-6FAE7FCEF53E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {7C28E614-4BDF-41AA-A521-6FAE7FCEF53E}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {7C28E614-4BDF-41AA-A521-6FAE7FCEF53E}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {7C28E614-4BDF-41AA-A521-6FAE7FCEF53E}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /Quartz/QuartzTest/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /Quartz/QuartzTest/JobLgoTask.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading; 6 | using System.Threading.Tasks; 7 | using Quartz; 8 | namespace QuartzTest 9 | { 10 | //DisallowConcurrentExecution 11 | [PersistJobDataAfterExecution,DisallowConcurrentExecution] 12 | class JobLgoTask : IJob 13 | { 14 | public string Name { get; set; } 15 | public string Age { get; set; } 16 | 17 | public string IsRun { get; set; } 18 | 19 | 20 | public async Task Execute(IJobExecutionContext context) 21 | { 22 | await Console.Out.WriteAsync(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")); 23 | await Console.Out.WriteLineAsync($"name:{Name},age:{Age},IsRun:{IsRun}"); 24 | context.JobDetail.JobDataMap["Age"] = Convert.ToInt32(Age) + 1; 25 | Thread.Sleep(2000); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Quartz/QuartzTest/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 有关程序集的一般信息由以下 6 | // 控制。更改这些特性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("QuartzTest")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("HP Inc.")] 12 | [assembly: AssemblyProduct("QuartzTest")] 13 | [assembly: AssemblyCopyright("Copyright © HP Inc. 2021")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // 将 ComVisible 设置为 false 会使此程序集中的类型 18 | //对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 19 | //请将此类型的 ComVisible 特性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID 23 | [assembly: Guid("7c28e614-4bdf-41aa-a521-6fae7fcef53e")] 24 | 25 | // 程序集的版本信息由下列四个值组成: 26 | // 27 | // 主版本 28 | // 次版本 29 | // 生成号 30 | // 修订号 31 | // 32 | //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值 33 | //通过使用 "*",如下所示: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /Quartz/QuartzTest/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /Quartz/Quartz用法学习.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LessIsMoreInSZ/bilibiliDemo/c2ae5264474fc77e9db1003f0bbf54248900709c/Quartz/Quartz用法学习.pdf -------------------------------------------------------------------------------- /README.en.md: -------------------------------------------------------------------------------- 1 | # 酱醋茶演示demo 2 | 3 | #### Description 4 | 平时演示的一些demo 5 | 6 | 7 | #### Software Architecture 8 | Software architecture description 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Hello Industrial Control People 2 | 3 | ## 起因 4 | 5 | 之前一直有朋友让我给演示代码,老是弄忘记了,现在决定将自己平时积累分享的代码总结到这个仓库里。 6 | 7 | 8 | ## BiliBili 9 | 10 | 11 | ``` 12 | AutofacDemo 依赖注入demo 13 | C#andCpp C# 和cpp使用pinvoke技术通信demo 14 | dump 自动创建转储文件demo 15 | TestAvRegion wpf使用AVDock内置region demo 16 | WPFCustomChart wpf自定义图表 demo 17 | CrossProcess 展示不同.NET版本间的跨进程调用 18 | ThreadTest 多线程专用demo 19 | 20 | ``` 21 | -------------------------------------------------------------------------------- /RuleEngine/NewRuleEngine/NewRuleEngine.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net6.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /RuleEngine/RuleEngine/Program.cs: -------------------------------------------------------------------------------- 1 | using RulesEngine.Models; 2 | using Newtonsoft.Json; 3 | 4 | namespace RuleEngine 5 | { 6 | class Program 7 | { 8 | static async Task Main1(string[] args) 9 | { 10 | //模拟用户的输入内容 11 | var userInput = new UserInput 12 | { 13 | IdNo = null, 14 | Age = 18 15 | }; 16 | 17 | 18 | //定义规则 19 | var rulesStr = @"[{ 20 | ""WorkflowName"": ""UserInputWorkflow"", 21 | ""Rules"": [ 22 | { 23 | ""RuleName"": ""CheckAge"", 24 | ""ErrorMessage"": ""年龄必须大于18岁."", 25 | ""ErrorType"": ""Error"", 26 | ""RuleExpressionType"": ""LambdaExpression"", 27 | ""Expression"": ""Age > 18"" 28 | }, 29 | { 30 | ""RuleName"": ""CheckIDNoIsEmpty"", 31 | ""ErrorMessage"": ""身份证号不可以为空."", 32 | ""ErrorType"": ""Error"", 33 | ""RuleExpressionType"": ""LambdaExpression"", 34 | ""Expression"": ""IdNo != null"" 35 | } 36 | ] 37 | }] "; 38 | 39 | 40 | 41 | //反序列化Json格式规则字符串 42 | 43 | var workflowRules = JsonConvert.DeserializeObject>(rulesStr); 44 | //初始化规则引擎 45 | var rulesEngine = new RulesEngine.RulesEngine(workflowRules.ToArray()); 46 | 47 | //使用规则进行判断,并返回结果 48 | List resultList = await rulesEngine.ExecuteAllRulesAsync("UserInputWorkflow", userInput); 49 | 50 | //返回结果并展示 51 | foreach (var item in resultList) 52 | { 53 | Console.WriteLine("验证成功:{0},消息:{1}", item.IsSuccess, item.ExceptionMessage); 54 | } 55 | 56 | //RulesEngine.Models.Rule 57 | 58 | Console.ReadLine(); 59 | } 60 | } 61 | 62 | public class UserInput 63 | { 64 | public string IdNo { get; set; } 65 | public int Age { get; set; } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /RuleEngine/RuleEngine/RuleEngine.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net6.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | Always 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /RuleEngine/RuleEngine/RuleEngine.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.12.35707.178 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RuleEngine", "RuleEngine.csproj", "{40BA27EC-AEBC-4683-9657-035FFCD50EC8}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NewRuleEngine", "..\NewRuleEngine\NewRuleEngine.csproj", "{0F4F02AD-46AC-4AE2-85A8-7A69A2B578B2}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Release|Any CPU = Release|Any CPU 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {40BA27EC-AEBC-4683-9657-035FFCD50EC8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {40BA27EC-AEBC-4683-9657-035FFCD50EC8}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {40BA27EC-AEBC-4683-9657-035FFCD50EC8}.Release|Any CPU.ActiveCfg = Release|Any CPU 19 | {40BA27EC-AEBC-4683-9657-035FFCD50EC8}.Release|Any CPU.Build.0 = Release|Any CPU 20 | {0F4F02AD-46AC-4AE2-85A8-7A69A2B578B2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {0F4F02AD-46AC-4AE2-85A8-7A69A2B578B2}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {0F4F02AD-46AC-4AE2-85A8-7A69A2B578B2}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {0F4F02AD-46AC-4AE2-85A8-7A69A2B578B2}.Release|Any CPU.Build.0 = Release|Any CPU 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | EndGlobal 29 | -------------------------------------------------------------------------------- /RuleEngine/RuleEngine/Test2.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using RulesEngine.Models; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace RuleEngine 10 | { 11 | class Program2 12 | { 13 | private static readonly RulesEngine.Models.ReSettings reSettings = new RulesEngine.Models.ReSettings 14 | { 15 | CustomTypes = new[] { typeof(IdCardUtil) } 16 | }; 17 | 18 | static async Task Main2(string[] args) 19 | { 20 | //模拟用户的输入内容 21 | var userInput = new UserInput 22 | { 23 | IdNo = null, 24 | Age = 18 25 | }; 26 | 27 | 28 | //定义规则 29 | // ""Expression"": ""IdNo.GetAgeByIdCard() < 18"" ,这一句可以和下面判断方法是相同的 30 | var rulesStr = @"[{ 31 | ""WorkflowName"": ""UserInputWorkflow"", 32 | ""Rules"": [ 33 | { 34 | ""RuleName"": ""CheckAge"", 35 | ""ErrorMessage"": ""年龄必须大于18岁."", 36 | ""ErrorType"": ""Error"", 37 | ""RuleExpressionType"": ""LambdaExpression"", 38 | ""Expression"": ""IdCardUtil.getAgeByIdCardNo(IdNo) < 18"" 39 | }, 40 | { 41 | ""RuleName"": ""CheckIDNoIsEmpty"", 42 | ""ErrorMessage"": ""身份证号不可以为空."", 43 | ""ErrorType"": ""Error"", 44 | ""RuleExpressionType"": ""LambdaExpression"", 45 | ""Expression"": ""IdNo != null"" 46 | } 47 | ] 48 | }] "; 49 | 50 | 51 | 52 | //反序列化Json格式规则字符串 53 | var workflowRules = JsonConvert.DeserializeObject>(rulesStr); 54 | 55 | //初始化规则引擎 56 | var rulesEngine = new RulesEngine.RulesEngine(workflowRules.ToArray(), reSettings); 57 | 58 | 59 | 60 | //使用规则进行判断,并返回结果 61 | List resultList = await rulesEngine.ExecuteAllRulesAsync("UserInputWorkflow", userInput); 62 | 63 | //返回结果并展示 64 | foreach (var item in resultList) 65 | { 66 | Console.WriteLine("验证成功:{0},消息:{1}", item.IsSuccess, item.ExceptionMessage); 67 | } 68 | 69 | Console.ReadLine(); 70 | } 71 | } 72 | 73 | 74 | 75 | public static class IdCardUtil 76 | { 77 | //此处使用了C#的方法扩展 78 | public static int GetAgeByIdCard(this string str) 79 | { 80 | //假设进行了相关处理,得到结果 81 | return 45; 82 | } 83 | 84 | //此处是正常的业务逻辑方法 85 | public static int getAgeByIdCardNo(string str) 86 | { 87 | return 50; 88 | } 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /RuleEngine/RuleEngine/Test3.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using RulesEngine.Models; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace RuleEngine 10 | { 11 | class Program3 12 | { 13 | private static readonly RulesEngine.Models.ReSettings reSettings = new RulesEngine.Models.ReSettings 14 | { 15 | CustomTypes = new[] { typeof(IdCardUtil) } 16 | }; 17 | 18 | static async Task Main(string[] args) 19 | { 20 | //模拟用户的输入内容 21 | var userInput = new UserInput 22 | { 23 | IdNo = null, 24 | Age = 18 25 | }; 26 | 27 | 28 | //定义规则 29 | // ""Expression"": ""IdNo.GetAgeByIdCard() < 18"" ,这一句可以和下面判断方法是相同的 30 | //var rulesStr = @"[{ 31 | // ""WorkflowName"": ""UserInputWorkflow"", 32 | // ""Rules"": [ 33 | // { 34 | // ""RuleName"": ""CheckAge"", 35 | // ""ErrorMessage"": ""年龄必须大于18岁."", 36 | // ""ErrorType"": ""Error"", 37 | // ""localParams"": [ 38 | // { 39 | // ""Name"": ""model1"", 40 | // ""Expression"": ""Age!=0"" 41 | // }, 42 | // { 43 | // ""Name"": ""model2"", 44 | // ""Expression"": ""IdCardUtil.getAgeByIdCardNo(Test.IdNo) < 18"" 45 | // } 46 | // ], 47 | // ""RuleExpressionType"": ""LambdaExpression"", 48 | // ""Expression"": ""model1 AND model2"" 49 | // }, 50 | // { 51 | // ""RuleName"": ""CheckIDNoIsEmpty"", 52 | // ""ErrorMessage"": ""身份证号不可以为空."", 53 | // ""ErrorType"": ""Error"", 54 | // ""RuleExpressionType"": ""LambdaExpression"", 55 | // ""Expression"": ""IdNo != null "" 56 | // } 57 | // ] 58 | // }] "; 59 | 60 | 61 | 62 | string filePath = "Test3.json"; // 文件路径 63 | string rulesStr = File.ReadAllText(filePath); 64 | 65 | RulesEngine.Models.RuleParameter ruleParameter = new RulesEngine.Models.RuleParameter("Test", userInput); 66 | 67 | //反序列化Json格式规则字符串 68 | var workflowRules = JsonConvert.DeserializeObject>(rulesStr); 69 | 70 | //初始化规则引擎 71 | var rulesEngine = new RulesEngine.RulesEngine(workflowRules.ToArray(), reSettings); 72 | 73 | 74 | 75 | //使用规则进行判断,并返回结果 76 | List resultList = await rulesEngine.ExecuteAllRulesAsync("UserInputWorkflow", ruleParameter); 77 | 78 | //返回结果并展示 79 | foreach (var item in resultList) 80 | { 81 | Console.WriteLine("验证成功:{0},消息:{1}", item.IsSuccess, item.ExceptionMessage); 82 | } 83 | 84 | Console.ReadLine(); 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /RuleEngine/RuleEngine/Test3.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "WorkflowName": "UserInputWorkflow", 4 | "Rules": [ 5 | { 6 | "RuleName": "CheckAge", 7 | "ErrorMessage": "年龄必须大于18岁.", 8 | "ErrorType": "Error", 9 | "localParams": [ 10 | { 11 | "Name": "model1", 12 | "Expression": "Age!=0" 13 | }, 14 | { 15 | "Name": "model2", 16 | "Expression": "IdCardUtil.getAgeByIdCardNo(Test.IdNo) < 18" 17 | } 18 | ], 19 | "RuleExpressionType": "LambdaExpression", 20 | "Expression": "model1 AND model2" 21 | }, 22 | { 23 | "RuleName": "CheckIDNoIsEmpty", 24 | "ErrorMessage": "身份证号不可以为空.", 25 | "ErrorType": "Error", 26 | "RuleExpressionType": "LambdaExpression", 27 | "Expression": "IdNo != null " 28 | } 29 | ] 30 | } 31 | ] -------------------------------------------------------------------------------- /Test/Language/AddRoleLanguage.json: -------------------------------------------------------------------------------- 1 | { 2 | "Title":"中文=添加角色;English=AddRole;español=Añadir un rol", 3 | "ID":"中文=ID;English=ID;español=ID", 4 | "Role":"中文=角色;English=Role;español=papel", 5 | "Level":"中文=等级;English=Level;español=rango", 6 | "Enable":"中文=是否启用;English=Enable;español=Sí no habilitado", 7 | "Cancel":"中文=取消;English=Cancel;español=cancelación", 8 | "Confirm":"中文=确认;English=OK;español=confirmación" 9 | } -------------------------------------------------------------------------------- /Test/Language/AddUserLanguage.json: -------------------------------------------------------------------------------- 1 | { 2 | "Title":"中文=添加用户;English=AddUser;español=Añadir un usuario", 3 | "ID":"中文=ID;English=ID;español=ID", 4 | "Account":"中文=账号;English=Account;español=La cuenta", 5 | "CardId":"中文=卡号;English=CardId;español=La tarjeta", 6 | "FingerprintId":"中文=指纹;English=FingerprintId;español=Huellas dactilares", 7 | "Password":"中文=密码;English=Password;español=La contraseña", 8 | "Permissions":"中文=权限;English=Permissions;español=La competencia", 9 | "Enable":"中文=是否启用;English=Enable;español=Sí no habilitado", 10 | "Yes":"中文=是;English=Yes;español=es", 11 | "No":"中文=否;English=No;español=si", 12 | "Cancel":"中文=取消;English=Cancel;español=cancelación", 13 | "Confirm":"中文=确认;English=OK;español=confirmación" 14 | } -------------------------------------------------------------------------------- /Test/Language/ChartHistoryLanguage.json: -------------------------------------------------------------------------------- 1 | { 2 | "StartTime": "中文=开始时间:;English=Start Time:", 3 | "EndTime": "中文=结束时间:;English=End Time:", 4 | "Select": "中文=选择;English=Select", 5 | "Flow": "中文=流量;English=Flow", 6 | "Pressure": "中文=压力;English=Pressure", 7 | "Vacuum": "中文=真空;English=Vacuum", 8 | "Id": "中文=产品ID;English=ID", 9 | "Start": "中文=起始位置;English=Start Pos", 10 | "Scheme": "中文=方案名称;English=Scheme", 11 | "Stop": "中文=结束位置;English=Stop Pos", 12 | "Zongchouqi": "中文=总抽气;English=Air Exhaust", 13 | "Wurandu": "中文=污染度;English=Degree", 14 | "ProductTime": "中文=生产时间;English=Product Time", 15 | "Channel": "中文=通道;English=Channel", 16 | "Min_pressure": "中文=最小压力;English=Min Pressure", 17 | "Reaction_time": "中文=反应时间;English=Reaction Time", 18 | "Air_time": "中文=通风时间;English=Air Time", 19 | "Closed_position": "中文=封闭位置;English=Closed Position", 20 | "Speed": "中文=速度;English=Speed", 21 | "Position": "中文=位置;English=Position" 22 | } -------------------------------------------------------------------------------- /Test/Language/ChartPageLanguage.json: -------------------------------------------------------------------------------- 1 | { 2 | "Select": "中文=曲线选择;English=Select", 3 | "Flow": "中文=流量;English=Flow", 4 | "Pressure": "中文=压力;English=Pressure", 5 | "Vacuum": "中文=真空;English=Vacuum", 6 | "Id": "中文=产品ID;English=ID", 7 | "Start": "中文=起始位置;English=Start Pos", 8 | "Scheme": "中文=方案名称;English=Scheme", 9 | "Stop": "中文=结束位置;English=Stop Pos", 10 | "Zongchouqi": "中文=总抽气;English=Air Exhaust", 11 | "Wurandu": "中文=污染度;English=Degree", 12 | "ProductTime": "中文=生产时间;English=Product Time", 13 | "Channel": "中文=通道;English=Channel", 14 | "Min_pressure": "中文=最小压力;English=Min Pressure", 15 | "Reaction_time": "中文=反应时间;English=Reaction Time", 16 | "Air_time": "中文=通风时间;English=Air Time", 17 | "Closed_position": "中文=封闭位置;English=Closed Position", 18 | "Speed": "中文=速度;English=Speed", 19 | "Position": "中文=位置;English=Position", 20 | "Points_information": "中文=以下为相邻三点的坐标;English=Below are the coordinates of the three adjacent points", 21 | "Error_information": "中文=数组有误,无法显示;English=The array is incorrect and cannot be displayed" 22 | } -------------------------------------------------------------------------------- /Test/Language/ChartPageLanguage1.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LessIsMoreInSZ/bilibiliDemo/c2ae5264474fc77e9db1003f0bbf54248900709c/Test/Language/ChartPageLanguage1.json -------------------------------------------------------------------------------- /Test/Language/Data2CsvLanguage.json: -------------------------------------------------------------------------------- 1 | { 2 | "StartTime": "中文=开始时间:;English=Start Time:", 3 | "EndTime": "中文=结束时间:;English=End Time:", 4 | "Select": "中文=选择;English=Select", 5 | "SaveCsv": "中文=保存CSV;English=SaveCSV", 6 | "Flow": "中文=流量;English=Flow", 7 | "Pressure": "中文=压力;English=Pressure", 8 | "Vacuum": "中文=真空;English=Vacuum", 9 | "Id": "中文=产品ID;English=ID", 10 | "Start": "中文=起始位置;English=Start Pos", 11 | "Scheme": "中文=方案名称;English=Scheme", 12 | "Stop": "中文=结束位置;English=Stop Pos", 13 | "Zongchouqi": "中文=总抽气;English=Air Exhaust", 14 | "Wurandu": "中文=污染度;English=Degree", 15 | "ProductTime": "中文=生产时间;English=Product Time", 16 | "Channel": "中文=通道;English=Channel", 17 | "Min_pressure": "中文=最小压力;English=Min Pressure", 18 | "Reaction_time": "中文=反应时间;English=Reaction Time", 19 | "Air_time": "中文=通风时间;English=Air Time", 20 | "Closed_position": "中文=封闭位置;English=Closed Position", 21 | "Speed": "中文=速度;English=Speed", 22 | "Position": "中文=位置;English=Position" 23 | } -------------------------------------------------------------------------------- /Test/Language/EditRoleLanguage.json: -------------------------------------------------------------------------------- 1 | { 2 | "Title":"中文=编辑角色;English=EditRole;español=Rol de editor", 3 | "ID":"中文=ID;English=ID;español=ID", 4 | "Role":"中文=角色;English=Role;español=papel", 5 | "Level":"中文=等级;English=Level;español=rango", 6 | "Enable":"中文=是否启用;English=Enable;español=Sí no habilitado", 7 | "Cancel":"中文=取消;English=Cancel;español=cancelación", 8 | "Confirm":"中文=确认;English=OK;español=confirmación" 9 | } -------------------------------------------------------------------------------- /Test/Language/EditUserLanguage.json: -------------------------------------------------------------------------------- 1 | { 2 | "Title":"中文=编辑用户;English=EditUser;español=Editar un usuario", 3 | "ID":"中文=ID;English=ID;español=ID", 4 | "Account":"中文=账号;English=Account;español=La cuenta", 5 | "CardId":"中文=卡号;English=CardId;español=La tarjeta", 6 | "FingerprintId":"中文=指纹;English=FingerprintId;español=Huellas dactilares", 7 | "Password":"中文=密码;English=Password;español=La contraseña", 8 | "Permissions":"中文=权限;English=Permissions;español=La competencia", 9 | "Enable":"中文=是否启用;English=Enable;español=Sí no habilitado", 10 | "Cancel":"中文=取消;English=Cancel;español=cancelación", 11 | "Confirm":"中文=确认;English=OK;español=confirmación", 12 | "Yes":"中文=是;English=Yes;español=es", 13 | "No":"中文=否;English=No;español=si" 14 | } -------------------------------------------------------------------------------- /Test/Language/LoginLanguage.json: -------------------------------------------------------------------------------- 1 | { 2 | "AccountLogin":"中文=账号登录;English=AccountLogin;español=Login de cuenta", 3 | "ID":"中文=账号;English=ID;español=La cuenta", 4 | "Password":"中文=密码;English=Password;español=La contraseña", 5 | "Login":"中文=登录;English=Login;español=inicio", 6 | "Guest":"中文=游客;English=Guest;español=Los turistas", 7 | "CollectFinger":"中文=采集指纹;English=Collect Fingerprint;español=Toma huellas digitales", 8 | "CollectRun":"中文=采集中......;English=Collecting......;español=En proceso de adquisición...", 9 | "UnregisterFinger":"中文=指纹未注册;English=Fingerprint not registered,please register first;español=Huellas digitales no registradas", 10 | "CollectSuccess":"中文=采集指纹成功.;English=Collect Fingerprint success;español=Toma de huellas dactilares con éxito.", 11 | "CollectBad":"中文=指纹质量差,请重试;English=Fingerprint is bad ,please try again;español=Huellas digitales de mala calidad, por favor inténtelo de nuevo", 12 | "CollectCancel":"中文=指纹任务被取消,有其他线程或者进程在使用指纹仪;English=The fingerprint task is cancelled because another thread or process is using the fingerprint reader;español=La tarea de huellas digitales se cancela y hay otros hilos o procesos usando el fingerprint", 13 | "CollectStart":"中文=开始识别指纹, 请按手指;English=Start to collect fingerprint,please press your finger;español=Para comenzar a reconocer huellas dactilares, presione el dedo", 14 | "ConnectSuccess":"中文=指纹仪连接成功;English=Fingerprint render connect success;español=Dactilar conectado con éxito", 15 | "ConnectFail":"中文=指纹仪连接失败;English=Fingerprint render connect fail;español=La conexión del lector de huellas digitales falló", 16 | "NotFound":"中文=找不到设备;English=Fingerprint render is not found;español=Dispositivo no encontrado", 17 | "Tab1":"中文=账号密码登录;English=Sign in with Password;español=Cuenta contraseña login", 18 | "Tab2":"中文=指纹登录;English=Sign in with Fingerprint;español=Huellas digitales login", 19 | "Tab3":"中文=刷卡登录;English=Sign in with RFID;español=Login con tarjeta", 20 | "RememberThePassword":"中文=记住密码;English=RememberThePassword;español=Recordar la contraseña", 21 | "ForgetThePassword":"中文=忘记密码?;English=ForgetThePassword?;español=¿Olvidó su contraseña?" 22 | } -------------------------------------------------------------------------------- /Test/Language/MainLanguage.json: -------------------------------------------------------------------------------- 1 | { 2 | "Settings":"中文=设置;English=Settings;español=La configuración", 3 | "Maximize":"中文=最大化/默认;English=Maximize/Default;español=Maximizar/por defecto", 4 | "Minimize":"中文=最小化;English=Minimize;español=minimizar", 5 | "Logout":"中文=注销;English=Logout;español=cancelación", 6 | "Close":"中文=关闭;English=Close;español=cierre", 7 | "ExitTheSystem":"中文=是否要退出系统?;English=Whether to exit the system?;español=¿Quieres salir del sistema?", 8 | "ClosePage":"中文=请确认是否关闭页面?;English=Please confirm whether to close the page?;español=¿Puede confirmar si cierra la página?", 9 | "ClosePages":"中文=请确认是否关闭所有被允许关闭的页面?;English=Make sure to close all pages that are allowed to close?;español=¿Puede confirmar si cierra todas las páginas que se permiten cerrar?" 10 | } -------------------------------------------------------------------------------- /Test/Language/MessageLanguage.json: -------------------------------------------------------------------------------- 1 | { 2 | "Title": "中文=温馨提示;English=Tips", 3 | "Ok": "中文=确定;English=Confirm", 4 | "Cancel": "中文=取消;English=Canecl" 5 | } -------------------------------------------------------------------------------- /Test/Language/SwichTheLanguage.json: -------------------------------------------------------------------------------- 1 | { 2 | "Title":"中文=切换语言;English=Swich the language;español=Cambiar el idioma", 3 | "LanguageStr":"中文=语言;English=Language;español=El lenguaje", 4 | "Cancel":"中文=取消;English=Cancel;español=cancelación", 5 | "Confirm":"中文=确认;English=OK;español=confirmación" 6 | } -------------------------------------------------------------------------------- /Test/Language/UserLanguage.json: -------------------------------------------------------------------------------- 1 | { 2 | "Add":"中文=添加;English=Add;español=añadir", 3 | "Edit":"中文=修改;English=Edit;español=La modificación", 4 | "Delete":"中文=删除;English=Delete;español=borrar", 5 | "ID":"中文=ID;English=ID;español=ID", 6 | "Account":"中文=账号;English=Account;español=La cuenta", 7 | "CardId":"中文=卡号;English=CardId;español=La tarjeta", 8 | "FingerprintId":"中文=指纹;English=FingerprintId;español=Huellas dactilares", 9 | "Password":"中文=密码;English=Password;español=La contraseña", 10 | "HeadPortrait":"中文=头像;English=HeadPortrait;español=avatares", 11 | "Role":"中文=角色;English=Role;español=papel", 12 | "Enable":"中文=是否启用;English=Enable;español=Sí no habilitado", 13 | "AddSuccess":"中文=添加成功;English=Add Success;español=Añadido con éxito", 14 | "AddFail":"中文=添加失败;English=Add Fail;español=Error al agregar", 15 | "EditSuccess":"中文=修改成功;English=Edit Success;español=Modificado con éxito", 16 | "EditFail":"中文=修改失败;English=Edit Fail;español=Modificación fallida", 17 | "DeleteSuccess":"中文=删除成功;English=Delete Success;español=Eliminado con éxito", 18 | "DeleteFail":"中文=删除失败;English=Delete Fail;español=Eliminación fallida" 19 | } -------------------------------------------------------------------------------- /Test/WpfApp1/App.xaml: -------------------------------------------------------------------------------- 1 |  7 | 8 | 9 | -------------------------------------------------------------------------------- /Test/WpfApp1/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using Prism.Ioc; 2 | using Prism.Modularity; 3 | using Prism.Unity; 4 | using System.Configuration; 5 | using System.Data; 6 | using System.IO; 7 | using System.Windows; 8 | 9 | namespace WpfApp1 10 | { 11 | /// 12 | /// Interaction logic for App.xaml 13 | /// 14 | 15 | public partial class App : PrismApplication 16 | { 17 | protected override Window CreateShell() 18 | { 19 | //return Container.Resolve(); 20 | return Container.Resolve(); 21 | } 22 | 23 | protected override void RegisterTypes(IContainerRegistry containerRegistry) 24 | { 25 | containerRegistry.RegisterForNavigation(); 26 | containerRegistry.RegisterForNavigation(); 27 | } 28 | 29 | protected override IModuleCatalog CreateModuleCatalog() 30 | { 31 | DirectoryModuleCatalog catelog = new DirectoryModuleCatalog(); 32 | try 33 | { 34 | if (!Directory.Exists(Path.Combine(AppContext.BaseDirectory, "Functions"))) 35 | { 36 | Directory.CreateDirectory(Path.Combine(AppContext.BaseDirectory, "Functions")); 37 | } 38 | else 39 | { 40 | catelog.ModulePath = Path.Combine(AppContext.BaseDirectory, "Functions"); 41 | } 42 | } 43 | catch (Exception ex) 44 | { 45 | //_logger.Error("load dll fail," + ex.Message); 46 | } 47 | return catelog; 48 | } 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /Test/WpfApp1/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | 3 | [assembly: ThemeInfo( 4 | ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located 5 | //(used if a resource is not found in the page, 6 | // or application resource dictionaries) 7 | ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located 8 | //(used if a resource is not found in the page, 9 | // app, or any theme specific resource dictionaries) 10 | )] 11 | -------------------------------------------------------------------------------- /Test/WpfApp1/BoolToVisibilityConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Globalization; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using System.Windows.Data; 8 | using System.Windows; 9 | 10 | namespace WpfApp1 11 | { 12 | public class BoolToVisibilityConverter : IValueConverter 13 | { 14 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 15 | { 16 | bool isVisible = (bool)value; 17 | return isVisible ? Visibility.Visible : Visibility.Collapsed; 18 | } 19 | 20 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 21 | { 22 | //Visibility visibility = (Visibility)value; 23 | //return visibility == Visibility.Visible; 24 | throw new NotImplementedException(); 25 | 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Test/WpfApp1/CustomFreezable.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Windows; 7 | 8 | namespace WpfApp1 9 | { 10 | public class CustomFreezable : Freezable 11 | { 12 | public static readonly DependencyProperty ValueProperty = DependencyProperty.Register("Value", typeof(object), typeof(CustomFreezable)); 13 | 14 | public object Value 15 | { 16 | get => (object)GetValue(ValueProperty); 17 | set => SetValue(ValueProperty, value); 18 | } 19 | 20 | protected override void OnChanged() 21 | { 22 | base.OnChanged(); 23 | } 24 | 25 | protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e) 26 | { 27 | base.OnPropertyChanged(e); 28 | } 29 | 30 | protected override Freezable CreateInstanceCore() 31 | { 32 | return new CustomFreezable(); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Test/WpfApp1/MainWindow.xaml.cs: -------------------------------------------------------------------------------- 1 | using System.Text; 2 | using System.Windows; 3 | using System.Windows.Controls; 4 | using System.Windows.Data; 5 | using System.Windows.Documents; 6 | using System.Windows.Input; 7 | using System.Windows.Media; 8 | using System.Windows.Media.Imaging; 9 | using System.Windows.Navigation; 10 | using System.Windows.Shapes; 11 | 12 | namespace WpfApp1 13 | { 14 | /// 15 | /// Interaction logic for MainWindow.xaml 16 | /// 17 | public partial class MainWindow : Window 18 | { 19 | public MainWindow() 20 | { 21 | InitializeComponent(); 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /Test/WpfApp1/StringConcatConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Globalization; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using System.Windows.Data; 8 | 9 | namespace WpfApp1 10 | { 11 | public class StringConcatConverter : IMultiValueConverter 12 | { 13 | public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) 14 | { 15 | // 使用string.Join来拼接字符串,并移除null或空字符串 16 | //return string.Join(" ", values.Where(x => x != null && x.ToString() != string.Empty)); 17 | return values[0].ToString() + parameter.ToString(); 18 | } 19 | 20 | public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) 21 | { 22 | // 双向绑定通常不需要实现ConvertBack 23 | throw new NotImplementedException(); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Test/WpfApp1/TestWindow.xaml: -------------------------------------------------------------------------------- 1 |  13 | 14 | 15 | 16 |