forked from lmsweb/LMSweb
-
Notifications
You must be signed in to change notification settings - Fork 2
/
CodeServiceHub.cs
81 lines (74 loc) · 2.97 KB
/
CodeServiceHub.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using LMSweb.Models;
using LMSweb.Service;
using LMSweb.ViewModel;
using Microsoft.AspNet.SignalR;
using System;
using System.Collections.Generic;
using System.Data.Entity.Infrastructure;
using System.Linq;
using System.Threading.Tasks;
using System.Web;
using System.Web.Configuration;
namespace LMSweb
{
public class CodeServiceHub : Hub
{
private LMSmodel db = new LMSmodel();
private TextIO textIO = new TextIO();
public void editCode(string gid, string content, int line, int ch)
{
//Clients.All.broadcastCode(content, line, ch);
Clients.Group(gid).broadcastCode(content, line, ch);
}
public void saveCode(StudentCodingViewModel viewModel)
{
StudentCode model_insert = null;
string FileName = viewModel.CID + " " + viewModel.MID + " " + viewModel.GID;
StudentCode model_update = db.StudentCodes.Find(viewModel.CID, viewModel.MID, viewModel.GID);
if(model_update == null)
{
model_insert = new StudentCode();
model_insert.CID = viewModel.CID;
model_insert.MID = viewModel.MID;
model_insert.GID = viewModel.GID;
model_insert.IsEdit = viewModel.IsEdit;
//model_insert.course = db.Courses.Find(viewModel.CourseID);
//model_insert.mission = db.Missions.Find(viewModel.MID);
//model_insert.group = db.Groups.Find(viewModel.GID);
model_insert.CodePath = FileName;
db.StudentCodes.Add(model_insert);
}
else
{
model_update.CID = viewModel.CID;
model_update.MID = viewModel.MID;
model_update.GID = viewModel.GID;
model_update.IsEdit = viewModel.IsEdit;
//model_update.course = db.Courses.Find(viewModel.CourseID);
//model_update.mission = db.Missions.Find(viewModel.MID);
//model_update.group = db.Groups.Find(viewModel.GID);
model_update.CodePath = FileName;
}
db.SaveChanges();
textIO.SaveFile(FileName, viewModel.CodeContent);
}
public async Task readCode(string cid, string mid, string gid)
{
string discPath = WebConfigurationManager.AppSettings["CodePath"];
string PathRoot = HttpContext.Current.Server.MapPath(discPath);
string FileName = cid + " " + mid + " " + gid;
string content = textIO.readCodeText(PathRoot + FileName + ".txt");
await joinGroup(gid);
//Clients.All.broadcastCode(content, 0, 0);
Clients.Group(gid).broadcastCode(content, 0, 0);
}
public Task joinGroup(string gid)
{
return Groups.Add(Context.ConnectionId, gid);
}
public Task removeGroup(string gid)
{
return Groups.Remove(Context.ConnectionId, gid);
}
}
}