using DevExpress.CodeParser; using DevExpress.Mvvm.Native; using DevExpress.Utils.Html; using DevExpress.XtraEditors; using Ips.Library.Basic; using Ips.Library.DxpLib; using Ips.Library.Entity; using Ips.Sps.Scheduling; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Forms; namespace Ips.Sps.Svrs { public partial class CtrlSvrs : DevExpress.XtraEditors.XtraUserControl { List list = new List(); public CtrlSvrs() { InitializeComponent(); } private void CtrlSvrs_Load(object sender, EventArgs e) { gridSvrs.UseDefault(list).UseGroup().UseRowNumber(); gridSvrs.UseEdit(); var linkEdit = new DevExpress.XtraEditors.Repository.RepositoryItemHyperLinkEdit(); this.gridSvrs.RepositoryItems.Add(linkEdit); if (gridView1.Columns.Count > 0) { gridView1.Columns[nameof(ModelSvrRpt.SwaggerAddr)].ColumnEdit = linkEdit; gridView1.Columns[nameof(ModelSvrRpt.SwaggerAddr)].OptionsColumn.AllowEdit = true; } this.list.AddRange(ServerContext.Instance.GetAll()); gridView1.RefreshData(); IpsMessenger.Default.Sub>("服务集合改变", RefreshSvr); this.simpleLabelItem2.Text = $"如果服务无法注册到此程序需要到在此程序服务器防火墙入栈规则中允许Tcp端口{ToolConfig.GetAppSetting("HttpPort", 8091)}通过"; } private void RefreshSvr(List items) { if (!this.IsHandleCreated || this.Disposing || this.IsDisposed) return; try { var listCopy = list.Skip(0).ToList(); foreach (var item in listCopy) { var find = items.Find(p => p.BaseHttpAddr == item.BaseHttpAddr); if (find == null) { list.Remove(item); } } foreach (var item in items) { var find = list.Find(p => p.BaseHttpAddr == item.BaseHttpAddr); if (find == null) { list.Add(new ModelSvrRpt() { SvrType = item.SvrType, SvrNo = item.SvrNo, Features = item.Features, CapDevType = item.CapDevType, SvrRptType = item.SvrRptType, BaseHttpAddr = item.BaseHttpAddr, SwaggerAddr = item.SwaggerAddr, ReportTime = item.ReportTime, }); } else { find.BaseHttpAddr = item.BaseHttpAddr; find.SwaggerAddr = item.SwaggerAddr; find.Features = item.Features; find.SvrType = item.SvrType; find.SvrNo = item.SvrNo; find.CapDevType = item.CapDevType; find.SvrRptType = item.SvrRptType; find.ReportTime = item.ReportTime; } } this.BeginInvoke(new Action(() => { gridView1.RefreshData(); })); } catch (Exception ex) { IpsLogger.Error("处理服务状态上报异常", ex); } } protected override void Dispose(bool disposing) { IpsMessenger.Default.UnSub>("服务集合改变", RefreshSvr); if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } } }