private ContactData Convert(Person person)
        {
            if (person != null)
            {
                var contentTypeRepository  = ServiceLocator.Current.GetInstance <IContentTypeRepository>();
                var identityMappingService = ServiceLocator.Current.GetInstance <IdentityMappingService>();

                var         contentFactory = ServiceLocator.Current.GetInstance <IContentFactory>();
                ContentType type           = contentTypeRepository.Load(typeof(ContactData));

                ContactData contactData = contentFactory.CreateContent(type, new BuildingContext(type)
                {
                    Parent = DataFactory.Instance.Get <ContentFolder>(EntryPoint),
                }) as ContactData;

                Uri            externalId    = MappedIdentity.ConstructExternalIdentifier(ProviderKey, person.ResourceName.Split('/')[1]);
                MappedIdentity mappedContent = identityMappingService.Get(externalId, true);

                contactData.ContentLink      = mappedContent.ContentLink;
                contactData.ContentGuid      = mappedContent.ContentGuid;
                contactData.Status           = VersionStatus.Published;
                contactData.IsPendingPublish = false;
                contactData.StartPublish     = DateTime.Now.Subtract(TimeSpan.FromDays(1));

                var name            = (person.Names != null && person.Names.FirstOrDefault() != null ? person.Names.FirstOrDefault().DisplayName : string.Empty);
                var email           = (person.EmailAddresses != null && person.EmailAddresses.FirstOrDefault() != null ? person.EmailAddresses.FirstOrDefault().Value : string.Empty);
                var telephonenumber = (person.PhoneNumbers != null && person.PhoneNumbers.FirstOrDefault() != null ? person.PhoneNumbers.FirstOrDefault().Value : string.Empty);

                contactData.Name        = name;
                contactData.FullName    = name;
                contactData.Email       = email;
                contactData.Phonenumber = telephonenumber;

                var address = (person.Addresses != null && person.Addresses.FirstOrDefault() != null ? person.Addresses.FirstOrDefault() : null);

                if (address != null)
                {
                    contactData.StreetAddress = address.StreetAddress;
                    contactData.PostalCode    = address.PostalCode;
                    contactData.PoBox         = address.PoBox;
                    contactData.City          = address.City;
                    contactData.Region        = address.Region;
                    contactData.Country       = address.Country;
                }

                if (person.Organizations != null && person.Organizations.FirstOrDefault() != null)
                {
                    var organization = person.Organizations.FirstOrDefault();

                    contactData.Company  = organization.Name;
                    contactData.Function = organization.Title;
                }

                contactData.MakeReadOnly();

                return(contactData);
            }
            return(null);
        }
        protected override IList <GetChildrenReferenceResult> LoadChildrenReferencesAndTypes(ContentReference contentLink, string languageID, out bool languageSpecific)
        {
            var identityMappingService = ServiceLocator.Current.GetInstance <IdentityMappingService>();
            var googleContactsService  = ServiceLocator.Current.GetInstance <GoogleContactsService>();

            var contacts = googleContactsService.GetContacts();

            languageSpecific = false;

            var result = contacts.Result.Select(p =>
                                                new GetChildrenReferenceResult()
            {
                // MappedIdentity.ConstructExternalIdentifier(ProviderKey, p.ResourceName.Split('/')[1]): epi.cms.identity://google-contacts-provider/c5792122681440133761
                ContentLink = identityMappingService.Get(MappedIdentity.ConstructExternalIdentifier(ProviderKey, p.ResourceName.Split('/')[1]), true).ContentLink,
                ModelType   = typeof(ContactData)
            }).ToList();

            return(result);
        }
        public override IEnumerable <SearchResult> Search(Query query)
        {
            var searchResults = new List <SearchResult>();

            // Clear previous search results
            _youTubeProvider.SearchResult.Clear();

            foreach (var item in _youTubeRepository.Search(query.SearchQuery))
            {
                if (item.id.kind == "youtube#video")
                {
                    var mappedIdentity      = _identityMappingService.Get(MappedIdentity.ConstructExternalIdentifier(_youTubeProvider.ProviderKey, string.Format("video/{0}/{1}", _youTubeProvider.SearchResultNode.ID, item.id.videoId)), true);
                    var youTubeSearchResult = _youTubeProvider.CreateSearchResult(mappedIdentity, item);
                    searchResults.Add(CreateSearchResult(youTubeSearchResult));
                    _youTubeProvider.SearchResult.Add(youTubeSearchResult);
                }
            }

            // Clear child items from the search node
            DataFactoryCache.RemoveListing(_youTubeProvider.SearchResultNode);

            return(searchResults);
        }
