Debug() public static method

public static Debug ( string message ) : void
message string
return void
コード例 #1
0
ファイル: Consensus.cs プロジェクト: yuop2002cn/IOBft
        public async void Run()
        {
            await Task.Delay(2000);

            long.TryParse(levelDBStore.Get("UndoHeight"), out transferHeight);

            Log.Debug($"Consensus.Run at height {transferHeight}");

            // 恢复到停机前的高度
            ApplyBlockChain();

            // 算力统计
            calculatePower.Clear();
            for (long ii = Math.Max(1, transferHeight - calculatePower.statistic); ii <= transferHeight; ii++)
            {
                calculatePower.Insert(BlockChainHelper.GetMcBlock(ii));
            }

            int blockIndex = 0;

            while (true)
            {
                try
                {
                    if (newBlocks.Count > 0)
                    {
                        for (blockIndex = blockIndex % newBlocks.Count; blockIndex < newBlocks.Count; blockIndex++)
                        {
                            if (newBlocks[blockIndex] == null)
                            {
                                continue;
                            }
                            var   ipEndPoint = newBlocks[blockIndex].ipEndPoint;
                            Block otherMcBlk = JsonHelper.FromJson <Block>(newBlocks[blockIndex].block);
                            if (Check(otherMcBlk))
                            {
                                if (await SyncHeight(otherMcBlk, newBlocks[blockIndex].ipEndPoint))
                                {
                                    newBlocks.RemoveAll((x) => { return(x.ipEndPoint == ipEndPoint); });
                                    break;
                                }
                                //if (await SyncHeight(otherMcBlk, newBlocks[ii].ipEndPoint))
                                ApplyBlockChain();
                            }
                            //break;
                        }
                    }

                    ApplyBlockChain();

                    lock (this)
                    {
                        runAction?.Invoke();
                        runAction = null;
                    }

                    if (bifurcatedReportTime.IsPassOnce() && bifurcatedReport != "")
                    {
                        Log.Info(bifurcatedReport);
                        bifurcatedReport = "";
                    }

                    await Task.Delay(1000);
                }
                catch (Exception e)
                {
                    newBlocks.Clear();
                    Log.Error(e);
                    await Task.Delay(1000);
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// 返回是否需要下载
        /// </summary>
        /// <returns></returns>
        public async Task<bool> LoadInfo()
        {
            isNetNotReach = false;
            string versionUploadSelfResUrl = GlobalConfigComponent.Instance.GlobalProto.VersionUploadSelfResUrl;
            Log.Debug($"versionUploadSelfResUrl:{versionUploadSelfResUrl}");
            if (ETModel.Define.isInnetNet)
            {
                versionUploadSelfResUrl = GlobalConfigComponent.Instance.GlobalProto.VersionUploadSelfResUrl_InnerNet;
                Log.Debug($"VersionUploadSelfResUrl_InnerNet:{versionUploadSelfResUrl}");
            }
            UnityWebRequestAsync webRequestSelfVersionAsync = ComponentFactory.Create<UnityWebRequestAsync>();
            UnityWebRequestAsync webRequestAsync = ComponentFactory.Create<UnityWebRequestAsync>();
            string versionText = string.Empty;
            try
            {
                //下载外层资源文件夹版本,即父目录
                var webRequestSelfResVersionTask = webRequestSelfVersionAsync.DownloadAsync(versionUploadSelfResUrl);
                await webRequestSelfResVersionTask;
                ZLog.Info($"webRequestSelfResVersionText:{webRequestSelfVersionAsync.Request.downloadHandler.text}");
                ETModel.Define.ParentResABDirectory = webRequestSelfVersionAsync.Request.downloadHandler.text;
                ZLog.Info($"ParentDirectory:{ETModel.Define.ParentResABDirectory}");
                webRequestSelfVersionAsync.Dispose();
                //下载bundle流程
                string versionUrl = GlobalConfigComponent.Instance.GlobalProto.GetUrl() + "StreamingAssets/" + "Version.txt";
                if (ETModel.Define.IsABNotFromServer)
                {
                    versionUrl = GetUrlWithPlatform(ETModel.Define.SelfResourceServerIpAndPort + "/") + "StreamingAssets/" + "Version.txt";
                }
                Log.Debug($"versionUrl:{versionUrl}");
                var webRequestTask = webRequestAsync.DownloadAsync(versionUrl);
                await webRequestTask;
                versionText = webRequestAsync.Request.downloadHandler.text;
                webRequestSelfVersionAsync.Dispose();
            }
            catch (Exception e)
            {
                if (e.Message.Contains("request error"))
                {
                    webRequestSelfVersionAsync.Dispose();
                    webRequestAsync.Dispose();
                    ZLog.Info("load Version err", e.Message);
                    Define.isUseStreamingAssetRes = true;
                    OnFileServerNotReach(e.Message);
                    return false;
                }
            }
            ZLog.Info($"versionText:{versionText}");
            if (!versionText.StartsWith("{"))
            {
                this.VersionConfig = null;
                return false;
            }
            this.VersionConfig = JsonHelper.FromJson<VersionConfig>(versionText);
            //Log.Debug(JsonHelper.ToJson(this.VersionConfig));


            if (isNetNotReach)//文件服务器没开启
            {
                //var timeTask = DelayFrame();
                //this.TagDownloadFinish();
                //await timeTask;
                return false;
            }
            else //成功的事情
            {
                VersionConfig localVersionConfig;
                // 对比本地的Version.txt
                string versionPath = Path.Combine(PathHelper.AppHotfixResPath, "Version.txt");
                if (File.Exists(versionPath))
                {
                    localVersionConfig = JsonHelper.FromJson<VersionConfig>(File.ReadAllText(versionPath));
                }
                else
                {
                    versionPath = Path.Combine(PathHelper.AppResPath4Web, "Version.txt");

                    using (UnityWebRequestAsync request = ComponentFactory.Create<UnityWebRequestAsync>())
                    {
                        try
                        {
                            await request.DownloadAsync(versionPath);
                            localVersionConfig = JsonHelper.FromJson<VersionConfig>(request.Request.downloadHandler.text);
                        }
                        catch (System.Exception e)
                        {
                            Log.Debug(e.ToString());
                            localVersionConfig = null;
                        }
                    }
                }

                if (localVersionConfig != null)
                {
                    // 先删除服务器端没有的ab
                    foreach (FileVersionInfo fileVersionInfo in localVersionConfig.FileInfoDict.Values)
                    {
                        if (this.VersionConfig.FileInfoDict.ContainsKey(fileVersionInfo.File))
                        {
                            continue;
                        }
                        string abPath = Path.Combine(PathHelper.AppHotfixResPath, fileVersionInfo.File);

                        if(File.Exists(abPath))File.Delete(abPath);
                    }
                }


                // 再下载
                foreach (FileVersionInfo fileVersionInfo in this.VersionConfig.FileInfoDict.Values)
                {
                    FileVersionInfo localVersionInfo;
                    if (localVersionConfig != null && localVersionConfig.FileInfoDict.TryGetValue(fileVersionInfo.File, out localVersionInfo))
                    {
                        if (fileVersionInfo.MD5 == localVersionInfo.MD5)
                        {
                            continue;
                        }
                    }

                    if (fileVersionInfo.File == "Version.txt")
                    {
                        continue;
                    }

                    this.bundles.Enqueue(fileVersionInfo.File);
                    this.TotalSize += fileVersionInfo.Size;
                }
                DownloadInfo.TotalSize = TotalSize;

                //if (this.bundles.Count == 0)
                //{
                //	return;
                //}

                //Log.Debug($"need download bundles: {this.bundles.ToList().ListToString()}");
                return true;
                //await Down();
            }
        }