示例#1
0
            public DistSession GetSession(IntPtr nativeReference)
            {
                // We must allow GetSession for null reference

                if (nativeReference == IntPtr.Zero)
                {
                    return(null);
                }

                lock (instanses)
                {
                    DistSession sess;

                    if (!instanses.TryGetValue(nativeReference, out sess))
                    {
                        sess = new DistSession(nativeReference);

                        instanses.Add(nativeReference, sess);
                    }

                    if (sess == null || !sess.IsValid())
                    {
                        instanses[nativeReference] = sess = new DistSession(nativeReference);
                    }

                    return(sess);
                }
            }
示例#2
0
            public bool SendEvent(DistEvent e, DistSession session)
            {
                if (UseAutoProperty && e.GetType().IsDefined(typeof(DistPropertyAutoStore), true))
                {
                    e.StorePropertiesAndFields();
                }

                return(DistClient_sendEvent(GetNativeReference(), e.GetNativeReference(), session.GetNativeReference()));
            }
示例#3
0
            static private DistSession GetSession(IntPtr s)
            {
                DistSession session = ReferenceDictionary <DistSession> .GetObject(s);

                if (session == null)
                {
                    session = new DistSession(s);
                }

                return(session);
            }
示例#4
0
            public DistSession GetSession(string sessionName, bool create = false, bool global = false, ServerPriority prio = ServerPriority.PRIO_NORMAL)
            {
                IntPtr s = DistManager_getSession(GetNativeReference(), sessionName, create, global, prio);

                DistSession session = ReferenceDictionary <DistSession> .GetObject(s);

                if (session == null)
                {
                    session = new DistSession(s);
                }

                return(session);
            }
示例#5
0
        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);

            System.Threading.Thread.Sleep(10000);

            client.ResignSession(session);

            client.Uninitialize();

            // Some kind of graceful shutdown
            manager.Shutdown();


            // GC and platform uninit is managed by the system automatically
        }
示例#6
0
        private static void Client_OnNewObject(DistClient sender, DistObject o, DistSession session)
        {
            if (object_counter == 0)
            {
                new_object_timer = new Timer();
            }

            object_counter++;

            sender.SubscribeAttributes(o, true);

            if (object_counter == OBJECTS)
            {
                Console.WriteLine($"Got {OBJECTS} new objects in {new_object_timer.GetTime()} seconds -> Frequency: {new_object_timer.GetFrequency(OBJECTS)} ");
                object_counter = 0;
            }
        }
示例#7
0
            public DistEvent SendEventAndAwaitResponse(DistEvent e, DistSession session, DistEvent responseEventType, UInt32 timeout = 100)
            {
                if (UseAutoProperty && e.GetType().IsDefined(typeof(DistPropertyAutoStore), true))
                {
                    e.StorePropertiesAndFields();
                }

                DistEvent response = Reference.CreateObject(DistClient_sendEventAndAwaitResponse(GetNativeReference(), e.GetNativeReference(), session.GetNativeReference(), responseEventType.GetNativeReference(), timeout)) as DistEvent;

                if (response?.IsValid() ?? false)
                {
                    if (UseAutoProperty && response.GetType().IsDefined(typeof(DistPropertyAutoRestore), true))
                    {
                        response.RestorePropertiesAndFields();
                    }
                }

                return(response);
            }
        static void Main(string[] args)
        {
            // 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);

            // Let the manager know about our special event
            manager.RegisterEvent <MessageEvent>();

            // 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("MessageClient", 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);
            client.SubscribeEvents <MessageEvent>(session); // Subscribe MessageEvent as base type

            // Create a delegete
            client.OnEvent += Client_OnEvent;


            // Now loops around some simple program to get strings from console and distribute them as a message app

            while (true)
            {
                string result = Console.ReadLine();

                if (result == "quit")
                {
                    break;
                }

                // get a new empty event from manager
                MessageEvent e = manager.GetEvent <MessageEvent>();

                // set some attributes in the event to any kind of value
                Array.Resize <ComplexType>(ref e.Compis, 1);

                e.Compis[0] = new ComplexType {
                    SenderID = "Aloha", Speed = 27
                };

                e.Message = result;

                e.Time = Time.SystemSeconds;

                e.EnumTest = MessageEvent.Fault.BZ;

                // and send the event on the specific session
                client.SendEvent(e, session);
            }

            client.Uninitialize();

            // Some kind of graceful shutdown
            manager.Shutdown();


            // GC and platform uninit is managed by the system automatically
        }
        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.SubscribeObjects(session, null, true);

            // Create a delegete
            client.OnNewObject        += Client_OnNewObject;
            client.OnNewAttributes    += Client_OnNewAttributes;
            client.OnUpdateAttributes += Client_OnUpdateAttributes;

            DistObject o = manager.GetObject("TestObject");

            client.AddObject(o, session);

            o = client.WaitForObject("TestObject", session);

            DistTransaction update = new DistTransaction();

            for (int i = 0; i < 100; i++)
            {
                update.NewTransaction();

                update.SetAttributeValue("Updater", client.GetClientID().InstanceID.ToString());
                update.SetAttributeValue("Time", Time.SystemSeconds);

                client.UpdateObject(update, o);

                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
        }
