/// <summary> /// Gets the ID from the data transmitted. /// </summary> /// <param name="data">The data that was transmitted.</param> /// <returns>Returns the username.</returns> private static string GetUserID(string data) { string json = data; ClientDataManifest.Rootobject dataValues = JsonConvert.DeserializeObject <ClientDataManifest.Rootobject>(json); return(dataValues.UserID); }
private static void CopyData(string origin) { string clientJson = File.ReadAllText(origin); ClientDataManifest.Rootobject clientDataValues = JsonConvert.DeserializeObject <ClientDataManifest.Rootobject>(clientJson); string serverJson = File.ReadAllText(DATA_FILE); ServerDataManifest.Rootobject serverDataValues = JsonConvert.DeserializeObject <ServerDataManifest.Rootobject>(serverJson); serverDataValues.AmountOpened += clientDataValues.AmountOpened; for (int i = 0; i < serverDataValues.DaysOpened.Length; i++) { clientDataValues.DaysOpened[i] = Regex.Replace(clientDataValues.DaysOpened[i], @"\s+", ""); string[] clientSides = clientDataValues.DaysOpened[i].Split(':'); long clientValue = Int64.Parse(clientSides[1]); serverDataValues.DaysOpened[i] = Regex.Replace(serverDataValues.DaysOpened[i], @"\s+", ""); string[] serverSides = serverDataValues.DaysOpened[i].Split(':'); long serverValue = Int64.Parse(serverSides[1]); serverValue += clientValue; string rebuiltString = serverSides[0] + ": " + serverValue; serverDataValues.DaysOpened[i] = rebuiltString; } serverDataValues.ProjectsCount += clientDataValues.ProjectsCount; serverDataValues.YearlyOpens += clientDataValues.YearlyOpens; serverDataValues.MonthlyOpens += clientDataValues.MonthlyOpens; serverDataValues.WeeklyOpens += clientDataValues.WeeklyOpens; if (clientDataValues.IsOpen && !onlineUsers.Contains(clientDataValues.UserID)) { serverDataValues.CurrentlyOpenSessions++; onlineUsers.Add(clientDataValues.UserID); } // Write new values StringBuilder sb = new StringBuilder(); StringWriter sw = new StringWriter(sb); using (JsonWriter js = new JsonTextWriter(sw)) { js.Formatting = Formatting.Indented; js.WriteStartObject(); js.WritePropertyName("AmountOpened"); js.WriteValue(serverDataValues.AmountOpened); js.WritePropertyName("DaysOpened"); js.WriteStartArray(); foreach (string day in serverDataValues.DaysOpened) { js.WriteValue(day); } js.WriteEnd(); js.WritePropertyName("ProjectsCount"); js.WriteValue(serverDataValues.ProjectsCount); js.WritePropertyName("YearlyOpens"); js.WriteValue(serverDataValues.YearlyOpens); js.WritePropertyName("MonthlyOpens"); js.WriteValue(serverDataValues.MonthlyOpens); js.WritePropertyName("WeeklyOpens"); js.WriteValue(serverDataValues.WeeklyOpens); js.WritePropertyName("CurrentlyOpenSessions"); js.WriteValue(serverDataValues.CurrentlyOpenSessions); js.WriteEndObject(); } File.WriteAllText(DATA_FILE, sw.ToString()); sb.Clear(); sw.Close(); }