using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using Library;
using LitJson;
using MySystem;

public class TestHelper
{
    public readonly static TestHelper Instance = new TestHelper();
    private TestHelper()
    { }

    public void Start()
    {
        Thread th = new Thread(DoQueue);
        th.IsBackground = true;
        th.Start();
    }

    public void DoWorks()
    {
        while (true)
        {
            string content = RedisDbconn.Instance.RPop<string>("LogQueue");
            if (!string.IsNullOrEmpty(content))
            {
                try
                {
                }
                catch (Exception ex)
                {
                    LogHelper.Instance.WriteLog(DateTime.Now.ToString() + "\n" + content + "\n" + ex, "SLS日志异常");
                }
            }
            else
            {
                Thread.Sleep(5000);
            }
        }
    }

    public void DoQueue()
    { 
        string check = function.ReadInstance("/chk.txt");
        if(!string.IsNullOrEmpty(check))
        {
            return;
        }
        function.WritePage("/", "chk.txt", DateTime.Now.ToString());
        string[] list = function.ReadInstance("9.txt").Split('\n');
        foreach(string sub in list)
        {
            Utils.WriteLog(sub);
            function.GetWebRequest("https://logic-executor-api.kexiaoshuang.com/noauth/prize/pushbyone?n=QUEUE_KXS_MACHINE_PRIZE_CONFIG_DIVISION&m=" + sub + "&ids=3");
        }
        // list = function.ReadInstance("10.txt").Split('\n');
        // foreach(string sub in list)
        // {
        //     Utils.WriteLog(sub);
        //     // function.GetWebRequest("https://logic-executor-api.kexiaoshuang.com/noauth/prize/pushbyone?n=" + data[1] + "&m=" + data[0] + "&ids=60,");
        //     function.GetWebRequest("https://logic-executor-api.kexiaoshuang.com/noauth/prize/push?n=QUEUE_KXS_MACHINE_PRIZE_CONFIG_DIVISION&m=" + sub);
        // }
    }
}