diff --git a/BPASmartClient.Compiler/BPASmartClient.Compiler.csproj b/BPASmartClient.Compiler/BPASmartClient.Compiler.csproj
deleted file mode 100644
index efb7ba9f..00000000
--- a/BPASmartClient.Compiler/BPASmartClient.Compiler.csproj
+++ /dev/null
@@ -1,32 +0,0 @@
-
-
-
- net6.0-windows
- enable
- enable
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- DLL\Antlr3.Runtime.dll
-
-
- DLL\Unvell.ReoScript.dll
-
-
-
-
diff --git a/BPASmartClient.Compiler/CSharpConfig.cs b/BPASmartClient.Compiler/CSharpConfig.cs
deleted file mode 100644
index faab7eee..00000000
--- a/BPASmartClient.Compiler/CSharpConfig.cs
+++ /dev/null
@@ -1,181 +0,0 @@
-using Microsoft.CodeAnalysis;
-using Microsoft.CodeAnalysis.CSharp;
-using Microsoft.CodeAnalysis.Emit;
-using Microsoft.CSharp;
-using System;
-using System.CodeDom.Compiler;
-using System.Collections.Generic;
-using System.Linq;
-using System.Reflection;
-using System.Text;
-using System.Threading.Tasks;
-using Newtonsoft.Json;
-using Newtonsoft.Json.Linq;
-using System.Runtime;
-using System.Runtime.CompilerServices;
-
-namespace BPASmartClient.Compiler
-{
- ///
- /// C#编译器
- ///
- public class CSharpConfig
- {
- #region 单例模式
- public static CSharpConfig Instance = null;
-
- public static CSharpConfig GetInstance()
- {
- if (Instance == null)
- {
- Instance = new CSharpConfig();
- }
- return Instance;
- }
- #endregion
-
- public CSharpConfig()
- {
-
-
- }
-
-
-
- public object RunCSharp(string code,object[] objValue,string error = "")
- {
- object strretu = string.Empty;
- try
- {
- string funName = "main";
- StringBuilder builder = new StringBuilder();
- //builder.Append("using System;\n");
- //builder.Append("using System.Linq;\n");
- builder.Append("using Newtonsoft.Json;\n");
- builder.Append("using Newtonsoft.Json.Linq;\n");
- //builder.Append("using System.IO;\n");
- //builder.Append("using System.Runtime;\n");
- //builder.Append("using System.Text;\n");
- builder.Append("using System.Collections.Generic;\n");
- builder.Append("namespace YF \n{\n class CSharpConfigRun\n");
- builder.Append(" {\n");
- builder.Append(code);
- builder.Append(" }\n}\n");
- //1.添加要引用的程序集
- string output = Path.GetTempFileName();
- string assemblyName = Path.GetFileName(output);
- var refPaths = new[] {
- Assembly.GetExecutingAssembly().Location,
- typeof(object).GetTypeInfo().Assembly.Location,
- Path.Combine(Path.GetDirectoryName(typeof(System.Runtime.GCSettings).GetTypeInfo().Assembly.Location), "System.dll"),
- Path.Combine(Path.GetDirectoryName(typeof(System.Runtime.GCSettings).GetTypeInfo().Assembly.Location), "System.Collections.dll"),
- Path.Combine(Path.GetDirectoryName(typeof(System.Runtime.GCSettings).GetTypeInfo().Assembly.Location), "System.Threading.dll"),
- Path.Combine(Path.GetDirectoryName(typeof(System.Runtime.GCSettings).GetTypeInfo().Assembly.Location), "System.Runtime.dll"),
- Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Newtonsoft.Json.dll"),
- typeof(DynamicAttribute).GetTypeInfo().Assembly.Location,
- };
- MetadataReference[] references = refPaths.Select(r => MetadataReference.CreateFromFile(r)).ToArray();
-
- List refs = new List() {
- MetadataReference.CreateFromFile (typeof (object).Assembly.Location),
- MetadataReference.CreateFromFile (typeof (List).Assembly.Location),
- MetadataReference.CreateFromFile (typeof (ASCIIEncoding).Assembly.Location),
- MetadataReference.CreateFromFile (typeof (JsonConvert).Assembly.Location),
- MetadataReference.CreateFromFile (typeof (JObject).Assembly.Location),
- MetadataReference.CreateFromFile (typeof (Object).Assembly.Location),
- MetadataReference.CreateFromFile (typeof (JContainer).Assembly.Location),
- MetadataReference.CreateFromFile (typeof (JToken).Assembly.Location),
- MetadataReference.CreateFromFile (typeof (Enumerable).Assembly.Location),
- };
- //2.需要编辑的C#代码
- SyntaxTree tree = CSharpSyntaxTree.ParseText(builder.ToString());
- //3.生成C#编译
- var compilation = CSharpCompilation.Create(Guid.NewGuid().ToString() + ".dll")
- .WithOptions(new CSharpCompilationOptions(
- Microsoft.CodeAnalysis.OutputKind.DynamicallyLinkedLibrary
- ,
- usings: null,
- optimizationLevel: OptimizationLevel.Debug, // TODO
- checkOverflow: false, // TODO
- allowUnsafe: true, // TODO
- platform: Platform.AnyCpu,
- warningLevel: 4,
- xmlReferenceResolver: null
- ))
- .AddReferences(references)
- .AddSyntaxTrees(tree);
-
- //var emitResult = compilation.Emit(output);
- EmitResult emitResult;
- byte[] dllBytes;
- using (var stream = new MemoryStream())
- {
- emitResult = compilation.Emit(stream);
- dllBytes = stream.ToArray();
- }
-
- if (emitResult.Success)
- {
- Assembly assembly = Assembly.Load(dllBytes);
- var obj = assembly.CreateInstance("YF.CSharpConfigRun");
- var method = obj.GetType().GetMethod("main",new Type[] { typeof(string) });
- strretu = method.Invoke(obj,objValue);
- }
-
-
- //var providerOptions = new Dictionary();
- //providerOptions.Add("CompilerVersion","v4.0");
- //CSharpCodeProvider compiler = new CSharpCodeProvider(providerOptions);
- //string output = Path.GetTempFileName();
- //var cp = new CompilerParameters() { GenerateInMemory = true,OutputAssembly = output };
- //cp.ReferencedAssemblies.Add(Assembly.GetExecutingAssembly().Location);
- //cp.ReferencedAssemblies.Add("Microsoft.CSharp.dll");
- //cp.ReferencedAssemblies.Add("System.Core.dll");
- //cp.ReferencedAssemblies.Add("Newtonsoft.Json.dll"); //添加引用
- //cp.ReferencedAssemblies.Add("System.dll");
- //cp.GenerateExecutable = false;
- //cp.EmbeddedResources.Clear();
- //cp.LinkedResources.Clear();
- //cp.Win32Resource = null;
- //cp.TreatWarningsAsErrors = false;
- //cp.WarningLevel = 4;
- //cp.TempFiles.KeepFiles = false;
- //CompilerResults cr = compiler.CompileAssemblyFromSource(cp,builder.ToString());
-
-
-
-
- // 1.ICodeComplier
- // CSharpCodeProvider complier = new CSharpCodeProvider();
- // // 2.CompilerParameters
- // CompilerParameters cp = new CompilerParameters();
- // cp.ReferencedAssemblies.Add("System.dll"); //添加引用
- //// cp.ReferencedAssemblies.Add("Newtonsoft.Json.dll"); //添加引用
- // cp.GenerateExecutable = false;
- // cp.GenerateInMemory = true;
- // // 3.CompilerResults
- // CompilerResults cr = complier.CompileAssemblyFromSource(cp,builder.ToString());
- //if (cr.Errors.HasErrors)
- //{
- // foreach (CompilerError err in cr.Errors)
- // {
- // error += err.ErrorText + "\r\n";
- // }
- //}
- //else
- //{
- // // 通过反射,调用HelloWorld的实例
- // Assembly objAssembly = cr.CompiledAssembly;
- // object objClass = objAssembly.CreateInstance("CSharpConfigRun");
- // MethodInfo objFun = objClass.GetType().GetMethod(funName);
- // strretu = objFun.Invoke(objClass,objValue);
- //}
- }
- catch (Exception ex)
- {
- error += ex.Message;
- }
- return strretu;
- }
- }
-}
diff --git a/BPASmartClient.Compiler/Config.cs b/BPASmartClient.Compiler/Config.cs
deleted file mode 100644
index 1b6cbea0..00000000
--- a/BPASmartClient.Compiler/Config.cs
+++ /dev/null
@@ -1,94 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.Windows;
-using Unvell.ReoScript;
-
-namespace BPASmartClient.Compiler
-{
- ///
- /// 编译器
- /// 创建人:奉友福
- /// 创建时间:20220824
- ///
- public class Config
- {
- #region 单例模式
- public static Config Instance = null;
-
- public static Config GetInstance()
- {
- if (Instance == null)
- {
- Instance = new Config();
- }
- return Instance;
- }
- #endregion
-
- public static ScriptRunningMachine srm { get; } = new ScriptRunningMachine();
-
- public Config()
- {
- srm.WorkMode |=
- // Enable DirectAccess
- MachineWorkMode.AllowDirectAccess
- // Ignore exceptions in CLR calling (by default)
- | MachineWorkMode.IgnoreCLRExceptions
- // Enable CLR Event Binding
- | MachineWorkMode.AllowCLREventBind;
-
- RegisterFunction();
- }
-
- ///
- /// 运行脚本
- ///
- ///
- public void RunJsScipt(string script)
- {
- try
- {
- srm.Run(script);
- }
- catch (Exception e)
- {
- //MessageBox.Show(e.Message, "脚本错误");
- }
- }
-
- ///
- /// 注册对象到js
- ///
- public void SetVariable(string name, object obj)
- {
- srm.SetGlobalVariable(name, obj);
- }
-
- ///
- /// 注册方法到Js
- ///
- private static void RegisterFunction()
- {
- srm["ShowMessage"] = new NativeFunctionObject("ShowMessage", (ctx, owner, args) =>
- {
- StringBuilder sb = new StringBuilder();
- foreach (var item in args)
- {
- sb.Append(item.ToString());
- }
-
- //MessageBox.Show($"{sb}", "提示");
- return null;
- });
-
- srm["SetICDValue"] = new NativeFunctionObject("SetICDValue", (ctx, owner, args) =>
- {
- //MessageBox.Show($"发送ICD数据", "提示");
- return null;
- });
- }
- }
-}
\ No newline at end of file
diff --git a/BPASmartClient.Compiler/FJson.cs b/BPASmartClient.Compiler/FJson.cs
deleted file mode 100644
index a5dc848f..00000000
--- a/BPASmartClient.Compiler/FJson.cs
+++ /dev/null
@@ -1,68 +0,0 @@
-using Newtonsoft.Json;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace BPASmartClient.Compiler
-{
- public class FJson where T : class, new()
- {
- private static string path
- {
- get
- {
- Directory.CreateDirectory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory,"AccessFile\\JSON"));
- return AppDomain.CurrentDomain.BaseDirectory + "AccessFile\\JSON\\" + typeof(T).Name + ".json";
- }
- }
-
- public static T Data
- {
- get;
- set;
- } = new T();
-
-
- public static void Save()
- {
- string contents = JsonConvert.SerializeObject(Data);
- File.WriteAllText(path,contents);
- }
-
- public static void Read()
- {
- if (File.Exists(path))
- {
- T val = JsonConvert.DeserializeObject(File.ReadAllText(path));
- if (val != null)
- {
- Data = val;
- }
- }
- }
-
- public static void SaveInterface()
- {
- JsonSerializerSettings jsonSerializerSettings = new JsonSerializerSettings();
- jsonSerializerSettings.TypeNameHandling = TypeNameHandling.Objects;
- string contents = JsonConvert.SerializeObject(Data,Formatting.Indented,jsonSerializerSettings);
- File.WriteAllText(path,contents);
- }
-
- public static void ReadInterface()
- {
- if (File.Exists(path))
- {
- JsonSerializerSettings jsonSerializerSettings = new JsonSerializerSettings();
- jsonSerializerSettings.TypeNameHandling = TypeNameHandling.Objects;
- T val = JsonConvert.DeserializeObject(File.ReadAllText(path),jsonSerializerSettings);
- if (val != null)
- {
- Data = val;
- }
- }
- }
- }
-}
diff --git a/BPASmartClient.Compiler/FRedisClient.cs b/BPASmartClient.Compiler/FRedisClient.cs
deleted file mode 100644
index 63d28bb4..00000000
--- a/BPASmartClient.Compiler/FRedisClient.cs
+++ /dev/null
@@ -1,178 +0,0 @@
-using StackExchange.Redis;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-
-namespace BPASmartClient.Compiler
-{
- public class FRedisClient
- {
- #region 单例模式
- //private static FRedisClient instance = null;
- //public static FRedisClient Instance()
- //{
- // if (instance == null) instance = new FRedisClient();
- // return instance;
- //}
- #endregion
-
- #region 变量
- ///
- /// IP地址
- ///
- public string redisconnection = "124.222.238.75:16000,password=123456";
- ///
- /// redis 连接状态
- ///
- public ConnectionMultiplexer _connection = null;
- ///
- /// 数据存储位置
- ///
- public IDatabase _database = null;
- ///
- /// 通道建立连接
- ///
- public ISubscriber subscibe = null;
- #endregion
-
- #region 外部访问
- ///
- /// 委托出去
- ///
- public Action LogMeaage = null;
- #endregion
-
- public void Connect()
- {
- _connection = ConnectionMultiplexer.Connect(ConfigurationOptions.Parse(redisconnection));
- _database = _connection.GetDatabase(0);//默认使用db0
- subscibe = _connection.GetSubscriber();
- }
- int dbi = 0;
- public void Connect(string connection)
- {
- _connection = ConnectionMultiplexer.Connect(ConfigurationOptions.Parse(connection));
- if (connection.Contains("defaultDatabase="))
- {
- string[] str=connection.Split(',');
- string stro = str.ToList().Find(s => s.Contains("defaultDatabase="));
-
- try
- {
- dbi=int.Parse(stro.Replace("defaultDatabase=",""));
- }
- catch (Exception ex)
- {
-
- throw;
- }
- _database = _connection.GetDatabase(dbi);//默认使用db0
- }
- else
- {
- _database = _connection.GetDatabase(dbi);//默认使用db0
- }
- subscibe = _connection.GetSubscriber();
- }
-
- ///
- /// 获取设备列表
- ///
- ///
- public Dictionary GetKeys()
- {
- Dictionary keys = new Dictionary();
- foreach (var endPoint in _connection.GetEndPoints())
- {
- //获取指定服务器
- var server = _connection.GetServer(endPoint);
- //在指定服务器上使用 keys 或者 scan 命令来遍历key
- //foreach (var key in server.Keys(0,"设备列表:*"))
- //{
- // //获取key对于的值
- // var val = _database.StringGet(key);
- // Console.WriteLine($"key: {key}, value: {val}");
- // keys[key] = val;
- //}
- foreach (var key in server.Keys(dbi,"*"))
- {
- //获取key对于的值
- var val = _database.StringGet(key);
- Console.WriteLine($"key: {key}, value: {val}");
- keys[key] = val;
- }
- }
- return keys;
- }
-
- ///
- /// 订阅通道消息
- ///
- public void SubscribeChanne(string channelname)
- {
- if (subscibe == null) return;
- subscibe.Subscribe(channelname,(channel,message) =>
- {
- MessageLog(channel,message);
- });
- }
-
- ///
- /// 发布通道消息
- ///
- public void PublishChanne(string channelname,string value)
- {
- if (subscibe == null) return;
- subscibe.Publish(channelname,value);
- }
-
- ///
- /// 获取 key 值
- ///
- public RedisValue RedisGet(string key,string hashField = "")
- {
- if (_database == null) return new RedisValue();
- RedisValue result;
- if (string.IsNullOrEmpty(hashField))
- {
- result = _database.StringGet(key);
- }
- else
- {
- result = _database.HashGet(key,hashField);
- }
- return result;
- //MessageLog(key,result);
- }
- ///
- /// 设置 redis 的值
- ///
- public bool RedisSet(string key,string hashField,string value)
- {
- bool result;
- if (string.IsNullOrEmpty(hashField))
- {
- result = _database.StringSet(key,value);
- }
- else
- {
- result = _database.HashSet(key,hashField,value);
- }
- return result;
- }
-
- ///
- /// 消息打印
- ///
- private void MessageLog(string key,string msg)
- {
- if (LogMeaage != null)
- {
- LogMeaage.Invoke(key,msg);
- }
- }
- }
-}
diff --git a/BPASmartClient.Compiler/HttpRequestHelper.cs b/BPASmartClient.Compiler/HttpRequestHelper.cs
deleted file mode 100644
index a969c9e5..00000000
--- a/BPASmartClient.Compiler/HttpRequestHelper.cs
+++ /dev/null
@@ -1,328 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Net;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace BPASmartClient.Compiler
-{
- ///
- /// 该类实现客户端http 同步请求
- /// 支持环境 -.net4.0/-.net4.5
- /// 创建人:奉友福
- ///
- public class HttpRequestHelper
- {
- #region 私有变量
- #endregion
-
- #region 公用函数
- ///
- /// GET 同步请求
- /// 创建人:奉友福
- /// 创建时间:2020-11-19
- ///
- /// 请求地址
- /// 超时时间设置,默认5秒
- public static string HttpGetRequest(string url,int _timeout = 2000)
- {
- string resultData = string.Empty;
-
- try
- {
- WebClient wc = new WebClient();
- byte[] bytes = wc.DownloadData(url);
- string s = Encoding.UTF8.GetString(bytes);
- return s;
- }
- catch (Exception e)
- {
- throw e;
- }
- return "";
-
- try
- {
- var getrequest = HttpRequest.GetInstance().CreateHttpRequest(url,"GET",_timeout);
- var getreponse = getrequest.GetResponse() as HttpWebResponse;
- resultData = HttpRequest.GetInstance().GetHttpResponse(getreponse,"GET");
- }
- catch (Exception)
- {
- throw;
- }
- return resultData;
- }
- ///
- /// POST 同步请求
- /// 创建人:奉友福
- /// 创建时间:2020-11-19
- ///
- /// 请求地址
- /// 请求数据
- ///
- public static string HttpPostRequest(string url,string PostJsonData,int _timeout = 2000)
- {
- string resultData = string.Empty;
- try
- {
- var postrequest = HttpRequest.GetInstance().CreateHttpRequest(url,"POST",_timeout,PostJsonData);
- var postreponse = postrequest.GetResponse() as HttpWebResponse;
- resultData = HttpRequest.GetInstance().GetHttpResponse(postreponse,"POST");
- }
- catch (Exception ex)
- {
- return ex.Message;
- }
- return resultData;
- }
-
- public static string HttpDeleteRequest(string url,string PostJsonData,int _timeout = 10000)
- {
- string resultData = string.Empty;
- try
- {
- var deleteRequest = HttpRequest.CreateDeleteHttpRequest(url,PostJsonData,_timeout);
- var deleteReponse = deleteRequest.GetResponse() as HttpWebResponse;
- using (StreamReader reader = new StreamReader(deleteReponse.GetResponseStream(),Encoding.GetEncoding("UTF-8")))
- {
- resultData = reader.ReadToEnd();
- }
- }
- catch (Exception ex)
- {
- }
- return resultData;
- }
-
- ///
- /// GET 同步请求
- ///
- /// 地址
- /// 头
- /// 内容
- ///
- public static string GetHttpGetResponseWithHead(string url,HttpRequestHeader head,string headInfo)
- {
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
- request.Method = "GET";
- request.ContentType = "application/json;charset=UTF-8";
- request.Timeout = 6000;
- request.Headers.Set(head,headInfo);
- StreamReader sr = null;
- HttpWebResponse response = null;
- Stream stream = null;
- try
- {
- response = (HttpWebResponse)request.GetResponse();
- stream = response.GetResponseStream();
- sr = new StreamReader(stream,Encoding.GetEncoding("utf-8"));
- var resultData = sr.ReadToEnd();
- return resultData;
- }
- catch (Exception ex)
- {
- Console.WriteLine(url + " 访问失败:" + ex.Message);
- //return ex.Message;
- }
- finally
- {
- if (response != null)
- {
- response.Dispose();
- }
- if (stream != null)
- {
- stream.Dispose();
- }
- if (sr != null)
- {
- sr.Dispose();
- }
- }
- return null;
- }
-
-
-
- ///
- /// Post请求带Token
- /// 2021-2-2 by dulf
- ///
- ///
- ///
- ///
- ///
- ///
- public static string HttpPostResponseWithHead(string url,HttpRequestHeader head,string headInfo,string postParam,int Timeout = 6000)
- {
- string resultData = string.Empty;
- try
- {
- var postrequest = WebRequest.Create(url) as HttpWebRequest;
- postrequest.Timeout = Timeout;
- postrequest.Method = "POST";
- postrequest.ContentType = "application/json;charset=UTF-8";
- postrequest.Headers.Set(head,headInfo);
- byte[] data = Encoding.UTF8.GetBytes(postParam);
- using (Stream reqStream = postrequest.GetRequestStream())
- {
- reqStream.Write(data,0,data.Length);
- var postreponse = postrequest.GetResponse() as HttpWebResponse;
- resultData = HttpRequest.GetInstance().GetHttpResponse(postreponse,"POST");
- reqStream.Close();
- }
- return resultData;
- }
- catch (Exception ex)
- {
- Console.Write("请求异常:" + ex.Message);
- }
- return "";
- }
- #endregion
-
- }
- ///
- /// HTTP请求类
- ///
- public class HttpRequest
- {
- #region 私有变量
- ///
- /// http请求超时时间设置
- /// 默认值:5秒
- ///
- private static int Timeout = 5000;
- #endregion
-
- #region 单例模式
- private static HttpRequest _HttpRequest = null;
- public static HttpRequest GetInstance()
- {
- if (_HttpRequest == null)
- {
- _HttpRequest = new HttpRequest();
- }
- return _HttpRequest;
- }
- private HttpRequest()
- {
-
- }
- #endregion
-
- #region 公用函数
- ///
- /// 函数名称:创建http请求
- /// 创建人:奉友福
- /// 创建时间:2020-11-19
- /// 例如GET 请求: 地址 + "GET"
- /// 例如POST请求: 地址 + "POST" + JSON
- ///
- /// http请求地址
- /// http请求方式:GET/POST
- /// http请求附带数据
- ///
- public HttpWebRequest CreateHttpRequest(string url,string requestType,int _timeout = 5000,params object[] strjson)
- {
- HttpWebRequest request = null;
- const string get = "GET";
- const string post = "POST";
- Timeout = _timeout;
- if (string.Equals(requestType,get,StringComparison.OrdinalIgnoreCase))
- {
- request = CreateGetHttpRequest(url);
- }
- if (string.Equals(requestType,post,StringComparison.OrdinalIgnoreCase))
- {
- request = CreatePostHttpRequest(url,strjson[0].ToString());
- }
- return request;
- }
- ///
- /// http获取数据
- ///
- ///
- ///
- ///
- public string GetHttpResponse(HttpWebResponse response,string requestType)
- {
- var resultData = string.Empty;
- const string post = "POST";
- string encoding = "UTF-8";
- if (string.Equals(requestType,post,StringComparison.OrdinalIgnoreCase))
- {
- encoding = response.ContentEncoding;
- if (encoding == null || encoding.Length < 1)
- encoding = "UTF-8";
- }
- using (StreamReader reader = new StreamReader(response.GetResponseStream(),Encoding.GetEncoding(encoding)))
- {
- resultData = reader.ReadToEnd();
- }
- return resultData;
- }
- #endregion
-
- #region 私有函数
- ///
- /// http+GET请求
- ///
- /// 请求地址
- /// 请求结果
- private static HttpWebRequest CreateGetHttpRequest(string url)
- {
- var getrequest = WebRequest.Create(url) as HttpWebRequest;
- getrequest.Method = "GET";
- getrequest.Timeout = Timeout;
- getrequest.ContentType = "application/json;charset=UTF-8";
- getrequest.Proxy = null;
- getrequest.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
- return getrequest;
- }
- ///
- /// http+POST请求
- ///
- /// 请求地址
- ///
- /// 请求结果
- private static HttpWebRequest CreatePostHttpRequest(string url,string postData)
- {
- var postrequest = WebRequest.Create(url) as HttpWebRequest;
- //postrequest.KeepAlive = false;
- postrequest.Timeout = Timeout;
- postrequest.Method = "POST";
- postrequest.ContentType = "application/json;charset=UTF-8";
- //postrequest.ContentLength = postData.Length;
- //postrequest.AllowWriteStreamBuffering = false;
- //StreamWriter writer = new StreamWriter(postrequest.GetRequestStream(), Encoding.UTF8);
- //writer.Write(postData);
- //writer.Flush();
- byte[] data = Encoding.UTF8.GetBytes(postData);
- using (Stream reqStream = postrequest.GetRequestStream())
- {
- reqStream.Write(data,0,data.Length);
- reqStream.Close();
- }
- return postrequest;
- }
-
- public static HttpWebRequest CreateDeleteHttpRequest(string url,string postJson,int _timeout = 5000)
- {
- var deleteRequest = WebRequest.Create(url) as HttpWebRequest;
- deleteRequest.Timeout = _timeout;
- deleteRequest.Method = "DELETE";
- deleteRequest.ContentType = "application/json;charset=UTF-8";
- byte[] data = Encoding.UTF8.GetBytes(postJson);
- using (Stream reqStream = deleteRequest.GetRequestStream())
- {
- reqStream.Write(data,0,data.Length);
- reqStream.Close();
- }
- return deleteRequest;
- }
- #endregion
- }
-}
diff --git a/BPASmartClient.Compiler/IExecutable.cs b/BPASmartClient.Compiler/IExecutable.cs
deleted file mode 100644
index bc656d23..00000000
--- a/BPASmartClient.Compiler/IExecutable.cs
+++ /dev/null
@@ -1,30 +0,0 @@
-using BPASmartClient.MessageName.接收消息Model;
-using System;
-using System.Collections.Generic;
-using System.Collections.ObjectModel;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace BPASmartClient.Compiler
-{
- public interface IExecutable
- {
- ///
- /// 是否执行
- ///
- bool IsExecuteState { get; set; }
- ///
- /// 运行程序 注册事件
- ///
- void Register();
- ///
- /// 控件类型
- ///
- string ControlType { get; }
- ///
- /// 属性改变
- ///
- event EventHandler PropertyChange; //声明一个事件
- }
-}
diff --git a/BPASmartClient.Compiler/MQTT.cs b/BPASmartClient.Compiler/MQTT.cs
deleted file mode 100644
index c532ddd4..00000000
--- a/BPASmartClient.Compiler/MQTT.cs
+++ /dev/null
@@ -1,142 +0,0 @@
-using MQTTnet;
-using MQTTnet.Client;
-using MQTTnet.Client.Options;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace BPASmartClient.Compiler
-{
- public class MQTT
- {
-
- //private volatile static MQTT _Instance;
- //public static MQTT GetInstance => _Instance ?? (_Instance = new MQTT());
- //private MQTT() { }
-
-
- public IMqttClient client;
- IMqttClientOptions options;
-
- ///
- /// MQTT 接收消息
- ///
- public Action MqttReceive { get; set; }
-
- ///
- /// MQTT 连接成功
- ///
- public Action ConnectOk { get; set; }
-
- ///
- /// 重连成功
- ///
- public Action Reconnection { get; set; }
-
-
- public async void MqttInitAsync(string UserName,string pass,string IP,int port,string clientID)
- {
- p1:
- options = new MqttClientOptionsBuilder().WithTcpServer(IP,port).WithClientId(clientID).WithCredentials(UserName,pass).Build();
- client = new MqttFactory().CreateMqttClient();
- client.UseDisconnectedHandler(async c =>
- {
- Thread.Sleep(2000);
- //while (!Device.DataBus.内存数据缓存.DataBus.GetInstance().NetworkConnectState)
- //{
- // Thread.Sleep(2000);
- //}
- //Device.DataBus.内存数据缓存.DataBus.GetInstance().MQTTConnectState = false;
- //logHelper.GetLogConfigInstance().WriteLog(LogLevel.INFO,$"断开连接");
-
- try
- {
- //logHelper.GetLogConfigInstance().WriteLog(LogLevel.INFO,$"重连中");
- await client.ConnectAsync(options);
- }
- catch (Exception ex)
- {
- //logHelper.GetLogConfigInstance().WriteLog(LogLevel.ERROR,ex.Message);
- }
- if (client.IsConnected)
- {
- //logHelper.GetLogConfigInstance().WriteLog(LogLevel.INFO,$"MQTT重连成功");
- if (Reconnection != null) Reconnection();
- }
-
- }).UseApplicationMessageReceivedHandler(c =>
- {
- MqttReceive(c);
- }).UseConnectedHandler((e) =>
- {
- //logHelper.GetLogConfigInstance().WriteLog(LogLevel.INFO,$"连接成功");
- });
-
-
- try
- {
- await client.ConnectAsync(options);
- }
- catch (Exception ex)
- {
- //logHelper.GetLogConfigInstance().WriteLog(LogLevel.ERROR,ex.Message);
- }
- if (!client.IsConnected)
- {
- Thread.Sleep(2000);
- //logHelper.GetLogConfigInstance().WriteLog(LogLevel.INFO,$"mqtt连接失败!重连执行中");
- goto p1;
- }
- Thread.Sleep(2000);
- //logHelper.GetLogConfigInstance().WriteLog(LogLevel.INFO,$"MQTT连接成功!");
- if (ConnectOk != null) ConnectOk();
- }
-
- ///
- /// Mqtt 订阅
- ///
- /// 需要订阅的主题
- public async void MqttSubscriptionAsync(string topic)
- {
- if (client != null)
- {
- if (client.IsConnected)
- {
- try
- {
- var result = await client.SubscribeAsync(new MqttTopicFilterBuilder().WithTopic(topic).WithExactlyOnceQoS().Build());
- }
- catch { }
- }
- }
- }
-
- ///
- /// Mqtt 发布
- ///
- /// 需要发布的主题
- /// 需要发布的内容
- public async void MqttPublishAsync(string topic,string content)
- {
- if (client != null)
- {
- if (client.IsConnected)
- {
-
- var msg = new MqttApplicationMessageBuilder().WithTopic(topic).WithPayload(content).WithExactlyOnceQoS().Build();
- try
- {
- var result = await client.PublishAsync(msg);
- }
- catch { }
- }
- }
- }
-
- private static readonly object sendMessageLock = new object();
-
-
- }
-}
diff --git a/BPASmartClient.Compiler/RedisHelper.cs b/BPASmartClient.Compiler/RedisHelper.cs
deleted file mode 100644
index b3f8e21b..00000000
--- a/BPASmartClient.Compiler/RedisHelper.cs
+++ /dev/null
@@ -1,69 +0,0 @@
-using ServiceStack.Redis;
-using System.Diagnostics;
-
-namespace BPASmartClient.Compiler
-{
- public class RedisHelper
- {
-
- private volatile static RedisHelper _Instance;
- public static RedisHelper GetInstance => _Instance ?? (_Instance = new RedisHelper());
- private RedisHelper() { }
- RedisClient client;
-
- public async Task ConnectAsync(string redisconnection)
- {
- return await Task.Factory.StartNew(new Func(() =>
- {
- if (client == null)
- {
- //"124.222.238.75:16000,password=123456";
- client = new RedisClient("124.222.238.75",16000,"123456",1);
- client.ConnectTimeout = 5000;
- Stopwatch sw = new Stopwatch();
- sw.Start();
- while (!client.IsSocketConnected())
- {
- if (sw.ElapsedMilliseconds >= client.ConnectTimeout) break;
- Thread.Sleep(1000);
- }
- string status = client.IsSocketConnected() ? "成功" : "失败";
- }
- return client.IsSocketConnected();
- }));
-
- }
-
- ///
- /// 清除所有redis 数据
- ///
- public void FlushDb()
- {
- client?.FlushDb();
- }
-
- ///
- /// 设置值
- ///
- ///
- ///
- ///
- public void SetValue(string key,TValue value)
- {
- var res = client?.Set(key,value);
- }
-
- ///
- /// 获取值
- ///
- ///
- ///
- ///
- public TResult GetValue(string key)
- {
- if (client == null) return default(TResult);
- return client.Get(key);
- }
-
- }
-}
diff --git a/BPASmartClient.MinimalistUI/BPASmartClient.MinimalistUI.csproj b/BPASmartClient.MinimalistUI/BPASmartClient.MinimalistUI.csproj
index 0cd74038..449b3683 100644
--- a/BPASmartClient.MinimalistUI/BPASmartClient.MinimalistUI.csproj
+++ b/BPASmartClient.MinimalistUI/BPASmartClient.MinimalistUI.csproj
@@ -27,12 +27,17 @@
-
+
+
+ ..\BPASmartClient.SCADAControl\DLL\BPASmartClient.Compiler.dll
+
+
+
diff --git a/BPASmartClient.MinimalistUI/FControl/RunCanvas.xaml.cs b/BPASmartClient.MinimalistUI/FControl/RunCanvas.xaml.cs
index 7b7c212e..6049c3ab 100644
--- a/BPASmartClient.MinimalistUI/FControl/RunCanvas.xaml.cs
+++ b/BPASmartClient.MinimalistUI/FControl/RunCanvas.xaml.cs
@@ -1,4 +1,5 @@
-using BPASmartClient.Compiler;
+
+using BPASmartClient.Compiler;
using BPASmartClient.MessageName.接收消息Model;
using System;
using System.Collections.Generic;
diff --git a/BPASmartClient.SCADAControl/BPASmartClient.SCADAControl.csproj b/BPASmartClient.SCADAControl/BPASmartClient.SCADAControl.csproj
index 552fa8f3..3854ac4a 100644
--- a/BPASmartClient.SCADAControl/BPASmartClient.SCADAControl.csproj
+++ b/BPASmartClient.SCADAControl/BPASmartClient.SCADAControl.csproj
@@ -56,6 +56,10 @@
..\BPASmartClient.Compiler\DLL\Antlr3.Runtime.dll
+
+ DLL\BPASmartClient.Compiler.dll
+ True
+
..\BPASmartClient.Compiler\DLL\Unvell.ReoScript.dll
diff --git a/BPASmartClient.Compiler/DLL/Antlr3.Runtime.dll b/BPASmartClient.SCADAControl/DLL/Antlr3.Runtime.dll
similarity index 100%
rename from BPASmartClient.Compiler/DLL/Antlr3.Runtime.dll
rename to BPASmartClient.SCADAControl/DLL/Antlr3.Runtime.dll
diff --git a/BPASmartClient.SCADAControl/DLL/BPASmartClient.Compiler.dll b/BPASmartClient.SCADAControl/DLL/BPASmartClient.Compiler.dll
new file mode 100644
index 00000000..bf41ab07
Binary files /dev/null and b/BPASmartClient.SCADAControl/DLL/BPASmartClient.Compiler.dll differ
diff --git a/BPASmartClient.Compiler/DLL/Unvell.ReoScript.dll b/BPASmartClient.SCADAControl/DLL/Unvell.ReoScript.dll
similarity index 100%
rename from BPASmartClient.Compiler/DLL/Unvell.ReoScript.dll
rename to BPASmartClient.SCADAControl/DLL/Unvell.ReoScript.dll
diff --git a/BeDesignerSCADA/Adorners/SelectionAdorner.cs b/BeDesignerSCADA/Adorners/SelectionAdorner.cs
deleted file mode 100644
index 9865ba98..00000000
--- a/BeDesignerSCADA/Adorners/SelectionAdorner.cs
+++ /dev/null
@@ -1,228 +0,0 @@
-using BeDesignerSCADA.Controls;
-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.Documents;
-using System.Windows.Input;
-using System.Windows.Media;
-
-namespace BeDesignerSCADA.Adorners
-{
- internal class SelectionAdorner : Adorner
- {
- public SelectionAdorner(UIElement adornedEIeent) : base(adornedEIeent) { }
-
- protected override void OnRender(DrawingContext drawingContext)
- {
- base.OnRender(drawingContext);
- Rect adornerRect = new Rect(AdornedElement.DesiredSize);
- SolidColorBrush renderBrush = Brushes.Transparent;
- Pen renderPen1 = new Pen(new SolidColorBrush(Colors.Tomato), 1);
- Pen renderPen = new Pen(new SolidColorBrush(Colors.Tomato), 1);
- renderPen1.DashStyle = new DashStyle(new List() { 6, 4 }, 4);
-
- //1.绘制边框
- drawingContext.DrawRectangle(renderBrush, renderPen1, new Rect(adornerRect.TopLeft.X, adornerRect.TopLeft.Y, adornerRect.Width, adornerRect.Height));
- //2.绘制拖动正方形
- // Draw a circle at each corner.
- drawingContext.DrawRectangle(renderBrush, renderPen, new Rect(adornerRect.TopLeft.X - 2.5, adornerRect.TopLeft.Y - 2.5, 5, 5));
- drawingContext.DrawRectangle(renderBrush, renderPen, new Rect(adornerRect.TopRight.X - 2.5, adornerRect.TopRight.Y - 2.5, 5, 5));
- drawingContext.DrawRectangle(renderBrush, renderPen, new Rect(adornerRect.BottomLeft.X - 2.5, adornerRect.BottomLeft.Y - 2.5, 5, 5));
- drawingContext.DrawRectangle(renderBrush, renderPen, new Rect(adornerRect.BottomRight.X - 2.5, adornerRect.BottomRight.Y - 2.5, 5, 5));
- //3.绘制4个中心正方形
- drawingContext.DrawRectangle(renderBrush, renderPen,
- new Rect(adornerRect.TopLeft.X + adornerRect.Width / (double)2 - 2.5, adornerRect.TopLeft.Y - 2.5, 5, 5));
- drawingContext.DrawRectangle(renderBrush, renderPen,
- new Rect(adornerRect.TopRight.X - 2.5, adornerRect.TopRight.Y + adornerRect.Height / (double)2 - 2.5, 5, 5));
- drawingContext.DrawRectangle(renderBrush, renderPen,
- new Rect(adornerRect.BottomLeft.X - 2.5, adornerRect.BottomLeft.Y - adornerRect.Height / (double)2 - 2.5, 5, 5));
- drawingContext.DrawRectangle(renderBrush, renderPen,
- new Rect(adornerRect.BottomRight.X - adornerRect.Width / (double)2 - 2.5, adornerRect.BottomRight.Y - 2.5, 5, 5));
-
- MouseDown += SelectionAdorner_MouseDown;
- MouseMove += SelectionAdorner_MouseMove;
- MouseUp += SelectionAdorner_MouseUp;
- ResourceDictionary languageResDic = new ResourceDictionary();
- languageResDic.Source = new Uri(@"/BeDesignerSCADA;component/Themes/Styles.xaml", UriKind.RelativeOrAbsolute);
- this.Resources.MergedDictionaries.Add(languageResDic);
- ContextMenu = FindResource("AdornerRightMenu") as ContextMenu;
- Tag = CanvasPanel.GetParentObject(AdornedElement);
-
- this.Focus();
- this.SelectionAdorner_MouseDown(this, null);
- this.SelectionAdorner_MouseMove(this, null);
- }
-
- private void SelectionAdorner_MouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
- {
- ReleaseMouseCapture();
- CanvasPanel.GetParentObject(AdornedElement).ClearAlignLine();
- }
-
- ///
- /// 鼠标最后一次按下位置
- ///
- Point lastPoint = new Point();
- ///
- /// 鼠标在控件中的位置
- ///
- public MousePos mousePos;
- double tempX = 0d;
- double tempY = 0d;
- double movePx = 0d;
- ///
- /// 改变鼠标状态,鼠标在控件上,下,左,右,左上,右上,左下,右下,向上不同的光标
- ///
- private void SetCursor()
- {
- Rect adornerRect = new Rect(AdornedElement.DesiredSize);
- double _left = CanvasPanel.GetLeft(AdornedElement);
- double _top = CanvasPanel.GetTop(AdornedElement);
- var DQPoint = Mouse.GetPosition(CanvasPanel.GetParentObject(AdornedElement));
- if (DQPoint.X >= (adornerRect.TopLeft.X - 2.5 + _left) && DQPoint.X <= (adornerRect.TopLeft.X + 2.5 + _left) && DQPoint.Y >= (adornerRect.TopLeft.Y - 2.5 + _top) && DQPoint.Y <= (adornerRect.TopLeft.Y + 2.5 + _top))
- {
- //左上
- this.Cursor = Cursors.SizeNWSE; mousePos = MousePos.LeftTop;
- }
- else if (DQPoint.X >= (adornerRect.TopRight.X - 2.5 + _left) && DQPoint.X <= (adornerRect.TopRight.X + 2.5 + _left) && DQPoint.Y >= (adornerRect.TopRight.Y - 2.5 + _top) && DQPoint.Y <= (adornerRect.TopRight.Y + 2.5 + _top))
- {
- //右上
- this.Cursor = Cursors.SizeNESW; mousePos = MousePos.RightTop;
- }
- else if (DQPoint.X >= (adornerRect.BottomLeft.X - 2.5 + _left) && DQPoint.X <= (adornerRect.BottomLeft.X + 2.5 + _left) && DQPoint.Y >= (adornerRect.BottomLeft.Y - 2.5 + _top) && DQPoint.Y <= (adornerRect.BottomLeft.Y + 2.5 + _top))
- {
- //左下
- this.Cursor = Cursors.SizeNESW; mousePos = MousePos.LeftBottom ;
- }
- else if (DQPoint.X >= (adornerRect.BottomRight.X - 2.5 + _left) && DQPoint.X <= (adornerRect.BottomRight.X + 2.5 + _left) && DQPoint.Y >= (adornerRect.BottomRight.Y - 2.5 + _top) && DQPoint.Y <= (adornerRect.BottomRight.Y + 2.5 + _top))
- {
- //右下
- this.Cursor = Cursors.SizeNWSE; mousePos = MousePos.RightBottom;
- }
- else if (DQPoint.X >= (adornerRect.TopLeft.X + adornerRect.Width / (double)2 - 2.5 + _left) && DQPoint.X <= (adornerRect.TopLeft.X + adornerRect.Width / (double)2 + 2.5 + _left) && DQPoint.Y >= (adornerRect.TopLeft.Y - 2.5 + _top) && DQPoint.Y <= (adornerRect.TopLeft.Y + 2.5 + _top))
- {
- //上中
- this.Cursor = Cursors.SizeNS; mousePos = MousePos.Top;
- }
- else if (DQPoint.X >= (adornerRect.BottomRight.X - adornerRect.Width / (double)2 - 2.5 + _left) && DQPoint.X <= (adornerRect.BottomRight.X - adornerRect.Width / (double)2 + 2.5 + _left) && DQPoint.Y >= (adornerRect.BottomRight.Y - 2.5 + _top) && DQPoint.Y <= (adornerRect.BottomRight.Y + 2.5 + _top))
- {
- //下中
- this.Cursor = Cursors.SizeNS; mousePos = MousePos.Bottom;
- }
- else if (DQPoint.X >= (adornerRect.TopRight.X - 2.5 + _left) && DQPoint.X <= (adornerRect.TopRight.X + 2.5 + _left) && DQPoint.Y >= (adornerRect.TopRight.Y + adornerRect.Height / (double)2 - 2.5 + _top) && DQPoint.Y <= (adornerRect.TopRight.Y + adornerRect.Height / (double)2 + 2.5 + _top))
- {
- //右中
- this.Cursor = Cursors.SizeWE; mousePos = MousePos.Right;
- }
- else if (DQPoint.X >= (adornerRect.BottomLeft.X - 2.5 + _left) && DQPoint.X <= (adornerRect.BottomLeft.X + 2.5 + _left) && DQPoint.Y >= (adornerRect.BottomLeft.Y - adornerRect.Height / (double)2 - 2.5 + _top) && DQPoint.Y <= (adornerRect.BottomLeft.Y - adornerRect.Height / (double)2 + 2.5 + _top))
- {
- //左中
- this.Cursor = Cursors.SizeWE; mousePos = MousePos.Left;
- }
- else
- {
- this.Cursor = Cursors.Arrow; mousePos = MousePos.None;
- }
- }
-
-
- private void SelectionAdorner_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
- {
- if (Mouse.LeftButton != MouseButtonState.Pressed
- && Mouse.MiddleButton != MouseButtonState.Pressed
- && Mouse.RightButton != MouseButtonState.Pressed)//鼠标没有按下,改变鼠标状态
- {
- SetCursor();
- }
-
- if (this.Cursor == Cursors.Arrow && Mouse.LeftButton == MouseButtonState.Pressed)//移动控件
- {
- if (lastPoint.X == 0 && lastPoint.Y == 0)
- {
- return;
- }
-
- CaptureMouse();
- var nowPoint = Mouse.GetPosition(CanvasPanel.GetParentObject(AdornedElement));
- double offsetX = nowPoint.X - lastPoint.X;
- double offsetY = nowPoint.Y - lastPoint.Y;
- lastPoint = nowPoint;
-
- tempX += offsetX;
- tempY += offsetY;
-
- var canvas = CanvasPanel.GetParentObject(AdornedElement);
- movePx = canvas.GridPxiel;
-
- if (Math.Abs(tempX) >= movePx)
- {
- offsetX = Math.Round(tempX / movePx) * movePx;
- tempX -= offsetX;
- canvas.MoveControls(offsetX, 0);
- }
-
- if (Math.Abs(tempY) >= movePx)
- {
- offsetY = Math.Round(tempY / movePx) * movePx;
- tempY -= offsetY;
- canvas.MoveControls(0, offsetY);
- }
- }
- else if (this.Cursor != Cursors.Arrow && Mouse.LeftButton == MouseButtonState.Pressed)
- {
- CaptureMouse();
- //lastPoint 最后一次鼠标按下位置 nowPonit 鼠标当前位置 mousePos 鼠标在控件中的位置
- var nowPoint = Mouse.GetPosition(CanvasPanel.GetParentObject(AdornedElement));
- CanvasPanel.GetParentObject(AdornedElement).ReCtrlSize(lastPoint, nowPoint, mousePos);
- lastPoint = nowPoint;
- }
- else if (Mouse.MiddleButton == MouseButtonState.Pressed)//中间同步拖拽控件大小
- {
- CaptureMouse();
- var nowPoint = Mouse.GetPosition(CanvasPanel.GetParentObject(AdornedElement));
- int offsetX = (int)(nowPoint.X - lastPoint.X);
- int offsetY = (int)(nowPoint.Y - lastPoint.Y);
- CanvasPanel.GetParentObject(AdornedElement).ZoomControls(offsetX, offsetY);
- lastPoint = nowPoint;
- }
- }
-
- private void SelectionAdorner_MouseDown(object sender, MouseButtonEventArgs e)
- {
- var canv = CanvasPanel.GetParentObject(AdornedElement);
- lastPoint = Mouse.GetPosition(canv);
- Keyboard.Focus(canv);
-
- if (Keyboard.Modifiers == ModifierKeys.Control && e != null)
- {
- var layer = AdornerLayer.GetAdornerLayer(AdornedElement);
- var arr = layer.GetAdorners(AdornedElement);
- if (canv.SelectedItems.Contains(AdornedElement))
- {
- canv.SelectedItems.Remove(AdornedElement as FrameworkElement);
- canv.RefreshSelection();
- }
- }
- }
- }
-
- ///
- /// 鼠标在控件中的位置
- ///
- public enum MousePos
- {
- None,
- Top,
- Right,
- Bottom,
- Left,
- LeftTop,
- LeftBottom,
- RightTop,
- RightBottom
- }
-}
diff --git a/BeDesignerSCADA/Adorners/SelectionAlignLine.cs b/BeDesignerSCADA/Adorners/SelectionAlignLine.cs
deleted file mode 100644
index 38be84d8..00000000
--- a/BeDesignerSCADA/Adorners/SelectionAlignLine.cs
+++ /dev/null
@@ -1,32 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.Windows;
-using System.Windows.Documents;
-using System.Windows.Media;
-
-namespace BeDesignerSCADA.Adorners
-{
- public class SelectionAlignLine : Adorner
- {
- public SelectionAlignLine(UIElement adornedElement, Point start, Point end) : base(adornedElement)
- {
- startPoint = start;
- endPoint = end;
- }
-
- Point startPoint = default(Point);
- Point endPoint = default(Point);
- protected override void OnRender(DrawingContext drawingContext)
- {
- base.OnRender(drawingContext);
- Rect adornerRect = new Rect(AdornedElement.DesiredSize);
- Pen render = new Pen(new SolidColorBrush(Colors.RoyalBlue), 1);
- render.DashCap = PenLineCap.Round;
- render.DashStyle = new DashStyle(new List() { 4, 2 }, 2);
- drawingContext.DrawLine(render, startPoint, endPoint);
- }
- }
-}
diff --git a/BeDesignerSCADA/BeDesignerSCADA.csproj b/BeDesignerSCADA/BeDesignerSCADA.csproj
index 5bf728ff..fbf1f44f 100644
--- a/BeDesignerSCADA/BeDesignerSCADA.csproj
+++ b/BeDesignerSCADA/BeDesignerSCADA.csproj
@@ -8,9 +8,21 @@
Images\fyf.ico
+
+
+
+
+
+
+
+
+
+
+
+
@@ -68,15 +80,6 @@
-
-
- DLL\Antlr3.Runtime.dll
-
-
- DLL\Unvell.ReoScript.dll
-
-
-
@@ -102,11 +105,22 @@
-
+
+
+ ..\BPASmartClient.SCADAControl\DLL\Antlr3.Runtime.dll
+
+
+ ..\BPASmartClient.SCADAControl\DLL\BPASmartClient.Compiler.dll
+
+
+ ..\BPASmartClient.SCADAControl\DLL\Unvell.ReoScript.dll
+
+
+
diff --git a/BeDesignerSCADA/Controls/CanvasPanel.cs b/BeDesignerSCADA/Controls/CanvasPanel.cs
deleted file mode 100644
index 40f37ead..00000000
--- a/BeDesignerSCADA/Controls/CanvasPanel.cs
+++ /dev/null
@@ -1,990 +0,0 @@
-using BeDesignerSCADA.Adorners;
-using BeDesignerSCADA.Speical;
-using BPASmartClient.Compiler;
-using BPASmartClient.SCADAControl;
-using Microsoft.Toolkit.Mvvm.Input;
-using System;
-using System.Collections.Generic;
-using System.Collections.ObjectModel;
-using System.IO;
-using System.Linq;
-using System.Reflection;
-using System.Text;
-using System.Threading.Tasks;
-using System.Windows;
-using System.Windows.Controls;
-using System.Windows.Controls.Primitives;
-using System.Windows.Documents;
-using System.Windows.Input;
-using System.Windows.Markup;
-using System.Windows.Media;
-using System.Windows.Shapes;
-using System.Xml;
-
-namespace BeDesignerSCADA.Controls
-{
- public class CanvasPanel : Canvas
- {
- public CanvasPanel()
- {
- UseLayoutRounding = true;
- Drop += CanvasPanel_Drop;
- CopySelectItemsCommand = new RelayCommand(CopySelectItems);
- PasteSelectItemsCommand = new RelayCommand(PasteSelectItems);
- DeleteSelectItemsCommand = new RelayCommand(DeleteSelectItems);
- SetTopLayerCommand = new RelayCommand(SetTopLayer);
- SetBottomLayerCommand = new RelayCommand(SetBottomLayer);
- SelectedItems = new ObservableCollection();
- ContextMenu=Application.Current.Resources["CanvasRightMenu"] as ContextMenu;
- KeyDown += CanvasPanel_KeyDown;
- }
-
- #region 添加控件
- private void CanvasPanel_Drop(object sender, DragEventArgs e)
- {
- Type type = e.Data.GetData("System.RuntimeType") as Type;
- var t = type.GetCustomAttributes(typeof(ControlTypeAttribute), false);
- if (t.Length > 0)
- {
- Console.WriteLine((t as ControlTypeAttribute[])[0].Group);
- }
-
- try
- {
- var control = Activator.CreateInstance(type) as FrameworkElement;
- control.Name = GetControlName(type);
- Children.Add(control);
-
- var xPos = e.GetPosition(this).X;
- var yPos = e.GetPosition(this).Y;
- if (xPos % GridPxiel != 0)
- xPos = (GridPxiel - xPos % GridPxiel) + xPos;
- if (yPos % GridPxiel != 0)
- yPos = (GridPxiel - yPos % GridPxiel) + yPos;
-
- SetLeft(control, xPos);
- SetTop(control, yPos);
-
- SelectedItems = new ObservableCollection() { control };
- SelectedItem = control;
- }
- catch (Exception)
- {
- }
-
- }
-
- string GetControlName(Type ctrlType)
- {
- var children = Children.GetEnumerator();
- children.Reset();
- List names = new List();
- while (children.MoveNext())
- {
- if (children.Current.GetType().Name == ctrlType.Name)
- {
- names.Add((children.Current as FrameworkElement).Name);
- }
- }
-
- var nameIndex = names.Count;
- while (names.Contains($"{ctrlType.Name.ToLower().Replace("the", string.Empty)}{nameIndex}"))
- {
- nameIndex++;
- }
-
- return $"{ctrlType.Name.ToLower().Replace("the", string.Empty)}{nameIndex}";
- }
- #endregion
-
- #region 初始化
- protected override void OnVisualChildrenChanged(DependencyObject visualAdded, DependencyObject visualRemoved)
- {
- if (visualAdded is Border || visualRemoved is Border)
- {
- return;
- }
-
- if (visualAdded is FrameworkElement ctrl)
- {
- ctrl.PreviewMouseLeftButtonDown += Ctrl_MouseLeftButtonDown;
- }
- if (visualRemoved is FrameworkElement ctr)
- {
- ctr.PreviewMouseLeftButtonDown -= Ctrl_MouseLeftButtonDown;
- }
-
- base.OnVisualChildrenChanged(visualAdded, visualRemoved);
- }
- #endregion
-
- #region 单击选中项处理
- ///
- /// 单击了控件时:不调用框选的刷新方式
- ///
- bool isClickedControl = false;
- ///
- /// 左键按下
- ///
- ///
- ///
- private void Ctrl_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
- {
- if (sender is FrameworkElement ctl)
- {
- var cp = GetParentObject(ctl);
- if (Keyboard.Modifiers == ModifierKeys.Control)
- {
- cp.SelectedItems.Add(ctl);
- }
- else
- {
- cp.SelectedItems = new ObservableCollection() { ctl };
- }
- isClickedControl = true;
- RefreshSelection();
- }
- }
- ///
- /// 获取属性
- ///
- ///
- ///
- ///
- public static T GetParentObject(DependencyObject obj) where T : FrameworkElement
- {
- DependencyObject parent = VisualTreeHelper.GetParent(obj);
- while (parent != null)
- {
- if (parent is T)
- {
- return (T)parent;
- }
- parent = VisualTreeHelper.GetParent(parent);
- }
- return null;
- }
- #endregion
-
- #region 右键菜单
- #endregion
-
- #region 绘制选择框
- Border selectionBorder = new Border()
- {
- Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#557F7F7F")),
- BorderThickness = new Thickness(1),
- BorderBrush = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FF303030")),
- };
-
- protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
- {
- base.OnMouseLeftButtonDown(e);
- selectionStart = e.GetPosition(this);
- if (!this.Children.Contains(selectionBorder))
- {
- this.Children.Add(selectionBorder);
- this.CaptureMouse();
- }
-
- }
-
- Point selectionStart = default;
- protected override void OnMouseMove(MouseEventArgs e)
- {
- if (isClickedControl)
- {
- return;
- }
- base.OnMouseMove(e);
- if (e.LeftButton == MouseButtonState.Pressed)
- {
- var nowPoint = e.GetPosition(this);
-
- var offsetX = nowPoint.X - selectionStart.X;
- var offsetY = nowPoint.Y - selectionStart.Y;
- Clear();
-
- selectionBorder.Width = Math.Abs(offsetX);
- selectionBorder.Height = Math.Abs(offsetY);
- // 分四种情况绘制
- if (offsetX >= 0 && offsetY >= 0)// 右下
- {
- SetLeft(selectionBorder, selectionStart.X);
- SetTop(selectionBorder, selectionStart.Y);
- }
- else if (offsetX > 0 && offsetY < 0)// 右上
- {
- SetLeft(selectionBorder, selectionStart.X);
- SetBottom(selectionBorder, ActualHeight - selectionStart.Y);
-
- }
- else if (offsetX < 0 && offsetY > 0)// 左下
- {
- SetRight(selectionBorder, ActualWidth - selectionStart.X);
- SetTop(selectionBorder, selectionStart.Y);
- }
- else if (offsetX < 0 && offsetY < 0)// 左上
- {
- SetRight(selectionBorder, ActualWidth - selectionStart.X);
- SetBottom(selectionBorder, ActualHeight - selectionStart.Y);
- }
-
-
- }
- }
-
- protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
- {
- base.OnMouseLeftButtonUp(e);
- if (double.IsNaN(GetLeft(selectionBorder)))
- {
- SetLeft(selectionBorder, ActualWidth - GetRight(selectionBorder) - selectionBorder.ActualWidth);
- }
- if (double.IsNaN(GetTop(selectionBorder)))
- {
- SetTop(selectionBorder, ActualHeight - GetBottom(selectionBorder) - selectionBorder.ActualHeight);
- }
-
- FrameSelection(GetLeft(selectionBorder), GetTop(selectionBorder), selectionBorder.Width, selectionBorder.Height);
- selectionBorder.Width = 0;
- selectionBorder.Height = 0;
- this.Children.Remove(selectionBorder);
- this.ReleaseMouseCapture();
- }
-
- private void Clear()
- {
- SetLeft(selectionBorder, double.NaN);
- SetRight(selectionBorder, double.NaN);
- SetTop(selectionBorder, double.NaN);
- SetBottom(selectionBorder, double.NaN);
- }
-
- #endregion
-
- #region 选中属性
- public FrameworkElement SelectedItem
- {
- get { return (FrameworkElement)GetValue(SelectedItemProperty); }
- set { SetValue(SelectedItemProperty, value); }
- }
- public static readonly DependencyProperty SelectedItemProperty =
- DependencyProperty.Register("SelectedItem", typeof(FrameworkElement), typeof(CanvasPanel), new PropertyMetadata(null, OnSelectedItemChanged));
- private static void OnSelectedItemChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) => (d as CanvasPanel)?.RefreshSelection1();
- public void RefreshSelection1()
- {
-
- }
- #endregion
-
- #region 框选
- public ObservableCollection SelectedItems
- {
- get { return (ObservableCollection)GetValue(SelectedItemsProperty); }
- set { SetValue(SelectedItemsProperty, value); }
- }
- public static readonly DependencyProperty SelectedItemsProperty =
- DependencyProperty.Register("SelectedItems", typeof(ObservableCollection), typeof(CanvasPanel), new PropertyMetadata(null, OnSelectedItemsChanged));
-
- private static void OnSelectedItemsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) => (d as CanvasPanel)?.RefreshSelection();
-
- public void RefreshSelection()
- {
- foreach (var item in Children)
- {
- if (!(item is IExecutable))
- continue;
-
- var ele = item as FrameworkElement;
- if (ele == null) continue;
-
- var layer = AdornerLayer.GetAdornerLayer(ele);
- var arr = layer.GetAdorners(ele);//获取该控件上所有装饰器,返回一个数组
- if (arr != null)
- {
- for (int i = arr.Length - 1; i >= 0; i--)
- {
- layer.Remove(arr[i]);
- }
- }
- }
-
- if (SelectedItems != null)
- {
- foreach (var item in SelectedItems)
- {
- var layer = AdornerLayer.GetAdornerLayer(item);
- layer.Add(new SelectionAdorner(item));
- SelectedItem = item;
- }
- }
- }
-
- ///
- /// 移除所有选择装饰器
- ///
- public void ClearSelection()
- {
- foreach (var item in Children)
- {
- if (!(item is IExecutable))
- continue;
-
- var ele = item as FrameworkElement;
- if (ele == null) continue;
-
- var layer = AdornerLayer.GetAdornerLayer(ele);
- var arr = layer.GetAdorners(ele);//获取该控件上所有装饰器,返回一个数组
- if (arr != null)
- {
- for (int i = arr.Length - 1; i >= 0; i--)
- {
- layer.Remove(arr[i]);
- }
- }
- }
- }
-
- ///
- /// 计算框选项
- ///
- private void FrameSelection(double x, double y, double width, double height)
- {
- if (width > 0 || height > 0)
- {
- isClickedControl = false;
- }
- if (isClickedControl)
- {
- isClickedControl = false;
- SelectedItems = new ObservableCollection();
- return;
- }
- SelectedItems = new ObservableCollection();
- foreach (var item in Children)
- {
- if (item is FrameworkElement ctrl && !(ctrl is Border))
- {
- // 框左上角
- var left = GetLeft(ctrl);
- var top = GetTop(ctrl);
- if (left >= x && left <= x + width && top >= y && top <= y + height)
- {
- if (!SelectedItems.Contains(ctrl))
- SelectedItems.Add(ctrl);
- }
-
- // 框右下角
- var right = left + ctrl.ActualWidth;
- var bottom = top + ctrl.ActualHeight;
- if (right >= x && right <= x + width && bottom >= y && bottom <= y + height)
- {
- if (!SelectedItems.Contains(ctrl))
- SelectedItems.Add(ctrl);
- }
-
- // 框右上角
- if (right >= x && right <= x + width && top >= y && top <= y + height)
- {
- if (!SelectedItems.Contains(ctrl))
- SelectedItems.Add(ctrl);
- }
-
- // 框左下角
- if (left >= x && left <= x + width && bottom >= y && bottom <= y + height)
- {
- if (!SelectedItems.Contains(ctrl))
- SelectedItems.Add(ctrl);
- }
- }
- }
-
- RefreshSelection();
- }
- #endregion
-
- #region 外部调用
- public List GetAllExecChildren()
- {
- List result = new List();
- foreach (var ctrl in Children)
- {
- if (ctrl is IExecutable exec)
- {
- result.Add(ctrl as FrameworkElement);
- }
- }
-
- return result;
- }
-
- ///
- /// 对齐像素单位
- ///
- public int GridPxiel
- {
- get { return (int)GetValue(GridPxielProperty); }
- set { SetValue(GridPxielProperty, value); }
- }
- public static readonly DependencyProperty GridPxielProperty =
- DependencyProperty.Register("GridPxiel", typeof(int), typeof(CanvasPanel), new PropertyMetadata(4));
-
-
- public void MoveControls(double offsetX, double offsetY)
- {
- ClearAlignLine();
-
- // 获取可对齐的点
- List points = new List();
- foreach (FrameworkElement ctrl in Children)
- {
- if (!SelectedItems.Contains(ctrl))
- {
- // 左上的点
- Point item = new Point(GetLeft(ctrl), GetTop(ctrl));
- points.Add(item);
-
- // 左下的点
- Point itemlb = new Point(GetLeft(ctrl), GetTop(ctrl) + ctrl.ActualHeight);
- points.Add(itemlb);
-
- // 右下的点
- Point itemrb = new Point(GetLeft(ctrl) + ctrl.ActualWidth, GetTop(ctrl) + ctrl.ActualHeight);
- points.Add(itemrb);
-
- // 右上的点
- Point itemrt = new Point(GetLeft(ctrl) + ctrl.ActualWidth, GetTop(ctrl));
- points.Add(itemrt);
- }
- }
-
- // 控件移动
- foreach (var item in SelectedItems)
- {
- var moveX = GetLeft(item) + offsetX;
- moveX = (moveX < 0) ? 0 : moveX;
-
- var moveY = GetTop(item) + offsetY;
- moveY = moveY < 0 ? 0 : moveY;
-
- if (moveX % GridPxiel != 0)
- moveX = (GridPxiel - moveX % GridPxiel) + moveX;
- if (moveY % GridPxiel != 0)
- moveY = (GridPxiel - moveY % GridPxiel) + moveY;
-
- SetLeft(item, moveX);
- SetTop(item, moveY);
- }
-
- // 计算是否显示对齐线
- var targetItemTop = SelectedItems?.Min(x => GetTop(x));
- var targetItem = SelectedItems.FirstOrDefault(x => GetTop(x) == targetItemTop);
- var lefAlign = points.FirstOrDefault(x => Math.Abs(x.X - GetLeft(targetItem)) == 0);
- if (lefAlign != default)
- {
- //SetLeft(targetItem, lefAlign.X);
- var layer = AdornerLayer.GetAdornerLayer(this);
- layer.Add(new SelectionAlignLine(this, lefAlign, new Point(GetLeft(targetItem), GetTop(targetItem))));
- }
-
- var topAlign = points.FirstOrDefault(x => Math.Abs(x.Y - GetTop(targetItem)) == 0);
- if (topAlign != default)
- {
- //SetTop(targetItem, topAlign.Y);
- var layer = AdornerLayer.GetAdornerLayer(this);
- layer.Add(new SelectionAlignLine(this, topAlign, new Point(GetLeft(targetItem), GetTop(targetItem))));
- }
-
- int px = 20;
- // 网格对齐
- if (UseAutoAlignment)
- {
- foreach (var item in SelectedItems)
- {
- var left = GetLeft(item);
- if (left % px <= 1)
- {
- SetLeft(item, (int)left / px * px);
- }
-
- var top = GetTop(item);
- if (top % px <= 1)
- {
- SetTop(item, (int)top / px * px);
- }
- }
- }
- }
-
- ///
- /// 清除绘制的对齐线
- ///
- public void ClearAlignLine()
- {
- var arr = AdornerLayer.GetAdornerLayer(this).GetAdorners(this);
- if (arr != null)
- {
- for (int i = arr.Length - 1; i >= 0; i--)
- {
- AdornerLayer.GetAdornerLayer(this).Remove(arr[i]);
- }
- }
- }
-
- public void ZoomControls(int offsetX, int offsetY)
- {
- foreach (var item in SelectedItems)
- {
- if (item.ActualHeight + offsetY > 10)
- {
- item.Height += offsetY;
- }
- if (item.ActualWidth + offsetX > 10)
- {
- item.Width += offsetX;
- }
- }
- }
-
- ///
- /// 调整控件大小:鼠标在控件中的不同位置,调整控件大小
- ///
- public void ReCtrlSize(Point lastPoint,Point currentPoint, MousePos mousePos)
- {
- foreach (var control in SelectedItems)
- {
- //计算偏移量
- double x = currentPoint.X - lastPoint.X;
- double y = currentPoint.Y - lastPoint.Y;
- switch (mousePos)
- {
- case MousePos.None:
- break;
- case MousePos.Top://上,调整
- if (control.Height - y > control.MinHeight)
- {
- SetTop(control, GetTop(control) + y);
- //control.Top += y;
- control.Height -= y;
- }
- break;
- case MousePos.Right:
- if (control.Width + x > control.MinWidth)
- {
- control.Width += x;
- }
- break;
- case MousePos.Bottom:
- if (control.Height + y > control.MinHeight)
- {
- control.Height += y;
- }
- break;
- case MousePos.Left:
- if (control.Width - x > control.MinWidth)
- {
- SetLeft(control, GetLeft(control) + x);//control.Left += x;
- control.Width -= x;
- }
- break;
- case MousePos.LeftTop://左上
- if (control.Width - x > control.MinWidth)
- {
- SetLeft(control, GetLeft(control) + x);//control.Left += x;
- control.Width -= x;
- }
- if (control.Height - y > control.MinHeight)
- {
- SetTop(control, GetTop(control) + y);//control.Top += y;
- control.Height -= y;
- }
- break;
- case MousePos.LeftBottom:
- if (control.Width - x > control.MinWidth)
- {
- SetLeft(control, GetLeft(control) + x);//control.Left += x;
- control.Width -= x;
- }
- if (control.Height + y > control.MinHeight)
- {
- control.Height += y;
- }
- break;
- case MousePos.RightTop:
- if (control.Width + x > MinWidth)
- {
- control.Width += x;
- }
- if (control.Height - y > MinHeight)
- {
- SetTop(control, GetTop(control) + y);//control.Top += y;
- control.Height -= y;
- }
- break;
- case MousePos.RightBottom:
- if (control.Width + x > MinWidth)
- {
- control.Width += x;
- }
- if (control.Height + y > MinHeight)
- {
- control.Height += y;
- }
- break;
- default:
- break;
- }
- }
-
- }
- #endregion
-
- #region 对齐操作
- ///
- /// 是否使用网格对齐 10px
- ///
- public bool UseAutoAlignment
- {
- get { return (bool)GetValue(UseAutoAlignmentProperty); }
- set { SetValue(UseAutoAlignmentProperty, value); }
- }
- public static readonly DependencyProperty UseAutoAlignmentProperty =
- DependencyProperty.Register("UseAutoAlignment", typeof(bool), typeof(CanvasPanel), new PropertyMetadata(false));
-
-
- public void AlignLeft()
- {
- if (SelectedItems == null || SelectedItems.Count == 0)
- return;
-
- var leftMin = SelectedItems.Min(x => Canvas.GetLeft(x));
- foreach (var item in SelectedItems)
- {
- SetLeft(item, leftMin);
- }
- }
-
- public void AlignRight()
- {
- if (SelectedItems == null || SelectedItems.Count == 0)
- return;
-
- var rightMax = SelectedItems.Max(x => GetLeft(x) + x.ActualWidth);
- foreach (var item in SelectedItems)
- {
- var targetLeft = rightMax - item.ActualWidth;
- SetLeft(item, targetLeft);
- }
- }
-
- public void AlignCenter()
- {
- if (SelectedItems == null || SelectedItems.Count == 0)
- return;
-
- var leftmin = SelectedItems.Min(x => GetLeft(x));
- var rightmax = SelectedItems.Max(x => GetLeft(x) + x.ActualWidth);
- var center = (rightmax - leftmin) / 2 + leftmin;
-
- foreach (var item in SelectedItems)
- {
- var target = center - (item.ActualWidth / 2);
- SetLeft(item, target);
- }
- }
-
- public void AlignTop()
- {
- if (SelectedItems == null || SelectedItems.Count == 0)
- return;
-
- var topMin = SelectedItems.Min(x => GetTop(x));
- foreach (var item in SelectedItems)
- {
- SetTop(item, topMin);
- }
- }
-
- public void AlignBottom()
- {
- if (SelectedItems == null || SelectedItems.Count == 0)
- return;
-
- var botMax = SelectedItems.Max(x => GetTop(x) + x.ActualHeight);
- foreach (var item in SelectedItems)
- {
- var targetLeft = botMax - item.ActualHeight;
- SetTop(item, targetLeft);
- }
- }
-
- public void VertialLayout()
- {
- if (SelectedItems == null || SelectedItems.Count < 3)
- return;
-
- var topCtl = SelectedItems.Min(x => GetTop(x) + x.ActualHeight);
- var botCtrl = SelectedItems.Max(x => GetTop(x));
- var emptyHeight = botCtrl - topCtl;
-
- var orderCtrl = SelectedItems.OrderBy(x => GetTop(x)).ToList();
- orderCtrl.RemoveAt(0);
- orderCtrl.RemoveAt(orderCtrl.Count - 1);
- var useSpace = orderCtrl.Sum(x => x.ActualHeight);
-
- var ableSpaceAvg = (emptyHeight - useSpace) / (SelectedItems.Count - 1);
- double nowPostion = topCtl;
- foreach (var item in orderCtrl)
- {
- SetTop(item, nowPostion + ableSpaceAvg);
- nowPostion += item.ActualHeight + ableSpaceAvg;
- }
- }
-
- public void HorizontalLayout()
- {
- if (SelectedItems == null || SelectedItems.Count < 3)
- return;
-
- var leftCtl = SelectedItems.Min(x => GetLeft(x) + x.ActualWidth);
- var rightCtrl = SelectedItems.Max(x => GetLeft(x));
- var emptyHeight = rightCtrl - leftCtl;
-
- var orderCtrl = SelectedItems.OrderBy(x => GetLeft(x)).ToList();
- orderCtrl.RemoveAt(0);
- orderCtrl.RemoveAt(orderCtrl.Count - 1);
- var useSpace = orderCtrl.Sum(x => x.ActualWidth);
-
- var ableSpaceAvg = (emptyHeight - useSpace) / (SelectedItems.Count - 1);
- double nowPostion = leftCtl;
- foreach (var item in orderCtrl)
- {
- SetLeft(item, nowPostion + ableSpaceAvg);
- nowPostion += item.ActualWidth + ableSpaceAvg;
- }
- }
- #endregion
-
- #region 按键操作
- public RelayCommand CopySelectItemsCommand { get; set; }
- public RelayCommand PasteSelectItemsCommand { get; set; }
- public RelayCommand DeleteSelectItemsCommand { get; set; }
- public RelayCommand SetTopLayerCommand { get; set; }
- public RelayCommand SetBottomLayerCommand { get; set; }
-
- List copyTemp = new List();
-
- private void CanvasPanel_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.Key == Key.C && Keyboard.Modifiers == ModifierKeys.Control)
- {
- CopySelectItems();
- }
- else if (e.Key == Key.V && Keyboard.Modifiers == ModifierKeys.Control)
- {
- PasteSelectItems();
- }
- else if (e.Key == Key.Delete)
- {
- DeleteSelectItems();
- }
- else if (e.Key == Key.Up)
- {
- var offset = -1;
- foreach (var item in SelectedItems)
- {
- SetTop(item, (GetTop(item) + offset) < 0 ? 0 : GetTop(item) + offset);
- }
- e.Handled = true;
- }
- else if (e.Key == Key.Down)
- {
- var offset = 1;
- foreach (var item in SelectedItems)
- {
- SetTop(item, (GetTop(item) + offset) < 0 ? 0 : GetTop(item) + offset);
- }
- e.Handled = true;
- }
- else if (e.Key == Key.Left)
- {
- var offset = -1;
- foreach (var item in SelectedItems)
- {
- SetLeft(item, (GetLeft(item) + offset) < 0 ? 0 : GetLeft(item) + offset);
- }
- e.Handled = true;
-
- }
- else if (e.Key == Key.Right)
- {
- var offset = 1;
- foreach (var item in SelectedItems)
- {
- SetLeft(item, (GetLeft(item) + offset) < 0 ? 0 : GetLeft(item) + offset);
- }
- e.Handled = true;
- }
- }
-
- ///
- /// 复制
- ///
- public void CopySelectItems()
- {
- copyTemp.Clear();
- foreach (var item in SelectedItems)
- {
- copyTemp.Add(item);
- }
- }
-
- ///
- /// 粘贴
- ///
- public void PasteSelectItems()
- {
- SelectedItems.Clear();
- foreach (var item in copyTemp)
- {
- var xml = XamlWriter.Save(item);
- var element = XamlReader.Parse(xml) as FrameworkElement;
- element.Name += "_1";
-
- SetLeft(element, GetLeft(element) + 10);
- SetTop(element, GetTop(element) + 10);
-
- Children.Add(element);
- SelectedItems.Add(element);
- }
-
- // 将复制的内容替换 以便处理连续复制
- copyTemp.Clear();
- foreach (var item in SelectedItems)
- {
- copyTemp.Add(item);
- }
- RefreshSelection();
- }
-
- ///
- /// 置于顶层
- ///
- public void SetTopLayer()
- {
- if (SelectedItems.Count == 0)
- return;
-
- foreach (var item in SelectedItems)
- {
- Children.Remove(item);
- }
-
- foreach (var item in SelectedItems)
- {
- Children.Add(item);
- }
- }
-
- ///
- /// 置于底层
- ///
- public void SetBottomLayer()
- {
- if (SelectedItems.Count == 0)
- return;
-
- foreach (var item in SelectedItems)
- {
- Children.Remove(item);
- }
-
- foreach (var item in SelectedItems)
- {
- Children.Insert(0, item);
- }
- }
- ///
- /// 删除
- ///
- public void DeleteSelectItems()
- {
- foreach (var item in SelectedItems)
- {
- Children.Remove(item);
- }
-
- SelectedItems.Clear();
- RefreshSelection();
- }
- #endregion
-
- #region 运行Xaml 保存 读取
- public List Generator()
- {
- List elements = new List();
- foreach (var item in Children)
- {
- // 排除非自定义的控件们
- if (!(item is IExecutable))
- continue;
- if(item is IDisposable) (item as IDisposable).Dispose();
- var xml = XamlWriter.Save(item);
- var ele = XamlReader.Parse(xml) as FrameworkElement;
- elements.Add(ele);
- }
-
- return elements;
- }
-
- ///
- /// 保存数据到文本
- ///
- public string Save()
- {
- StringBuilder sb = new StringBuilder();
-
- foreach (var item in Children)
- {
- // 排除非自定义的控件们
- if (!(item is IExecutable))
- continue;
- if (item is IDisposable) (item as IDisposable).Dispose();
- var xml = XamlWriter.Save(item);
- sb.Append(xml + "\r\n");
- }
-
- return sb.ToString();
- }
-
- ///
- /// 读取文件
- ///
- public void Load(string path)
- {
- Children.Clear();
- FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
- using (StreamReader sr = new StreamReader(fs, System.Text.Encoding.Unicode))
- {
- while (sr.Peek() > -1)
- {
- string str = sr.ReadLine();
- try
- {
- var ele = XamlReader.Parse(str) as FrameworkElement;
- Children.Add(ele);
- }
- catch (Exception ex)
- {
-
- }
-
- }
- }
-
- SelectedItems?.Clear();
- }
- #endregion
- }
-}
diff --git a/BeDesignerSCADA/Controls/MainCanvasPanel.xaml b/BeDesignerSCADA/Controls/MainCanvasPanel.xaml
index 93c2c854..7a4290c9 100644
--- a/BeDesignerSCADA/Controls/MainCanvasPanel.xaml
+++ b/BeDesignerSCADA/Controls/MainCanvasPanel.xaml
@@ -1,4 +1,5 @@
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -->
-
-
+