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

misc.propertymanager,添加 copyto

parent 192a6a82
......@@ -108,6 +108,9 @@
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<None Include="..\版本说明.txt" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- 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.
......
......@@ -23,11 +23,12 @@ namespace Misc
/// <summary>
/// 设定参数(属性)的值,触发属性值变化“通知”,writeVal
/// </summary>
/// <param name="obj"></param>
/// <param name="propertyName">属性名</param>
/// <param name="val">属性值</param>
/// <param name="v"></param>
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)
{
property.SetValue(obj, v, null);
......@@ -37,11 +38,12 @@ namespace Misc
/// <summary>
/// 设定参数(属性)的值,触发属性值变化“通知”,writeVal
/// </summary>
/// <param name="pname">属性名</param>
/// <param name="val">属性值</param>
/// <param name="obj"></param>
/// <param name="propertyName"></param>
/// <param name="val"></param>
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)
{
object v = Converter.Parse(val, property.PropertyType);
......@@ -52,11 +54,12 @@ namespace Misc
/// <summary>
/// 获取设定的属性值,writeVal
/// </summary>
/// <param name="pname"></param>
/// <param name="obj"></param>
/// <param name="propertyName"></param>
/// <returns></returns>
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)
{
return property.GetValue(obj, null);
......@@ -64,5 +67,20 @@ namespace Misc
else
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
****************************************************************************************************
......
......@@ -175,7 +175,8 @@ namespace FLY.Thick.Blowing.UI.Fix.Client
delegate(object AsyncState, object retData)
{
BlowingFixProfileParam p = (BlowingFixProfileParam)retData;
p.CopyTo(mProfile.Param);
Misc.PropertiesManager.CopyTo<BlowingFixProfileParam>(p, mProfile.Param);
}), null);
}
}
......
......@@ -3,6 +3,7 @@ using FLY.Thick.Blowing.Common;
using FLY.Thick.Blowing.IService;
using FLY.Thick.Blowing.OBJ_INTERFACE;
using FObjBase;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
......@@ -40,9 +41,10 @@ namespace FLY.Thick.Blowing.Client
/// </summary>
public void Apply()
{
string json = JsonConvert.SerializeObject(Param);
CurrObjSys.SetValueEx(mConn, mServerID, ID,
BLOWINGFIX_PROFILE_OBJ_INTERFACE.SET_PARAMS,
Param.ToBytes());
Misc.Converter.StringToBytes(json));
}
......@@ -116,11 +118,10 @@ namespace FLY.Thick.Blowing.Client
{
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))
return;
Param.TryParse(infodata);
Misc.PropertiesManager.CopyTo(p, Param);
}
break;
......@@ -147,9 +148,9 @@ namespace FLY.Thick.Blowing.Client
break;
case BLOWINGFIX_PROFILE_OBJ_INTERFACE.CALL_READ:
{
BlowingFixProfileParam p = new BlowingFixProfileParam();
if (!p.TryParse(retdata))
return;
string json = Misc.Converter.BytesToString(retdata);
BlowingFixProfileParam p = JsonConvert.DeserializeObject<BlowingFixProfileParam>(json);
((AsyncCBHandler)AsyncDelegate)(AsyncState, p);
}
break;
......
......@@ -3,6 +3,7 @@ using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Text;
namespace FLY.Thick.Blowing.Common
......@@ -40,108 +41,32 @@ namespace FLY.Thick.Blowing.Common
public bool SolveEnable { get; set; } = false;
/// <summary>
/// 膜宽 单位 mm
/// 膜宽 单位 mm, 收卷时,切膜前,测量的宽度
/// </summary>
public int FilmWidth { get; set; } = 1500;
public int FilmWidth { get; set; } = 1180;
/// <summary>
/// 探头所在膜的横向位置 单位 mm
/// </summary>
public int FilmPosH { get; set; } = 70;
#endregion
#region INotifyPropertyChanged
public event PropertyChangedEventHandler PropertyChanged;
#endregion
#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;
/// <summary>
/// 袋测量模式
/// </summary>
public bool IsBag { get; set; } = false;
#endregion
#region 吹膜定点解方程用
cnt += 1 + 4 + 4;
if (value.Length < index + cnt)
return false;
SolveEnable = BitConverter.ToBoolean(value, idx);
idx += 1;
FilmWidth = BitConverter.ToInt32(value, idx);
idx += 4;
FilmPosH = BitConverter.ToInt32(value, idx);
idx += 4;
#endregion
/// <summary>
/// 探头测量位置,袋折叠的宽度 单位 mm
/// </summary>
public int BagFold0 { get; set; } = 405;
return true;
}
/// <summary>
/// 另一端 袋折叠的宽度 单位 mm
/// </summary>
public int BagFold1 { get; set; } = 415;
#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 @@
<Reference Include="MathNet.Numerics">
<HintPath>..\dll\MathNet.Numerics.dll</HintPath>
</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">
<HintPath>..\..\packages\PropertyChanged2.Fody.2.5.13\lib\net40\PropertyChanged2.dll</HintPath>
</Reference>
......
......@@ -3,6 +3,7 @@ using FLY.Thick.Blowing.Common;
using FLY.Thick.Blowing.IService;
using FLY.Thick.Blowing.OBJ_INTERFACE;
using FObjBase;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
......@@ -47,7 +48,8 @@ namespace FLY.Thick.Blowing.Server.OBJProxy
{
case BLOWINGFIX_PROFILE_OBJ_INTERFACE.GET_PARAMS:
{
infodata = mProfile.Param.ToBytes();
string json = JsonConvert.SerializeObject(mProfile.Param);
infodata = Misc.Converter.StringToBytes(json);
}
break;
default:
......@@ -61,10 +63,10 @@ namespace FLY.Thick.Blowing.Server.OBJProxy
{
case BLOWINGFIX_PROFILE_OBJ_INTERFACE.SET_PARAMS:
{
BlowingFixProfileParam p = new BlowingFixProfileParam();
if (!p.TryParse(infodata))
break;
mProfile.Param.TryParse(infodata);
string json = Misc.Converter.BytesToString(infodata);
BlowingFixProfileParam p = JsonConvert.DeserializeObject<BlowingFixProfileParam>(json);
Misc.PropertiesManager.CopyTo(p, mProfile.Param);
mProfile.Apply();
}
break;
......@@ -113,6 +115,7 @@ namespace FLY.Thick.Blowing.Server.OBJProxy
new AsyncCBHandler(delegate (object AsyncState, object retdata)
{
ConnContext context = (ConnContext)AsyncState;
string json = JsonConvert.SerializeObject(retdata);
CurrObjSys.PushCallFunctionEx(
context.from,
......@@ -120,7 +123,7 @@ namespace FLY.Thick.Blowing.Server.OBJProxy
ID,
context.magic,
BLOWINGFIX_PROFILE_OBJ_INTERFACE.CALL_READ,
((BlowingFixProfileParam)retdata).ToBytes());
Misc.Converter.StringToBytes(json));
}), new ConnContext(from, srcid, magic));
}
break;
......
<?xml version="1.0" encoding="utf-8"?>
<packages>
<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" />
</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