Exemplo n.º 1
0
 public Contact(Vector2 position, Geometry geometry, int feature)
 {
     Position = position;
     ID = new ContactID(geometry, feature);
     MassNormal = 0;
     MassTangent = 0;
     NormalVelocityBias = 0;
     BounceVelocity = 0;
     NormalImpulse = 0;
     TangentImpulse = 0;
     NormalImpulseBias = 0;
 }
Exemplo n.º 2
0
 public Contact(Vector2 position, Geometry geometry, int feature)
 {
     this.Position = position;
     this.ID = new ContactID() { Geometry = geometry, Feature = feature };
     this.massNormal = 0;
     this.massTangent = 0;
     this.normalVelocityBias = 0;
     this.bounceVelocity = 0;
     this.normalImpulse = 0;
     this.tangentImpulse = 0;
     this.normalImpulseBias = 0;
 }
Exemplo n.º 3
0
 public ClipVertex()
 {
     v = new Vec2();
     id = new ContactID();
 }
Exemplo n.º 4
0
 /// <summary>
 /// Blank manifold point with everything zeroed out.
 /// </summary>
 public ManifoldPoint()
 {
     LocalPoint = new Vec2();
     NormalImpulse = TangentImpulse = 0f;
     Id = new ContactID();
 }
 private void RemoveContact(ContactID contactId)
 {
     foreach (var contactViewModel in this.Contacts)
     {
         if (contactViewModel.Contact == contactId)
         {
             this.Contacts.Remove(contactViewModel);
             OnPropertyChanged("Contacts");
             return;
         }
     }
 }
 public ContactEventArgs(ContactID id)
 {
     Contact = id;
 }
