void SaveEverything() { using( LogRecorder applyLogger = new LogRecorder() ) { SaveConfig(); if( applyLogger.HasMessages ) { MessageBox.Show( applyLogger.MessageString, "Some problems were encountered with the selected values." ); return; } } using( LogRecorder saveLogger = new LogRecorder() ) { if( Config.Save() ) { bApply.Enabled = false; } if( saveLogger.HasMessages ) { MessageBox.Show( saveLogger.MessageString, "Some problems were encountered while saving." ); } } }
private void AddWorldPopup_FormClosing( object sender, FormClosingEventArgs e ) { Redraw( false ); if( DialogResult == DialogResult.OK ) { if( Map == null ) { e.Cancel = true; } else { bwRenderer.CancelAsync(); Enabled = false; progressBar.Visible = true; progressBar.Style = ProgressBarStyle.Marquee; tStatus1.Text = "Saving map..."; tStatus2.Text = ""; Refresh(); string newFileName = World.FullFileName; using (LogRecorder logRec = new LogRecorder(true, LogType.Error, LogType.SeriousError)) { Map.Save(newFileName); if (logRec.HasMessages) { MessageBox.Show(logRec.MessageString); } } string oldFileName = Path.Combine( Paths.MapPath, originalWorldName + ".fcm" ); if( originalWorldName != null && originalWorldName != World.Name && File.Exists( oldFileName ) ) { try { File.Delete( oldFileName ); } catch( Exception ex ) { string errorMessage = String.Format( "Renaming the map file failed. Please delete the old file ({0}.fcm) manually.{1}{2}", originalWorldName, Environment.NewLine, ex ); MessageBox.Show( errorMessage, "Error renaming the map file" ); } } } } }
static void ShowMapDetails( TextBox textBox, string fileName ) { DateTime creationTime, modificationTime; long fileSize; if( File.Exists( fileName ) ) { FileInfo existingMapFileInfo = new FileInfo( fileName ); creationTime = existingMapFileInfo.CreationTime; modificationTime = existingMapFileInfo.LastWriteTime; fileSize = existingMapFileInfo.Length; } else if( Directory.Exists( fileName ) ) { DirectoryInfo dirInfo = new DirectoryInfo( fileName ); creationTime = dirInfo.CreationTime; modificationTime = dirInfo.LastWriteTime; fileSize = dirInfo.GetFiles().Sum( finfo => finfo.Length ); } else { textBox.Text = "File or directory \"" + fileName + "\" does not exist."; return; } MapFormat format = MapUtility.Identify( fileName, true ); try { Map loadedMap; using( LogRecorder logRec = new LogRecorder() ) { loadedMap = MapUtility.LoadHeader( fileName ); if( logRec.HasMessages ) { MessageBox.Show( logRec.MessageString ); } } const string msgFormat = @" Location: {0} Format: {1} Filesize: {2} KB Created: {3} Modified: {4} Dimensions: {5}×{6}×{7} Blocks: {8}"; textBox.Text = String.Format( msgFormat, fileName, format, (fileSize / 1024), creationTime.ToLongDateString(), modificationTime.ToLongDateString(), loadedMap.Width, loadedMap.Length, loadedMap.Height, loadedMap.Volume ); if( loadedMap.Zones.Count > 0 ) { StringBuilder sb = new StringBuilder(); sb.AppendLine(); sb.Append( " Zones: " ); bool first = true; foreach( Zone zone in loadedMap.Zones ) { if( !first ) sb.Append( " " ); sb.AppendFormat( "{0} {1}", zone.Name, zone.Bounds.Dimensions ); } textBox.AppendText( sb.ToString() ); } } catch( Exception ex ) { const string msgFormat = @" Location: {0} Format: {1} Filesize: {2} KB Created: {3} Modified: {4} Could not load more information: {5}: {6}"; textBox.Text = String.Format( msgFormat, fileName, format, (fileSize / 1024), creationTime.ToLongDateString(), modificationTime.ToLongDateString(), ex.GetType().Name, ex.Message ); } }
/// <summary> /// 生成请求对象 /// </summary> /// <param name="apiName"></param> /// <param name="method"></param> /// <param name="destRequest"></param> /// <param name="data"></param> /// <returns></returns> public void CreateRequest(string apiName, string method, HttpRequest destRequest, RouteData data) { ApiName = apiName; var auth = Bearer; _url = $"{Host?.TrimEnd('/') + "/"}{apiName?.TrimStart('/')}"; _webRequest = (HttpWebRequest)WebRequest.Create(_url); _webRequest.Headers.Add(HttpRequestHeader.Authorization, auth); _webRequest.Timeout = RouteOption.Option.SystemConfig.HttpTimeOut; _webRequest.Method = method; _webRequest.KeepAlive = false; if (destRequest.ContentLength != null) { _webRequest.ContentType = destRequest.ContentType; if (destRequest.HasFormContentType) { _webRequest.ContentType = "application/x-www-form-urlencoded"; var builder = new StringBuilder(); var first = true; foreach (var kvp in destRequest.Form) { if (first) { first = false; } else { builder.Append('&'); } builder.Append($"{kvp.Key}="); if (!string.IsNullOrEmpty(kvp.Value)) { builder.Append($"{HttpUtility.UrlEncode(kvp.Value, Encoding.UTF8)}"); } } var form = builder.ToString(); using (var rs = _webRequest.GetRequestStream()) { var formData = Encoding.UTF8.GetBytes(form); rs.Write(formData, 0, formData.Length); } LogRecorder.MonitorTrace($"Form:{form}"); } else { _webRequest.ContentType = "application/json;charset=utf-8"; if (string.IsNullOrWhiteSpace(data.Context)) { using (var texter = new StreamReader(destRequest.Body)) { data.Context = texter.ReadToEnd(); } } if (!string.IsNullOrWhiteSpace(data.Context)) { var buffer = data.Context.ToUtf8Bytes(); using (var rs = _webRequest.GetRequestStream()) { rs.Write(buffer, 0, buffer.Length); } LogRecorder.MonitorTrace($"Context:{data.Context}"); } } } LogRecorder.MonitorTrace($"Url:{_webRequest.RequestUri.PathAndQuery}"); LogRecorder.MonitorTrace($"Auth:{Bearer}"); }
void SaveEverything() { using( LogRecorder applyLogger = new LogRecorder() ) { SaveConfig(); if( applyLogger.HasMessages ) { MessageBox.Show( applyLogger.MessageString, "Some problems were encountered with the selected values." ); return; } } try { Config.Save(); bApply.Enabled = false; } catch( Exception ex ) { MessageBox.Show( ex.ToString() ); } }
/// <summary> /// 序列化到错误内容 /// </summary> /// <param name="code"></param> /// <param name="message"></param> /// <param name="message2"></param> /// <returns></returns> private string ToErrorString(int code, string message, string message2 = null) { LogRecorder.MonitorTrace($"调用异常:{message}"); return(JsonConvert.SerializeObject(ApiResult.Error(code, _url + message, message2))); }
private void ReadNetWork(PoolSocket socket) { ZeroResultData result; var old = GlobalContext.RequestInfo.LocalGlobalId; if (Simple) { result = socket.Socket.QuietSend(CallDescription, Commmand, GlobalContext.RequestInfo.RequestId, null,//JsonConvert.SerializeObject(GlobalContext.Current), Argument, null, ZeroApplication.Config.StationName, null, "0"); } else { result = socket.Socket.QuietSend(GetGlobalIdDescription, GlobalContext.RequestInfo.RequestId); if (!result.InteractiveSuccess) { socket.HaseFailed = true; //ZeroTrace.WriteError("GetGlobalId", "Send Failed", station, commmand, argument); //ApiContext.Current.LastError = ErrorCode.NetworkError; State = ZeroOperatorStateType.LocalSendError; return; } if (result.State == ZeroOperatorStateType.Pause) { socket.HaseFailed = true; State = ZeroOperatorStateType.Pause; return; } result = ReceiveString(socket.Socket); if (!result.InteractiveSuccess) { socket.HaseFailed = true; //ZeroTrace.WriteError("GlobalId", "Recv Failed", station, commmand, argument); //ApiContext.Current.LastError = ErrorCode.NetworkError; State = ZeroOperatorStateType.LocalRecvError; return; } if (result.TryGetValue(ZeroFrameType.GlobalId, out GlobalId)) { GlobalContext.RequestInfo.LocalGlobalId = GlobalId; LogRecorder.MonitorTrace($"GlobalId:{GlobalId}"); } result = socket.Socket.QuietSend(CallDescription, Commmand, GlobalContext.RequestInfo.RequestId, JsonConvert.SerializeObject(GlobalContext.Current), Argument, ExtendArgument, ZeroApplication.Config.StationName, GlobalContext.Current.Organizational.RouteName, GlobalContext.RequestInfo.LocalGlobalId); GlobalContext.RequestInfo.LocalGlobalId = old; } if (!result.InteractiveSuccess) { socket.HaseFailed = true; //ZeroTrace.WriteError(station, "Send Failed", commmand, argument); //ApiContext.Current.LastError = ErrorCode.NetworkError; State = ZeroOperatorStateType.LocalSendError; return; } result = ReceiveString(socket.Socket); if (!result.InteractiveSuccess) { socket.HaseFailed = true; //ZeroTrace.WriteError("API", "incorrigible", commmand, globalId); //ApiContext.Current.LastError = ErrorCode.NetworkError; State = ZeroOperatorStateType.LocalRecvError; return; } //if (result.State == ZeroOperatorStateType.NoWorker) //{ // return; //} //var lr = socket.Socket.QuietSend(CloseDescription, name, globalId); //if (!lr.InteractiveSuccess) //{ // ZeroTrace.WriteError(station, "Close Failed", commmand, globalId); //} //lr = ReceiveString(socket.Socket); //if (!lr.InteractiveSuccess) //{ // socket.HaseFailed = true; // ZeroTrace.WriteError(station, "Close Failed", commmand, globalId, lr.ZmqErrorMessage); //} result.TryGetValue(ZeroFrameType.JsonValue, out _json); State = result.State; }
protected bool ExeBindA(ref string reStr) { if (!ExeBusinessAB(ref reStr)) { return(false); } switch (currentTaskPhase) { case 1: if (!RfidReadAB()) { break; } bool needReparid = false; if (this.repairProcess.GetNeedRepairALine(this.rfidUID, this.NodeID, ref needReparid, ref reStr) == false) { this.logRecorder.AddDebugLog(this.nodeName, "获取返修状态失败:" + reStr); break; } if (needReparid == false) { currentTaskPhase = 3; //直接放行 this.repairProcess.ReportToMesByProcessStationID(this.nodeID, this.rfidUID); this.TxtLogRecorder.WriteLog("当前工艺此工位不需要加工,直接放行,工装板号:" + this.rfidUID); break; } if (!ProductTraceRecord()) { break; } LogRecorder.AddDebugLog(nodeName, string.Format("RFID:{0}", this.rfidUID)); currentTaskPhase++; this.currentTask.TaskPhase = this.currentTaskPhase; this.TxtLogRecorder.WriteLog("当前工位开始加工!"); this.ctlTaskBll.Update(this.currentTask); break; case 2: int uploadStatus = 0; if (this.nodeID == "OPA013") { uploadStatus = UploadDataToMes(1, "Y00100501", this.rfidUID, ref reStr); } else if (this.nodeID == "OPA014") { //LogRecorder.AddDebugLog(nodeName, "烘烤1NG流程开始处理:"); if (BakeNHHandler(this.rfidUID, "OPA016", ref reStr) == false) { LogRecorder.AddDebugLog(nodeName, "烘烤1NG流程处理失败:" + reStr); break; } //LogRecorder.AddDebugLog(nodeName, "烘烤1NG流程开始成功!"); uploadStatus = UploadDataToMes(1, "Y00101001", this.rfidUID, ref reStr); } else if (this.nodeID == "OPA015") { //LogRecorder.AddDebugLog(nodeName, "烘烤2NG流程开始处理:"); if (BakeNHHandler(this.rfidUID, "OPA017", ref reStr) == false) { LogRecorder.AddDebugLog(nodeName, "烘烤2NG流程处理失败:" + reStr); break; } //LogRecorder.AddDebugLog(nodeName, "烘烤2NG流程成功!"); uploadStatus = UploadDataToMes(1, "Y00101301", this.rfidUID, ref reStr); } if (uploadStatus == 0) { //this.logRecorder.AddDebugLog(this.nodeName, "上传MES数据成功:" + reStr); } else if (uploadStatus == 1) { //this.logRecorder.AddDebugLog(this.nodeName, "上传MES数据成功,返回NG:" + reStr); } else if (uploadStatus == 3) //空板放行 { //this.logRecorder.AddDebugLog(this.nodeName, "空板直接放行!" +this.rfidUID); } else { currentTaskDescribe = "上传MES数据失败:" + reStr; Console.WriteLine(this.nodeName + "上传MES数据失败:" + reStr); break; } currentTaskPhase++; this.currentTask.TaskPhase = this.currentTaskPhase; this.ctlTaskBll.Update(this.currentTask); this.TxtLogRecorder.WriteLog(string.Format("上传MES二位码成功:{0}", this.rfidUID)); LogRecorder.AddDebugLog(nodeName, string.Format("上传MES二位码成功:{0}", this.rfidUID)); this.currentTaskDescribe = string.Format("上传MES二维码成功!"); break; case 3: { this.currentTask.TaskPhase = this.currentTaskPhase; this.currentTask.TaskStatus = EnumTaskStatus.已完成.ToString(); this.ctlTaskBll.Update(this.currentTask); db1ValsToSnd[2 + this.channelIndex - 1] = 3; currentTaskDescribe = "流程完成"; this.TxtLogRecorder.WriteLog("工位加工处理完成!"); break; } default: break; } return(true); }
void LoadWorldList() { if (Worlds.Count > 0) { Worlds.Clear(); } if (!File.Exists(Paths.WorldListFileName)) { return; } try { XDocument doc = XDocument.Load(Paths.WorldListFileName); XElement root = doc.Root; if (root == null) { MessageBox.Show("Worlds.xml is empty or corrupted."); return; } string errorLog = ""; using (LogRecorder logRecorder = new LogRecorder()) { foreach (XElement el in root.Elements("World")) { try { Worlds.Add(new WorldListEntry(el)); } catch (Exception ex) { errorLog += ex + Environment.NewLine; } } if (logRecorder.HasMessages) { MessageBox.Show(logRecorder.MessageString, "World list loading warnings."); } } if (errorLog.Length > 0) { MessageBox.Show("Some errors occured while loading the world list:" + Environment.NewLine + errorLog, "Warning"); } FillWorldList(); XAttribute mainWorldAttr = root.Attribute("main"); if (mainWorldAttr != null) { foreach (WorldListEntry world in Worlds) { if (world.Name.ToLower() == mainWorldAttr.Value.ToLower()) { cMainWorld.SelectedItem = world.Name; break; } } } } catch (Exception ex) { MessageBox.Show("Error occured while loading the world list: " + Environment.NewLine + ex, "Warning"); } Worlds.ListChanged += SomethingChanged; }
void LoadConfig() { string missingFileMsg = null; if (!File.Exists(Paths.WorldListFileName) && !File.Exists(Paths.ConfigFileName)) { missingFileMsg = String.Format("Configuration ({0}) and world list ({1}) were not found. Using defaults.", Paths.ConfigFileName, Paths.WorldListFileName); } else if (!File.Exists(Paths.ConfigFileName)) { missingFileMsg = String.Format("Configuration ({0}) was not found. Using defaults.", Paths.ConfigFileName); } else if (!File.Exists(Paths.WorldListFileName)) { missingFileMsg = String.Format("World list ({0}) was not found. Assuming 0 worlds.", Paths.WorldListFileName); } if (missingFileMsg != null) { MessageBox.Show(missingFileMsg); } using (LogRecorder loadLogger = new LogRecorder()) { if (Config.Load(false, false)) { if (loadLogger.HasMessages) { MessageBox.Show(loadLogger.MessageString, "Config loading warnings"); } } else { MessageBox.Show(loadLogger.MessageString, "Error occured while trying to load config"); } } ApplyTabGeneral(); ApplyTabChat(); ApplyTabWorlds(); // also reloads world list ApplyTabRanks(); ApplyTabSecurity(); ApplyTabSavingAndBackup(); ApplyTabLogging(); ApplyTabIRC(); ApplyTabAdvanced(); AddChangeHandler(tabs, SomethingChanged); AddChangeHandler(bResetTab, SomethingChanged); AddChangeHandler(bResetAll, SomethingChanged); dgvWorlds.CellValueChanged += delegate { SomethingChanged(null, null); }; AddChangeHandler(tabChat, HandleTabChatChange); bApply.Enabled = false; }