Пример #1
0
        /// <summary>Gets the unique contacts.</summary>
        /// <param name="shred30Contacts">The shred30 contacts.</param>
        public IEnumerable <IShred30Contact> GetUniqueContacts(IEnumerable <IShred30Contact> shred30Contacts)
        {
            Shred30ContactCollection uniqueContacts = new Shred30ContactCollection();

            foreach (IShred30Contact contact in shred30Contacts)
            {
                if (contact.CanBeUnique && !uniqueContacts.Contains(contact, new Shred30ContactComparer()))
                {
                    uniqueContacts.Add(contact);
                }
            }

            return(this.GetFinalizedUniqueContacts(uniqueContacts));
        }
        /// <summary>Deserializes the specified contacts string.</summary>
        /// <param name="contactsJson">The contacts string.</param>
        public IEnumerable <IShred30Contact> Deserialize()
        {
            List <ContactElementJson> contactElementsJson =
                JsonConvert.DeserializeObject <List <ContactElementJson> >(this.ContactsJson);

            bool anyElementHasBlankName = contactElementsJson
                                          .Any(contactElement => string.IsNullOrWhiteSpace(contactElement.Name));

            if (anyElementHasBlankName)
            {
                throw new DeserializationException("Cannot deserialize contacts because not all elements have a name.");
            }

            Shred30ContactCollection shred30Contacts = new Shred30ContactCollection();

            foreach (ContactElementJson contactElementJson in contactElementsJson)
            {
                IShred30Contact shred30Contact;
                if (contactElementJson.Name.Equals(DropElementName, StringComparison.OrdinalIgnoreCase))
                {
                    shred30Contact = new Drop();
                }
                else
                {
                    shred30Contact = new Shred30Trick(
                        contactElementJson.Side,
                        contactElementJson.Name,
                        contactElementJson.SameSide
                        );
                }

                shred30Contacts.Add(shred30Contact);
            }

            return(shred30Contacts);
        }