Skip to content
This repository has been archived by the owner on Jul 23, 2020. It is now read-only.

Commit

Permalink
rename
Browse files Browse the repository at this point in the history
  • Loading branch information
xljiulang committed Nov 13, 2016
1 parent 8971978 commit 93405fc
Show file tree
Hide file tree
Showing 43 changed files with 261 additions and 294 deletions.
1 change: 0 additions & 1 deletion NetworkSocket/ByteBits.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ namespace NetworkSocket
/// 表示byte的位集合
/// 位索引为高位到低位顺序
/// </summary>
[Serializable]
[DebuggerDisplay("{value}")]
[DebuggerTypeProxy(typeof(DebugView))]
public struct ByteBits : IComparable<ByteBits>
Expand Down
1 change: 0 additions & 1 deletion NetworkSocket/Core/ApiParameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.Remoting.Messaging;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
Expand Down
23 changes: 9 additions & 14 deletions NetworkSocket/Core/Internal/DefaultDynamicJsonSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Dynamic;
using System.IO;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
Expand Down Expand Up @@ -33,10 +33,10 @@ public string Serialize(object model)
/// 序列化为Json
/// </summary>
/// <param name="model">实体</param>
/// <param name="datetimeFomat">时期时间格式化</param>
/// <param name="datetimeFomat">时期时间格式</param>
/// <exception cref="SerializerException"></exception>
/// <returns></returns>
public string Serialize(object model, Func<DateTime, string> datetimeFomat)
public string Serialize(object model, string datetimeFomat)
{
try
{
Expand Down Expand Up @@ -118,20 +118,15 @@ private static class JSON
/// 序列化得到Json
/// </summary>
/// <param name="model">模型</param>
/// <param name="datetimeFomat">时期时间格式化</param>
/// <param name="datetimeFomat">时期时间格式</param>
/// <returns></returns>
public static string Parse(object model, Func<DateTime, string> datetimeFomat)
public static string Parse(object model, string datetimeFomat)
{
if (model == null)
{
return null;
}

if (datetimeFomat == null)
{
datetimeFomat = (time) => time.ToString();
}

var serializer = new JavaScriptSerializer();
var dateTimeConverter = new DateTimeConverter(datetimeFomat);
serializer.MaxJsonLength = int.MaxValue;
Expand All @@ -154,13 +149,13 @@ private class DateTimeConverter : JavaScriptConverter
/// <summary>
/// 时期时间格式化
/// </summary>
private readonly Func<DateTime, string> datetimeFomat;
private readonly string datetimeFomat;

/// <summary>
/// 时间转换
/// </summary>
/// <param name="datetimeFomat">时期时间格式化</param>
public DateTimeConverter(Func<DateTime, string> datetimeFomat)
/// <param name="datetimeFomat">时期时间格式</param>
public DateTimeConverter(string datetimeFomat)
{
this.datetimeFomat = datetimeFomat;
}
Expand Down Expand Up @@ -202,7 +197,7 @@ public override IDictionary<string, object> Serialize(object obj, JavaScriptSeri
}

this.isUsed = true;
var dateTimeString = this.datetimeFomat(dateTime.Value);
var dateTimeString = dateTime.Value.ToString(this.datetimeFomat, DateTimeFormatInfo.InvariantInfo);
return new UriEscapeValue(dateTimeString);
}

Expand Down
4 changes: 0 additions & 4 deletions NetworkSocket/Core/Internal/DefaultSerializer.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
using NetworkSocket.Exceptions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Web.Script.Serialization;

namespace NetworkSocket.Core
{
Expand Down
1 change: 0 additions & 1 deletion NetworkSocket/Exceptions/ApiExecuteException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ namespace NetworkSocket.Exceptions
/// <summary>
/// 表示Api执行异常
/// </summary>
[Serializable]
public class ApiExecuteException : Exception
{
/// <summary>
Expand Down
1 change: 0 additions & 1 deletion NetworkSocket/Exceptions/ApiNotExistException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ namespace NetworkSocket.Exceptions
/// <summary>
/// 表示Api不存在引发的异常
/// </summary>
[Serializable]
[DebuggerDisplay("Message = {Message}")]
public class ApiNotExistException : Exception
{
Expand Down
1 change: 0 additions & 1 deletion NetworkSocket/Exceptions/RemoteException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ namespace NetworkSocket.Exceptions
/// <summary>
/// 表示远程端Api行为异常
/// </summary>
[Serializable]
[DebuggerDisplay("Message = {Message}")]
public class RemoteException : Exception
{
Expand Down
1 change: 0 additions & 1 deletion NetworkSocket/Exceptions/ResolveException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ namespace NetworkSocket.Exceptions
/// <summary>
/// 表示依赖反转异常
/// </summary>
[Serializable]
[DebuggerDisplay("Message = {Message}")]
public class ResolveException : Exception
{
Expand Down
7 changes: 0 additions & 7 deletions NetworkSocket/Fast/FastApiService.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
using NetworkSocket.Core;
using NetworkSocket.Exceptions;
using NetworkSocket.Tasks;
using NetworkSocket.Util;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Reflection;
using System.Runtime.Remoting.Messaging;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace NetworkSocket.Fast
Expand Down
4 changes: 2 additions & 2 deletions NetworkSocket/Fast/FastMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ Task IMiddleware.Invoke(IContenxt context)
private Task OnFastRequestAsync(IContenxt context)
{
var fastPacket = default(FastPacket);
if (FastPacket.Parse(context.InputStream, out fastPacket) == false)
if (FastPacket.Parse(context.StreamReader, out fastPacket) == false)
{
return this.Next.Invoke(context);
}
Expand Down Expand Up @@ -168,7 +168,7 @@ private IList<FastPacket> GenerateFastPackets(IContenxt context, FastPacket fast
while (true)
{
var packet = default(FastPacket);
if (FastPacket.Parse(context.InputStream, out packet) == false)
if (FastPacket.Parse(context.StreamReader, out packet) == false)
{
return list;
}
Expand Down
28 changes: 14 additions & 14 deletions NetworkSocket/Fast/FastPacket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,26 +168,26 @@ public override string ToString()
/// 解析一个数据包
/// 不足一个封包时返回null
/// </summary>
/// <param name="stream">接收到的历史数据</param>
/// <param name="streamReader">数据读取器</param>
/// <param name="packet">数据包</param>
/// <returns></returns>
public static bool Parse(IStreamReader stream, out FastPacket packet)
public static bool Parse(ISessionStreamReader streamReader, out FastPacket packet)
{
if (stream.Length < 1 || stream[0] != FastPacket.Mark)
if (streamReader.Length < 1 || streamReader[0] != FastPacket.Mark)
{
packet = null;
return false;
}

if (stream.Length < 5)
if (streamReader.Length < 5)
{
packet = null;
return true;
}

stream.Position = 1;
streamReader.Position = 1;
const int packetMinSize = 16;
var totalBytes = stream.ReadInt32();
var totalBytes = streamReader.ReadInt32();

if (totalBytes < packetMinSize)
{
Expand All @@ -196,33 +196,33 @@ public static bool Parse(IStreamReader stream, out FastPacket packet)
}

// 数据包未接收完整
if (stream.Length < totalBytes)
if (streamReader.Length < totalBytes)
{
packet = null;
return true;
}

// api名称数据长度
var apiNameLength = stream.ReadByte();
var apiNameLength = streamReader.ReadByte();
if (totalBytes < apiNameLength + packetMinSize)
{
packet = null;
return false;
}

// api名称数据
var apiNameBytes = stream.ReadArray(apiNameLength);
var apiNameBytes = streamReader.ReadArray(apiNameLength);
// 标识符
var id = stream.ReadInt64();
var id = streamReader.ReadInt64();
// 是否为客户端封包
var isFromClient = stream.ReadBoolean();
var isFromClient = streamReader.ReadBoolean();
// 是否异常
var isException = stream.ReadBoolean();
var isException = streamReader.ReadBoolean();
// 实体数据
var body = stream.ReadArray(totalBytes - stream.Position);
var body = streamReader.ReadArray(totalBytes - streamReader.Position);

// 清空本条数据
stream.Clear(totalBytes);
streamReader.Clear(totalBytes);

var apiName = Encoding.UTF8.GetString(apiNameBytes);
packet = new FastPacket(apiName, id, isFromClient)
Expand Down
12 changes: 6 additions & 6 deletions NetworkSocket/Fast/FastTcpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ private void Init()
/// <summary>
/// 当接收到远程端的数据时,将触发此方法
/// </summary>
/// <param name="inputStream">接收到的历史数据</param>
/// <param name="streamReader">数据读取器</param>
/// <returns></returns>
protected sealed override Task OnReceiveAsync(IStreamReader inputStream)
protected sealed override Task OnReceiveAsync(ISessionStreamReader streamReader)
{
var packages = this.GenerateFastPackets(inputStream);
var packages = this.GenerateFastPackets(streamReader);
foreach (var package in packages)
{
this.ProcessPacketAsync(package);
Expand All @@ -108,15 +108,15 @@ protected sealed override Task OnReceiveAsync(IStreamReader inputStream)
/// <summary>
/// 生成数据包
/// </summary>
/// <param name="inputStream">数据流</param>
/// <param name="streamReader">数据流</param>
/// <returns></returns>
private IList<FastPacket> GenerateFastPackets(IStreamReader inputStream)
private IList<FastPacket> GenerateFastPackets(ISessionStreamReader streamReader)
{
var list = new List<FastPacket>();
while (true)
{
var packet = default(FastPacket);
if (FastPacket.Parse(inputStream, out packet) == false)
if (FastPacket.Parse(streamReader, out packet) == false)
{
return list;
}
Expand Down
6 changes: 3 additions & 3 deletions NetworkSocket/Flex/FlexPolicyMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ public class FlexPolicyMiddleware : IMiddleware
/// <returns></returns>
async Task IMiddleware.Invoke(IContenxt context)
{
if (context.Session.Protocol != Protocol.None || context.InputStream.Length != 23)
if (context.Session.Protocol != Protocol.None || context.StreamReader.Length != 23)
{
await this.Next.Invoke(context);
}

context.InputStream.Position = 0;
var request = context.InputStream.ReadString(Encoding.ASCII);
context.StreamReader.Position = 0;
var request = context.StreamReader.ReadString(Encoding.ASCII);
if (string.Equals(request, "<policy-file-request/>\0", StringComparison.OrdinalIgnoreCase))
{
this.SendPolicyXML(context);
Expand Down
6 changes: 0 additions & 6 deletions NetworkSocket/Http/HttpController.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
using NetworkSocket.Core;
using NetworkSocket.Exceptions;
using NetworkSocket.Tasks;
using NetworkSocket.Util;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Sockets;
using System.Reflection;
using System.Runtime.Remoting.Messaging;
using System.Text;
using System.Threading.Tasks;
using System.Web;

namespace NetworkSocket.Http
{
Expand Down
2 changes: 1 addition & 1 deletion NetworkSocket/Http/HttpMiddlewareBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private Task ProcessParseResultAsync(IContenxt context, HttpParseResult result)
return this.Next.Invoke(context);
}

context.InputStream.Clear(result.PackageLength);
context.StreamReader.Clear(result.PackageLength);
if (context.Session.Protocol == Protocol.None)
{
context.Session.SetProtocolWrapper(Protocol.Http, null);
Expand Down
1 change: 0 additions & 1 deletion NetworkSocket/Http/Internal/DefaultModelBinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using System.Linq;
using System.Reflection;
using System.Text;
using System.Web.Script.Serialization;

namespace NetworkSocket.Http
{
Expand Down
Loading

0 comments on commit 93405fc

Please sign in to comment.