Commit 45ca1529 authored by 潘栩锋's avatar 潘栩锋 🚴

misc.propertymanager,添加 copyto

parent 192a6a82
...@@ -108,6 +108,9 @@ ...@@ -108,6 +108,9 @@
<Install>true</Install> <Install>true</Install>
</BootstrapperPackage> </BootstrapperPackage>
</ItemGroup> </ItemGroup>
<ItemGroup>
<None Include="..\版本说明.txt" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets. Other similar extension points exist, see Microsoft.Common.targets.
......
...@@ -23,11 +23,12 @@ namespace Misc ...@@ -23,11 +23,12 @@ namespace Misc
/// <summary> /// <summary>
/// 设定参数(属性)的值,触发属性值变化“通知”,writeVal /// 设定参数(属性)的值,触发属性值变化“通知”,writeVal
/// </summary> /// </summary>
/// <param name="obj"></param>
/// <param name="propertyName">属性名</param> /// <param name="propertyName">属性名</param>
/// <param name="val">属性值</param> /// <param name="v"></param>
public static void SetValue(object obj, string propertyName, object v) public static void SetValue(object obj, string propertyName, object v)
{ {
PropertyInfo property = obj.GetType().GetProperties().First(p => { return p.Name == propertyName; }); PropertyInfo property = obj.GetType().GetProperty(propertyName);
if (property != null) if (property != null)
{ {
property.SetValue(obj, v, null); property.SetValue(obj, v, null);
...@@ -37,11 +38,12 @@ namespace Misc ...@@ -37,11 +38,12 @@ namespace Misc
/// <summary> /// <summary>
/// 设定参数(属性)的值,触发属性值变化“通知”,writeVal /// 设定参数(属性)的值,触发属性值变化“通知”,writeVal
/// </summary> /// </summary>
/// <param name="pname">属性名</param> /// <param name="obj"></param>
/// <param name="val">属性值</param> /// <param name="propertyName"></param>
/// <param name="val"></param>
public static void SetValue(object obj, string propertyName, string val) public static void SetValue(object obj, string propertyName, string val)
{ {
PropertyInfo property = obj.GetType().GetProperties().First(p => { return p.Name == propertyName; }); PropertyInfo property = obj.GetType().GetProperty(propertyName);
if (property != null) if (property != null)
{ {
object v = Converter.Parse(val, property.PropertyType); object v = Converter.Parse(val, property.PropertyType);
...@@ -52,11 +54,12 @@ namespace Misc ...@@ -52,11 +54,12 @@ namespace Misc
/// <summary> /// <summary>
/// 获取设定的属性值,writeVal /// 获取设定的属性值,writeVal
/// </summary> /// </summary>
/// <param name="pname"></param> /// <param name="obj"></param>
/// <param name="propertyName"></param>
/// <returns></returns> /// <returns></returns>
public static object GetValue(object obj, string propertyName) public static object GetValue(object obj, string propertyName)
{ {
PropertyInfo property = obj.GetType().GetProperties().First(p => { return p.Name == propertyName; }); PropertyInfo property = obj.GetType().GetProperty(propertyName);
if (property != null) if (property != null)
{ {
return property.GetValue(obj, null); return property.GetValue(obj, null);
...@@ -64,5 +67,20 @@ namespace Misc ...@@ -64,5 +67,20 @@ namespace Misc
else else
return null; return null;
} }
/// <summary>
/// 把 src内的全部属性,复制到 dest
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="src"></param>
/// <param name="dest"></param>
public static void CopyTo<T>(T src, T dest)
{
Type t = typeof(T);
foreach (PropertyInfo propertyInfo in t.GetProperties())
{
propertyInfo.SetValue(dest, propertyInfo.GetValue(src, null), null);
}
}
} }
} }
****************************************************************************************************
产品版本:Misc v1.8.0 20181210
****************************************************************************************************
PropertiesManager
1.增加 CopyTo(1210)
**************************************************************************************************** ****************************************************************************************************
产品版本:Misc v1.7.0 20181126 产品版本:Misc v1.7.0 20181126
**************************************************************************************************** ****************************************************************************************************
......
...@@ -175,7 +175,8 @@ namespace FLY.Thick.Blowing.UI.Fix.Client ...@@ -175,7 +175,8 @@ namespace FLY.Thick.Blowing.UI.Fix.Client
delegate(object AsyncState, object retData) delegate(object AsyncState, object retData)
{ {
BlowingFixProfileParam p = (BlowingFixProfileParam)retData; BlowingFixProfileParam p = (BlowingFixProfileParam)retData;
p.CopyTo(mProfile.Param); Misc.PropertiesManager.CopyTo<BlowingFixProfileParam>(p, mProfile.Param);
}), null); }), null);
} }
} }
......
...@@ -3,6 +3,7 @@ using FLY.Thick.Blowing.Common; ...@@ -3,6 +3,7 @@ using FLY.Thick.Blowing.Common;
using FLY.Thick.Blowing.IService; using FLY.Thick.Blowing.IService;
using FLY.Thick.Blowing.OBJ_INTERFACE; using FLY.Thick.Blowing.OBJ_INTERFACE;
using FObjBase; using FObjBase;
using Newtonsoft.Json;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
...@@ -40,9 +41,10 @@ namespace FLY.Thick.Blowing.Client ...@@ -40,9 +41,10 @@ namespace FLY.Thick.Blowing.Client
/// </summary> /// </summary>
public void Apply() public void Apply()
{ {
string json = JsonConvert.SerializeObject(Param);
CurrObjSys.SetValueEx(mConn, mServerID, ID, CurrObjSys.SetValueEx(mConn, mServerID, ID,
BLOWINGFIX_PROFILE_OBJ_INTERFACE.SET_PARAMS, BLOWINGFIX_PROFILE_OBJ_INTERFACE.SET_PARAMS,
Param.ToBytes()); Misc.Converter.StringToBytes(json));
} }
...@@ -116,11 +118,10 @@ namespace FLY.Thick.Blowing.Client ...@@ -116,11 +118,10 @@ namespace FLY.Thick.Blowing.Client
{ {
case BLOWINGFIX_PROFILE_OBJ_INTERFACE.GET_PARAMS: case BLOWINGFIX_PROFILE_OBJ_INTERFACE.GET_PARAMS:
{ {
BlowingFixProfileParam p = new BlowingFixProfileParam(); string json = Misc.Converter.BytesToString(infodata);
BlowingFixProfileParam p = JsonConvert.DeserializeObject<BlowingFixProfileParam>(json);
if (!p.TryParse(infodata)) Misc.PropertiesManager.CopyTo(p, Param);
return;
Param.TryParse(infodata);
} }
break; break;
...@@ -147,9 +148,9 @@ namespace FLY.Thick.Blowing.Client ...@@ -147,9 +148,9 @@ namespace FLY.Thick.Blowing.Client
break; break;
case BLOWINGFIX_PROFILE_OBJ_INTERFACE.CALL_READ: case BLOWINGFIX_PROFILE_OBJ_INTERFACE.CALL_READ:
{ {
BlowingFixProfileParam p = new BlowingFixProfileParam(); string json = Misc.Converter.BytesToString(retdata);
if (!p.TryParse(retdata)) BlowingFixProfileParam p = JsonConvert.DeserializeObject<BlowingFixProfileParam>(json);
return;
((AsyncCBHandler)AsyncDelegate)(AsyncState, p); ((AsyncCBHandler)AsyncDelegate)(AsyncState, p);
} }
break; break;
......
...@@ -3,6 +3,7 @@ using System; ...@@ -3,6 +3,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Linq; using System.Linq;
using System.Reflection;
using System.Text; using System.Text;
namespace FLY.Thick.Blowing.Common namespace FLY.Thick.Blowing.Common
...@@ -40,108 +41,32 @@ namespace FLY.Thick.Blowing.Common ...@@ -40,108 +41,32 @@ namespace FLY.Thick.Blowing.Common
public bool SolveEnable { get; set; } = false; public bool SolveEnable { get; set; } = false;
/// <summary> /// <summary>
/// 膜宽 单位 mm /// 膜宽 单位 mm, 收卷时,切膜前,测量的宽度
/// </summary> /// </summary>
public int FilmWidth { get; set; } = 1500; public int FilmWidth { get; set; } = 1180;
/// <summary> /// <summary>
/// 探头所在膜的横向位置 单位 mm /// 探头所在膜的横向位置 单位 mm
/// </summary> /// </summary>
public int FilmPosH { get; set; } = 70; public int FilmPosH { get; set; } = 70;
#endregion /// <summary>
#region INotifyPropertyChanged /// 袋测量模式
public event PropertyChangedEventHandler PropertyChanged; /// </summary>
#endregion public bool IsBag { get; set; } = false;
#region IPack 成员
public virtual byte[] ToBytes()
{
List<byte> buf = new List<byte>();
byte[] bs;
#region 正常运行参数
bs = Misc.Converter.StringToBytes(PName);
buf.AddRange(BitConverter.GetBytes(bs.Length));
buf.AddRange(bs);
buf.AddRange(BitConverter.GetBytes(Target));
buf.AddRange(BitConverter.GetBytes(Alarm));
buf.AddRange(BitConverter.GetBytes(Comp));
#endregion
#region 吹膜定点解方程用
buf.AddRange(BitConverter.GetBytes(SolveEnable));
buf.AddRange(BitConverter.GetBytes(FilmWidth));
buf.AddRange(BitConverter.GetBytes(FilmPosH));
#endregion
return buf.ToArray();
}
public virtual bool TryParse(byte[] value)
{
int cnt = 0;
return TryParse(value, 0, out cnt);
}
public virtual bool TryParse(byte[] value, int index, out int cnt)
{
cnt = 0;
int idx = index;
#region 正常运行参数
cnt += 4 + 4 + 4 + 8;
if (value.Length < index + cnt)
return false;
int len = BitConverter.ToInt32(value, idx);
idx += 4;
cnt += len;
if (value.Length < index + cnt)
return false;
PName = Misc.Converter.BytesToString(value, idx, len);
idx += len;
Target = BitConverter.ToInt32(value, idx);
idx += 4;
Alarm = BitConverter.ToInt32(value, idx);
idx += 4;
Comp = BitConverter.ToDouble(value, idx);
idx += 8;
#endregion /// <summary>
#region 吹膜定点解方程用 /// 探头测量位置,袋折叠的宽度 单位 mm
cnt += 1 + 4 + 4; /// </summary>
if (value.Length < index + cnt) public int BagFold0 { get; set; } = 405;
return false;
SolveEnable = BitConverter.ToBoolean(value, idx);
idx += 1;
FilmWidth = BitConverter.ToInt32(value, idx);
idx += 4;
FilmPosH = BitConverter.ToInt32(value, idx);
idx += 4;
#endregion
return true; /// <summary>
} /// 另一端 袋折叠的宽度 单位 mm
/// </summary>
public int BagFold1 { get; set; } = 415;
#endregion #endregion
public event PropertyChangedEventHandler PropertyChanged;
public void CopyTo(BlowingFixProfileParam param)
{
param.PName = PName;
param.Target = Target;
param.Alarm = Alarm;
param.Comp = Comp;
param.SolveEnable = SolveEnable;
param.FilmWidth = FilmWidth;
param.FilmPosH = FilmPosH;
}
} }
} }
...@@ -38,6 +38,9 @@ ...@@ -38,6 +38,9 @@
<Reference Include="MathNet.Numerics"> <Reference Include="MathNet.Numerics">
<HintPath>..\dll\MathNet.Numerics.dll</HintPath> <HintPath>..\dll\MathNet.Numerics.dll</HintPath>
</Reference> </Reference>
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\..\packages\Newtonsoft.Json.12.0.1\lib\net40\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="PropertyChanged2, Version=2.5.13.0, Culture=neutral, PublicKeyToken=ee3ee20bcf148ddd, processorArchitecture=MSIL"> <Reference Include="PropertyChanged2, Version=2.5.13.0, Culture=neutral, PublicKeyToken=ee3ee20bcf148ddd, processorArchitecture=MSIL">
<HintPath>..\..\packages\PropertyChanged2.Fody.2.5.13\lib\net40\PropertyChanged2.dll</HintPath> <HintPath>..\..\packages\PropertyChanged2.Fody.2.5.13\lib\net40\PropertyChanged2.dll</HintPath>
</Reference> </Reference>
......
...@@ -3,6 +3,7 @@ using FLY.Thick.Blowing.Common; ...@@ -3,6 +3,7 @@ using FLY.Thick.Blowing.Common;
using FLY.Thick.Blowing.IService; using FLY.Thick.Blowing.IService;
using FLY.Thick.Blowing.OBJ_INTERFACE; using FLY.Thick.Blowing.OBJ_INTERFACE;
using FObjBase; using FObjBase;
using Newtonsoft.Json;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
...@@ -47,7 +48,8 @@ namespace FLY.Thick.Blowing.Server.OBJProxy ...@@ -47,7 +48,8 @@ namespace FLY.Thick.Blowing.Server.OBJProxy
{ {
case BLOWINGFIX_PROFILE_OBJ_INTERFACE.GET_PARAMS: case BLOWINGFIX_PROFILE_OBJ_INTERFACE.GET_PARAMS:
{ {
infodata = mProfile.Param.ToBytes(); string json = JsonConvert.SerializeObject(mProfile.Param);
infodata = Misc.Converter.StringToBytes(json);
} }
break; break;
default: default:
...@@ -61,10 +63,10 @@ namespace FLY.Thick.Blowing.Server.OBJProxy ...@@ -61,10 +63,10 @@ namespace FLY.Thick.Blowing.Server.OBJProxy
{ {
case BLOWINGFIX_PROFILE_OBJ_INTERFACE.SET_PARAMS: case BLOWINGFIX_PROFILE_OBJ_INTERFACE.SET_PARAMS:
{ {
BlowingFixProfileParam p = new BlowingFixProfileParam(); string json = Misc.Converter.BytesToString(infodata);
if (!p.TryParse(infodata))
break; BlowingFixProfileParam p = JsonConvert.DeserializeObject<BlowingFixProfileParam>(json);
mProfile.Param.TryParse(infodata); Misc.PropertiesManager.CopyTo(p, mProfile.Param);
mProfile.Apply(); mProfile.Apply();
} }
break; break;
...@@ -113,6 +115,7 @@ namespace FLY.Thick.Blowing.Server.OBJProxy ...@@ -113,6 +115,7 @@ namespace FLY.Thick.Blowing.Server.OBJProxy
new AsyncCBHandler(delegate (object AsyncState, object retdata) new AsyncCBHandler(delegate (object AsyncState, object retdata)
{ {
ConnContext context = (ConnContext)AsyncState; ConnContext context = (ConnContext)AsyncState;
string json = JsonConvert.SerializeObject(retdata);
CurrObjSys.PushCallFunctionEx( CurrObjSys.PushCallFunctionEx(
context.from, context.from,
...@@ -120,7 +123,7 @@ namespace FLY.Thick.Blowing.Server.OBJProxy ...@@ -120,7 +123,7 @@ namespace FLY.Thick.Blowing.Server.OBJProxy
ID, ID,
context.magic, context.magic,
BLOWINGFIX_PROFILE_OBJ_INTERFACE.CALL_READ, BLOWINGFIX_PROFILE_OBJ_INTERFACE.CALL_READ,
((BlowingFixProfileParam)retdata).ToBytes()); Misc.Converter.StringToBytes(json));
}), new ConnContext(from, srcid, magic)); }), new ConnContext(from, srcid, magic));
} }
break; break;
......
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<packages> <packages>
<package id="Fody" version="3.2.13" targetFramework="net40" developmentDependency="true" /> <package id="Fody" version="3.2.13" targetFramework="net40" developmentDependency="true" />
<package id="Newtonsoft.Json" version="12.0.1" targetFramework="net40" />
<package id="PropertyChanged2.Fody" version="2.5.13" targetFramework="net40" /> <package id="PropertyChanged2.Fody" version="2.5.13" targetFramework="net40" />
</packages> </packages>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment