Exemplo n.º 1
0
        public override void OnNavigatedTo(NavigationParameters parameters)
        {
            base.OnNavigatedTo(parameters);

            ContactDetails = parameters["CardDetails"] as ContactCard;
            RaisePropertyChanged(nameof(ContactDetails));
        }
Exemplo n.º 2
0
        public ContactCard SaveContactCard(ContactCard contactCard)
        {
            using (var daoFactory = new DaoFactory())
            {
                using (var tx = daoFactory.DbManager.BeginTransaction(IsolationLevel.ReadUncommitted))
                {
                    var daoContact     = daoFactory.CreateContactDao(Tenant, User);
                    var daoContactInfo = daoFactory.CreateContactInfoDao(Tenant, User);

                    var contactId = daoContact.SaveContact(contactCard.ContactInfo);

                    contactCard.ContactInfo.Id = contactId;

                    foreach (var contactItem in contactCard.ContactItems)
                    {
                        contactItem.ContactId = contactId;

                        var contactItemId = daoContactInfo.SaveContactInfo(contactItem);

                        contactItem.Id = contactItemId;
                    }

                    tx.Commit();
                }
            }

            var factory = new EngineFactory(Tenant, User, Log);

            Log.Debug("IndexEngine->SaveContactCard()");

            factory.IndexEngine.Add(contactCard.ToMailContactWrapper());

            return(contactCard);
        }
 public static void deleteContactCard(ContactCard contactCardDataItem)
 {
     if (contactCards.Count(I => I.contactId == contactCardDataItem.contactId) > 0)
     {
         contactCards.Remove(contactCards.Find(I => I.contactId == contactCardDataItem.contactId));
     }
 }
 public static void updateContactCard(ContactCard contactCardDataItem)
 {
     if (contactCards.Count(I => I.contactId == contactCardDataItem.contactId) > 0)
     {
         contactCards[contactCards.FindIndex(I => I.contactId == contactCardDataItem.contactId)] = contactCardDataItem;
     }
 }
Exemplo n.º 5
0
        internal void AddContactCard(ContactCard card)
        {
            if (!string.IsNullOrEmpty(card.DisplayName))
            {
                m_displayName = card.DisplayName.Trim(new char[] { ' ', '\n' });
            }

            m_contactCards.Add(card);
        }
        public static void addNewContactCardDetail(ContactCardDetail contactCardDetailDataItem)
        {
            ContactCard contactCard = contactCards.Where(I => I.contactId == contactCardDetailDataItem.contactCardId).FirstOrDefault();

            if (contactCard != null)
            {
                contactCard.contactCardDetails.Add(contactCardDetailDataItem);
            }
        }
Exemplo n.º 7
0
        public MailContactData CreateContact(string name, string description, List <string> emails, List <string> phoneNumbers)
        {
            if (!emails.Any())
            {
                throw new ArgumentException(@"Invalid list of emails.", "emails");
            }

            var contactCard = new ContactCard(0, TenantId, Username, name, description, ContactType.Personal, emails,
                                              phoneNumbers);

            var newContact = MailEngineFactory.ContactEngine.SaveContactCard(contactCard);

            return(newContact.ToMailContactData());
        }
        public Window1()
        {
            InitializeComponent();

            users.Add("sip:[email protected]");
            users.Add("sip:[email protected]");
            users.Add("sip:[email protected]");

            foreach (string user in users)
            {
                ContactCard contactCard = new ContactCard();
                contactCard.Source = user;
                listBox1.Items.Add(contactCard);
            }
        }
Exemplo n.º 9
0
        public static async Task <ContactCard> ReadBusinessCard(byte[] fileContent)
        {
            OcrData data = await GetOCRData(fileContent).ConfigureAwait(false);

            ContactCard contact = new ContactCard();
            Region      region  = data.Regions[0];

            contact.Name     = region.Lines.Count > 0 ? string.Join(" ", region.Lines[0].Words.Select(a => a.Text)) : string.Empty;
            contact.Company  = region.Lines.Count > 1 ? string.Join(" ", region.Lines[1].Words.Select(a => a.Text)) : string.Empty;
            contact.Position = region.Lines.Count > 2 ? string.Join(" ", region.Lines[2].Words.Select(a => a.Text)) : string.Empty;
            contact.PhoneNo  = GetFromRegex(region, Constants.RegexPatterns.Phone);
            contact.Email    = GetFromRegex(region, Constants.RegexPatterns.Email);
            contact.Website  = GetFromRegex(region, Constants.RegexPatterns.Website, Constants.RegexPatterns.WebsiteFacebook);
            contact.Facebook = GetFromRegex(region, Constants.RegexPatterns.Facebook);
            contact.Twitter  = GetFromRegex(region, Constants.RegexPatterns.Twitter);

            return(contact);
        }
