// --- Reflection mechanisms -------------------------------- static public bool StorePropertiesAndFields(DistEvent e, object obj, bool allProperties = false) { foreach (System.Reflection.PropertyInfo prop in obj.GetType().GetProperties()) { if (allProperties || Attribute.IsDefined(prop, typeof(DistProperty))) { if (!e.SetAttributeValue(prop.Name, DynamicType.CreateDynamicType(prop.GetValue(obj), allProperties))) { return(false); } } } foreach (System.Reflection.FieldInfo field in obj.GetType().GetFields()) { if (allProperties || Attribute.IsDefined(field, typeof(DistProperty))) { if (!e.SetAttributeValue(field.Name, DynamicType.CreateDynamicType(field.GetValue(obj), allProperties))) { return(false); } } } return(true); }
static void Main(string[] args) { // Add a message receiver Message.OnMessage += Message_OnMessage; // Set message level to debug Message.SetMessageLevel(MessageLevel.DEBUG); // Initialize platforms for various used SDKs GizmoSDK.GizmoBase.Platform.Initialize(); GizmoSDK.GizmoDistribution.Platform.Initialize(); // Create a manager. The manager controls it all DistManager manager = DistManager.GetManager(true); // Start the manager with settting for transport protocols manager.Start(DistRemoteChannel.CreateDefaultSessionChannel(), DistRemoteChannel.CreateDefaultServerChannel()); //If we want to attach the DistMonitor debugger manager.EnableDebug(true); // Client set up. You are a client that sends and receives information DistClient client = new DistClient("Our Test Client", manager); // We need to tell the client how to initialize client.Initialize(); // Now we can get a session. A kind of a meeting room that is used to exchange various "topics" DistSession session = client.GetSession("MessageSession", true, true); // Joint that session and subribe all events client.JoinSession(session); // Subscribe standard events client.SubscribeEvents(session); // Create a delegete client.OnEvent += Client_OnEvent; for (int i = 0; i < 100; i++) { DistEvent e = manager.GetEvent(); e.SetAttributeValue("Message", "Helluuuu"); e.SetAttributeValue("Count", i); client.SendEvent(e, session); System.Threading.Thread.Sleep(1000); } client.ResignSession(session); client.Uninitialize(); // Some kind of graceful shutdown manager.Shutdown(); // GC and platform uninit is managed by the system automatically }