Remove subject IDs and improve request handling
This commit is contained in:
@@ -16,12 +16,12 @@ namespace StudySystemClient {
|
||||
scrolled_window.add_css_class("card-container");
|
||||
|
||||
var activities = new Activity[] {
|
||||
{ 2, "Linguistics", ActivityType.EXERCISES },
|
||||
{ 1, "Cybernetics", ActivityType.EXERCISES },
|
||||
{ 2, "Linguistics", ActivityType.READING },
|
||||
{ 0, "Physics", ActivityType.READING },
|
||||
{ 1, "Cybernetics", ActivityType.READING },
|
||||
{ 0, "Physics", ActivityType.EXERCISES },
|
||||
{ "Linguistics", ActivityType.EXERCISES },
|
||||
{ "Cybernetics", ActivityType.EXERCISES },
|
||||
{ "Linguistics", ActivityType.READING },
|
||||
{ "Physics", ActivityType.READING },
|
||||
{ "Cybernetics", ActivityType.READING },
|
||||
{ "Physics", ActivityType.EXERCISES },
|
||||
};
|
||||
foreach (var activity in activities) {
|
||||
var card = new ActivityCard(client, activity);
|
||||
@@ -42,7 +42,7 @@ namespace StudySystemClient {
|
||||
var text = new Gtk.Box(Gtk.Orientation.VERTICAL, 6);
|
||||
text.hexpand = true;
|
||||
|
||||
var subject = new Gtk.Label(activity.subject_name);
|
||||
var subject = new Gtk.Label(activity.subject);
|
||||
subject.halign = Gtk.Align.START;
|
||||
subject.add_css_class("activity-subject");
|
||||
text.append(subject);
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
namespace StudySystemClient {
|
||||
public struct Activity {
|
||||
public int subject_id;
|
||||
public string subject_name;
|
||||
public string subject;
|
||||
public ActivityType type;
|
||||
public double priority;
|
||||
}
|
||||
|
||||
public enum ActivityType {
|
||||
EXERCISES,
|
||||
READING;
|
||||
READING = 0,
|
||||
EXERCISES = 1;
|
||||
|
||||
public string to_string() {
|
||||
switch (this) {
|
||||
|
||||
@@ -41,11 +41,11 @@ namespace StudySystemClient {
|
||||
}
|
||||
}
|
||||
|
||||
public async void log_session(int subject_id, ActivityType type,
|
||||
public async void log_session(string subject, ActivityType type,
|
||||
int minutes) throws ClientError {
|
||||
var timestamp = new DateTime.now_utc().to_unix();
|
||||
var request = new Request.LogSession(subject_id, type,
|
||||
timestamp, minutes);
|
||||
var request
|
||||
= new Request.LogSession(subject, type, timestamp, minutes);
|
||||
var response = yield connection.send(request);
|
||||
if (response is Response.Ack) {
|
||||
return;
|
||||
|
||||
@@ -39,11 +39,11 @@ namespace StudySystemClient.Request {
|
||||
}
|
||||
|
||||
public class LogSession : Body {
|
||||
public LogSession(int subject_id, ActivityType type,
|
||||
public LogSession(string subject, ActivityType type,
|
||||
int64 timestamp, int minutes)
|
||||
{
|
||||
var fields = new Der.Datum[] {
|
||||
new Der.Integer(subject_id),
|
||||
new Der.Utf8String(subject),
|
||||
new Der.Enumerated((int)type),
|
||||
new Der.Integer(timestamp),
|
||||
new Der.Integer(minutes),
|
||||
|
||||
@@ -127,20 +127,17 @@ namespace StudySystemClient.Response {
|
||||
throws DecodeError {
|
||||
if (datum is Der.Sequence) {
|
||||
var fields = datum.value;
|
||||
if (fields.length < 4) {
|
||||
if (fields.length < 3) {
|
||||
throw new DecodeError.INVALID_BODY(
|
||||
"Too few fields in Activity: %u (expected 4)",
|
||||
"Too few fields in Activity: %u (expected 3)",
|
||||
fields.length);
|
||||
}
|
||||
var subject_id = get_int("Activity.subjectId", fields[0]);
|
||||
var subject_name
|
||||
= get_string("Activity.subjectName", fields[1]);
|
||||
var subject = get_string("Activity.subject", fields[0]);
|
||||
var activity_type
|
||||
= get_activity_type("Activity.type", fields[2]);
|
||||
var int_priority = get_int("Activity.priority", fields[3]);
|
||||
var priority = (double)int_priority / 100.0;
|
||||
return { subject_id, subject_name, activity_type, priority };
|
||||
|
||||
= get_activity_type("Activity.type", fields[1]);
|
||||
var priority_int = get_int("Activity.priority", fields[2]);
|
||||
var priority = (double)priority_int / 100.0;
|
||||
return { subject, activity_type, priority };
|
||||
} else {
|
||||
throw new DecodeError.INVALID_BODY(
|
||||
"Activity was not a SEQUENCE");
|
||||
|
||||
@@ -65,7 +65,7 @@ namespace StudySystemClient {
|
||||
public class SessionFactory {
|
||||
private const string CA_FILENAME = "/ca.pem";
|
||||
private const string CERT_FILENAME = "/client.pem";
|
||||
private const uint TIMEOUT_S = 1;
|
||||
private const uint TIMEOUT_S = 5;
|
||||
|
||||
private InetSocketAddress host;
|
||||
private TlsCertificate cert;
|
||||
|
||||
Reference in New Issue
Block a user