Commit e7d9bf62 authored by 潘栩锋's avatar 潘栩锋 🚴

1.优化 SQLiteHelper 删除多余

2.添加 WSCF , Reflect_Proxy 添加释放事件资源
parent a91821bb
......@@ -9,8 +9,6 @@ namespace SQLite
public class DBTable<T> : IDBTable
where T : new()
{
public List<SQLiteHelper.ArrayFieldTypeInfo> ArrayFieldTypeInfos = new List<SQLiteHelper.ArrayFieldTypeInfo>();
public string TableName { get; private set; }
private long freeID = 0;
......@@ -32,10 +30,7 @@ namespace SQLite
{
get
{
if (ArrayFieldTypeInfos.Count() == 0)
return ddl;
else
return SQLiteHelper.GetCreateTableCommandText(typeof(T), ArrayFieldTypeInfos.ToArray());
return ddl;
}
}
......@@ -81,7 +76,7 @@ namespace SQLite
sql += " " + condition;
DataTable dataTable = sqliteHelper.ExecuteReader(sql);
return SQLiteHelper.ToObjs<T>(dataTable, ArrayFieldTypeInfos.ToArray());
return SQLiteHelper.ToObjs<T>(dataTable);
}
/// <summary>
......
......@@ -11,15 +11,6 @@ namespace SQLite
}
}
public class BortherAttribute : Attribute
{
}
public class ChildAttribute : Attribute
{
}
public class PropertyIndexAttribute : Attribute
{
......
......@@ -7,7 +7,11 @@
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
<Grid.RowDefinitions>
<RowDefinition Height="100"/>
<RowDefinition/>
</Grid.RowDefinitions>
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center" >
<TextBlock>
Number=<Run Text="{Binding Number,Mode=OneWay}"/>
</TextBlock>
......@@ -15,5 +19,13 @@
AddFuncTime=<Run Text="{Binding AddFuncTime,Mode=OneWay}"/>
</TextBlock>
</StackPanel>
<Grid Grid.Row="1" Margin="5">
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<TextBlock Text="Session 开始时间:"/>
<ListBox x:Name="lst" Grid.Row="1" />
</Grid>
</Grid>
</Window>
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
......@@ -12,6 +13,7 @@ using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;
namespace WSCF.Test.Server
{
......@@ -22,6 +24,10 @@ namespace WSCF.Test.Server
{
WSCF.Test.Server.WsProxy.WsProxy wsProxy;
Foo foo;
DispatcherTimer timer;
ObservableCollection<DateTime> SessionStartTimes = new ObservableCollection<DateTime>();
public MainWindow()
{
InitializeComponent();
......@@ -30,6 +36,35 @@ namespace WSCF.Test.Server
wsProxy = new WsProxy.WsProxy("127.0.0.1:5540",foo);
this.DataContext = foo;
timer = new DispatcherTimer();
timer.Interval = TimeSpan.FromSeconds(1);
timer.Tick += Timer_Tick;
timer.Start();
lst.ItemsSource = SessionStartTimes;
}
private void Timer_Tick(object sender, EventArgs e)
{
if (wsProxy.wssv.WebSocketServices.Hosts.Count() > 0)
{
var startimes = wsProxy.wssv.WebSocketServices.Hosts.First().Sessions.Sessions.Select(s => s.StartTime);
for (int i = 0; i < startimes.Count(); i++)
{
var startime = startimes.ElementAt(i);
if (i < SessionStartTimes.Count)
{
SessionStartTimes[i] = startime;
}
else
{
SessionStartTimes.Add(startime);
}
}
while (SessionStartTimes.Count() > startimes.Count())
SessionStartTimes.RemoveAt(SessionStartTimes.Count() - 1);
}
}
}
}
......@@ -46,6 +46,7 @@
<Reference Include="System.Xaml">
<RequiredTargetFramework>4.0</RequiredTargetFramework>
</Reference>
<Reference Include="websocket-sharp, Version=1.0.1.0, Culture=neutral, PublicKeyToken=5660b08a1845a91e" />
<Reference Include="WindowsBase" />
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
......
......@@ -10,7 +10,7 @@ namespace WSCF.Test.Server.WsProxy
{
public class WsProxy
{
WebSocketServer wssv;
public WebSocketServer wssv;
public WsProxy(string addr, Foo foo)
{
wssv = new WebSocketServer($"ws://{addr}/");
......
......@@ -11,8 +11,9 @@ using WebSocketSharp.Server;
namespace WSCF
{
public class Reflect_Proxy : WebSocketBehavior
public class Reflect_Proxy : WebSocketBehavior,IDisposable
{
static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
//对象的接口类型
Type interfaceType;
//代理对象
......@@ -45,7 +46,20 @@ namespace WSCF
//处理[Push]
InitEventPush();
}
List<DisposeAction> DisposeActions = new List<DisposeAction>();
class DisposeAction
{
public Action<object> Dispose;
public object Obj;
public DisposeAction(Action<object> dispose, object obj)
{
this.Dispose = dispose;
this.Obj = obj;
}
public void Do() {
Dispose(Obj);
}
}
#region Init
void InitPropertyChanged()
{
......@@ -55,6 +69,13 @@ namespace WSCF
//继承了INotifyPropertyChanged
((INotifyPropertyChanged)(this.obj)).PropertyChanged += Obj_PropertyChanged;
//资源释放时断开引用
DisposeActions.Add(new DisposeAction((_obj) =>
{
((INotifyPropertyChanged)(_obj)).PropertyChanged -= Obj_PropertyChanged;
}, this.obj));
var interfaceTypes = new List<Type>();
interfaceTypes.Add(this.interfaceType);
interfaceTypes.AddRange(this.interfaceType.GetInterfaces());
......@@ -112,7 +133,7 @@ namespace WSCF
JObject.FromObject(rd)
);
string json = JsonConvert.SerializeObject(pkgData);
Send(json);
SendEx(json);
}
};
//这个事件需要推送
......@@ -168,6 +189,12 @@ namespace WSCF
subProperties.Add(propertyValue, path);
((INotifyPropertyChanged)(propertyValue)).PropertyChanged += Sub_PropertyChanged;
//资源释放时断开引用
DisposeActions.Add(new DisposeAction((_obj) =>
{
((INotifyPropertyChanged)(_obj)).PropertyChanged -= Sub_PropertyChanged;
}, propertyValue));
//继续向下找
var subPropertyInfos = propertyInfo.PropertyType.GetProperties();
......@@ -203,9 +230,19 @@ namespace WSCF
jObject
);
string json = JsonConvert.SerializeObject(pkgData);
Send(json);
SendEx(json);
}
void SendEx(string msg) {
try
{
Send(msg);
}
catch (Exception e)
{
//异常,通常是断开了!!
logger.Error(e);
}
}
private void Sub_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (ignoreSet)//从服务器接收的数据,不用再推送给服务器
......@@ -249,7 +286,7 @@ namespace WSCF
jObject_parent
);
string json = JsonConvert.SerializeObject(pkgData);
Send(json);
SendEx(json);
}
#endregion
......@@ -264,6 +301,8 @@ namespace WSCF
{
base.OnClose(e);
isAlive = false;
Dispose();
}
protected override void OnMessage(MessageEventArgs e)
......@@ -299,7 +338,7 @@ namespace WSCF
pkgData.data = jObject;
string json = JsonConvert.SerializeObject(pkgData);
Send(json);
SendEx(json);
}
break;
case Reflect_OBJ_INTERFACE.PkgName.CALL_SetProperty:
......@@ -361,13 +400,24 @@ namespace WSCF
);
string json = JsonConvert.SerializeObject(pkgData);
Send(json);
SendEx(json);
}
public void Dispose()
{
foreach (var act in DisposeActions) {
act.Do();
}
DisposeActions.Clear();
}
class CC
{
public string methodName;
public string guid;
}
}
/// <summary>
/// 事件推送包装
......
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