public void Test_DefaultUrl_From_Cache_Need_AddItem()
        {
            var baseUrl       = "http://localhost/";
            var connectionStr = "fake_connection_string";
            List <ServerDefaultUrl> lsUrls = new List <ServerDefaultUrl>();

            lsUrls.Add(new ServerDefaultUrl()
            {
                defaultUrl = "http://test.url/", serverId = 1
            });
            var retUrlSet = lsUrls.AsEnumerable();

            mockCacheProvider = new Mock <ICacheProvider>();
            mockCacheProvider.Setup(p => p.TryGetValue <IEnumerable <ServerDefaultUrl> >("CMADefaultUrl_localhost", out retUrlSet)).Returns(true);

            mockDefaultUrlRepository = new Mock <IDefaultUrlRepository>();
            mockDefaultUrlRepository.Setup(p => p.GetDefaultUrl(2, connectionStr)).Returns("http://test2.url");

            defaultUrlService = new DefaultUrlService(mockCacheProvider.Object, mockOptions.Object, mockDefaultUrlRepository.Object);

            var url = defaultUrlService.GetDefaultUrl(2, baseUrl, connectionStr);

            Assert.NotNull(url);
            Assert.Equal("http://test2.url", url);
        }
        public void Test_DefaultUrl_From_Cache()
        {
            var baseUrl       = "http://localhost/";
            var connectionStr = "fake_connection_string";
            List <ServerDefaultUrl> lsUrls = new List <ServerDefaultUrl>();

            lsUrls.Add(new ServerDefaultUrl()
            {
                defaultUrl = "http://test.url/", serverId = 1
            });
            var retUrlSet = lsUrls.AsEnumerable();

            mockCacheProvider = new Mock <ICacheProvider>();
            mockCacheProvider.Setup(p => p.TryGetValue <IEnumerable <ServerDefaultUrl> >("CMADefaultUrl_localhost", out retUrlSet)).Returns(true);

            mockDefaultUrlRepository = new Mock <IDefaultUrlRepository>();
            //mockPeopleSettingsRepository.Setup(p => p.GetPeopleSettings(1, connectionStr)).Returns(new PeopleSettings() { SelectGroups = "1234", ExcludedUser = "******", HiddenAttributres = "dks,da", serverId=1 });

            defaultUrlService = new DefaultUrlService(mockCacheProvider.Object, mockOptions.Object, mockDefaultUrlRepository.Object);

            var url = defaultUrlService.GetDefaultUrl(1, baseUrl, connectionStr);

            Assert.NotNull(url);
            Assert.Equal("http://test.url/", url);
        }
