基线 SVN r240

SVN-Revision: r240
This commit is contained in:
cyf
2025-02-06 06:46:06 +00:00
commit ab56a9bcf7
5317 changed files with 902274 additions and 0 deletions
@@ -0,0 +1,27 @@
using System;
using System.Runtime.InteropServices;
namespace Lskj.AttachStart.Service
{
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct C2S2C_BackgroundFileData
{
public const uint ID = 65545;
public MsgHeader header;
public int dwErrId;
public int dwTotalCount;
public int dwPacketOrder;
public int dwPacketLen;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 1024)]
public byte[] FileData;
public C2S2C_BackgroundFileData(bool autoSet)
{
this.FileData = new byte[1024];
this.dwErrId = this.dwTotalCount = this.dwPacketOrder = this.dwPacketLen = 0;
this.header = new MsgHeader();
this.header.dwType = 65545;
this.header.dwLen = (uint)Marshal.SizeOf(this);
}
}
}
@@ -0,0 +1,28 @@
using System;
using System.Runtime.InteropServices;
namespace Lskj.AttachStart.Service
{
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct C2S2C_FileData
{
public const uint ID = 4097;
public MsgHeader header;
public int dwErrId;
public int dwFileId;
public int dwTotalBytes;
public int dwTotalCount;
public int dwPacketOrder;
public int dwPacketLen;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 1024)]
public byte[] FileData;
public C2S2C_FileData(bool autoSet)
{
this.FileData = new byte[1024];
this.dwErrId = this.dwFileId = this.dwTotalCount = this.dwPacketOrder = this.dwPacketLen = this.dwTotalBytes = 0;
this.header = new MsgHeader();
this.header.dwType = 4097;
this.header.dwLen = (uint)Marshal.SizeOf(this);
}
}
}
@@ -0,0 +1,25 @@
using System;
using System.Runtime.InteropServices;
namespace Lskj.AttachStart.Service
{
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct C2S2C_FileTranslateComplete
{
public const uint ID = 4098;
public MsgHeader header;
public int dwErrId;
public int dwFileId;
public int dwTotalBytes;
public int dwTotalCount;
public int dwRevPacketCount;
public int dwRevBytesLen;
public C2S2C_FileTranslateComplete(bool autoSet)
{
this.dwErrId = this.dwFileId = this.dwTotalBytes = this.dwTotalCount = this.dwRevPacketCount = this.dwRevBytesLen = 0;
this.header = new MsgHeader();
this.header.dwType = 4098;
this.header.dwLen = (uint)Marshal.SizeOf(this);
}
}
}
@@ -0,0 +1,21 @@
using System;
using System.Runtime.InteropServices;
namespace Lskj.AttachStart.Service
{
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct C2S2C_SmartResponse
{
public const uint ID = 69634;
public MsgHeader header;
public uint dwFieldCount;
public uint dwDataLen;
public C2S2C_SmartResponse(bool autoSet)
{
this.dwFieldCount = this.dwDataLen = 0;
this.header = new MsgHeader();
this.header.dwType = 69634;
this.header.dwLen = (uint)Marshal.SizeOf(this);
}
}
}
@@ -0,0 +1,22 @@
using System;
using System.Runtime.InteropServices;
namespace Lskj.AttachStart.Service
{
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct C2S_AddFile
{
public const uint ID = 17;
public MsgHeader header;
public StructFileInfo fi;
public C2S_AddFile(bool autoSet)
{
this.header = new MsgHeader();
this.fi = new StructFileInfo(true);
this.header.dwType = 17;
this.header.dwLen = (uint)Marshal.SizeOf(this);
}
}
}
@@ -0,0 +1,20 @@
using System;
using System.Runtime.InteropServices;
namespace Lskj.AttachStart.Service
{
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct C2S_AddFileDirectory
{
public const uint ID = 1;
public MsgHeader header;
public StructFileInfo fi;
public C2S_AddFileDirectory(bool autoSet)
{
this.header = new MsgHeader();
this.fi = new StructFileInfo(true);
this.header.dwType = 1;
this.header.dwLen = (uint)Marshal.SizeOf(this);
}
}
}
@@ -0,0 +1,21 @@
using System;
using System.Runtime.InteropServices;
namespace Lskj.AttachStart.Service
{
[StructLayout(LayoutKind.Sequential, Pack=1)]
public struct C2S_DeleteFile
{
public const uint ID = 22;
public MsgHeader header;
public int dwFileId;
public C2S_DeleteFile(bool autoSet)
{
this.header = new MsgHeader();
this.dwFileId = 0;
this.header.dwType = 22;
this.header.dwLen = (uint) Marshal.SizeOf(this);
}
}
}
@@ -0,0 +1,55 @@
using System;
using System.Runtime.InteropServices;
namespace Lskj.AttachStart.Service
{
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct C2S_DownloadFile
{
public const uint ID = 19;
public MsgHeader header;
public int dwDirectoryId;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 50)]
public int[] dwFileIds;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 50)]
public int[] dwProductIds;
public C2S_DownloadFile(bool autoSet)
{
this.header = new MsgHeader();
this.dwDirectoryId = 0;
this.dwFileIds = new int[50];
this.dwProductIds = new int[50];
this.header.dwType = 19;
this.header.dwLen = (uint)Marshal.SizeOf(this);
}
public string strFileIds
{
get
{
return this.getIds(this.dwFileIds);
}
}
public string strProductIds
{
get
{
return this.getIds(this.dwProductIds);
}
}
private string getIds(int[] arr)
{
string str = "";
for (int i = 0; i < arr.Length; i++)
{
int num2 = arr[i];
if (num2 != 0)
{
str = str + num2.ToString() + "|";
}
}
return str;
}
}
}
@@ -0,0 +1,24 @@
using System;
using System.Runtime.InteropServices;
namespace Lskj.AttachStart.Service
{
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct C2S_EditFileDirectory
{
public const uint ID = 3;
public MsgHeader header;
public uint dwFileId;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 512)]
public byte[] szDirName;
public C2S_EditFileDirectory(bool autoSet)
{
this.dwFileId = 0;
this.szDirName = new byte[512];
this.header = new MsgHeader();
this.header.dwType = 3;
this.header.dwLen = (uint)Marshal.SizeOf(this);
}
}
}
@@ -0,0 +1,20 @@
using System;
using System.Runtime.InteropServices;
namespace Lskj.AttachStart.Service
{
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct C2S_RemoveFileDirectory
{
public const uint ID = 5;
public MsgHeader header;
public uint dwFileId;
public C2S_RemoveFileDirectory(bool autoSet)
{
this.dwFileId = 0;
this.header = new MsgHeader();
this.header.dwType = 5;
this.header.dwLen = (uint)Marshal.SizeOf(this);
}
}
}
@@ -0,0 +1,54 @@
using System;
using System.Runtime.InteropServices;
namespace Lskj.AttachStart.Service
{
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct C2S_ReqBackgroundDownload
{
public const int DownLoadModel = 1;
public const int GetFileListModel = 2;
public const uint ID = 65543;
public MsgHeader header;
public int reqType;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 1024)]
public byte[] szPath;
public C2S_ReqBackgroundDownload(bool autoSet)
{
this.header = new MsgHeader();
this.reqType = 1;
this.szPath = new byte[1024];
this.header.dwType = 65543;
this.header.dwLen = (uint)Marshal.SizeOf(this);
}
public bool isDownloadModel
{
get
{
return (this.reqType == 1);
}
}
public bool isGetFileListModel
{
get
{
return (this.reqType == 2);
}
}
public string strPath
{
get
{
return PubUtils.BytesToStr(this.szPath);
}
set
{
byte[] src = PubUtils.StrToBytes(value);
Buffer.BlockCopy(src, 0, this.szPath, 0, src.Length);
src = null;
}
}
}
}
@@ -0,0 +1,24 @@
using System;
using System.Runtime.InteropServices;
namespace Lskj.AttachStart.Service
{
[StructLayout(LayoutKind.Sequential, Pack=1)]
public struct C2S_ReqestFileList
{
public const uint ID = 33;
public MsgHeader header;
public int dwParentId;
public int dwReqType;
public int dwFileId;
public C2S_ReqestFileList(bool autoSet)
{
this.header = new MsgHeader();
this.dwParentId = -1;
this.dwReqType = this.dwFileId = 0;
this.header.dwType = 33;
this.header.dwLen = (uint) Marshal.SizeOf(this);
}
}
}
@@ -0,0 +1,19 @@
using System;
using System.Runtime.InteropServices;
namespace Lskj.AttachStart.Service
{
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct C2S_SmartClientLogin
{
public const uint ID = 69633;
public MsgHeader header;
public C2S_SmartClientLogin(bool autoSet)
{
this.header = new MsgHeader();
this.header.dwType = 69633;
this.header.dwLen = (uint)Marshal.SizeOf(this);
}
}
}
@@ -0,0 +1,37 @@
using System;
using System.Runtime.InteropServices;
namespace Lskj.AttachStart.Service
{
[StructLayout(LayoutKind.Sequential, Size = 1)]
internal struct ErrorType
{
private static readonly int NONE;
public static readonly int SUCCESS;
public static readonly int FILE_EXIST;
public static readonly int DIRECTORY_EXIST;
public static readonly int FILE_NOT_EXIST;
public static readonly int DIRECTORY_NOT_EXIST;
public static readonly int DELETE_FILE_ERROR;
public static readonly int DELETEFILE_FROMDB_ERROR;
public static readonly int FILE_BEEN_LOCKED;
public static readonly int FAIL;
public static readonly int UNKNOWN;
private static readonly int MAX;
static ErrorType()
{
NONE = 0;
SUCCESS = NONE++;
FILE_EXIST = NONE++;
DIRECTORY_EXIST = NONE++;
FILE_NOT_EXIST = NONE++;
DIRECTORY_NOT_EXIST = NONE++;
DELETE_FILE_ERROR = NONE++;
DELETEFILE_FROMDB_ERROR = NONE++;
FILE_BEEN_LOCKED = NONE++;
FAIL = NONE++;
UNKNOWN = NONE++;
MAX = NONE++;
}
}
}
@@ -0,0 +1,366 @@
using System;
using System.Net;
using System.Net.Sockets;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Threading;
using Lskj.Util;
namespace Lskj.AttachStart.Service
{
public abstract class LSASyncSocket
{
private byte _HandledCloseEventCounter = 0;
private int _LastExchangeStamp = 0;
protected int _ReceivedLen = 0;
private int _SendedLen = 0;
protected Socket _socket;
protected int _socketstate = 0;
private object[] _source;
private int nSendLength = 0;
public object ObjClient2Server = 2;
public object ObjServer2Client = 1;
protected const uint PACKETMAXLEN = 102400;
private AutoResetEvent RevDone_Event = new AutoResetEvent(true);
private AutoResetEvent SendDone_Event = new AutoResetEvent(true);
protected StateObject StateObj = new StateObject();
public event SocketCloseEventHandle SocketCloseEvent;
protected LSASyncSocket()
{
}
protected void CheckCloseState(int ErrorCode)
{
switch (ErrorCode)
{
case 10053:
case 10054:
case 10057:
case 10058:
this.CloseSocket();
break;
}
}
public void CloseSocket()
{
if (this._socketstate != 2)
{
try
{
this._socketstate = 2;
if ((this._socket != null) && this._socket.Connected)
{
string str = ((IPEndPoint)this._socket.RemoteEndPoint).Port.ToString();
this._socket.Shutdown(SocketShutdown.Receive);
Thread.Sleep(1);
this._socket.Close();
}
}
catch (Exception ex)
{
LogHelper.Instance.WriteError(ex);
}
if (this.SocketCloseEvent != null)
{
this.SocketCloseEvent(this);
}
}
}
protected void ContinueReceive()
{
try
{
if (((this._socket != null) && this._socket.Connected) && (this._socketstate != 2))
{
this._ReceivedLen = 0;
if (this.StateObj.buffer.Length > this.StateObj.BufferSize)
{
this.StateObj.buffer = new byte[this.StateObj.BufferSize];
}
this.SetLastStamp();
this._socket.BeginReceive(this.StateObj.buffer, 0, this.StateObj.BufferSize, SocketFlags.None, new AsyncCallback(this.ReceiveCallback), this._socket);
}
}
catch (Exception exception)
{
LogHelper.Instance.WriteError(exception);
}
}
~LSASyncSocket()
{
if (this.SendDone_Event != null)
{
this.SendDone_Event.Close();
this.SendDone_Event = null;
}
if (this.RevDone_Event != null)
{
this.RevDone_Event.Close();
this.RevDone_Event = null;
}
}
public void HandledCloseEvent()
{
this._HandledCloseEventCounter = (byte)(this._HandledCloseEventCounter + 1);
}
protected abstract void ParseReceiveData(byte[] byteData);
protected abstract void ReceiveCallback(IAsyncResult ar);
protected void ReceiveReady()
{
this._socketstate = 1;
this._ReceivedLen = 0;
try
{
this._socket.BeginReceive(this.StateObj.buffer, 0, this.StateObj.BufferSize, SocketFlags.None, new AsyncCallback(this.ReceiveCallback), this._socket);
}
catch (SocketException exception)
{
this.CheckCloseState(exception.ErrorCode);
}
catch (Exception ex)
{
LogHelper.Instance.WriteError(ex);
}
}
public bool Send(object structObj)
{
byte[] byteData = PubUtils.StructToBytes(structObj);
return this.Send(byteData);
}
public bool Send(byte[] byteData)
{
return this.Send(byteData, byteData.Length);
}
public bool Send(byte[] byteData, int sendLength)
{
int tickCount = Environment.TickCount;
if (((this._socket == null) || !this._socket.Connected) || (this._socketstate == 2))
{
if (this._socket == null)
{
LogHelper.Instance.WriteLog(string.Format(this.ToString() + ".send 过程即将要发送数据,但是不能发出去,socket = null, _socketstate=={0}, 要发送的数据内容是:\n{1}", this._socketstate, byteData));
}
else
{
LogHelper.Instance.WriteLog(string.Format(this.ToString() + ".send 过程即将要发送数据,但是不能发出去,socket id= {0}, socket.Connected=={1},_socketstate=={2}, 要发送的数据内容是:\n{3}", this._socket.Handle, this._socket.Connected, this._socketstate, byteData));
}
return false;
}
this.SendDone_Event.WaitOne();
if (((this._socket == null) || !this._socket.Connected) || (this._socketstate == 2))
{
this.SendDone_Event.Set();
return false;
}
LogHelper.Instance.WriteLog(string.Format("Socket Send Data WaitOne过程等待周期 = {0}", Environment.TickCount - tickCount));
this.SetLastStamp();
this._SendedLen = 0;
this.nSendLength = sendLength;
try
{
this._socket.BeginSend(byteData, 0, sendLength, SocketFlags.None, new AsyncCallback(this.SendCallback), tickCount);
return true;
}
catch (SocketException exception)
{
this.SendDone_Event.Set();
LogHelper.Instance.WriteLog(string.Format("LSASyncSocket.Sen SOCKET errorcode: {0} errormsg: {1}", exception.SocketErrorCode, exception.StackTrace));
this.CheckCloseState(exception.ErrorCode);
}
catch (Exception ex)
{
this.SendDone_Event.Set();
LogHelper.Instance.WriteError(ex);
}
return false;
}
private void SendCallback(IAsyncResult ar)
{
if (((this._socket == null) || !this._socket.Connected) || (this._socketstate == 2))
{
this.SendDone_Event.Set();
}
else
{
int asyncState = 2147483647;
try
{
asyncState = (int)ar.AsyncState;
int num2 = this._socket.EndSend(ar);
this._SendedLen += num2;
if (this.nSendLength != this._SendedLen)
{
LogHelper.Instance.WriteLog(string.Format("严重错误!!!需要发送的长度是= {0},但实际发送的长度为= {1}", this._SendedLen, this.nSendLength));
this.CloseSocket();
}
}
catch (SocketException exception)
{
this.CheckCloseState(exception.ErrorCode);
}
catch (Exception ex)
{
LogHelper.Instance.WriteError(ex);
}
asyncState = Environment.TickCount - asyncState;
LogHelper.Instance.WriteLog(string.Format("Socket Send Data周期(包含WaitOne) = {0}", asyncState));
this.SendDone_Event.Set();
}
}
public void SetLastStamp()
{
this._LastExchangeStamp = Environment.TickCount;
}
private void SetOptBuffer(int SendBufSize, int RevBufSize)
{
if (SendBufSize <= 0)
{
this._socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendBuffer, 1024);
}
else
{
this._socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendBuffer, SendBufSize);
}
if (RevBufSize <= 0)
{
this._socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveBuffer, 1024);
}
else
{
this._socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveBuffer, RevBufSize);
}
}
private void SetOptKeepAlive()
{
uint num = 10000;
uint num2 = 2000;
uint structure = 0;
byte[] array = new byte[Marshal.SizeOf(structure) * 3];
BitConverter.GetBytes((uint)1).CopyTo(array, 0);
BitConverter.GetBytes(num).CopyTo(array, Marshal.SizeOf(structure));
BitConverter.GetBytes(num2).CopyTo(array, (int)(Marshal.SizeOf(structure) * 2));
this._socket.IOControl(IOControlCode.KeepAliveValues, array, null);
}
private void SetOptLinger(int nMilliSecond)
{
LingerOption optionValue = null;
if (nMilliSecond <= 0)
{
optionValue = new LingerOption(true, 1000);
}
else
{
optionValue = new LingerOption(true, nMilliSecond);
}
this._socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Linger, optionValue);
}
private void SetOptTimeOut(int nMilliSecond)
{
if (nMilliSecond <= 0)
{
this._socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, 1000);
}
else
{
this._socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, nMilliSecond);
}
}
public bool TimeOutCheck(int TimeOutValue)
{
return ((Environment.TickCount - this._LastExchangeStamp) > TimeOutValue);
}
public bool HandledCloseEventCounter
{
get
{
return (this._HandledCloseEventCounter > 0);
}
}
public int ReceivedLen
{
get
{
return this._ReceivedLen;
}
}
public int SendedLen
{
get
{
return this._SendedLen;
}
}
public Socket socket
{
get
{
return this._socket;
}
}
public int SocketState
{
get
{
return this._socketstate;
}
}
public object[] source
{
get
{
return this._source;
}
set
{
this._source = value;
}
}
public delegate void SocketCloseEventHandle(LSASyncSocket AsyncSocket);
protected class StateObject
{
private const int _BufferSize = 10240;
public byte[] buffer = new byte[10240];
public void ExtentBuffer()
{
int num = this.buffer.Length * 2;
byte[] dst = new byte[num];
Buffer.BlockCopy(this.buffer, 0, dst, 0, this.buffer.Length);
this.buffer = dst;
}
public int BufferSize
{
get
{
return 10240;
}
}
}
}
}
@@ -0,0 +1,215 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Runtime.InteropServices;
using System.Text;
namespace Lskj.AttachStart.Service
{
internal class LSDBManage
{
public SqlConnection conn = null;
public static string connectionStr = "";
public static Dictionary<string, LSDBManage> dbmanageList = new Dictionary<string, LSDBManage>();
public int checkFileLockState(int fileId, int parentId, string name)
{
int num = 0;
try
{
SqlParameter[] parameterArray = new SqlParameter[] { new SqlParameter("@RetParam", SqlDbType.Int), new SqlParameter("@fileId", SqlDbType.Int), new SqlParameter("@parentId", SqlDbType.Int), new SqlParameter("@name", SqlDbType.VarChar, 64) };
parameterArray[0].Direction = ParameterDirection.ReturnValue;
parameterArray[1].Value = fileId;
parameterArray[2].Value = parentId;
parameterArray[3].Value = name;
using (SqlCommand command = new SqlCommand("pr_fm_CheckFileLockState", this.conn))
{
command.CommandType = CommandType.StoredProcedure;
foreach (SqlParameter parameter in parameterArray)
{
command.Parameters.Add(parameter);
}
command.ExecuteNonQuery();
num = int.Parse(parameterArray[0].Value.ToString());
}
}
catch (Exception exception)
{
//PubUtils.WriteLog("LSDBManage.createFile error is : {0} ", new object[] { exception });
}
return num;
}
public int createFile(int parentId, string name, int fileSize, int creator, int productId)
{
int num = 0;
try
{
SqlParameter[] parameterArray = new SqlParameter[] { new SqlParameter("@RetParam", SqlDbType.Int), new SqlParameter("@parentId", SqlDbType.Int), new SqlParameter("@name", SqlDbType.VarChar, 500), new SqlParameter("@fileSize", SqlDbType.Int), new SqlParameter("@creator", SqlDbType.Int), new SqlParameter("@productId", SqlDbType.Int) };
parameterArray[0].Direction = ParameterDirection.ReturnValue;
parameterArray[1].Value = parentId;
parameterArray[2].Value = name;
parameterArray[3].Value = fileSize;
parameterArray[4].Value = creator;
parameterArray[5].Value = productId;
using (SqlCommand command = new SqlCommand("pr_fm_createFile", this.conn))
{
command.CommandType = CommandType.StoredProcedure;
foreach (SqlParameter parameter in parameterArray)
{
command.Parameters.Add(parameter);
}
command.ExecuteNonQuery();
num = int.Parse(parameterArray[0].Value.ToString());
}
}
catch (Exception exception)
{
//PubUtils.WriteLog("LSDBManage.createFile error is : {0} ", new object[] { exception });
}
return num;
}
public bool deleteFile(int fileId)
{
bool flag = false;
try
{
SqlParameter[] parameterArray = new SqlParameter[] { new SqlParameter("@RetParam", SqlDbType.Int), new SqlParameter("@fileId", SqlDbType.Int) };
parameterArray[0].Direction = ParameterDirection.ReturnValue;
parameterArray[1].Value = fileId;
using (SqlCommand command = new SqlCommand("pr_fm_deleteFile", this.conn))
{
command.CommandType = CommandType.StoredProcedure;
foreach (SqlParameter parameter in parameterArray)
{
command.Parameters.Add(parameter);
}
command.ExecuteNonQuery();
flag = int.Parse(parameterArray[0].Value.ToString()) == 1;
}
}
catch (Exception exception)
{
//PubUtils.WriteLog("LSDBManage.deleteFile fileId={0} error is : {1} ", new object[] { fileId, exception });
}
return flag;
}
public bool existFile(int parentId, string name)
{
bool flag = false;
try
{
SqlCommand command = new SqlCommand(string.Format("select * from P_fm_FileTab where parentId={0} and sName='{1}'", parentId, name), this.conn)
{
CommandType = CommandType.Text
};
using (SqlDataReader reader = command.ExecuteReader())
{
if (reader.Read())
{
flag = true;
}
}
command.Dispose();
}
catch (Exception exception)
{
//PubUtils.WriteLog("LSDBManage.existFile error is : {0} ", new object[] { exception });
}
return flag;
}
public string getAbsoluteFile(int dwFileId)
{
if (dwFileId <= 0)
{
return "";
}
string str = "";
try
{
using (SqlDataReader reader = this.querySql(string.Format("select dbo.[fun_fm_getAbsolutePath]({0}) as absolutePath", dwFileId)))
{
if ((reader != null) && reader.Read())
{
str = reader["absolutePath"].ToString();
}
}
}
catch (Exception exception)
{
//PubUtils.WriteLog("LSDBManage.getAbsoluteFile error is : {0} ", new object[] { exception });
}
return str;
}
public SqlDataReader getDownloadFileList(int parentId, string fileIds, string strProductIds)
{
try
{
SqlCommand command = new SqlCommand("pr_fm_getDownloadFileInfo", this.conn)
{
CommandType = CommandType.StoredProcedure
};
SqlParameter[] parameterArray = new SqlParameter[] { new SqlParameter("@parentId", SqlDbType.Int), new SqlParameter("@fileIds", SqlDbType.VarChar, 1000), new SqlParameter("@productIds", SqlDbType.VarChar, 1000) };
parameterArray[0].Value = parentId;
parameterArray[1].Value = fileIds;
parameterArray[2].Value = strProductIds;
command.Parameters.Add(parameterArray[0]);
command.Parameters.Add(parameterArray[1]);
command.Parameters.Add(parameterArray[2]);
return command.ExecuteReader();
}
catch (Exception exception)
{
//PubUtils.WriteLog("LSDBManage.getDownloadFileList error is : {0} ", new object[] { exception });
}
return null;
}
public string getRelativePath(int parentId)
{
if (parentId <= 0)
{
return "";
}
string str = "";
try
{
using (SqlDataReader reader = this.querySql(string.Format("select dbo.[fun_fm_getRelativePath]({0}) as relativePath", parentId)))
{
if ((reader != null) && reader.Read())
{
str = reader["relativePath"].ToString();
}
}
}
catch (Exception exception)
{
//PubUtils.WriteLog("LSDBManage.getRelativePath error is : {0} ", new object[] { exception });
}
return str;
}
public SqlDataReader querySql(string strSql)
{
try
{
SqlCommand command = new SqlCommand(strSql, this.conn)
{
CommandType = CommandType.Text
};
return command.ExecuteReader();
}
catch (Exception exception)
{
//PubUtils.WriteLog("LSDBManage.querySql error is : {0} ", new object[] { exception });
}
return null;
}
}
}
@@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using Lskj.Util;
namespace Lskj.AttachStart.Service
{
internal static class LSErrorManage
{
private static Dictionary<int, string> m_errList = new Dictionary<int, string>();
public static string getDes(int dwErrId)
{
try
{
return m_errList[dwErrId];
}
catch (Exception ex)
{
LogHelper.Instance.WriteError(ex);
}
return "";
}
public static void init()
{
try
{
m_errList.Add(ErrorType.SUCCESS, "成功");
m_errList.Add(ErrorType.FILE_EXIST, "文件已经存在");
m_errList.Add(ErrorType.DIRECTORY_EXIST, "文件夹已经存在");
m_errList.Add(ErrorType.FILE_NOT_EXIST, "文件不存在");
m_errList.Add(ErrorType.DIRECTORY_NOT_EXIST, "文件夹不存在");
m_errList.Add(ErrorType.FAIL, "失败");
m_errList.Add(ErrorType.UNKNOWN, "未知错误");
}
catch (Exception ex)
{
LogHelper.Instance.WriteError(ex);
}
}
}
}
@@ -0,0 +1,23 @@
using System;
using System.IO;
namespace Lskj.AttachStart.Service
{
internal class LSFileData
{
public int dwFileId;
public int dwRevPacketCount;
public int dwTotalBytes;
public int dwTotalCount;
public uint dwUserId = 0;
public FileStream fs;
public int lastWriteTime;
public LSFileData()
{
this.dwFileId = this.dwTotalBytes = this.dwTotalCount = this.dwRevPacketCount = 0;
this.fs = null;
this.lastWriteTime = Environment.TickCount;
}
}
}
@@ -0,0 +1,256 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using Lskj.Util;
namespace Lskj.AttachStart.Service
{
internal static class LSFileManage
{
private static Dictionary<int, LSFileData> m_fileList = new Dictionary<int, LSFileData>();
private static string m_rootPath = "";
public static void createClientDirectory(string strPath)
{
if (strPath != "")
{
try
{
string str = "";
string[] strArray = strPath.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < strArray.Length; i++)
{
str = str + strArray[i] + "/";
if (!Directory.Exists(m_rootPath + str))
{
Directory.CreateDirectory(m_rootPath + str);
}
}
}
catch (Exception exception)
{
LogHelper.Instance.WriteError(exception);
}
}
}
public static LSFileData createClientFile(string strName)
{
if (strName == "")
{
return null;
}
LSFileData fd = new LSFileData();
try
{
string path = m_rootPath + strName;
fd.fs = File.Open(path, FileMode.Create, FileAccess.Write, FileShare.Read);
}
catch (Exception exception)
{
LogHelper.Instance.WriteError(exception);
eraseFile(fd);
}
return fd;
}
public static bool createDir(LSDBManage dbmanager, int parentId, string dirName)
{
try
{
Directory.CreateDirectory(m_rootPath + dbmanager.getRelativePath(parentId) + dirName);
return true;
}
catch (Exception exception)
{
LogHelper.Instance.WriteError(exception);
}
return false;
}
public static LSFileData createFile(LSDBManage dbmanager, int parentId, string fileName, bool saveOld)
{
LSFileData data = new LSFileData();
try
{
string str = dbmanager.getRelativePath(parentId);
string rootPath = m_rootPath;
string[] strArray = str.Split(new string[] { "//" }, StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < strArray.Length; i++)
{
rootPath = rootPath + strArray[i] + "//";
if (!Directory.Exists(rootPath))
{
Directory.CreateDirectory(rootPath);
}
}
string path = m_rootPath + str + fileName;
if (saveOld && File.Exists(path))
{
File.Move(path, path + "#" + DateTime.Now.ToString("yyyy_MM_dd#hh_mm_ss"));
}
data.fs = File.Open(path, FileMode.Create, FileAccess.Write, FileShare.Read);
}
catch (Exception exception)
{
LogHelper.Instance.WriteError(exception);
}
return data;
}
public static bool createFileData(C2S2C_FileData data, out C2S2C_FileTranslateComplete structComplete)
{
structComplete = new C2S2C_FileTranslateComplete(true);
try
{
LSFileData data2 = m_fileList[data.dwFileId];
if (data2 != null)
{
data2.fs.Write(data.FileData, 0, data.dwPacketLen);
data2.dwTotalBytes = data.dwTotalBytes;
data2.dwTotalCount = data.dwTotalCount;
data2.dwRevPacketCount++;
data2.lastWriteTime = Environment.TickCount;
if (data2.fs.Length >= data2.dwTotalBytes)
{
structComplete.dwFileId = data2.dwFileId;
structComplete.dwTotalBytes = data2.dwTotalBytes;
structComplete.dwTotalCount = data2.dwTotalCount;
structComplete.dwRevPacketCount = data2.dwRevPacketCount;
structComplete.dwRevBytesLen = (int)data2.fs.Length;
data2.fs.Flush();
data2.fs.Close();
data2.fs.Dispose();
data2.fs = null;
lock (m_fileList)
{
m_fileList.Remove(data.dwFileId);
}
return true;
}
}
}
catch (Exception exception)
{
LogHelper.Instance.WriteError(exception);
}
return false;
}
public static bool deleteFile(LSDBManage dbmanager, int fileId)
{
try
{
string path = m_rootPath + dbmanager.getAbsoluteFile(fileId);
if (File.Exists(path))
{
File.Move(path, path + "#" + DateTime.Now.ToString("yyyy_MM_dd#hh_mm_ss"));
}
}
catch (Exception exception)
{
LogHelper.Instance.WriteError(exception);
return false;
}
return true;
}
public static void dispose()
{
try
{
lock (m_fileList)
{
foreach (KeyValuePair<int, LSFileData> pair in m_fileList)
{
}
}
}
catch (Exception exception)
{
LogHelper.Instance.WriteError(exception);
}
}
public static void eraseFile(LSFileData fd)
{
if ((fd != null) && (fd.fs != null))
{
try
{
string name = fd.fs.Name;
fd.fs.Flush();
fd.fs.Close();
fd.fs.Dispose();
fd.fs = null;
File.Delete(name);
if (File.Exists(name))
{
LogHelper.Instance.WriteLog("无法删除指定文件: {0}", name);
}
}
catch (Exception exception)
{
LogHelper.Instance.WriteError(exception);
}
lock (m_fileList)
{
m_fileList.Remove(fd.dwFileId);
}
}
}
public static void eraseFile(int dwFileId)
{
lock (m_fileList)
{
LSFileData fd = m_fileList[dwFileId];
eraseFile(fd);
}
}
public static bool existDir(LSDBManage dbmanager, int parentId, string dirName)
{
string str = dbmanager.getRelativePath(parentId);
return Directory.Exists(m_rootPath + str + dirName);
}
public static bool existFile(LSDBManage dbmanager, int parentId, string fileName)
{
string str = dbmanager.getRelativePath(parentId);
return File.Exists(m_rootPath + str + fileName);
}
public static bool init(string rootPath)
{
m_rootPath = rootPath;
return Directory.Exists(rootPath);
}
public static void insertFileData(LSFileData fd)
{
lock (m_fileList)
{
if (m_fileList.ContainsKey(fd.dwFileId))
{
m_fileList.Remove(fd.dwFileId);
}
else
{
m_fileList.Add(fd.dwFileId, fd);
}
}
}
public static string joinFileName(string filename)
{
string path = m_rootPath + filename;
if (File.Exists(path))
{
return path;
}
return "";
}
}
}
@@ -0,0 +1,143 @@
using System;
using System.Runtime.InteropServices;
using System.Text;
using System.Xml;
using Lskj.Util;
namespace Lskj.AttachStart.Service
{
public static class LSIniFile
{
private static string _IniPath = "";
private static XmlDocument xmlDoc = new XmlDocument();
[DllImport("kernel32")]
private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);
public static XmlNodeList ReadNodeList(string strNodeName)
{
XmlNodeList elementsByTagName;
try
{
elementsByTagName = xmlDoc.GetElementsByTagName(strNodeName);
}
catch (Exception exception)
{
LogHelper.Instance.WriteError(exception);
return null;
}
return elementsByTagName;
}
public static string ReadNodeValue(XmlNode node, string strName)
{
string str = null;
if (node.HasChildNodes)
{
for (int i = 0; i < node.ChildNodes.Count; i++)
{
if (node.ChildNodes[i].LocalName == strName)
{
return node.ChildNodes[i].InnerXml;
}
}
return str;
}
return null;
}
public static XmlNode ReadSingleNode(string strNodeName)
{
XmlNode node = null;
try
{
node = xmlDoc.DocumentElement.SelectSingleNode(strNodeName);
}
catch (Exception exception)
{
LogHelper.Instance.WriteError(exception);
return null;
}
return node;
}
public static string ReadValue(string NodePath, string NodeName)
{
try
{
for (XmlNode node = xmlDoc.DocumentElement.SelectNodes(NodePath)[0].FirstChild; node != null; node = node.NextSibling)
{
if (node.Name == NodeName)
{
return node.InnerText;
}
}
}
catch (Exception exception)
{
LogHelper.Instance.WriteError(exception);
}
return "";
}
public static bool ReadValue(string NodeName, int index, params string[] NodeValues)
{
try
{
XmlNode node = ReadSingleNode(NodeName);
if (node.ChildNodes.Count <= index)
{
return false;
}
node = node.ChildNodes[index];
int num = 0;
for (XmlNode node2 = node.FirstChild; (node2 != null) && (num < NodeValues.Length); node2 = node2.NextSibling)
{
if (node2.NodeType == XmlNodeType.Element)
{
NodeValues[num] = node2.InnerText;
num++;
}
}
return true;
}
catch (Exception exception)
{
LogHelper.Instance.WriteError(exception);
return false;
}
}
public static string ReadValue(string Section, string Key, string path)
{
StringBuilder retVal = new StringBuilder(255);
int num = GetPrivateProfileString(Section, Key, "", retVal, 255, path);
return retVal.ToString();
}
[DllImport("kernel32")]
private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
public static void WriteValue(string Section, string Key, string Value)
{
WritePrivateProfileString(Section, Key, Value, _IniPath);
}
public static void WriteValue(string Section, string Key, string Value, string path)
{
WritePrivateProfileString(Section, Key, Value, path);
}
public static string IniPath
{
set
{
string baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
if (!baseDirectory.EndsWith(@"\"))
{
baseDirectory = baseDirectory + @"\";
}
_IniPath = baseDirectory + value;
xmlDoc.Load(_IniPath);
}
}
}
}
@@ -0,0 +1,14 @@
using System;
namespace Lskj.AttachStart.Service
{
public static class LSProtocol
{
public const int LS_DOWNLOADFILE_MAXCOUNT = 50;
public const int LS_FILEDATAPACKET_LEN = 1024;
public const int LS_FILENAM_LEN = 512;
public const int LS_PATH_LEN = 1024;
public const uint PACKETMAXLEN = 102400;
}
}
@@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
using System.Threading;
namespace Lskj.AttachStart.Service
{
internal static class LSQueueManage
{
private static Queue<LSSocketRev> LSSocketRevQueue = new Queue<LSSocketRev>();
private static AutoResetEvent Rev_Event = new AutoResetEvent(true);
public static LSSocketRev GetSocketRevData()
{
LSSocketRev socketRevData = null;
if (LSSocketRevQueue.Count > 0)
{
lock (LSSocketRevQueue)
{
socketRevData = LSSocketRevQueue.Dequeue();
}
}
else
{
Rev_Event.WaitOne();
}
if (socketRevData == null)
{
socketRevData = GetSocketRevData();
}
return socketRevData;
}
public static void InsertSocketRevData(LSSocketRev socketRev)
{
lock (LSSocketRevQueue)
{
LSSocketRevQueue.Enqueue(socketRev);
}
Rev_Event.Set();
}
public static int LSSocketRevQueueCount
{
get
{
return LSSocketRevQueue.Count;
}
}
}
}
@@ -0,0 +1,219 @@
using System;
using System.Net;
using System.Net.Sockets;
using System.Runtime.CompilerServices;
using Lskj.Util;
namespace Lskj.AttachStart.Service
{
public class LSSocket : LSASyncSocket
{
private int _selDirectoryId = 0;
private string _ServerIP = "";
private uint _ServerPort = 0;
private const int FIONREAD = 1074030207;
private uint m_dwUserId = 0;
private string m_remoteIP;
private int m_remotePort;
public event ParseReceiveDataEventHandle ParseReceiveDataEvent;
public LSSocket()
{
base._socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
}
public void clientAdd(Socket s)
{
base._socket = s;
base.ReceiveReady();
}
public void Connect(string strHost, uint nPort)
{
try
{
this.ServerIP = strHost;
this.ServerPort = nPort;
IPEndPoint remoteEP = new IPEndPoint(IPAddress.Parse(strHost), (int)nPort);
LogHelper.Instance.WriteLog(string.Format("begin connect server ip={0}, port={1}.", strHost, nPort));
base._socket.BeginConnect(remoteEP, new AsyncCallback(this.ConnectCallback), base._socket);
}
catch (Exception ex)
{
LogHelper.Instance.WriteError(ex);
}
}
private void ConnectCallback(IAsyncResult ar)
{
try
{
((Socket)ar.AsyncState).EndConnect(ar);
LogHelper.Instance.WriteLog(string.Format("connected server ip={0} port={1} success.", this.ServerIP, this.ServerPort));
base.ReceiveReady();
}
catch (Exception ex)
{
LogHelper.Instance.WriteError(ex);
}
}
protected override void ParseReceiveData(byte[] byteData)
{
this.ParseReceiveDataEvent(this, byteData);
}
protected override void ReceiveCallback(IAsyncResult ar)
{
try
{
LogHelper.Instance.WriteLog(this.ToString() + ".ReceiveCallback is running socketid = " + base._socket.Handle);
if (!((base._socket != null) && base._socket.Connected))
{
base.CloseSocket();
return;
}
LogHelper.Instance.WriteLog(this.ToString() + ".ReceiveCallback socketid = " + base._socket.Handle + " bytesAvailable is " + base._socket.Available.ToString() + " _socketstate=" + this._socketstate.ToString());
if ((base._socket.Available == 0) && (base._socketstate == 2))
{
return;
}
int count = base._socket.EndReceive(ar);
byte[] dst = new byte[count];
Buffer.BlockCopy(base.StateObj.buffer, 0, dst, 0, count);
if (count > 0)
{
int num3;
base._ReceivedLen += count;
for (int i = 0; i < base._ReceivedLen; i += num3)
{
bool flag = (base._ReceivedLen - i) <= 8;
Label_0158:
if (flag)
{
if ((base._ReceivedLen - i) < base.StateObj.buffer.Length)
{
Buffer.BlockCopy(base.StateObj.buffer, i, base.StateObj.buffer, 0, base._ReceivedLen - i);
}
else
{
base.StateObj.ExtentBuffer();
}
base._ReceivedLen -= i;
base._socket.BeginReceive(base.StateObj.buffer, base._ReceivedLen, base.StateObj.buffer.Length - base._ReceivedLen, SocketFlags.None, new AsyncCallback(this.ReceiveCallback), base._socket);
return;
}
num3 = BitConverter.ToInt32(base.StateObj.buffer, 4 + i);
if ((num3 + i) > base._ReceivedLen)
{
flag = true;
goto Label_0158;
}
byte[] buffer2 = new byte[num3];
Buffer.BlockCopy(base.StateObj.buffer, i, buffer2, 0, num3);
if (num3 > 102400)
{
byte[] buffer3 = new byte[base._ReceivedLen];
Buffer.BlockCopy(base.StateObj.buffer, 0, buffer3, 0, base._ReceivedLen);
LogHelper.Instance.WriteLog(string.Format("received proxy data is unnormal! socketid= {0} and a packet data is :{1} and whole data is :{2}", base._socket.Handle, buffer2, buffer3));
}
else
{
this.ParseReceiveData(buffer2);
}
}
}
else
{
base.CloseSocket();
}
}
catch (Exception ex)
{
LogHelper.Instance.WriteError(ex);
}
base.ContinueReceive();
}
public void reConnect()
{
base._socketstate = 0;
this.Connect(this.m_remoteIP, (uint)this.m_remotePort);
}
public uint dwUserId
{
get
{
return this.m_dwUserId;
}
set
{
this.m_dwUserId = value;
}
}
public string remoteIP
{
get
{
return this.m_remoteIP;
}
set
{
this.m_remoteIP = value;
}
}
public int remotePort
{
get
{
return this.m_remotePort;
}
set
{
this.m_remotePort = value;
}
}
public int selDirectoryId
{
get
{
return this._selDirectoryId;
}
set
{
this._selDirectoryId = value;
}
}
public string ServerIP
{
get
{
return this._ServerIP;
}
set
{
this._ServerIP = value;
}
}
public uint ServerPort
{
get
{
return this._ServerPort;
}
set
{
this._ServerPort = value;
}
}
public delegate void ParseReceiveDataEventHandle(LSSocket ProxySocket, byte[] byteData);
}
}
@@ -0,0 +1,34 @@
using System;
namespace Lskj.AttachStart.Service
{
public class LSSocketRev
{
private byte[] _ByteData = null;
private LSSocket _ClientSocket = null;
public byte[] ByteData
{
get
{
return this._ByteData;
}
set
{
this._ByteData = value;
}
}
public LSSocket ClientSocket
{
get
{
return this._ClientSocket;
}
set
{
this._ClientSocket = value;
}
}
}
}
@@ -0,0 +1,14 @@
using System;
using System.Runtime.InteropServices;
namespace Lskj.AttachStart.Service
{
[StructLayout(LayoutKind.Sequential)]
public struct MsgHeader
{
public const uint sizeOf = 8;
public uint dwType;
public uint dwLen;
public uint dwUserId;
}
}
@@ -0,0 +1,333 @@
using System;
using System.ComponentModel;
using System.Net;
using System.Net.Sockets;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
namespace Lskj.AttachStart.Service
{
public class PubUtils
{
public static readonly PubUtils Instance = new PubUtils();
private PubUtils()
{
}
public static byte[] BytesAddStruct(byte[] bytesHead, object structObj)
{
byte[] src = StructToBytes(structObj);
if ((bytesHead == null) || (bytesHead.Length <= 0))
{
return src;
}
int num = bytesHead.Length + src.Length;
byte[] dst = new byte[num];
Buffer.BlockCopy(bytesHead, 0, dst, 0, bytesHead.Length);
Buffer.BlockCopy(src, 0, dst, bytesHead.Length, src.Length);
return dst;
}
public static byte[] BytesAddStruct(object structObj, byte[] bytesTail)
{
byte[] src = StructToBytes(structObj);
if ((bytesTail == null) || (bytesTail.Length <= 0))
{
return src;
}
int num = src.Length + bytesTail.Length;
byte[] dst = new byte[num];
Buffer.BlockCopy(src, 0, dst, 0, src.Length);
Buffer.BlockCopy(bytesTail, 0, dst, src.Length, bytesTail.Length);
return dst;
}
public static byte[] BytesIntercept(byte[] SrcBytes, uint FixedLen)
{
byte[] dst = new byte[FixedLen];
int count = (SrcBytes.Length > FixedLen) ? ((int) FixedLen) : SrcBytes.Length;
Buffer.BlockCopy(SrcBytes, 0, dst, 0, count);
return dst;
}
public static string BytesToStr(byte[] SrcBytes)
{
return Encoding.Default.GetString(SrcBytes).Replace("\0", "");
}
public static string BytesToStr(byte[] SrcBytes, int index, int count)
{
return Encoding.Default.GetString(SrcBytes, index, count).Replace("\0", "");
}
public static object BytesToStruct(byte[] bytes, Type structType)
{
return BytesToStruct(bytes, structType, 0, 0);
}
public static object BytesToStruct(byte[] bytes, Type structType, int startIndex)
{
return BytesToStruct(bytes, structType, startIndex, 0);
}
public static object BytesToStruct(byte[] bytes, Type structType, string ExceptField)
{
return BytesToStruct(bytes, structType, 0, 0, new string[] { ExceptField });
}
public static object BytesToStruct(byte[] bytes, Type structType, string[] ExceptFields)
{
return BytesToStruct(bytes, structType, 0, 0, ExceptFields);
}
public static object BytesToStruct(byte[] bytes, Type structType, int startIndex, int decCount)
{
object obj2 = null;
int num = 1;
int num2 = 0;
int num3 = 0;
while (num > 0)
{
int cb = Marshal.SizeOf(structType);
IntPtr destination = Marshal.AllocHGlobal(cb);
try
{
num3 = 0;
Marshal.Copy(bytes, startIndex, destination, cb - decCount);
num3 = 1;
obj2 = Marshal.PtrToStructure(destination, structType);
num3 = 2;
}
catch (Exception exception)
{
num++;
if (num2 > 2)
{
throw new Exception(exception.Message.ToString());
}
num2++;
}
finally
{
Marshal.FreeHGlobal(destination);
}
num--;
}
return obj2;
}
public static object BytesToStruct(byte[] bytes, Type structType, int startIndex, string ExceptField)
{
return BytesToStruct(bytes, structType, startIndex, 0, new string[] { ExceptField });
}
public static object BytesToStruct(byte[] bytes, Type structType, int startIndex, string[] ExceptFields)
{
return BytesToStruct(bytes, structType, startIndex, 0, ExceptFields);
}
public static object BytesToStruct(byte[] bytes, Type structType, int startIndex, int decCount, string ExceptField)
{
return BytesToStruct(bytes, structType, startIndex, decCount, new string[] { ExceptField });
}
public static object BytesToStruct(byte[] bytes, Type structType, int startIndex, int decCount, string[] ExceptFields)
{
object obj3;
try
{
string str = "|";
for (int i = 0; i < ExceptFields.Length; i++)
{
str = str + ExceptFields[i] + "|";
}
int dstOffset = 0;
int num3 = Marshal.SizeOf(structType) - decCount;
byte[] buffer = new byte[num3];
object obj2 = BytesToStruct(buffer, structType);
FieldInfo[] fields = structType.GetFields();
foreach (FieldInfo info in fields)
{
int count = 0;
if (info.FieldType.IsArray)
{
Array array = (Array) info.GetValue(obj2);
count = array.Length;
}
else
{
count = Marshal.SizeOf(info.FieldType);
}
string str2 = "|" + info.Name + "|";
if (!str.Contains(str2))
{
Buffer.BlockCopy(bytes, startIndex, buffer, dstOffset, count);
startIndex += count;
}
dstOffset += count;
}
obj3 = BytesToStruct(buffer, structType);
}
catch (Exception exception)
{
throw new Exception(exception.Message.ToString());
}
return obj3;
}
public static byte[] ComposeTwoBytes(byte[] bytesHead, byte[] bytesTail)
{
int num = bytesHead.Length + bytesTail.Length;
byte[] dst = new byte[num];
Buffer.BlockCopy(bytesHead, 0, dst, 0, bytesHead.Length);
Buffer.BlockCopy(bytesTail, 0, dst, bytesHead.Length, bytesTail.Length);
return dst;
}
public static byte[] CopyArrayData(byte[] source, int startIndex, int length)
{
byte[] buffer = new byte[length];
for (int i = 0; i < length; i++)
{
buffer[i] = source[startIndex + i];
}
return buffer;
}
public static void CopyStructToBytes(object structObj, byte[] destBytes, int dstOffset)
{
int cb = Marshal.SizeOf(structObj);
IntPtr ptr = Marshal.AllocHGlobal(cb);
try
{
Marshal.StructureToPtr(structObj, ptr, false);
Marshal.Copy(ptr, destBytes, dstOffset, cb);
}
finally
{
Marshal.FreeHGlobal(ptr);
}
}
public static IPAddress GetServerIP()
{
IPHostEntry hostEntry = Dns.GetHostEntry(Dns.GetHostName());
foreach (IPAddress address in hostEntry.AddressList)
{
if (address.AddressFamily == AddressFamily.InterNetwork)
{
return address;
}
}
return null;
}
public static uint IPToLong(string strIP)
{
return (uint) IPAddress.Parse(strIP).Address;
}
public static string LongToIP(uint dwIP)
{
return new IPAddress((long) dwIP).ToString();
}
public static string ReadXmlStr(string SrcStr)
{
return SrcStr.Replace("&lt;", "<").Replace("&gt;", ">").Replace("&amp;", "&").Replace("&apos;", "'").Replace("&quot;", "\"");
}
public static byte[] StrToBytes(string SrcString)
{
return Encoding.Default.GetBytes(SrcString);
}
public static byte[] StrToBytes(string SrcString, uint FixedLen)
{
return StrToBytes(SrcString.ToCharArray(), FixedLen);
}
public static byte[] StrToBytes(char[] SrcChar, uint FixedLen)
{
return BytesIntercept(Encoding.Default.GetBytes(SrcChar), FixedLen);
}
public static byte[] StructToBytes(object structObj)
{
byte[] buffer2;
int cb = Marshal.SizeOf(structObj);
IntPtr ptr = Marshal.AllocHGlobal(cb);
try
{
Marshal.StructureToPtr(structObj, ptr, false);
byte[] destination = new byte[cb];
Marshal.Copy(ptr, destination, 0, cb);
buffer2 = destination;
}
finally
{
Marshal.FreeHGlobal(ptr);
}
return buffer2;
}
public static byte[] StructToBytes(object structObj, int decCount)
{
byte[] buffer2;
int cb = Marshal.SizeOf(structObj);
IntPtr ptr = Marshal.AllocHGlobal(cb);
try
{
Marshal.StructureToPtr(structObj, ptr, false);
byte[] destination = new byte[cb - decCount];
Marshal.Copy(ptr, destination, 0, cb - decCount);
buffer2 = destination;
}
finally
{
Marshal.FreeHGlobal(ptr);
}
return buffer2;
}
public static string WriteXmlStr(string SrcStr)
{
return SrcStr.Replace("<", "&lt;").Replace(">", "&gt;").Replace("&", "&amp;").Replace("'", "&apos;").Replace("\"", "&quot;");
}
public static IPAddress LocalFirstIPAddr
{
get
{
return Dns.Resolve(LocalMachineName).AddressList[0];
}
}
public static uint LocalFirstIPLong
{
get
{
return (uint) LocalFirstIPAddr.Address;
}
}
public static string LocalFirstIPStr
{
get
{
return LocalFirstIPAddr.Address.ToString();
}
}
public static string LocalMachineName
{
get
{
return Environment.MachineName;
}
}
}
}
@@ -0,0 +1,23 @@
using System;
using System.Runtime.InteropServices;
namespace Lskj.AttachStart.Service
{
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct S2C2S_Heart
{
public static uint ID;
public MsgHeader header;
public S2C2S_Heart(bool autoSet)
{
this.header = new MsgHeader();
this.header.dwType = ID;
this.header.dwLen = (uint)Marshal.SizeOf(this);
}
static S2C2S_Heart()
{
ID = 65542;
}
}
}
@@ -0,0 +1,22 @@
using System;
using System.Runtime.InteropServices;
namespace Lskj.AttachStart.Service
{
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct S2C_AddFile
{
public const uint ID = 18;
public MsgHeader header;
public int dwErrId;
public StructFileInfo fi;
public S2C_AddFile(bool autoSet)
{
this.dwErrId = 0;
this.fi = new StructFileInfo(true);
this.header = new MsgHeader();
this.header.dwType = 18;
this.header.dwLen = (uint)Marshal.SizeOf(this);
}
}
}
@@ -0,0 +1,22 @@
using System;
using System.Runtime.InteropServices;
namespace Lskj.AttachStart.Service
{
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct S2C_AddFileDirectory
{
public const uint ID = 2;
public MsgHeader header;
public int dwErrId;
public StructFileInfo fi;
public S2C_AddFileDirectory(bool autoSet)
{
this.dwErrId = 0;
this.fi = new StructFileInfo(true);
this.header = new MsgHeader();
this.header.dwType = 2;
this.header.dwLen = (uint)Marshal.SizeOf(this);
}
}
}
@@ -0,0 +1,21 @@
using System;
using System.Runtime.InteropServices;
namespace Lskj.AttachStart.Service
{
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct S2C_DeleteFile
{
public const uint ID = 23;
public MsgHeader header;
public int dwErrId;
public int dwFileId;
public S2C_DeleteFile(bool autoSet)
{
this.dwErrId = this.dwFileId = 0;
this.header = new MsgHeader();
this.header.dwType = 23;
this.header.dwLen = (uint)Marshal.SizeOf(this);
}
}
}
@@ -0,0 +1,24 @@
using System;
using System.Runtime.InteropServices;
namespace Lskj.AttachStart.Service
{
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct S2C_DownloadFile
{
public const uint ID = 20;
public MsgHeader header;
public int dwErrId;
public int dwTotalCount;
public int dwCurrentIndex;
public StructFileInfo fi;
public S2C_DownloadFile(bool autoSet)
{
this.header = new MsgHeader();
this.dwErrId = this.dwTotalCount = this.dwCurrentIndex = 0;
this.fi = new StructFileInfo(true);
this.header.dwType = 20;
this.header.dwLen = (uint)Marshal.SizeOf(this);
}
}
}
@@ -0,0 +1,21 @@
using System;
using System.Runtime.InteropServices;
namespace Lskj.AttachStart.Service
{
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct S2C_EditFileDirectory
{
public const uint ID = 4;
public MsgHeader header;
public int dwErrId;
public int dwFileId;
public S2C_EditFileDirectory(bool autoSet)
{
this.dwErrId = this.dwFileId = 0;
this.header = new MsgHeader();
this.header.dwType = 4;
this.header.dwLen = (uint)Marshal.SizeOf(this);
}
}
}
@@ -0,0 +1,21 @@
using System;
using System.Runtime.InteropServices;
namespace Lskj.AttachStart.Service
{
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct S2C_RemoveFileDirectory
{
public const uint ID = 6;
public MsgHeader header;
public int dwErrId;
public int dwFileId;
public S2C_RemoveFileDirectory(bool autoSet)
{
this.header = new MsgHeader();
this.dwErrId = this.dwFileId = 0;
this.header.dwType = 6;
this.header.dwLen = (uint)Marshal.SizeOf(this);
}
}
}
@@ -0,0 +1,37 @@
using System;
using System.Runtime.InteropServices;
namespace Lskj.AttachStart.Service
{
public struct S2C_ReqBackgroundDownload
{
public const uint ID = 65544;
public MsgHeader header;
public int dwErrId;
public int reqType;
public int dwCount;
public S2C_ReqBackgroundDownload(bool autoSet)
{
this.dwErrId = this.dwCount = 0;
this.reqType = 1;
this.header = new MsgHeader();
this.header.dwType = 65544;
this.header.dwLen = (uint)Marshal.SizeOf(this);
}
public bool isDownloadModel
{
get
{
return (this.reqType == 1);
}
}
public bool isGetFileListModel
{
get
{
return (this.reqType == 2);
}
}
}
}
@@ -0,0 +1,20 @@
using System;
using System.Runtime.InteropServices;
namespace Lskj.AttachStart.Service
{
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct S2C_ReqUpdateFile
{
public const uint ID = 4099;
public MsgHeader header;
public StructFileInfo fi;
public S2C_ReqUpdateFile(bool autoSet)
{
this.fi = new StructFileInfo(true);
this.header = new MsgHeader();
this.header.dwType = 4099;
this.header.dwLen = (uint)Marshal.SizeOf(this);
}
}
}
@@ -0,0 +1,22 @@
using System;
using System.Runtime.InteropServices;
namespace Lskj.AttachStart.Service
{
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct S2C_ReqestFileList
{
public const uint ID = 34;
public MsgHeader header;
public int dwErrId;
public int dwReqType;
public int dwCount;
public S2C_ReqestFileList(bool autoSet)
{
this.dwErrId = this.dwCount = this.dwReqType = 0;
this.header = new MsgHeader();
this.header.dwType = 34;
this.header.dwLen = (uint)Marshal.SizeOf(this);
}
}
}
@@ -0,0 +1,20 @@
using System;
using System.Runtime.InteropServices;
namespace Lskj.AttachStart.Service
{
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct StructDirectoryInfo
{
public int dwParentId;
public int dwFileId;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 512)]
public byte[] szName;
public int isDir;
public StructDirectoryInfo(bool autoSet)
{
this.dwParentId = this.dwFileId = this.isDir = 0;
this.szName = new byte[512];
}
}
}
@@ -0,0 +1,77 @@
namespace Lskj.AttachStart.Service
{
using System;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential, Pack=1)]
public struct StructFileInfo
{
public int dwParentId;
public int dwFileId;
public int dwCreator;
public int dwFileSize;
public long dwCreateTime;
[MarshalAs(UnmanagedType.ByValArray, SizeConst=512)]
public byte[] szName;
public StructFileInfo(bool autoSet)
{
this.dwParentId = this.dwFileId = this.dwCreator = this.dwFileSize = 0;
this.dwCreateTime = 0L;
this.szName = new byte[512];
}
public StructFileInfo clone()
{
StructFileInfo fi = new StructFileInfo(true);
this.clone(fi);
return fi;
}
public void clone(StructFileInfo fi)
{
fi.dwParentId = this.dwParentId;
fi.dwFileId = this.dwFileId;
fi.dwCreator = this.dwCreator;
fi.dwFileSize = this.dwFileSize;
fi.dwCreateTime = this.dwCreateTime;
Buffer.BlockCopy(this.szName, 0, fi.szName, 0, this.szName.Length);
}
public string strName
{
get
{
return PubUtils.BytesToStr(this.szName);
}
set
{
byte[] src = PubUtils.StrToBytes(value);
Buffer.BlockCopy(src, 0, this.szName, 0, src.Length);
src = null;
}
}
public string strCreateTime
{
get
{
return DateTime.FromFileTime(this.dwCreateTime).ToString("yyyy-MM-dd HH:mm:ss");
}
set
{
this.dwCreateTime = DateTime.Parse(value).ToFileTime();
}
}
public DateTime dtCreateTime
{
get
{
return DateTime.FromFileTime(this.dwCreateTime);
}
set
{
this.dwCreateTime = value.ToFileTime();
}
}
}
}