Skip to content

create begin-exam #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions eManagerSystem/eManagerSystem/FormServer/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 30 additions & 10 deletions eManagerSystem/eManagerSystem/FormServer/Form1.cs
Original file line number Diff line number Diff line change
@@ -9,19 +9,40 @@
using System.Threading.Tasks;
using System.Windows.Forms;
using eManagerSystem.Application.Catalog.Server;
using eManagerSystem.Application.Catalog.Begin;
namespace FormServer
{
public partial class Form1 : Form
{
// ServerService server = new ServerService();
IServerService _server;


int counter = 0;
System.Timers.Timer countdown;

public Form1(IServerService server)
{


_server = server;
InitializeComponent();
CheckForIllegalCrossThreadCalls = false;


countdown = new System.Timers.Timer();
countdown.Elapsed += Countdown_Elapsed;

}

private void Countdown_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
counter -= 1;
int minute = counter / 60;
int second = counter % 60;
lblTimeLeft.Text = minute + " : " + second;
if (counter == 0)
{
countdown.Stop();
}
}

private void Form1_Load(object sender, EventArgs e)
@@ -31,8 +52,7 @@ private void Form1_Load(object sender, EventArgs e)

private void cmdBatDauLamBai_Click(object sender, EventArgs e)
{


counter = _server.BeginExam(txtThoiGianLamBai.Text,this.counter,countdown);
}
private OpenFileDialog openFileDialog1;
// them de thi
@@ -42,19 +62,19 @@ private void button3_Click(object sender, EventArgs e)
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
try
{

{
var PathName = openFileDialog1.FileName;
_server.Send(PathName);


}
catch
{
MessageBox.Show("Loi mo file");

MessageBox.Show("Loi mo file");
}
}
}
private void cmdChapNhan_Click(object sender, EventArgs e)
{
cmdBatDauLamBai.Visible = true;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace eManagerSystem.Application.Catalog.Server
{
public interface IServerService
{
void Connect();


void Connect();
void Send(string filePath);

void Receive(object obj);
@@ -18,7 +22,9 @@ public interface IServerService
byte[] GetFilePath(string filePath);

object Deserialize(byte[] data);
byte[] Serialize(object data);
object Data { get; set; }


int BeginExam(string inputTime, int counter, System.Timers.Timer countdown);
}
}
Original file line number Diff line number Diff line change
@@ -16,7 +16,8 @@ public class ServerService : IServerService
IPEndPoint IP;
Socket server;
List<Socket> clientList;

public object Data { get; set; }

public void Connect()
{
clientList = new List<Socket>();
@@ -103,13 +104,46 @@ public byte[] GetFilePath(string filePath)
return serverData;
}

public byte[] Serialize(object data)
{
MemoryStream stream = new MemoryStream();
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(stream, data);
return stream.ToArray();
}
public object Deserialize(byte[] data)
{
MemoryStream stream = new MemoryStream(data);
BinaryFormatter formatter = new BinaryFormatter();
formatter.Deserialize(stream);
return stream;
}

public int BeginExam(string inputTime, int counter, System.Timers.Timer countdown)
{


int minute = Convert.ToInt32(inputTime);
counter = minute * 60;
countdown.Enabled = true;

this.Data = minute;
Byte[] buffer = Serialize(this.Data);

foreach (Socket client in clientList)
{
try
{
client.Send(buffer);
}
catch (Exception ex)
{
clientList.Remove(client);
client.Close();
}
}
return counter;
}


}
}
Original file line number Diff line number Diff line change
@@ -41,6 +41,8 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Catalog\Begin\BeginExamService.cs" />
<Compile Include="Catalog\Begin\IBeginExamServie.cs" />
<Compile Include="Catalog\Examination\ExaminationService.cs" />
<Compile Include="Catalog\Examination\IExaminationService.cs" />
<Compile Include="Catalog\Message\IMessageService.cs" />