当前仓库属于暂停状态,部分功能使用受限,详情请查阅 仓库状态说明
1 Star 0 Fork 6

small_fly / data_publish
暂停

forked from 海风 / data_publish
暂停
 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Program.cs 4.80 KB
一键复制 编辑 原始数据 按行查看 历史
海风 提交于 2018-08-31 13:54 . 更新:mongo组件升级到2.7
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using NetMQ;
using NetMQ.Sockets;
using static data_publish.PublishDepth;
namespace data_publish
{
class Program
{
private static string _errLog = string.Empty;
readonly static ManualResetEvent _terminateEvent = new ManualResetEvent(false);
//params: port , mongorul: "mongodb://root:kingisgod.@172.111.111.210:27017/?authenticationDatabase=admin"
static void Main(string[] args)
{
if (args.Length < 1)
{
Console.WriteLine("params: port , mongorul(eg: mongodb://root:kingisgod.@172.111.111.210:27017/?authenticationDatabase=admin");
Console.ReadLine();
return;
}
Console.Title = "数据发布服务器";
_errLog = "err.log";
//处理非UI线程异常
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
DisableCloseButton(Console.Title);
int client = 0;
if (client == 0)
{
//var rsp = new Response("*:8888",args[0] );
var rsp = new Response($"*:{args[0]}", args[1]);
Console.WriteLine("listen to port: *:5055 ( internet 5055 )");
new Thread(() =>
{
rsp.ResponseData();
}).Start();
//var req = new Request();
//foreach (var b in req.QueryMin("cu1610", "20120501", "20160623"))
// Console.WriteLine($"{b._id}, {b.Open}, {b.High}, {b.Low}, {b.Close}, {b.Volume}, {b.OpenInterest}");
//foreach (var b in req.QueryDay("cu1610", "20120501", "20160623"))
// Console.WriteLine($"{b._id}, {b.Open}, {b.High}, {b.Low}, {b.Close}, {b.Volume}, {b.OpenInterest}");
//foreach (var b in req.QueryReal("IF1609"))
// Console.WriteLine($"{b._id}, {b.Open}, {b.High}, {b.Low}, {b.Close}, {b.Volume}, {b.OpenInterest}");
//foreach (var b in req.QueryDate())
// Console.WriteLine(b);
//foreach (var b in req.QueryProduct())
// Console.WriteLine(b._id);
//foreach (var b in req.QueryTime())
// Console.WriteLine(b.GroupId);
//深度行情
//var pub = new PublishDepth("*:5058"); //公网 5058
//Console.WriteLine("listen to port: *:5058 ( internet 5058 )");
//new Thread(() =>
//{
// pub.Publish();
//}).Start();
}
else//20档接受
{
Thread.Sleep(1000);
using (var sub = new SubscriberSocket())
{
sub.Options.ReceiveHighWatermark = 1000;
//sub.Connect("tcp://58.247.171.146:5058");
sub.Connect("tcp://192.168.105.197:5058");
sub.Subscribe("rb1610");
sub.Subscribe("cu1610");
int size = Marshal.SizeOf(typeof(Level20));
byte[] buf = new byte[size];
IntPtr buffer = Marshal.AllocHGlobal(size);
while (true)
{
string inst = sub.ReceiveFrameString();
var bytes = sub.ReceiveFrameBytes();
if (bytes.Length > 6)
{
Marshal.Copy(bytes, 0, buffer, size);
Level20 f = (Level20)Marshal.PtrToStructure(buffer, typeof(Level20));
Console.WriteLine(f.Instrument);
}
}
}
}
while (true) ;
}
#region 禁用关闭按钮
[DllImport("User32.dll", EntryPoint = "FindWindow")]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll", EntryPoint = "GetSystemMenu")]
static extern IntPtr GetSystemMenu(IntPtr hWnd, IntPtr bRevert);
[DllImport("user32.dll", EntryPoint = "RemoveMenu")]
static extern IntPtr RemoveMenu(IntPtr hMenu, uint uPosition, uint uFlags);
///<summary>
/// 禁用关闭按钮
///</summary>
///<param name="consoleName">控制台名字</param>
public static void DisableCloseButton(string title)
{
//线程睡眠,确保closebtn中能够正常FindWindow,否则有时会Find失败。。
//Thread.Sleep(100);
IntPtr windowHandle = FindWindow(null, title);
IntPtr closeMenu = GetSystemMenu(windowHandle, IntPtr.Zero);
uint SC_CLOSE = 0xF060;
RemoveMenu(closeMenu, SC_CLOSE, 0x0);
}
public static bool IsExistsConsole(string title)
{
IntPtr windowHandle = FindWindow(null, title);
if (windowHandle.Equals(IntPtr.Zero)) return false;
return true;
}
#endregion
#region 处理未捕获异常的挂钩函数
private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
Exception error = e.ExceptionObject as Exception;
if (error != null)
{
using (StreamWriter sw = new StreamWriter(_errLog, true))
{
sw.WriteLine(DateTime.Now.ToString("yyyyMMdd HH:mm:ss") + "\t" + string.Format("Application UnhandledException:{0}; 堆栈信息:{1}", error.Message, error.StackTrace));
}
}
else
{
using (StreamWriter sw = new StreamWriter(_errLog, true))
{
sw.WriteLine(DateTime.Now.ToString("yyyyMMdd HH:mm:ss") + "\t" + string.Format("Application UnhandledError:{0}", e));
}
}
}
#endregion
}
}
C#
1
https://gitee.com/small_fly/data_publish.git
git@gitee.com:small_fly/data_publish.git
small_fly
data_publish
data_publish
master

搜索帮助