コード例 #1
0
        private MappedIdentity MapIdentity(string externalKey, TKey key)
        {
            try
            {
                var mapped = new MappedIdentity(externalKey, key);
                _collection.InsertOne(mapped);
                return(mapped);
            }
            catch (Exception ex)
            {
                if (ex is MongoWriteException || ex is MongoWriteConcernException)
                {
                    if (ex.Message.Contains("E11000 duplicate key"))
                    {
                        var mapped = _collection.FindOneById(externalKey);
                        if (mapped != null)
                        {
                            return(mapped);
                        }
                    }
                }

                throw;
            }

            throw new JarvisFrameworkEngineException("Something went damn wrong...");
        }
コード例 #2
0
        private MappedIdentity MapIdentity(string externalKey, TKey key)
        {
            try
            {
                var mapped = new MappedIdentity(externalKey, key);
                _collection.Insert(mapped);
                return(mapped);
            }
            catch (WriteConcernException ex)
            {
                if (ex.Message.Contains("E11000 duplicate key"))
                {
                    var mapped = _collection.FindOneById(externalKey);
                    if (mapped != null)
                    {
                        return(mapped);
                    }
                }
                else
                {
                    throw;
                }
            }

            throw new Exception("Something went damn wrong...");
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        private YouTubeVideo CreateVideo(MappedIdentity mappedIdentity, dynamic video)
        {
            var contentMedia = CreateYouTubeData(mappedIdentity, typeof(YouTubeVideo), video) as YouTubeVideo;

            contentMedia.VideoId   = video.id;
            contentMedia.Thumbnail = CreateThumbnail(contentMedia);
            return(contentMedia);
        }
コード例 #5
0
        private YouTubePlaylistItem CreatePlaylistItem(MappedIdentity mappedIdentity, dynamic playlistItem)
        {
            var contentMedia = CreateYouTubeData(mappedIdentity, typeof(YouTubePlaylistItem), playlistItem) as YouTubePlaylistItem;

            contentMedia.VideoId   = playlistItem.snippet.resourceId.videoId;
            contentMedia.Thumbnail = CreateThumbnail(contentMedia);
            return(contentMedia);
        }
コード例 #6
0
        private IContent CreateYouTubeData(MappedIdentity mappedIdentity, Type modelType, dynamic youTubeData)
        {
            var content = CreateAndAssignIdentity(mappedIdentity, modelType, youTubeData.snippet.title);

            content.ItemId       = youTubeData.id;
            content.ChannelId    = youTubeData.snippet.channelId;
            content.ChannelTitle = youTubeData.snippet.channelTitle;
            content.Description  = youTubeData.snippet.description;
            content.Published    = DateTime.Parse(youTubeData.snippet.publishedAt);
            content.ThumbnailUrl = youTubeData.snippet.thumbnails.high.url;
            return(content);
        }
コード例 #7
0
        public YouTubeVideo CreateSearchResult(MappedIdentity mappedIdentity, dynamic youTubeData)
        {
            var content = CreateAndAssignIdentity(mappedIdentity, typeof(YouTubeVideo), youTubeData.snippet.title);

            content.VideoId      = youTubeData.id.videoId;
            content.ItemId       = youTubeData.id.videoId;
            content.ChannelId    = youTubeData.snippet.channelId;
            content.ChannelTitle = youTubeData.snippet.channelTitle;
            content.Description  = youTubeData.snippet.description;
            content.Published    = DateTime.Parse(youTubeData.snippet.publishedAt);
            content.ThumbnailUrl = youTubeData.snippet.thumbnails.high.url;

            return(content);
        }
コード例 #8
0
        private IContent CreateAndAssignIdentity(MappedIdentity mappedIdentity, Type modelType, string name)
        {
            // Find parent
            var parentLink = EntryPoint;

            if (modelType == typeof(YouTubeVideo))
            {
                parentLink = SearchResultNode;
            }
            else if (modelType != typeof(YouTubeFolder))
            {
                parentLink = new ContentReference(int.Parse(RemoveEndingSlash(mappedIdentity.ExternalIdentifier.Segments[2])), ProviderKey);
            }

            // Set content type and content type Id.
            var contentType = ContentTypeRepository.Load(modelType);
            var content     = ContentFactory.CreateContent(contentType);

            content.ContentTypeID = contentType.ID;
            content.ParentLink    = parentLink;
            content.ContentGuid   = mappedIdentity.ContentGuid;
            content.ContentLink   = mappedIdentity.ContentLink;
            content.Name          = name;
            (content as IRoutable).RouteSegment = UrlSegment.GetUrlFriendlySegment(content.Name);

            var securable = content as IContentSecurable;

            securable.GetContentSecurityDescriptor().AddEntry(new AccessControlEntry(EveryoneRole.RoleName, AccessLevel.Read));

            var versionable = content as IVersionable;

            if (versionable != null)
            {
                versionable.Status = VersionStatus.Published;
            }

            var changeTrackable = content as IChangeTrackable;

            if (changeTrackable != null)
            {
                changeTrackable.Changed = DateTime.Now;
            }

            return(content);
        }
コード例 #9
0
        private void OnRegistrationMessage(Message msg)
        {
            switch (msg.Command)
            {
            case "USER":
                userMsgSent = true;
                break;

            case "PASS":
                password = msg.Argv[0];
                break;

            case "NICK":
                username = msg.Argv[0];
                break;
            }

            if (username != null && password != null && userMsgSent)
            {
                var    names     = username.Split('.');
                string firstname = names[0];
                string lastname  = names.Count() == 1 ? "resident" : names[1];

                SendFromServer("NOTICE", username, "Connecting to the grid");

                if (upstream.Connect(firstname, lastname, password))
                {
                    selfId = mapper.Client;
                    SendFromServer(Numeric.RPL_WELCOME, username, string.Format("Welcome to the Headless SL Client {0}", selfId.IrcFullId));
                    SendFromServer(Numeric.RPL_YOURHOST, username, "Your host is sl.local, running HeadlessSlClient 0.1");

                    var tokens = new List <string>(supportTokens);
                    foreach (var i in handlers)
                    {
                        tokens.AddRange(i.SupportTokens);
                    }

                    tokens.Add("are supported by this server");

                    SendNumeric(Numeric.RPL_ISUPPORT, tokens.ToArray());
                    state = ConnectionState.CONNECTED;
                }
            }
        }
コード例 #10
0
        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);
        }
