public bool ClntBufHndl(byte[] buf) { int offs = 0; int l, errc; switch (mState) { case NetPhase.Dating: if (!DT.ReadByte(buf, ref offs, out mDt) && bRunning) { Dispatcher.Invoke(() => { txtDate.Text = Txt.s._[(int)TxI.DATE] + mDt.ToString(DT.RR); EnableControls(); btnReconn.IsEnabled = false; }); mState = NetPhase.Authenticating; } break; case NetPhase.Authenticating: l = buf.Length - offs; if (l < 4) { break; } errc = BitConverter.ToInt32(buf, offs); offs += 4; if (errc == 0) { ExamineeC e = new ExamineeC(); e.bLog = User.bLog; bool b = e.ReadByte(buf, ref offs); l = buf.Length - offs; if (!b) { User.Merge(e); mState = NetPhase.ExamRetrieving; return(true); //continue } } else { string msg = null; if (errc == (int)TxI.SIGNIN_AL) { if (l < 4) { break; } int sz = BitConverter.ToInt32(buf, offs); l -= 4; offs += 4; if (l < sz) { break; } string comp = ""; if (0 < sz) { comp = Encoding.UTF8.GetString(buf, offs, sz); l -= sz; offs += sz; } if (l < 8) { break; } int h = BitConverter.ToInt32(buf, offs); offs += 4; int m = BitConverter.ToInt32(buf, offs); offs += 4; l -= 8; StringBuilder sb = new StringBuilder(); sb.AppendFormat(Txt.s._[(int)TxI.SIGNIN_AL], h.ToString() + ':' + m); sb.Append(comp + '.'); msg = sb.ToString(); } else if (errc == (int)TxI.SIGNIN_NOK) { msg = Txt.s._[(int)TxI.SIGNIN_NOK]; } else if (errc == (int)TxI.NEEID_NF) { msg = Txt.s._[(int)TxI.NEEID_NF]; } else if (errc == (int)TxI.RECV_DAT_ER) { msg = Txt.s._[(int)TxI.RECV_DAT_ER]; } if (bRunning && msg != null) { Dispatcher.Invoke(() => { AppView.Opacity = 0.5; PopupMgr.Singleton.ShowDialog(msg); AppView.Opacity = 1; EnableControls(); }); } } break; case NetPhase.ExamRetrieving: errc = BitConverter.ToInt32(buf, offs); offs += 4; if (errc == (int)TxI.QS_NFOUND) { mState = NetPhase.Authenticating; int qsid = BitConverter.ToInt32(buf, offs); offs += 4; if (bRunning) { Dispatcher.Invoke(() => { AppView.Opacity = 0.5; PopupMgr.Singleton.ShowDialog(Txt.s._[(int)TxI.QS_NFOUND] + qsid); AppView.Opacity = 1; EnableControls(); }); } break; } QuestSheet qs = new QuestSheet(); if (qs.ReadByte(buf, ref offs)) { mState = NetPhase.Authenticating; if (bRunning) { Dispatcher.Invoke(() => { AppView.Opacity = 0.5; PopupMgr.Singleton.ShowDialog(Txt.s._[(int)TxI.QS_READ_ER]); AppView.Opacity = 1; EnableControls(); }); } break; } if (bRunning) { Dispatcher.Invoke(() => { pgTkExm = new TakeExam(); pgTkExm.mExaminee = User; pgTkExm.QuestSheetModel = qs; NavigationService.Navigate(pgTkExm); }); } break; } return(false); }
public bool ClntBufHndl(byte[] buf) { int offs = 0; switch (mState) { case NetPhase.Submiting: int rs; string msg = null; int l = buf.Length - offs; if (l < 4) { rs = -1; msg = Txt.s._[(int)TxI.RECV_DAT_ER]; } else { rs = BitConverter.ToInt32(buf, offs); } l -= 4; offs += 4; if (rs == 0) { ExamineeC e = new ExamineeC(); if (!e.ReadByte(buf, ref offs)) { mExaminee.Merge(e); btnSubmit.Content = mExaminee.Grade; msg = Txt.s._[(int)TxI.RESULT] + mExaminee.Grade; } else { msg = Txt.s._[(int)TxI.RECV_DAT_ER]; } } else if (rs == (int)TxI.NEEID_NF) { msg = Txt.s._[(int)TxI.NEEID_NF]; } else if (rs == (int)TxI.RECV_DAT_ER) { msg = Txt.s._[(int)TxI.RECV_DAT_ER]; } else if (msg == null) { if (l < 4) { msg = Txt.s._[(int)TxI.RECV_DAT_ER]; } else { int sz = BitConverter.ToInt32(buf, offs); l -= 4; offs += 4; if (l < sz) { msg = Txt.s._[(int)TxI.RECV_DAT_ER]; } else { msg = System.Text.Encoding.UTF8.GetString(buf, offs, sz); } } } Dispatcher.Invoke(() => { AppView.Opacity = 0.5; PopupMgr.Singleton.ShowDialog(msg); AppView.Opacity = 1; }); break; } bBtnBusy = false; return(false); }