Exemplo n.º 1
0
        // Sends log to server
        private static bool sendLogs()
        {
            // Create JSON String
            var jsonString = Json.BuildNamedArray(LogHeader, logList);

            // Create URL
            string url = buildUrlFromSettings(DataRequest);

            // Send request
            DebugOnly.Print("Sending logs to server...");
            Remote.Result result = Remote.Post(url, jsonString);

            if (result.Success)
            {
                DebugOnly.Print("Logs sent to server");

                // Log list sent to server successfully: delete loglist
                logList.Clear();
                CacheManager.Store(logList, CacheManager.LogsCacheFile);
            }
            else
            {
                DebugOnly.Print("ERROR: Log sending failed!");
            }

            // Return result of the operation
            return(result.Success);
        }
Exemplo n.º 2
0
        // Loads userlist from server
        private static bool requestUsers()
        {
            // Create URL
            string url = buildUrlFromSettings(DataRequest);

            // Send request
            DebugOnly.Print("Requesting user list to server...");
            Remote.Result result = Remote.Get(url);

            // Parse response
            if (result.Success)
            {
                ArrayList tempUserList = new ArrayList();

                if (Json.ParseNamedArray(UserHeader, result.Content, tempUserList, typeof(User)))
                {
                    // Copy content to main list
                    // NOTE: CopyFrom clears list automatically
                    userList.CopyFrom(tempUserList);

                    // Store cache copy
                    CacheManager.Store(userList, CacheManager.UsersCacheFile);

                    DebugOnly.Print(userList.Count + " users received from server");
                }
                else
                {
                    DebugOnly.Print("ERROR: User list request failed!");
                }
            }

            // Return result of the operation
            return(result.Success);
        }
Exemplo n.º 3
0
        // Get current time from server
        private static bool requestTime()
        {
            string url = buildUrlFromSettings(TimeRequest);

            Remote.Result result = Remote.Get(url);

            if (result.Success)
            {
                // Request current time
                DebugOnly.Print("Requesting current time to server...");
                DateTime serverDt = result.Content.ToDateTime();

                DateTime rtcDt = Utils.SafeRtc();

                if (!serverDt.WeakCompare(rtcDt))
                {
                    // Found time mismatch
                    DebugOnly.Print("ERROR: RTC/Server time mismatch! Server: " + serverDt.ToMyString() + ", RTC: " + rtcDt.ToMyString());
                    DebugOnly.Print("Setting RTC...");
                    Log log = new Log(Log.TypeInfo, "RTC/Server time mismatch! Server: " + serverDt.ToMyString() + ", RTC: " + rtcDt.ToMyString());
                    AddLog(log);

                    RealTimeClock.SetDateTime(serverDt);
                }
                else
                {
                    DebugOnly.Print("RTC already synced with server time!");
                }

                // RTC time is now valid
                timeChecked = true;

                return(true);
            }

            return(false);
        }