예제 #1
0
        /// <summary>
        /// Sends a heart-beat to the server, while also checking for updates
        /// </summary>
        public void runHeartBeat()
        {
            Boolean hasNewVersion = false;
            Constants.STATIC_RUN_COUNTER++;
            Utils util = new Utils();
            try
            {
                ConfigObj cfg = util.readConfig();
                if (cfg != null && cfg.remoteTarget != null && cfg.remoteServer != null && cfg.strId != null)
                {
                    String data = util.getUrlStatusCode(cfg.remoteTarget);

                    HeartbeatData h = new HeartbeatData();

                    h.downloadSpeed = WebUtil.DownloadSpeed(false);
                    runUploadTrafficSensor(1024, out h.uploadSpeed);
                    h.assVersion = util.getAssemblyVersion();
                    h.errorCounter = Constants.STATIC_ERROR_COUNTER;
                    h.runCounter = Constants.STATIC_RUN_COUNTER;
                    h.strId = cfg.strId;
                    h.version = cfg.version;
                    string json = JsonConvert.SerializeObject(h);

                    String link = cfg.remoteServer + "?action=ACK&data=" + data + "&version=" + util.getAssemblyVersion() + "&strId=" + cfg.strId + "&errorcounter=" + Constants.STATIC_ERROR_COUNTER + "&runcounter=" + Constants.STATIC_RUN_COUNTER;
                    link = link.Trim();
                    String code = util.getUrlStatusCode(link);
                    util.writeToLogFile(link);
                    if (code != null)
                    {
                        if (!code.Equals("OK"))
                        {
                            Constants.STATIC_ERROR_COUNTER++;
                        }
                        else
                        {
                            hasNewVersion = runDownloadTrafficSensor();
                            runUploadTrafficSensor();
                            if (hasNewVersion)
                            {
                                updateService();
                            }
                        }
                    }
                    else
                    {
                        Constants.STATIC_ERROR_COUNTER++;
                    }
                }
            }
            catch (Exception e)
            {
                Constants.STATIC_ERROR_COUNTER++;
                util.writeEventLog(e.Message);
                util.writeEventLog(e.StackTrace);
            }
        }