static void Main()
        {
            try
            {
                var str = SynnCore.Generics.XmlHelper.ToXml(new AppConfiguration {
                    MediaPlayerPath = " ", ProdConnectionString = " ", SyncDirectories = new System.Collections.Generic.List <string> {
                        "dir2", "dir1"
                    }, TempMusicListPath = " ", TestConnectionString = " ", YoutubeDataFolder = " ", RequireAuthentication = false
                });
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                var appcfg = LoadStationConfigurations();

                HandleDbMigration();
#if DEBUG
                GlobalAppData.SetUser(new LoggedUser {
                    Id = 0, Password = "", UserName = "******"
                });
                Application.Run(new Form1());
#else
                if (appcfg.RequireAuthentication)
                {
                    Application.Run(new LoginForm());
                }
                else
                {
                    GlobalAppData.SetUser(new LoggedUser {
                        Id = 0, Password = "", UserName = "******"
                    });
                    Application.Run(new Form1());
                }
#endif
            }
            catch (Exception ex)
            {
                var logP = @"C:\temp\musictemp\log.txt";
                var msg  = string.Format("{0} - {1} Trace = {2}", DateTime.Now, ex.Message, ex.StackTrace);
                File.AppendAllLines(logP, new string[] { msg });
            }
        }
示例#2
0
        private void Ok_Click(object sender, HtmlElementEventArgs e)
        {
            string oldPass        = GetElementById("oldPass").GetAttribute("value");
            string newPass        = GetElementById("newPass").GetAttribute("value");
            string newPassConfirm = GetElementById("newPassConfirm").GetAttribute("value");

            if (Encrypt.AESEncrypt(oldPass, GlobalAppData.EncryptKey) != GlobalAppData.GetInstance().EntryPwd)
            {
                GetElementById("info").InnerText = "¾ÉÃÜÂëÊäÈë´íÎó£¡";
                GetElementById("oldPass").SetAttribute("value", "");
                GetElementById("newPass").SetAttribute("value", "");
                GetElementById("newPassConfirm").SetAttribute("value", "");
                return;
            }
            if (newPass.Length != 6)
            {
                GetElementById("info").InnerText = "ÐÂÃÜÂ볤¶È´íÎó£¡";
                GetElementById("oldPass").SetAttribute("value", "");
                GetElementById("newPass").SetAttribute("value", "");
                GetElementById("newPassConfirm").SetAttribute("value", "");
                return;
            }
            if (newPass != newPassConfirm)
            {
                GetElementById("info").InnerText = "ÐÂÃÜÂëÊäÈë²»Ò»Ö£¡";
                GetElementById("oldPass").SetAttribute("value", "");
                GetElementById("newPass").SetAttribute("value", "");
                GetElementById("newPassConfirm").SetAttribute("value", "");
                return;
            }
            GlobalAppData.GetInstance().EntryPwd = Encrypt.AESEncrypt(newPass, GlobalAppData.EncryptKey);
            GetElementById("info").InnerText = "ÃÜÂëÐ޸ijɹ¦£¡";
            GetElementById("oldPass").SetAttribute("value", "");
            GetElementById("newPass").SetAttribute("value", "");
            GetElementById("newPassConfirm").SetAttribute("value", "");
        }
示例#3
0
 private void btnPlayPlaylist_Click(object sender, EventArgs e)
 {
     GlobalAppData.SetWait();
     MusicListManager.PlayPlayList(PlayList());
     GlobalAppData.EndWait();
 }
