//根节点远程执行命令 public static string RootRemoteCommand(string identify, string eprocess, string method, string arg) { Dictionary <string, string> argDic = JsonConvert.DeserializeObject <Dictionary <string, string> >(arg); string argstr = ""; foreach (var i in argDic) { if (argstr == "") { argstr = i.Key + "=" + i.Value; } else { argstr += "&" + i.Key + "=" + i.Value; } } if (WcfGlobal.Identify == identify) { return(WcfGlobal.normalIPC.CallCmd(eprocess, method, argstr)); } else { MNodePath NodePath = null; MNodeTree mtree = new MNodeTree(); mtree.LoadCache(); NodePath = mtree.CalculateMNodePath(WcfGlobal.Identify, identify); return(ReplyRemoteCommand(eprocess, method, argstr, NodePath)); } }
//路径首次执行 private static MNodePath FirstGetNodePath(string plugin, MNodePlugin localPlugin) { try { List <MNodePath> pathlist = new List <MNodePath>(); string[] remoteNodeId = localPlugin.RemotePlugin.Find(x => x.PluginName == plugin).MNodeIdentify.ToArray(); MNodeTree mtree = new MNodeTree(); mtree.LoadCache(); foreach (string Id in remoteNodeId) { pathlist.Add(mtree.CalculateMNodePath(WcfGlobal.Identify, Id)); } MNodePath nodePath = null; if (localPlugin.PathStrategy == 0)//随机策略 { Random ro = new Random(); int index = ro.Next(0, pathlist.Count); nodePath = pathlist[index]; } else//最短路径? { nodePath = pathlist[0]; } return(nodePath); } catch (Exception err) { throw err; } }
//根节点远程获取服务 public static string RootRemoteGetServices(string identify) { if (WcfGlobal.Identify == identify) { return(GetServiceConfig()); } else { MNodePath NodePath = null; MNodeTree mtree = new MNodeTree(); mtree.LoadCache(); NodePath = mtree.CalculateMNodePath(WcfGlobal.Identify, identify); return(ReplyRemoteGetServices(NodePath)); } }
//根节点回调获取远程服务 public static string ReplyRemoteGetServices(MNodePath NodePath) { NodePath.NextStep(); //节点路径下一步 if (NodePath.IsEndMNode) //到达终节点 { return(GetServiceConfig()); } else { foreach (var client in ClientManage.ClientDic) { if (client.Value.IsMNode && client.Value.ServerIdentify == NodePath.nextMNode) { return(client.Value.dataReply.ReplyRemoteGetServices(NodePath)); } } return(null); } }
/// <summary> /// 计算两个节点之间路径 /// </summary> /// <param name="beginNode">开始节点,一般是当前中间件</param> /// <param name="endNode">结束节点</param> /// <returns></returns> public MNodePath CalculateMNodePath(string beginNode, string endNode) { List <MNodeObject> beginToRoot = new List <MNodeObject>(); //开始节点到根节点经过的所有节点 List <MNodeObject> endToRoot = new List <MNodeObject>(); //结束节点到根节点经过的所有节点 nodeToRoot(beginNode, beginToRoot); nodeToRoot(endNode, endToRoot); MNodeObject coincideNode = null;//重合点 foreach (var bn in beginToRoot) { if (endToRoot.FindIndex(x => x.ServerIdentify == bn.ServerIdentify) == -1) { continue; } if (endToRoot.FindIndex(x => x.ServerIdentify == bn.ServerIdentify) != -1) { coincideNode = bn; break; } } if (coincideNode == null) { return(null); } List <MNodeObject> pathNodeList = new List <MNodeObject>();//路径节点列表 //1.添加向上节点 for (int i = 0; i < beginToRoot.Count; i++) { if (beginToRoot[i].ServerIdentify == coincideNode.ServerIdentify) { break; } pathNodeList.Add(beginToRoot[i]); } //2.添加交叉节点 pathNodeList.Add(coincideNode); //3.添加向下节点 bool flag = false; for (int i = endToRoot.Count - 1; i >= 0; i--) { if (endToRoot[i].ServerIdentify == coincideNode.ServerIdentify && flag == false) { flag = true; continue; } else { if (flag == true) { pathNodeList.Add(endToRoot[i]); } continue; } } MNodePath path = new MNodePath(pathNodeList, coincideNode);//转换为节点路径 return(path); }
//根节点回调远程命令 public static string ReplyRemoteCommand(string eprocess, string method, string arg, MNodePath NodePath) { NodePath.NextStep(); //节点路径下一步 if (NodePath.IsEndMNode) //到达终节点 { return(WcfGlobal.normalIPC.CallCmd(eprocess, method, arg)); } else { foreach (var client in ClientManage.ClientDic) { if (client.Value.IsMNode && client.Value.ServerIdentify == NodePath.nextMNode) { return(client.Value.dataReply.ReplyRemoteCommand(eprocess, method, arg, NodePath)); } } return(null); } }
public string ReplyRemoteGetServices(MNodePath NodePath) { return(MiddlewareConfigManage.ReplyRemoteGetServices(NodePath)); }
public string ReplyRemoteCommand(string eprocess, string method, string arg, MNodePath NodePath) { return(DataManage.ReplyRemoteCommand(eprocess, method, arg, NodePath)); }