示例#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);
        }
示例#2
0
        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);
        }
示例#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);
        }
示例#4
0
        public bool SrvrBufHndl(byte[] buf, out byte[] outMsg)
        {
            outMsg = null;
            int     offs = 0;
            NetCode c    = (NetCode)BitConverter.ToInt32(buf, offs);

            offs += 4;
            QuestSheet qs;
            int        lvid;
            ExamineeA  e;
            DateTime   dt;

            switch (c)
            {
            case NetCode.Dating:
                outMsg = new byte[DT.BYTE_COUNT];
                offs   = 0;
                DT.ToByte(outMsg, ref offs, mBrd.mDt);
                return(true);

            case NetCode.Authenticating:
                e        = new ExamineeS1();
                e.bFromC = true;
                e.ReadByte(buf, ref offs);
                bool lck   = true;
                bool found = false;
                foreach (SortedList <int, bool> l in vfbLock)
                {
                    if (l.TryGetValue(e.LvId, out lck))
                    {
                        found = true;
                        break;
                    }
                }
                if (!found)
                {
                    lck = false;
                }
                if (!lck)
                {
                    ExamineeA o = null;
                    dt = DateTime.Now;
                    foreach (ExamSlot sl in mBrd.Slots.Values)
                    {
                        if ((o = sl.Signin(e)) != null)
                        {
                            dt = sl.Dt;
                            break;
                        }
                    }

                    if (o != null)
                    {
                        if (o.dtTim1.Hour == DT.INV)
                        {
                            o.dtTim1 = DateTime.Now;
                        }
                        Dispatcher.InvokeAsync(() =>
                        {
                            foreach (Op1SlotView vw in tbcSl.Items.OfType <Op1SlotView>())
                            {
                                TextBlock t;
                                lvid = o.LvId;
                                if (vw.vComp.TryGetValue(lvid, out t))
                                {
                                    t.Text = o.tComp;
                                }
                                if (vw.vDt1.TryGetValue(lvid, out t))
                                {
                                    t.Text = o.dtTim1.ToString("HH:mm");
                                }
                                CheckBox cbx;
                                if (vw.vLock.TryGetValue(lvid, out cbx))
                                {
                                    cbx.IsChecked = true;
                                    cbx.IsEnabled = true;
                                }
                                if (vw.vbLock.Keys.Contains(lvid))
                                {
                                    vw.vbLock[lvid] = true;
                                }
                            }
                        });
                        byte[] a;
                        o.bFromC = true;
                        o.ToByte(out a);
                        outMsg = new byte[4 + a.Length];
                        Buffer.BlockCopy(BitConverter.GetBytes(0), 0, outMsg, 0, 4);
                        Buffer.BlockCopy(a, 0, outMsg, 4, a.Length);
                    }
                    else
                    {
                        outMsg = new byte[4];
                        Buffer.BlockCopy(BitConverter.GetBytes((int)TxI.SIGNIN_NOK), 0, outMsg, 0, 4);
                        return(false);   //close
                    }
                }
                else
                {
                    ExamineeA o = null;
                    foreach (ExamSlot sl in mBrd.Slots.Values)
                    {
                        if ((o = sl.Find(e.LvId)) != null)
                        {
                            break;
                        }
                    }
                    if (o == null)
                    {
                        o = new ExamineeC(e.tId);
                    }
                    if (o.tComp == null)
                    {
                        outMsg = new byte[16];
                    }
                    else
                    {
                        outMsg = new byte[16 + o.tComp.Length];
                    }
                    Buffer.BlockCopy(BitConverter.GetBytes((int)TxI.SIGNIN_AL), 0, outMsg, 0, 4);
                    if (o.tComp == null)
                    {
                        Buffer.BlockCopy(BitConverter.GetBytes(0), 0, outMsg, 4, 4);
                        offs = 8;
                    }
                    else
                    {
                        byte[] comp = Encoding.UTF8.GetBytes(o.tComp);
                        Buffer.BlockCopy(BitConverter.GetBytes(comp.Length), 0, outMsg, 4, 4);
                        offs = 8;
                        Buffer.BlockCopy(comp, 0, outMsg, offs, o.tComp.Length);
                        offs += comp.Length;
                    }

                    Buffer.BlockCopy(BitConverter.GetBytes(o.dtTim1.Hour), 0, outMsg, offs, 4);
                    offs += 4;
                    Buffer.BlockCopy(BitConverter.GetBytes(o.dtTim1.Minute), 0, outMsg, offs, 4);
                    break;
                }
                return(true);

            case NetCode.ExamRetrieving:
                outMsg = null;
                lvid   = BitConverter.ToInt32(buf, offs);
                ExamSlot slo = null;
                foreach (ExamSlot s in mBrd.Slots.Values)
                {
                    foreach (ExamRoom r in s.Rooms.Values)
                    {
                        if (r.vExaminee.ContainsKey(lvid))
                        {
                            slo = s;
                            break;
                        }
                    }
                }
                if (slo == null)
                {
                    outMsg = new byte[4];
                    Array.Copy(BitConverter.GetBytes((int)TxI.NEEID_NF), 0, outMsg, 0, 4);
                    break;
                }
                Level lv = (lvid < (int)Level.MAX_COUNT_EACH_LEVEL) ? Level.A : Level.B;
                offs += 4;
                int qsid = BitConverter.ToInt32(buf, offs);
                if (qsid == (int)Level.MAX_COUNT_EACH_LEVEL)
                {
                    byte[] a = slo.ToByteNextQS(lv);
                    if (a != null)
                    {
                        outMsg = new byte[a.Length + 4];
                        Array.Copy(BitConverter.GetBytes(0), outMsg, 4);
                        Array.Copy(a, 0, outMsg, 4, a.Length);
                    }
                }
                else if (slo.MainPacks[lv].Sheets.TryGetValue(qsid, out qs))
                {
                    outMsg = new byte[qs.ItemsInBytes.Length + 4];
                    Array.Copy(BitConverter.GetBytes(0), outMsg, 4);
                    Array.Copy(qs.ItemsInBytes, 0, outMsg, 4, qs.ItemsInBytes.Length);
                }
                if (outMsg == null)
                {
                    mCbMsg += Txt.s._[(int)TxI.QS_NFOUND] + (qsid);
                    outMsg  = new byte[8];
                    Array.Copy(BitConverter.GetBytes((int)TxI.QS_NFOUND), 0, outMsg, 0, 4);
                    Array.Copy(BitConverter.GetBytes(qsid), 0, outMsg, 4, 4);
                }
                break;

            case NetCode.Submiting:
                e        = new ExamineeS1();
                e.bFromC = true;
                if (!e.ReadByte(buf, ref offs))
                {
                    AnsSheet keySh = null;
                    found = false;
                    foreach (ExamSlot sl in mBrd.Slots.Values)
                    {
                        if (sl.mKeyPack.Sheets.TryGetValue(e.mAnsSh.uQSLvId, out keySh))
                        {
                            found = true;
                            break;
                        }
                    }
                    if (!found)
                    {
                        outMsg = BitConverter.GetBytes(101);    //todo
                        break;
                    }
                    ExamineeA o = null;
                    lvid  = e.LvId;
                    found = false;
                    foreach (ExamSlot sl in mBrd.Slots.Values)
                    {
                        if ((o = sl.Find(lvid)) != null)
                        {
                            break;
                        }
                    }
                    if (o != null)
                    {
                        o.eStt   = NeeStt.Finished;
                        o.mAnsSh = e.mAnsSh;
                        o.uGrade = keySh.Grade(e.mAnsSh.aAns);
                        o.dtTim2 = DateTime.Now;
                        foreach (SortedList <int, bool> sl in vfbLock)
                        {
                            if (sl.ContainsKey(lvid))
                            {
                                sl[lvid] = true;
                            }
                        }
                        Dispatcher.InvokeAsync(() =>
                        {
                            bool toSubm = true;
                            foreach (Op1SlotView vw in tbcSl.Items.OfType <Op1SlotView>())
                            {
                                TextBlock t = null;
                                if (vw.vDt2.TryGetValue(lvid, out t))
                                {
                                    t.Text = o.dtTim2.ToString("HH:mm");
                                }
                                if (vw.vMark.TryGetValue(lvid, out t))
                                {
                                    t.Text = o.Grade.ToString();
                                }
                                CheckBox cbx;
                                if (vw.vLock.TryGetValue(lvid, out cbx))
                                {
                                    cbx.IsChecked = true;
                                    cbx.IsEnabled = false;
                                }
                                if (vw.vAbsen.TryGetValue(lvid, out cbx))
                                {
                                    cbx.IsChecked = cbx.IsEnabled = false;
                                }
                                if (!vw.ToSubmit())
                                {
                                    toSubm = false;
                                }
                            }
                            if (toSubm)
                            {
                                ToSubmit(true);
                            }
                        });
                        o.ToByte(out outMsg, 0);
                    }
                    else
                    {
                        mCbMsg += Txt.s._[(int)TxI.NEEID_NF] + ' ' + lvid;
                        outMsg  = BitConverter.GetBytes((int)TxI.NEEID_NF);
                    }
                }
                else
                {
                    mCbMsg += Txt.s._[(int)TxI.RECV_DAT_ER];
                    outMsg  = BitConverter.GetBytes((int)TxI.RECV_DAT_ER);
                }
                break;

            default:
                outMsg = null;
                break;
            }
            return(false);
        }