From 98003d7c4353d62c68ec74010aeee5c35c64dac7 Mon Sep 17 00:00:00 2001 From: fyf Date: Thu, 13 Oct 2022 17:35:10 +0800 Subject: [PATCH] 1 --- BPASmart.MenuLoad/App.xaml | 8 + BPASmart.MenuLoad/App.xaml.cs | 67 +++++ BPASmart.MenuLoad/AssemblyInfo.cs | 10 + BPASmart.MenuLoad/BPASmart.MenuLoad.csproj | 28 +++ BPASmart.MenuLoad/MainWindow.xaml | 12 + BPASmart.MenuLoad/MainWindow.xaml.cs | 28 +++ BPASmart.MenuLoad/fyf.ico | Bin 0 -> 4286 bytes BeDesignerSCADA/BeDesignerSCADA.csproj | 14 +- BeDesignerSCADA/Controls/CanvasPanelNew.xaml | 5 + .../Controls/CanvasPanelNew.xaml.cs | 70 +----- BeDesignerSCADA/Helper/SystemHelper.cs | 232 ++++++++++++++++++ BeDesignerSCADA/ViewModel/MainViewModelNew.cs | 87 +++++-- SmartClient.sln | 23 ++ 13 files changed, 503 insertions(+), 81 deletions(-) create mode 100644 BPASmart.MenuLoad/App.xaml create mode 100644 BPASmart.MenuLoad/App.xaml.cs create mode 100644 BPASmart.MenuLoad/AssemblyInfo.cs create mode 100644 BPASmart.MenuLoad/BPASmart.MenuLoad.csproj create mode 100644 BPASmart.MenuLoad/MainWindow.xaml create mode 100644 BPASmart.MenuLoad/MainWindow.xaml.cs create mode 100644 BPASmart.MenuLoad/fyf.ico create mode 100644 BeDesignerSCADA/Helper/SystemHelper.cs diff --git a/BPASmart.MenuLoad/App.xaml b/BPASmart.MenuLoad/App.xaml new file mode 100644 index 00000000..18ae0c59 --- /dev/null +++ b/BPASmart.MenuLoad/App.xaml @@ -0,0 +1,8 @@ + + + + + diff --git a/BPASmart.MenuLoad/App.xaml.cs b/BPASmart.MenuLoad/App.xaml.cs new file mode 100644 index 00000000..b530458c --- /dev/null +++ b/BPASmart.MenuLoad/App.xaml.cs @@ -0,0 +1,67 @@ +using BeDesignerSCADA.Helper; +using BeDesignerSCADA.View; +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Data; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Runtime.InteropServices; +using System.Threading; +using System.Threading.Tasks; +using System.Windows; + +namespace BPASmart.MenuLoad +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + bool isShow = false; + [DllImport("kernel32.dll")] + private static extern bool SetProcessWorkingSetSize(IntPtr proc, int min, int max); + string _path = $"{System.AppDomain.CurrentDomain.BaseDirectory}Layouts\\可视化界面菜单布局.yf"; + private void FlushMemory() + { + GC.Collect(); + GC.WaitForPendingFinalizers(); + if (Environment.OSVersion.Platform == PlatformID.Win32NT) + SetProcessWorkingSetSize(Process.GetCurrentProcess().Handle, -1, -1); + } + + protected override void OnStartup(StartupEventArgs e) + { + base.OnStartup(e); + + RunWindows run = new RunWindows(); + _ = Task.Factory.StartNew(delegate + { + while (true) + { + try + { + if (!isShow) + { + this.Dispatcher.Invoke(() => { + if (File.Exists(_path)) + { + SystemHelperNew.GetInstance.CreateDesktopShortcut(); + run.LoadingData(_path); + run.Show(); + isShow = true; + } + }); + + } + FlushMemory(); + Thread.Sleep(TimeSpan.FromSeconds((double)1000)); + } + catch { } + } + }); + + } + } +} diff --git a/BPASmart.MenuLoad/AssemblyInfo.cs b/BPASmart.MenuLoad/AssemblyInfo.cs new file mode 100644 index 00000000..8b5504ec --- /dev/null +++ b/BPASmart.MenuLoad/AssemblyInfo.cs @@ -0,0 +1,10 @@ +using System.Windows; + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) +)] diff --git a/BPASmart.MenuLoad/BPASmart.MenuLoad.csproj b/BPASmart.MenuLoad/BPASmart.MenuLoad.csproj new file mode 100644 index 00000000..15c0fe6e --- /dev/null +++ b/BPASmart.MenuLoad/BPASmart.MenuLoad.csproj @@ -0,0 +1,28 @@ + + + + WinExe + net6.0-windows + enable + true + 可视化应用 + fyf.ico + + + + + + + + + + + + + + + + + + + diff --git a/BPASmart.MenuLoad/MainWindow.xaml b/BPASmart.MenuLoad/MainWindow.xaml new file mode 100644 index 00000000..fdbdd6a5 --- /dev/null +++ b/BPASmart.MenuLoad/MainWindow.xaml @@ -0,0 +1,12 @@ + + + + + diff --git a/BPASmart.MenuLoad/MainWindow.xaml.cs b/BPASmart.MenuLoad/MainWindow.xaml.cs new file mode 100644 index 00000000..35bed5b7 --- /dev/null +++ b/BPASmart.MenuLoad/MainWindow.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace BPASmart.MenuLoad +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class MainWindow : Window + { + public MainWindow() + { + InitializeComponent(); + } + } +} diff --git a/BPASmart.MenuLoad/fyf.ico b/BPASmart.MenuLoad/fyf.ico new file mode 100644 index 0000000000000000000000000000000000000000..346bbc6ca2a20235e7105d7fe7b5e70698805fb8 GIT binary patch literal 4286 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 literal 0 HcmV?d00001 diff --git a/BeDesignerSCADA/BeDesignerSCADA.csproj b/BeDesignerSCADA/BeDesignerSCADA.csproj index e2cf5a23..3b2ea24f 100644 --- a/BeDesignerSCADA/BeDesignerSCADA.csproj +++ b/BeDesignerSCADA/BeDesignerSCADA.csproj @@ -9,6 +9,16 @@ + + tlbimp + 0 + 1 + f935dc20-1cf0-11d0-adb9-00c04fd58a0b + 0 + false + true + true + @@ -119,8 +129,4 @@ - - - - diff --git a/BeDesignerSCADA/Controls/CanvasPanelNew.xaml b/BeDesignerSCADA/Controls/CanvasPanelNew.xaml index 2184ba60..39d4fdf2 100644 --- a/BeDesignerSCADA/Controls/CanvasPanelNew.xaml +++ b/BeDesignerSCADA/Controls/CanvasPanelNew.xaml @@ -78,6 +78,11 @@ + + + + + diff --git a/BeDesignerSCADA/Controls/CanvasPanelNew.xaml.cs b/BeDesignerSCADA/Controls/CanvasPanelNew.xaml.cs index 057dbbd2..b92e4d0e 100644 --- a/BeDesignerSCADA/Controls/CanvasPanelNew.xaml.cs +++ b/BeDesignerSCADA/Controls/CanvasPanelNew.xaml.cs @@ -44,7 +44,6 @@ namespace BeDesignerSCADA.Controls viewModel.LayoutsPath = _Path; this.DataContext = viewModel; viewModel.Loaded(cav, runCanvas); - //控件加载 Assembly assembly = Assembly.LoadFile($"{System.AppDomain.CurrentDomain.BaseDirectory}\\BPASmartClient.SCADAControl.dll"); //Assembly.GetExecutingAssembly(); CtlList.ItemsSource = assembly.GetTypes().Where(t => t.GetInterface("IExecutable") != null).OrderBy(o => o.Name)?.ToList(); @@ -139,10 +138,10 @@ namespace BeDesignerSCADA.Controls /// public void FileSave() { - SaveBtn_Click(null, null); + viewModel.SaveAllPageHeaderPath(viewModel.LayoutsPath); } /// - /// 读取文件 + /// 读取文件,加载布局 /// /// public void FileRead(string path) @@ -151,59 +150,14 @@ namespace BeDesignerSCADA.Controls { if (File.Exists(path)) { - cav.Load(path); - - DoubleAnimation da = new DoubleAnimation(-200, 0, new Duration(TimeSpan.FromMilliseconds(250))); - da.EasingFunction = new CubicEase() { EasingMode = EasingMode.EaseOut }; - CanvasTranslate.BeginAnimation(TranslateTransform.XProperty, da); - - DoubleAnimation daop = new DoubleAnimation(0, 1, new Duration(TimeSpan.FromMilliseconds(250))); - daop.EasingFunction = new CubicEase() { EasingMode = EasingMode.EaseOut }; - cav.BeginAnimation(OpacityProperty, daop); + viewModel.LoadAllPageHeaderPath(path); } } catch (Exception ex) { - } } /// - /// 根据流加载数据 - /// - public void LoadFrameworkElement(UIElementCollection frameworks) - { - try - { - cav.Children.Clear(); - foreach (FrameworkElement element in frameworks) - { - string xamlText = XamlWriter.Save(element); - FrameworkElement item = XamlReader.Parse(xamlText) as FrameworkElement; - cav.Children.Add(item); - } - cav.SelectedItems?.Clear(); - } - catch (Exception ex) - { - - } - } - /// - /// 获取所有控件 - /// - /// - public List GetChildren() - { - List frameworks = new List(); - foreach (FrameworkElement child in cav.Children) - { - string xamlText = XamlWriter.Save(child); - FrameworkElement item = XamlReader.Parse(xamlText) as FrameworkElement; - frameworks.Add(item); - } - return frameworks; - } - /// /// 运行程序 /// public void Run() @@ -303,21 +257,13 @@ namespace BeDesignerSCADA.Controls /// private void SaveBtn_Click(object sender, RoutedEventArgs e) { - if (File.Exists(viewModel.LayoutsPath)) + SaveFileDialog sfd = new SaveFileDialog(); + sfd.Filter = "布局文件|*.lay"; + + if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { string str = cav.Save(); - File.WriteAllText(viewModel.LayoutsPath, str, Encoding.Unicode); - } - else - { - SaveFileDialog sfd = new SaveFileDialog(); - sfd.Filter = "布局文件|*.lay"; - - if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK) - { - string str = cav.Save(); - File.WriteAllText(sfd.FileName, str, Encoding.Unicode); - } + File.WriteAllText(sfd.FileName, str, Encoding.Unicode); } } /// diff --git a/BeDesignerSCADA/Helper/SystemHelper.cs b/BeDesignerSCADA/Helper/SystemHelper.cs new file mode 100644 index 00000000..2a957edf --- /dev/null +++ b/BeDesignerSCADA/Helper/SystemHelper.cs @@ -0,0 +1,232 @@ +using IWshRuntimeLibrary; +using Microsoft.Win32; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; + +namespace BeDesignerSCADA.Helper +{ + /// + /// 系统操作类 + /// + public class SystemHelperNew + { + private volatile static SystemHelperNew _Instance; + public static SystemHelperNew GetInstance => _Instance ?? (_Instance = new SystemHelperNew()); + private SystemHelperNew() { } + + /// + /// 获取当前应用程序名称,包括后缀名 + /// + public string GetApplicationName => $"{AppDomain.CurrentDomain.FriendlyName}.exe"; + + /// + /// 获取当前应用程序完整路径 + /// + public string GetApplicationPath => $"{AppDomain.CurrentDomain.BaseDirectory}{GetApplicationName}"; + + /// + /// 创建桌面快捷方式 + /// + /// 成功或失败 + public bool CreateDesktopShortcut() + { + //1、在COM对象中找到 Windows Script Host Object Model + //2、添加引用 using IWshRuntimeLibrary; + string deskTop = string.Empty; + try + { + deskTop = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\"; + if (System.IO.File.Exists(deskTop + GetApplicationName + ".lnk")) // + { + return true; + //System.IO.File.Delete(deskTop + FileName + ".lnk");//删除原来的桌面快捷键方式 + } + WshShell shell = new WshShell(); + //快捷键方式创建的位置、名称 + IWshShortcut shortcut = shell.CreateShortcut(deskTop + GetApplicationName + ".lnk") as IWshShortcut; + shortcut.TargetPath = GetApplicationPath; //目标文件 + //该属性指定应用程序的工作目录,当用户没有指定一个具体的目录时,快捷方式的目标应用程序将使用该属性所指定的目录来装载或保存文件。 + shortcut.WorkingDirectory = System.Environment.CurrentDirectory; + shortcut.WindowStyle = 1; //目标应用程序的窗口状态分为普通、最大化、最小化【1,3,7】 + shortcut.Description = GetApplicationName; //描述 + //shortcut.IconLocation = exePath + "\\logo.ico"; //快捷方式图标 + shortcut.Arguments = ""; + //shortcut.Hotkey = "CTRL+ALT+F11"; // 快捷键 + shortcut.Save(); //必须调用保存快捷才成创建成功 + return true; + } + catch (Exception ex) + { + return false; + } + } + + /// + /// 设置开机自启动 + /// + /// true:开机启动,false:不开机自启 + public void AutoStart(bool isAuto = true) + { + if (isAuto == true) + { + RegistryKey R_local = Registry.CurrentUser; + RegistryKey R_run = R_local.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run"); + R_run.SetValue(GetApplicationName, GetApplicationPath); + R_run.Close(); + R_local.Close(); + } + else + { + RegistryKey R_local = Registry.CurrentUser; + RegistryKey R_run = R_local.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run"); + R_run.DeleteValue(GetApplicationName, false); + R_run.Close(); + R_local.Close(); + } + } + + /// + /// 判断是否是自动启动 + /// + /// + public bool IsAutoStart() + { + RegistryKey R_local = Registry.CurrentUser; + RegistryKey R_run = R_local.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run"); + bool res = R_run.GetValueNames().Contains(GetApplicationName); + R_run.Close(); + R_local.Close(); + return res; + } + + #region U盘,串口插拔信息 + private const int WM_DEVICECHANGE = 0x219; //设备改变 + private const int DBT_DEVICEARRIVAL = 0x8000; //检测到新设备 + private const int DBT_DEVICEREMOVECOMPLETE = 0x8004; //移除设备 + public const int DBT_DEVTYP_PORT = 0x00000003; + public const int DBT_DEVTYP_VOLUME = 0x00000002; + + public IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) + { + if (msg == WM_DEVICECHANGE) + { + //插入 + if (wParam.ToInt32() == DBT_DEVICEARRIVAL) + { + var volume = (DEV_BROADCAST_HDR)Marshal.PtrToStructure(lParam, typeof(DEV_BROADCAST_HDR)); + + switch (volume.dbch_devicetype) + { + case DBT_DEVTYP_PORT://串口设备 + string portName = Marshal.PtrToStringUni(lParam + Marshal.SizeOf(typeof(DEV_BROADCAST_PORT))); + break; + case DBT_DEVTYP_VOLUME: + var drive = GetDrive(lParam); + break; + default: + break; + } + } + + //拔出 + if (wParam.ToInt32() == DBT_DEVICEREMOVECOMPLETE) + { + var volume = (DEV_BROADCAST_HDR)Marshal.PtrToStructure(lParam, typeof(DEV_BROADCAST_HDR)); + switch (volume.dbch_devicetype) + { + case DBT_DEVTYP_PORT://串口设备 + string portName = Marshal.PtrToStringUni(lParam + Marshal.SizeOf(typeof(DEV_BROADCAST_PORT))); + break; + case DBT_DEVTYP_VOLUME: + var drive = GetDrive(lParam); + break; + default: + break; + } + } + } + return IntPtr.Zero; + } + + private static string GetDrive(IntPtr lParam) + { + var volume = (DEV_BROADCAST_VOLUME)Marshal.PtrToStructure(lParam, typeof(DEV_BROADCAST_VOLUME)); + var letter = GetLetter(volume.dbcv_unitmask); + return string.Format("{0}:\\", letter); + } + + /// + /// 获得盘符 + /// + /// + /// 1 = A + /// 2 = B + /// 4 = C... + /// + /// 结果是A~Z的任意一个字符或者为'?' + private static char GetLetter(uint dbcvUnitmask) + { + const char nona = '?'; + const string drives = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + if (dbcvUnitmask == 0) return nona; + var i = 0; + var pom = dbcvUnitmask >> 1; + while (pom != 0) + { + pom = pom >> 1; + i++; + } + if (i < drives.Length) + return drives[i]; + return nona; + } + + + #endregion + } + + [StructLayout(LayoutKind.Sequential)] + struct DEV_BROADCAST_HDR + { + public UInt32 dbch_size; + public UInt32 dbch_devicetype; + public UInt32 dbch_reserved; + } + + [StructLayout(LayoutKind.Sequential)] + struct DEV_BROADCAST_PORT + { + public uint dbcp_size; + public uint dbcp_devicetype; + public uint dbcp_reserved; + } + + [StructLayout(LayoutKind.Sequential)] + struct DEV_BROADCAST_PORT_A + { + public uint dbcp_size; + public uint dbcp_devicetype; + public uint dbcp_reserved; + //public string dbcp_name; + } + + [StructLayout(LayoutKind.Sequential)] + struct DEV_BROADCAST_VOLUME + { + /// DWORD->unsigned int + public uint dbcv_size; + /// DWORD->unsigned int + public uint dbcv_devicetype; + /// DWORD->unsigned int + public uint dbcv_reserved; + /// DWORD->unsigned int + public uint dbcv_unitmask; + /// WORD->unsigned short + public ushort dbcv_flags; + } +} diff --git a/BeDesignerSCADA/ViewModel/MainViewModelNew.cs b/BeDesignerSCADA/ViewModel/MainViewModelNew.cs index 72f50c19..bac9f12a 100644 --- a/BeDesignerSCADA/ViewModel/MainViewModelNew.cs +++ b/BeDesignerSCADA/ViewModel/MainViewModelNew.cs @@ -384,6 +384,10 @@ namespace BeDesignerSCADA.ViewModel /// public RelayCommand SaveAllPageCommand { get; set; } /// + /// 另存页面文件 + /// + public RelayCommand LWSaveAllPageCommand { get; set; } + /// /// 加载页面文件 /// public RelayCommand LoadAllPageCommand { get; set; } @@ -403,6 +407,7 @@ namespace BeDesignerSCADA.ViewModel DeletePageCommand = new RelayCommand(new Action(DeletePageHeader)); SelectPageCommand = new RelayCommand(new Action(SelectPageHeader)); SaveAllPageCommand = new RelayCommand(new Action(SaveAllPageHeader)); + LWSaveAllPageCommand=new RelayCommand(new Action(LWSaveAllPageHeader)); LoadAllPageCommand = new RelayCommand(new Action(LoadAllPageHeader)); LoadValuesCommand = new RelayCommand(new Action(LoadValuesHeader)); @@ -412,7 +417,6 @@ namespace BeDesignerSCADA.ViewModel MenuModel.SelectPageModels = MenuModel.pageModels[0]; GxSortTarget(); } - /// /// 刷新排序 /// @@ -573,15 +577,37 @@ namespace BeDesignerSCADA.ViewModel /// 导出页面文件 /// public void SaveAllPageHeader() + { + try + { + string _path = $"{System.AppDomain.CurrentDomain.BaseDirectory}Layouts\\可视化界面菜单布局.yf"; + if (!Directory.Exists($"{System.AppDomain.CurrentDomain.BaseDirectory}Layouts")) // 返回bool类型,存在返回true,不存在返回false + { + Directory.CreateDirectory($"{System.AppDomain.CurrentDomain.BaseDirectory}Layouts"); //不存在则创建路径 + } + if (File.Exists(_path)) // 返回bool类型,存在返回true,不存在返回false + { + File.Delete(_path); + } + SaveAllPageHeaderPath(_path); + } + catch (Exception ex) + { + + } + } + /// + /// 另存文件 + /// + public void LWSaveAllPageHeader() { try { SaveFileDialog sfd = new SaveFileDialog(); sfd.Filter = "页面布局|*.yf"; - if (sfd.ShowDialog() == true) { - BinaryFile.SaveBinary(MenuModel, sfd.FileName); + SaveAllPageHeaderPath(sfd.FileName); } } catch (Exception ex) @@ -589,6 +615,22 @@ namespace BeDesignerSCADA.ViewModel } } + + /// + /// 根据路径保存菜单布局 + /// + /// + public void SaveAllPageHeaderPath(string path) + { + try + { + BinaryFile.SaveBinary(MenuModel, path); + } + catch (Exception ex) + { + + } + } /// /// 加载页面文件 /// @@ -600,20 +642,35 @@ namespace BeDesignerSCADA.ViewModel ofd.Filter = "页面布局|*.yf"; if (ofd.ShowDialog() == true) { - MenuModel = BinaryFile.ReadBinary(ofd.FileName) as MenuModel; - MenuModel?.pageModels?.ToList().ForEach(par => + LoadAllPageHeaderPath(ofd.FileName); + } + } + catch (Exception ex) + { + + } + } + /// + /// 根据路径加载菜单布局 + /// + /// + public void LoadAllPageHeaderPath(string path) + { + try + { + MenuModel = BinaryFile.ReadBinary(path) as MenuModel; + MenuModel?.pageModels?.ToList().ForEach(par => + { + par.visual = new CanvasPanel(); + par?.ChildrenStr?.ForEach(k => { - par.visual = new CanvasPanel(); - par?.ChildrenStr?.ForEach(k => - { - FrameworkElement item = XamlReader.Parse(k) as FrameworkElement; - par.visual.Children.Add(item); - }); + FrameworkElement item = XamlReader.Parse(k) as FrameworkElement; + par.visual.Children.Add(item); }); - if (MenuModel.pageModels != null && MenuModel.pageModels.Count > 0) - { - SelectPageHeader(MenuModel.pageModels?.ToList()?[0]); - } + }); + if (MenuModel.pageModels != null && MenuModel.pageModels.Count > 0) + { + SelectPageHeader(MenuModel.pageModels?.ToList()?[0]); } } catch (Exception ex) diff --git a/SmartClient.sln b/SmartClient.sln index 4ccee7c0..fd280f95 100644 --- a/SmartClient.sln +++ b/SmartClient.sln @@ -180,6 +180,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BPASmartClient.MorkMOC", "B EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BPASmartClient.DosingHKProject", "BPASmartClient.DosingProject\BPASmartClient.DosingHKProject.csproj", "{6763F73A-555C-41E2-91F7-ADF26C59A946}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BPASmart.MenuLoad", "BPASmart.MenuLoad\BPASmart.MenuLoad.csproj", "{7A7547D3-F2EF-4DA4-AD45-D1B49210082B}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -1694,6 +1696,26 @@ Global {6763F73A-555C-41E2-91F7-ADF26C59A946}.Release|x64.Build.0 = Release|Any CPU {6763F73A-555C-41E2-91F7-ADF26C59A946}.Release|x86.ActiveCfg = Release|Any CPU {6763F73A-555C-41E2-91F7-ADF26C59A946}.Release|x86.Build.0 = Release|Any CPU + {7A7547D3-F2EF-4DA4-AD45-D1B49210082B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7A7547D3-F2EF-4DA4-AD45-D1B49210082B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7A7547D3-F2EF-4DA4-AD45-D1B49210082B}.Debug|ARM.ActiveCfg = Debug|Any CPU + {7A7547D3-F2EF-4DA4-AD45-D1B49210082B}.Debug|ARM.Build.0 = Debug|Any CPU + {7A7547D3-F2EF-4DA4-AD45-D1B49210082B}.Debug|ARM64.ActiveCfg = Debug|Any CPU + {7A7547D3-F2EF-4DA4-AD45-D1B49210082B}.Debug|ARM64.Build.0 = Debug|Any CPU + {7A7547D3-F2EF-4DA4-AD45-D1B49210082B}.Debug|x64.ActiveCfg = Debug|Any CPU + {7A7547D3-F2EF-4DA4-AD45-D1B49210082B}.Debug|x64.Build.0 = Debug|Any CPU + {7A7547D3-F2EF-4DA4-AD45-D1B49210082B}.Debug|x86.ActiveCfg = Debug|Any CPU + {7A7547D3-F2EF-4DA4-AD45-D1B49210082B}.Debug|x86.Build.0 = Debug|Any CPU + {7A7547D3-F2EF-4DA4-AD45-D1B49210082B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7A7547D3-F2EF-4DA4-AD45-D1B49210082B}.Release|Any CPU.Build.0 = Release|Any CPU + {7A7547D3-F2EF-4DA4-AD45-D1B49210082B}.Release|ARM.ActiveCfg = Release|Any CPU + {7A7547D3-F2EF-4DA4-AD45-D1B49210082B}.Release|ARM.Build.0 = Release|Any CPU + {7A7547D3-F2EF-4DA4-AD45-D1B49210082B}.Release|ARM64.ActiveCfg = Release|Any CPU + {7A7547D3-F2EF-4DA4-AD45-D1B49210082B}.Release|ARM64.Build.0 = Release|Any CPU + {7A7547D3-F2EF-4DA4-AD45-D1B49210082B}.Release|x64.ActiveCfg = Release|Any CPU + {7A7547D3-F2EF-4DA4-AD45-D1B49210082B}.Release|x64.Build.0 = Release|Any CPU + {7A7547D3-F2EF-4DA4-AD45-D1B49210082B}.Release|x86.ActiveCfg = Release|Any CPU + {7A7547D3-F2EF-4DA4-AD45-D1B49210082B}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -1777,6 +1799,7 @@ Global {BA588F22-87FB-4124-AF62-CA8DC492ED7D} = {8712125E-14CD-4E1B-A1CE-4BDE03805942} {D5081D7B-3EBB-42C7-8FB9-A889870D08C2} = {9FB27073-61A0-4FE3-94DB-5FDDE062332F} {6763F73A-555C-41E2-91F7-ADF26C59A946} = {8712125E-14CD-4E1B-A1CE-4BDE03805942} + {7A7547D3-F2EF-4DA4-AD45-D1B49210082B} = {06F0B369-0483-46DD-82D2-70431FB505C1} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {9AEC9B81-0222-4DE9-B642-D915C29222AC}