Example #4
0
        protected override IList <GetChildrenReferenceResult> LoadChildrenReferencesAndTypes(ContentReference contentLink, string languageID, out bool languageSpecific)
        {
            languageSpecific = false;
            var childrenList = new List <GetChildrenReferenceResult>();

            // Add Playlists, Subscriptions and Search as default nodes
            if (EntryPoint.CompareToIgnoreWorkID(contentLink))
            {
                childrenList.Add(new GetChildrenReferenceResult {
                    ContentLink = _identityMappingService.Get(MappedIdentity.ConstructExternalIdentifier(ProviderKey, "Playlists"), true).ContentLink, IsLeafNode = false, ModelType = typeof(YouTubeFolder)
                });
                childrenList.Add(new GetChildrenReferenceResult {
                    ContentLink = _identityMappingService.Get(MappedIdentity.ConstructExternalIdentifier(ProviderKey, "Subscriptions"), true).ContentLink, IsLeafNode = false, ModelType = typeof(YouTubeFolder)
                });

                SearchResultNode = _identityMappingService.Get(MappedIdentity.ConstructExternalIdentifier(ProviderKey, "Search"), true).ContentLink;
                childrenList.Add(new GetChildrenReferenceResult {
                    ContentLink = SearchResultNode, IsLeafNode = false, ModelType = typeof(YouTubeFolder)
                });

                return(childrenList);
            }

            var     mappedItem = _identityMappingService.Get(contentLink);
            dynamic items;

            switch (GetYouTubeResourceType(mappedItem.ExternalIdentifier))
            {
            case YouTubeResourceType.PlaylistRoot:

                items = _youTubeRepository.ListPlaylists();
                if (items != null)
                {
                    foreach (var item in items)
                    {
                        var uri = MappedIdentity.ConstructExternalIdentifier(ProviderKey,
                                                                             string.Format("{0}/{1}/{2}", YouTubeResourceType.Playlist.ToString().ToLower(), contentLink.ID, item.id));
                        var mappedChild = _identityMappingService.Get(uri, true);
                        childrenList.Add(new GetChildrenReferenceResult
                        {
                            ContentLink = mappedChild.ContentLink,
                            IsLeafNode  = false,
                            ModelType   = typeof(YouTubePlaylist)
                        });

                        // We have all the data about the YouTube resource and creates the content instance and adds it to the cache.
                        AddContentToCache(CreateYouTubeData(mappedChild, typeof(YouTubePlaylist), item));
                    }
                }
                break;

            case YouTubeResourceType.Playlist:

                items = _youTubeRepository.ListPlaylistItems(mappedItem.ExternalIdentifier.Segments[3]);
                if (items != null)
                {
                    foreach (var item in items)
                    {
                        var uri = MappedIdentity.ConstructExternalIdentifier(ProviderKey,
                                                                             string.Format("{0}/{1}/{2}/{3}", YouTubeResourceType.Playlist.ToString().ToLower(), contentLink.ID,
                                                                                           mappedItem.ExternalIdentifier.Segments[3], item.id));
                        var mappedChild = _identityMappingService.Get(uri, true);
                        childrenList.Add(new GetChildrenReferenceResult
                        {
                            ContentLink = mappedChild.ContentLink,
                            IsLeafNode  = true,
                            ModelType   = typeof(YouTubePlaylistItem)
                        });

                        // We have all the data about the YouTube resource and creates the content instance and adds it to the cache.
                        AddContentToCache(CreatePlaylistItem(mappedChild, item));
                    }
                }
                break;

            case YouTubeResourceType.SubscriptionRoot:

                items = _youTubeRepository.ListSubscriptions();
                if (items != null)
                {
                    foreach (var item in items)
                    {
                        var uri = MappedIdentity.ConstructExternalIdentifier(ProviderKey,
                                                                             string.Format("{0}/{1}/{2}/{3}", YouTubeResourceType.Subscription.ToString().ToLower(), contentLink.ID, item.id,
                                                                                           item.snippet.resourceId.channelId));
                        var mappedChild = _identityMappingService.Get(uri, true);
                        childrenList.Add(new GetChildrenReferenceResult
                        {
                            ContentLink = mappedChild.ContentLink,
                            IsLeafNode  = false,
                            ModelType   = typeof(YouTubeSubscription)
                        });

                        // We have all the data about the YouTube resource and creates the content instance and adds it to the cache.
                        AddContentToCache(CreateYouTubeData(mappedChild, typeof(YouTubeSubscription), item));
                    }
                }
                break;

            case YouTubeResourceType.Subscription:

                items = _youTubeRepository.ListPlaylists(mappedItem.ExternalIdentifier.Segments[4]);
                if (items != null)
                {
                    foreach (var item in items)
                    {
                        var uri = MappedIdentity.ConstructExternalIdentifier(ProviderKey,
                                                                             string.Format("{0}/{1}/{2}", YouTubeResourceType.Playlist.ToString().ToLower(), contentLink.ID, item.id));
                        var mappedChild = _identityMappingService.Get(uri, true);
                        childrenList.Add(new GetChildrenReferenceResult
                        {
                            ContentLink = mappedChild.ContentLink,
                            IsLeafNode  = false,
                            ModelType   = typeof(YouTubePlaylist)
                        });

                        // We have all the data about the YouTube resource and creates the content instance and adds it to the cache.
                        AddContentToCache(CreateYouTubeData(mappedChild, typeof(YouTubePlaylist), item));
                    }
                }
                break;

            case YouTubeResourceType.Search:

                childrenList.AddRange(SearchResult.Select(item => new GetChildrenReferenceResult()
                {
                    ContentLink = item.ContentLink, IsLeafNode = true, ModelType = typeof(YouTubeVideo)
                }));

                break;
            }

            return(childrenList);
        }