コード例 #11
0
        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);
        }
コード例 #12
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);
        }
コード例 #13
0
        private void OnRegistrationMessage(Message msg)
        {
            switch(msg.Command)
            {
                case "USER":
                    userMsgSent = true;
                    break;
                case "PASS":
                    password = msg.Argv[0];
                    break;
                case "NICK":
                    username = msg.Argv[0];
                    break;
            }

            if (username != null && password != null && userMsgSent)
            {
                var names = username.Split('.');
                string firstname = names[0];
                string lastname = names.Count() == 1 ? "resident" : names[1];

                SendFromServer("NOTICE", username, "Connecting to the grid");

                if (upstream.Connect(firstname, lastname, password))
                {
                    selfId = mapper.Client;
                    SendFromServer(Numeric.RPL_WELCOME, username, string.Format("Welcome to the Headless SL Client {0}", selfId.IrcFullId));
                    SendFromServer(Numeric.RPL_YOURHOST, username, "Your host is sl.local, running HeadlessSlClient 0.1");

                    var tokens = new List<string>(supportTokens);
                    foreach(var i in handlers)
                    {
                        tokens.AddRange(i.SupportTokens);
                    }

                    tokens.Add("are supported by this server");

                    SendNumeric(Numeric.RPL_ISUPPORT, tokens.ToArray());
                    state = ConnectionState.CONNECTED;
                }
            }
        }
