using DevExpress.Mvvm.Native; using DevExpress.Utils.Html; using DevExpress.XtraEditors; 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; using DW5S.App.EditForms; using DW5S.DTO; using DW5S.Repostory; using DW5S.Service; using DW5S.Entity; using Serilog; using DW5S.ViewModel; namespace DW5S.App.UserControl { public partial class CtrlSvrs : DevExpress.XtraEditors.XtraUserControl { List list = new List(); public CtrlSvrs() { InitializeComponent(); } private async 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(SvrViewModel.SwaggerAddr)].ColumnEdit = linkEdit; gridView1.Columns[nameof(SvrViewModel.SwaggerAddr)].OptionsColumn.AllowEdit = true; } this.list.AddRange(ServerContext.Instance.GetAll().To>()); gridView1.RefreshData(); Messenger.Defalut.Sub>("服务集合改变", RefreshSvr); var unitOfWork = IocContainer.UnitOfWork; var repsSys = unitOfWork.Of(); var settings = await repsSys.FirstOrDefaultAsync(); if (settings != null) this.simpleLabelItem2.Text = $"如果服务无法注册到平台需要到平台所在设备允许防火墙通过平台端口{settings.HttpPort}"; } 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 SvrViewModel() { SvrType = item.SvrType, SvrID = item.SvrID, BaseHttpAddr = item.BaseHttpAddr, SwaggerAddr = item.SwaggerAddr, ReportTime = item.ReportTime, }); } else { find.BaseHttpAddr = item.BaseHttpAddr; find.SwaggerAddr = item.SwaggerAddr; find.SvrType = item.SvrType; find.SvrID = item.SvrID; find.ReportTime = item.ReportTime; } } this.BeginInvoke(new Action(() => { gridView1.RefreshData(); })); } catch (Exception ex) { IocContainer.Logger.Error(ex,"处理服务状态上报异常"); } } protected override void Dispose(bool disposing) { Messenger.Defalut.UnSub>("服务集合改变", RefreshSvr); if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } } }