Skip to content

Commit 89425fa

Browse files
committed
Add project counting for server
1 parent e799149 commit 89425fa

6 files changed

Lines changed: 41 additions & 22 deletions

File tree

app/Project Tracker Server/Project Tracker Server/Program.cs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,6 @@ private static void CopyData(string origin) {
9393
ClientDataManifest.Rootobject clientDataValues =
9494
JsonConvert.DeserializeObject<ClientDataManifest.Rootobject>(clientJson);
9595

96-
if (onlineUsers.Contains(clientDataValues.UserID)) {
97-
return;
98-
}
99-
onlineUsers.Add(clientDataValues.UserID);
100-
10196
string serverJson = File.ReadAllText(DATA_FILE);
10297
ServerDataManifest.Rootobject serverDataValues =
10398
JsonConvert.DeserializeObject<ServerDataManifest.Rootobject>(serverJson);
@@ -127,11 +122,9 @@ private static void CopyData(string origin) {
127122
serverDataValues.MonthlyOpens += clientDataValues.MonthlyOpens;
128123
serverDataValues.WeeklyOpens += clientDataValues.WeeklyOpens;
129124

130-
if (clientDataValues.IsOpen) {
125+
if (clientDataValues.IsOpen && !onlineUsers.Contains(clientDataValues.UserID)) {
131126
serverDataValues.CurrentlyOpenSessions++;
132-
}
133-
else {
134-
serverDataValues.CurrentlyOpenSessions--;
127+
onlineUsers.Add(clientDataValues.UserID);
135128
}
136129

137130
// Write new values

app/Project Tracker/Project Tracker/BackgroundProcesses.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ public static void DataReporting() {
121121
MethodInfo[] methods = type.GetMethods();
122122
// 0: SetActivity
123123
// 1: Refresh
124+
// 2: AddProject
124125

125126
methods[0].Invoke(instance, new object[] {true});
126127

@@ -130,5 +131,23 @@ public static void DataReporting() {
130131
methods[1].Invoke(instance, new object[] { 1 });
131132
}
132133
}
134+
135+
public static void ReportProject() {
136+
if (!File.Exists(SERVER_DLL_LOCATION)) {
137+
return;
138+
}
139+
140+
// Add Server Communication DLL
141+
Assembly assembly = Assembly.LoadFrom(SERVER_DLL_LOCATION);
142+
Type type = assembly.GetType("Server_Communication_DLL.SetData");
143+
object instance = Activator.CreateInstance(type);
144+
145+
MethodInfo[] methods = type.GetMethods();
146+
// 0: SetActivity
147+
// 1: Refresh
148+
// 2: AddProject
149+
150+
methods[2].Invoke(instance, new object[] { 1 });
151+
}
133152
}
134153
}

app/Project Tracker/Project Tracker/MainWindow.xaml.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,9 @@ private void DeleteProjectButtonPressed(object sender, MouseButtonEventArgs e) {
436436
settingsBorder.BeginAnimation(HeightProperty, animation);
437437
}));
438438

439+
addItemTextBox.Text = "Add something to the project";
440+
Keyboard.ClearFocus();
441+
439442
File.Delete(filesRead[selectedIndex - 1]);
440443

441444
selectedIndex = 0;
@@ -579,6 +582,13 @@ private void KeyPress(object sender, KeyEventArgs e) {
579582
else if (e.Key == Key.Return && addProjectTextBox.Text != "" &&
580583
addProjectTextBox.Text != "Create a new project" &&
581584
addProjectTextBox.IsFocused) {
585+
586+
Thread thread = new Thread(() => {
587+
BackgroundProcesses.ReportProject();
588+
});
589+
thread.Start();
590+
591+
582592
StringBuilder sb = new StringBuilder();
583593
StringWriter sw = new StringWriter(sb);
584594

app/Server Communication DLL/Server Communication DLL/Connections.cs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,6 @@
55
using System.Text;
66

77
namespace Server_Communication_DLL {
8-
/*
9-
* Ideas
10-
*
11-
* Pass a variable to the function that lets it know whether the program is open or closed rn
12-
* Track how many times they've logged on in the last month
13-
* Track how many times they've logged on in the last week
14-
* Track how many times they've logged on in the last year
15-
*
16-
*
17-
*/
188
public class Connections {
199
// WARNING: READONLY VALUES. IF YOU CHANGE THESE, CHANGE IN OTHER FILES TOO INCLUDING SERVER
2010
private static readonly int PORT = 2784;
@@ -29,7 +19,7 @@ public class Connections {
2919

3020
public static bool CreateConnection() {
3121
// Get the address to go to
32-
try {
22+
/*try {
3323
WebClient client = new WebClient();
3424
client.DownloadFile(new Uri(SERVER_ADDRESS_URL), SERVER_ADDRESS);
3525
@@ -38,7 +28,7 @@ public static bool CreateConnection() {
3828
}
3929
catch (WebException) {
4030
return false;
41-
}
31+
}*/
4232

4333
// Get IP Address and create endpoint
4434
IPAddress ip = IPAddress.Parse(SERVER_IP);

app/Server Communication DLL/Server Communication DLL/FileManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class FileManager {
2323
"Saturday: 0",
2424
"Sunday: 0"
2525
};
26-
private static long projectsCount = 0;
26+
public static long projectsCount = 0;
2727
public static string userID = "null";
2828
public static bool isOpen = true;
2929
public static long yearlyOpens = 0;

app/Server Communication DLL/Server Communication DLL/SetData.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,5 +109,12 @@ public static void Refresh(int a) {
109109
// throw new Exception("hiiii");
110110
// Add something here about how long the user has been active
111111
}
112+
113+
public static void AddProject(int a) {
114+
FileManager.PrepareDataTransfer();
115+
FileManager.projectsCount++;
116+
FileManager.SaveData();
117+
Connections.CreateConnection();
118+
}
112119
}
113120
}

0 commit comments

Comments
 (0)