Ejemplo n.º 1
0
        /// <summary>
        /// <para>Attaches the element to the specified host. To overide Attach, please override <see cref="OnAttach(IRenderHost)"/> function.</para>
        /// <para>To set different render technique instead of using technique from host, override <see cref="OnCreateRenderTechnique"/></para>
        /// <para>Attach Flow: <see cref="OnCreateRenderTechnique(IRenderHost)"/> -> Set RenderHost -> Get Effect -> <see cref="OnAttach(IRenderHost)"/> -> <see cref="InvalidateSceneGraph"/></para>
        /// </summary>
        /// <param name="host">The host.</param>
        public void Attach(IRenderHost host)
        {
            if (IsAttached || host == null || host.EffectsManager == null)
            {
                return;
            }
            renderHost           = host;
            this.renderTechnique = OnSetRenderTechnique != null?OnSetRenderTechnique(host) : OnCreateRenderTechnique(host);

            if (renderTechnique == null)
            {
                var techniqueName = RenderHost.EffectsManager.RenderTechniques.FirstOrDefault();
                if (string.IsNullOrEmpty(techniqueName))
                {
                    return;
                }
                renderTechnique = RenderHost.EffectsManager[techniqueName];
            }
            IsAttached = OnAttach(host);
            if (IsAttached)
            {
                Attached();
                OnAttached?.Invoke(this, EventArgs.Empty);
            }
            InvalidateSceneGraph();
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Initializes a sender link.
 /// </summary>
 /// <param name="session">The session within which to create the link.</param>
 /// <param name="name">The link name.</param>
 /// <param name="attach">The attach frame to send for this link.</param>
 /// <param name="onAttached">The callback to invoke when an attach is received from peer.</param>
 public SenderLink(Session session, string name, Attach attach, OnAttached onAttached)
     : base(session, name, onAttached)
 {
     this.settleMode = attach.SndSettleMode;
     this.outgoingList = new LinkedList();
     this.SendAttach(false, this.deliveryCount, attach);
 }
Ejemplo n.º 3
0
        public void TestMethod_DynamicSenderLink()
        {
            string     testName   = "DynamicSenderLink";
            Connection connection = new Connection(address);
            Session    session    = new Session(connection);

            string     targetAddress = null;
            OnAttached onAttached    = (link, attach) =>
            {
                targetAddress = ((Target)attach.Target).Address;
            };

            SenderLink sender = new SenderLink(session, "sender-" + testName, new Target()
            {
                Dynamic = true
            }, onAttached);
            Message message = new Message("hello");

            sender.Send(message, 60000);

            Assert.IsTrue(targetAddress != null, "dynamic target not attached");
            ReceiverLink receiver = new ReceiverLink(session, "receiver-" + testName, targetAddress);

            message = receiver.Receive();
            Assert.IsTrue(message != null, "no message was received.");
            receiver.Accept(message);

            sender.Close();
            receiver.Close();
            session.Close();
            connection.Close();
        }
Ejemplo n.º 4
0
        public void TestMethod_DynamicReceiverLink()
        {
            string     testName   = "DynamicReceiverLink";
            Connection connection = new Connection(address);
            Session    session    = new Session(connection);

            string           remoteSource = null;
            ManualResetEvent attached     = new ManualResetEvent(false);
            OnAttached       onAttached   = (link, attach) => { remoteSource = ((Source)attach.Source).Address; attached.Set(); };
            ReceiverLink     receiver     = new ReceiverLink(session, "receiver-" + testName, new Source()
            {
                Dynamic = true
            }, onAttached);

            attached.WaitOne(10000, waitExitContext);

            Assert.IsTrue(remoteSource != null, "dynamic source not attached");

            SenderLink sender  = new SenderLink(session, "sender-" + testName, remoteSource);
            Message    message = new Message("hello");

            sender.Send(message, 60000);

            message = receiver.Receive();
            Assert.IsTrue(message != null, "no message was received.");
            receiver.Accept(message);

            sender.Close();
            receiver.Close();
            session.Close();
            connection.Close();
        }
 /// <summary>
 /// Initializes a sender link.
 /// </summary>
 /// <param name="session">The session within which to create the link.</param>
 /// <param name="name">The link name.</param>
 /// <param name="attach">The attach frame to send for this link.</param>
 /// <param name="onAttached">The callback to invoke when an attach is received from peer.</param>
 public SenderLink(Session session, string name, Attach attach, OnAttached onAttached)
     : base(session, name, onAttached)
 {
     this.settleMode   = attach.SndSettleMode;
     this.outgoingList = new LinkedList();
     this.SendAttach(false, this.deliveryCount, attach);
 }
Ejemplo n.º 6
0
        public void run()
        {
            // Send the messages
            ManualResetEvent senderAttached   = new ManualResetEvent(false);
            OnAttached       onSenderAttached = (l, a) => { senderAttached.Set(); };
            Address          address          = new Address(string.Format("amqp://{0}", brokerUrl));
            Connection       connection       = new Connection(address);
            Session          session          = new Session(connection);
            SenderLink       sender           = new SenderLink(session,
                                                               "Lite-amqp-large-content-test-sender",
                                                               new Target()
            {
                Address = queueName
            },
                                                               onSenderAttached);

            if (senderAttached.WaitOne(10000))
            {
                foreach (Message message in AllMessages())
                {
                    sender.Send(message);
                }
            }
            else
            {
                throw new ApplicationException(string.Format(
                                                   "Time out attaching to test broker {0} queue {1}", brokerUrl, queueName));
            }

            sender.Close();
            session.Close();
            connection.Close();
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Initializes the link.
 /// </summary>
 /// <param name="session">The session.</param>
 /// <param name="name">The link name.</param>
 /// <param name="onAttached">The callback to handle received attach.</param>
 protected Link(Session session, string name, OnAttached onAttached)
 {
     this.session = session;
     this.name = name;
     this.onAttached = onAttached;
     this.handle = session.AddLink(this);
     this.state = LinkState.Start;
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Initializes a receiver link.
 /// </summary>
 /// <param name="session">The session within which to create the link.</param>
 /// <param name="name">The link name.</param>
 /// <param name="attach">The attach frame to send for this link.</param>
 /// <param name="onAttached">The callback to invoke when an attach is received from peer.</param>
 public ReceiverLink(Session session, string name, Attach attach, OnAttached onAttached)
     : base(session, name, onAttached)
 {
     this.totalCredit = -1;
     this.receivedMessages = new LinkedList();
     this.waiterList = new LinkedList();
     this.SendAttach(true, 0, attach);
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Initializes the link.
 /// </summary>
 /// <param name="session">The session.</param>
 /// <param name="name">The link name.</param>
 /// <param name="onAttached">The callback to handle received attach.</param>
 protected Link(Session session, string name, OnAttached onAttached)
 {
     this.session    = session;
     this.name       = name;
     this.onAttached = onAttached;
     this.handle     = session.AddLink(this);
     this.state      = LinkState.Start;
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Initializes a receiver link.
 /// </summary>
 /// <param name="session">The session within which to create the link.</param>
 /// <param name="name">The link name.</param>
 /// <param name="attach">The attach frame to send for this link.</param>
 /// <param name="onAttached">The callback to invoke when an attach is received from peer.</param>
 public ReceiverLink(Session session, string name, Attach attach, OnAttached onAttached)
     : base(session, name, onAttached)
 {
     this.totalCredit      = -1;
     this.receivedMessages = new LinkedList();
     this.waiterList       = new LinkedList();
     this.SendAttach(true, 0, attach);
 }
Ejemplo n.º 11
0
        static void Main(string[] args)
        {
            if (args.Length != 2 && args.Length != 3)
            {
                Console.Error.WriteLine("Usage: TopicReceive <connection-url> <address> [<message-count>]");
                Environment.Exit(1);
            }

            string connUrl  = args[0];
            string address  = args[1];
            int    desired  = 0;
            int    received = 0;

            if (args.Length == 3)
            {
                desired = Int32.Parse(args[2]);
            }

            Connection conn = new Connection(new Address(connUrl));

            try
            {
                Session session = new Session(conn);

                Source source = new Source()
                {
                    Address      = address,
                    Capabilities = new Symbol[] { "topic" },
                };

                OnAttached onAttached = (link, attach) =>
                {
                    Console.WriteLine("RECEIVE: Opened receiver for source address '{0}'", address);
                };

                ReceiverLink receiver = new ReceiverLink(session, "r1", source, onAttached);

                while (true)
                {
                    Message message = receiver.Receive();
                    receiver.Accept(message);

                    Console.WriteLine("RECEIVE: Received message '{0}'", message.Body);

                    received++;

                    if (received == desired)
                    {
                        break;
                    }
                }
            }
            finally
            {
                conn.Close();
            }
        }
        public void Attach(List <DeviceAlignmentAnchor> anchors)
        {
            if (m_Filler != null)
            {
                m_WasFillerEnabled = m_Filler.enabled;
                m_Filler.enabled   = false;
            }

            if (m_HideInVr)
            {
                m_WasActive = gameObject.activeSelf;
                gameObject.SetActive(false);
                return;
            }

            var anchor = anchors.Find(x => x.device == m_Device && x.alignment == m_Alignment);

            if (anchor == null)
            {
                Debug.LogError($"[{nameof(VRAnchor)}] anchor for {m_Device} device with {m_Alignment} alignment not found!");
                return;
            }

            if (m_RectTransform == null)
            {
                m_RectTransform = GetComponent <RectTransform>();
            }

            m_InitialParent = m_RectTransform.parent;
            m_SiblingIndex  = m_RectTransform.GetSiblingIndex();

            m_AnchorMin = m_RectTransform.anchorMin;
            m_AnchorMax = m_RectTransform.anchorMax;
            m_Pivot     = m_RectTransform.pivot;

            m_Position = m_RectTransform.localPosition;
            m_Rotation = m_RectTransform.localEulerAngles;
            m_Scale    = m_RectTransform.localScale;

            m_RectTransform.SetParent(anchor.transform);

            // only change if anchors are equal and therefore not stretched to fit
            if (m_RectTransform.anchorMin == m_RectTransform.anchorMax)
            {
                m_RectTransform.anchorMin = m_RectTransform.anchorMax = k_AnchorMinMaxPivots[m_Alignment];
            }
            m_RectTransform.pivot = k_AnchorMinMaxPivots[m_Alignment];

            m_RectTransform.localPosition    = m_PositionOffset;
            m_RectTransform.localEulerAngles = Vector3.zero;
            m_RectTransform.localScale       = Vector3.one;

            OnAttached?.Invoke();
        }
Ejemplo n.º 13
0
        public void run()
        {
            ManualResetEvent receiverAttached   = new ManualResetEvent(false);
            OnAttached       onReceiverAttached = (l, a) => { receiverAttached.Set(); };
            Address          address            = new Address(string.Format("amqp://{0}", brokerUrl));
            Connection       connection         = new Connection(address);
            Session          session            = new Session(connection);
            ReceiverLink     receiverlink       = new ReceiverLink(session,
                                                                   "Lite-amqp-types-test-receiver",
                                                                   new Source()
            {
                Address = queueName
            },
                                                                   onReceiverAttached);

            if (receiverAttached.WaitOne(10000))
            {
                while (nReceived < nExpected)
                {
                    Message message = receiverlink.Receive(System.TimeSpan.FromSeconds(10));
                    if (message != null)
                    {
                        nReceived += 1;
                        receiverlink.Accept(message);
                        MessageValue mv = new MessageValue(message.Body);
                        mv.Decode();

                        if (mv.QpiditTypeName != amqpType)
                        {
                            throw new ApplicationException(string.Format
                                                               ("Incorrect AMQP type found in message body: expected: {0}; found: {1}",
                                                               amqpType, mv.QpiditTypeName));
                        }
                        //Console.WriteLine("{0} [{1}]", mv.QpiditTypeName, mv.ToString());
                        receivedMessageValues.Add(mv);
                    }
                    else
                    {
                        throw new ApplicationException(string.Format(
                                                           "Time out receiving message {0} of {1}", nReceived + 1, nExpected));
                    }
                }
            }
            else
            {
                throw new ApplicationException(string.Format(
                                                   "Time out attaching to test broker {0} queue {1}", brokerUrl, queueName));
            }

            receiverlink.Close();
            session.Close();
            connection.Close();
        }
Ejemplo n.º 14
0
        public void run()
        {
            List <Message> messagesToSend = new List <Message>();

            // Deserialize the json message list
            JavaScriptSerializer jss = new JavaScriptSerializer();
            var itMsgs = jss.Deserialize <dynamic>(jsonMessages);

            //if (!(itMsgs is Array))
            //    throw new ApplicationException(String.Format(
            //        "Messages are not formatted as a json list: {0}, but as type: {1}", jsonMessages, itMsgs.GetType().Name));

            // Generate messages
            foreach (object itMsg in itMsgs)
            {
                MessageValue mv = new MessageValue(amqpType, itMsg);
                mv.Encode();
                messagesToSend.Add(mv.ToMessage());
            }

            // Send the messages
            ManualResetEvent senderAttached   = new ManualResetEvent(false);
            OnAttached       onSenderAttached = (l, a) => { senderAttached.Set(); };
            Address          address          = new Address(string.Format("amqp://{0}", brokerUrl));
            Connection       connection       = new Connection(address);
            Session          session          = new Session(connection);
            SenderLink       sender           = new SenderLink(session,
                                                               "Lite-amqp-types-test-sender",
                                                               new Target()
            {
                Address = queueName
            },
                                                               onSenderAttached);

            if (senderAttached.WaitOne(10000))
            {
                foreach (Message message in messagesToSend)
                {
                    sender.Send(message);
                }
            }
            else
            {
                throw new ApplicationException(string.Format(
                                                   "Time out attaching to test broker {0} queue {1}", brokerUrl, queueName));
            }

            sender.Close();
            session.Close();
            connection.Close();
        }
Ejemplo n.º 15
0
 /// <summary>
 /// <para>Attaches the element to the specified host. To overide Attach, please override <see cref="OnAttach(IRenderHost)"/> function.</para>
 /// <para>Attach Flow: Set RenderHost -> Get Effect ->
 /// <see cref="OnAttach(IRenderHost)"/> -> <see cref="OnAttach"/> -> <see cref="InvalidateRender"/></para>
 /// </summary>
 /// <param name="host">The host.</param>
 public void Attach(IRenderHost host)
 {
     if (IsAttached || host == null)
     {
         return;
     }
     RenderHost = host;
     IsAttached = OnAttach(host);
     if (IsAttached)
     {
         OnAttached?.Invoke(this, EventArgs.Empty);
     }
     InvalidateAll();
 }
Ejemplo n.º 16
0
        public void TestMethod_RequestResponse()
        {
            string     testName   = "RequestResponse";
            Connection connection = new Connection(address);
            Session    session    = new Session(connection);

            // server app: the request handler
            ReceiverLink requestLink = new ReceiverLink(session, "srv.requester-" + testName, "q1");

            requestLink.Start(10, (l, m) =>
            {
                l.Accept(m);

                // got a request, send back a reply
                SenderLink sender = new SenderLink(session, "srv.replier-" + testName, m.Properties.ReplyTo);
                Message reply     = new Message("received");
                reply.Properties  = new Properties()
                {
                    CorrelationId = m.Properties.MessageId
                };
                sender.Send(reply, (a, b, c) => ((Link)c).Close(0), sender);
            });

            // client: setup a temp queue and waits for responses
            OnAttached onAttached = (l, at) =>
            {
                // client: sends a request to the request queue, specifies the temp queue as the reply queue
                SenderLink sender  = new SenderLink(session, "cli.requester-" + testName, "q1");
                Message    request = new Message("hello");
                request.Properties = new Properties()
                {
                    MessageId = "request1", ReplyTo = ((Source)at.Source).Address
                };
                sender.Send(request, (a, b, c) => ((Link)c).Close(0), sender);
            };
            ReceiverLink responseLink = new ReceiverLink(session, "cli.responder-" + testName, new Source()
            {
                Dynamic = true
            }, onAttached);
            Message response = responseLink.Receive();

            Assert.IsTrue(response != null, "no response was received");
            responseLink.Accept(response);

            requestLink.Close();
            responseLink.Close();
            session.Close();
            connection.Close();
        }
Ejemplo n.º 17
0
        // Unsubscribing a durable subscription involves recovering an existing
        // subscription and then closing the receiver link explicitly or in AMQP
        // terms the close value of the Detach frame should be 'true'
        private static void UnsubscribeDurableSubscription()
        {
            Connection connection = new Connection(new Address(DEFAULT_BROKER_URI),
                                                   SaslProfile.Anonymous,
                                                   new Open()
            {
                ContainerId = DEFAULT_CONTAINER_ID
            }, null);

            try
            {
                Session          session         = new Session(connection);
                Source           recoveredSource = null;
                ManualResetEvent attached        = new ManualResetEvent(false);

                OnAttached onAttached = (link, attach) =>
                {
                    recoveredSource = (Source)attach.Source;
                    attached.Set();
                };

                ReceiverLink receiver = new ReceiverLink(session, DEFAULT_SUBSCRIPTION_NAME, (Source)null, onAttached);

                attached.WaitOne(10000);
                if (recoveredSource == null)
                {
                    // The remote had no subscription matching what we asked for.
                    throw new AmqpException(new Error());
                }
                else
                {
                    Console.WriteLine("  Receovered subscription for address: " + recoveredSource.Address);
                    Console.WriteLine("  Recovered Source Expiry Policy = " + recoveredSource.ExpiryPolicy);
                    Console.WriteLine("  Recovered Source Durability = " + recoveredSource.Durable);
                    Console.WriteLine("  Recovered Source Distribution Mode = " + recoveredSource.DistributionMode);
                }

                // Closing the Receiver vs. detaching it will unsubscribe
                receiver.Close();

                session.Close();
            }
            finally
            {
                connection.Close();
            }
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Initializes the link.
        /// </summary>
        /// <param name="session">The session.</param>
        /// <param name="name">The link name.</param>
        /// <param name="onAttached">The callback to handle received attach.</param>
        protected Link(Session session, string name, OnAttached onAttached)
        {
            if (session == null)
            {
                throw new ArgumentNullException("session");
            }

            if (name == null)
            {
                throw new ArgumentNullException("name");
            }

            this.session    = session;
            this.name       = name;
            this.onAttached = onAttached;
            this.handle     = session.AddLink(this);
            this.state      = LinkState.Start;
        }
Ejemplo n.º 19
0
        public void TestMethod_InterfaceSendReceiveOnAttach()
        {
            string    testName  = "InterfaceSendReceiveOnAttach";
            const int nMsgs     = 200;
            int       nAttaches = 0;

            OnAttached onAttached = (link, attach) => {
                nAttaches++;
            };

            IConnection connection = new Connection(testTarget.Address);
            ISession    session    = connection.CreateSession();
            ISenderLink sender     = session.CreateSender("sender-" + testName, new Target()
            {
                Address = testTarget.Path
            }, onAttached);

            for (int i = 0; i < nMsgs; ++i)
            {
                Message message = new Message("msg" + i);
                message.Properties = new Properties()
                {
                    GroupId = "abcdefg"
                };
                message.ApplicationProperties       = new ApplicationProperties();
                message.ApplicationProperties["sn"] = i;
                sender.Send(message, null, null);
            }

            IReceiverLink receiver = session.CreateReceiver("receiver-" + testName, new Source()
            {
                Address = testTarget.Path
            }, onAttached);

            for (int i = 0; i < nMsgs; ++i)
            {
                Message message = receiver.Receive();
                Trace.WriteLine(TraceLevel.Verbose, "receive: {0}", message.ApplicationProperties["sn"]);
                receiver.Accept(message);
            }

            Assert.AreEqual(2, nAttaches);
            connection.Close();
        }
Ejemplo n.º 20
0
        static void Main(string[] args)
        {
            if (args.Length != 3)
            {
                Console.Error.WriteLine("Usage: QueueSend <connection-url> <address> <message-body>");
                Environment.Exit(1);
            }

            string connUrl     = args[0];
            string address     = args[1];
            string messageBody = args[2];

            Connection conn = new Connection(new Address(connUrl));

            try
            {
                Session session = new Session(conn);

                Target target = new Target()
                {
                    Address      = address,
                    Capabilities = new Symbol[] { "queue" },
                };

                OnAttached onAttached = (link, attach) =>
                {
                    Console.WriteLine("SEND: Opened sender for target address '{0}'", address);
                };

                SenderLink sender = new SenderLink(session, "s1", target, onAttached);

                Message message = new Message(messageBody);

                sender.Send(message);

                Console.WriteLine("SEND: Sent message '{0}'", messageBody);
            }
            finally
            {
                conn.Close();
            }
        }
Ejemplo n.º 21
0
        static void Main(string[] args)
        {
            if (args.Length != 2 && args.Length != 3)
            {
                Console.Error.WriteLine("Usage: DurableSubscribe <connection-url> <address> [<message-count>]");
                Environment.Exit(1);
            }

            string connUrl  = args[0];
            string address  = args[1];
            int    desired  = 0;
            int    received = 0;

            if (args.Length == 3)
            {
                desired = Int32.Parse(args[2]);
            }

            // Set the container ID to a stable value, such as "client-1"
            Connection conn = new Connection(new Address(connUrl),
                                             SaslProfile.Anonymous,
                                             new Open()
            {
                ContainerId = "client-1"
            },
                                             null);

            try
            {
                Session session = new Session(conn);

                // Configure the receiver source for durability
                Source source = new Source()
                {
                    Address = address,
                    // Preserve unsettled delivery state
                    Durable = 2,
                    // Don't expire the source
                    ExpiryPolicy = new Symbol("never"),
                };

                OnAttached onAttached = (link, attach) =>
                {
                    Console.WriteLine("SUBSCRIBE: Opened receiver for source address '{0}'", address);
                };

                // Set the receiver name to a stable value, such as "sub-1"
                ReceiverLink receiver = new ReceiverLink(session, "sub-1", source, onAttached);

                while (true)
                {
                    Message message = receiver.Receive();
                    receiver.Accept(message);

                    Console.WriteLine("SUBSCRIBE: Received message '{0}'", message.Body);

                    received++;

                    if (received == desired)
                    {
                        // Explicitly closing the receiver terminates the subscription
                        // receiver.Close();

                        break;
                    }
                }
            }
            finally
            {
                conn.Close();
            }
        }
Ejemplo n.º 22
0
        public void Attach(HandVR handVR, bool iterateAttachmentPoint = false)
        {
            //Debug.Log("Attach: " + this, gameObject);

            // TO DO: Test if not necessary I did it because maybe detach events are important. But attach should let things as they should be.
            if (Attached)
            {
                //True to avoid possible attach to Slot. Imagine you get from one hand to the other but the from hand is hovering a slot. then the detach will attach grabbable to the slot and then attach to the new hand making a strange effect
                Detach(true);
            }
            else if (Stored)
            {
                TryUnstore(OwnerSlot);
            }

            if (iterateAttachmentPoint)
            {
                currentAttachmentPointIndex++;
            }
            if (currentAttachmentPointIndex == attachmentPoints.Count)
            {
                currentAttachmentPointIndex = 0;
            }

            transform.DOKill();
            transform.parent         = handVR.transform;
            OwnerHandVR              = handVR; //Important to do this and next line before real physic attach (position and rotation) to be able to detach from it if other hand steal it on the fly to the hand
            handVR.AttachedGrabbable = this;
            DisableColliders();                //Disable collider to avoid not desired collisions on attach

            Vector3    attachPositionOffset = Vector3.zero;
            Quaternion attachRotationOffset = Quaternion.identity;

            GetLocalAttachmentPositionAndRotation(handVR.transform, out attachPositionOffset, out attachRotationOffset, handVR.AttachmentPointName.name, iterateAttachmentPoint);

            float attachTime = DataVR.Instance.grabbable.attachTime;

            transform.DOLocalMove(-attachPositionOffset, attachTime).SetEase(Ease.OutSine);
            transform.DOLocalRotate(-attachRotationOffset.eulerAngles, attachTime).SetEase(Ease.OutSine).OnComplete
            (
                () =>
            {
                PhysicsExt.IgnoreCollisions(OwnerHandVR.CharacterVR.CharacterController, Colliders); //Ignore Collisions between this and CharacterVR
                EnableColliders();                                                                   //Enable collider (disabled above, before tween attach) WARNING. it is detected by ontriggerenter of physicsproximityAdjust

                //TrackedPoseDriver approach
                {
                    ////Set final position
                    ////-------------------------------------------------
                    //if (attachmentPoints.Count == 0 || (handVR.AttachmentPointName.name == "" && iterateAttachmentPoint == false))
                    //{
                    //	transform.localPosition = Vector3.zero;
                    //	transform.localRotation = Quaternion.identity;
                    //}
                    //else
                    //{
                    //	transform.localPosition = -attachPositionOffset;
                    //	transform.localRotation = Quaternion.Inverse(attachRotationOffset);
                    //}
                    ////-------------------------------------------------
                }

                //SLOT: as it could be in a slot make it kinematic again
                Rigidbody.interpolation          = RigidbodyInterpolation.None;
                Rigidbody.collisionDetectionMode = CollisionDetectionMode.ContinuousSpeculative;
                //TrackedPoseDriver approach
                {
                    //Original approach
                    //Rigidbody.isKinematic = true;

                    AddTrackedPoseDriver(handVR, attachPositionOffset, attachRotationOffset);
                }
                Rigidbody.useGravity = false;

                state = BelongState.Attached;

                //Events
                OnAttached?.Invoke(handVR);

#if UNITY_EDITOR
                Debug.Log("Attach Grabbable: " + this + " to HandVR: " + handVR, gameObject);
#endif
            }
            );
        }
Ejemplo n.º 23
0
 /// <summary>
 /// Initializes a receiver link.
 /// </summary>
 /// <param name="session">The session within which to create the link.</param>
 /// <param name="name">The link name.</param>
 /// <param name="source">The source on attach that specifies the message source.</param>
 /// <param name="onAttached">The callback to invoke when an attach is received from peer.</param>
 public ReceiverLink(Session session, string name, Source source, OnAttached onAttached)
     : this(session, name, new Attach() { Source = source, Target = new Target() }, onAttached)
 {
 }
Ejemplo n.º 24
0
 IReceiverLink ISession.CreateReceiver(string name, Source source, OnAttached onAttached)
 {
     return(new ReceiverLink(this, name, source, onAttached));
 }
Ejemplo n.º 25
0
 /// <summary>
 /// Initializes a sender link.
 /// </summary>
 /// <param name="session">The session within which to create the link.</param>
 /// <param name="name">The link name.</param>
 /// <param name="target">The target on attach that specifies the message target.</param>
 /// <param name="onAttached">The callback to invoke when an attach is received from peer.</param>
 public SenderLink(Session session, string name, Target target, OnAttached onAttached)
     : this(session, name, new Attach() { Source = new Source(), Target = target }, onAttached)
 {
 }
Ejemplo n.º 26
0
 ISenderLink ISession.CreateSender(string name, Target target, OnAttached onAttached)
 {
     return(new SenderLink(this, name, target, onAttached));
 }
Ejemplo n.º 27
0
        static void Main(string[] args)
        {
            if (args.Length != 3)
            {
                Console.Error.WriteLine("Usage: Request <connection-url> <address> <message-body>");
                Environment.Exit(1);
            }

            string connUrl     = args[0];
            string address     = args[1];
            string messageBody = args[2];

            Connection conn = new Connection(new Address(connUrl));

            try
            {
                Session session = new Session(conn);

                Target target = new Target()
                {
                    Address = address,
                };

                OnAttached onSenderAttached = (link, attach) =>
                {
                    Console.WriteLine("REQUEST: Opened sender for target address '{0}'", address);
                };

                SenderLink sender = new SenderLink(session, "s1", target, onSenderAttached);

                string           responseAddress = null;
                ManualResetEvent done            = new ManualResetEvent(false);

                Source source = new Source()
                {
                    Dynamic = true,
                };

                OnAttached onReceiverAttached = (link, attach) =>
                {
                    Console.WriteLine("REQUEST: Opened dynamic receiver for responses");

                    responseAddress = ((Source)attach.Source).Address;
                    done.Set();
                };

                ReceiverLink receiver = new ReceiverLink(session, "r1", source, onReceiverAttached);
                done.WaitOne();

                Message request = new Message(messageBody);

                request.Properties = new Properties()
                {
                    MessageId = Guid.NewGuid().ToString(),
                    ReplyTo   = responseAddress,
                };

                sender.Send(request);

                Console.WriteLine("REQUEST: Sent request '{0}'", messageBody);

                Message response = receiver.Receive();
                receiver.Accept(response);

                Console.WriteLine("REQUEST: Received response '{0}'", response.Body);
            }
            finally
            {
                conn.Close();
            }
        }
Ejemplo n.º 28
0
 /// <summary>
 /// Initializes a receiver link.
 /// </summary>
 /// <param name="session">The session within which to create the link.</param>
 /// <param name="name">The link name.</param>
 /// <param name="source">The source on attach that specifies the message source.</param>
 /// <param name="onAttached">The callback to invoke when an attach is received from peer.</param>
 public ReceiverLink(Session session, string name, Source source, OnAttached onAttached)
     : this(session, name, new Attach() { Source = source, Target = new Target() }, onAttached)
 {
 }
Ejemplo n.º 29
0
        //
        // Sample invocation: Interop.Client amqp://guest:guest@localhost:5672 [loopcount]
        //
        static int Main(string[] args)
        {
            String url = "amqp://*****:*****@localhost:5672";
            String requestQueueName = "service_queue";
            int    loopcount        = 1;

            if (args.Length > 0)
            {
                url = args[0];
            }
            if (args.Length > 1)
            {
                loopcount = Convert.ToInt32(args[1]);
            }

            Connection.DisableServerCertValidation = true;
            // uncomment the following to write frame traces
            //Trace.TraceLevel = TraceLevel.Frame;
            //Trace.TraceListener = (f, a) => Console.WriteLine(DateTime.Now.ToString("[hh:mm:ss.fff]") + " " + string.Format(f, a));

            Connection connection = null;

            try
            {
                Address address = new Address(url);
                connection = new Connection(address);
                Session session = new Session(connection);

                // Sender attaches to fixed request queue name
                SenderLink sender = new SenderLink(session, "Interop.Client-sender", requestQueueName);

                // Receiver attaches to dynamic address.
                // Discover its name when it attaches.
                String           replyTo            = "";
                ManualResetEvent receiverAttached   = new ManualResetEvent(false);
                OnAttached       onReceiverAttached = (l, a) =>
                {
                    replyTo = ((Source)a.Source).Address;
                    receiverAttached.Set();
                };

                // Create receiver and wait for it to attach.
                ReceiverLink receiver = new ReceiverLink(
                    session, "Interop.Client-receiver", new Source()
                {
                    Dynamic = true
                }, onReceiverAttached);
                if (receiverAttached.WaitOne(10000))
                {
                    // Receiver is attached.
                    // Send a series of requests, gather and print responses.
                    String[] requests = new String[] {
                        "Twas brillig, and the slithy toves",
                        "Did gire and gymble in the wabe.",
                        "All mimsy were the borogoves,",
                        "And the mome raths outgrabe."
                    };

                    for (int j = 0; j < loopcount; j++)
                    {
                        Console.WriteLine("Pass {0}", j);
                        for (int i = 0; i < requests.Length; i++)
                        {
                            Message request = new Message(requests[i]);
                            request.Properties = new Properties()
                            {
                                MessageId = "request" + i, ReplyTo = replyTo
                            };
                            sender.Send(request);
                            Message response = receiver.Receive(10000);
                            if (null != response)
                            {
                                receiver.Accept(response);
                                Console.WriteLine("Processed request: {0} -> {1}",
                                                  GetContent(request), GetContent(response));
                            }
                            else
                            {
                                Console.WriteLine("Receiver timeout receiving response {0}", i);
                                break;
                            }
                        }
                    }
                }
                else
                {
                    Console.WriteLine("Receiver attach timeout");
                }
                receiver.Close();
                sender.Close();
                session.Close();
                connection.Close();
                return(0);
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception {0}.", e);
                if (null != connection)
                {
                    connection.Close();
                }
            }
            return(1);
        }
Ejemplo n.º 30
0
 /// <summary>
 /// Initializes a sender link.
 /// </summary>
 /// <param name="session">The session within which to create the link.</param>
 /// <param name="name">The link name.</param>
 /// <param name="target">The target on attach that specifies the message target.</param>
 /// <param name="onAttached">The callback to invoke when an attach is received from peer.</param>
 public SenderLink(Session session, string name, Target target, OnAttached onAttached)
     : this(session, name, new Attach() { Source = new Source(), Target = target }, onAttached)
 {
 }
Ejemplo n.º 31
0
        static void Main(string[] args)
        {
            if (args.Length != 2 && args.Length != 3)
            {
                Console.Error.WriteLine("Usage: SharedSubscribe <connection-url> <address> [<message-count>]");
                Environment.Exit(1);
            }

            string connUrl  = args[0];
            string address  = args[1];
            int    desired  = 0;
            int    received = 0;

            if (args.Length == 3)
            {
                desired = Int32.Parse(args[2]);
            }

            // Set the container ID to a stable value, such as "client-1"
            Connection conn = new Connection(new Address(connUrl),
                                             SaslProfile.Anonymous,
                                             new Open()
            {
                ContainerId = "client-1"
            },
                                             null);

            try
            {
                Session session = new Session(conn);

                // Configure the receiver source for sharing
                Source source = new Source()
                {
                    Address = address,
                    // Global means shared across clients (distinct container IDs)
                    Capabilities = new Symbol[] { "shared", "global" },
                };

                OnAttached onAttached = (link, attach) =>
                {
                    Console.WriteLine("SUBSCRIBE: Opened receiver for source address '{0}'", address);
                };

                // Set the receiver name to a stable value, such as "sub-1"
                ReceiverLink receiver = new ReceiverLink(session, "sub-1", source, onAttached);

                while (true)
                {
                    Message message = receiver.Receive();
                    receiver.Accept(message);

                    Console.WriteLine("SUBSCRIBE: Received message '{0}'", message.Body);

                    received++;

                    if (received == desired)
                    {
                        break;
                    }
                }
            }
            finally
            {
                conn.Close();
            }
        }
Ejemplo n.º 32
0
        static void Main(string[] args)
        {
            if (args.Length != 2 && args.Length != 3)
            {
                Console.Error.WriteLine("Usage: Respond <connection-url> <address> [<message-count>]");
                Environment.Exit(1);
            }

            string connUrl  = args[0];
            string address  = args[1];
            int    desired  = 0;
            int    received = 0;

            if (args.Length == 3)
            {
                desired = Int32.Parse(args[2]);
            }

            Connection conn = new Connection(new Address(connUrl));

            try
            {
                Session session = new Session(conn);

                OnAttached onSenderAttached = (link, attach) =>
                {
                    Console.WriteLine("RESPOND: Opened anonymous sender for responses");
                };

                SenderLink sender = new SenderLink(session, "s1", (Target)null, onSenderAttached);

                Source source = new Source()
                {
                    Address = address,
                };

                OnAttached onReceiverAttached = (link, attach) =>
                {
                    Console.WriteLine("RESPOND: Opened receiver for source address '{0}'", address);
                };

                ReceiverLink receiver = new ReceiverLink(session, "r1", source, onReceiverAttached);

                while (true)
                {
                    Message request = receiver.Receive();
                    receiver.Accept(request);

                    Console.WriteLine("RESPOND: Received request '{0}'", request.Body);

                    string responseBody = ((string)request.Body).ToUpper();

                    Message response = new Message(responseBody);

                    response.Properties = new Properties()
                    {
                        To            = request.Properties.ReplyTo,
                        CorrelationId = request.Properties.MessageId,
                    };

                    sender.Send(response);

                    Console.WriteLine("RESPOND: Sent response '{0}'", response.Body);

                    received++;

                    if (received == desired)
                    {
                        break;
                    }
                }
            }
            finally
            {
                conn.Close();
            }
        }