private void DesignArea_AddNewServer_Click(object sender, EventArgs e) { var newServer = new MDSServer { ServerInfo = new ServerGraphInfo.ServerOnGraph { Name = "", IpAddress = "", Port = CommunicationConsts.DefaultMDSPort, Adjacents = "", Location = _designPanelLastX + "," + _designPanelLastY, } }; var addServerForm = new EditServerForm(newServer.ServerInfo, true); addServerForm.ShowDialog(); if (!addServerForm.Updated) { return; } newServer.LabelOfServer = CreateServerLabel(newServer); newServer.LabelOfServer.Text = newServer.ServerInfo.Name + Environment.NewLine + newServer.ServerInfo.IpAddress; newServer.LabelOfServer.Left = _designPanelLastX; newServer.LabelOfServer.Top = _designPanelLastY; _servers.Add(newServer); pnlDesign.Invalidate(); }
public ActionResult CollectMDS(string ip, int port, string arrangeStr) { MDSServer mdsServer = new MDSServer(); mdsServer.ArrangeStr = arrangeStr; mdsServer.MDS_IP = ip; mdsServer.MDS_Port = port; mdsServer.MDS_IP = System.Configuration.ConfigurationManager.AppSettings["LocalIP"].ToString(); lock (CommonFlag.lockobject) { if (cacheManage.GetCache <IList <MDSServer> >("MDSServers") == null) { IList <MDSServer> mdsServers = new List <MDSServer>(); mdsServers.Add(mdsServer); cacheManage.AddCache <IList <MDSServer> >("MDSServers", mdsServers); } else { if (cacheManage.GetCache <IList <MDSServer> >("MDSServers").Count > 0) { for (int i = cacheManage.GetCache <IList <MDSServer> >("MDSServers").Count - 1; i >= 0; i--) { if (cacheManage.GetCache <IList <MDSServer> >("MDSServers")[i].MDS_IP == mdsServer.MDS_IP && cacheManage.GetCache <IList <MDSServer> >("MDSServers")[i].MDS_Port == mdsServer.MDS_Port) { cacheManage.GetCache <IList <MDSServer> >("MDSServers").RemoveAt(i); } } } cacheManage.GetCache <IList <MDSServer> >("MDSServers").Add(mdsServer); } } return(Json("ok", JsonRequestBehavior.AllowGet)); }
/// <summary> /// Creates a label for a server. /// </summary> /// <param name="server">Server</param> /// <returns>Label</returns> private Label CreateServerLabel(MDSServer server) { var label = new Label { BackColor = Color.DodgerBlue, BorderStyle = BorderStyle.FixedSingle, Font = new Font("Verdana", 9.75F, FontStyle.Bold, GraphicsUnit.Point, 162), ForeColor = Color.White, Location = new Point(1, 1), Name = "lbl" + server.ServerInfo.Name, Size = new Size(180, 40), TabIndex = 1, Text = server.ServerInfo.Name + Environment.NewLine + server.ServerInfo.IpAddress, TextAlign = ContentAlignment.MiddleCenter }; if (server == _thisServer) { label.BackColor = Color.Crimson; } label.ContextMenuStrip = cmsServerRightMenu; label.MouseDown += ServerLabel_MouseDown; label.MouseUp += ServerLabel_MouseUp; label.MouseMove += ServerLabel_MouseMove; label.MouseDoubleClick += ServerLabel_MouseDoubleClick; pnlDesign.Controls.Add(label); return(label); }
public MDSServer FindMDSServer(IList <MDSServer> servers, String objectID) { MDSServer server = null; foreach (MDSServer tempserver in servers) { if (tempserver.ArrangeStr.Contains(objectID.Substring(0, 1))) { return(tempserver); } } return(server); }
/// <summary> /// Creates a comma delimited string list from adjacent names of given server. /// </summary> /// <param name="server">Server to get adjacent list</param> /// <returns>Adjacent list as string</returns> private static string GetAdjacentListAsString(MDSServer server) { var adjacentList = new StringBuilder(); for (var i = 0; i < server.Adjacents.Count; i++) { if (i > 0) { adjacentList.Append(","); } adjacentList.Append(server.Adjacents[i].ServerInfo.Name); } return(adjacentList.ToString()); }
private void ServerRightMenu_SetAsThisServer_Click(object sender, EventArgs e) { var newThisServer = GetSelectedServer(); if (newThisServer == null || newThisServer == _thisServer) { return; } if (_thisServer != null) { _thisServer.LabelOfServer.BackColor = _serverBackColor; } _thisServer = newThisServer; _thisServer.LabelOfServer.BackColor = _thisServerBackColor; }
private IList <MsgRecordModel> GenerateMsgRecordModel(MsgRecordModel msgRecordModel) { IList <MsgRecordModel> msgRecords = new List <MsgRecordModel>(); if (!string.IsNullOrEmpty(msgRecordModel.MsgRecipientGroupID)) { IContactPersonService contactGroupService = ObjectContainerFactory.CurrentContainer.Resolver <IContactPersonService>(); IList <String> ContactPersonIDs = contactGroupService.GetContactPersonIDListByGroupID(msgRecordModel.MsgSenderObjectID, msgRecordModel.MsgRecipientGroupID); foreach (String objectID in ContactPersonIDs) { MsgRecordModel _msgRecordModel = new MsgRecordModel(); _msgRecordModel.MsgContent = msgRecordModel.MsgContent; _msgRecordModel.MsgType = msgRecordModel.MsgType; _msgRecordModel.MsgSenderObjectID = msgRecordModel.MsgSenderObjectID; _msgRecordModel.MsgSenderName = msgRecordModel.MsgSenderName; _msgRecordModel.MsgRecipientGroupID = msgRecordModel.MsgRecipientGroupID; _msgRecordModel.IsSended = msgRecordModel.IsSended; _msgRecordModel.MsgRecipientObjectID = objectID; _msgRecordModel.SendTime = msgRecordModel.SendTime; _msgRecordModel.MsgID = Guid.NewGuid().ToString(); MDSServer server = CommonVariables.CommonFunctions.FindMDSServer(CommonVariables.MDSServers, objectID); _msgRecordModel.MDS_IP = server.MDS_IP; _msgRecordModel.MDS_Port = server.MDS_Port; //_msgRecordModel.MDS_ID = CommonVariables.MDSServers[i].MDS_ID; msgRecords.Add(_msgRecordModel); } } else if (string.IsNullOrEmpty(msgRecordModel.MsgRecipientGroupID) && !string.IsNullOrEmpty(msgRecordModel.MsgRecipientObjectID)) { for (int i = 0; i < CommonVariables.MDSServers.Count; i++) { MDSServer server = CommonVariables.CommonFunctions.FindMDSServer(CommonVariables.MDSServers, msgRecordModel.MsgRecipientObjectID); msgRecordModel.MDS_IP = server.MDS_IP; msgRecordModel.MDS_Port = server.MDS_Port; if (string.IsNullOrEmpty(msgRecordModel.MsgID)) { msgRecordModel.MsgID = Guid.NewGuid().ToString(); } } msgRecords.Add(msgRecordModel); } return(msgRecords); }
static void Main(string[] args) { try { var server = new MDSServer(); server.Start(); Console.WriteLine("DotNetMQ server has started."); Console.WriteLine("Press enter to stop..."); Console.ReadLine(); server.Stop(true); } catch (Exception ex) { Console.WriteLine(ex.Message); Console.ReadLine(); } }
/// <summary> /// Checks if there is a path from a MDS server to another. /// I runs as recursive and searches all nodes to find a path from source to destination. /// </summary> /// <param name="sourceServer">Source server of path</param> /// <param name="destServer">Destination server of path</param> /// <param name="passedServers">List of all passed servers until now</param> /// <returns>True, if there is a path</returns> private static bool IsThereAPath(MDSServer sourceServer, MDSServer destServer, ICollection <MDSServer> passedServers) { if (passedServers.Contains(sourceServer)) { return(false); } if (sourceServer.Adjacents.Contains(destServer)) { return(true); } passedServers.Add(sourceServer); foreach (var adjacent in sourceServer.Adjacents) { if (IsThereAPath(adjacent, destServer, passedServers)) { return(true); } } return(false); }
/// <summary> /// Creates a label for a server. /// </summary> /// <param name="server">Server</param> /// <returns>Label</returns> private Label CreateServerLabel(MDSServer server) { var label = new Label { BackColor = Color.DodgerBlue, BorderStyle = BorderStyle.FixedSingle, Font = new Font("Verdana", 9.75F, FontStyle.Bold, GraphicsUnit.Point, 162), ForeColor = Color.White, Location = new Point(1, 1), Name = "lbl" + server.ServerInfo.Name, Size = new Size(180, 40), TabIndex = 1, Text = server.ServerInfo.Name + Environment.NewLine + server.ServerInfo.IpAddress, TextAlign = ContentAlignment.MiddleCenter }; if (server == _thisServer) { label.BackColor = Color.Crimson; } label.ContextMenuStrip = cmsServerRightMenu; label.MouseDown += ServerLabel_MouseDown; label.MouseUp += ServerLabel_MouseUp; label.MouseMove += ServerLabel_MouseMove; label.MouseDoubleClick += ServerLabel_MouseDoubleClick; pnlDesign.Controls.Add(label); return label; }
/// <summary> /// Checks if there is a path from a MDS server to another. /// I runs as recursive and searches all nodes to find a path from source to destination. /// </summary> /// <param name="sourceServer">Source server of path</param> /// <param name="destServer">Destination server of path</param> /// <param name="passedServers">List of all passed servers until now</param> /// <returns>True, if there is a path</returns> private static bool IsThereAPath(MDSServer sourceServer, MDSServer destServer, ICollection<MDSServer> passedServers) { if (passedServers.Contains(sourceServer)) { return false; } if (sourceServer.Adjacents.Contains(destServer)) { return true; } passedServers.Add(sourceServer); foreach (var adjacent in sourceServer.Adjacents) { if(IsThereAPath(adjacent, destServer, passedServers)) { return true; } } return false; }
/// <summary> /// Creates a comma delimited string list from adjacent names of given server. /// </summary> /// <param name="server">Server to get adjacent list</param> /// <returns>Adjacent list as string</returns> private static string GetAdjacentListAsString(MDSServer server) { var adjacentList = new StringBuilder(); for (var i = 0; i < server.Adjacents.Count; i++) { if (i > 0) { adjacentList.Append(","); } adjacentList.Append(server.Adjacents[i].ServerInfo.Name); } return adjacentList.ToString(); }
/// <summary> /// Creates graph on design area from _serverGraphInfo. /// </summary> private void CreateGraph() { //Create MDSServerNode objects and get names of adjacents of nodes var adjacentsOfServers = new SortedList<string, string>(); foreach (var server in _serverGraphInfo.Servers) { var mdsServer = new MDSServer { ServerInfo = server, }; _servers.Add(mdsServer); adjacentsOfServers.Add(server.Name, server.Adjacents); if (server.Name == _serverGraphInfo.ThisServerName) { _thisServer = mdsServer; } } //Set Adjacent servers foreach (var mdsServer in _servers) { //Get adjacent names var adjacents = adjacentsOfServers[mdsServer.ServerInfo.Name].Split(','); //Add nodes as adjacent foreach (var adjacent in adjacents) { var trimmedAdjacentName = adjacent.Trim(); if (string.IsNullOrEmpty(trimmedAdjacentName)) { continue; } var adjacentServer = FindServer(trimmedAdjacentName); if (adjacentServer == null) { continue; } mdsServer.Adjacents.Add(adjacentServer); } } //Create labels for servers foreach (var server in _servers) { server.LabelOfServer = CreateServerLabel(server); } //Set design properties foreach (var server in _serverGraphInfo.Servers) { var mdsServer = FindServer(server.Name); if (mdsServer == null) { continue; } var splittedLocation = server.Location.Split(new[] { ',', ';' }); mdsServer.LabelOfServer.Left = Convert.ToInt32(splittedLocation[0]); mdsServer.LabelOfServer.Top = Convert.ToInt32(splittedLocation[1]); } }
/// <summary> /// Creates graph on design area from _serverGraphInfo. /// </summary> private void CreateGraph() { //Create MDSServerNode objects and get names of adjacents of nodes var adjacentsOfServers = new SortedList <string, string>(); foreach (var server in _serverGraphInfo.Servers) { var mdsServer = new MDSServer { ServerInfo = server, }; _servers.Add(mdsServer); adjacentsOfServers.Add(server.Name, server.Adjacents); if (server.Name == _serverGraphInfo.ThisServerName) { _thisServer = mdsServer; } } //Set Adjacent servers foreach (var mdsServer in _servers) { //Get adjacent names var adjacents = adjacentsOfServers[mdsServer.ServerInfo.Name].Split(','); //Add nodes as adjacent foreach (var adjacent in adjacents) { var trimmedAdjacentName = adjacent.Trim(); if (string.IsNullOrEmpty(trimmedAdjacentName)) { continue; } var adjacentServer = FindServer(trimmedAdjacentName); if (adjacentServer == null) { continue; } mdsServer.Adjacents.Add(adjacentServer); } } //Create labels for servers foreach (var server in _servers) { server.LabelOfServer = CreateServerLabel(server); } //Set design properties foreach (var server in _serverGraphInfo.Servers) { var mdsServer = FindServer(server.Name); if (mdsServer == null) { continue; } var splittedLocation = server.Location.Split(new[] { ',', ';' }); mdsServer.LabelOfServer.Left = Convert.ToInt32(splittedLocation[0]); mdsServer.LabelOfServer.Top = Convert.ToInt32(splittedLocation[1]); } }
/// <summary> /// Constructor. /// </summary> public DotNetMqService() { InitializeComponent(); _mdsServer = new MDSServer(); }