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.
 
 
 
 
 
 

254 lines
7.1 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Sog;
using LitJson;
using Sog.IO;
using Google.Protobuf.WellKnownTypes;
using Google.Protobuf;
using System.Threading;
namespace bill_statistics
{
public class Program
{
//判断是不是数字
private static bool IsNumberArgs(string args)
{
for (int i = 0; i < args.Length; i++)
{
if (args[i] < '0' || args[i] > '9')
{
return false;
}
}
return true;
}
public static void Main(string[] args)
{
//if (OSUtils.IsWindows())
//{
// Console.WriteLine("please input any key to continue..");
// Console.Read();
// TestJson();
// TestZip();
// TestStaticClass();
// TestUrl();
// //TestBigMemory();
// //TestHexString();
//}
ExportToMysql.Instance.Init("tbill", "127.0.0.1", "mmog", "mmog");
AppTime time = new AppTime();
time.UpdateTime();
TraceLog.SetLogPathName("../log/", "bill_stat");
GameConfigMgr.Instance.ReadAllConfig();
BillAlldays allbill = BillAlldays.Instance;
//入库的时候1个小时调用一次,如果是凌晨0点,那么入库1天数据,否则只入库小时数据,比如在线
int onlyDayNumber = 0;
if (args.Length > 0)
{
if (args[0] == "exporthour")
{
BillMode.Mode = BillModeType.EXPORT_HOUR_LOG;
}
//强制指定导出日数据
if (args[0] == "exportday")
{
BillMode.Mode = BillModeType.EXPROT_DAY_STAT;
}
//
//强制指定导出所有小时数据
if (args[0] == "exportallhour")
{
BillMode.Mode = BillModeType.EXPROT_ALL_HOUR;
}
//强制指定导出所有天计算数据
if (args[0] == "exportallday")
{
BillMode.Mode = BillModeType.EXPROT_ALL_DAY;
}
//强制指定导出日数据
if (args[0] == "exporttoday")
{
BillMode.Mode = BillModeType.EXPROT_TODAY_STAT;
}
//强制指定导出日数据
if (args[0] == "longkeep")
{
BillMode.Mode = BillModeType.LONG_KEEP;
}
//只算今天
if (IsNumberArgs(args[0]))
{
int.TryParse(args[0], out onlyDayNumber);
}
else if (args[0] == "all")
{
onlyDayNumber = 0;//所有
}
}
else
{
BillMode.Mode = BillModeType.EXPROT_ALL_HOUR;
onlyDayNumber = 10; //缺省跑个10天算了
}
ExportToMysql.Instance.Init("tbill", "127.0.0.1", "mmog", "mmog");
NameMgr.Instance.RegisterAllUidName();
allbill.ReadDataFromFile(onlyDayNumber);
allbill.CalcAll();
WriteBillAllToExport.WriteAllAndExportIfNeed();
//正常日志输出模式和每天入库的时候打印bill out 文件
if (BillMode.Mode == BillModeType.NORMAL || BillMode.Mode == BillModeType.EXPROT_DAY_STAT)
{
LogWrapper.LogToFileAll();
Console.WriteLine("all bill log gen success.");
}
if (BillMode.Mode == BillModeType.LONG_KEEP)
{
LogWrapper.LogToFileLongKeep();
Console.WriteLine("all long bill log gen success.");
}
}
private static void TestJson()
{
JsonData data = new JsonData();
data["ret"] = 0;
data["msg"] = "error!";
JsonData subData = new JsonData();
data["data"] = subData;
subData["name"] = "testname";
subData["value"] = 555;
JsonData array = new JsonData();
subData["idarray"] = array;
array.Add(1);
array.Add(2);
List<int> list = new List<int>();
//list.ad
string jsonString = data.ToJson();
//empty json?
JsonData emptyJsonArray = new JsonData();
data["array"] = emptyJsonArray;
jsonString = data.ToJson();
Console.WriteLine(jsonString);
}
private static void TestZip()
{
string strContent = "oiwerjladnajsd;lfopwenrlkndlfalks&*%&$%@!#*&(!@*#)(*lkjlfajlsdkjflaksdf\tasdkfla 666666666666666testonly hello world";
byte[] zipBytes = ZipUtils.CompressString(strContent);
byte[] unzipBytes = ZipUtils.DecompressBytes(zipBytes);
string outStr = System.Text.Encoding.UTF8.GetString(unzipBytes);
if (outStr == strContent)
{
Console.WriteLine("zip unzip success");
}
}
private static void TestStaticClass()
{
//BillChangeItemReasonMap.Instance.CheckAllReasonRegisted();
}
private static void TestBigMemory()
{
List<byte[]> bytesarray = new List<byte[]>();
//测试成功
// 6000为6G,1000为1G
for (int i = 0; i < 1000; i++)
{
byte[] onebytes = new byte[1024 * 1024];
for (int j = 0; j < 10000; j++)
{
onebytes[j * 100] = (byte)j;
}
bytesarray.Add(onebytes);
}
Console.WriteLine("new byte count " + bytesarray.Count.ToString());
Console.Read();
}
private static void TestUrl()
{
string url = @"space test !@#$%^&*()_+中文测试下 \][.,/";
string escapeUrl = Uri.EscapeDataString(url);
escapeUrl = "++++" + escapeUrl;
escapeUrl = escapeUrl.Replace("+", "%20");
string unesUrl = Uri.UnescapeDataString(escapeUrl);
int i = 0;
i++;
}
private static void TestHexString()
{
byte[] bytes = new byte[255];
for (int i = 0; i < bytes.Length; i++)
{
bytes[i] = (byte)i;
}
string hexString = StringUtils.ToHexString(bytes);
byte[] newBytes = StringUtils.HexStringToBytes(hexString);
for (int i = 0; i < bytes.Length; i++)
{
if (bytes[i] != newBytes[i])
{
Console.WriteLine("TestHexString failed");
return;
}
}
}
private static void TestSpan()
{
//byte[] sb = stackalloc byte[2];
}
}
}