Beispiel #1
0
        public Authentication()
        {
            InitializeComponent();

            mState   = NetPhase.Dating;
            mClnt    = new Client2(ClntBufHndl, ClntBufPrep, false);
            mCbMsg   = new UICbMsg();
            bRunning = true;

            mDt  = DT.INV_;
            User = new ExamineeC();

            User.kDtDuration = new TimeSpan(1, 0, 0);
        }
Beispiel #2
0
        private void InitModels()
        {
            mState   = NetPhase.Dating;
            mClnt    = new Client2(ClntBufHndl, ClntBufPrep, false);
            mCbMsg   = new UICbMsg();
            bRunning = true;

            mExaminee = new ExamineeC();

            QuestSheetModel = new QuestSheet();

            bBtnBusy = false;

            InitRemainingTime();
        }
Beispiel #3
0
        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);
        }