Exemplo n.º 7
0
        private void LoadMessages(VATRPChat chat, IntPtr chatRoomPtr)
        {
            IntPtr msgListPtr = LinphoneAPI.linphone_chat_room_get_history(chatRoomPtr, 0);
            if (msgListPtr != IntPtr.Zero)
            {
                MSList msMessagePtr;

                var loggedInContact = _contactSvc.FindLoggedInContact();
                if (loggedInContact == null)
                    return;
                do
                {
                    msMessagePtr.next = IntPtr.Zero;
                    msMessagePtr.prev = IntPtr.Zero;
                    msMessagePtr.data = IntPtr.Zero;

                    msMessagePtr = (MSList) Marshal.PtrToStructure(msgListPtr, typeof (MSList));
                    if (msMessagePtr.data != IntPtr.Zero)
                    {
                        IntPtr tmpPtr = LinphoneAPI.linphone_chat_message_get_from_address(msMessagePtr.data);
                        tmpPtr = LinphoneAPI.linphone_address_as_string(tmpPtr);
                        if (tmpPtr != IntPtr.Zero)
                        {
                            var fromParty = LinphoneAPI.PtrToStringUtf8(tmpPtr).TrimSipPrefix();
                            LinphoneAPI.ortp_free(tmpPtr);

                            tmpPtr = LinphoneAPI.linphone_chat_message_get_to_address(msMessagePtr.data);
                            if (tmpPtr != IntPtr.Zero)
                            {
                                tmpPtr = LinphoneAPI.linphone_address_as_string(tmpPtr);
                                var toParty = LinphoneAPI.PtrToStringUtf8(tmpPtr).TrimSipPrefix();
                                LinphoneAPI.ortp_free(tmpPtr);

                                string dn, un, host;
                                int port;

                                if (fromParty == loggedInContact.ID || toParty == loggedInContact.ID)
                                {
                                    bool isOutgoing = false;
                                    string remoteParty = fromParty;
                                    if (fromParty == loggedInContact.ID)
                                    {
                                        isOutgoing = true;
                                        remoteParty = toParty;
                                    }

                                    if (
                                        !VATRPCall.ParseSipAddressEx(remoteParty, out dn, out un,
                                            out host, out port))
                                        un = "";

                                    if (un.NotBlank())
                                    {
                                        var contactAddress = string.Format("{0}@{1}", un, host);
                                        var contactID = new ContactID(contactAddress, IntPtr.Zero);
                                        var contact = FindContact(contactID);

                                        if (contact == null)
                                        {
                                            contact = new VATRPContact(contactID)
                                            {
                                                DisplayName = dn,
                                                Fullname = un,
                                                SipUsername = un,
                                                RegistrationName = contactAddress
                                            };
                                            _contactSvc.AddContact(contact, "");
                                        }

                                        IntPtr msgPtr = LinphoneAPI.linphone_chat_message_get_text(msMessagePtr.data);
                                        var messageString = string.Empty;
                                        if (msgPtr != IntPtr.Zero)
                                            messageString = LinphoneAPI.PtrToStringUtf8(msgPtr);

                                        if (messageString.NotBlank())
                                        {
                                            var localTime =
                                                Time.ConvertUtcTimeToLocalTime(
                                                    LinphoneAPI.linphone_chat_message_get_time(msMessagePtr.data));
                                            var declineMessage = false;
                                            if (messageString.StartsWith(VATRPChatMessage.DECLINE_PREFIX))
                                            {
                                                messageString = messageString.Substring(VATRPChatMessage.DECLINE_PREFIX.Length);
                                                declineMessage = true;
                                            }
                                            var chatMessage = new VATRPChatMessage(MessageContentType.Text)
                                            {
                                                Direction =
                                                    isOutgoing
                                                        ? MessageDirection.Outgoing
                                                        : MessageDirection.Incoming,
                                                IsIncompleteMessage = false,
                                                MessageTime = localTime,
                                                Content = messageString,
                                                IsRTTMessage = false,
                                                IsDeclineMessage = declineMessage,
                                                IsRead = LinphoneAPI.linphone_chat_message_is_read(msMessagePtr.data) == 1,
                                                Status = LinphoneAPI.linphone_chat_message_get_state(msMessagePtr.data),
                                                Chat = chat
                                            };

                                            chat.AddMessage(chatMessage, false);
                                            chat.UpdateLastMessage(false);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    msgListPtr = msMessagePtr.next;
                } while (msMessagePtr.next != IntPtr.Zero);

            }
        }
Exemplo n.º 8
0
 /**
  * Blank manifold point with everything zeroed ref.
  */
 public ManifoldPoint()
 {
     localPoint = new Vec2();
     normalImpulse = tangentImpulse = 0f;
     id = new ContactID();
 }
Exemplo n.º 9
0
        public void Update(IContactListener listener)
        {
            Manifold oldManifold = _manifold.Clone();

            Evaluate();

            Body bodyA = _fixtureA.Body;
            Body bodyB = _fixtureB.Body;

            int oldCount = oldManifold.PointCount;
            int newCount = _manifold.PointCount;

            if (newCount == 0 && oldCount > 0)
            {
                bodyA.WakeUp();
                bodyB.WakeUp();
            }

            // Slow contacts don't generate TOI events.
            if (bodyA.IsStatic() || bodyA.IsBullet() || bodyB.IsStatic() || bodyB.IsBullet())
            {
                _flags &= ~CollisionFlags.Slow;
            }
            else
            {
                _flags |= CollisionFlags.Slow;
            }

            // Match old contact ids to new contact ids and copy the
            // stored impulses to warm start the solver.
            for (int i = 0; i < _manifold.PointCount; ++i)
            {
                ManifoldPoint mp2 = _manifold.Points[i];
                mp2.NormalImpulse  = 0.0f;
                mp2.TangentImpulse = 0.0f;
                ContactID id2 = mp2.ID;

                for (int j = 0; j < oldManifold.PointCount; ++j)
                {
                    ManifoldPoint mp1 = oldManifold.Points[j];

                    if (mp1.ID.Key == id2.Key)
                    {
                        mp2.NormalImpulse  = mp1.NormalImpulse;
                        mp2.TangentImpulse = mp1.TangentImpulse;
                        break;
                    }
                }
            }

            if (oldCount == 0 && newCount > 0)
            {
                _flags |= CollisionFlags.Touch;
                if (listener != null)
                {
                    listener.BeginContact(this);
                }
            }

            if (oldCount > 0 && newCount == 0)
            {
                _flags &= ~CollisionFlags.Touch;
                if (listener != null)
                {
                    listener.EndContact(this);
                }
            }

            if ((_flags & CollisionFlags.NonSolid) == 0)
            {
                if (listener != null)
                {
                    listener.PreSolve(this, oldManifold);
                }

                // The user may have disabled contact.
                if (_manifold.PointCount == 0)
                {
                    _flags &= ~CollisionFlags.Touch;
                }
            }
        }
        protected override void Execute(CodeActivityContext context)
        {
            try
            {
                // Get the context service.
                IWorkflowContext            Icontext       = context.GetExtension <IWorkflowContext>();
                IOrganizationServiceFactory serviceFactory = context.GetExtension <IOrganizationServiceFactory>();

                // Use the context service to create an instance of IOrganizationService.
                IOrganizationService service = serviceFactory.CreateOrganizationService(Icontext.InitiatingUserId);

                //get input fields
                var birthDate = Birthdate.Get(context) == new DateTime(0001, 01, 01) ? new DateTime(1753, 01, 01) : Birthdate.Get(context);
                var firstName = Firstname.Get(context);
                var lastName  = Lastname.Get(context);
                var userName  = Username.Get(context) == null ? "" : Username.Get(context);

                // made in fetchXML builder
                // Instantiate QueryExpression QEcontact
                var QEcontact = new QueryExpression("contact");

                // Add columns to QEcontact.ColumnSet
                QEcontact.ColumnSet.AddColumns("fullname", "firstname", "lastname", "birthdate", "sdu_brugernavn", "sdu_domne", "emailaddress1", "address1_city", "jobtitle", "sdu_crmomkostningssted", "sdu_brugernavn", "address1_line1");

                // Define filter QEcontact.Criteria // all must match birthdate + sdu_crmudlb + opdateret fra fim
                var QEcontact_Criteria = new FilterExpression();
                QEcontact.Criteria.AddFilter(QEcontact_Criteria);

                // Define filter QEcontact_Criteria // either match on username, or firstname + lastname
                QEcontact_Criteria.FilterOperator = LogicalOperator.Or;
                QEcontact_Criteria.AddCondition("sdu_brugernavn", ConditionOperator.Equal, userName);

                var QEcontact_Criteria_name = new FilterExpression();
                QEcontact_Criteria.AddFilter(QEcontact_Criteria_name);

                // Define filter QEcontact_Criteria_name_birthdate
                QEcontact_Criteria_name.AddCondition("firstname", ConditionOperator.Like, "%" + firstName + "%");
                QEcontact_Criteria_name.AddCondition("lastname", ConditionOperator.Like, "%" + lastName + "%");
                QEcontact_Criteria_name.AddCondition("birthdate", ConditionOperator.On, birthDate);

                var QEcontact_Criteria_state = new FilterExpression();
                QEcontact.Criteria.AddFilter(QEcontact_Criteria_state);

                // define filter QEcontact_Criteria_dates
                QEcontact_Criteria_state.AddCondition("statecode", ConditionOperator.Equal, RecordStatus.Get(context) == false ? 1 : 0);                            // kontoen er inaktiv
                QEcontact_Criteria_state.AddCondition("sdu_crmudlb", ConditionOperator.OnOrAfter, DateTime.Today.AddMonths(ExpirationDateLimit.Get(context) * -1)); // CRM udløb er maksimalt 13 måneder gammelt
                QEcontact_Criteria_state.AddCondition("sdu_crmudlb", ConditionOperator.OnOrBefore, DateTime.Today.AddDays(-1));                                     // CRM er igår eller før
                QEcontact_Criteria_state.AddCondition("jobtitle", ConditionOperator.NotLike, "%Studentermedhjælp%");

                //find records
                var queryResult = service.RetrieveMultiple(QEcontact);

                if (queryResult.Entities.Count == 1)
                {
                    foreach (var record in queryResult.Entities)
                    {
                        // fullname
                        FullnameOutput.Set(context, record.GetAttributeValue <string>("fullname"));

                        // contactid
                        ContactID.Set(context, record.GetAttributeValue <Guid>("contactid").ToString());

                        // omkostningssted
                        var omkStedIdLocal = SearchForRecord(service, "sdu_brugeradmomksted",
                                                             new KeyValuePair <string, string>("sdu_omksted", record.GetAttributeValue <EntityReference>("sdu_crmomkostningssted").Id.ToString()),
                                                             new KeyValuePair <string, string>("", ""),
                                                             "sdu_brugeradmomkstedid");

                        OmkStedId.Set(context, omkStedIdLocal);

                        // domæne
                        String[] seperator_domaene = { "_" };

                        if (omkStedIdLocal != "")
                        {
                            Domaene.Set(context, SearchForRecord(service,
                                                                 "sdu_domner",
                                                                 new KeyValuePair <string, string>("sdu_brugeradmomksted", omkStedIdLocal.Split(seperator_domaene, StringSplitOptions.RemoveEmptyEntries).GetValue(0).ToString()),
                                                                 new KeyValuePair <string, string>("sdu_name", record.GetAttributeValue <string>("sdu_domne")),
                                                                 "sdu_domnerid"));

                            // email domæne
                            String[] seperator_emailDomaene = { "@" };
                            var      emailDomainFromContact = "@" + record.GetAttributeValue <string>("emailaddress1").Split(seperator_emailDomaene, StringSplitOptions.RemoveEmptyEntries).GetValue(1).ToString();

                            EmailDomaene.Set(context, SearchForRecord(service,
                                                                      "sdu_emaildomne",
                                                                      new KeyValuePair <string, string>("sdu_brugeradmomksted", omkStedIdLocal.Split(seperator_domaene, StringSplitOptions.RemoveEmptyEntries).GetValue(0).ToString()),
                                                                      new KeyValuePair <string, string>("sdu_name", emailDomainFromContact.Replace(" ", "")), // remove whitespaces
                                                                      "sdu_emaildomneid"));
                        }
                        else
                        {
                            // set output parameters to empty strings, if no omk sted
                            Domaene.Set(context, "");
                            EmailDomaene.Set(context, "");
                        }

                        // lokation + arbejdsadresse
                        var LokationOptionSetValue = "";

                        switch (record.GetAttributeValue <string>("address1_city"))
                        {
                        case "Odense":
                            LokationOptionSetValue = "100000000";
                            break;

                        case "Odense M":
                            LokationOptionSetValue = "100000000";
                            break;

                        case "Odense C":
                            LokationOptionSetValue = "100000000";
                            break;

                        case "Sønderborg":
                            LokationOptionSetValue = "100000001";
                            break;

                        case "Esbjerg":
                            LokationOptionSetValue = "100000002";
                            break;

                        case "Slagelse":
                            LokationOptionSetValue = "100000003";
                            break;

                        case "Kolding":
                            LokationOptionSetValue = "100000004";
                            break;

                        default:
                            break;
                        }

                        var workAddress = record.GetAttributeValue <string>("address1_line1") == null ? "" : record.GetAttributeValue <string>("address1_line1");

                        if (workAddress.Contains("Campusvej"))
                        {
                            LokationOptionSetValue = LokationOptionSetValue + "_" + "100000000";
                        }
                        else if (workAddress.Contains("J.B. Winsløws Vej"))
                        {
                            LokationOptionSetValue = LokationOptionSetValue + "_" + "100000001";
                        }

                        Lokation.Set(context, LokationOptionSetValue);


                        // stillingsbetegnelse
                        StillingsBetegnelse.Set(context, SearchForRecord(service,
                                                                         "sdu_stikogruppe",
                                                                         new KeyValuePair <string, string>("sdu_name", record.GetAttributeValue <string>("jobtitle") == null ? "" : record.GetAttributeValue <string>("jobtitle")),
                                                                         new KeyValuePair <string, string>("", ""),
                                                                         "sdu_stikogruppeid"));


                        // fødselsdato
                        BirthDateOutput.Set(context, record.GetAttributeValue <DateTime>("birthdate") < new DateTime(1900, 01, 01) ? DateTime.Now : record.GetAttributeValue <DateTime>("birthdate"));

                        // brugernavn
                        UsernameOutput.Set(context, record.GetAttributeValue <string>("sdu_brugernavn"));
                    }
                }
                else
                {
                    FullnameOutput.Set(context, "");
                    ContactID.Set(context, "");
                    OmkStedId.Set(context, "");
                    Domaene.Set(context, "");
                    EmailDomaene.Set(context, "");
                    Lokation.Set(context, "");
                    StillingsBetegnelse.Set(context, "");
                    BirthDateOutput.Set(context, DateTime.Now);
                    UsernameOutput.Set(context, "");
                }
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }
        public void CreateRttConversation(string remoteUsername, IntPtr callPtr)
        {
            string un, host;
            int port;
            VATRPCall.ParseSipAddress(remoteUsername, out un, out host, out port);
            var contactAddress = string.Format("{0}@{1}", un, host.NotBlank() ? host : App.CurrentAccount.ProxyHostname);
            var contactID = new ContactID(contactAddress, IntPtr.Zero);

            VATRPContact contact =
                ServiceManager.Instance.ContactService.FindContact(contactID);
            if (contact == null)
            {
                contact = new VATRPContact(contactID)
                {
                    Fullname = un,
                    DisplayName = un,
                    SipUsername = un,
                    RegistrationName = contactAddress
                };
                ServiceManager.Instance.ContactService.AddContact(contact, string.Empty);
            }
            SetActiveChatContact(contact, callPtr);
            #if false
            if (Chat != null)
                Chat.InsertRttWrapupMarkers(callPtr);
            #endif
        }
Exemplo n.º 12
0
        /// <summary>
        /// Update the contact manifold and touching status.
        /// Note: do not assume the fixture AABBs are overlapping or are valid.
        /// </summary>
        /// <param name="contactManager">The contact manager.</param>
        internal void Update(ContactManager contactManager)
        {
            Manifold oldManifold = Manifold;

            // Re-enable this contact.
            Flags |= ContactFlags.Enabled;

            bool touching;
            bool wasTouching = (Flags & ContactFlags.Touching) == ContactFlags.Touching;

            bool sensor = FixtureA.IsSensor || FixtureB.IsSensor;

            Body bodyA = FixtureA.Body;
            Body bodyB = FixtureB.Body;

            // Is this contact a sensor?
            if (sensor)
            {
                Shape shapeA = FixtureA.Shape;
                Shape shapeB = FixtureB.Shape;
                touching = AABB.TestOverlap(shapeA, ChildIndexA, shapeB, ChildIndexB, ref bodyA.Xf, ref bodyB.Xf);

                // Sensors don't generate manifolds.
                Manifold.PointCount = 0;
            }
            else
            {
                Evaluate(ref Manifold, ref bodyA.Xf, ref bodyB.Xf);
                touching = Manifold.PointCount > 0;

                // Match old contact ids to new contact ids and copy the
                // stored impulses to warm start the solver.
                for (int i = 0; i < Manifold.PointCount; ++i)
                {
                    ManifoldPoint mp2 = Manifold.Points[i];
                    mp2.NormalImpulse  = 0.0f;
                    mp2.TangentImpulse = 0.0f;
                    ContactID id2   = mp2.Id;
                    bool      found = false;

                    for (int j = 0; j < oldManifold.PointCount; ++j)
                    {
                        ManifoldPoint mp1 = oldManifold.Points[j];

                        if (mp1.Id.Key == id2.Key)
                        {
                            mp2.NormalImpulse  = mp1.NormalImpulse;
                            mp2.TangentImpulse = mp1.TangentImpulse;
                            found = true;
                            break;
                        }
                    }
                    if (found == false)
                    {
                        mp2.NormalImpulse  = 0.0f;
                        mp2.TangentImpulse = 0.0f;
                    }

                    Manifold.Points[i] = mp2;
                }

                if (touching != wasTouching)
                {
                    bodyA.Awake = true;
                    bodyB.Awake = true;
                }
            }

            if (touching)
            {
                Flags |= ContactFlags.Touching;
            }
            else
            {
                Flags &= ~ContactFlags.Touching;
            }

            if (wasTouching == false && touching)
            {
                //Report the collision to both participants:
                if (FixtureA != null)
                {
                    if (FixtureA.OnCollision != null)
                    {
                        Enabled = FixtureA.OnCollision(FixtureA, FixtureB, this);
                    }
                }

                //Reverse the order of the reported fixtures. The first fixture is always the one that the
                //user subscribed to.
                if (FixtureB != null)
                {
                    if (FixtureB.OnCollision != null)
                    {
                        Enabled = FixtureB.OnCollision(FixtureB, FixtureA, this);
                    }
                }

                //BeginContact can also return false and disable the contact
                if (contactManager.BeginContact != null)
                {
                    Enabled = contactManager.BeginContact(this);
                }

                //if the user disabled the contact (needed to exclude it in TOI solver), we also need to mark
                //it as not touching.
                if (Enabled == false)
                {
                    Flags &= ~ContactFlags.Touching;
                }
            }

            if (wasTouching && touching == false)
            {
                //Report the separation to both participants:
                if (FixtureA != null && FixtureA.OnSeparation != null)
                {
                    FixtureA.OnSeparation(FixtureA, FixtureB);
                }

                //Reverse the order of the reported fixtures. The first fixture is always the one that the
                //user subscribed to.
                if (FixtureB != null && FixtureB.OnSeparation != null)
                {
                    FixtureB.OnSeparation(FixtureB, FixtureA);
                }

                if (contactManager.EndContact != null)
                {
                    contactManager.EndContact(this);
                }
            }

            if (sensor)
            {
                return;
            }

            if (contactManager.PreSolve != null)
            {
                contactManager.PreSolve(this, ref oldManifold);
            }
        }
Exemplo n.º 13
0
 public bool Equals(ContactID obj)
 {
     return(this.Geometry == obj.Geometry &&
            this.Feature == obj.Feature);
 }
Exemplo n.º 14
0
        /// <summary>
        /// Update the contact manifold and touching status.
        /// Note: do not assume the fixture AABBs are overlapping or are valid.
        /// </summary>
        /// <param name="contactManager">The contact manager.</param>
        internal void Update(ContactManager contactManager)
        {
            Body bodyA = FixtureA.Body;
            Body bodyB = FixtureB.Body;

            if (FixtureA == null || FixtureB == null)
            {
                return;
            }

            Manifold oldManifold = Manifold;

            // Re-enable this contact.
            Enabled = true;

            bool touching;
            bool wasTouching = IsTouching;

            bool sensor = FixtureA.IsSensor || FixtureB.IsSensor;

            // Is this contact a sensor?
            if (sensor)
            {
                Shape shapeA = FixtureA.Shape;
                Shape shapeB = FixtureB.Shape;
                touching = Collision.Collision.TestOverlap(shapeA, ChildIndexA, shapeB, ChildIndexB, ref bodyA._xf, ref bodyB._xf);

                // Sensors don't generate manifolds.
                Manifold.PointCount = 0;
            }
            else
            {
                Evaluate(ref Manifold, ref bodyA._xf, ref bodyB._xf);
                touching = Manifold.PointCount > 0;

                // Match old contact ids to new contact ids and copy the
                // stored impulses to warm start the solver.
                for (int i = 0; i < Manifold.PointCount; ++i)
                {
                    ManifoldPoint mp2 = Manifold.Points[i];
                    mp2.NormalImpulse  = 0.0f;
                    mp2.TangentImpulse = 0.0f;
                    ContactID id2 = mp2.Id;

                    for (int j = 0; j < oldManifold.PointCount; ++j)
                    {
                        ManifoldPoint mp1 = oldManifold.Points[j];

                        if (mp1.Id.Key == id2.Key)
                        {
                            mp2.NormalImpulse  = mp1.NormalImpulse;
                            mp2.TangentImpulse = mp1.TangentImpulse;
                            break;
                        }
                    }

                    Manifold.Points[i] = mp2;
                }

                if (touching != wasTouching)
                {
                    bodyA.Awake = true;
                    bodyB.Awake = true;
                }
            }

            IsTouching = touching;

            if (wasTouching == false)
            {
                if (touching)
                {
#if (AllCollisionCallbacksAgree)
                    {
                        bool enabledA = true, enabledB = true;

                        // Report the collision to both participants. Track which ones returned true so we can
                        // later call OnSeparation if the contact is disabled for a different reason.
                        enabledA = FixtureA.RaiseOnCollision(FixtureA, FixtureB, this) && enabledA;

                        // Reverse the order of the reported fixtures. The first fixture is always the one that the
                        // user subscribed to.
                        enabledB = FixtureB.RaiseOnCollision(FixtureB, FixtureA, this) && enabledB;

                        Enabled = enabledA && enabledB;

                        // BeginContact can also return false and disable the contact
                        if (enabledA && enabledB && contactManager.BeginContact != null)
                        {
                            Enabled = contactManager.BeginContact(this);
                        }
                    }
#else
                    {
                        //Report the collision to both participants:
                        Enabled = FixtureA.RaiseOnCollision(FixtureA, FixtureB, this);

                        //Reverse the order of the reported fixtures. The first fixture is always the one that the
                        //user subscribed to.
                        Enabled = FixtureB.RaiseOnCollision(FixtureB, FixtureA, this);

                        //BeginContact can also return false and disable the contact
                        if (contactManager.BeginContact != null)
                        {
                            Enabled = contactManager.BeginContact(this);
                        }
                    }
#endif
                    // If the user disabled the contact (needed to exclude it in TOI solver) at any point by
                    // any of the callbacks, we need to mark it as not touching and call any separation
                    // callbacks for fixtures that didn't explicitly disable the collision.
                    if (!Enabled)
                    {
                        IsTouching = false;
                    }
                }
            }
            else
            {
                if (touching == false)
                {
                    //Report the separation to both participants:
                    FixtureA?.RaiseOnSeparation(FixtureA, FixtureB);

                    //Reverse the order of the reported fixtures. The first fixture is always the one that the
                    //user subscribed to.
                    FixtureB?.RaiseOnSeparation(FixtureB, FixtureA);

                    contactManager.EndContact?.Invoke(this);
                }
            }

            if (sensor)
            {
                return;
            }

            if (contactManager.PreSolve != null)
            {
                contactManager.PreSolve(this, ref oldManifold);
            }
        }
Exemplo n.º 15
0
 public VATRPContact FindContact(ContactID contactID)
 {
     if (contactID == null)
     {
         return null;
     }
     return this.FindContact(contactID.ID);
 }
Exemplo n.º 16
0
 public ChatID(ContactID contactId, bool isRTT, string dialogId)
     : base(contactId.ID, contactId.NativePtr)
 {
     this.DialogID = dialogId;
     this.IsRttChat = isRTT;
 }
Exemplo n.º 17
0
 internal bool SearchContactIfExistOrCreateNew(ContactID contactID, out VATRPContact contact)
 {
     bool flag = false;
     contact = this.FindContact(contactID);
     if (contact == null)
     {
         flag = true;
         contact = new VATRPContact(contactID);
     }
     return flag;
 }
        private void OnCallStateChanged(VATRPCall call)
        {
            if (this.Dispatcher == null)
                return;

            if (this.Dispatcher.Thread != Thread.CurrentThread)
            {
                this.Dispatcher.BeginInvoke((Action)(() => this.OnCallStateChanged(call)));
                return;
            }

            if (call == null)
                return;

            lock (deferredLock)
            {
                if (deferredHideTimer != null && deferredHideTimer.IsEnabled)
                    deferredHideTimer.Stop();
            }

            if (_mainViewModel == null)
                return;

            if (_mainViewModel.ActiveCallModel != null &&
                _mainViewModel.ActiveCallModel.CallState == VATRPCallState.Declined)
            {
                _mainViewModel.ActiveCallModel.DeclinedMessage = string.Empty;
                _mainViewModel.RemoveCalViewModel(_mainViewModel.ActiveCallModel);
            }

            CallViewModel callViewModel = _mainViewModel.FindCallViewModel(call);

            if (callViewModel == null)
            {
                callViewModel = new CallViewModel(_linphoneService, call)
                {
                    CallInfoCtrl = _callInfoView
                };

                callViewModel.CallQualityChangedEvent += OnCallQualityChanged;

                callViewModel.VideoWidth = (int)CombinedUICallViewSize.Width;
                callViewModel.VideoHeight = (int)CombinedUICallViewSize.Height;
                _mainViewModel.AddCalViewModel(callViewModel);
            }

            if ((call.CallState == VATRPCallState.InProgress) ||
                (call.CallState == VATRPCallState.StreamsRunning))
            {
                _mainViewModel.ActiveCallModel = callViewModel;
            }

            if (callViewModel.Declined)
            {
                // do not process declined call
                _mainViewModel.RemoveCalViewModel(callViewModel);
                return;
            }

            if (_mainViewModel.ActiveCallModel == null)
                _mainViewModel.ActiveCallModel = callViewModel;

            LOG.Info(string.Format("CallStateChanged: State - {0}. Call: {1}", call.CallState, call.NativeCallPtr));
            ctrlCall.SetCallViewModel(_mainViewModel.ActiveCallModel);
            VATRPContact contact = null;

            var stopPlayback = false;
            var destroycall = false;
            var callDeclined = false;
            bool isError = false;
            switch (call.CallState)
            {
                case VATRPCallState.Trying:
                    // call started,
                    call.RemoteParty = call.To;
                    callViewModel.OnTrying();
                    _mainViewModel.IsCallPanelDocked = true;

                    if (callViewModel.Contact == null)
                        callViewModel.Contact =
            ServiceManager.Instance.ContactService.FindContact(new ContactID(string.Format("{0}@{1}", call.To.Username, call.To.HostAddress), IntPtr.Zero));

                    if (callViewModel.Avatar == null && callViewModel.Contact != null)
                    {
                        callViewModel.LoadAvatar(callViewModel.Contact.Avatar);
                    }

                    if (callViewModel.Contact == null)
                    {
                        var contactID = new ContactID(string.Format("{0}@{1}", call.To.Username, call.To.HostAddress),
                            IntPtr.Zero);
                        callViewModel.Contact = new VATRPContact(contactID)
                        {
                            DisplayName = call.To.DisplayName,
                            Fullname = call.To.Username,
                            SipUsername = call.To.Username,
                            RegistrationName = contactID.ID
                        };
                    }

                    break;
                case VATRPCallState.InProgress:
                    WakeupScreenSaver();
                    this.ShowSelfPreviewItem.IsEnabled = false;
                    call.RemoteParty = call.From;
                    ServiceManager.Instance.SoundService.PlayRingTone();
                    if (callViewModel.Contact == null)
                        callViewModel.Contact =
            ServiceManager.Instance.ContactService.FindContact(new ContactID(string.Format("{0}@{1}", call.From.Username, call.From.HostAddress), IntPtr.Zero));

                    if (callViewModel.Avatar == null && callViewModel.Contact != null)
                    {
                        callViewModel.LoadAvatar(callViewModel.Contact.Avatar);
                    }

                    if (callViewModel.Contact == null)
                    {
                        var contactID = new ContactID(string.Format("{0}@{1}", call.From.Username, call.From.HostAddress),
                            IntPtr.Zero);
                        callViewModel.Contact = new VATRPContact(contactID)
                        {
                            DisplayName = call.From.DisplayName,
                            Fullname = call.From.Username,
                            SipUsername = call.From.Username,
                            RegistrationName = contactID.ID
                        };
                    }

                    callViewModel.OnIncomingCall();

                    if (_linphoneService.GetActiveCallsCount == 2)
                    {
                        ShowOverlayNewCallWindow(true);
                        ctrlCall.ctrlOverlay.SetNewCallerInfo(callViewModel.CallerInfo);
                    }
                    else
                    {
                        callViewModel.ShowIncomingCallPanel = true;
                    }

                    if (WindowState != WindowState.Minimized)
                        _mainViewModel.IsCallPanelDocked = true;

                    if (_flashWindowHelper != null)
                        _flashWindowHelper.FlashWindow(this);
                    if (WindowState == WindowState.Minimized)
                        this.WindowState = WindowState.Normal;

                    Topmost = true;
                    Activate();
                    Topmost = false;
                    break;
                case VATRPCallState.Ringing:
                    this.ShowSelfPreviewItem.IsEnabled = false;
                    callViewModel.OnRinging();
                    _mainViewModel.IsCallPanelDocked = true;
                    call.RemoteParty = call.To;
                    ctrlCall.ctrlOverlay.SetCallerInfo(callViewModel.CallerInfo);
                    ctrlCall.ctrlOverlay.SetCallState("Ringing");
                    if (callViewModel.Contact == null)
                        callViewModel.Contact =
            ServiceManager.Instance.ContactService.FindContact(new ContactID(string.Format("{0}@{1}", call.To.Username, call.To.HostAddress), IntPtr.Zero));

                    if (callViewModel.Avatar == null && callViewModel.Contact != null)
                    {
                        callViewModel.LoadAvatar(callViewModel.Contact.Avatar);
                    }

                    if (callViewModel.Contact == null)
                    {
                        var contactID = new ContactID(string.Format("{0}@{1}", call.To.Username, call.To.HostAddress),
                            IntPtr.Zero);
                        callViewModel.Contact = new VATRPContact(contactID)
                        {
                            DisplayName = call.To.DisplayName,
                            Fullname = call.To.Username,
                            SipUsername = call.To.Username,
                            RegistrationName = contactID.ID
                        };
                    }

                    ServiceManager.Instance.SoundService.PlayRingBackTone();
                    break;
                case VATRPCallState.EarlyMedia:
                    callViewModel.OnEarlyMedia();
                    break;
                case VATRPCallState.Connected:
                    if (ServiceManager.Instance.ConfigurationService.Get(Configuration.ConfSection.GENERAL,
                        Configuration.ConfEntry.USE_RTT, true))
                    {
                        _mainViewModel.IsRTTViewEnabled = true;
                        ctrlRTT.SetViewModel(_mainViewModel.RttMessagingModel);
                        _mainViewModel.RttMessagingModel.CreateRttConversation(call.RemoteParty.Username, call.NativeCallPtr);
                    }
                    else
                    {
                        _mainViewModel.IsRTTViewEnabled = false;
                    }

                    callViewModel.OnConnected();
                    if (_flashWindowHelper != null)
                        _flashWindowHelper.StopFlashing();
                    stopPlayback = true;
                    callViewModel.ShowOutgoingEndCall = false;
                    callViewModel.IsRTTEnabled =
                        ServiceManager.Instance.ConfigurationService.Get(Configuration.ConfSection.GENERAL,
                            Configuration.ConfEntry.USE_RTT, true) && callViewModel.ActiveCall != null &&
                        _linphoneService.IsRttEnabled(callViewModel.ActiveCall.NativeCallPtr);

                    ShowCallOverlayWindow(true);
                    ShowOverlayNewCallWindow(false);
                    ctrlCall.ctrlOverlay.SetCallerInfo(callViewModel.CallerInfo);
                    ctrlCall.ctrlOverlay.SetCallState("Connected");
                    ctrlCall.ctrlOverlay.ForegroundCallDuration = callViewModel.CallDuration;

                    if (_linphoneService.GetActiveCallsCount == 2)
                    {
                        CallViewModel nextVM = _mainViewModel.GetNextViewModel(callViewModel);
                        if (nextVM != null)
                        {
                            ShowOverlaySwitchCallWindow(true);
                            ctrlCall.ctrlOverlay.SetPausedCallerInfo(nextVM.CallerInfo);
                            ctrlCall.ctrlOverlay.BackgroundCallDuration = nextVM.CallDuration;
                            ctrlCall.ctrlOverlay.StartPausedCallTimer(ctrlCall.ctrlOverlay.BackgroundCallDuration);
                            ctrlCall.BackgroundCallViewModel = nextVM;
                        }
                    }
                    else
                    {
                        ShowOverlaySwitchCallWindow(false);
                    }

                    ctrlCall.ctrlOverlay.StartCallTimer(ctrlCall.ctrlOverlay.ForegroundCallDuration);
                    _callOverlayView.EndCallRequested = false;

                    if (_selfView.IsVisible)
                    {
                        _selfView.ResetNativePreviewHandle = false;
                        _selfView.Hide();
                    }

                    ctrlCall.ctrlVideo.DrawCameraImage = false;
                    ctrlCall.AddVideoControl();
                    ctrlCall.RestartInactivityDetectionTimer();
                    ctrlCall.UpdateVideoSettingsIfOpen();
                    ctrlCall.UpdateMuteSettingsIfOpen();

            //                    MuteCall(createCmd.MuteMicrophone);
            //                    MuteSpeaker(createCmd.MuteSpeaker);

                    break;
                case VATRPCallState.StreamsRunning:
                    callViewModel.OnStreamRunning();
                    ShowCallOverlayWindow(true);

                    // VATRP-1623: we are setting mute microphone true prior to initiating a call, but the call is always started
                    //   with the mic enabled. attempting to mute right after call is connected here to side step this issue -
                    //   it appears to be an initialization issue in linphone
                    if (_linphoneService.GetActiveCallsCount == 1)
                    {
                        ServiceManager.Instance.ApplyMediaSettingsChanges();
                    }
                    ctrlCall.ctrlOverlay.SetCallState("Connected");
                    ctrlCall.UpdateControls();
                    ctrlCall.ctrlOverlay.ForegroundCallDuration = _mainViewModel.ActiveCallModel.CallDuration;
                    ctrlCall.RestartInactivityDetectionTimer();
                    ctrlCall.UpdateVideoSettingsIfOpen();
                    // VATRP-1899: This is a quick and dirty solution for POC. It will be funational, but not the end implementation we will want.
                    if ((App.CurrentAccount != null) && App.CurrentAccount.UserNeedsAgentView)
                    {
                        _mainViewModel.IsMessagingDocked = true;
                    }
                    break;
                case VATRPCallState.RemotePaused:
                    callViewModel.OnRemotePaused();
                    callViewModel.CallState = VATRPCallState.RemotePaused;
                    ShowCallOverlayWindow(true);
                    ctrlCall.ctrlOverlay.SetCallerInfo(callViewModel.CallerInfo);
                    ctrlCall.ctrlOverlay.SetCallState("On Hold");
                    ctrlCall.UpdateControls();
                    break;
                case VATRPCallState.LocalPausing:
                    callViewModel.CallState = VATRPCallState.LocalPausing;
                    break;
                case VATRPCallState.LocalPaused:
                    callViewModel.OnLocalPaused();
                    callViewModel.CallState = VATRPCallState.LocalPaused;
                    callViewModel.IsCallOnHold = true;
                    bool updateInfoView = callViewModel.PauseRequest;
                    if (_linphoneService.GetActiveCallsCount == 2)
                    {
                        if (!callViewModel.PauseRequest)
                        {
                            CallViewModel nextVM = _mainViewModel.GetNextViewModel(callViewModel);

                            if (nextVM != null)
                            {
                                ShowOverlaySwitchCallWindow(true);
                                ctrlCall.ctrlOverlay.SetPausedCallerInfo(callViewModel.CallerInfo);
                                ctrlCall.ctrlOverlay.BackgroundCallDuration = callViewModel.CallDuration;
                                ctrlCall.ctrlOverlay.StartPausedCallTimer(ctrlCall.ctrlOverlay.BackgroundCallDuration);
                                ctrlCall.BackgroundCallViewModel = callViewModel;
                                ctrlCall.ctrlOverlay.ForegroundCallDuration = nextVM.CallDuration;
                                ctrlCall.SetCallViewModel(nextVM);
                                if (!nextVM.PauseRequest)
                                    _mainViewModel.ResumeCall(nextVM);
                                else
                                    updateInfoView = true;
                            }
                        }
                    }

                    if (updateInfoView)
                    {
                        ShowCallOverlayWindow(true);
                        ctrlCall.ctrlOverlay.SetCallerInfo(callViewModel.CallerInfo);
                        ctrlCall.ctrlOverlay.SetCallState("On Hold");
                        ctrlCall.UpdateControls();
                    }
                    break;
                case VATRPCallState.LocalResuming:
                    callViewModel.OnResumed();
                    callViewModel.IsCallOnHold = false;
                    ShowCallOverlayWindow(true);
                    ctrlCall.ctrlOverlay.SetCallerInfo(callViewModel.CallerInfo);
                    ctrlCall.ctrlOverlay.SetCallState("Connected");
                    ctrlCall.UpdateControls();

                    if (_linphoneService.GetActiveCallsCount == 2)
                    {
                        CallViewModel nextVM = _mainViewModel.GetNextViewModel(callViewModel);
                        if (nextVM != null)
                        {
                            ShowOverlaySwitchCallWindow(true);
                            ctrlCall.ctrlOverlay.SetPausedCallerInfo(nextVM.CallerInfo);
                            ctrlCall.ctrlOverlay.BackgroundCallDuration = nextVM.CallDuration ;
                            ctrlCall.ctrlOverlay.StartPausedCallTimer(ctrlCall.ctrlOverlay.BackgroundCallDuration);
                            ctrlCall.BackgroundCallViewModel = nextVM;
                            ctrlCall.SetCallViewModel(callViewModel);
                            ctrlCall.ctrlOverlay.ForegroundCallDuration = callViewModel.CallDuration;
                            if (ServiceManager.Instance.ConfigurationService.Get(Configuration.ConfSection.GENERAL,
                        Configuration.ConfEntry.USE_RTT, true))
                            {
                                _mainViewModel.RttMessagingModel.CreateRttConversation(call.RemoteParty.Username, call.NativeCallPtr);
                            }
                        }
                        else
                        {
                            ShowOverlaySwitchCallWindow(false);
                        }
                    }
                    else
                    {
                        ShowOverlaySwitchCallWindow(false);
                    }
                    ctrlCall.ctrlVideo.DrawCameraImage = false;
                    ctrlCall.AddVideoControl();
                    break;
                case VATRPCallState.Closed:
                    if (_flashWindowHelper != null)
                        _flashWindowHelper.StopFlashing();
                    LOG.Info(string.Format("CallStateChanged: Result Code - {0}. Message: {1} Call: {2}", call.SipErrorCode, call.LinphoneMessage, call.NativeCallPtr));
                    callDeclined = call.SipErrorCode == 603;
                    callViewModel.OnClosed(ref isError, call.LinphoneMessage, call.SipErrorCode, callDeclined);
                    stopPlayback = true;
                    destroycall = true;
                    callViewModel.CallQualityChangedEvent -= OnCallQualityChanged;
                    if (ServiceManager.Instance.ConfigurationService.Get(Configuration.ConfSection.GENERAL,
                       Configuration.ConfEntry.USE_RTT, true))
                    {
                        _mainViewModel.RttMessagingModel.ClearRTTConversation(call.NativeCallPtr);
                        ctrlRTT.SetViewModel(null);
                    }
                    ShowOverlayNewCallWindow(false);
                    ShowOverlaySwitchCallWindow(false);
                    ctrlCall.BackgroundCallViewModel = null;

                    if (callDeclined)
                    {
                        _mainViewModel.IsRTTViewEnabled = false;
                        this.ShowSelfPreviewItem.IsEnabled = true;
                        _callInfoView.Hide();
                        ctrlCall.ctrlOverlay.StopCallTimer();
                        ShowCallOverlayWindow(false);
                        _mainViewModel.IsMessagingDocked = false;
                        if (_mainViewModel.ActiveCallModel.DeclinedMessage.NotBlank())
                            _mainViewModel.ActiveCallModel.ShowDeclinedMessage = true;
                        else
                        {
                            _mainViewModel.ActiveCallModel.WaitForDeclineMessage = true;
                        }
                        if (deferredHideTimer != null)
                        {
                            lock (deferredLock)
                            {
                                deferredHideTimer.Interval = TimeSpan.FromMilliseconds(DECLINE_WAIT_TIMEOUT);
                                deferredHideTimer.Start();
                            }
                        }
                    }
                    else
                    {
                        int callsCount = _mainViewModel.RemoveCalViewModel(callViewModel);
                        if (callsCount == 0)
                        {
                            _mainViewModel.IsRTTViewEnabled = false;
                            this.ShowSelfPreviewItem.IsEnabled = true;
                            _callInfoView.Hide();
                            ctrlCall.ctrlOverlay.StopCallTimer();

                            if (!isError)
                            {
                                this.SizeToContent = SizeToContent.WidthAndHeight;
                                ctrlCall.SetCallViewModel(null);
                                _mainViewModel.IsCallPanelDocked = false;
                            }
                            else
                            {
                                if (deferredHideTimer != null)
                                {
                                    lock (deferredLock)
                                    {
                                        deferredHideTimer.Interval = TimeSpan.FromMilliseconds(DECLINE_WAIT_TIMEOUT);
                                        deferredHideTimer.Start();
                                    }
                                }
                            }
                            ShowCallOverlayWindow(false);
                            _mainViewModel.IsMessagingDocked = false;
                            _mainViewModel.ActiveCallModel = null;
                            OnFullScreenToggled(false); // restore main window to dashboard

                            if (this.ShowSelfPreviewItem.IsChecked && !_selfView.ResetNativePreviewHandle)
                            {
                                _selfView.ResetNativePreviewHandle = true;
                                deferredShowPreviewTimer.Start();
                            }
                        }
                        else
                        {
                            var nextVM = _mainViewModel.GetNextViewModel(null);
                            if (nextVM != null)
                            {
                                // defensive coding here- do not try to operate on an errored call state object
                                if (nextVM.CallState != VATRPCallState.Error)
                                {
                                    _mainViewModel.ActiveCallModel = nextVM;
                                    nextVM.CallSwitchLastTimeVisibility = Visibility.Hidden;

                                    if (ServiceManager.Instance.ConfigurationService.Get(Configuration.ConfSection.GENERAL,
                                        Configuration.ConfEntry.USE_RTT, true))
                                    {
                                        _mainViewModel.IsRTTViewEnabled = true;
                                        ctrlRTT.SetViewModel(_mainViewModel.RttMessagingModel);
                                        _mainViewModel.RttMessagingModel.CreateRttConversation(
                                            nextVM.ActiveCall.RemoteParty.Username, nextVM.ActiveCall.NativeCallPtr);
                                    }
                                    else
                                    {
                                        _mainViewModel.IsRTTViewEnabled = false;
                                    }
                                    ShowCallOverlayWindow(true);
                                    ctrlCall.ctrlOverlay.SetCallerInfo(nextVM.CallerInfo);
                                    ctrlCall.ctrlOverlay.ForegroundCallDuration = _mainViewModel.ActiveCallModel.CallDuration;
                                    ctrlCall.SetCallViewModel(_mainViewModel.ActiveCallModel);
                                    ctrlCall.UpdateControls();
                                    if (nextVM.ActiveCall.CallState == VATRPCallState.LocalPaused)
                                    {
                                        if (!nextVM.PauseRequest)
                                            _mainViewModel.ResumeCall(nextVM);
                                        else
                                        {
                                            ctrlCall.ctrlOverlay.SetCallState("On Hold");
                                        }
                                    }
                                }
                            }
                        }
                    }
                    if ((registerRequested || signOutRequest || defaultConfigRequest) && _linphoneService.GetActiveCallsCount == 0)
                    {
                        _linphoneService.Unregister(false);
                    }

                    break;
                case VATRPCallState.Error:
                    destroycall = true;
                    if (_flashWindowHelper != null)
                        _flashWindowHelper.StopFlashing();
                    ctrlCall.BackgroundCallViewModel = null;
                    isError = true;
                    callViewModel.OnClosed(ref isError, call.LinphoneMessage, call.SipErrorCode, false);
                    callViewModel.CallSwitchLastTimeVisibility = Visibility.Hidden;
                    stopPlayback = true;
                    if (ServiceManager.Instance.ConfigurationService.Get(Configuration.ConfSection.GENERAL,
                       Configuration.ConfEntry.USE_RTT, true))
                    {
                        _mainViewModel.RttMessagingModel.ClearRTTConversation(call.NativeCallPtr);
                        ctrlRTT.SetViewModel(null);
                    }

                    if (_linphoneService.GetActiveCallsCount == 0)
                    {
                        _mainViewModel.IsRTTViewEnabled = false;
                        this.ShowSelfPreviewItem.IsEnabled = true;
                        if (this.ShowSelfPreviewItem.IsChecked && !_selfView.ResetNativePreviewHandle)
                        {
                            _selfView.ResetNativePreviewHandle = true;
                            deferredShowPreviewTimer.Start();
                        }
                        if (callViewModel.CallState != VATRPCallState.Declined)
                            _mainViewModel.RemoveCalViewModel(callViewModel);
                        _callInfoView.Hide();
                        ctrlCall.ctrlOverlay.StopCallTimer();
                        ShowCallOverlayWindow(false);
                        _mainViewModel.IsMessagingDocked = false;

                        if (deferredHideTimer != null)
                        {
                            lock (deferredLock)
                            {
                                deferredHideTimer.Interval = TimeSpan.FromMilliseconds(DECLINE_WAIT_TIMEOUT);
                                deferredHideTimer.Start();
                            }
                        }

                        _mainViewModel.ActiveCallModel = null;
                        OnFullScreenToggled(false); // restore main window to dashboard
                    }
                    else
                    {
                        _mainViewModel.RemoveCalViewModel(callViewModel);
                    }

                    break;
                default:
                    break;
            }

            if (stopPlayback)
            {
                ServiceManager.Instance.SoundService.StopRingBackTone();
                ServiceManager.Instance.SoundService.StopRingTone();
            }

            if (destroycall)
            {
                if (_linphoneService.GetActiveCallsCount == 0)
                {
                    if (_mainViewModel.IsCallPanelDocked)
                    {
                        ServiceManager.Instance.LinphoneService.SetVideoCallWindowHandle(IntPtr.Zero, true);
                        if (_remoteVideoView != null)
                        {
                            _remoteVideoView.DestroyOnClosing = true; // allow window to be closed
                            _remoteVideoView.Close();
                            _remoteVideoView = null;
                        }
                        if (deferredHideTimer != null && !deferredHideTimer.IsEnabled)
                        {
                            _mainViewModel.IsMessagingDocked = false;
                            _mainViewModel.IsCallPanelDocked = false;
                        }
                    }

                    if (!callDeclined)
                        _mainViewModel.ActiveCallModel = null;
                }
            }
        }
Exemplo n.º 19
0
        private void LoadLinphoneChatEvents()
        {
            if (_chatItems == null)
                _chatItems = new ObservableCollection<VATRPChat>();

            if (_linphoneSvc.LinphoneCore == IntPtr.Zero)
                return;

            IntPtr chatRoomPtr = LinphoneAPI.linphone_core_get_chat_rooms(_linphoneSvc.LinphoneCore);
            if (chatRoomPtr != IntPtr.Zero)
            {
                MSList msChatRoomList;

                do
                {
                    msChatRoomList.next = IntPtr.Zero;
                    msChatRoomList.prev = IntPtr.Zero;
                    msChatRoomList.data = IntPtr.Zero;

                    msChatRoomList = (MSList)Marshal.PtrToStructure(chatRoomPtr, typeof(MSList));
                    if (msChatRoomList.data != IntPtr.Zero)
                    {
                        IntPtr tmpPtr = LinphoneAPI.linphone_chat_room_get_peer_address(msChatRoomList.data);
                        if (tmpPtr != IntPtr.Zero)
                        {
                            tmpPtr = LinphoneAPI.linphone_address_as_string(tmpPtr);
                            if (tmpPtr != IntPtr.Zero)
                            {
                                var remoteParty = LinphoneAPI.PtrToStringUtf8(tmpPtr);
                                LinphoneAPI.ortp_free(tmpPtr);
                                 string dn, un, host;
                                int port;
                                if (
                                    !VATRPCall.ParseSipAddressEx( remoteParty, out dn, out un,
                                        out host, out port))
                                    un = "";

                                if (un.NotBlank())
                                {
                                    var contactAddress = string.Format("{0}@{1}", un, host);
                                    var contactId = new ContactID(contactAddress, IntPtr.Zero);
                                    VATRPContact contact = _contactSvc.FindContact(contactId);
                                    if (contact == null)
                                    {
                                        contact = new VATRPContact(contactId)
                                        {
                                            DisplayName = dn,
                                            Fullname = un,
                                            SipUsername = un,
                                            RegistrationName = contactAddress
                                        };
                                        _contactSvc.AddContact(contact, string.Empty);
                                    }

                                    var chat = this.AddChat(contact, string.Empty);
                                    chat.NativePtr = msChatRoomList.data;
                                    LoadMessages(chat, chat.NativePtr);
                                    OnConversationUpdated(chat, true);
                                }
                            }
                        }
                    }
                    chatRoomPtr = msChatRoomList.next;
                } while (msChatRoomList.next != IntPtr.Zero);

            }
            if (ServiceStarted != null)
                ServiceStarted(this, EventArgs.Empty);
        }
Exemplo n.º 20
0
 public ChatID(ContactID contactId, string dialogId)
     : base(contactId.ID, contactId.NativePtr)
 {
     this.DialogID = dialogId;
 }
Exemplo n.º 21
0
        private void OnChatMessageComposing(string remoteUser, IntPtr chatPtr, uint rttCode)
        {
            string dn, un, host;
            int port;
            System.Windows.Threading.Dispatcher dispatcher = null;
            try
            {
                dispatcher = this._serviceManager.Dispatcher;
            }
            catch (NullReferenceException)
            {
                return;
            }
            if (dispatcher != null)
                dispatcher.BeginInvoke((Action) delegate()
                {
                    if (!VATRPCall.ParseSipAddressEx(remoteUser, out dn, out un,
                        out host, out port))
                        un = "";

                    if (!un.NotBlank() )
                        return;
                    var contactAddress = string.Format("{0}@{1}", un, host);
                    var contactID = new ContactID(contactAddress, IntPtr.Zero);

                    VATRPContact contact = FindContact(contactID);

                    if (contact == null)
                    {
                        contact = new VATRPContact(contactID)
                        {
                            DisplayName = dn,
                            Fullname = dn.NotBlank() ? dn : un,
                            RegistrationName = remoteUser,
                            SipUsername = un
                        };
                        _contactSvc.AddContact(contact, "");
                    }

                    VATRPChat chat = GetChat(contact);

                    chat.UnreadMsgCount++;

                    chat.CharsCountInBubble++;
                    var rttCodeArray = new char[2];
                    var rttCodearrayLength = 1;
                    if (chat.CharsCountInBubble == 201)
                    {
                        rttCodeArray[0] = UNLF;
                        try
                        {
                            rttCodeArray[1] = Convert.ToChar(rttCode);
                        }
                        catch (Exception)
                        {

                        }
                        rttCodearrayLength = 2;
                        chat.CharsCountInBubble = 0;
                    }
                    else
                    {
                        try
                        {
                            rttCodeArray[0] = Convert.ToChar(rttCode);
                        }
                        catch
                        {

                        }
                    }

                    for (int i = 0; i < rttCodearrayLength; i++)
                    {
                        VATRPChatMessage message = chat.SearchIncompleteMessage(MessageDirection.Incoming);

                        if (message == null)
                        {
                            message = new VATRPChatMessage(MessageContentType.Text)
                            {
                                Direction = MessageDirection.Incoming,
                                IsIncompleteMessage = true,
                                Chat = chat,
                                IsRTTMarker = false,
                            };

                            chat.AddMessage(message, false);
                        }

                        try
                        {
                            var sb = new StringBuilder(message.Content);
                            switch (rttCodeArray[i])
                            {
                                case UNLF: //
                                case CR:
                                case LF:
                                    message.IsIncompleteMessage = false;
                                    break;
                                case '\b':
                                    if (sb.Length > 0)
                                        sb.Remove(sb.Length - 1, 1);
                                    break;
                                default:
                                    sb.Append(rttCodeArray[i]);
                                    break;
                            }
                            if (message.IsIncompleteMessage)
                                message.Content = sb.ToString();
                        }
                        catch (Exception ex)
                        {
                            Debug.WriteLine("Error in OnChatMessageComposing: " + ex.Message);
                            message.IsIncompleteMessage = false;
                        }
                        if (string.IsNullOrEmpty(message.Content))
                            chat.DeleteMessage(message);
                        else
                            chat.UpdateLastMessage(false);
                        this.OnConversationUpdated(chat, true);

                        if (this.RttReceived != null)
                        {
                            this.RttReceived(this, EventArgs.Empty);
                        }
                    }
                });
        }
        internal void DeclineCall(CallViewModel viewModel, string message)
        {
            lock (CallsViewModelList)
            {
                if (FindCallViewModel(viewModel))
                {
                    LOG.Info(String.Format("Declining call for {0}. {1}", viewModel.CallerInfo,
                        viewModel.ActiveCall.NativeCallPtr));
                    var contactID = new ContactID(
                            string.Format("{0}@{1}", viewModel.ActiveCall.RemoteParty.Username,
                                viewModel.ActiveCall.RemoteParty.HostAddress), IntPtr.Zero);
                    var contact = ServiceManager.Instance.ContactService.FindContact(contactID);
                    if (contact == null)
                    {
                        contact = new VATRPContact(contactID)
                        {
                            Fullname = viewModel.ActiveCall.RemoteParty.Username,
                            DisplayName = viewModel.ActiveCall.RemoteParty.Username,
                            SipUsername = viewModel.ActiveCall.RemoteParty.Username,
                            RegistrationName = contactID.ID
                        };
                        ServiceManager.Instance.ContactService.AddContact(contact, string.Empty);
                    }
                    viewModel.DeclineCall(false);
                    try
                    {
                        _linphoneService.DeclineCall(viewModel.ActiveCall.NativeCallPtr);
                    }
                    catch (Exception ex)
                    {
                        ServiceManager.LogError("DeclineCall", ex);
                    }

                    if (message.NotBlank())
                    {
                        if (_simpleMessageViewModel != null)
                        {
                            _simpleMessageViewModel.SetActiveChatContact(contact, IntPtr.Zero);
                            _simpleMessageViewModel.SendMessage(string.Format("{0}{1}", VATRPChatMessage.DECLINE_PREFIX, message));
                        }
                    }
                }
            }
        }
Exemplo n.º 23
0
 public bool Equals(ContactID obj)
 {
     return Geometry == obj.Geometry
         && Feature == obj.Feature;
 }
 private void RemoveContactModel(ContactID contactID)
 {
     lock (this.Contacts)
     {
         foreach (var contact in Contacts)
         {
             if (contact.Contact == contactID)
             {
                 contact.PropertyChanged -= OnContactPropertyChanged;
                 Contacts.Remove(contact);
                 ContactsListView.Refresh();
                 break;
             }
         }
     }
 }
 private ContactViewModel FindContactViewModel(ContactID contact)
 {
     if (contact != null)
     {
         foreach (var contactViewModel in this.Contacts)
         {
             if (contactViewModel.Contact == contact)
                 return contactViewModel;
         }
     }
     return null;
 }
 public ContactBasedEventArgs(ContactID id)
 {
     _contact = id;
 }
Exemplo n.º 27
0
 /// <summary>
 /// Creates a manifold point as a copy of the given point
 /// </summary>
 /// <param name="cp">point to copy from</param>
 public ManifoldPoint(ManifoldPoint cp)
 {
     LocalPoint = cp.LocalPoint.Clone();
     NormalImpulse = cp.NormalImpulse;
     TangentImpulse = cp.TangentImpulse;
     Id = new ContactID(cp.Id);
 }
Exemplo n.º 28
0
        private void OnChatMessageReceived(IntPtr chatPtr, IntPtr callChatPtr, string remoteUser, VATRPChatMessage chatMessage)
        {
            string dn, un, host;
            int port;
            if (callChatPtr == chatPtr /*&& RttEnabled*/)
            {
                return;
            }

            System.Windows.Threading.Dispatcher dispatcher = null;
            try
            {
               dispatcher = this._serviceManager.Dispatcher;
            }
            catch (NullReferenceException)
            {
                return;
            }

            if (dispatcher != null)
                dispatcher.BeginInvoke((Action) delegate()
                {
                    if (!VATRPCall.ParseSipAddressEx(remoteUser, out dn, out un,
                        out host, out port))
                        un = "";

                    if (!un.NotBlank())
                        return;

                    var contactAddress = string.Format("{0}@{1}", un, host);
                    var contactID = new ContactID(contactAddress, IntPtr.Zero);
                    VATRPContact contact = FindContact(contactID);

                    if (contact == null)
                    {
                        contact = new VATRPContact(contactID)
                        {
                            DisplayName = dn,
                            Fullname = dn.NotBlank() ? dn : un,
                            SipUsername = un,
                            RegistrationName = contactAddress
                        };
                        _contactSvc.AddContact(contact, "");
                        Contacts.Add(contact);
                        if (ContactAdded != null)
                            ContactAdded(this, new ContactEventArgs(new ContactID(contact)));
                    }

                    VATRPChat chat = GetChat(contact);
                    chat.NativePtr = chatPtr;

                    if (chat.CheckMessage(chatMessage))
                    {
                        chat.UnreadMsgCount++;
                        if (!chat.IsSelected)
                            contact.UnreadMsgCount++;
                        chatMessage.IsRTTMessage = false;
                        chatMessage.IsIncompleteMessage = false;
                        chatMessage.Chat = chat;
                        if (chatMessage.Content.StartsWith(VATRPChatMessage.DECLINE_PREFIX))
                        {
                            chatMessage.Content = chatMessage.Content.Substring(VATRPChatMessage.DECLINE_PREFIX.Length);

                            chatMessage.IsDeclineMessage = true;
                            if (ConversationDeclineMessageReceived != null)
                            {
                                var declineArgs = new DeclineMessageArgs(chatMessage.Content) { Sender = contact };
                                ConversationDeclineMessageReceived(this, declineArgs);
                            }
                        }

                        chat.AddMessage(chatMessage, false);
                        chat.UpdateLastMessage(false);

                        OnConversationUnReadStateChanged(chat);
                        this.OnConversationUpdated(chat, true);
                    }
                });
        }
        internal bool CheckReceiverContact()
        {
            var receiver = string.Empty;
            if (ReceiverAddress != null)
            {
                receiver = ReceiverAddress.Trim();
            }

            if (Contact != null && receiver == Contact.Contact.RegistrationName)
                return true;

            VATRPContact contact = _chatsManager.FindContact(new ContactID(receiver, IntPtr.Zero));
            if (contact == null)
            {
                string un, host, dn;
                int port;
                if (!VATRPCall.ParseSipAddress(receiver, out un,
                    out host, out port))
                    un = "";

                if (!un.NotBlank())
                    return false;

                if (string.IsNullOrEmpty(host))
                    host = App.CurrentAccount.ProxyHostname;
                var contactAddress = string.Format("{0}@{1}", un, host);
                var contactID = new ContactID(contactAddress, IntPtr.Zero);

                contact = new VATRPContact(contactID)
                {
                    DisplayName = un,
                    Fullname = un,
                    SipUsername = un,
                    RegistrationName = contactAddress
                };
                _contactsManager.AddContact(contact, "");
            }

            SetActiveChatContact(contact, IntPtr.Zero);
            if ( ReceiverAddress != contact.RegistrationName )
                ReceiverAddress = contact.RegistrationName;

            return true;
        }
Exemplo n.º 30
0
 public void CloseChat(ContactID contactID)
 {
     if (contactID != null)
     {
         VATRPChat chat = this.FindChat(contactID);
         if (chat != null)
         {
             this.CloseChat(chat);
         }
     }
 }
Exemplo n.º 31
0
        public void AddLinphoneContact(string name, string username, string address)
        {
            if (_manager.LinphoneService.LinphoneCore == IntPtr.Zero)
                return;

            var sipAddress = address.TrimSipPrefix();

            var fqdn = string.Format("{0} <sip:{1}>", name, sipAddress);
            IntPtr friendPtr = LinphoneAPI.linphone_friend_new_with_address(fqdn);
            if (friendPtr != IntPtr.Zero)
            {
                IntPtr friendList =
                    LinphoneAPI.linphone_core_get_default_friend_list(_manager.LinphoneService.LinphoneCore);
                LinphoneAPI.linphone_friend_set_name(friendPtr, name);
                LinphoneAPI.linphone_friend_enable_subscribes(friendPtr, false);
                LinphoneAPI.linphone_friend_set_inc_subscribe_policy(friendPtr, 1);
                LinphoneAPI.linphone_friend_list_add_friend(friendList, friendPtr);

                var refKey = Guid.NewGuid().ToString();
                LinphoneAPI.linphone_friend_set_ref_key(friendPtr, refKey);

                var contactID = new ContactID(sipAddress, IntPtr.Zero);
                VATRPContact contact = FindContact(contactID);
                if (contact == null)
                {
                    contact = new VATRPContact(new ContactID(sipAddress, IntPtr.Zero))
                    {
                        DisplayName = name,
                        Fullname = name,
                        Gender = "male",
                        SipUsername = username,
                        RegistrationName = sipAddress,
                        IsLinphoneContact = true,
                        LinphoneRefKey = refKey
                    };
                    Contacts.Add(contact);
                }
                else
                {
                    contact.DisplayName = name;
                    contact.Fullname = name;
                    contact.IsLinphoneContact = true;
                    contact.SipUsername = username;
                    contact.LinphoneRefKey = refKey;
                }
                UpdateAvatar(contact);
                UpdateContactDbId(contact);

                if (ContactAdded != null)
                {
                    Dispatcher.CurrentDispatcher.BeginInvoke(new Action(() =>
                    {
                        ContactAdded(this, new ContactEventArgs(new ContactID(contact)));
                    }));
                }
            }
        }
Exemplo n.º 32
0
        public VATRPChat FindChat(ContactID contactID)
        {
            if (contactID == null)
                return null;

            lock (this._chatItems)
            {
                foreach (VATRPChat chatItem in this._chatItems)
                {
                    if ((chatItem != null) && chatItem.ID == contactID.ID)
                    {
                        return chatItem;
                    }
                }
            }

            return null;
        }
Exemplo n.º 33
0
 public void RenameContact(ContactID contactID, string nick)
 {
 }
Exemplo n.º 34
0
        public VATRPContact FindContact(ContactID contactID)
        {
            foreach (var contactItem in Contacts)
            {
                if (contactItem.ID == contactID.ID)
                {
                    return contactItem;
                }
            }

            return null;
        }
Exemplo n.º 35
0
        internal void UpdateLoggedinContact()
        {
            if (App.CurrentAccount == null || !App.CurrentAccount.Username.NotBlank())
                return;
            var contactAddress = string.Format("{0}@{1}", App.CurrentAccount.Username,
                App.CurrentAccount.ProxyHostname);
            VATRPContact contact = this.ContactService.FindLoggedInContact();
            bool addLogedInContact = true;
            if (contact != null)
            {
                if (contact.SipUsername == contactAddress)
                {
                    contact.IsLoggedIn = false;
                    addLogedInContact = false;
                }
            }

            if (addLogedInContact)
            {
                var contactID = new ContactID(contactAddress, IntPtr.Zero);
                contact = new VATRPContact(contactID)
                {
                    IsLoggedIn = true,
                    Fullname = App.CurrentAccount.Username,
                    DisplayName = App.CurrentAccount.DisplayName,
                    RegistrationName =
                        string.Format("sip:{0}@{1}", App.CurrentAccount.Username, App.CurrentAccount.ProxyHostname)
                };
                contact.Initials = contact.Fullname.Substring(0, 1).ToUpper();
                this.ContactService.AddContact(contact, string.Empty);
            }
        }
Exemplo n.º 36
0
        public override void Evaluate(ContactListener listener)
        {
            Body     body     = this._shape1.GetBody();
            Body     body2    = this._shape2.GetBody();
            Manifold manifold = this._manifold.Clone();

            Collision.Collision.CollidePolygons(ref this._manifold, (PolygonShape)this._shape1, body.GetXForm(), (PolygonShape)this._shape2, body2.GetXForm());
            bool[]       array        = new bool[2];
            bool[]       array2       = array;
            ContactPoint contactPoint = new ContactPoint();

            contactPoint.Shape1      = this._shape1;
            contactPoint.Shape2      = this._shape2;
            contactPoint.Friction    = Settings.MixFriction(this._shape1.Friction, this._shape2.Friction);
            contactPoint.Restitution = Settings.MixRestitution(this._shape1.Restitution, this._shape2.Restitution);
            if (this._manifold.PointCount > 0)
            {
                for (int i = 0; i < this._manifold.PointCount; i++)
                {
                    ManifoldPoint manifoldPoint = this._manifold.Points[i];
                    manifoldPoint.NormalImpulse  = 0f;
                    manifoldPoint.TangentImpulse = 0f;
                    bool      flag = false;
                    ContactID iD   = manifoldPoint.ID;
                    for (int j = 0; j < manifold.PointCount; j++)
                    {
                        if (!array2[j])
                        {
                            ManifoldPoint manifoldPoint2 = manifold.Points[j];
                            if (manifoldPoint2.ID.Key == iD.Key)
                            {
                                array2[j] = true;
                                manifoldPoint.NormalImpulse  = manifoldPoint2.NormalImpulse;
                                manifoldPoint.TangentImpulse = manifoldPoint2.TangentImpulse;
                                flag = true;
                                if (listener != null)
                                {
                                    contactPoint.Position = body.GetWorldPoint(manifoldPoint.LocalPoint1);
                                    Vec2 linearVelocityFromLocalPoint  = body.GetLinearVelocityFromLocalPoint(manifoldPoint.LocalPoint1);
                                    Vec2 linearVelocityFromLocalPoint2 = body2.GetLinearVelocityFromLocalPoint(manifoldPoint.LocalPoint2);
                                    contactPoint.Velocity   = linearVelocityFromLocalPoint2 - linearVelocityFromLocalPoint;
                                    contactPoint.Normal     = this._manifold.Normal;
                                    contactPoint.Separation = manifoldPoint.Separation;
                                    contactPoint.ID         = iD;
                                    listener.Persist(contactPoint);
                                }
                                break;
                            }
                        }
                    }
                    if (!flag && listener != null)
                    {
                        contactPoint.Position = body.GetWorldPoint(manifoldPoint.LocalPoint1);
                        Vec2 linearVelocityFromLocalPoint  = body.GetLinearVelocityFromLocalPoint(manifoldPoint.LocalPoint1);
                        Vec2 linearVelocityFromLocalPoint2 = body2.GetLinearVelocityFromLocalPoint(manifoldPoint.LocalPoint2);
                        contactPoint.Velocity   = linearVelocityFromLocalPoint2 - linearVelocityFromLocalPoint;
                        contactPoint.Normal     = this._manifold.Normal;
                        contactPoint.Separation = manifoldPoint.Separation;
                        contactPoint.ID         = iD;
                        listener.Add(contactPoint);
                    }
                }
                this._manifoldCount = 1;
            }
            else
            {
                this._manifoldCount = 0;
            }
            if (listener != null)
            {
                for (int i = 0; i < manifold.PointCount; i++)
                {
                    if (!array2[i])
                    {
                        ManifoldPoint manifoldPoint2 = manifold.Points[i];
                        contactPoint.Position = body.GetWorldPoint(manifoldPoint2.LocalPoint1);
                        Vec2 linearVelocityFromLocalPoint  = body.GetLinearVelocityFromLocalPoint(manifoldPoint2.LocalPoint1);
                        Vec2 linearVelocityFromLocalPoint2 = body2.GetLinearVelocityFromLocalPoint(manifoldPoint2.LocalPoint2);
                        contactPoint.Velocity   = linearVelocityFromLocalPoint2 - linearVelocityFromLocalPoint;
                        contactPoint.Normal     = manifold.Normal;
                        contactPoint.Separation = manifoldPoint2.Separation;
                        contactPoint.ID         = manifoldPoint2.ID;
                        listener.Remove(contactPoint);
                    }
                }
            }
        }