本文整理汇总了C#中NetMQSocket.ReceiveString方法的典型用法代码示例。如果您正苦于以下问题:C# NetMQSocket.ReceiveString方法的具体用法?C# NetMQSocket.ReceiveString怎么用?C# NetMQSocket.ReceiveString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NetMQSocket
的用法示例。
在下文中一共展示了NetMQSocket.ReceiveString方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetBehaviorModules
private static IList<BehaviorInfo> GetBehaviorModules(NetMQSocket socket,
IList<BehaviorInfo> behaviorList)
{
var ret = new List<BehaviorInfo>();
var dict = new Dictionary<string, BehaviorInfo>();
//behavior_modules
if (socket != null && behaviorList != null && behaviorList.Count > 0)
{
ret.AddRange(behaviorList);
socket.Send("behavior_modules");
var resp = socket.ReceiveString(new TimeSpan(0, 0, 0, 0, RecvTimeout));
if (!string.IsNullOrEmpty(resp))
{
var modules = JArray.Parse(resp);
if (modules != null && modules.Count > 0)
{
//Console.WriteLine(resp);
foreach (var module in modules)
{
var moduleName = module.Value<string>("name");
var responder = module.SelectToken("$.responder");
string host = string.Empty;
int port = 0;
if (responder != null)
{
host = responder.Value<string>("Host");
port = responder.Value<int>("Port");
}
var behaviors = module.SelectToken("$.behaviors");
foreach (var behavior in behaviors)
{
string name = behavior.Value<string>("name");
string functionName = behavior.Value<string>("function_name");
var args = behavior.SelectToken("$.arg");
var parameters = new Dictionary<string, object>();
foreach (var arg in args)
{
parameters.Add(arg.Value<string>("name"), new Dictionary<string, object>
{
{"value", arg.Value<string>("value")},
{"place_holder", arg.Value<string>("place_holder")},
{"type", arg.Value<string>("type")}
});
}
var matchingBehaviors = ret.Where(s => s.BehaviorName == name).ToList();
foreach (var matchingBehavior in matchingBehaviors)
{
matchingBehavior.ModuleName = moduleName;
matchingBehavior.FunctionName = functionName;
matchingBehavior.Ip = host;
matchingBehavior.Port = port;
foreach (var parameter in parameters)
{
if (!matchingBehavior.Parameters.ContainsKey(parameter.Key))
{
matchingBehavior.Parameters.Add(parameter);
}
}
}
}
}
}
}
}
return ret;
}
示例2: GetBehaviorModules2
private static IList<BehaviorInfo> GetBehaviorModules2(NetMQSocket socket,
IList<BehaviorInfo> behaviorList)
{
var ret = new List<BehaviorInfo>();
var dict = new Dictionary<string, BehaviorInfo>();
//behavior_modules
if (socket != null && behaviorList != null && behaviorList.Count > 0)
{
socket.Send("behavior_modules");
var resp = socket.ReceiveString(new TimeSpan(0, 0, 0, 0, RecvTimeout));
if (!string.IsNullOrEmpty(resp))
{
var modules = JArray.Parse(resp);
if (modules != null && modules.Count > 0)
{
//Console.WriteLine(resp);
foreach (var module in modules)
{
var moduleName = module.Value<string>("name");
var responder = module.SelectToken("$.responder");
string host = string.Empty;
int port = 0;
if (responder != null)
{
host = responder.Value<string>("Host");
port = responder.Value<int>("Port");
}
var behaviors = module.SelectToken("$.behaviors");
foreach (var behavior in behaviors)
{
string name = behavior.Value<string>("name");
string functionName = behavior.Value<string>("function_name");
var parameters = new Dictionary<string, object>();
var args = behavior.SelectToken("$.arg");
foreach (var arg in args)
{
parameters.Add(arg.Value<string>("name"), new Dictionary<string, object>
{
{"value", arg.Value<string>("value")},
{"place_holder", arg.Value<string>("place_holder")},
{"type", arg.Value<string>("type")}
});
}
if (!dict.ContainsKey(name))
{
dict.Add(name, new BehaviorInfo
{
BehaviorName = name,
FunctionName = functionName,
Ip = host,
Port = port,
Parameters = parameters
});
}
}
}
}
}
if (dict.Count > 0)
{
// ReSharper disable once LoopCanBeConvertedToQuery
foreach (var item in behaviorList)
{
Log.InfoFormat("Before : {0}",item.ToString());
if (dict.ContainsKey(item.BehaviorName))
{
var temp = dict[item.BehaviorName].Clone() as BehaviorInfo;
if (temp != null)
{
foreach (var parameter in item.Parameters)
{
if (!temp.Parameters.ContainsKey(parameter.Key))
{
temp.Parameters.Add(parameter);
}
else
{
temp.Parameters[parameter.Key] = parameter.Value;
}
}
Log.InfoFormat("After : {0}", temp.ToString());
ret.Add(temp);
}
//ret.Add(dict[item.BehaviorName]);
// Update the values of the parameter list with the once originally parsed from the xml file
//foreach (var parameter in item.Parameters)
//{
// if (!dict[item.BehaviorName].Parameters.ContainsKey(parameter.Key))
// {
// dict[item.BehaviorName].Parameters.Add(parameter);
// }
// else
// {
// dict[item.BehaviorName].Parameters[parameter.Key] = parameter.Value;
// }
//}
//ret.Add(dict[item.BehaviorName]);
}
//.........这里部分代码省略.........