コード例 #14
0
        public YouTubeVideo CreateSearchResult(MappedIdentity mappedIdentity, dynamic youTubeData)
        {
            var content = CreateAndAssignIdentity(mappedIdentity, typeof(YouTubeVideo), youTubeData.snippet.title);
            content.VideoId = youTubeData.id.videoId;
            content.ItemId = youTubeData.id.videoId;
            content.ChannelId = youTubeData.snippet.channelId;
            content.ChannelTitle = youTubeData.snippet.channelTitle;
            content.Description = youTubeData.snippet.description;
            content.Published = DateTime.Parse(youTubeData.snippet.publishedAt);
            content.ThumbnailUrl = youTubeData.snippet.thumbnails.high.url;

            return content;
        }
コード例 #15
0
 private IContent CreateYouTubeData(MappedIdentity mappedIdentity, Type modelType, dynamic youTubeData)
 {
     var content = CreateAndAssignIdentity(mappedIdentity, modelType, youTubeData.snippet.title);
     content.ItemId = youTubeData.id;
     content.ChannelId = youTubeData.snippet.channelId;
     content.ChannelTitle = youTubeData.snippet.channelTitle;
     content.Description = youTubeData.snippet.description;
     content.Published = DateTime.Parse(youTubeData.snippet.publishedAt);
     content.ThumbnailUrl = youTubeData.snippet.thumbnails.high.url;
     return content;
 }
コード例 #16
0
 private YouTubeVideo CreateVideo(MappedIdentity mappedIdentity, dynamic video)
 {
     var contentMedia = CreateYouTubeData(mappedIdentity, typeof(YouTubeVideo), video) as YouTubeVideo;
     contentMedia.VideoId = video.id;
     contentMedia.Thumbnail = CreateThumbnail(contentMedia);
     return contentMedia;
 }
コード例 #17
0
 private YouTubePlaylistItem CreatePlaylistItem(MappedIdentity mappedIdentity, dynamic playlistItem)
 {
     var contentMedia = CreateYouTubeData(mappedIdentity, typeof(YouTubePlaylistItem), playlistItem) as YouTubePlaylistItem;
     contentMedia.VideoId = playlistItem.snippet.resourceId.videoId;
     contentMedia.Thumbnail = CreateThumbnail(contentMedia);
     return contentMedia;
 }
コード例 #18
0
        private IContent CreateAndAssignIdentity(MappedIdentity mappedIdentity, Type modelType, string name)
        {
            // Find parent
            var parentLink = EntryPoint;
            if (modelType == typeof(YouTubeVideo))
                parentLink = SearchResultNode;
            else if (modelType != typeof(YouTubeFolder))
                parentLink = new ContentReference(int.Parse(RemoveEndingSlash(mappedIdentity.ExternalIdentifier.Segments[2])), ProviderKey);

            // Set content type and content type Id.
            var contentType = ContentTypeRepository.Load(modelType);
            var content = ContentFactory.CreateContent(contentType);
            content.ContentTypeID = contentType.ID;
            content.ParentLink = parentLink;
            content.ContentGuid = mappedIdentity.ContentGuid;
            content.ContentLink = mappedIdentity.ContentLink;
            content.Name = name;
            (content as IRoutable).RouteSegment = UrlSegment.GetUrlFriendlySegment(content.Name);

            var securable = content as IContentSecurable;
            securable.GetContentSecurityDescriptor().AddEntry(new AccessControlEntry(EveryoneRole.RoleName, AccessLevel.Read));

            var versionable = content as IVersionable;
            if (versionable != null)
            {
                versionable.Status = VersionStatus.Published;
            }

            var changeTrackable = content as IChangeTrackable;
            if (changeTrackable != null)
            {
                changeTrackable.Changed = DateTime.Now;
            }

            return content;
        }