mirror of
https://github.com/eggplantlwj/VisionEdit.git
synced 2026-03-23 16:26:35 +08:00
传输优化
This commit is contained in:
@@ -33,6 +33,9 @@
|
||||
<Reference Include="halcondotnet">
|
||||
<HintPath>C:\Program Files\MVTec\HALCON-19.05-Progress\bin\dotnet20\halcondotnet.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json">
|
||||
<HintPath>G:\2D程序最新版本\G3\UMP_BandOnly_2D_V2.5.4\UMP_BandOnly_S3\bin\x64\Debug\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Drawing" />
|
||||
@@ -46,10 +49,14 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="CommonMethods.cs" />
|
||||
<Compile Include="FileOperate.cs" />
|
||||
<Compile Include="Interface\CommonStruct.cs" />
|
||||
<Compile Include="Interface\IToolInfo.cs" />
|
||||
<Compile Include="Interface\IVisionJobInterface.cs" />
|
||||
<Compile Include="Interface\ToolRun.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Serialize.cs" />
|
||||
<Compile Include="VisionToolAttribute.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
|
||||
144
CommonMethods/FileOperate.cs
Normal file
144
CommonMethods/FileOperate.cs
Normal file
@@ -0,0 +1,144 @@
|
||||
/*
|
||||
* ==============================================================================
|
||||
*
|
||||
* Filename: FileOperate
|
||||
* Description:
|
||||
*
|
||||
* Version: 1.0
|
||||
* Created: 2021/2/26 16:59:16
|
||||
*
|
||||
* Author: liu.wenjie
|
||||
*
|
||||
* ==============================================================================
|
||||
*/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CommonMethods
|
||||
{
|
||||
public class FileTimeInfo
|
||||
{
|
||||
public string FileName; //文件名
|
||||
public DateTime FileCreateTime; //创建时间
|
||||
}
|
||||
|
||||
public class FileOperate
|
||||
{
|
||||
public static void DelFile(string filePath)
|
||||
{
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
File.Delete(filePath);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 文件夹及其子目录的删除
|
||||
/// </summary>
|
||||
/// <param name="directoryPath"></param>
|
||||
public static void DeleteFolder(string directoryPath)
|
||||
{
|
||||
try
|
||||
{
|
||||
foreach (string d in Directory.GetFileSystemEntries(directoryPath))
|
||||
{
|
||||
if (File.Exists(d))
|
||||
{
|
||||
FileInfo fi = new FileInfo(d);
|
||||
if (fi.Attributes.ToString().IndexOf("ReadOnly") != -1)
|
||||
fi.Attributes = FileAttributes.Normal;
|
||||
File.Delete(d);
|
||||
}
|
||||
else
|
||||
DeleteFolder(d); // 递归删除
|
||||
}
|
||||
Directory.Delete(directoryPath);
|
||||
}
|
||||
catch (Exception)
|
||||
{ }
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static FileTimeInfo GetLatestFileTimeInfo(string dir)
|
||||
{
|
||||
List<FileTimeInfo> list = new List<FileTimeInfo>();
|
||||
DirectoryInfo d = new DirectoryInfo(dir);
|
||||
foreach (DirectoryInfo fi in d.GetDirectories())
|
||||
{
|
||||
list.Add(new FileTimeInfo()
|
||||
{
|
||||
FileName = fi.FullName,
|
||||
FileCreateTime = fi.CreationTime
|
||||
});
|
||||
}
|
||||
var qry = from x in list
|
||||
orderby x.FileCreateTime
|
||||
select x;
|
||||
return qry.LastOrDefault();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取某目录下的所有文件(包括子目录下文件)的数量
|
||||
/// </summary>
|
||||
/// <param name="srcPath"></param>
|
||||
/// <returns></returns>
|
||||
public static int GetFileNum(string srcPath)
|
||||
{
|
||||
int fileNum = 0;
|
||||
try
|
||||
{
|
||||
string[] fileList = System.IO.Directory.GetFileSystemEntries(srcPath);
|
||||
foreach (string file in fileList)
|
||||
{
|
||||
fileNum++;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
}
|
||||
return fileNum;
|
||||
}
|
||||
public static void WriteFile(string filePath, string text)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (StreamWriter sw = new StreamWriter(filePath, false, Encoding.UTF8))
|
||||
{
|
||||
byte[] mybyte = Encoding.UTF8.GetBytes(text);
|
||||
text = Encoding.UTF8.GetString(mybyte);
|
||||
sw.Write(text);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
public static string ReadFile(string filePath)
|
||||
{
|
||||
string readResult = string.Empty;
|
||||
try
|
||||
{
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
using (StreamReader sr = new StreamReader(filePath, Encoding.UTF8))
|
||||
{
|
||||
readResult = sr.ReadToEnd();
|
||||
byte[] mybyte = Encoding.UTF8.GetBytes(readResult);
|
||||
readResult = Encoding.UTF8.GetString(mybyte);
|
||||
}
|
||||
}
|
||||
return readResult;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -7,6 +7,7 @@ using System.Windows.Forms;
|
||||
|
||||
namespace CommonMethods
|
||||
{
|
||||
[Serializable]
|
||||
public class IToolInfo
|
||||
{
|
||||
/// <summary>
|
||||
@@ -26,9 +27,9 @@ namespace CommonMethods
|
||||
/// </summary>
|
||||
public object tool { get; set; }
|
||||
/// <summary>
|
||||
/// 工具窗体
|
||||
/// 工具窗体,由于无法对Form进行序列化,所以作为静态变量
|
||||
/// </summary>
|
||||
public Form FormTool { get; set; }
|
||||
public static Form FormTool { get; set; }
|
||||
/// <summary>
|
||||
/// 工具窗体名
|
||||
/// </summary>
|
||||
@@ -116,6 +117,16 @@ namespace CommonMethods
|
||||
toolOutput.RemoveAt(i);
|
||||
}
|
||||
}
|
||||
|
||||
public Form GetFormTool()
|
||||
{
|
||||
return FormTool;
|
||||
}
|
||||
|
||||
public void SetFormTool(Form myForm)
|
||||
{
|
||||
FormTool = myForm;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
27
CommonMethods/Interface/IToolRun.cs
Normal file
27
CommonMethods/Interface/IToolRun.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* ==============================================================================
|
||||
*
|
||||
* Filename: IToolRun
|
||||
* Description:
|
||||
*
|
||||
* Version: 1.0
|
||||
* Created: 2021/2/25 14:49:20
|
||||
*
|
||||
* Author: liu.wenjie
|
||||
*
|
||||
* ==============================================================================
|
||||
*/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace CommonMethods.Interface
|
||||
{
|
||||
public interface IToolRun
|
||||
{
|
||||
void ToolRun(int toolIndex, int inputItemNum, TreeNode selectNode, FormLog myFormLog, FormImageWindow myFormWindow, List<IToolInfo> L_toolList);
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,10 @@ namespace CommonMethods
|
||||
/// </summary>
|
||||
public Dictionary<TreeNode, TreeNode> D_itemAndSource { get; set; } = new Dictionary<TreeNode, TreeNode>();
|
||||
/// <summary>
|
||||
/// JOB上的树结构,取消该参数,TreeView无法二进制序列化
|
||||
/// </summary>
|
||||
//public TreeView tvwOnWorkJob { get; set; } = new TreeView();
|
||||
/// <summary>
|
||||
/// 工具输入项个数
|
||||
/// </summary>
|
||||
public int inputItemNum = 0;
|
||||
@@ -34,9 +38,9 @@ namespace CommonMethods
|
||||
/// </summary>
|
||||
public int outputItemNum = 0;
|
||||
/// <summary>
|
||||
/// 流程运行结果图像
|
||||
/// 流程运行结果图像,取消,无法序列化
|
||||
/// </summary>
|
||||
public HObject jobResultImage { get; set; } = new HObject();
|
||||
public static HObject jobResultImage { get; set; } = new HObject();
|
||||
/// <summary>
|
||||
/// 流程树中节点的最大长度
|
||||
/// </summary>
|
||||
@@ -83,11 +87,11 @@ namespace CommonMethods
|
||||
/// <summary>
|
||||
/// 流程编辑时的右击菜单
|
||||
/// </summary>
|
||||
public ContextMenuStrip rightClickMenu { get; set; } = new ContextMenuStrip();
|
||||
public static ContextMenuStrip rightClickMenu { get; set; } = new ContextMenuStrip();
|
||||
/// <summary>
|
||||
/// 在空白除右击菜单
|
||||
/// </summary>
|
||||
public ContextMenuStrip rightClickMenuAtBlank { get; set; }
|
||||
public static ContextMenuStrip rightClickMenuAtBlank { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
27
CommonMethods/Interface/ToolRun.cs
Normal file
27
CommonMethods/Interface/ToolRun.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* ==============================================================================
|
||||
*
|
||||
* Filename: ToolRun
|
||||
* Description:
|
||||
*
|
||||
* Version: 1.0
|
||||
* Created: 2021/2/25 15:27:56
|
||||
*
|
||||
* Author: liu.wenjie
|
||||
*
|
||||
* ==============================================================================
|
||||
*/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace CommonMethods.Interface
|
||||
{
|
||||
public interface IToolRun
|
||||
{
|
||||
void ToolRun(string jobName, int toolIndex, int inputItemNum, TreeNode selectNode, List<IToolInfo> L_toolList);
|
||||
}
|
||||
}
|
||||
Binary file not shown.
168
CommonMethods/Serialize.cs
Normal file
168
CommonMethods/Serialize.cs
Normal file
@@ -0,0 +1,168 @@
|
||||
/*
|
||||
* ==============================================================================
|
||||
*
|
||||
* Filename: Serial
|
||||
* Description:
|
||||
*
|
||||
* Version: 1.0
|
||||
* Created: 2021/2/25 17:24:56
|
||||
*
|
||||
* Author: liu.wenjie
|
||||
*
|
||||
* ==============================================================================
|
||||
*/
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace CommonMethods
|
||||
{
|
||||
public class Serialize
|
||||
{
|
||||
public static void XmlSerialize<T>(string objname, T obj)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
string filename = objname + ".xml";
|
||||
if (System.IO.File.Exists(filename))
|
||||
System.IO.File.Delete(filename);
|
||||
using (FileStream fileStream = new FileStream(filename, FileMode.Create))
|
||||
{
|
||||
// 序列化为xml
|
||||
XmlSerializer formatter = new XmlSerializer(typeof(T));
|
||||
formatter.Serialize(fileStream, obj);
|
||||
fileStream.Close();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
System.Windows.Forms.MessageBox.Show(ex.Message);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static T XmlDeserailize<T>(string objname)
|
||||
{
|
||||
// System.Runtime.Serialization.IFormatter formatter = new XmlSerializer(typeof(Car));
|
||||
string filename = objname + ".xml";
|
||||
T obj;
|
||||
if (!System.IO.File.Exists(filename))
|
||||
throw new Exception("对反序列化之前,请先序列化");
|
||||
//Xml格式反序列化
|
||||
using (Stream stream = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read))
|
||||
{
|
||||
XmlSerializer formatter = new XmlSerializer(typeof(T));
|
||||
obj = (T)formatter.Deserialize(stream);
|
||||
stream.Close();
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
public static void BinarySerialize<T>(string filename, T obj)
|
||||
{
|
||||
try
|
||||
{
|
||||
//string filename = objname + ".ump";
|
||||
if (System.IO.File.Exists(filename))
|
||||
System.IO.File.Delete(filename);
|
||||
using (FileStream fileStream = new FileStream(filename, FileMode.Create))
|
||||
{
|
||||
// 用二进制格式序列化
|
||||
BinaryFormatter binaryFormatter = new BinaryFormatter();
|
||||
binaryFormatter.Serialize(fileStream, obj);
|
||||
fileStream.Close();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
System.Windows.Forms.MessageBox.Show(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static T BinaryDeserialize<T>(string filename)
|
||||
{
|
||||
System.Runtime.Serialization.IFormatter formatter = new BinaryFormatter();
|
||||
//二进制格式反序列化
|
||||
T obj;
|
||||
//string filename = objname + ".ump";
|
||||
if (!System.IO.File.Exists(filename))
|
||||
throw new Exception("在反序列化之前,请先序列化");
|
||||
using (Stream stream = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read))
|
||||
{
|
||||
obj = (T)formatter.Deserialize(stream);
|
||||
stream.Close();
|
||||
}
|
||||
return obj;
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// 把对象序列化并返回相应的字节
|
||||
/// </summary>
|
||||
/// <param name="pObj">需要序列化的对象</param>
|
||||
/// <returns>byte[]</returns>
|
||||
public static byte[] SerializeObject(object pObj)
|
||||
{
|
||||
if (pObj == null)
|
||||
return null;
|
||||
System.IO.MemoryStream _memory = new System.IO.MemoryStream();
|
||||
BinaryFormatter formatter = new BinaryFormatter();
|
||||
formatter.Serialize(_memory, pObj);
|
||||
_memory.Position = 0;
|
||||
byte[] read = new byte[_memory.Length];
|
||||
_memory.Read(read, 0, read.Length);
|
||||
_memory.Close();
|
||||
return read;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 把字节反序列化成相应的对象
|
||||
/// </summary>
|
||||
/// <param name="pBytes">字节流</param>
|
||||
/// <returns>object</returns>
|
||||
public static object DeserializeObject(byte[] pBytes)
|
||||
{
|
||||
object _newOjb = null;
|
||||
if (pBytes == null)
|
||||
return _newOjb;
|
||||
System.IO.MemoryStream _memory = new System.IO.MemoryStream(pBytes);
|
||||
_memory.Position = 0;
|
||||
BinaryFormatter formatter = new BinaryFormatter();
|
||||
_newOjb = formatter.Deserialize(_memory);
|
||||
_memory.Close();
|
||||
return _newOjb;
|
||||
}
|
||||
public static void JsonSerialize<T>(T obj, string filePath)
|
||||
{
|
||||
string resultJson = JsonConvert.SerializeObject(obj, Formatting.Indented);
|
||||
FileInfo fi = new FileInfo(filePath);
|
||||
if (!fi.Directory.Exists)
|
||||
{
|
||||
Directory.CreateDirectory(fi.Directory.FullName);
|
||||
}
|
||||
FileOperate.WriteFile(filePath, resultJson);
|
||||
}
|
||||
|
||||
public static T JsonDeserializeObject<T>(string jsonString)
|
||||
{
|
||||
T obj;
|
||||
try
|
||||
{
|
||||
obj = JsonConvert.DeserializeObject<T>(FileOperate.ReadFile(jsonString));
|
||||
return obj;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
31
CommonMethods/VisionToolAttribute.cs
Normal file
31
CommonMethods/VisionToolAttribute.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* ==============================================================================
|
||||
*
|
||||
* Filename: VisionToolAttribute
|
||||
* Description:
|
||||
*
|
||||
* Version: 1.0
|
||||
* Created: 2021/2/26 13:46:51
|
||||
*
|
||||
* Author: liu.wenjie
|
||||
*
|
||||
* ==============================================================================
|
||||
*/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CommonMethods
|
||||
{
|
||||
//自定义Attribute
|
||||
public sealed class VisionToolAttribute : Attribute
|
||||
{
|
||||
public ToolType ToolType { get; private set; }
|
||||
public VisionToolAttribute(ToolType toolType)
|
||||
{
|
||||
ToolType = toolType;
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,6 @@
|
||||
G:\VisionEdit\VisionEdit\CommonMethods\bin\Debug\CommonMethods.dll
|
||||
G:\VisionEdit\VisionEdit\CommonMethods\bin\Debug\CommonMethods.pdb
|
||||
G:\VisionEdit\VisionEdit\CommonMethods\bin\Debug\halcondotnet.dll
|
||||
G:\VisionEdit\VisionEdit\CommonMethods\bin\Debug\halcondotnet.xml
|
||||
G:\VisionEdit\VisionEdit\CommonMethods\obj\Debug\CommonMethods.dll
|
||||
G:\VisionEdit\VisionEdit\CommonMethods\obj\Debug\CommonMethods.pdb
|
||||
G:\VisionEdit\VisionEdit\CommonMethods\bin\Debug\CommonMethods.dll
|
||||
G:\VisionEdit\VisionEdit\CommonMethods\bin\Debug\CommonMethods.pdb
|
||||
G:\VisionEdit\VisionEdit\CommonMethods\bin\Debug\halcondotnet.dll
|
||||
G:\VisionEdit\VisionEdit\CommonMethods\bin\Debug\halcondotnet.xml
|
||||
G:\VisionEdit\VisionEdit\CommonMethods\obj\Debug\CommonMethods.dll
|
||||
G:\VisionEdit\VisionEdit\CommonMethods\obj\Debug\CommonMethods.pdb
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user