fyf 2 yıl önce
ebeveyn
işleme
ae65c82952
6 değiştirilmiş dosya ile 188 ekleme ve 4 silme
  1. BIN
     
  2. +1
    -0
      BeDesignerSCADA/Controls/CanvasPanelNew.xaml
  3. +148
    -0
      BeDesignerSCADA/Controls/CanvasPanelNew.xaml.cs
  4. +0
    -3
      BeDesignerSCADA/Controls/MainCanvasPanel.xaml.cs
  5. +38
    -0
      BeDesignerSCADA/ViewModel/DataBusModel.cs
  6. +1
    -1
      BeDesignerSCADA/ViewModel/MainViewModelNew.cs

+ 1
- 0
BeDesignerSCADA/Controls/CanvasPanelNew.xaml Dosyayı Görüntüle

@@ -40,6 +40,7 @@
Background="Transparent"
ScrollViewer.VerticalScrollBarVisibility="Auto"
ItemTemplate="{DynamicResource PageBoxStyle}"
SelectionChanged="PageList_SelectionChanged"
FontSize="14" BorderThickness="0" >
<ListBox.ContextMenu>
<ContextMenu>


+ 148
- 0
BeDesignerSCADA/Controls/CanvasPanelNew.xaml.cs Dosyayı Görüntüle

@@ -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

}
}

+ 0
- 3
BeDesignerSCADA/Controls/MainCanvasPanel.xaml.cs Dosyayı Görüntüle

@@ -511,8 +511,5 @@ namespace BeDesignerSCADA.Controls
}
}
#endregion


}
}

+ 38
- 0
BeDesignerSCADA/ViewModel/DataBusModel.cs Dosyayı Görüntüle

@@ -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;
}

/// <summary>
/// 读取文件
/// </summary>
/// <returns></returns>
public bool ReadFile()
{
bool IsSucess = false;
try
{
if (File.Exists(path))
{
CommunicationPar val = JsonConvert.DeserializeObject<CommunicationPar>(File.ReadAllText(path));
if (val != null)
{
if (KeyValues == null)
{
KeyValues = new ConcurrentDictionary<string, CommunicationPar>();
}
KeyValues[path] = val;
IsSucess = true;
}
}
}
catch (Exception ex)
{

}
return IsSucess ;
}

}
}

+ 1
- 1
BeDesignerSCADA/ViewModel/MainViewModelNew.cs Dosyayı Görüntüle

@@ -623,7 +623,7 @@ namespace BeDesignerSCADA.ViewModel
}
}
/// <summary>
/// 导出页面文件
/// 保存页面文件
/// </summary>
public void SaveAllPageHeader()
{


Yükleniyor…
İptal
Kaydet