Ejemplo n.º 1
0
        private void ParsePidf(byte[] pidfContent)
        {
            presence presence;

            using (MemoryStream stream = new MemoryStream(pidfContent))
            {
                XmlSerializer serializer = new XmlSerializer(typeof(presence));
                presence = serializer.Deserialize(stream) as presence;
            }

            PresenceStatus status = PresenceStatus.Offline;

            if (presence != null)
            {
                person[] persons = presence.Persons;
                person   person  = null;
                if (persons != null)
                {
                    if (persons.Length > 0)
                    {
                        person = persons[0];
                    }

                    DateTime lastTimeStamp = DateTime.MinValue;
                    foreach (person p in persons)
                    {
                        String timeStamp = p.GetTimeStamp();
                        if (!String.IsNullOrEmpty(timeStamp))
                        {
                            DateTime timestamp = Rfc3339DateTime.Parse(timeStamp);
                            if (timestamp.CompareTo(lastTimeStamp) > 0)
                            {
                                lastTimeStamp = timestamp;
                                person        = p;
                            }
                        }
                    }
                }
                String statusicon = (person != null && person.statusicon != null) ? person.statusicon.Value : null;

                Contact contact = this.contactService.ContactFind(presence.entity);
                if (contact != null)
                {
                    if (person != null)
                    {
                        //
                        // Basic
                        //
                        if (person.overridingWillingness != null)
                        {
                            status = (person.overridingWillingness.basic == basicType.closed) ? PresenceStatus.Offline : PresenceStatus.Online;
                            if (!String.IsNullOrEmpty(person.overridingWillingness.Until))
                            {
                                contact.HyperAvaiability = Rfc3339DateTime.Parse(person.overridingWillingness.Until).ToLocalTime();
                            }
                        }

                        //
                        //  Activities
                        //
                        if (person.activities != null && person.activities.ItemsElementName != null)
                        {
                            if (person.activities.ItemsElementName.Length > 0)
                            {
                                switch (person.activities.ItemsElementName[0])
                                {
                                case BogheCore.Generated.rpid.ItemsChoiceType.away:
                                case BogheCore.Generated.rpid.ItemsChoiceType.shopping:
                                case BogheCore.Generated.rpid.ItemsChoiceType.sleeping:
                                case BogheCore.Generated.rpid.ItemsChoiceType.working:
                                case BogheCore.Generated.rpid.ItemsChoiceType.appointment:
                                    status = PresenceStatus.Away;
                                    break;

                                case BogheCore.Generated.rpid.ItemsChoiceType.busy:
                                    status = PresenceStatus.Busy;
                                    break;

                                case BogheCore.Generated.rpid.ItemsChoiceType.vacation:
                                    status = PresenceStatus.BeRightBack;
                                    break;

                                case BogheCore.Generated.rpid.ItemsChoiceType.onthephone:
                                case BogheCore.Generated.rpid.ItemsChoiceType.playing:
                                    status = PresenceStatus.OnThePhone;
                                    break;

                                case BogheCore.Generated.rpid.ItemsChoiceType.dinner:
                                case BogheCore.Generated.rpid.ItemsChoiceType.breakfast:
                                case BogheCore.Generated.rpid.ItemsChoiceType.meal:
                                    status = PresenceStatus.OutToLunch;
                                    break;
                                }
                            }
                        }

                        // Assign status
                        contact.PresenceStatus = status;

                        // Free Text
                        String note = person.GetNote();
                        if (!String.IsNullOrEmpty(note))
                        {
                            contact.FreeText = note;
                        }

                        // Avatar

                        /*if (!String.IsNullOrEmpty(statusicon))
                         * {
                         *  contact.Avatar = this.GetContactStatusIcon(statusicon);
                         * }*/

                        // Home Page
                        String hp = person.homepage;
                        if (!String.IsNullOrEmpty(hp))
                        {
                            contact.HomePage = hp;
                        }

                        // Service willingness (open/closed)
                        // IMPORTANT: ignore availability[service.status]

                        /*if (presence.tuple != null && presence.tuple.Length > 0)
                         * {
                         *  foreach (tuple service in presence.tuple)
                         *  {
                         *      if (service != null && service.willingness != null && service.serviceDescription != null)
                         *      {
                         *          if (service.willingness.basic == basicType.closed)
                         *          {
                         *              contact.AddClosedServices(service.serviceDescription.serviceid);
                         *          }
                         *          else if (contact.ClosedServices.Contains(service.serviceDescription.serviceid))
                         *          {
                         *              contact.RemoveClosedServices(service.serviceDescription.serviceid);
                         *          }
                         *      }
                         *  }
                         * }*/
                    }
                    else
                    {
                        // Get the first tuple
                        tuple tuple = (presence.tuple != null && presence.tuple.Length > 0) ? presence.tuple[0] : null;
                        contact.PresenceStatus = (tuple != null && tuple.status != null && tuple.status.basic == basic.open) ? PresenceStatus.Online : PresenceStatus.Offline;
                    }
                }
            }
        }