天津投入产出系统后端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
3.8 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QMFrameWork.Data;
namespace NSC
{
/// <summary>
/// 功能:异步网络服务引擎
/// 作者:王昊昇
/// 时间:2012.11.8
/// </summary>
public static class ServiceDataBufferEngine
{
/// <summary>
/// 创建新的服务流水号
/// </summary>
/// <returns>返回一个新的服务流水号</returns>
public static string CreateNewServiceSN()
{
Common.Data.SqlLite.SqlLiteHelper dal = new Common.Data.SqlLite.SqlLiteHelper();
using (System.Data.IDbConnection conn = dal.OpenConnection(Common.Config.ConfigSetting.GetConnectionString()))
{
string pid = dal.GetSingle(conn,
"INSERT INTO T_SERVICELOG(SERVICEPATH,SUBMITTIME,COMPLETE) VALUES('','" + DateTime.Now.ToString(Common.TextUtil.DateTimeUtil.DATETIME_YYYYMMDD_HHMMSS) + "','0');"
+ Common.Data.SqlLite.SqlLiteHelper.SELECT_IDENTITY_ID).ToString();
return pid;
}
}
/// <summary>
/// 写入服务数据文件
/// </summary>
/// <param name="serviceSN">服务代码</param>
/// <param name="data">要写入的服务数据</param>
public static void WriteServiceFile(string serviceSN, NetServiceStruct data)
{
string configPath = Common.Config.ConfigSetting.GetSetting("0001");
string fileName = configPath == "" ? System.Windows.Forms.Application.StartupPath + @"\ServiceBuffer\" + serviceSN : configPath + @"\" + serviceSN;
using (System.IO.MemoryStream ms = PacketsEncoder.ConvertToStream(data))
using (System.IO.FileStream fs = new System.IO.FileStream(fileName, System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.Read))
{
fs.Write(ms.ToArray(), 0, (int)ms.Length);
fs.Flush();
}
Common.Data.SqlLite.SqlLiteHelper dal = new Common.Data.SqlLite.SqlLiteHelper();
using (System.Data.IDbConnection conn = dal.OpenConnection(Common.Config.ConfigSetting.GetConnectionString()))
{
dal.ExecuteSql(conn, string.Format("UPDATE T_SERVICELOG SET SERVICEPATH={0},COMPLETE='1' WHERE PID={1}", fileName, serviceSN));
}
}
/// <summary>
/// 获取执行结果
/// </summary>
/// <param name="serviceSN">服务代码</param>
/// <param name="data">结果数据</param>
/// <returns>返回是否执行成功</returns>
public static bool GetServiceResult(string serviceSN, out NetServiceStruct data)
{
Common.Data.SqlLite.SqlLiteHelper dal = new Common.Data.SqlLite.SqlLiteHelper();
using (System.Data.IDbConnection conn = dal.OpenConnection(Common.Config.ConfigSetting.GetConnectionString()))
using (System.Data.DataTable table = dal.QueryReturnDataTable(conn, string.Format("SELECT VERSIONNO FROM T_UPDATE")))
{
if (table.Rows.Count > 0)
{
using (System.IO.FileStream fs = new System.IO.FileStream(table.Rows[0]["VERSIONNO"].ToString(), System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read))
using (System.IO.MemoryStream ms = new System.IO.MemoryStream((int)fs.Length))
{
fs.CopyTo(ms);
data = PacketsDecoder.ParseNetStream(ms);
}
return true;
}
else
{
data = null;
throw new Common.Exceptions.NoServiceLogException();
}
}
}
}
}