|
|
@@ -37,7 +37,14 @@ namespace BeDesignerSCADA.Controls |
|
|
|
/// </summary> |
|
|
|
public partial class CanvasPanelNew : System.Windows.Controls.UserControl |
|
|
|
{ |
|
|
|
/// <summary> |
|
|
|
/// 界面Model |
|
|
|
/// </summary> |
|
|
|
public MainViewModelNew viewModel = new MainViewModelNew(); |
|
|
|
/// <summary> |
|
|
|
/// 文件夹监视 |
|
|
|
/// </summary> |
|
|
|
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<FrameworkElement>(o => { |
|
|
|
if (ReditSeleceTab.SelectedIndex!=1) |
|
|
|
ReditSeleceTab.SelectedIndex = 1; |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
#region 位置调整 |
|
|
@@ -128,6 +141,130 @@ namespace BeDesignerSCADA.Controls |
|
|
|
} |
|
|
|
#endregion |
|
|
|
|
|
|
|
#region 变量管理器文件夹监听事件 |
|
|
|
/// <summary> |
|
|
|
/// 创建文件夹,监视文件夹 |
|
|
|
/// </summary> |
|
|
|
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) |
|
|
|
{ |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
/// <summary> |
|
|
|
/// 监视启动 |
|
|
|
/// </summary> |
|
|
|
public void Start() |
|
|
|
{ |
|
|
|
this._watcher.EnableRaisingEvents = true; |
|
|
|
Console.WriteLine("文件监控已经启动..."); |
|
|
|
ReadFileVlaue(); |
|
|
|
} |
|
|
|
/// <summary> |
|
|
|
/// 监视停止 |
|
|
|
/// </summary> |
|
|
|
public void Stop() |
|
|
|
{ |
|
|
|
this._watcher.EnableRaisingEvents = false; |
|
|
|
this._watcher.Dispose(); |
|
|
|
this._watcher = null; |
|
|
|
} |
|
|
|
/// <summary> |
|
|
|
/// 文件夹新增 |
|
|
|
/// </summary> |
|
|
|
/// <param name="sender"></param> |
|
|
|
/// <param name="e"></param> |
|
|
|
protected void FileWatcher_Created(object sender, FileSystemEventArgs e) |
|
|
|
{ |
|
|
|
Console.WriteLine("新增:" + e.ChangeType + ";" + e.FullPath + ";" + e.Name); |
|
|
|
ReadFileVlaue(); |
|
|
|
} |
|
|
|
/// <summary> |
|
|
|
/// 文件名变更-文件大小变化 |
|
|
|
/// </summary> |
|
|
|
/// <param name="sender"></param> |
|
|
|
/// <param name="e"></param> |
|
|
|
protected void FileWatcher_Changed(object sender, FileSystemEventArgs e) |
|
|
|
{ |
|
|
|
Console.WriteLine("变更:" + e.ChangeType + ";" + e.FullPath + ";" + e.Name); |
|
|
|
ReadFileVlaue(); |
|
|
|
} |
|
|
|
/// <summary> |
|
|
|
/// 删除 |
|
|
|
/// </summary> |
|
|
|
/// <param name="sender"></param> |
|
|
|
/// <param name="e"></param> |
|
|
|
protected void FileWatcher_Deleted(object sender, FileSystemEventArgs e) |
|
|
|
{ |
|
|
|
Console.WriteLine("删除:" + e.ChangeType + ";" + e.FullPath + ";" + e.Name); |
|
|
|
ReadFileVlaue(); |
|
|
|
} |
|
|
|
/// <summary> |
|
|
|
/// 文件名 |
|
|
|
/// </summary> |
|
|
|
/// <param name="sender"></param> |
|
|
|
/// <param name="e"></param> |
|
|
|
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(); |
|
|
|
} |
|
|
|
/// <summary> |
|
|
|
/// 读取文件变量 |
|
|
|
/// </summary> |
|
|
|
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 外部调用事件 |
|
|
|
/// <summary> |
|
|
|
/// 传入变量管理器地址 |
|
|
@@ -350,6 +487,15 @@ namespace BeDesignerSCADA.Controls |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
/// <summary> |
|
|
|
/// 页选中改变事件 |
|
|
|
/// </summary> |
|
|
|
/// <param name="sender"></param> |
|
|
|
/// <param name="e"></param> |
|
|
|
private void PageList_SelectionChanged(object sender, SelectionChangedEventArgs e) |
|
|
|
{ |
|
|
|
ReditSeleceTab.SelectedIndex = 0; |
|
|
|
} |
|
|
|
#endregion |
|
|
|
|
|
|
|
#region 左侧控件栏移动 |
|
|
@@ -522,5 +668,7 @@ namespace BeDesignerSCADA.Controls |
|
|
|
} |
|
|
|
} |
|
|
|
#endregion |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |