本文整理汇总了C#中Parameters.SetString方法的典型用法代码示例。如果您正苦于以下问题:C# Parameters.SetString方法的具体用法?C# Parameters.SetString怎么用?C# Parameters.SetString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Parameters
的用法示例。
在下文中一共展示了Parameters.SetString方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
if(args.Length != 1)
{
System.Console.WriteLine(
"expecting one parameter: name server address");
return;
}
string nameServerAddress = args[0];
try
{
Agent serverAgent = new Agent();
// prepare the server and bind its address
// to the name server
String resolvedAddress =
serverAgent.AddListener("tcp://*:*");
System.Console.WriteLine(
"The server is listening on {0}",
resolvedAddress);
Parameters bindParams = new Parameters();
bindParams.SetString("object", "calculator");
bindParams.SetString("location", resolvedAddress);
OutgoingMessage nsBind =
serverAgent.Send(nameServerAddress,
"names", "bind", bindParams);
nsBind.WaitForCompletion();
if (nsBind.State !=
OutgoingMessage.MessageState.REPLIED) {
Console.WriteLine("error: {0}" +
nsBind.ExceptionMsg);
return;
}
nsBind.Close();
Console.WriteLine("Address bound by name server.");
serverAgent.RegisterObject("calculator", calculator);
// block
while(true)
{
Thread.Sleep(10000);
}
}
catch(Exception ex)
{
Console.WriteLine("error: {0}", ex.Message);
}
}
示例2: Main
static void Main(string[] args)
{
if(args.Length != 1)
{
Console.WriteLine(
"expecting one parameter: " +
"publisher destination");
return;
}
String publisherAddress = args[0];
try
{
Agent subscriberAgent = new Agent();
// prepare subscription update callback
string updateObjectName =
"update_handler";
subscriberAgent.RegisterObject(
updateObjectName, updateHandler);
// subscribe to the producer
Parameters param = new Parameters();
param.SetString(
"destination_object", updateObjectName);
subscriberAgent.SendOneWay(publisherAddress,
"random_number", "subscribe", param);
Console.WriteLine(
"subscribed, waiting for updates");
// block forever
// and receive updates in background
while(true)
{
Thread.Sleep(10000);
}
}
catch(Exception ex)
{
Console.WriteLine(
"error: {0}", ex.Message);
}
}
示例3: Main
static void Main(string[] args)
{
if(args.Length != 1)
{
Console.WriteLine(
"expecting one parameter: server destination");
return;
}
string serverAddress = args[0];
try
{
Agent clientAgent = new Agent();
// read lines of text from standard input
// and post each one for transmission
string inputLine = null;
while((inputLine = Console.ReadLine()) != null)
{
Parameters param = new Parameters();
// the "content" field name is arbitrary,
// but needs to be recognized at the server side
param.SetString("content", inputLine);
OutgoingMessage message =
clientAgent.Send(serverAddress,
"printer", "print", param);
message.WaitForTransmission();
message.Close();
}
clientAgent.Close();
}
catch(Exception ex)
{
Console.WriteLine(
"error: {0}", ex.Message);
}
}
示例4: testSubscribeUnsubscribe
public void testSubscribeUnsubscribe()
{
Agent publisherAgent = new Agent();
string publisherAddress =
publisherAgent.AddListener(localAddress);
ValuePublisher value = new ValuePublisher();
publisherAgent.RegisterValuePublisher("my_value", value);
// no subscribers yet
Assert.AreEqual(0, value.NumberOfSubscribers);
Assert.AreEqual(0, value.Subscribers.Count);
// set up the subscriber side
bool gotUpdate = false;
Agent subscriberAgent = new Agent();
subscriberAgent.RegisterObject("my_update_handler",
delegate(object sender, IncomingMessageArgs args)
{
Assert.AreEqual("subscription_update",
args.Message.MessageName);
gotUpdate = true;
});
// subscribe
Parameters parameters = new Parameters();
parameters.SetString("destination_object", "my_update_handler");
OutgoingMessage subscribeMsg = subscriberAgent.Send(
publisherAddress, "my_value", "subscribe", parameters);
subscribeMsg.WaitForCompletion();
// there should be one subscriber, as seen at the publisher side
Assert.AreEqual(1, value.NumberOfSubscribers);
Assert.AreEqual(1, value.Subscribers.Count);
Assert.AreEqual("my_update_handler",
value.Subscribers[0].DestinationObject);
// publish some value
Parameters dummy = new Parameters();
value.Publish(dummy);
// check if the listener got it
pause();
Assert.IsTrue(gotUpdate);
// unsubscribe
OutgoingMessage unsubscribeMsg = subscriberAgent.Send(
publisherAddress, "my_value", "unsubscribe", null);
unsubscribeMsg.WaitForCompletion();
// there should be no subscribers
Assert.AreEqual(0, value.NumberOfSubscribers);
Assert.AreEqual(0, value.Subscribers.Count);
// check that the updates do not arrive any longer
gotUpdate = false;
value.Publish(dummy);
pause();
Assert.IsFalse(gotUpdate);
value.Close();
subscriberAgent.Close();
publisherAgent.Close();
}
示例5: Main
static void Main(string[] args)
{
if(args.Length != 3)
{
Console.WriteLine(
"expecting three parameters: " +
"name server address and two integers");
return;
}
String nameServerAddress = args[0];
int a;
int b;
try
{
a = int.Parse(args[1]);
b = int.Parse(args[2]);
}
catch(Exception)
{
Console.WriteLine("cannot parse the parameters");
return;
}
try
{
Agent clientAgent = new Agent();
// obtain the address of calculator server
Parameters resolveParams = new Parameters();
resolveParams.SetString("object", "calculator");
OutgoingMessage nsQuery =
clientAgent.Send(nameServerAddress,
"names", "resolve", resolveParams);
nsQuery.WaitForCompletion();
if (nsQuery.State !=
OutgoingMessage.MessageState.REPLIED) {
Console.WriteLine("error: {0}",
nsQuery.ExceptionMsg);
return;
}
Parameters resolveReply = nsQuery.Reply;
String calculatorAddress =
resolveReply.GetString("location");
nsQuery.Close();
// send message to the calculator object
Parameters param = new Parameters();
param.SetInteger("a", a);
param.SetInteger("b", b);
OutgoingMessage message =
clientAgent.Send(calculatorAddress,
"calculator", "calculate", param);
message.WaitForCompletion();
OutgoingMessage.MessageState state =
message.State;
if(state == OutgoingMessage.MessageState.REPLIED)
{
Parameters reply = message.Reply;
int sum = reply.GetInteger("sum");
int difference = reply.GetInteger("difference");
int product = reply.GetInteger("product");
int ratio = 0;
Parameters.Entry ratioEntry =
reply.Find("ratio");
bool ratioDefined = ratioEntry != null;
if(ratioDefined)
{
ratio = ratioEntry.GetInteger();
}
Console.WriteLine("sum = {0}", sum);
Console.WriteLine("difference = {0}",
difference);
Console.WriteLine("product = {0}", product);
Console.Write("ratio = ");
if(ratioDefined)
{
Console.WriteLine(ratio);
}
else
{
Console.WriteLine("<undefined>");
}
}
else if(state ==
OutgoingMessage.MessageState.REJECTED)
{
//.........这里部分代码省略.........
示例6: deserializeFromBytes
private static void deserializeFromBytes(Parameters parameters,
ByteIterator bytes)
{
int numOfEntries = consumeInt(bytes);
for(int i = 0; i != numOfEntries; ++i)
{
string entryName = consumeString(bytes);
int typeCode = consumeInt(bytes);
Parameters.EntryType type = codeToType(typeCode);
switch(type)
{
case Parameters.EntryType.BOOLEAN:
{
int value = consumeInt(bytes);
parameters.SetBoolean(entryName, value != 0);
}
break;
case Parameters.EntryType.INTEGER:
{
int value = consumeInt(bytes);
parameters.SetInteger(entryName, value);
}
break;
case Parameters.EntryType.LONG:
{
long value = consumeLong(bytes);
parameters.SetLong(entryName, value);
}
break;
case Parameters.EntryType.DOUBLE:
{
double value = consumeDouble(bytes);
parameters.SetDouble(entryName, value);
}
break;
case Parameters.EntryType.STRING:
{
string value = consumeString(bytes);
parameters.SetString(entryName, value);
}
break;
case Parameters.EntryType.BINARY:
{
byte[] value = consumeBinary(bytes);
parameters.SetBinary(entryName, value);
}
break;
case Parameters.EntryType.BOOLEAN_ARRAY:
{
int arrayLength = consumeInt(bytes);
int bytesNeeded =
(arrayLength + BITS_IN_BYTE - 1)
/ BITS_IN_BYTE;
byte[] packedArray =
consumeBytes(bytes, bytesNeeded);
bool[] array = new bool[arrayLength];
for(int j = 0; j != arrayLength; ++j)
{
int bytePosition = j / BITS_IN_BYTE;
int bitPosition = j % BITS_IN_BYTE;
int mask = 1 << bitPosition;
if((packedArray[bytePosition] & mask) != 0)
{
array[j] = true;
}
}
parameters.SetBooleanArray(entryName, array);
}
break;
case Parameters.EntryType.INTEGER_ARRAY:
{
int arrayLength = consumeInt(bytes);
int[] array = new int[arrayLength];
for(int j = 0; j != arrayLength; ++j)
{
array[j] = consumeInt(bytes);
}
parameters.SetIntegerArray(entryName, array);
}
break;
case Parameters.EntryType.LONG_ARRAY:
{
int arrayLength = consumeInt(bytes);
long[] array = new long[arrayLength];
for(int j = 0; j != arrayLength; ++j)
{
array[j] = consumeLong(bytes);
}
parameters.SetLongArray(entryName, array);
}
break;
case Parameters.EntryType.DOUBLE_ARRAY:
{
int arrayLength = consumeInt(bytes);
double[] array = new double[arrayLength];
for(int j = 0; j != arrayLength; ++j)
//.........这里部分代码省略.........
示例7: testForString
public void testForString()
{
string sourceValue =
"Kolorowe kredki w pudeleczku nosze,\n"
+ "kolorowe kredki, bardzo lubie je!";
string name = "some rather longer name";
parameters.SetString(name, sourceValue);
Assert.IsTrue(parameters.Count == 1);
Parameters.EntryType t = parameters.GetType(name);
Assert.AreEqual(t, Parameters.EntryType.STRING);
Assert.AreEqual(sourceValue, parameters.GetString(name));
parameters.SetString("other name", sourceValue);
Assert.IsTrue(parameters.Count == 2);
Assert.AreEqual(sourceValue, parameters.GetString("other name"));
string[] array = { "Kazio", "Krzysio", "Rysio", "Zbysio" };
parameters.SetStringArray("nameA", array);
Assert.IsTrue(parameters.Count == 3);
Assert.AreEqual(parameters.GetType("nameA"),
Parameters.EntryType.STRING_ARRAY);
Assert.AreEqual(parameters.GetStringArray("nameA"), array);
Assert.IsTrue(array.Length == 4);
Assert.IsTrue(
array[0] == "Kazio"
&& array[1] == "Krzysio"
&& array[2] == "Rysio"
&& array[3] == "Zbysio"
);
IEnumerator<Parameters.Entry> it = parameters.GetEnumerator();
Assert.IsTrue(it.MoveNext());
Parameters.Entry e = it.Current;
Assert.AreEqual(e.Type, Parameters.EntryType.STRING);
Assert.AreEqual(name, e.Name);
Assert.AreEqual(sourceValue, e.GetString());
Assert.IsTrue(it.MoveNext());
e = it.Current;
Assert.AreEqual(e.Type, Parameters.EntryType.STRING);
Assert.AreEqual("other name", e.Name);
Assert.AreEqual(sourceValue, e.GetString());
Assert.IsTrue(it.MoveNext());
e = it.Current;
Assert.AreEqual(e.Type, Parameters.EntryType.STRING_ARRAY);
Assert.AreEqual("nameA", e.Name);
Assert.AreEqual(array, e.GetStringArray());
Assert.IsTrue(array.Length == 4);
Assert.IsTrue(
array[0] == "Kazio"
&& array[1] == "Krzysio"
&& array[2] == "Rysio"
&& array[3] == "Zbysio"
);
Assert.IsFalse(it.MoveNext());
Assert.AreEqual(
"entry 0:\n"
+ "name: some rather longer name\n"
+ "string: Kolorowe kredki w pudeleczku nosze,\n"
+ "kolorowe kredki, bardzo lubie je!\n"
+ "entry 1:\n"
+ "name: other name\n"
+ "string: Kolorowe kredki w pudeleczku nosze,\n"
+ "kolorowe kredki, bardzo lubie je!\n"
+ "entry 2:\n"
+ "name: nameA\n"
+ "string array: Kazio Krzysio Rysio Zbysio\n",
parameters.ToString());
byte[] expected = {
3, 0, 0, 0, // num of entries
23, 0, 0, 0, // length of "some rather longer name"
(byte)'s', (byte)'o', (byte)'m', (byte)'e',
(byte)' ', (byte)'r', (byte)'a', (byte)'t',
(byte)'h', (byte)'e', (byte)'r', (byte)' ',
(byte)'l', (byte)'o', (byte)'n', (byte)'g',
(byte)'e', (byte)'r', (byte)' ', (byte)'n',
(byte)'a', (byte)'m', (byte)'e', 0,
5, 0, 0, 0, // type code for string
69, 0, 0, 0, // length
(byte)'K', (byte)'o', (byte)'l', (byte)'o',
(byte)'r', (byte)'o', (byte)'w', (byte)'e',
(byte)' ', (byte)'k', (byte)'r', (byte)'e',
(byte)'d', (byte)'k', (byte)'i', (byte)' ',
(byte)'w', (byte)' ', (byte)'p', (byte)'u',
(byte)'d', (byte)'e', (byte)'l', (byte)'e',
(byte)'c', (byte)'z', (byte)'k', (byte)'u',
(byte)' ', (byte)'n', (byte)'o', (byte)'s',
(byte)'z', (byte)'e', (byte)',', (byte)'\n',
(byte)'k', (byte)'o', (byte)'l', (byte)'o',
(byte)'r', (byte)'o', (byte)'w', (byte)'e',
(byte)' ', (byte)'k', (byte)'r', (byte)'e',
//.........这里部分代码省略.........
示例8: testSendReply
public void testSendReply()
{
//BooleanHolder gotMessage = new BooleanHolder(false);
bool gotMessage = false;
serverAgent.RegisterObject(
objectName,
delegate(object sender, IncomingMessageArgs args)
{
gotMessage = true;
Assert.AreEqual(objectName, args.Message.ObjectName);
Assert.AreEqual(messageName, args.Message.MessageName);
Parameters receivedContent = args.Message.Parameters;
Assert.AreEqual(1, receivedContent.Count);
Assert.AreEqual(
"ping", receivedContent.GetString("value"));
receivedContent.SetString("value", "pong");
args.Message.Reply(receivedContent);
}
);
Parameters content = new Parameters();
content.SetString("value", "ping");
OutgoingMessage message = clientAgent.Send(
serverAddress, objectName, messageName, content);
message.WaitForTransmission();
// after transmission the whole message is pushed out
OutgoingMessage.MessageStateInfo messageInfo = message.StateInfo;
Assert.IsTrue(
messageInfo.SentBytes == messageInfo.TotalByteCount);
message.WaitForCompletion();
Assert.IsTrue(gotMessage);
Assert.AreEqual(
OutgoingMessage.MessageState.REPLIED, message.State);
content = message.Reply;
Assert.AreEqual("pong", content.GetString("value"));
message.Close();
}
示例9: testBigMessages
public void testBigMessages()
{
// Note:
// The messages are sent with different priorities, which means
// that they might complete in the order that is different from the
// order of posting them to the outgoing queue.
// The messages are posted with increasing priorities (first message
// is sent with lowest priority, last message with highest),
// so it is *very likely* that they will be received by server
// in the reversed order, but this cannot be guaranteed as there is
// no relation between the speed of posting and the speed
// of transmission.
int numOfMessages = 10;
bool[] gotMessages = new bool[numOfMessages];
int sizeOfBigString = 1000000;
StringBuilder bigStringBld = new StringBuilder(sizeOfBigString);
for (int i = 0; i != sizeOfBigString; ++i)
{
bigStringBld.Append('x');
}
string bigString = bigStringBld.ToString();
serverAgent.RegisterObject(objectName,
delegate(object sender, IncomingMessageArgs args)
{
Parameters receivedContent = args.Message.Parameters;
int id = receivedContent.GetInteger("id");
// uncomment it to see how the messages get reordered
// verify the big value
//Console.WriteLine("received message {0}", id);
gotMessages[id] = true;
Assert.AreEqual(bigString,
receivedContent.GetString("big"));
args.Message.Reply(null);
});
Parameters content = new Parameters();
content.SetString("big", bigString);
OutgoingMessage[] messages =
new OutgoingMessage[numOfMessages];
// send all messages with different ids and priorities
for (int i = 0; i != numOfMessages; ++i)
{
int id = i;
int priority = i; // increasing priority
content.SetInteger("id", id);
messages[i] = clientAgent.Send(
serverAddress, objectName,
messageName, content, priority);
}
// wait for all messages to complete
for (int i = 0; i != numOfMessages; ++i)
{
messages[i].WaitForCompletion();
messages[i].Close();
}
for (int i = 0; i != numOfMessages; ++i)
{
Assert.IsTrue(gotMessages[i]);
}
}