Esempio n. 1
0
        /// <summary>
        /// Measures the download speed
        /// </summary>
        /// <returns></returns>
        public bool runDownloadTrafficSensor(out double speed)
        {
            speed = -1;

            Boolean hasNewVersion = false;
            Utils util = new Utils();
            Stopwatch sw = new Stopwatch();
            String content = null;
            long elapsed = -1L;
            try
            {
                ConfigObj cfg = util.readConfig();

                sw.Start();
                content = util.getTextFromUrl(cfg.downloadUrl);
                sw.Stop();
                if (content.Length == 1048586)
                {
                    elapsed = sw.ElapsedMilliseconds;
                    long size = Encoding.ASCII.GetByteCount(content);
                    speed = size / sw.Elapsed.TotalSeconds / 1024;

                    util.getUrlStatusCode(cfg.remoteServer + "?action=DW&version=" + cfg.version + "&strId=" + cfg.strId + "&elapsed=" + elapsed);

                    // Check if the current service version is equals to server service version

                    String[] words = content.Split(' ');
                    String serverVersion = null;
                    if (words.Length > 0)
                    {
                        serverVersion = words[0];

                        if (!serverVersion.Equals(cfg.version))
                        {
                            hasNewVersion = true;
                        }
                    }
                }

            }
            catch (Exception e)
            {
                util.writeEventLog(e.Message);
                util.writeEventLog(e.StackTrace);
            }

            return hasNewVersion;
        }