-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSource.cpp
More file actions
166 lines (148 loc) · 4.54 KB
/
Source.cpp
File metadata and controls
166 lines (148 loc) · 4.54 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#include "Grading.h"
#include "MatrixMult.h"
using namespace std;
using namespace tinyxml2;
using namespace boost::filesystem;
// Mỗi khi file upload lên thì thêm vào File "Task.xml" - danh sách các folder có sự thay đổi
// Nếu queue trống thì lại đọc lại file Task.xml để nhận thêm task và xóa các task đó đi trong file "Task.xml"
// Khi upload thì file sẽ được lưu vào "Trash"
int main()
{
//MatrixMult::makeTestCase();
Grading* gr = new Grading();
gr->process();
system("pause");
return 0;
}
void readTask()
{
/*
string copyTaskPath = serverPath + "\\TaskCopy.xml";
bool error = false;
boost::filesystem::path src(taskPath);
boost::filesystem::path des(copyTaskPath);
if (!boost::filesystem::exists(src))
return;
while (!boost::filesystem::exists(des))
{
try
{
boost::system::error_code err;
boost::filesystem::rename(src, des, err);
cout << err.message() << endl;
}
catch (...)
{ }
}
tinyxml2::XMLDocument doc;
doc.LoadFile(copyTaskPath.c_str());
XMLElement* ele = nullptr;
try
{
ele = doc.LastChildElement("ListUpload")->FirstChildElement("Upload");
while (ele != nullptr)
{
string folder = ele->FirstChildElement("FolderName")->GetText();
string id = ele->FirstChildElement("ID")->GetText();
int submitID = stoi(ele->FirstChildElement("SubmitID")->GetText());
string time = ele->FirstChildElement("Time")->GetText();
ele = ele->NextSiblingElement("Upload");
submitList.push(new Submit(id, submitID, time, folder));
}
boost::filesystem::remove(copyTaskPath);
}
catch (exception ex)
{
return;
}
catch (const filesystem_error& ex)
{
cout << ex.what() << endl;
}
*/
boost::filesystem::path unprocessPath(unprocess);
boost::filesystem::directory_iterator it(unprocessPath), eod;
BOOST_FOREACH(boost::filesystem::path const &p, std::make_pair(it, eod))
{
if (is_regular_file(p))
{
if (p.extension().string() == ".xml")
{
cout << p.string() << endl;
}
}
}
}
void processFolder(Submit* s)
{
/*
boost::filesystem::path copyPath(serverPath + "\\Unprocess\\" + s->folderName);
boost::filesystem::directory_iterator it(copyPath), eod;
string targetPathStr = serverPath + "\\_" + s->userID + "\\Sub" + to_string(s->submitID + 1);
boost::filesystem::path targetPath(targetPathStr);
if (!boost::filesystem::exists(targetPath))
boost::filesystem::create_directories(targetPath);
string xmlFile = targetPathStr + "\\Pro.xml";
std::ofstream fs(xmlFile);
fs << "<?xml version =\"1.0\" encoding =\"UTF-8\"?>\n<ListFile>\n</ListFile>";
fs.close();
tinyxml2::XMLDocument doc;
doc.LoadFile(xmlFile.c_str());
XMLElement* rootEle = doc.FirstChildElement("ListFile");
BOOST_FOREACH(boost::filesystem::path const &p, std::make_pair(it, eod))
{
if (is_regular_file(p))
{
boost::filesystem::path newFilePath(targetPath.string() + "\\" + p.filename().string());
boost::filesystem::copy_file(p, newFilePath);
XMLElement* newEle = doc.NewElement("File");
string fileName = p.filename().string();
newEle->SetText(fileName.c_str());
rootEle->InsertEndChild(newEle);
}
}
doc.SaveFile(xmlFile.c_str());
boost::filesystem::remove_all(serverPath + "\\Unprocess\\" + s->folderName);
compileAndRun(s);
//boost::filesystem::remove(serverPath + "\\Unprocess\\" + s->folderName);
*/
}
void processing()
{
}
string getSubmitPath(Submit s)
{
return serverPath + "\\_" + s.getUserID() + "\\Sub" + to_string(s.getSubmitID() + 1);
}
string getCompileStr(Submit s, string compileStd)
{
/*
string submitPath = getSubmitPath(s);
string compileStr = "g++ " + compileStd + " ";
string proFile = submitPath + "\\Pro.xml";
tinyxml2::XMLDocument doc;
doc.LoadFile(proFile.c_str());
tinyxml2::XMLElement* ele = doc.FirstChildElement("ListFile")->FirstChildElement("File");
while (ele != nullptr)
{
compileStr += submitPath + "\\" + ele->GetText();
ele = ele->NextSiblingElement("File");
}
compileStr += " -o " + submitPath + "\\program.exe";
return compileStr;
*/
return "";
}
void compileAndRun(Submit s)
{
/*
string submitPath = serverPath + "\\_" + s->userID + "\\Sub" + to_string(s->submitID + 1);
string compileStr = getCompileStr(s, "-std=c++11");
string compile = "set PATH=%PATH%;" + compileToolPath + " && " + compileStr;
system(compile.c_str());
for (int i = 0; i < N_TESTCASE; ++i)
{
//string testFile = testCaseFilePath + "\\" + "Test" + to_string(i) + ".txt";
}
*/
}