/// <summary> /// Writes the DebugRecord to informational buffers. /// </summary> /// <param name="record">DebugRecord</param> internal void WriteDebugInfoBuffers(DebugRecord record) { if (_informationalBuffers != null) { _informationalBuffers.AddDebug(record); } }
/// <summary> /// Handle the object obtained from an ObjectStream's reader /// based on its type. /// </summary> /// <param name="cmdlet">Cmdlet to use for outputting the object.</param> /// <param name="instanceId"></param> /// <param name="overrideInquire">Suppresses prompt on messages with Inquire preference. /// Needed for Receive-Job</param> internal void WriteStreamObject(Cmdlet cmdlet, Guid instanceId, bool overrideInquire = false) { switch (ObjectType) { case PSStreamObjectType.Output: { if (instanceId != Guid.Empty) { PSObject o = Value as PSObject; if (o != null) { AddSourceJobNoteProperty(o, instanceId); } } cmdlet.WriteObject(Value); } break; case PSStreamObjectType.Error: { ErrorRecord errorRecord = (ErrorRecord)this.Value; RemotingErrorRecord remoteErrorRecord = errorRecord as RemotingErrorRecord; if (remoteErrorRecord == null) { // if we get a base ErrorRecord object, check if the computerName is // populated in the RecommendedAction field if (errorRecord.ErrorDetails != null && !string.IsNullOrEmpty(errorRecord.ErrorDetails.RecommendedAction)) { string computerName; Guid jobInstanceId; GetIdentifierInfo(errorRecord.ErrorDetails.RecommendedAction, out jobInstanceId, out computerName); errorRecord = new RemotingErrorRecord(errorRecord, new OriginInfo(computerName, Guid.Empty, jobInstanceId)); } } else { errorRecord = remoteErrorRecord; } errorRecord.PreserveInvocationInfoOnce = true; MshCommandRuntime mshCommandRuntime = cmdlet.CommandRuntime as MshCommandRuntime; if (mshCommandRuntime != null) { mshCommandRuntime.WriteError(errorRecord, overrideInquire); } } break; case PSStreamObjectType.Warning: { string warning = (string)Value; WarningRecord warningRecord = new WarningRecord(warning); MshCommandRuntime mshCommandRuntime = cmdlet.CommandRuntime as MshCommandRuntime; if (mshCommandRuntime != null) { mshCommandRuntime.WriteWarning(warningRecord, overrideInquire); } } break; case PSStreamObjectType.Verbose: { string verbose = (string)Value; VerboseRecord verboseRecord = new VerboseRecord(verbose); MshCommandRuntime mshCommandRuntime = cmdlet.CommandRuntime as MshCommandRuntime; if (mshCommandRuntime != null) { mshCommandRuntime.WriteVerbose(verboseRecord, overrideInquire); } } break; case PSStreamObjectType.Progress: { ProgressRecord progressRecord = (ProgressRecord)Value; RemotingProgressRecord remotingProgressRecord = progressRecord as RemotingProgressRecord; if (remotingProgressRecord == null) { Guid jobInstanceId; string computerName; GetIdentifierInfo(progressRecord.CurrentOperation, out jobInstanceId, out computerName); OriginInfo info = new OriginInfo(computerName, Guid.Empty, jobInstanceId); progressRecord = new RemotingProgressRecord(progressRecord, info); } else { progressRecord = remotingProgressRecord; } MshCommandRuntime mshCommandRuntime = cmdlet.CommandRuntime as MshCommandRuntime; if (mshCommandRuntime != null) { mshCommandRuntime.WriteProgress(progressRecord, overrideInquire); } } break; case PSStreamObjectType.Debug: { string debug = (string)Value; DebugRecord debugRecord = new DebugRecord(debug); MshCommandRuntime mshCommandRuntime = cmdlet.CommandRuntime as MshCommandRuntime; if (mshCommandRuntime != null) { mshCommandRuntime.WriteDebug(debugRecord, overrideInquire); } } break; case PSStreamObjectType.Information: { InformationRecord informationRecord = (InformationRecord)this.Value; RemotingInformationRecord remoteInformationRecord = informationRecord as RemotingInformationRecord; if (remoteInformationRecord == null) { // if we get a base InformationRecord object, check if the computerName is // populated in the Source field if (!string.IsNullOrEmpty(informationRecord.Source)) { string computerName; Guid jobInstanceId; GetIdentifierInfo(informationRecord.Source, out jobInstanceId, out computerName); informationRecord = new RemotingInformationRecord(informationRecord, new OriginInfo(computerName, Guid.Empty, jobInstanceId)); } } else { informationRecord = remoteInformationRecord; } MshCommandRuntime mshCommandRuntime = cmdlet.CommandRuntime as MshCommandRuntime; if (mshCommandRuntime != null) { mshCommandRuntime.WriteInformation(informationRecord, overrideInquire); } } break; case PSStreamObjectType.WarningRecord: case PSStreamObjectType.MethodExecutor: case PSStreamObjectType.BlockingError: case PSStreamObjectType.ShouldMethod: { WriteStreamObject(cmdlet, overrideInquire); } break; } }
/// <summary> /// /// </summary> internal void WriteDebugRecord(DebugRecord record) { WriteDebugInfoBuffers(record); if (_externalUI == null) { return; } _externalUI.WriteDebugLine(record.Message); }
/// <summary> /// Handle the object obtained from an ObjectStream's reader /// based on its type. /// </summary> /// <param name="cmdlet">Cmdlet to use for outputting the object.</param> /// <param name="overrideInquire">Used by Receive-Job to suppress inquire preference.</param> public void WriteStreamObject(Cmdlet cmdlet, bool overrideInquire = false) { if (cmdlet != null) { switch (this.ObjectType) { case PSStreamObjectType.Output: { cmdlet.WriteObject(this.Value); } break; case PSStreamObjectType.Error: { ErrorRecord errorRecord = (ErrorRecord)this.Value; errorRecord.PreserveInvocationInfoOnce = true; MshCommandRuntime mshCommandRuntime = cmdlet.CommandRuntime as MshCommandRuntime; if (mshCommandRuntime != null) { mshCommandRuntime.WriteError(errorRecord, overrideInquire); } } break; case PSStreamObjectType.Debug: { string debug = (string)Value; DebugRecord debugRecord = new DebugRecord(debug); MshCommandRuntime mshCommandRuntime = cmdlet.CommandRuntime as MshCommandRuntime; if (mshCommandRuntime != null) { mshCommandRuntime.WriteDebug(debugRecord, overrideInquire); } } break; case PSStreamObjectType.Warning: { string warning = (string)Value; WarningRecord warningRecord = new WarningRecord(warning); MshCommandRuntime mshCommandRuntime = cmdlet.CommandRuntime as MshCommandRuntime; if (mshCommandRuntime != null) { mshCommandRuntime.WriteWarning(warningRecord, overrideInquire); } } break; case PSStreamObjectType.Verbose: { string verbose = (string)Value; VerboseRecord verboseRecord = new VerboseRecord(verbose); MshCommandRuntime mshCommandRuntime = cmdlet.CommandRuntime as MshCommandRuntime; if (mshCommandRuntime != null) { mshCommandRuntime.WriteVerbose(verboseRecord, overrideInquire); } } break; case PSStreamObjectType.Progress: { MshCommandRuntime mshCommandRuntime = cmdlet.CommandRuntime as MshCommandRuntime; if (mshCommandRuntime != null) { mshCommandRuntime.WriteProgress((ProgressRecord)Value, overrideInquire); } } break; case PSStreamObjectType.Information: { MshCommandRuntime mshCommandRuntime = cmdlet.CommandRuntime as MshCommandRuntime; if (mshCommandRuntime != null) { mshCommandRuntime.WriteInformation((InformationRecord)Value, overrideInquire); } } break; case PSStreamObjectType.WarningRecord: { WarningRecord warningRecord = (WarningRecord)Value; MshCommandRuntime mshCommandRuntime = cmdlet.CommandRuntime as MshCommandRuntime; if (mshCommandRuntime != null) { mshCommandRuntime.AppendWarningVarList(warningRecord); } } break; case PSStreamObjectType.MethodExecutor: { Dbg.Assert(this.Value is ClientMethodExecutor, "Expected psstreamObject.value is ClientMethodExecutor"); ClientMethodExecutor methodExecutor = (ClientMethodExecutor)Value; methodExecutor.Execute(cmdlet); } break; case PSStreamObjectType.BlockingError: { CmdletMethodInvoker <object> methodInvoker = (CmdletMethodInvoker <object>)Value; InvokeCmdletMethodAndWaitForResults(methodInvoker, cmdlet); } break; case PSStreamObjectType.ShouldMethod: { CmdletMethodInvoker <bool> methodInvoker = (CmdletMethodInvoker <bool>)Value; InvokeCmdletMethodAndWaitForResults(methodInvoker, cmdlet); } break; case PSStreamObjectType.Exception: { Exception e = (Exception)Value; throw e; } } } else if (ObjectType == PSStreamObjectType.Exception) { Exception e = (Exception)Value; throw e; } }
/// <summary> /// Sets up the PowerShell shell stream event handlers. /// </summary> /// <param name="shell">The PowerShell shell.</param> private static void SetupStreamEventHandlers(PowerShell shell) { Logger.Instance.WriteMethodEntry(EventIdentifier.RunPowerShellScriptSetupStreamEventHandlers); try { shell.Streams.ClearStreams(); shell.Streams.Error.DataAdded += delegate(object sender, DataAddedEventArgs e) { PSDataCollection <ErrorRecord> errorStream = (PSDataCollection <ErrorRecord>)sender; ErrorRecord record = errorStream[e.Index]; if (record == null) { return; } StringBuilder builder = new StringBuilder(); builder.AppendLine(record.ToString()); if (record.InvocationInfo != null) { builder.AppendLine(); builder.AppendLine(record.InvocationInfo.PositionMessage); } Logger.Instance.WriteError(EventIdentifier.RunPowerShellScriptSetupStreamEventHandlersErrorEvents, builder.ToString()); }; shell.Streams.Warning.DataAdded += delegate(object sender, DataAddedEventArgs e) { PSDataCollection <WarningRecord> warningStream = (PSDataCollection <WarningRecord>)sender; WarningRecord record = warningStream[e.Index]; if (record != null) { Logger.Instance.WriteWarning(EventIdentifier.RunPowerShellScriptSetupStreamEventHandlersWarningEvents, record.ToString()); } }; shell.Streams.Debug.DataAdded += delegate(object sender, DataAddedEventArgs e) { PSDataCollection <DebugRecord> debugStream = (PSDataCollection <DebugRecord>)sender; DebugRecord record = debugStream[e.Index]; if (record != null) { Logger.Instance.WriteInfo(EventIdentifier.RunPowerShellScriptSetupStreamEventHandlersDebugEvents, record.ToString()); } }; shell.Streams.Verbose.DataAdded += delegate(object sender, DataAddedEventArgs e) { PSDataCollection <VerboseRecord> versboseStream = (PSDataCollection <VerboseRecord>)sender; VerboseRecord record = versboseStream[e.Index]; if (record != null) { Logger.Instance.WriteVerbose(EventIdentifier.RunPowerShellScriptSetupStreamEventHandlersEvents, record.ToString()); } }; shell.Streams.Progress.DataAdded += delegate(object sender, DataAddedEventArgs e) { PSDataCollection <ProgressRecord> progressStream = (PSDataCollection <ProgressRecord>)sender; ProgressRecord record = progressStream[e.Index]; if (record != null) { Logger.Instance.WriteInfo(EventIdentifier.RunPowerShellScriptSetupStreamEventHandlersProgressEvents, record.ToString()); } }; } finally { Logger.Instance.WriteMethodExit(EventIdentifier.RunPowerShellScriptSetupStreamEventHandlers); } }
public void Record(string msg = "") { //return; //Debug.Log("sync record " + m_world.FrameCount); if (!m_world.IsCertainty) { return; } if (x >= m_world.FrameCount) { Debug.LogError("重复的确定帧!" + st + "\n\n"); } DebugRecord dr = new DebugRecord(); dr.frame = m_world.FrameCount; //把有哪些ID也打印进来 //msgCache.Append("\nIDs:\n"); //for (int i = 0; i < m_world.m_entityList.Count; i++) //{ // msgCache.Append(m_world.m_entityList[i].ID + "\n"); //} dr.msg = msgCache.ToString(); RecordMsg("DebugMsg", m_world.FrameCount, dr.msg); msgCacheList.Add(dr); x = m_world.FrameCount; st = new System.Diagnostics.StackTrace(); //Debug.Log("Record"); for (int i = 0; i < m_world.m_entityList.Count; i++) { EntityBase entity = m_world.m_entityList[i]; bool isFilter = false; if (isPlayerOnly && !entity.GetExistComp(ComponentType.PlayerComponent)) { isFilter = true; } if (isFlyObject && !entity.GetExistComp(ComponentType.FlyObjectComponent)) { isFilter = true; } if (isFilter) { continue; } foreach (var item in entity.comps) { if (item == null) { continue; } string compName = item.GetType().Name; if (IsFilter(compName)) { string key = "local_" + compName; string content = ""; if (!debugContent.ContainsKey(key)) { debugContent.Add(key, new StringBuilder()); } content += "\nframe " + m_world.FrameCount + " id " + entity.ID + " -> " + Serializer.Serialize(item); debugContent[key].Append(content); //Debug.Log("frame " + m_world.FrameCount + " id " + entity.ID + "-> " + Serializer.Serialize(item)); } } } foreach (var item in m_world.m_singleCompDict) { string compName = item.Value.GetType().Name; if (IsFilter(compName)) { string key = "local_singleComp_" + compName; string content = ""; if (!debugContent.ContainsKey(key)) { debugContent.Add(key, new StringBuilder()); } content += "\nframe " + m_world.FrameCount + " -> " + Serializer.Serialize(item.Value); debugContent[key].Append(content); } } RecordMsg("errorMsg", m_world.FrameCount, msg); RecordRandomSeed("local_randomSeed", m_world.FrameCount, m_world.m_RandomSeed); //Debug.Log("local_randomSeed " + m_world.FrameCount + " " + m_world.m_RandomSeed); }
/// <summary> /// set return 本身自带广播功能 /// </summary> /// <param name="startT"></param> /// <param name="cmp"></param> private void setReturn(int startT, commandWithTime.returnning cmp) { Console.WriteLine($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}开始执行setReturn"); Thread.Sleep(startT + 1); Console.WriteLine($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}开始执行setReturn正文"); List <string> notifyMsg = new List <string>(); bool needUpdatePromoteState = false; lock (this.PlayerLock) { var player = this._Players[cmp.key]; var car = this._Players[cmp.key].getCar(); car.targetFpIndex = this._Players[cmp.key].StartFPIndex; if ((cmp.changeType == "mile" || cmp.changeType == "business" || cmp.changeType == "volume" || cmp.changeType == "speed") && car.state == CarState.buying) { ReturnThenSetComeBack(player, car, cmp, ref notifyMsg); } else if ((cmp.changeType == "mile" || cmp.changeType == "business" || cmp.changeType == "volume" || cmp.changeType == "speed") && car.state == CarState.waitOnRoad) { /* * 此项对应的条件是在找能力提升宝石过程中,里程不够然后安排返回。 * */ ReturnThenSetComeBack(player, car, cmp, ref notifyMsg); } else if (cmp.changeType == CollectReturn && (car.state == CarState.waitForCollectOrAttack || car.state == CarState.waitOnRoad)) { ReturnThenSetComeBack(player, car, cmp, ref notifyMsg); } else if (cmp.changeType == "tax-return" && (car.state == CarState.waitForTaxOrAttack || car.state == CarState.waitOnRoad)) { ReturnThenSetComeBack(player, car, cmp, ref notifyMsg); } else if (cmp.changeType == "Attack" && car.state == CarState.roadForAttack && car.purpose == Purpose.attack) { ReturnThenSetComeBack(player, car, cmp, ref notifyMsg); } else if (cmp.changeType == AttackFailedReturn) { ReturnThenSetComeBack(player, car, cmp, ref notifyMsg); } else if (cmp.changeType == "sys-return") { //if (car.state == CarState.roadForAttack) { ReturnThenSetComeBack(player, car, cmp, ref notifyMsg); } } else if (cmp.changeType == "orderToReturn") { ReturnThenSetComeBack(player, car, cmp, ref notifyMsg); } else if (cmp.changeType == "Bust" && car.state == CarState.roadForAttack && car.purpose == Purpose.attack) { ReturnThenSetComeBack(player, car, cmp, ref notifyMsg); } else { var json = Newtonsoft.Json.JsonConvert.SerializeObject(car); for (var i = 0; i < 100; i++) { Console.WriteLine("↓↓↓↓↓出现异常↓↓↓↓↓"); } Console.WriteLine(json); DebugRecord.FileRecord($@"-----setReturn 以下情况未注册----- {json} -----setReturn 以下情况未注册-----"); } } for (var i = 0; i < notifyMsg.Count; i += 2) { var url = notifyMsg[i]; var sendMsg = notifyMsg[i + 1]; // Console.WriteLine($"url:{url}"); Startup.sendMsg(url, sendMsg); } Console.WriteLine($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}执行setReturn结束"); if (needUpdatePromoteState) { CheckAllPlayersPromoteState(cmp.changeType); } }
protected abstract void DoWriteDebug(DebugRecord debugRecord);