private static void TcpClient_OnPublishing(Scada.AsyncNetTcp.Net.AsyncTcpClient client, object sender, string msg, string ProjectID) { int index = int.Parse(sender.ToString()); if (index <= PublishObject.Count) { if (index == PublishObject.Count) { byte[] datas = PublishObject.ElementAt(index - 1).Value; TcpClient.Send(new ArraySegment <byte>(datas), ScadaTcpOperator.流程发布数据); AddLogToMainLog("已经发送第" + index + "条数据"); Thread.Sleep(3000); TcpClient.Send("采集站数据已经发送完毕,等待服务器更新程序!", ScadaTcpOperator.流程发布成功); AddLogToMainLog("流程图工程已经上传完毕,等待服务器更新程序!"); } else { byte[] datas = PublishObject.ElementAt(index - 1).Value; TcpClient.Send(new ArraySegment <byte>(datas), ScadaTcpOperator.流程发布数据); } } AddLogToMainLog("数据接收进度 " + (Convert.ToSingle(index) / PublishObject.Count * 100) + "%"); }
private void TcpClient_OnConnectedServer(Scada.AsyncNetTcp.Net.AsyncTcpClient client, object sender, string msg) { if (Convert.ToBoolean(sender) & Core.IOMonitorManager.TcpClient != null) { if (Core.IOMonitorManager.TcpClient.Client == client) { Core.IOMonitorManager.UserLogin(User, Password); } } }
private void TcpClient_OnConnectedServer(Scada.AsyncNetTcp.Net.AsyncTcpClient client, object sender, string msg, string projectid) { SetInfo("与服务器连接成功!"); Thread.Sleep(1000); SetInfo("正在验证登录....."); if (Convert.ToBoolean(sender)) { if (FlowManager.TcpClient.Client == client) { FlowManager.LoginManager(User, Password); } } }
private void TcpClient_OnUserLogined(Scada.AsyncNetTcp.Net.AsyncTcpClient client, object sender, string msg, string projectid) { if (Convert.ToBoolean(sender)) { FlowManager.Config.User = this.tbUser.Text.Trim(); FlowManager.Config.Password = this.tbPassword.Text.Trim(); FlowManager.Config.RemoteIP = this.txtIP.Text.Trim(); FlowManager.Config.WriteConfig();//保存用户配置信息 this.DialogResult = DialogResult.OK; } else { SetInfo("登录服务器失败!" + msg); } }
private void TcpClient_OnConnectTimeout(Scada.AsyncNetTcp.Net.AsyncTcpClient client, object sender, string msg, string projectid) { return; }
private static void TcpClient_OnDisConnectedServer(Scada.AsyncNetTcp.Net.AsyncTcpClient client, object sender, string msg) { AddLogToMainLog(msg + ",系统自动尝试重新连接服务器中...."); }
/// <summary> ///下置命令 /// </summary> /// <param name="receivebytes"></param> /// <returns></returns> private static void TcpClient_OnConnectedServer(Scada.AsyncNetTcp.Net.AsyncTcpClient client, object sender, string msg) { AddLogToMainLog("与服务器成功连接!"); }
/// <summary> /// 用户登录成功的返回事件 /// </summary> /// <param name="client"></param> /// <param name="sender"></param> /// <param name="msg"></param> private static void TcpClient_OnUserLogined(Scada.AsyncNetTcp.Net.AsyncTcpClient client, object sender, string msg) { }
private static void TcpClient_OnPublishProject(Scada.AsyncNetTcp.Net.AsyncTcpClient client, object sender, string msg, string ProjectID) { bool res = Convert.ToBoolean(sender); if (res) { PublishObject.Clear(); var pubProject = Projects.Find(x => x.ProjectID == ProjectID); if (pubProject == null) { AddLogToMainLog("未找到ID" + ProjectID + "的工程,无法发布!"); return; } bool isindex = false; for (int i = 0; i < pubProject.GraphList.Count; i++) { isindex = pubProject.GraphList[i].Index; if (isindex) { break; } } if (isindex == false) { AddLogToMainLog("您发布的工程没有创建主视图,无法发布。请选择主先设置主视图后在尝试发布"); return; } StringBuilder sb = new StringBuilder(); int ViewNum = pubProject.GraphList.Count;//当前发布的视图数量 sb.AppendLine("\r\n--PROJ #" + pubProject.ProjectID + "#" + pubProject.Title + "\r\n"); sb.AppendLine(" "); for (int i = 0; i < ViewNum; i++) { sb.AppendLine("\r\n--VIEW #" + pubProject.GraphList[i].GID + "#" + pubProject.GraphList[i].ViewTitle + "#" + pubProject.GraphList[i].Index.ToString() + "\r\n"); sb.AppendLine(" "); pubProject.GraphList[i].Site.IsPublish = true; sb.Append(pubProject.GraphList[i].Site.ExportSVG()); sb.AppendLine(""); sb.AppendLine("\r\n--ENDVIEW\r\n"); } //工程包含的用户数据 for (int i = 0; i < pubProject.FlowUsers.Count; i++) { sb.AppendLine("\r\n--USER #" + pubProject.FlowUsers[i].Nickname + "#" + pubProject.FlowUsers[i].UserName + "#" + pubProject.FlowUsers[i].Password.ToString() + "#" + pubProject.FlowUsers[i].Read.ToString() + "#" + pubProject.FlowUsers[i].Write.ToString() + "\r\n"); sb.AppendLine("\r\n--ENDUSER\r\n"); } byte[] byteArray = System.Text.Encoding.Default.GetBytes(sb.ToString()); int num = byteArray.Length / 8192; if (byteArray.Length % 8192 != 0) { num++; } List <byte> tempBytes = new List <byte>(); for (int i = 0; i < num; i++) { byte[] subBytes; if (i == num - 1 && byteArray.Length % 8192 != 0) { subBytes = byteArray.Skip(i * 8192).Take(byteArray.Length % 8192).ToArray(); } else { subBytes = byteArray.Skip(i * 8192).Take(8192).ToArray(); } PublishObject.Add(i + 1, subBytes); tempBytes.AddRange(subBytes); } TcpData tcpData = new TcpData(); tcpData.Items.Add(new TcpDataItem() { Key = "RELUST", Value = "" }); tcpData.Items.Add(new TcpDataItem() { Key = "MSG", Value = "" }); tcpData.Items.Add(new TcpDataItem() { Key = "IO_SERVER_ID", Value = FlowDataBaseManager.IOServer.SERVER_ID }); tcpData.Items.Add(new TcpDataItem() { Key = "NUMBER", Value = num.ToString() }); tcpData.Items.Add(new TcpDataItem() { Key = "BYTENUMBER", Value = byteArray.Length.ToString() }); AddLogToMainLog("发布视图数量" + ViewNum); byte[] datas = tcpData.StringToTcpByte(tcpData.TcpItemToString(), Scada.AsyncNetTcp.ScadaTcpOperator.流程发布准备); TcpClient.Send(new ArraySegment <byte>(datas)); } else { AddLogToMainLog(msg + ", 无法发布!"); } }
private static void TcpClient_OnPublishProjectFault(Scada.AsyncNetTcp.Net.AsyncTcpClient client, object sender, string msg, string ProjectID) { AddLogToMainLog("流程图发布失败!"); MessageBox.Show(FlowDesign, "发布流程图成功!"); }
private static void TcpClient_OnDisConnectedServer(Scada.AsyncNetTcp.Net.AsyncTcpClient client, object sender, string msg, string ProjectID) { AddLogToMainLog(msg + ",正在尝试连接服务器...."); }