示例#10
0
 public DistObject WaitForObject(string objectName, DistSession session, Int32 timeOut = 10)
 {
     return(manager.DistObjectInstanceManager.GetObject(DistClient_waitForObject(GetNativeReference(), objectName, session.GetNativeReference(), timeOut)));
 }
示例#11
0
 public bool SubscribeObjects(DistSession session, string typeName = null, bool notifyExisting = false, Int32 timeOut = 0)
 {
     return(DistClient_subscribeObjects(GetNativeReference(), session.GetNativeReference(), typeName, notifyExisting, timeOut));
 }
示例#12
0
 public bool SendEvent(DistEvent e, DistSession session)
 {
     return(DistClient_sendEvent(GetNativeReference(), e.GetNativeReference(), session.GetNativeReference()));
 }
示例#13
0
        private static void Client_OnUpdateAttributes(DistClient sender, DistNotificationSet notif, DistObject o, DistSession session)
        {
            if (update_counter == OBJECTS)
            {
                update_timer = new Timer();
            }

            update_counter++;

            if (update_counter == OBJECTS * (COUNT + 1))
            {
                Console.WriteLine($"Got {OBJECTS * COUNT} objects updates in {update_timer.GetTime()} seconds -> Frequency: {update_timer.GetFrequency(OBJECTS * COUNT)} ");
                update_counter = 0;
            }

            foreach (var a in notif)
            {
                var b = a.GetValue();

                if (b.Is(DynamicType.Type.GUID))
                {
                    Guid c = b.GetGuid();
                }
            }
        }
示例#14
0
 public T SendEventAndAwaitResponse <T>(DistEvent e, DistSession session, UInt32 timeout = 100) where T : DistEvent
 {
     return(SendEventAndAwaitResponse(e, session, manager.GetEvent <T>(), timeout) as T);
 }
示例#15
0
 public bool SubscribeEvents <T>(DistSession session, Int32 timeOut = 0) where T : DistEvent
 {
     return(SubscribeEvents(session, typeof(T).Name, timeOut));
 }
