Ejemplo n.º 1
0
        public IEnumerable <Person> GetPeople(int serverId, string baseUrl)
        {
            string connectionStr = _dbConnectionService.GetConnection(baseUrl);

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

            //1.Get portlet Instance Properties to [selectedGroups], [excludedUsers], [HiddenAttributes]
            PeopleSettings peopleSetting = _peopleSettingsService.GetPeopleSettings(serverId, baseUrl, connectionStr);

            //2.Get all users with [selectedGroups]
            if (peopleSetting == null || string.IsNullOrEmpty(peopleSetting.SelectGroups))
            {
                _logger.Error($"No selected groups found based on {baseUrl}.");
                return(new List <Person>());
            }
            var people = _databaseProvider.GetData <Person>(connectionStr, "[dbo].[cma_people_simple]", new
                                                            { group_ids = peopleSetting.SelectGroups }, CommandType.StoredProcedure);

            //3.Remove excluded users
            if (string.IsNullOrEmpty(peopleSetting.ExcludedUser))
            {
                foreach (Person p in people)
                {
                    p.ServerId = serverId;
                }
                return(people);
            }
            else
            {
                var spUsers         = new List <Person>();
                var lsExcludedUsers = peopleSetting.ExcludedUser.Split(',').Select(int.Parse);
                foreach (Person p in people)
                {
                    if (!lsExcludedUsers.Contains(p.UserId))
                    {
                        spUsers.Add(new Person
                        {
                            UserId    = p.UserId,
                            FirstName = p.FirstName,
                            LastName  = p.LastName,
                            JobTitle  = p.JobTitle,
                            ServerId  = serverId
                        });
                    }
                }
                return(spUsers);
            }
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        public void Test_GetConnection_From_Repository()
        {
            string conn = "asdfa";

            mockCacheProvider = new Mock <ICacheProvider>();
            mockCacheProvider.Setup(p => p.TryGetValue <string>("CMAConnections_localhost", out conn)).Returns(false);

            mockConnectionRepository = new Mock <IConnectionRepository>();
            mockConnectionRepository.Setup(p => p.GetConnection("http://localhost/")).Returns("conn_111");

            dbConnectionService = new DBConnectionService(mockCacheProvider.Object, mockOptions.Object, mockConnectionRepository.Object);
            string connStr = dbConnectionService.GetConnection("http://localhost/");

            Assert.Equal("conn_111", connStr);
        }
Ejemplo n.º 4
0
        public IEnumerable <School> GetSchools(string baseUrl)
        {
            string connectionStr = _dbConnectionService.GetConnection(baseUrl);

            if (string.IsNullOrEmpty(connectionStr))
            {
                _logger.Error($"Get connection string based on {baseUrl} failed.");
                return(null);
            }
            int serverId = _databaseProvider.GetCellValue <int>(connectionStr, "SELECT TOP 1 server_id FROM click_server_urls WHERE url = @url", new { url = baseUrl }, CommandType.Text);

            if (serverId <= 0)
            {
                _logger.Error($"No server_id found based on {baseUrl}.");
                return(null);
            }
            var schools = _databaseProvider.GetData <School>(connectionStr, "[dbo].[cma_server_v2]", new { district_server_id = serverId }, CommandType.StoredProcedure);

            if (schools.Count() == 0)
            {
                _logger.Information($"No school found by based on {baseUrl} : {serverId}");
                return(schools);
            }

            foreach (School s in schools)
            {
                var atts = _databaseProvider.GetData <MAttribute>(connectionStr, "[dbo].[cma_server_attributes.get]", new { server_id = s.ServerId }, CommandType.StoredProcedure);
                s.Address = new Address()
                {
                    Address1 = atts.Where(a => a.AttributeName == "org_address1").Select(x => x.AttributeValue).FirstOrDefault(),
                    Address2 = atts.Where(a => a.AttributeName == "org_address2").Select(x => x.AttributeValue).FirstOrDefault(),
                    City     = atts.Where(a => a.AttributeName == "org_city").Select(x => x.AttributeValue).FirstOrDefault(),
                    Country  = atts.Where(a => a.AttributeName == "org_country").Select(x => x.AttributeValue).FirstOrDefault(),
                    PostCode = atts.Where(a => a.AttributeName == "org_postal").Select(x => x.AttributeValue).FirstOrDefault(),
                    Province = atts.Where(a => a.AttributeName == "org_province").Select(x => x.AttributeValue).FirstOrDefault()
                };

                s.Phone    = atts.Where(a => a.AttributeName == "org_phone").Select(x => x.AttributeValue).FirstOrDefault();
                s.Slogan   = atts.Where(a => a.AttributeName == "org_slogan").Select(x => x.AttributeValue).FirstOrDefault();
                s.Fax      = atts.Where(a => a.AttributeName == "org_fax").Select(x => x.AttributeValue).FirstOrDefault();
                s.Facebook = atts.Where(a => a.AttributeName == "org_facebook_website").Select(x => x.AttributeValue).FirstOrDefault();
                s.Twitter  = atts.Where(a => a.AttributeName == "org_twitter_website").Select(x => x.AttributeValue).FirstOrDefault();
                s.Youtube  = atts.Where(a => a.AttributeName == "org_youtube_channel").Select(x => x.AttributeValue).FirstOrDefault();
                s.Email    = atts.Where(a => a.AttributeName == "org_email_address").Select(x => x.AttributeValue).FirstOrDefault();
            }

            return(schools);
        }
Ejemplo n.º 5
0
        public IEnumerable <Channel2Group> GetChannel2Group(string baseUrl, int districtServerId)
        {
            string connectionStr = _dbConnectionService.GetConnection(baseUrl);

            return(_databaseProvider.GetData <Channel2Group>(connectionStr, "[dbo].[cma_c2g.get_all]", new { district_server_Id = districtServerId }, CommandType.StoredProcedure));
        }
Ejemplo n.º 6
0
 public UserDataService(IDBConnectionService connectionService)
 {
     _masterConnection = connectionService.GetConnection();
     _masterConnection.CreateTableAsync <User>();
 }
Ejemplo n.º 7
0
 public PostDataService(IDBConnectionService connectionService)
 {
     _masterConnection = connectionService.GetConnection();
     _masterConnection.CreateTableAsync <Post>();
 }
Ejemplo n.º 8
0
        public IEnumerable <Event> GetEvents(int serverId, string baseUrl, DateTime startDate, DateTime endDate, bool cutEvents = true)
        {
            string connectionStr = _dBConnectionService.GetConnection(baseUrl);

            if (string.IsNullOrEmpty(connectionStr))
            {
                return(new List <Event>());
            }

            int calendarId = _databaseProvider.GetCellValue <int>(connectionStr, "SELECT TOP 1 object_id FROM cma_entries WHERE server_id=@serverId AND content_type='calendar'", new { serverId = serverId }, CommandType.Text);

            if (calendarId <= 0)
            {
                return(new List <Event>());
            }

            var responseData = _httpClientProvider.SoapPostData <Event>($"{baseUrl}common/controls/workspacecalendar/ws/workspacecalendarws.asmx/GetEventsByCalendarId", new
            {
                calendarId = serverId,
                startTime  = startDate,
                endTime    = endDate
            }, "PresenceApi");

            if (responseData == null)
            {
                return(responseData);
            }

            if (cutEvents)
            {
                List <Event> rerangeEvents = new List <Event>();
                foreach (Event ce in responseData)
                {
                    if (ce.EndTime.Date > ce.StartTime.Date)
                    {
                        // Split Multiple Event for cross date event
                        double days = Convert.ToInt32((ce.EndTime.Date - ce.StartTime.Date).TotalDays) + 1;
                        for (int i = 1; i <= days; i++)
                        {
                            DateTime tStartTime = i == 1 ? ce.StartTime : ce.StartTime.Date.AddDays(i - 1);
                            DateTime tEndTime   = i == days ? ce.EndTime : ce.StartTime.Date.AddDays(i).AddSeconds(-1);
                            if (tStartTime == tEndTime && tStartTime.ToString("HH:mm:ss") == "23:59:59")
                            {
                                continue;
                            }
                            Event newCe = new Event();
                            newCe.EventId     = int.Parse(ce.EventId.ToString() + i.ToString());
                            newCe.Description = ce.Description;
                            newCe.StartTime   = tStartTime;
                            newCe.EndTime     = tEndTime;
                            newCe.ServerId    = ce.ServerId;
                            rerangeEvents.Add(newCe);
                        }
                    }
                    else
                    {
                        ce.ServerId = serverId;
                        rerangeEvents.Add(ce);
                    }
                }

                return(rerangeEvents);
            }
            else
            {
                foreach (Event e in responseData)
                {
                    e.ServerId = serverId;
                }

                return(responseData);
            }
        }
Ejemplo n.º 9
0
 public NotificationDataService(IDBConnectionService connectionService)
 {
     _masterConnection = connectionService.GetConnection();
     _masterConnection.CreateTableAsync <Notification>();
 }