Пример #1
0
        static void Main(string[] args)
        {
            CardInfos ci = new CardInfos();

            try
            {
                StreamReader sr = new StreamReader("card.config");
                string       line;
                while ((line = sr.ReadLine()) != null)
                {
                    string[]   attr   = line.Split(',');
                    String[]   ccPair = attr[0].Split('=');
                    String[]   icard  = attr[1].Split('=');
                    CardConfig cc     = new CardConfig()
                    {
                        Name = ccPair[1].Trim()
                    };
                    ICard card = (ICard)Assembly.GetExecutingAssembly().CreateInstance(icard[1].Trim());
                    cc.Card = card;
                    ci.Add(cc);
                }
                sr.Close();
            }
            catch (Exception e)
            {
                String config = JsonConvert.SerializeObject(new Ret()
                {
                    Err = "卡配置文件错误。"
                });
                Console.Write(config);
                Log.Debug(config);
                return;
            }

            int   BaudRate = int.Parse(Config.GetConfig("Baud"));
            short Port     = short.Parse(Config.GetConfig("Port"));

            Log.Debug(String.Join(" ", args));

            GenericService service = new GenericService(ci, Port, BaudRate);
            Object         obj     = null;

            switch (args[0])
            {
            case "ReadCard":
                obj = service.ReadCard();
                break;

            case "WriteGasCard":
                obj = service.WriteGasCard(args[1], args[2], args[3], args[4],
                                           int.Parse(args[5]), int.Parse(args[6]), int.Parse(args[7]), short.Parse(args[8]),
                                           int.Parse(args[9]), int.Parse(args[10]), int.Parse(args[11]), int.Parse(args[12]),
                                           args[13], args[14], int.Parse(args[15]), int.Parse(args[16]), args[17], args[18]
                                           );
                break;

            case "WriteNewCard":
                obj = service.WriteNewCard(args[1], args[2], short.Parse(args[3]), args[4], args[5], args[6], args[7],
                                           int.Parse(args[8]), int.Parse(args[9]), int.Parse(args[10]), short.Parse(args[11]),
                                           int.Parse(args[12]), short.Parse(args[13]), int.Parse(args[14]), int.Parse(args[15]),
                                           int.Parse(args[16]), int.Parse(args[17]), args[18], args[19], int.Parse(args[20]), int.Parse(args[21]), args[22], args[23]
                                           );
                break;

            case "FormatGasCard":
                obj = service.FormatGasCard(args[1], args[2], args[3], args[4]);
                break;

            case "OpenCard":
                obj = service.OpenCard(args[1], args[2], args[3], args[4]);
                break;

            default:
                return;
            }

            String result = JsonConvert.SerializeObject(obj);

            Console.Write(result);
            Log.Debug(result);
            return;
        }
Пример #2
0
        static void Main(string[] args)
        {
            CardInfos ci = new CardInfos();
            try
            {
                StreamReader sr = new StreamReader("card.config");
                string line;
                while ((line = sr.ReadLine()) != null)
                {
                    string[] attr = line.Split(',');
                    String[] ccPair = attr[0].Split('=');
                    String[] icard = attr[1].Split('=');
                    CardConfig cc = new CardConfig() { Name = ccPair[1].Trim() };
                    ICard card = (ICard)Assembly.GetExecutingAssembly().CreateInstance(icard[1].Trim());
                    cc.Card = card;
                    ci.Add(cc);
                }
                sr.Close();
            }
            catch(Exception e)
            {
                String config = JsonConvert.SerializeObject(new Ret() {  Err="卡配置文件错误。"});
                Console.Write(config);
                Log.Debug(config);
                return;                
            }

            int BaudRate = int.Parse(Config.GetConfig("Baud"));
            short Port = short.Parse(Config.GetConfig("Port"));
            Log.Debug(String.Join(" ", args));

            GenericService service = new GenericService(ci, Port, BaudRate);
            Object obj = null;
            switch(args[0])
            {
                case "ReadCard":
                    obj = service.ReadCard();
                    break;
                case "WriteGasCard":
                    obj = service.WriteGasCard(args[1], args[2], args[3], args[4], 
                        int.Parse(args[5]), int.Parse(args[6]), int.Parse(args[7]), short.Parse(args[8]),
                        int.Parse(args[9]), int.Parse(args[10]), int.Parse(args[11]), int.Parse(args[12]),
                        args[13], args[14], int.Parse(args[15]), int.Parse(args[16]), args[17], args[18]
                        );
                    break;
                case "WriteNewCard":
                    obj = service.WriteNewCard(args[1], args[2], short.Parse(args[3]), args[4], args[5], args[6],args[7],
                        int.Parse(args[8]), int.Parse(args[9]), int.Parse(args[10]), short.Parse(args[11]),
                        int.Parse(args[12]), short.Parse(args[13]), int.Parse(args[14]), int.Parse(args[15]),
                        int.Parse(args[16]), int.Parse(args[17]), args[18], args[19], int.Parse(args[20]), int.Parse(args[21]), args[22], args[23]
                        );
                    break;
                case "FormatGasCard":
                    obj = service.FormatGasCard(args[1], args[2], args[3], args[4]);
                    break;
                case "OpenCard":
                    obj = service.OpenCard(args[1], args[2], args[3], args[4]);
                    break;
                default:
                    return;
            }

            String result = JsonConvert.SerializeObject(obj);
            Console.Write(result);
            Log.Debug(result);
            return;
        }