示例#16
0
        static void Main(string[] args)
        {
            // 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);

            DistTransportType protocol = DistTransportType.MULTICAST;

            //string iface =  "${wi-fi}";

            //string iface = "10.132.0.5";

            string iface = "127.0.0.1";

            string adress = "234.5.6.19";

            ushort server_port = 1122;
            ushort client_port = 2211;



            //string iface = null;

            // Start the manager with settting for transport protocols
            //manager.Start(DistRemoteChannel.CreateDefaultSessionChannel(true,protocol, iface), DistRemoteChannel.CreateDefaultServerChannel(true,protocol, iface));
            manager.Start(DistRemoteChannel.CreateChannel(5000, protocol, adress, client_port, iface), DistRemoteChannel.CreateChannel(5000, protocol, adress, server_port, iface));

            // Client set up. You are a client that sends and receives information
            DistClient client = new DistClient("PerfClient", manager);

            // We need to tell the client how to initialize
            client.Initialize(0, 0);

            // Now we can get a session. A kind of a meeting room that is used to exchange various "topics"
            DistSession session = client.GetSession("PerfSession", true, true);

            // Joint that session and subribe all events
            client.JoinSession(session);
            client.SubscribeEvents(session); // Subscribe All Events

            // Create a delegete
            client.OnEvent += Client_OnEvent;

            Console.WriteLine($"Press <RETURN> to start sending");

            // Now loops around some simple program to get strings from console and distribute them as a message app

            while (true)
            {
                string result = Console.ReadLine();

                if (result == "quit")
                {
                    break;
                }

                // Create COUNT test events

                Timer timer = new Timer();

                DistEvent [] e_arr = new DistEvent[COUNT];

                for (int i = 0; i < COUNT; i++)
                {
                    e_arr[i] = new DistEvent();
                    e_arr[i].SetAttributeValue("Cnt", i);

                    // Set some additional data e.g. two vec3
                    e_arr[i].SetAttributeValue("vec1", new Vec3(1, 2, 3));
                    e_arr[i].SetAttributeValue("vec2", new Vec3(4, 5, 6));
                }

                Console.WriteLine($"Created {COUNT} events in {timer.GetTime()} seconds -> Frequency: { timer.GetFrequency(COUNT)}");

                // Send COUNT events

                timer = new Timer();

                for (
                    int i = 0; i < COUNT; i++)
                {
                    client.SendEvent(e_arr[i], session);
                }

                Console.WriteLine($"Sent {COUNT} events in {timer.GetTime()} seconds -> Frequency: {timer.GetFrequency(COUNT)}");
            }

            while (manager.HasPendingData())
            {
                System.Threading.Thread.Sleep(10);
            }

            client.Uninitialize(true);

            // Some kind of graceful shutdown
            manager.Shutdown();


            // GC and platform uninit is managed by the system automatically
        }