Beispiel #3
0
        public IEnumerable <News> GetNews(int serverId, string baseUrl)
        {
            string connectionStr = _dbConnectionService.GetConnection(baseUrl);

            if (string.IsNullOrEmpty(connectionStr))
            {
                _logger.Error($"Get connection string based on {baseUrl} failed.");
                return(null);
            }

            string serverUrl = _defaultUrlService.GetDefaultUrl(serverId, baseUrl, connectionStr);

            if (string.IsNullOrEmpty(serverUrl))
            {
                _logger.Information($"No url found based on server id {serverId}.");
            }

            var rawNews = _databaseProvider.GetData <RawNews>(connectionStr, "[dbo].[cma_news_get]", new { server_id = serverId }, CommandType.StoredProcedure);

            List <News> news = new List <News>();

            foreach (RawNews rn in rawNews)
            {
                News n = LoadXmlData(rn.xmlData);
                if (string.IsNullOrEmpty(n.Body) &&
                    string.IsNullOrEmpty(n.Title) &&
                    string.IsNullOrEmpty(n.Summary))
                {
                    continue;
                }
                n.ServerId = serverId;

                if (n.PublishedDate.Year < 1900)
                {
                    n.PublishedDate = n.PageLastModified;
                }

                n.Body = n.Body.Replace("href=\"/", "href=" + "\"" + serverUrl).Replace("src=\"/", "src=" + "\"" + serverUrl);

                //AG3070 add abolutely url featuerImage and linkofCurrentPage
                if (!string.IsNullOrEmpty(n.LinkOfCurrentPage) && !n.LinkOfCurrentPage.StartsWith("http"))
                {
                    n.LinkOfCurrentPage = serverUrl + n.LinkOfCurrentPage;
                }
                if (!string.IsNullOrEmpty(n.FeaturedImage) && !n.FeaturedImage.StartsWith("http"))
                {
                    n.FeaturedImage = serverUrl + n.FeaturedImage;
                }

                news.Add(n);
            }
            return(news);
        }
        public IEnumerable <PersonInfo> GetPeopleInfo(string baseUrl, IEnumerable <Person> people)
        {
            string connectionStr = _dbConnectionService.GetConnection(baseUrl);

            string imageUrlFormat = "{0}common/pages/GalleryPhoto.aspx?photoId={1}&width=180&height=180";

            int[]  userIds           = people.Select(s => s.UserId).Distinct().ToArray();
            int[]  userFromServerIds = people.Select(s => s.ServerId).Distinct().ToArray();
            string strUserIds        = string.Join(",", userIds);
            //1. Load server information for [serverHiddenAttributes], [serverDefaultUrls]
            Dictionary <int, List <string> > serverHiddenAttributes = new Dictionary <int, List <string> >();
            Dictionary <int, string>         serverDefaultUrls      = new Dictionary <int, string>();

            foreach (int serverId in userFromServerIds)
            {
                PeopleSettings peopleSetting = _peopleSettingsService.GetPeopleSettings(serverId, baseUrl, connectionStr);
                serverHiddenAttributes.Add(serverId, peopleSetting.HiddenAttributres.Split(',').ToList());
                string defaultUrl = _defaultUrlService.GetDefaultUrl(serverId, baseUrl, connectionStr);
                if (!string.IsNullOrEmpty(defaultUrl))
                {
                    serverDefaultUrls.Add(serverId, defaultUrl);
                }
            }

            //2. Get data for all users details and attributes
            var peopleList           = _databaseProvider.GetData <PersonInfo>(connectionStr, "[dbo].[cma_people_userinfo]", new { userIds = strUserIds }, CommandType.StoredProcedure);
            var peopleListAttributes = _databaseProvider.GetData <MAttribute>(connectionStr, "[dbo].[cma_people_attributes]", new { userIds = strUserIds }, CommandType.StoredProcedure);

            //3. Loop by [simplePersonList], add details to person to [personList]
            List <PersonInfo> resultPeople = new List <PersonInfo>();

            foreach (Person p in people)
            {
                //3.1 Add person details
                PersonInfo personInfo = peopleList.Where(x => x.UserId == p.UserId).FirstOrDefault();
                personInfo.ServerId = p.ServerId;
                if (personInfo.ImageUrl != null)
                {
                    personInfo.ImageUrl = int.Parse(personInfo.ImageUrl) > 0 ? string.Format(imageUrlFormat, serverDefaultUrls[p.ServerId], int.Parse(personInfo.ImageUrl)) : "";
                }

                if (!serverHiddenAttributes[p.ServerId].Contains("youtube"))
                {
                    personInfo.YouTube = peopleListAttributes.Where(x => x.ObjectId == p.UserId && x.AttributeName == "youtube").Select(v => v.AttributeValue).FirstOrDefault();
                }

                if (!serverHiddenAttributes[p.ServerId].Contains("facebook"))
                {
                    personInfo.Facebook = peopleListAttributes.Where(x => x.ObjectId == p.UserId && x.AttributeName == "facebook").Select(v => v.AttributeValue).FirstOrDefault();
                }

                if (!serverHiddenAttributes[p.ServerId].Contains("twitter"))
                {
                    personInfo.Twitter = peopleListAttributes.Where(x => x.ObjectId == p.UserId && x.AttributeName == "twitter").Select(v => v.AttributeValue).FirstOrDefault();
                }

                if (!serverHiddenAttributes[p.ServerId].Contains("blog"))
                {
                    personInfo.Blog = peopleListAttributes.Where(x => x.ObjectId == p.UserId && x.AttributeName == "blog").Select(v => v.AttributeValue).FirstOrDefault();
                }

                if (!serverHiddenAttributes[p.ServerId].Contains("personal_message"))
                {
                    personInfo.PersonalMessage = peopleListAttributes.Where(x => x.ObjectId == p.UserId && x.AttributeName == "personal_message").Select(v => v.AttributeValue).FirstOrDefault();
                }

                if (!serverHiddenAttributes[p.ServerId].Contains("website"))
                {
                    personInfo.Website = peopleListAttributes.Where(x => x.ObjectId == p.UserId && x.AttributeName == "website").Select(v => v.AttributeValue).FirstOrDefault();
                }

                if (personInfo.Website != null && personInfo.Website.StartsWith("/"))
                {
                    personInfo.Website = serverDefaultUrls[p.ServerId] + personInfo.Website.Substring(1);
                }

                resultPeople.Add(personInfo);
            }
            return(resultPeople);
        }