本文整理汇总了C#中Event.SetValue方法的典型用法代码示例。如果您正苦于以下问题:C# Event.SetValue方法的具体用法?C# Event.SetValue怎么用?C# Event.SetValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Event
的用法示例。
在下文中一共展示了Event.SetValue方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AccessDefaultEmitter
public void AccessDefaultEmitter()
{
var e = new
{
EventName = "UserLogin",
Attributes = new
{
UserName = new { Name = "username", Token = TypeToken.STRING, Value = "bob" },
Password = new { Name = "password", Token = TypeToken.UINT64, Value = 0xfeedabbadeadbeefUL },
ClientIP = new { Name = "clientIP", Token = TypeToken.IP_ADDR, Value = IPAddress.Parse("127.0.0.1") },
Successful = new { Name = "successful", Token = TypeToken.BOOLEAN, Value = false }
}
};
// Create the event...
Event ev = new Event(e.EventName);
ev.SetValue(e.Attributes.UserName.Name, e.Attributes.UserName.Value);
ev.SetValue(e.Attributes.Password.Name, e.Attributes.Password.Value);
ev.SetValue(e.Attributes.ClientIP.Name, e.Attributes.ClientIP.Value);
ev.SetValue(e.Attributes.Successful.Name, e.Attributes.Successful.Value);
IEventEmitter emitter = EventEmitter.CreateDefault();
Assert.IsNotNull(emitter);
emitter.Emit(ev);
}
示例2: AccessDefaultListener
public void AccessDefaultListener()
{
var e = new
{
EventName = "UserLogin",
Attributes = new
{
UserName = new { Name = "username", Token = TypeToken.STRING, Value = "bob" },
Password = new { Name = "password", Token = TypeToken.UINT64, Value = 0xfeedabbadeadbeefUL },
ClientIP = new { Name = "clientIP", Token = TypeToken.IP_ADDR, Value = IPAddress.Parse("127.0.0.1") },
Successful = new { Name = "successful", Token = TypeToken.BOOLEAN, Value = false }
}
};
bool done = false;
Event receivedEvent = default(Event);
// Mock an IEventSink that records the incomming event...
Mock<IEventSink> mock = new Mock<IEventSink>();
mock.Setup(framework => framework.HandleEventArrival(It.IsAny<ISinkRegistrationKey>(), It.IsAny<Event>()))
.Callback<ISinkRegistrationKey, Event>((k, ev) =>
{
receivedEvent = ev;
done = true;
});
Event sourceEvent;
using (IEventListener listener = EventListener.CreateDefault())
{
Assert.IsNotNull(listener);
listener.RegisterEventSink(mock.Object).Activate();
IEventEmitter emitter = EventEmitter.CreateDefault();
Assert.IsNotNull(emitter);
// Create the event...
sourceEvent = new Event(e.EventName);
sourceEvent.SetValue(e.Attributes.UserName.Name, e.Attributes.UserName.Value);
sourceEvent.SetValue(e.Attributes.Password.Name, e.Attributes.Password.Value);
sourceEvent.SetValue(e.Attributes.ClientIP.Name, e.Attributes.ClientIP.Value);
sourceEvent.SetValue(e.Attributes.Successful.Name, e.Attributes.Successful.Value);
// give the round-trip 20 seconds to complete, this is extremely generous...
long time_out_ticks = DateTime.Now.Ticks + TimeSpan.FromSeconds(20).Ticks;
while (!done && DateTime.Now.Ticks < time_out_ticks)
{
emitter.Emit(sourceEvent);
Thread.Sleep(1000);
}
}
Assert.IsTrue(done, "Should have received an event");
Assert.AreEqual(sourceEvent[e.Attributes.UserName.Name].GetValue<string>(), receivedEvent[e.Attributes.UserName.Name].GetValue<string>());
Assert.AreEqual(sourceEvent[e.Attributes.Password.Name].GetValue<ulong>(), receivedEvent[e.Attributes.Password.Name].GetValue<ulong>());
Assert.AreEqual(sourceEvent[e.Attributes.ClientIP.Name].GetValue<IPAddress>(), receivedEvent[e.Attributes.ClientIP.Name].GetValue<IPAddress>());
Assert.AreEqual(sourceEvent[e.Attributes.Successful.Name].GetValue<bool>(), receivedEvent[e.Attributes.Successful.Name].GetValue<bool>());
Console.Write(receivedEvent.ToString());
}
示例3: GenerateRandomEvent
/// <summary>
/// Generates a random event suitable for use during testing. The event's attributes
/// are also generated randomly and populated with random data.
/// </summary>
/// <param name="name">the new event's name</param>
/// <param name="maxAttributeCount">maximum number of attributes in the random event.</param>
/// <param name="enc">an encoding for the event</param>
/// <returns>a new populated event.</returns>
public static Event GenerateRandomEvent(string name, int maxAttributeCount, SupportedEncoding enc)
{
int attributesToGenerate = _rand.Next(1, maxAttributeCount);
Event ev = new Event(name);
ev.SetValue("ID", Guid.NewGuid().ToString("B"));
ev.SetValue("Purpose", "This message is randomly generated by a test console. If you're seeing it then someone in your environment is testing.");
for (int i = 1; i < attributesToGenerate; i++)
{
String an = String.Concat("Attribute_", i.ToString("X03"));
TypeToken tt = (TypeToken)_rand.Next((int)TypeToken.MinValue, (int)TypeToken.MaxValue);
switch (tt)
{
case TypeToken.UINT16:
ev.SetValue(an, (UInt16)_rand.Next(UInt16.MinValue, UInt16.MaxValue));
break;
case TypeToken.INT16:
ev.SetValue(an, (Int16)_rand.Next(Int16.MinValue, Int16.MaxValue));
break;
case TypeToken.UINT32:
ev.SetValue(an, (UInt32)_rand.Next(0, Int32.MaxValue));
break;
case TypeToken.INT32:
ev.SetValue(an, (Int32)_rand.Next(Int32.MinValue, Int32.MaxValue));
break;
case TypeToken.STRING:
ev.SetValue(an, GenerateRandomString(_rand.Next(400), enc));
break;
case TypeToken.IP_ADDR:
byte[] addy = new byte[4];
_rand.NextBytes(addy);
ev.SetValue(an, new IPAddress(addy));
break;
case TypeToken.INT64:
ev.SetValue(an, (Int32)_rand.Next(Int32.MinValue, Int16.MaxValue));
break;
case TypeToken.UINT64:
ev.SetValue(an, (Int32)_rand.Next(0, Int32.MaxValue));
break;
case TypeToken.BOOLEAN:
ev.SetValue(an, (_rand.Next() % 2 == 0));
break;
}
}
return ev;
}
示例4: RoundTripSerialize_Event
public void RoundTripSerialize_Event()
{
var e = new
{
EventName = "UserLogin",
Attributes = new
{
UserName = new { Name = "username", Token = TypeToken.STRING, Value = "bob" },
Password = new { Name = "password", Token = TypeToken.UINT64, Value = 0xfeedabbadeadbeefUL },
ClientIP = new { Name = "clientIP", Token = TypeToken.IP_ADDR, Value = IPAddress.Parse("127.0.0.1") },
Successful = new { Name = "successful", Token = TypeToken.BOOLEAN, Value = false }
}
};
// Create the event...
Event ev = new Event(e.EventName);
ev.SetValue(e.Attributes.UserName.Name, e.Attributes.UserName.Value);
ev.SetValue(e.Attributes.Password.Name, e.Attributes.Password.Value);
ev.SetValue(e.Attributes.ClientIP.Name, e.Attributes.ClientIP.Value);
ev.SetValue(e.Attributes.Successful.Name, e.Attributes.Successful.Value);
// Ensure the token types match...
Assert.AreEqual(e.Attributes.UserName.Token, ev[e.Attributes.UserName.Name].TypeToken);
Assert.AreEqual(e.Attributes.Password.Token, ev[e.Attributes.Password.Name].TypeToken);
Assert.AreEqual(e.Attributes.ClientIP.Token, ev[e.Attributes.ClientIP.Name].TypeToken);
Assert.AreEqual(e.Attributes.Successful.Token, ev[e.Attributes.Successful.Name].TypeToken);
// Ensure the values match...
Assert.AreEqual(e.Attributes.UserName.Value, ev[e.Attributes.UserName.Name].GetValue<string>());
Assert.AreEqual(e.Attributes.Password.Value, ev[e.Attributes.Password.Name].GetValue<UInt64>());
Assert.AreEqual(e.Attributes.ClientIP.Value, ev[e.Attributes.ClientIP.Name].GetValue<IPAddress>());
Assert.AreEqual(e.Attributes.Successful.Value, ev[e.Attributes.Successful.Name].GetValue<bool>());
// Serialization requires an IEventTemplateDB, we're gonna mock it here...
var mock = new Mock<IEventTemplateDB>();
Event dummy;
mock.Setup(db => db.TryCreateEvent(It.IsAny<string>(), out dummy, It.IsAny<bool>(), It.IsAny<SupportedEncoding>()))
.Returns(false);
// Perform a roundtrip serialization...
byte[] data = LwesSerializer.Serialize(ev);
Event ev2 = LwesSerializer.Deserialize(data, 0, data.Length, mock.Object);
// Ensure the token types match on the deserialized object...
Assert.AreEqual(e.Attributes.UserName.Token, ev2[e.Attributes.UserName.Name].TypeToken);
Assert.AreEqual(e.Attributes.Password.Token, ev2[e.Attributes.Password.Name].TypeToken);
Assert.AreEqual(e.Attributes.ClientIP.Token, ev2[e.Attributes.ClientIP.Name].TypeToken);
Assert.AreEqual(e.Attributes.Successful.Token, ev2[e.Attributes.Successful.Name].TypeToken);
// Ensure the values match on the deserialized object...
Assert.AreEqual(e.Attributes.UserName.Value, ev2[e.Attributes.UserName.Name].GetValue<string>());
Assert.AreEqual(e.Attributes.Password.Value, ev2[e.Attributes.Password.Name].GetValue<UInt64>());
Assert.AreEqual(e.Attributes.ClientIP.Value, ev2[e.Attributes.ClientIP.Name].GetValue<IPAddress>());
Assert.AreEqual(e.Attributes.Successful.Value, ev2[e.Attributes.Successful.Name].GetValue<bool>());
}
示例5: MyDynamicEvent
public void MyDynamicEvent()
{
var e = new
{
EventName = "MyDynamicEvent",
Attributes = new
{
ValueUInt16 = new
{
Name = "ValueUInt16",
Token = TypeToken.UINT16,
Value = Convert.ToUInt16(_rand.Next(UInt16.MinValue, UInt16.MaxValue))
},
ValueInt16 = new
{
Name = "ValueInt16",
Token = TypeToken.INT16,
Value = Convert.ToInt16(_rand.Next(Int16.MinValue, Int16.MaxValue))
},
ValueUInt32 = new
{
Name = "ValueUInt32",
Token = TypeToken.UINT32,
Value = Convert.ToUInt32(_rand.Next(0, Int32.MaxValue))
},
ValueInt32 = new
{
Name = "ValueInt32",
Token = TypeToken.INT32,
Value = _rand.Next()
},
ValueString = new
{
Name = "ValueString",
Token = TypeToken.STRING,
Value = "This is a string"
},
ValueIPAddress = new
{
Name = "ValueIPAddress",
Token = TypeToken.IP_ADDR,
Value = IPAddress.Parse("127.0.0.1")
},
ValueInt64 = new
{
Name = "ValueInt64",
Token = TypeToken.INT64,
Value = Convert.ToInt64(_rand.Next())
},
ValueUInt64 = new
{
Name = "ValueUInt64",
Token = TypeToken.UINT64,
Value = Convert.ToUInt64(_rand.Next(0, Int32.MaxValue))
},
ValueBoolean = new
{
Name = "ValueBoolean",
Token = TypeToken.BOOLEAN,
Value = (_rand.Next() % 2 == 0)
},
}
};
// Events are immutable; .SetValue methods return a new mutated event
var ev = new Event(e.EventName);
ev.SetValue(e.Attributes.ValueUInt16.Name, e.Attributes.ValueUInt16.Value);
// Ensure the attributes match...
Assert.AreEqual(e.Attributes.ValueUInt16.Token, ev[e.Attributes.ValueUInt16.Name].TypeToken);
Assert.AreEqual(e.Attributes.ValueUInt16.Value, ev[e.Attributes.ValueUInt16.Name].GetValue<UInt16>());
// Be sure to assign it as it mutates...
ev.SetValue(e.Attributes.ValueInt16.Name, e.Attributes.ValueInt16.Value);
// Ensure the attributes match...
Assert.AreEqual(e.Attributes.ValueUInt16.Token, ev[e.Attributes.ValueUInt16.Name].TypeToken);
Assert.AreEqual(e.Attributes.ValueUInt16.Value, ev[e.Attributes.ValueUInt16.Name].GetValue<UInt16>());
Assert.AreEqual(e.Attributes.ValueInt16.Token, ev[e.Attributes.ValueInt16.Name].TypeToken);
Assert.AreEqual(e.Attributes.ValueInt16.Value, ev[e.Attributes.ValueInt16.Name].GetValue<Int16>());
// Be sure to assign it as it mutates...
ev.SetValue(e.Attributes.ValueUInt32.Name, e.Attributes.ValueUInt32.Value);
// Ensure the attributes match...
Assert.AreEqual(e.Attributes.ValueUInt16.Token, ev[e.Attributes.ValueUInt16.Name].TypeToken);
Assert.AreEqual(e.Attributes.ValueUInt16.Value, ev[e.Attributes.ValueUInt16.Name].GetValue<UInt16>());
Assert.AreEqual(e.Attributes.ValueInt16.Token, ev[e.Attributes.ValueInt16.Name].TypeToken);
Assert.AreEqual(e.Attributes.ValueInt16.Value, ev[e.Attributes.ValueInt16.Name].GetValue<Int16>());
Assert.AreEqual(e.Attributes.ValueUInt32.Token, ev[e.Attributes.ValueUInt32.Name].TypeToken);
Assert.AreEqual(e.Attributes.ValueUInt32.Value, ev[e.Attributes.ValueUInt32.Name].GetValue<UInt32>());
// Be sure to assign it as it mutates...
ev.SetValue(e.Attributes.ValueInt32.Name, e.Attributes.ValueInt32.Value);
ev.SetValue(e.Attributes.ValueString.Name, e.Attributes.ValueString.Value);
ev.SetValue(e.Attributes.ValueIPAddress.Name, e.Attributes.ValueIPAddress.Value);
ev.SetValue(e.Attributes.ValueInt64.Name, e.Attributes.ValueInt64.Value);
ev.SetValue(e.Attributes.ValueUInt64.Name, e.Attributes.ValueUInt64.Value);
ev.SetValue(e.Attributes.ValueBoolean.Name, e.Attributes.ValueBoolean.Value);
//.........这里部分代码省略.........