示例#17
0
        static void Main(string[] args)
        {
            // Initialize platforms for various used SDKs
            GizmoSDK.GizmoBase.Platform.Initialize();
            GizmoSDK.GizmoDistribution.Platform.Initialize();

            GizmoSDK.GizmoBase.Message.SetMessageLevel(MessageLevel.DEBUG);

            // Create a manager. The manager controls it all
            DistManager manager = DistManager.GetManager(true);

            DistTransportType protocol = DistTransportType.MULTICAST;

            //string iface =  "127.0.0.1";

            string iface = "";

            // Start the manager with settting for transport protocols
            manager.Start(DistRemoteChannel.CreateDefaultSessionChannel(false, protocol, iface), DistRemoteChannel.CreateDefaultServerChannel(false, protocol, iface));

            // Client set up. You are a client that sends and receives information
            DistClient client = new DistClient("PerfClient", manager);

            // We need to tell the client how to initialize
            client.Initialize(0, 0, true);

            // Now we can get a session. A kind of a meeting room that is used to exchange various "topics"
            DistSession session = client.GetSession("PerfSession", true, true);

            // Joint that session and subribe all events
            client.JoinSession(session);
            client.SubscribeObjects(session); // Subscribe All Objects


            // Create a delegete
            client.OnNewObject        += Client_OnNewObject;
            client.OnNewAttributes    += Client_OnNewAttributes;
            client.OnUpdateAttributes += Client_OnUpdateAttributes;

            Console.WriteLine($"Press <RETURN> to start sending");

            // Now loops around some simple program to get strings from console and distribute them as a message app

            while (true)
            {
                string result = Console.ReadLine();

                if (result == "quit")
                {
                    break;
                }

                Timer timer = new Timer();

                DistObject [] objects = new DistObject[OBJECTS];

                for (int i = 0; i < OBJECTS; i++)
                {
                    objects[i] = manager.GetObject($"Object {i}");

                    client.AddObject(objects[i], session);

                    objects[i] = client.WaitForObject($"Object {i}", session);
                }

                Console.WriteLine($"Added {OBJECTS} objects in {timer.GetTime()} seconds -> Frequency: {timer.GetFrequency(OBJECTS)}");

                // make sure all objects are updated once

                DistTransaction transaction = new DistTransaction();



                for (int j = 0; j < OBJECTS; j++)
                {
                    transaction.NewTransaction();

                    transaction.SetAttributeValue("Test", 0.0);

                    transaction.SetAttributeValue("id", Guid.NewGuid());

                    if (!client.UpdateObject(transaction, objects[j]))
                    {
                        Console.WriteLine("Boo");
                    }
                }

                System.Threading.Thread.Sleep(10);

                // Send COUNT updates on OBJECTS objects

                timer = new Timer();

                for (int i = 0; i < COUNT; i++)
                {
                    for (int j = 0; j < OBJECTS; j++)
                    {
                        transaction.NewTransaction();
                        transaction.SetAttributeValue("Test", timer.GetTime());

                        if (!client.UpdateObject(transaction, objects[j]))
                        {
                            Console.WriteLine("Failed to update object");
                        }
                    }
                }

                Console.WriteLine($"Updated {OBJECTS} objects with {COUNT} updates in {timer.GetTime()} seconds -> Frequency: {timer.GetFrequency(COUNT*OBJECTS)}");
            }

            while (manager.HasPendingData())
            {
                System.Threading.Thread.Sleep(10);
            }

            client.Uninitialize(true);

            // Some kind of graceful shutdown
            manager.Shutdown();


            // GC and platform uninit is managed by the system automatically
        }
