当前位置: 首页>>代码示例>>C#>>正文


C# Utils.readConfig方法代码示例

本文整理汇总了C#中System.Utils.readConfig方法的典型用法代码示例。如果您正苦于以下问题:C# Utils.readConfig方法的具体用法?C# Utils.readConfig怎么用?C# Utils.readConfig使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Utils的用法示例。


在下文中一共展示了Utils.readConfig方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: runDownloadTrafficSensor

        /// <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;
        }
开发者ID:damico,项目名称:open-audit,代码行数:52,代码来源:ServiceThreadImpl.cs

示例2: runHeartBeat

        /// <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);
            }
        }
开发者ID:damico,项目名称:open-audit,代码行数:59,代码来源:ServiceThreadImpl.cs

示例3: runUploadTrafficSensor

        /// <summary>
        /// Measures the upload speed
        /// </summary>
        public void runUploadTrafficSensor(long uploadSize, out double speed)
        {
            speed = -1;
            Stopwatch sw = new Stopwatch();
            Utils util = new Utils();
            String content = null;
            byte[] result = null;
            long elapsed = -1L;
            try
            {

                ConfigObj cfg = util.readConfig();
                System.Net.WebClient Client = new System.Net.WebClient();
                Client.Headers.Add("Content-Type", "binary/octet-stream");

                byte[] updata = new byte[uploadSize];
                Random rng = new Random();
                for (int i = 0; i < uploadSize; i++)
                {
                    updata[i] = (byte)rng.Next(0, 255);
                }

                sw.Start();
                result = Client.UploadData(cfg.uploadUrl, "POST", updata);
                sw.Stop();

                elapsed = sw.ElapsedMilliseconds;
                speed = uploadSize / sw.Elapsed.TotalSeconds / 1024.0;

                content = System.Text.Encoding.UTF8.GetString(result, 0, result.Length);
                if (content.Equals("OK"))
                {
                    util.getUrlStatusCode(cfg.remoteServer + "?action=UP&version=" + cfg.version + "&strId=" + cfg.strId + "&elapsed=" + elapsed);
                }

            }
            catch (Exception e)
            {
                util.writeEventLog(e.Message);
                util.writeEventLog(e.StackTrace);
            }
        }
开发者ID:damico,项目名称:open-audit,代码行数:45,代码来源:ServiceThreadImpl.cs


注:本文中的System.Utils.readConfig方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。