private void W_Closing(object sender, System.ComponentModel.CancelEventArgs e) { bRunning = false; UICbMsg dummy = new UICbMsg(); mServer.Stop(ref dummy); }
public Operation1() { InitializeComponent(); mState = NetCode.Srvr1DatRetriving; mClnt = new Client2(ClntBufHndl, ClntBufPrep, true); mServer = new Server2(SrvrBufHndl); mServer.SrvrPort = 23821; mCbMsg = new UICbMsg(); bRunning = true; mBrd = new ExamBoard(); if (!System.IO.File.Exists("Room.txt") || !int.TryParse(System.IO.File.ReadAllText("Room.txt"), out uRId)) { uRId = 0; } vfbLock = new List <SortedList <int, bool> >(); System.Timers.Timer aTimer = new System.Timers.Timer(2000); // Hook up the Elapsed event for the timer. aTimer.Elapsed += UpdateSrvrMsg; aTimer.AutoReset = true; aTimer.Enabled = true; }
public ExamineeA mNee;//reference to Auth.mNee public ExamPage() { InitializeComponent(); mState = NetCode.Dating; mClnt = new Client2(ClntBufHndl, ClntBufPrep, false); mCbMsg = new UICbMsg(); bRunning = true; mQSh = new QuestSheet(); }
public Archieve() { InitializeComponent(); mCbMsg = new UICbMsg(); mBrd = new ExamBoard(); bRunning = true; tbiSelected = null; }
public Operation0() { InitializeComponent(); mServer = new Server2(SrvrBufHndl); mCbMsg = new UICbMsg(); mBrd = new ExamBoard(); bRunning = true; tbiSelected = null; }
public MainMenu() { InitializeComponent(); mClnt = new Client2(ClntBufHndl, ClntBufPrep, true); tPw = "dummypwd"; mCbMsg = new UICbMsg(); if (!System.IO.File.Exists("Room.txt") || !int.TryParse(System.IO.File.ReadAllText("Room.txt"), out uRId)) { uRId = 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); }
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(); }
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); }
public bool SrvrBufHndl(byte[] buf, out byte[] outMsg) { int offs = 0; NetCode c = (NetCode)BitConverter.ToInt32(buf, offs); offs += 4; int x; switch (c) { case NetCode.Srvr1Auth: outMsg = BitConverter.GetBytes((int)TxI.OP_AUTH_NOK); if (buf.Length - offs < 12) { break; } x = BitConverter.ToInt32(buf, offs); offs += 4; string pw = Encoding.ASCII.GetString(buf, offs, 8); offs += 8; foreach (ExamSlot sl in mBrd.vSl.Values) { if (sl.vRoom.ContainsKey(x)) { if (pw == sl.vRoom[x].tPw) { outMsg = BitConverter.GetBytes((int)TxI.OP_AUTH_OK); break; } } } break; case NetCode.Srvr1DatRetriving: if (buf.Length - offs < 4) { outMsg = null; break; } x = BitConverter.ToInt32(buf, offs); offs += 4; outMsg = mBrd.ToByteSl1(x); Dispatcher.InvokeAsync(() => { foreach (Op0SlotView vw in tbcSl.Items.OfType <Op0SlotView>()) { vw.UpRT1(x); } }); return(true); case NetCode.QuestRetrieving: if (buf.Length - offs < 4) { outMsg = null; break; } x = BitConverter.ToInt32(buf, offs); offs += 4; outMsg = mBrd.ToByteQPack(x); return(true); case NetCode.AnsKeyRetrieving: outMsg = mBrd.ToByteKey(); break; case NetCode.SrvrSubmitting: int rid; if (-1 < (rid = mBrd.ReadByteSl0(buf, ref offs))) { string emsg; if (mBrd.DBUpdateRs(rid, out emsg)) { mCbMsg += emsg; } else if (emsg == null) { mCbMsg += Txt.s._[(int)TxI.SRVR_DB_OK]; Dispatcher.InvokeAsync(() => { foreach (Op0SlotView vw in tbcSl.Items.OfType <Op0SlotView>()) { vw.UpdateRsView(rid); } }); } mBrd.DBUpStt(); } outMsg = BitConverter.GetBytes(1); break; default: outMsg = null; break; } return(false); }