Пример #3
0
        static void Main(string[] args)
        {
            // Log.Debug("in");
            //  writeFile(args[0] +"*******"+ args[1]);
            CardInfos ci = new CardInfos();

            try
            {
                StreamReader sr = new StreamReader("card.config");
                string       line;
                while ((line = sr.ReadLine()) != null)
                {
                    string[]   attr   = line.Split(',');
                    String[]   ccPair = attr[0].Split('=');
                    String[]   icard  = attr[1].Split('=');
                    CardConfig cc     = new CardConfig()
                    {
                        Name = ccPair[1].Trim()
                    };
                    ICard card = (ICard)Assembly.GetExecutingAssembly().CreateInstance(icard[1].Trim());
                    cc.Card = card;
                    ci.Add(cc);
                }
                sr.Close();
            }
            catch (Exception e)
            {
                String config = JsonConvert.SerializeObject(new Ret()
                {
                    Err = "卡配置文件错误。"
                });
                Console.Write(config);
                Log.Debug(config);
                return;
            }

            int   BaudRate = int.Parse(Config.GetConfig("Baud"));
            short Port     = short.Parse(Config.GetConfig("Port"));

            Log.Debug(String.Join(" ", args));
            Log.Debug("args[0]: " + args[0] + "--" + args[1]);
            GenericService service = new GenericService(ci, Port, BaudRate);
            Object         obj     = null;
            Object         obj1    = null;

            string result  = null;
            string result1 = null;
            string result2 = null;
            string result3 = null;

            switch (args[0])
            {
            case "ReadCard":
                byte [] b = HexToBytes(args[1]);
                Log.Debug("args[1]: " + args[1]);
                srdCard_ver(256, b);
                obj = service.ReadCard();
                break;

            case "WriteGasCard":
//===================================================================
                byte[] bbbb = HexToBytes(args[19]);
                byte[] bbb  = new byte[3];
                byte[] bb   = new byte[256];
                Log.Debug("card password!!!!!!!!!!!!!!!!!!");

                srdCard_ver(256, bbbb);
                Log.Debug("start read card!!!!!!!!!!!!!!!!!!!!");

                Log.Debug("写卡开始:" + args[1] + "result" + args[19]);
                obj1 = service.WriteGasCard(args[1], args[2], args[3], args[4],
                                            int.Parse(args[5]), int.Parse(args[6]), int.Parse(args[7]), short.Parse(args[8]),
                                            int.Parse(args[9]), int.Parse(args[10]), int.Parse(args[11]), int.Parse(args[12]),
                                            args[13], args[14], int.Parse(args[15]), int.Parse(args[16]), args[17], args[18], args[19]
                                            );

                get_kmm(bbb);
                result1 = ToHexString(bbb);
                Log.Debug("result1" + result1);
                get_Date(bb);
                result2 = ToHexString(bb);
                Log.Debug("result2" + result2);
                WriteRet ret = new WriteRet();
                ret.Kmy   = result1;
                ret.Kdata = result2;
                break;

            case "WriteNewCard":
                byte[] data = HexToBytes(args[24]);
                Log.Debug("data======" + args[24]);
                byte[] password = new byte[3];
                string str      = "WriteNewCard";
                srdCard_ver(256, data);
                Log.Debug("WriteNewCard:" + str);
                obj = service.WriteNewCard(args[1], args[2], short.Parse(args[3]), args[4], args[5], args[6], args[7],
                                           int.Parse(args[8]), int.Parse(args[9]), int.Parse(args[10]), short.Parse(args[11]),
                                           int.Parse(args[12]), short.Parse(args[13]), int.Parse(args[14]), int.Parse(args[15]),
                                           int.Parse(args[16]), int.Parse(args[17]), args[18], args[19], int.Parse(args[20]), int.Parse(args[21]), args[22], args[23], args[24]
                                           );
                get_kmm(password);
                result1 = Convert.ToString(password);
                result2 = JsonConvert.SerializeObject(obj);
                break;

            case "FormatGasCard":
                obj = service.FormatGasCard(args[1], args[2], args[3], args[4]);
                break;

            case "OpenCard":
                obj = service.OpenCard(args[1], args[2], args[3], args[4]);
                break;

            default:
                return;
            }
            result = JsonConvert.SerializeObject(obj);

            result = result1 + result2 + result3;
            Console.Write(result);
            Log.Debug("*******************" + result + "*******************");
            return;
        }