diff --git a/BPASmartClient.SCADAControl/DLL/BPASmartClient.Compiler.dll b/BPASmartClient.SCADAControl/DLL/BPASmartClient.Compiler.dll index d7bb62ee..422b745a 100644 Binary files a/BPASmartClient.SCADAControl/DLL/BPASmartClient.Compiler.dll and b/BPASmartClient.SCADAControl/DLL/BPASmartClient.Compiler.dll differ diff --git a/BeDesignerSCADA/Controls/CanvasPanelNew.xaml b/BeDesignerSCADA/Controls/CanvasPanelNew.xaml index 891c23d8..9bdecddf 100644 --- a/BeDesignerSCADA/Controls/CanvasPanelNew.xaml +++ b/BeDesignerSCADA/Controls/CanvasPanelNew.xaml @@ -40,6 +40,7 @@ Background="Transparent" ScrollViewer.VerticalScrollBarVisibility="Auto" ItemTemplate="{DynamicResource PageBoxStyle}" + SelectionChanged="PageList_SelectionChanged" FontSize="14" BorderThickness="0" > diff --git a/BeDesignerSCADA/Controls/CanvasPanelNew.xaml.cs b/BeDesignerSCADA/Controls/CanvasPanelNew.xaml.cs index 5eab451c..cf552687 100644 --- a/BeDesignerSCADA/Controls/CanvasPanelNew.xaml.cs +++ b/BeDesignerSCADA/Controls/CanvasPanelNew.xaml.cs @@ -37,7 +37,14 @@ namespace BeDesignerSCADA.Controls /// public partial class CanvasPanelNew : System.Windows.Controls.UserControl { + /// + /// 界面Model + /// public MainViewModelNew viewModel = new MainViewModelNew(); + /// + /// 文件夹监视 + /// + public FileSystemWatcher _watcher; public CanvasPanelNew(string _Path) { InitializeComponent(); @@ -59,7 +66,13 @@ namespace BeDesignerSCADA.Controls CtlList.ItemsSource = typesView; //读取文件 + CreateDir(); FileRead(_Path); + + cav.SelectedItemAction += new Action(o => { + if (ReditSeleceTab.SelectedIndex!=1) + ReditSeleceTab.SelectedIndex = 1; + }); } #region 位置调整 @@ -128,6 +141,130 @@ namespace BeDesignerSCADA.Controls } #endregion + #region 变量管理器文件夹监听事件 + /// + /// 创建文件夹,监视文件夹 + /// + public void CreateDir() + { + try + { + //不存在则创建布局文件夹 + if (!Directory.Exists($"{System.AppDomain.CurrentDomain.BaseDirectory}Layouts")) + { + Directory.CreateDirectory($"{System.AppDomain.CurrentDomain.BaseDirectory}Layouts"); + } + //不存在则创建变量管理器路径 AccessFile + if (!Directory.Exists($"{System.AppDomain.CurrentDomain.BaseDirectory}AccessFile")) + { + Directory.CreateDirectory($"{System.AppDomain.CurrentDomain.BaseDirectory}AccessFile"); + } + if (!Directory.Exists($"{System.AppDomain.CurrentDomain.BaseDirectory}AccessFile/JSON")) + { + Directory.CreateDirectory($"{System.AppDomain.CurrentDomain.BaseDirectory}AccessFile/JSON"); + } + + try + { + + this._watcher = new FileSystemWatcher(); + _watcher.Path = $"{System.AppDomain.CurrentDomain.BaseDirectory}AccessFile/JSON"; + _watcher.NotifyFilter = NotifyFilters.FileName | NotifyFilters.Size | NotifyFilters.DirectoryName; + _watcher.IncludeSubdirectories = true; + _watcher.Created += new FileSystemEventHandler(FileWatcher_Created); + _watcher.Changed += new FileSystemEventHandler(FileWatcher_Changed); + _watcher.Deleted += new FileSystemEventHandler(FileWatcher_Deleted); + _watcher.Renamed += new RenamedEventHandler(FileWatcher_Renamed); + Start(); + } + + catch (Exception ex) + { + Console.WriteLine("Error:" + ex.Message); + } + } + catch (Exception ex) + { + + } + } + /// + /// 监视启动 + /// + public void Start() + { + this._watcher.EnableRaisingEvents = true; + Console.WriteLine("文件监控已经启动..."); + ReadFileVlaue(); + } + /// + /// 监视停止 + /// + public void Stop() + { + this._watcher.EnableRaisingEvents = false; + this._watcher.Dispose(); + this._watcher = null; + } + /// + /// 文件夹新增 + /// + /// + /// + protected void FileWatcher_Created(object sender, FileSystemEventArgs e) + { + Console.WriteLine("新增:" + e.ChangeType + ";" + e.FullPath + ";" + e.Name); + ReadFileVlaue(); + } + /// + /// 文件名变更-文件大小变化 + /// + /// + /// + protected void FileWatcher_Changed(object sender, FileSystemEventArgs e) + { + Console.WriteLine("变更:" + e.ChangeType + ";" + e.FullPath + ";" + e.Name); + ReadFileVlaue(); + } + /// + /// 删除 + /// + /// + /// + protected void FileWatcher_Deleted(object sender, FileSystemEventArgs e) + { + Console.WriteLine("删除:" + e.ChangeType + ";" + e.FullPath + ";" + e.Name); + ReadFileVlaue(); + } + /// + /// 文件名 + /// + /// + /// + protected void FileWatcher_Renamed(object sender, RenamedEventArgs e) + { + Console.WriteLine("重命名: OldPath:{0} NewPath:{1} OldFileName{2} NewFileName:{3}", e.OldFullPath, e.FullPath, e.OldName, e.Name); + ReadFileVlaue(); + } + /// + /// 读取文件变量 + /// + public void ReadFileVlaue() + { + try + { + Directory.CreateDirectory(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "AccessFile\\JSON")); + viewModel.VariablePath = AppDomain.CurrentDomain.BaseDirectory + "AccessFile\\JSON\\CommunicationPar.json"; + DataBusModel.GetInstance().RefreshVariableManager(viewModel.VariablePath); + } + catch (Exception ex) + { + + } + } + + #endregion + #region 外部调用事件 /// /// 传入变量管理器地址 @@ -350,6 +487,15 @@ namespace BeDesignerSCADA.Controls } } + /// + /// 页选中改变事件 + /// + /// + /// + private void PageList_SelectionChanged(object sender, SelectionChangedEventArgs e) + { + ReditSeleceTab.SelectedIndex = 0; + } #endregion #region 左侧控件栏移动 @@ -522,5 +668,7 @@ namespace BeDesignerSCADA.Controls } } #endregion + + } } diff --git a/BeDesignerSCADA/Controls/MainCanvasPanel.xaml.cs b/BeDesignerSCADA/Controls/MainCanvasPanel.xaml.cs index e9d7ae43..3bee9c26 100644 --- a/BeDesignerSCADA/Controls/MainCanvasPanel.xaml.cs +++ b/BeDesignerSCADA/Controls/MainCanvasPanel.xaml.cs @@ -511,8 +511,5 @@ namespace BeDesignerSCADA.Controls } } #endregion - - - } } diff --git a/BeDesignerSCADA/ViewModel/DataBusModel.cs b/BeDesignerSCADA/ViewModel/DataBusModel.cs index 83a47665..248817f4 100644 --- a/BeDesignerSCADA/ViewModel/DataBusModel.cs +++ b/BeDesignerSCADA/ViewModel/DataBusModel.cs @@ -13,6 +13,14 @@ namespace BeDesignerSCADA.ViewModel public class DataBusModel { #region 单例模式 + private static string path + { + get + { + Directory.CreateDirectory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "AccessFile\\JSON")); + return AppDomain.CurrentDomain.BaseDirectory + "AccessFile\\JSON\\CommunicationPar.json"; + } + } public static DataBusModel dataBus = null; public static DataBusModel GetInstance() @@ -75,5 +83,35 @@ namespace BeDesignerSCADA.ViewModel return IsSucess; } + /// + /// 读取文件 + /// + /// + public bool ReadFile() + { + bool IsSucess = false; + try + { + if (File.Exists(path)) + { + CommunicationPar val = JsonConvert.DeserializeObject(File.ReadAllText(path)); + if (val != null) + { + if (KeyValues == null) + { + KeyValues = new ConcurrentDictionary(); + } + KeyValues[path] = val; + IsSucess = true; + } + } + } + catch (Exception ex) + { + + } + return IsSucess ; + } + } } diff --git a/BeDesignerSCADA/ViewModel/MainViewModelNew.cs b/BeDesignerSCADA/ViewModel/MainViewModelNew.cs index f5db3681..635788b5 100644 --- a/BeDesignerSCADA/ViewModel/MainViewModelNew.cs +++ b/BeDesignerSCADA/ViewModel/MainViewModelNew.cs @@ -623,7 +623,7 @@ namespace BeDesignerSCADA.ViewModel } } /// - /// 导出页面文件 + /// 保存页面文件 /// public void SaveAllPageHeader() {