Commit 48729ac8 by liulongfei

修改

parent 6404a122
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VIZ.Framework.Core
{
/// <summary>
/// ObservableCollection列表辅助类
/// </summary>
public static class ObservableCollectionHelper
{
/// <summary>
/// 转化为ObservableCollection
/// </summary>
/// <typeparam name="T">子项类型</typeparam>
/// <param name="list">源</param>
/// <returns>ObservableCollection列表</returns>
public static ObservableCollection<T> ToObservableCollection<T>(this IEnumerable<T> list)
{
if (list == null)
return null;
ObservableCollection<T> result = new ObservableCollection<T>();
foreach (T item in list)
{
result.Add(item);
}
return result;
}
}
}
......@@ -30,35 +30,35 @@ namespace VIZ.Framework.Core
return (TValue)(object)value;
// Int32
if (type == typeof(Int32))
if (type == typeof(Int32) || type == typeof(Int32?))
return (TValue)(object)Convert.ToInt32(value);
// Int64
if (type == typeof(Int64))
if (type == typeof(Int64) || type == typeof(Int64?))
return (TValue)(object)Convert.ToInt64(value);
// Float
if (type == typeof(float))
if (type == typeof(float) || type == typeof(float?))
return (TValue)(object)(float)Convert.ToDouble(value);
// Double
if (type == typeof(double))
if (type == typeof(double) || type == typeof(double?))
return (TValue)(object)Convert.ToDouble(value);
// Bool
if (type == typeof(bool))
if (type == typeof(bool) || type == typeof(bool?))
return (TValue)(object)Convert.ToBoolean(value);
// RawColor4
if (type == typeof(RawColor4))
if (type == typeof(RawColor4) || type == typeof(RawColor4?))
return (TValue)(object)SharpDxColorHelper.FromString(value);
// DateTime
if (type == typeof(DateTime))
if (type == typeof(DateTime) || type == typeof(DateTime?))
return (TValue)(object)DateTime.Parse(value);
// TimeSpan
if (type == typeof(TimeSpan))
if (type == typeof(TimeSpan) || type == typeof(TimeSpan?))
return (TValue)(object)TimeSpan.Parse(value);
return default;
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VIZ.Framework.Core
{
/// <summary>
/// VIZ 控制对象值
/// </summary>
public interface IVizControlObjctsValue
{
/// <summary>
/// 值类型
/// </summary>
VizControlObjectsValueType ValueType { get; }
/// <summary>
/// 获取值
/// </summary>
/// <returns>值</returns>
string GetValue();
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VIZ.Framework.Core
{
/// <summary>
/// VIZ 控制插件命令
/// </summary>
public class VizControlObjctsCommand
{
/// <summary>
/// VIZ 控制插件命令
/// </summary>
/// <param name="args">参数</param>
public VizControlObjctsCommand(Dictionary<string, IVizControlObjctsValue> args)
{
this.Args = args;
}
/// <summary>
/// 参数
/// </summary>
public Dictionary<string, IVizControlObjctsValue> Args { get; private set; }
/// <summary>
/// 转化为命令字符串
/// </summary>
/// <remarks>
/// format: field|value#fild|value
/// </remarks>
/// <returns>命令字符串</returns>
public override string ToString()
{
StringBuilder sb = new StringBuilder();
foreach (var kv in this.Args)
{
sb.Append($"{kv.Key}|{kv.Value.GetValue()}#");
}
string cmd = sb.ToString();
if (cmd.EndsWith("#"))
{
cmd = cmd.Substring(0, cmd.Length - 1);
}
cmd = cmd.Replace("\"", "\\\"");
return cmd;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace VIZ.Framework.Core
{
/// <summary>
/// 控制对象字符串值
/// </summary>
public class VizControlObjectsElementValue : IVizControlObjctsValue
{
/// <summary>
/// XML版本
/// </summary>
public const string XML_VERSION = "<?xml version=\"1.0\"?>";
/// <summary>
/// 控制对象字符串值
/// </summary>
/// <param name="value">值</param>
public VizControlObjectsElementValue(IList<Dictionary<string, string>> items)
{
this.Items = items;
}
/// <summary>
/// 值类型
/// </summary>
public VizControlObjectsValueType ValueType { get; } = VizControlObjectsValueType.Element;
/// <summary>
/// 子项集合
/// </summary>
public IList<Dictionary<string, string>> Items { get; set; }
/// <summary>
/// 获取值
/// </summary>
/// <returns>值</returns>
public string GetValue()
{
XElement root = new XElement("entry");
if (this.Items == null)
return $"{XML_VERSION}{root}";
foreach (Dictionary<string, string> item in this.Items)
{
XElement element = new XElement("element");
element.SetAttributeValue("description", string.Empty);
XElement data = new XElement("entry");
data.SetAttributeValue("name", "data");
foreach (var kv in item)
{
XElement property = new XElement("entry");
property.SetAttributeValue("name", kv.Key);
property.Value = kv.Value ?? string.Empty;
data.Add(property);
}
element.Add(data);
root.Add(element);
}
return $"{XML_VERSION}{root.ToString(SaveOptions.DisableFormatting)}";
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VIZ.Framework.Core
{
/// <summary>
/// 控制对象字符串值
/// </summary>
public class VizControlObjectsStringValue : IVizControlObjctsValue
{
/// <summary>
/// 控制对象字符串值
/// </summary>
/// <param name="value">值</param>
public VizControlObjectsStringValue(string value)
{
this.Value = value;
}
/// <summary>
/// 值类型
/// </summary>
public VizControlObjectsValueType ValueType { get; } = VizControlObjectsValueType.String;
/// <summary>
/// 值
/// </summary>
public string Value { get; set; }
/// <summary>
/// 获取值
/// </summary>
/// <returns>值</returns>
public string GetValue()
{
return this.Value;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VIZ.Framework.Core
{
/// <summary>
/// VIZ 控制插件值
/// </summary>
public enum VizControlObjectsValueType
{
/// <summary>
/// 字符串
/// </summary>
String,
/// <summary>
/// 元素
/// </summary>
Element
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VIZ.Framework.Core
{
/// <summary>
/// VIZ引擎命令集合
/// </summary>
public static class VizEngineCommands
{
/// <summary>
/// 场景动画继续
/// </summary>
public const string STAGE_CONTINUE = "RENDERER*STAGE CONTINUE";
/// <summary>
/// 场景动画开始
/// </summary>
public const string STAGE_START = "RENDERER*STAGE START";
/// <summary>
/// 设置场景
/// 0: 场景目录
/// </summary>
public const string STAGE_SET = "RENDERER SET_OBJECT SCENE*{0}";
/// <summary>
/// 调用方法
/// 0: 方法名
/// 1: 参数
/// </summary>
public const string SCRIPT_INVOKE = "RENDERER*SCRIPT INVOKE {0} \"{1}\"";
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VIZ.Framework.Core
{
/// <summary>
/// VIZ 连接项
/// </summary>
public class VizEngineConnectionItem : ModelBase
{
/// <summary>
/// VIZ 连接项
/// </summary>
/// <param name="ip">IP</param>
/// <param name="port">端口</param>
public VizEngineConnectionItem(string ip, int port)
{
this.IP = ip;
this.Port = port;
}
#region IP -- IP
private string ip;
/// <summary>
/// IP
/// </summary>
public string IP
{
get { return ip; }
set { ip = value; this.RaisePropertyChanged(nameof(IP)); }
}
#endregion
#region Port -- 端口
private int port;
/// <summary>
/// 端口
/// </summary>
public int Port
{
get { return port; }
set { port = value; this.RaisePropertyChanged(nameof(Port)); }
}
#endregion
}
}
using log4net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using VIZ.Framework.Core;
using VizConnectC;
namespace VIZ.Framework.Core
{
/// <summary>
/// VIZ引擎模型
/// </summary>
public class VizEngineModel : ModelBase, IDisposable
{
/// <summary>
/// 日志
/// </summary>
private readonly ILog log = LogManager.GetLogger(typeof(VizEngineModel));
/// <summary>
/// VIZ引擎
/// </summary>
public VizEnginePool Pool { get; private set; } = new VizEnginePool();
/// <summary>
/// VIZ引擎模型
/// </summary>
public VizEngineModel()
{
this.Pool.Connected -= Pool_Connected;
this.Pool.Connected += Pool_Connected;
this.Pool.Disconnected -= Pool_Disconnected;
this.Pool.Disconnected += Pool_Disconnected;
}
#region IsConnected -- 是否连接
private bool isConnected;
/// <summary>
/// 是否连接
/// </summary>
public bool IsConnected
{
get { return isConnected; }
set { isConnected = value; this.RaisePropertySaveChanged(nameof(IsConnected)); }
}
#endregion
/// <summary>
/// 连接
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Pool_Connected(object sender, VizEnginePool.ConnectionEventArgs e)
{
this.IsConnected = true;
}
/// <summary>
/// 断开连接
/// </summary>
private void Pool_Disconnected(object sender, VizEnginePool.ConnectionEventArgs e)
{
this.IsConnected = false;
}
/// <summary>
/// 连接Viz
/// </summary>
/// <param name="ip">地址</param>
/// <param name="port">端口</param>
public bool Connection(string ip, int port)
{
this.Pool.Disconnect();
this.Pool.CleanRendererList();
this.Pool.AddRenderer(ip, port);
if (!this.Pool.Connect())
return false;
return true;
}
/// <summary>
/// 断开连接
/// </summary>
public void Disconnect()
{
this.Pool.Disconnect();
}
/// <summary>
/// 发送命令
/// </summary>
/// <param name="command">命令</param>
public void Send(string command)
{
if (!this.IsConnected)
throw new Exception("viz is not connectd");
this.Pool.Send(command);
StringBuilder sb = new StringBuilder();
sb.AppendLine(string.Empty);
sb.AppendLine("=====================================================================");
sb.AppendLine("发送 VIZ 命令");
sb.AppendLine("----------------------------------------------------------");
sb.AppendLine(command);
sb.AppendLine("=====================================================================");
log.Info(sb.ToString());
}
/// <summary>
/// 销毁
/// </summary>
public void Dispose()
{
this.Pool?.Dispose();
this.Pool?.CleanRendererList();
this.Pool?.Dispose();
this.Pool = null;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VIZ.Framework.Core
{
/// <summary>
/// VIZ 引擎命令扩展
/// </summary>
public static class VizEngineModelCommandExpand
{
/// <summary>
/// 场景开始
/// </summary>
/// <param name="engine">VIZ 引擎</param>
/// <param name="stage">场景名</param>
/// <param name="action">初始化方法名</param>
/// <param name="data">数据</param>
public static void STAGE_START(this VizEngineModel engine, string stage, string action, string data)
{
engine.Send(string.Format(VizEngineCommands.STAGE_SET, stage));
engine.Send(string.Format(VizEngineCommands.SCRIPT_INVOKE, action, data));
engine.Send(VizEngineCommands.STAGE_START);
}
}
}
......@@ -87,6 +87,9 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\05-Lib\TDx.SpaceMouse.Navigation3D.dll</HintPath>
</Reference>
<Reference Include="VizConnectC">
<HintPath>..\..\VIZ.TVP.Golf\Lib\VizConnectC.dll</HintPath>
</Reference>
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
......@@ -103,6 +106,7 @@
<Compile Include="Core\Helper\CmdHelper.cs" />
<Compile Include="Core\Helper\HttpHelper.cs" />
<Compile Include="Core\Helper\KeepSymbolHelper.cs" />
<Compile Include="Core\Helper\ObservableCollectionHelper.cs" />
<Compile Include="Core\Helper\ProcessHelper.cs" />
<Compile Include="Core\Helper\FPSHelper.cs" />
<Compile Include="Core\Helper\ValueHelper.cs" />
......@@ -131,6 +135,15 @@
<Compile Include="Core\Message\MessageInfo.cs" />
<Compile Include="Core\Message\MessageManager.cs" />
<Compile Include="Core\Task\TaskInfo.cs" />
<Compile Include="Core\VIZ\ControlObjects\IVizControlObjctsValue.cs" />
<Compile Include="Core\VIZ\ControlObjects\VizControlObjctsCommand.cs" />
<Compile Include="Core\VIZ\ControlObjects\VizControlObjectsElementValue.cs" />
<Compile Include="Core\VIZ\ControlObjects\VizControlObjectsStringValue.cs" />
<Compile Include="Core\VIZ\ControlObjects\VizControlObjectsValueType.cs" />
<Compile Include="Core\VIZ\Engine\VizEngineCommands.cs" />
<Compile Include="Core\VIZ\Engine\VizEngineConnectionItem.cs" />
<Compile Include="Core\VIZ\Engine\VizEngineModel.cs" />
<Compile Include="Core\VIZ\Engine\VizEngineModelCommandExpand.cs" />
<Compile Include="Expand\GPIO\Core\USB2GPIO.cs" />
<Compile Include="Expand\GPIO\Core\USBDevice.cs" />
<Compile Include="Expand\GPIO\Core\USBDeviceStruct.cs" />
......
......@@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using VIZ.Framework.Core;
......@@ -22,10 +23,7 @@ namespace VIZ.Framework.UnitTest
{
try
{
List<USBDeviceInfo> list = GPIOManager.ScanDevice();
GPIOModel model = new GPIOModel(list[0]);
model.Open();
string str = HttpHelper.Post("https://sportsdata.5club.cctv.cn/mobileinf/rest/sportsdata/matchdata?schedule_id=133001&user=yspxmt&matchtype=FWC2022&encrypted=e80ab00f28b2626898c07c083f1d71de&timestamp=1669138672085&type=1", null, null);
}
......
......@@ -20,6 +20,8 @@ namespace VIZ.Framework.WpfTest
base.OnStartup(e);
AppSetup.Setup();
}
protected override void OnExit(ExitEventArgs e)
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Remoting.Messaging;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
......
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