示例#4
0
 void Awake()
 {
     _instance = this;
     // 防止载入新场景时被销毁
     DontDestroyOnLoad(_instance.gameObject);
 }
        public MAVLinkMessage ReadPacket()
        {
            byte[]         buffer    = new byte[GlobalAppData.MAX_PACKET_LEN + 25];
            int            count     = 0;
            int            length    = 0;
            int            readcount = 0;
            MAVLinkMessage message   = null;

            DateTime start = DateTime.Now;

            lock (readlock)
            {
                while ((BaseStream != null && BaseStream.IsOpen) || logreadmode)
                {
                    try
                    {
                        if (readcount > 300)
                        {
                            break;
                        }

                        readcount++;
                        if (logreadmode)
                        {
                            message = ReadLog();
                            buffer  = message.buffer;
                            if (buffer == null || buffer.Length == 0)
                            {
                                return(MAVLinkMessage.Invalid);
                            }
                        }
                        else
                        {
                            if (BaseStream.ReadTimeout != 1200)
                            {
                                BaseStream.ReadTimeout = 1200; // 1200 ms between chars - the gps detection requires this.
                            }
                            DateTime to = DateTime.Now.AddMilliseconds(BaseStream.ReadTimeout);

                            while (BaseStream.IsOpen && BaseStream.BytesToRead <= 0)
                            {
                                if (DateTime.Now > to)
                                {
                                    throw new TimeoutException("Timeout");
                                }

                                Task.Delay(1);
                            }
                            if (BaseStream.IsOpen)
                            {
                                BaseStream.Read(buffer, count, 1);
                                if (rawlogfile != null && rawlogfile.CanWrite)
                                {
                                    rawlogfile.WriteByte(buffer[count]);
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        break;
                    }

                    // check if looks like a mavlink packet and check for exclusions and write to console
                    if (buffer[0] != 0xfe && buffer[0] != 'U' && buffer[0] != 0xfd)
                    {
                        if (buffer[0] >= 0x20 && buffer[0] <= 127 || buffer[0] == '\n' || buffer[0] == '\r')
                        {
                            // check for line termination
                            if (buffer[0] == '\r' || buffer[0] == '\n')
                            {
                                // check new line is valid
                                if (buildplaintxtline.Length > 3)
                                {
                                    plaintxtline = buildplaintxtline;
                                }

                                // reset for next line
                                buildplaintxtline = "";
                            }

                            TCPConsole.Write(buffer[0]);
                            buildplaintxtline += (char)buffer[0];
                        }

                        //_bytesReceivedSubj.OnNext(1);
                        count     = 0;
                        buffer[1] = 0;
                        continue;
                    }

                    // reset count on valid packet
                    readcount = 0;
                    // check for a header
                    if (buffer[0] == 0xfe || buffer[0] == 0xfd || buffer[0] == 'U')
                    {
                        var mavlinkv2 = buffer[0] == GlobalAppData.MAVLINK_STX ? true : false;

                        int headerlength    = mavlinkv2 ? GlobalAppData.MAVLINK_CORE_HEADER_LEN : GlobalAppData.MAVLINK_CORE_HEADER_MAVLINK1_LEN;
                        int headerlengthstx = headerlength + 1;

                        // if we have the header, and no other chars, get the length and packet identifiers
                        if (count == 0 && !logreadmode)
                        {
                            DateTime to = DateTime.Now.AddMilliseconds(BaseStream.ReadTimeout);

                            while (BaseStream.IsOpen && BaseStream.BytesToRead < headerlength)
                            {
                                if (DateTime.Now > to)
                                {
                                    throw new TimeoutException("Timeout");
                                }

                                Task.Delay(1);
                            }

                            int read = BaseStream.Read(buffer, 1, headerlength);
                            count = read;
                            if (rawlogfile != null && rawlogfile.CanWrite)
                            {
                                rawlogfile.Write(buffer, 1, read);
                            }
                        }

                        // packet length
                        if (buffer[0] == GlobalAppData.MAVLINK_STX)
                        {
                            length = buffer[1] + headerlengthstx +
                                     GlobalAppData.MAVLINK_NUM_CHECKSUM_BYTES; // data + header + checksum - magic - length
                            if ((buffer[2] & GlobalAppData.MAVLINK_IFLAG_SIGNED) > 0)
                            {
                                length += GlobalAppData.MAVLINK_SIGNATURE_BLOCK_LEN;
                            }
                        }
                        else
                        {
                            length = buffer[1] + headerlengthstx +
                                     GlobalAppData.MAVLINK_NUM_CHECKSUM_BYTES; // data + header + checksum - U - length
                        }

                        if (count >= headerlength || logreadmode)
                        {
                            try
                            {
                                if (logreadmode)
                                {
                                }
                                else
                                {
                                    DateTime to = DateTime.Now.AddMilliseconds(BaseStream.ReadTimeout);

                                    while (BaseStream.IsOpen && BaseStream.BytesToRead < (length - (headerlengthstx)))
                                    {
                                        if (DateTime.Now > to)
                                        {
                                            break;
                                        }

                                        Task.Delay(1);
                                    }

                                    if (BaseStream.IsOpen)
                                    {
                                        int read = BaseStream.Read(buffer, headerlengthstx, length - (headerlengthstx));
                                        if (rawlogfile != null && rawlogfile.CanWrite)
                                        {
                                            // write only what we read, temp is the whole packet, so 6-end
                                            rawlogfile.Write(buffer, headerlengthstx, read);
                                        }
                                    }
                                }

                                count = length;
                            }
                            catch
                            {
                                break;
                            }
                            break;
                        }
                    }
                    count++;
                    if (count == 299)
                    {
                        break;
                    }
                }
            } // end readlock

            // resize the packet to the correct length
            Array.Resize <byte>(ref buffer, count);

            // add byte count
            //_bytesReceivedSubj.OnNext(buffer.Length);

            // update bps statistics
            if (_bpstime.Second != DateTime.Now.Second)
            {
                long btr = 0;
                if (BaseStream != null && BaseStream.IsOpen)
                {
                    btr = BaseStream.BytesToRead;
                }
                else if (logreadmode)
                {
                    btr = logplaybackfile.BaseStream.Length - logplaybackfile.BaseStream.Position;
                }
                _bps2           = _bps1; // prev sec
                _bps1           = 0;     // current sec
                _bpstime        = DateTime.Now;
                _mavlink1count  = 0;
                _mavlink2count  = 0;
                _mavlink2signed = 0;
            }

            _bps1 += buffer.Length;

            if (buffer.Length == 0)
            {
                return(MAVLinkMessage.Invalid);
            }

            if (message == null)
            {
                message = new MAVLinkMessage(buffer, DateTime.UtcNow);
            }

            uint msgid = message.msgid;

            GlobalAppData.message_info msginfo = GlobalAppData.GetMessageInfo(msgid);

            // calc crc
            var    sigsize = (message.sig != null) ? GlobalAppData.MAVLINK_SIGNATURE_BLOCK_LEN : 0;
            ushort crc     = MavlinkCRC.crc_calculate(buffer, message.Length - sigsize - GlobalAppData.MAVLINK_NUM_CHECKSUM_BYTES);

            // calc extra bit of crc for mavlink 1.0/2.0
            if (message.header == 0xfe || message.header == 0xfd)
            {
                crc = MavlinkCRC.crc_accumulate(msginfo.crc, crc);
            }

            // check message length size vs table (mavlink1 explicit size check | mavlink2 allow all, undersize 0 trimmed, and oversize unknown extension)
            if (!message.ismavlink2 && message.payloadlength != msginfo.minlength)
            {
                if (msginfo.length == 0) // pass for unknown packets
                {
                }
                else
                {
                    return(MAVLinkMessage.Invalid);
                }
            }

            // check crc
            if ((message.crc16 >> 8) != (crc >> 8) ||
                (message.crc16 & 0xff) != (crc & 0xff))
            {
                return(MAVLinkMessage.Invalid);
            }


            byte sysid       = message.sysid;
            byte compid      = message.compid;
            byte packetSeqNo = message.seq;

            // stat count
            if (message.buffer[0] == GlobalAppData.MAVLINK_STX)
            {
                _mavlink2count++;
            }
            else if (message.buffer[0] == GlobalAppData.MAVLINK_STX_MAVLINK1)
            {
                _mavlink1count++;
            }

            // if its a gcs packet - dont process further
            if (buffer.Length >= 5 && (sysid == 255 || sysid == 253) && logreadmode) // gcs packet
            {
                return(message);
            }

            return(message);
        }
示例#6
0
        private void PayProcess()
        {
            TransAccessFactory db = new TransAccessFactory();
            int nTryConfirm       = 3;
            CPetroPayBeingPay     PetroPayBeingPay = new CPetroPayBeingPay();
            TransResult           retPay           = SyncTransaction(PetroPayBeingPay);
            CReverse_YAPaymentPay rev = new CReverse_YAPaymentPay(PetroPayBeingPay);

            if (retPay == TransResult.E_SUCC)
            {
                if (bisICCard)
                {
                    int state = emv.EMVTransEnd(YAPaymentPay.RecvField55, YAPaymentPay.RecvField38);
                    if (state != 0)
                    {
                        rev.Reason = "06";
                        SyncTransaction(rev);
                        ShowMessageAndGotoMain("IC确认错误,交易失败,请重试");
                        return;
                    }
                }

                if (GlobalAppData.GetInstance().AccessSwitch)
                {
                    db.PayTraceNo = YAPaymentPay.PayTraceNo;
                    ResponseData rd = new YAPaymentPay().GetResponseData();
                    db.InsertTransLog(rd);
                }
CONFIRM:
                //缴费成功,发起确认销账
                CPetroPayBillConfirm billConfirm = new CPetroPayBillConfirm();
                TransResult retConfirm = SyncTransaction(billConfirm);
                //Test
                //retConfirm = TransResult.E_RECV_FAIL;
                //PetroChinaPay.PayTraceNo = "111111";
                //PetroChinaPay.PayReferenceNo = "123456789012345678";
                if (retConfirm != TransResult.E_SUCC &&
                    retConfirm != TransResult.E_RECV_FAIL)
                {
                    if (GlobalAppData.GetInstance().AccessSwitch)
                    {
                        db.UpdateTransLog(EnumConfirmFlag.E_REVERSE);
                    }

                    //失败但不超时才发冲正
                    if (bisICCard)
                    {
                        rev.SetField55Value(emv.EMVInfo.EndField55, emv.EMVInfo.EndField55.Length);//处理之后的55域
                    }
                    rev.Reason = "06";
                    SyncTransaction(rev);
                    ShowMessageAndGotoMain("交易超时,请重试");
                    return;
                }
                else if (retConfirm == TransResult.E_RECV_FAIL)
                {
                    //超时无响应循环发送确认报文
                    if (nTryConfirm != 0)
                    {
                        nTryConfirm--;
                        goto CONFIRM;
                    }

                    //销账失败
                    //操作成功,后台发生异常,核销失败,请不要继续缴费,
                    //等待系统自动处理。次日下午4:00以后再行查看缴费情况
                    Log.Warn("银行卡扣款成功,但销账失败,需人工处理CardNo=" + CommonData.BankCardNum +
                             " 凭证号=" + YAPaymentPay.PayTraceNo + " 系统参考号=" + YAPaymentPay.PayReferenceNo);
                    rev.ClearReverseFile();//清除冲正文件
                    StartActivity("中石油支付销账失败");

                    //string failPath = Path.Combine(Application.StartupPath, "PetroConfirmFailInfo.dat");
                    //ConfirmFailInfo info = new ConfirmFailInfo();
                    //info.BankCardNo = CommonData.BankCardNum;
                    //info.PayTraceNo = PetroChinaPay.PayTraceNo;
                    //info.PayReferenceNo = PetroChinaPay.PayReferenceNo;
                    //List<ConfirmFailInfo> list = new List<ConfirmFailInfo>();
                    //list.Add(info);
                    //Utility.SaveToFile<ConfirmFailInfo>(failPath, list);
                }
                else
                {
                    if (GlobalAppData.GetInstance().AccessSwitch)
                    {
                        db.UpdateTransLog(EnumConfirmFlag.E_SUCC);
                    }

                    rev.ClearReverseFile();//清除冲正文件
                    if (ReceiptPrinter.ExistError())
                    {
                        StartActivity("中石油支付交易完成");
                    }
                    else
                    {
                        StartActivity("中石油支付交易成功是否打印");
                    }
                }
            }
            else if (retPay == TransResult.E_HOST_FAIL)
            {
                if (PetroPayBeingPay.ReturnCode == "51")
                {
                    ShowMessageAndGotoMain("温馨提示:抱歉!交易失败!" + "\n" +
                                           "您卡内余额不足!");
                }
                else if (PetroPayBeingPay.ReturnCode == "55")
                {
                    StartActivity("中石油支付密码错误");
                }
                else
                {
                    ShowMessageAndGotoMain(PetroPayBeingPay.ReturnCode + "-" + PetroPayBeingPay.ReturnMessage);
                }
            }
            else if (retPay == TransResult.E_RECV_FAIL)
            {
                rev.Reason = "98";
                SyncTransaction(rev);
                ShowMessageAndGotoMain("交易超时,请重试");
                return;
            }
            else
            {
                ShowMessageAndGotoMain("交易失败,请重试");
            }

            rev.ClearReverseFile();//在不发冲正文件的情况下,才清除冲正文件
        }