示例#18
0
 public bool ResignSession(DistSession session, Int32 timeOut = 0)
 {
     return(DistClient_resignSession(GetNativeReference(), session.GetNativeReference(), timeOut));
 }
        static void Main(string[] args)
        {
            // Add a message receiver
            Message.OnMessage += Message_OnMessage;

            // Set message level to debug
            Message.SetMessageLevel(MessageLevel.DEBUG | MessageLevel.INTERNAL);


            // 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);

            // Register some factories
            manager.RegisterObject <BattlefieldSoldierObject>();
            manager.RegisterObject <BattlefieldVehicleObject>();
            manager.RegisterObject <BattlefieldTimeObject>();

            // Events
            manager.RegisterEvent <BattlefieldTimeSyncEvent>();



            // Start the manager with settting for transport protocols
            var MCastAddress = "234.2.3.100";

            //var networkInterface = "10.23.24.50"; // Update this to your interface ip. E.g. 192.168.100.100.
            ushort serverPort  = 6667;
            ushort sessionPort = 6668;

            var serverChannel  = DistRemoteChannel.CreateChannel(5000, DistTransportType.MULTICAST, MCastAddress, serverPort /*,networkInterface*/);
            var sessionChannel = DistRemoteChannel.CreateChannel(5000, DistTransportType.MULTICAST, MCastAddress, sessionPort /*,networkInterface*/);

            manager.Start(sessionChannel, serverChannel);

            //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("Battlefield", true, true);

            // Joint that session and subribe all events
            client.JoinSession(session);

            // Create a delegete
            client.OnNewObject        += Client_OnNewObject;
            client.OnNewAttributes    += Client_OnNewAttributes;
            client.OnUpdateAttributes += Client_OnUpdateAttributes;

            client.OnEvent += Client_OnEvent;

            // Subscribe all standard objects
            client.SubscribeObjects(session, null, true);

            // Subscribe all standard events
            client.SubscribeEvents(session);


            //DistObject o = manager.GetObject("TestObject");

            //client.AddObject(o, session);

            //o = client.WaitForObject("TestObject", session);

            for (int i = 0; i < 100; i++)
            {
                //DistTransaction update = new DistTransaction();

                //update.SetAttributeValue("Updater", client.GetClientID().InstanceID.ToString());

                //client.UpdateObject(update, o);

                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
        }
示例#20
0
 public bool AddObject(DistObject o, DistSession session, Int32 timeOut = 0)
 {
     return(DistClient_addObject(GetNativeReference(), o.GetNativeReference(), session.GetNativeReference(), timeOut));
 }
示例#21
0
 private static void Client_OnNewAttributes(DistClient sender, DistNotificationSet notif, DistObject o, DistSession session)
 {
     sender.SubscribeAttributeValue(notif, o, true);
 }
示例#22
0
 public bool UnSubscribeObjects(DistSession session, string typeName = null, Int32 timeOut = 0)
 {
     return(DistClient_unsubscribeObjects(GetNativeReference(), session.GetNativeReference(), typeName, timeOut));
 }
示例#23
0
 private static void Client_OnUpdateAttributes(DistClient sender, DistNotificationSet notif, DistObject o, DistSession session)
 {
     foreach (DistAttribute attr in notif)
     {
         System.Console.WriteLine(attr.ToString());
     }
 }
示例#24
0
        static void Main(string[] args)
        {
            // Initialize platforms for various used SDKs
            GizmoSDK.GizmoBase.Platform.Initialize();
            GizmoSDK.GizmoDistribution.Platform.Initialize();


            Message.OnMessage += Message_OnMessage;

            Message.SetMessageLevel(MessageLevel.DEBUG);

            // Create a manager. The manager controls it all
            DistManager manager = DistManager.GetManager(true);

            // Start the manager with settting for transport protocols
            manager.Start();

            DistSession session = manager.GetSession("Perfa", true);

            // First Client -------------------------------------------------------------------

            // Client set up. You are a client that only sends information
            DistClient client = new DistClient("PerfClient", manager);

            // We need to tell the client how to initialize
            client.Initialize(0, 0, true);



            // Second Client -------------------------------------------------------------------

            // Client set up. You are a client that only receives information
            DistClient client2 = new DistClient("PerfClient2", manager);

            // We need to tell the client how to initialize
            client2.Initialize(0, 0, true);

            // Joint that session and subribe all events
            client2.JoinSession(session);
            client2.SubscribeEvents(session); // Subscribe All Events

            // Create a delegete
            client2.OnEvent += Client2_OnEvent;

            System.Threading.Thread.Sleep(100);

            // Create COUNT test event

            Timer timer = new Timer();

            DistEvent[] e_arr = new DistEvent[COUNT];

            for (int i = 0; i < COUNT; i++)
            {
                e_arr[i] = new DistEvent();
                e_arr[i].SetAttributeValue("Cnt", i);

                // Set some additional data e.g. two vec3
                e_arr[i].SetAttributeValue("vec1", new Vec3(1, 2, 3));
                e_arr[i].SetAttributeValue("vec2", new Vec3(4, 5, 6));
            }

            Console.WriteLine($"Created {COUNT} events in {timer.GetTime()} seconds -> Frequency: { timer.GetFrequency(COUNT)}");

            // Send COUNT events

            timer = new Timer();

            for (int i = 0; i < COUNT; i++)
            {
                client.SendEvent(e_arr[i], session);
            }

            Console.WriteLine($"Sent {COUNT} events in {timer.GetTime()} seconds -> Frequency: {timer.GetFrequency(COUNT)}");

            while (manager.HasPendingData() || !stopper)
            {
                System.Threading.Thread.Sleep(10);
            }

            client.Uninitialize(true);
            client2.Uninitialize(true);

            // Some kind of graceful shutdown
            manager.Shutdown();

            // GC and platform uninit is managed by the system automatically
        }
示例#25
0
 private static void Client_OnNewObject(DistClient sender, DistObject o, DistSession session)
 {
     sender.SubscribeAttributes(o, true);
 }