Exemplo n.º 10
0
        public static MailContactWrapper ToMailContactWrapper(this ContactCard contactCard)
        {
            var now = DateTime.UtcNow;

            var infoList = contactCard.ContactItems.ConvertAll(ToMailContactInfoWrapper);

            var contact = new MailContactWrapper
            {
                Id             = contactCard.ContactInfo.Id,
                TenantId       = contactCard.ContactInfo.Tenant,
                User           = Guid.Parse(contactCard.ContactInfo.User),
                Name           = contactCard.ContactInfo.ContactName,
                ContactType    = (int)contactCard.ContactInfo.Type,
                Description    = contactCard.ContactInfo.Description,
                InfoList       = infoList,
                LastModifiedOn = now
            };

            return(contact);
        }
Exemplo n.º 11
0
        private void PresenceView_NotificationReceived(
            object sender,
            RemotePresentitiesNotificationEventArgs e)
        {
            lock (this.SyncRoot)
            {
                foreach (var notification in e.Notifications)
                {
                    ContactInformation info = null;
                    if (!m_contacts.TryGetValue(notification.PresentityUri, out info))
                    {
                        continue;
                    }

                    foreach (var category in notification.Categories)
                    {
                        if (category.Name == PresenceCategoryNames.ContactCard)
                        {
                            var card = new ContactCard(category);
                            info.AddContactCard(card);
                        }
                        else if (category.Name == PresenceCategoryNames.State)
                        {
                            string rawXml = category.Category.GetCategoryDataXml();
                            if (string.IsNullOrEmpty(rawXml))
                            {
                                continue;
                            }

                            PresenceState state = new PresenceState(category);

                            var availability = state.Availability;
                            if (availability != PresenceAvailability.None)
                            {
                                info.Availability = availability;
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 12
0
        private static void SaveFrequentlyContactedAddress(int tenant, string user, MimeMessage mimeMessage,
                                                           string scheme)
        {
            var recipients = new List <MailboxAddress>();

            recipients.AddRange(mimeMessage.To.Mailboxes);
            recipients.AddRange(mimeMessage.Cc.Mailboxes);
            recipients.AddRange(mimeMessage.Bcc.Mailboxes);

            var treatedAddresses = new List <string>();

            foreach (var recipient in recipients)
            {
                var email = recipient.Address;
                if (treatedAddresses.Contains(email))
                {
                    continue;
                }

                var engine = new EngineFactory(tenant, user);

                var exp = new FullFilterContactsExp(tenant, user, searchTerm: email, infoType: ContactInfoType.Email);

                var contacts = engine.ContactEngine.GetContactCards(exp);

                if (!contacts.Any())
                {
                    var emails = engine.ContactEngine.SearchEmails(tenant, user, email, 1, scheme);
                    if (!emails.Any())
                    {
                        var contactCard = new ContactCard(0, tenant, user, recipient.Name, "",
                                                          ContactType.FrequentlyContacted, new[] { email });

                        engine.ContactEngine.SaveContactCard(contactCard);
                    }
                }

                treatedAddresses.Add(email);
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// Log the presence notification for the remote user.
        /// </summary>
        /// <param name="sender">View that received the notification.</param>
        /// <param name="e">Data about the notifications received.</param>
        private void RemotePresenceView_NotificationReceived(object sender,
                                                             RemotePresentitiesNotificationEventArgs e)
        {
            // Extract the RemotePresenceView that received the notification.
            RemotePresenceView view = sender as RemotePresenceView;

            // A RemotePresentityNotification will contain all the
            // categories for one user; Notifications can contain notifications
            // for multiple users.
            foreach (RemotePresentityNotification notification in e.Notifications)
            {
                Console.WriteLine("\nView: " + view.ApplicationContext
                                  + " Received a Notification for user "
                                  + notification.PresentityUri + ".");

                // If a category on notification is null, the category
                // was not present in the notification. This means there were no
                // changes in that category.
                if (notification.AggregatedPresenceState != null)
                {
                    Console.WriteLine("Aggregate State = " + notification.AggregatedPresenceState.Availability + ".");
                }

                if (notification.PersonalNote != null)
                {
                    Console.WriteLine("PersonalNote: " + notification.PersonalNote.Message + ".");
                }

                if (notification.ContactCard != null)
                {
                    // A ContactCard contains many properties; only display
                    // some.
                    ContactCard contactCard = notification.ContactCard;
                    Console.WriteLine("ContactCard Company: " + contactCard.Company + ".");
                    Console.WriteLine("ContactCard DisplayName: " + contactCard.DisplayName + ".");
                    Console.WriteLine("ContactCard EmailAddress: " + contactCard.EmailAddress + ".");
                }
            }
        }
        public static MailContactData ToMailContactData(this ContactCard contactCard)
        {
            var baseAbsolutePath = CommonLinkUtility.ToAbsolute(BASE_VIRTUAL_PATH).ToLower();

            var emails = new MailContactData.EmailsList <ContactInfo>();
            var phones = new MailContactData.PhoneNumgersList <ContactInfo>();

            foreach (var contact in contactCard.ContactItems)
            {
                if (contact.Type == (int)ContactInfoType.Email)
                {
                    if (contact.IsPrimary)
                    {
                        emails.Insert(0,
                                      new ContactInfo {
                            Id = contact.Id, Value = contact.Data, IsPrimary = contact.IsPrimary
                        });
                    }
                    else
                    {
                        emails.Add(new ContactInfo
                        {
                            Id        = contact.Id,
                            Value     = contact.Data,
                            IsPrimary = contact.IsPrimary
                        });
                    }
                }
                else if (contact.Type == (int)ContactInfoType.Phone)
                {
                    if (contact.IsPrimary)
                    {
                        phones.Insert(0,
                                      new ContactInfo {
                            Id = contact.Id, Value = contact.Data, IsPrimary = contact.IsPrimary
                        });
                    }
                    else
                    {
                        phones.Add(new ContactInfo
                        {
                            Id        = contact.Id,
                            Value     = contact.Data,
                            IsPrimary = contact.IsPrimary
                        });
                    }
                }
            }

            var contactData = new MailContactData
            {
                ContactId    = contactCard.ContactInfo.Id,
                Name         = contactCard.ContactInfo.ContactName,
                Description  = contactCard.ContactInfo.Description,
                Emails       = emails,
                PhoneNumbers = phones,
                Type         = (int)contactCard.ContactInfo.Type,
                SmallFotoUrl =
                    string.Format("{0}HttpHandlers/contactphoto.ashx?cid={1}&ps=1", baseAbsolutePath, contactCard.ContactInfo.Id)
                    .ToLower(),
                MediumFotoUrl =
                    string.Format("{0}HttpHandlers/contactphoto.ashx?cid={1}&ps=2", baseAbsolutePath, contactCard.ContactInfo.Id)
                    .ToLower()
            };

            return(contactData);
        }
Exemplo n.º 15
0
 public ContactCardForm(ContactCard cc)
 {
     InitializeComponent();
     card = cc;
 }
Exemplo n.º 16
0
        private List<VisualBubble> MakeMediaBubble(Message message, bool useCurrentTime, bool isUser, string addressStr, string participantAddress = null)
        {
            DebugPrint(">>>>>>> Making media bubble");
            var messageMedia = message.Media;
            var messageMediaPhoto = messageMedia as MessageMediaPhoto;
            var messageMediaDocument = messageMedia as MessageMediaDocument;
            var messageMediaGeo = messageMedia as MessageMediaGeo;
            var messageMediaVenue = messageMedia as MessageMediaVenue;
            var messageMediaContact = messageMedia as MessageMediaContact;

            if (messageMediaPhoto != null)
            {
                var fileLocation = GetPhotoFileLocation(messageMediaPhoto.Photo);
                var fileSize = GetPhotoFileSize(messageMediaPhoto.Photo);
                var dimensions = GetPhotoDimensions(messageMediaPhoto.Photo);
                var cachedPhoto = GetCachedPhotoBytes(messageMediaPhoto.Photo);
                FileInformation fileInfo = new FileInformation
                {
                    FileLocation = fileLocation,
                    Size = fileSize,
                    FileType = "image",
                    Document = new Document()
                };
                using (var memoryStream = new MemoryStream())
                {
                    Serializer.Serialize<FileInformation>(memoryStream, fileInfo);
                    ImageBubble imageBubble = null;
                    if (isUser)
                    {
                        imageBubble = new ImageBubble(useCurrentTime ? Time.GetNowUnixTimestamp() : (long) message.Date,
                            message.Out != null ? Bubble.BubbleDirection.Outgoing : Bubble.BubbleDirection.Incoming,
                            addressStr, null, false, this, null, ImageBubble.Type.Url,
                            cachedPhoto, message.Id.ToString(CultureInfo.InvariantCulture));
                    }
                    else
                    {
                        imageBubble = new ImageBubble(useCurrentTime ? Time.GetNowUnixTimestamp() : (long) message.Date,
                            message.Out != null ? Bubble.BubbleDirection.Outgoing : Bubble.BubbleDirection.Incoming,
                            addressStr, participantAddress, true, this, null,
                            ImageBubble.Type.Url, cachedPhoto, message.Id.ToString(CultureInfo.InvariantCulture));
                    }
                    if (imageBubble.Direction == Bubble.BubbleDirection.Outgoing)
                    {
                        imageBubble.Status = Bubble.BubbleStatus.Sent;
                    }
                    imageBubble.AdditionalData = memoryStream.ToArray();
                    imageBubble.Width = dimensions.Width;
                    imageBubble.Height = dimensions.Height;
                    var returnList = new List<VisualBubble>
                    {
                        imageBubble  
                    };
                    if (!string.IsNullOrEmpty(messageMediaPhoto.Caption))
                    {
                        TextBubble captionBubble = null;
                        if (isUser)
                        {
                            captionBubble = new TextBubble(useCurrentTime ? Time.GetNowUnixTimestamp() : (long)message.Date,
                                message.Out != null ? Bubble.BubbleDirection.Outgoing : Bubble.BubbleDirection.Incoming,
                                addressStr, null, false, this, messageMediaPhoto.Caption,
                                message.Id.ToString(CultureInfo.InvariantCulture));
                        }
                        else
                        {
                            captionBubble = new TextBubble(useCurrentTime ? Time.GetNowUnixTimestamp() : (long)message.Date,
                                message.Out != null ? Bubble.BubbleDirection.Outgoing : Bubble.BubbleDirection.Incoming,
                                addressStr, participantAddress, true, this, messageMediaPhoto.Caption,
                                message.Id.ToString(CultureInfo.InvariantCulture));
                        }
                        returnList.Add(captionBubble);
                    }
                    return returnList;
                }
                
            }
            else if (messageMediaDocument != null)
            {
                DebugPrint(">>>> Media document " + ObjectDumper.Dump(messageMediaDocument));
                //DebugPrint(">>>>> Media attributes " +  (messageMediaDocument.Document as Document).Attributes);
                var document = messageMediaDocument.Document as Document;
                if (document != null)
                {
                    FileInformation fileInfo = new FileInformation
                    {
                        FileType = "document",
                        Document = document
                    };
                    using (var memoryStream = new MemoryStream())
                    {
                        Serializer.Serialize<FileInformation>(memoryStream, fileInfo);
                        VisualBubble bubble = null;
                        if (document.MimeType.Contains("audio"))
                        {
                            var audioTime = (int) GetAudioTime(document);
                            if (isUser)
                            {
                                bubble =
                                    new AudioBubble(useCurrentTime ? Time.GetNowUnixTimestamp() : (long) message.Date,
                                        message.Out != null
                                            ? Bubble.BubbleDirection.Outgoing
                                            : Bubble.BubbleDirection.Incoming, addressStr, null, false, this, "",
                                        AudioBubble.Type.Url,
                                        false, audioTime, message.Id.ToString(CultureInfo.InvariantCulture));
                            }
                            else
                            {
                                bubble =
                                    new AudioBubble(useCurrentTime ? Time.GetNowUnixTimestamp() : (long) message.Date,
                                        message.Out != null
                                            ? Bubble.BubbleDirection.Outgoing
                                            : Bubble.BubbleDirection.Incoming, addressStr, participantAddress, true,
                                        this, "",
                                        AudioBubble.Type.Url, false, audioTime,
                                        message.Id.ToString(CultureInfo.InvariantCulture));
                            }
                        }
                        else
                        {
                            //TODO: localize
                            var filename = document.MimeType.Contains("video")
                                ? ""
                                : GetDocumentFileName(document);GetDocumentFileName(document);

                            if (isUser)
                            {
                                bubble =
                                    new FileBubble(useCurrentTime ? Time.GetNowUnixTimestamp() : (long) message.Date,
                                        message.Out != null
                                            ? Bubble.BubbleDirection.Outgoing
                                            : Bubble.BubbleDirection.Incoming, addressStr, null, false, this, "",
                                        FileBubble.Type.Url, filename, document.MimeType,
                                        message.Id.ToString(CultureInfo.InvariantCulture));
                            }
                            else
                            {
                                bubble =
                                    new FileBubble(useCurrentTime ? Time.GetNowUnixTimestamp() : (long) message.Date,
                                        message.Out != null
                                            ? Bubble.BubbleDirection.Outgoing
                                            : Bubble.BubbleDirection.Incoming, addressStr, participantAddress, true,
                                        this, "", FileBubble.Type.Url, filename, document.MimeType,
                                        message.Id.ToString(CultureInfo.InvariantCulture));
                            }

                        }

                        if (bubble.Direction == Bubble.BubbleDirection.Outgoing)
                        {
                            bubble.Status = Bubble.BubbleStatus.Sent;
                        }
                        bubble.AdditionalData = memoryStream.ToArray();

                        var returnList = new List<VisualBubble>
                        {
                            bubble
                        };
                        if (!string.IsNullOrEmpty(messageMediaDocument.Caption))
                        {
                            TextBubble captionBubble = null;
                            if (isUser)
                            {
                                captionBubble = new TextBubble(useCurrentTime ? Time.GetNowUnixTimestamp() : (long)message.Date,
                                    message.Out != null ? Bubble.BubbleDirection.Outgoing : Bubble.BubbleDirection.Incoming,
                                    addressStr, null, false, this, messageMediaDocument.Caption,
                                    message.Id.ToString(CultureInfo.InvariantCulture));
                            }
                            else
                            {
                                captionBubble = new TextBubble(useCurrentTime ? Time.GetNowUnixTimestamp() : (long)message.Date,
                                    message.Out != null ? Bubble.BubbleDirection.Outgoing : Bubble.BubbleDirection.Incoming,
                                    addressStr, participantAddress, true, this, messageMediaDocument.Caption,
                                    message.Id.ToString(CultureInfo.InvariantCulture));
                            }
                            returnList.Add(captionBubble);
                        }
                        return returnList;
                    }

                }

            }
            else if (messageMediaGeo != null)
            {

                var geoPoint = messageMediaGeo.Geo as GeoPoint;

                if (geoPoint != null)
                {
                    var geoBubble = MakeGeoBubble(geoPoint, message, isUser, useCurrentTime, addressStr, participantAddress, null);
                    return new List<VisualBubble>
                    {
                        geoBubble
                    };
                }


            }
            else if (messageMediaVenue != null)
            {
                var geoPoint = messageMediaVenue.Geo as GeoPoint;

                if (geoPoint != null)
                {
                    var geoBubble = MakeGeoBubble(geoPoint,message,isUser,useCurrentTime,addressStr,participantAddress,messageMediaVenue.Title);
                    return new List<VisualBubble>
                    {
                        geoBubble
                    };
                }

            }
            else if (messageMediaContact != null)
            {
                var contactCard = new ContactCard
                {
                    GivenName = messageMediaContact.FirstName,
                    FamilyName = messageMediaContact.LastName
                };
                contactCard.Phones.Add(new ContactCard.ContactCardPhone
                {
                    Number = messageMediaContact.PhoneNumber
                });
                var vCardData = Platform.GenerateBytesFromContactCard(contactCard);
                var contactBubble = MakeContactBubble(message, isUser, useCurrentTime, addressStr, participantAddress, vCardData, messageMediaContact.FirstName);

                return new List<VisualBubble>
                { 
                    contactBubble
                };
            }

            return new List<VisualBubble>();
        }
Exemplo n.º 17
0
        public ContactCard UpdateContactCard(ContactCard newContactCard)
        {
            var contactId = newContactCard.ContactInfo.Id;

            if (contactId < 0)
            {
                throw new ArgumentException("Invalid contact id");
            }

            var contactCard = GetContactCard(contactId);

            if (null == contactCard)
            {
                throw new ArgumentException("Contact not found");
            }

            var contactChanged = !contactCard.ContactInfo.Equals(newContactCard.ContactInfo);

            var newContactItems = newContactCard.ContactItems.Where(c => !contactCard.ContactItems.Contains(c)).ToList();

            var removedContactItems = contactCard.ContactItems.Where(c => !newContactCard.ContactItems.Contains(c)).ToList();

            if (!contactChanged && !newContactItems.Any() && !removedContactItems.Any())
            {
                return(contactCard);
            }

            using (var daoFactory = new DaoFactory())
            {
                using (var tx = daoFactory.DbManager.BeginTransaction(IsolationLevel.ReadUncommitted))
                {
                    if (contactChanged)
                    {
                        var daoContact = daoFactory.CreateContactDao(Tenant, User);

                        daoContact.SaveContact(newContactCard.ContactInfo);

                        contactCard.ContactInfo = newContactCard.ContactInfo;
                    }

                    var daoContactInfo = daoFactory.CreateContactInfoDao(Tenant, User);

                    if (newContactItems.Any())
                    {
                        foreach (var contactItem in newContactItems)
                        {
                            contactItem.ContactId = contactId;

                            var contactItemId = daoContactInfo.SaveContactInfo(contactItem);

                            contactItem.Id = contactItemId;

                            contactCard.ContactItems.Add(contactItem);
                        }
                    }

                    if (removedContactItems.Any())
                    {
                        foreach (var contactItem in removedContactItems)
                        {
                            daoContactInfo.RemoveContactInfo(contactItem.Id);

                            contactCard.ContactItems.Remove(contactItem);
                        }
                    }

                    tx.Commit();
                }
            }

            var factory = new EngineFactory(Tenant, User, Log);

            Log.Debug("IndexEngine->UpdateContactCard()");

            factory.IndexEngine.Update(new List <MailContactWrapper> {
                contactCard.ToMailContactWrapper()
            });

            return(contactCard);
        }
 public static void addNewContact(ContactCard contactCardDataItem)
 {
     contactCards.Add(contactCardDataItem);
 }
Exemplo n.º 19
0
        // Publish note, state, contact card presence categories
        private void PublishPresenceCategories(bool publishFlag)
        {
            try
            {
                if (publishFlag == true)
                {
                    // The CustomPresenceCategory class enables creation of a
                    // category using XML. This allows precise crafting of a
                    // category, but it is also possible to create a category
                    // in other, more simple ways, shown below.
                    _note = new CustomPresenceCategory("note", String.Format(_noteXml, _noteValue));

                    // The PresenceState class has several static properties
                    // and methods which will provide standard states such as
                    // online, busy, and on-the-phone, for example.
                    _userState = PresenceState.UserBusy;

                    // It is possible to create and publish state with a
                    // custom availablity string, shown below. "In a call" will
                    // be shown in Microsoft Lync.
                    LocalizedString localizedCallString = new LocalizedString(
                        "In a call" /* The string to be displayed. */);

                    // Create a PresenceActivity indicating the
                    // "In a call" state.
                    PresenceActivity inACall = new PresenceActivity(
                        localizedCallString);

                    // Set the Availability of the "In a call" state to Busy.
                    inACall.SetAvailabilityRange((int)PresenceAvailability.Busy,
                                                 (int)PresenceAvailability.IdleBusy);

                    // Microsoft Lync will also show the Busy presence icon.
                    _phoneState = new PresenceState(
                        (int)PresenceAvailability.Busy,
                        inACall,
                        PhoneCallType.Voip,
                        "phone uri");

                    // Machine or Endpoint states must always be published to
                    // indicate the endpoint is actually online, otherwise it is
                    // assumed the endpoint is offline, and no presence
                    // published from that endpoint will be displayed.
                    _machineState = PresenceState.EndpointOnline;

                    // It is also possible to create presence categories such
                    // as ContactCard, Note, PresenceState, and Services with
                    // their constructors.
                    // Here we create a ContactCard and change the title.
                    _contactCard = new ContactCard(3);
                    LocalizedString localizedTitleString = new LocalizedString(
                        "The Boss" /* The title string to be displayed. */);
                    _contactCard.JobTitle = localizedTitleString.Value;

                    // Publish a photo
                    // If the supplied value for photo is null or empty, then set value of IsAllowedToShowPhoto to false
                    _contactCard.IsAllowedToShowPhoto = true;
                    string photoUri = UCMASampleHelper.PromptUser("Please enter a Photo Uri in the form of http://mysite/photo1.jpg", "PhotoURI1");
                    if (String.IsNullOrEmpty(photoUri))
                    {
                        photoUri = null;
                        _contactCard.IsAllowedToShowPhoto = false;
                    }
                    _contactCard.PhotoUri = photoUri;

                    // Publish all presence categories with new values.
                    _localOwnerPresence.BeginPublishPresence(
                        new PresenceCategory[]
                    {
                        _userState,
                        _phoneState,
                        _machineState,
                        _note,
                        _contactCard
                    },
                        PublishPresenceCompleted, /* async callback when publishing operation completes. */
                        publishFlag /* value TRUE indicates that presence to be published with new values. */);
                }
                else
                {
                    // Delete all presence categories.
                    _localOwnerPresence.BeginDeletePresence(
                        new PresenceCategory[]
                    {
                        _userState,
                        _phoneState,
                        _machineState,
                        _note,
                        _contactCard
                    },
                        PublishPresenceCompleted,
                        publishFlag /* value FALSE indicates that presence reverted to original values. */);
                }
            }
            catch (PublishSubscribeException pse)
            {
                // PublishSubscribeException is thrown when there were
                // exceptions during this presence operation such as badly
                // formed sip request, duplicate publications in the same
                // request etc.
                // TODO (Left to the reader): Include exception handling code
                // here.
                Console.WriteLine(pse.ToString());
            }
            catch (RealTimeException rte)
            {
                // RealTimeException is thrown when SIP Transport, SIP
                // Authentication, and credential-related errors are
                // encountered.
                // TODO (Left to the reader): Include exception handling code
                // here.
                Console.WriteLine(rte.ToString());
            }
        }
Exemplo n.º 20
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="cCard"></param>
 public TrustedKey(ContactCard cCard)
 {
     throw new System.NotImplementedException();
 }
Exemplo n.º 21
0
 public override byte[] GenerateBytesFromContactCard(ContactCard contactCard)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 22
0
 public ContactCardForm(ContactCard cc)
 {
     InitializeComponent();
     card = cc;
 }
Exemplo n.º 23
0
        // Publish note, state, contact card presence categories
        private void PublishPresenceCategories(bool publishFlag, string status = null)
        {
            try
            {
                if (publishFlag == true)
                {
                    // The CustomPresenceCategory class enables creation of a
                    // category using XML. This allows precise crafting of a
                    // category, but it is also possible to create a category
                    // in other, more simple ways, shown below.
                    _note = new CustomPresenceCategory("note", String.Format(_noteXml, _noteValue));

                    switch (status)
                    {
                    default:     //Available
                        _userState = PresenceState.UserAvailable;
                        Console.WriteLine(DateTime.Now.ToString() + " Setting available status.");
                        // It is possible to create and publish state with a custom availablity string, shown below
                        LocalizedString localizedAvailableString = new LocalizedString("Available");

                        // Create a PresenceActivity indicating the "In a call" state.
                        PresenceActivity Available = new PresenceActivity(localizedAvailableString);

                        // Set the Availability of the "In a call" state to Busy.
                        Available.SetAvailabilityRange((int)PresenceAvailability.Online,
                                                       (int)PresenceAvailability.Online);

                        // Microsoft Lync will also show the Busy presence icon.
                        _phoneState = new PresenceState(
                            (int)PresenceAvailability.Online,
                            Available,
                            PhoneCallType.Voip,
                            "phone uri");
                        break;

                    case "Busy":     //Busy
                        Console.WriteLine(DateTime.Now.ToString() + " Setting busy status.");
                        _userState = PresenceState.UserBusy;
                        LocalizedString  localizedBusyString = new LocalizedString("Busy");
                        PresenceActivity Busy = new PresenceActivity(localizedBusyString);
                        Busy.SetAvailabilityRange((int)PresenceAvailability.Busy,
                                                  (int)PresenceAvailability.IdleBusy);
                        _phoneState = new PresenceState(
                            (int)PresenceAvailability.Busy,
                            Busy,
                            PhoneCallType.Voip,
                            "phone uri");
                        break;


                    case "In a call":     //In a call
                        Console.WriteLine(DateTime.Now.ToString() + " Setting in a call status.");
                        _userState = PresenceState.UserBusy;
                        LocalizedString  localizedCallString = new LocalizedString("In a call");
                        PresenceActivity inACall             = new PresenceActivity(localizedCallString);
                        inACall.SetAvailabilityRange((int)PresenceAvailability.Busy,
                                                     (int)PresenceAvailability.IdleBusy);
                        _phoneState = new PresenceState(
                            (int)PresenceAvailability.Busy,
                            inACall,
                            PhoneCallType.Voip,
                            "phone uri");
                        break;

                    case "In a meeting":     //In a meeting
                        Console.WriteLine(DateTime.Now.ToString() + " Setting in a meeting status.");
                        _userState = PresenceState.UserBusy;
                        LocalizedString  localizedMeetingString = new LocalizedString("In a meeting");
                        PresenceActivity inAMeeting             = new PresenceActivity(localizedMeetingString);
                        inAMeeting.SetAvailabilityRange((int)PresenceAvailability.Busy,
                                                        (int)PresenceAvailability.IdleBusy);
                        _phoneState = new PresenceState(
                            (int)PresenceAvailability.Busy,
                            inAMeeting,
                            PhoneCallType.Voip,
                            "phone uri");
                        break;

                    case "In a conference call":     //In a conference call
                        Console.WriteLine(DateTime.Now.ToString() + " Setting in a conference call status.");
                        _userState = PresenceState.UserBusy;
                        LocalizedString  localizedConferenceString = new LocalizedString("In a conference call");
                        PresenceActivity inAConference             = new PresenceActivity(localizedConferenceString);
                        inAConference.SetAvailabilityRange((int)PresenceAvailability.Busy,
                                                           (int)PresenceAvailability.IdleBusy);
                        _phoneState = new PresenceState(
                            (int)PresenceAvailability.Busy,
                            inAConference,
                            PhoneCallType.Voip,
                            "phone uri");
                        break;

                    case "Presenting":     //Presenting
                        Console.WriteLine(DateTime.Now.ToString() + " Setting presenting status.");
                        _userState = PresenceState.UserBusy;
                        LocalizedString  localizedPresentingString = new LocalizedString("Presenting");
                        PresenceActivity Presenting = new PresenceActivity(localizedPresentingString);
                        Presenting.SetAvailabilityRange((int)PresenceAvailability.Busy,
                                                        (int)PresenceAvailability.DoNotDisturb);
                        _phoneState = new PresenceState(
                            (int)PresenceAvailability.DoNotDisturb,
                            Presenting,
                            PhoneCallType.Voip,
                            "phone uri");
                        break;

                    case "Offline":     //Offline
                        Console.WriteLine(DateTime.Now.ToString() + " Setting offline status.");
                        _userState = PresenceState.UserOffline;
                        LocalizedString  localizedOfflineString = new LocalizedString("Offline");
                        PresenceActivity Offline = new PresenceActivity(localizedOfflineString);
                        Offline.SetAvailabilityRange((int)PresenceAvailability.Offline,
                                                     (int)PresenceAvailability.Offline);
                        _phoneState = new PresenceState(
                            (int)PresenceAvailability.Offline,
                            Offline,
                            PhoneCallType.Voip,
                            "phone uri");
                        break;
                    }

                    // Machine or Endpoint states must always be published to
                    // indicate the endpoint is actually online, otherwise it is
                    // assumed the endpoint is offline, and no presence
                    // published from that endpoint will be displayed.
                    _machineState = PresenceState.EndpointOnline;

                    // It is also possible to create presence categories such
                    // as ContactCard, Note, PresenceState, and Services with
                    // their constructors.
                    // Here we create a ContactCard and change the title.
                    _contactCard = new ContactCard(0);

                    /* The title string to be displayed. */
                    if (!String.IsNullOrEmpty(ConfigurationManager.AppSettings["UserTitle"]))
                    {
                        LocalizedString localizedTitleString = new LocalizedString(ConfigurationManager.AppSettings["UserTitle"]);
                        _contactCard.JobTitle = localizedTitleString.Value;
                    }

                    if (!String.IsNullOrEmpty(ConfigurationManager.AppSettings["UserOffice"]))
                    {
                        LocalizedString localizedTitleString = new LocalizedString(ConfigurationManager.AppSettings["UserOffice"]);
                        _contactCard.OfficeLocation = localizedTitleString.Value;
                    }

                    if (!String.IsNullOrEmpty(ConfigurationManager.AppSettings["JobTitle"]))
                    {
                        LocalizedString localizedTitleString = new LocalizedString(ConfigurationManager.AppSettings["JobTitle"]);
                        _contactCard.JobTitle = localizedTitleString.Value;
                    }
                    // Publish a photo
                    // If the supplied value for photo is null or empty, then set value of IsAllowedToShowPhoto to false
                    _contactCard.IsAllowedToShowPhoto = false;

                    string photoUri = ConfigurationManager.AppSettings["PhotoUri"];
                    if (!String.IsNullOrEmpty(photoUri))
                    {
                        _contactCard.IsAllowedToShowPhoto = true;
                        _contactCard.PhotoUri             = photoUri;
                    }

                    // Publish all presence categories with new values.
                    _localOwnerPresence.BeginPublishPresence(
                        new PresenceCategory[]
                    {
                        _userState,
                        _phoneState,
                        _machineState,
                        _note,
                        _contactCard
                    },
                        PublishPresenceCompleted, /* async callback when publishing operation completes. */
                        publishFlag /* value TRUE indicates that presence to be published with new values. */);
                }
                else
                {
                    // Delete all presence categories.
                    Console.WriteLine(DateTime.Now.ToString() + " Revert status back.");
                    _localOwnerPresence.BeginDeletePresence(
                        new PresenceCategory[]
                    {
                        _userState,
                        _phoneState,
                        _machineState,
                        _note,
                        _contactCard
                    },
                        PublishPresenceCompleted,
                        publishFlag /* value FALSE indicates that presence reverted to original values. */);
                }
            }
            catch (PublishSubscribeException pse)
            {
                // PublishSubscribeException is thrown when there were
                // exceptions during this presence operation such as badly
                // formed sip request, duplicate publications in the same
                // request etc.
                // TODO (Left to the reader): Include exception handling code
                // here.
                Console.WriteLine(pse.ToString());
            }
            catch (RealTimeException rte)
            {
                // RealTimeException is thrown when SIP Transport, SIP
                // Authentication, and credential-related errors are
                // encountered.
                // TODO (Left to the reader): Include exception handling code
                // here.
                Console.WriteLine(rte.ToString());
            }
        }