Exemplo n.º 1
0
        bool CreatQueByFile()
        {
            queList.Clear();
startTag:
            Console.Write("输入配置文件名:");
            string tfilename = Console.ReadLine();
            string tfilepath = Application.StartupPath + "/" + tfilename;

            if (!File.Exists(tfilepath))
            {
                goto startTag;
            }
            byte[] tarrys = File.ReadAllBytes(tfilepath);

            StreamReader treader = new StreamReader(new MemoryStream(tarrys));

            string tmsstr = treader.ReadLine();

            Console.WriteLine(string.Format("队列数 {0} ", tmsstr));
            if (!int.TryParse(tmsstr, out queCount))
            {
                queCount = 100;
            }
            queCount = System.Math.Min(100, queCount);

            for (int i = 0; i < queCount; i++)
            {
                QueObject tobj = new QueObject();
                tobj.index = i;

                string tms = treader.ReadLine();
                Console.WriteLine(string.Format("队列间隔 {0} ", tms));
                if (!int.TryParse(tms, out tobj.ms))
                {
                    tobj.ms = 1000;
                }
                tobj.ms = System.Math.Max(100, tobj.ms);

                string trdstrs = treader.ReadLine();
                Console.WriteLine(string.Format("队列按键组 {0} ", trdstrs));
                tobj.keys = trdstrs.Split(',');

                queList.Add(tobj);
                Console.WriteLine("-----------------------------------------------------------");
            }


            treader.Close();
            return(true);
        }
Exemplo n.º 2
0
        void CreatCustomQue()
        {
            queList.Clear();
            MemoryStream mem     = new MemoryStream();
            StreamWriter twriter = new StreamWriter(mem);

            Console.WriteLine("输入队列数.上限100次");
            string tmsstr = Console.ReadLine();

            if (!int.TryParse(tmsstr, out queCount))
            {
                queCount = 100;
            }
            queCount = System.Math.Min(100, queCount);

            twriter.WriteLine(queCount);

            for (int i = 0; i < queCount; i++)
            {
                QueObject tobj = new QueObject();
                tobj.index = i;
                Console.WriteLine(string.Format("输入队列 {0} 间隔.", i));
                string tms = Console.ReadLine();
                if (!int.TryParse(tms, out tobj.ms))
                {
                    tobj.ms = 1000;
                }
                tobj.ms = System.Math.Max(100, tobj.ms);

                Console.WriteLine(string.Format("输入队列 {0} 按键组,以 , 号分隔.", i));
                string trdstrs = Console.ReadLine();
                tobj.keys = trdstrs.Split(',');

                queList.Add(tobj);

                twriter.WriteLine(tobj.ms);
                twriter.WriteLine(trdstrs);
                Console.WriteLine("-----------------------------------------------------------");
            }


            twriter.Flush();
            twriter.Close();
            byte[] tarys = mem.ToArray();
            Console.Write("是否保存为配置文件? y/n : ");
            string yorn = Console.ReadLine();

            switch (yorn)
            {
            case "y":
            {
                Console.Write("输入文件名: ");
                string tfilename = Console.ReadLine();
                string tfilepath = Application.StartupPath + "/" + tfilename;
                Console.WriteLine(tfilepath);
                File.WriteAllBytes(tfilepath, tarys);
            }
            break;

            case "n":
                break;
            }

            mem.Close();
        }