Beispiel #1
0
        public ActionResult ROI([FromServices] IBlogRepository repository)
        {
            var blogs      = repository.GetAll();
            var collection = new BlogCollection(blogs, 1, 0, "ROI", BlogCollection.OrderBy.PublishedAscending);

            return(View(collection));
        }
Beispiel #2
0
        public async Task <IActionResult> Put([FromODataUri] int id, [FromBody] BlogCollection update)
        {
            if (!ModelState.IsValid)
            {
                HIHAPIUtility.HandleModalStateError(ModelState);
            }

            // User
            string usrName;

            try
            {
                usrName = HIHAPIUtility.GetUserID(this);
                if (String.IsNullOrEmpty(usrName))
                {
                    throw new UnauthorizedAccessException();
                }
                if (String.CompareOrdinal(update.Owner, usrName) != 0)
                {
                    throw new UnauthorizedAccessException();
                }
            }
            catch
            {
                throw new UnauthorizedAccessException();
            }

            // Check setting
            var setting = _context.BlogUserSettings.SingleOrDefault(p => p.Owner == usrName);

            if (setting == null)
            {
                throw new BadRequestException(" User has no setting ");
            }

            // Check ID
            if (id != update.ID)
            {
                return(BadRequest());
            }

            _context.Entry(update).State = EntityState.Modified;
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!_context.BlogCollections.Any(p => p.ID == id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Updated(update));
        }
Beispiel #3
0
        private static void ConnectMapContainerToCollections()
        {
            var mapContainers = GetAllInformationObjects(null, io => io is MapContainer).Cast <MapContainer>().ToArray();

            foreach (var mapContainer in mapContainers)
            {
                mapContainer.MarkerSourceActivities = ActivityCollection.CreateDefault();
                mapContainer.MarkerSourceBlogs      = BlogCollection.CreateDefault();
                mapContainer.MarkerSourceLocations  = AddressAndLocationCollection.CreateDefault();
                mapContainer.ReconnectMastersAndCollections(true);
            }
        }
        // GET: /<controller>/
        public IActionResult Index([FromServices] IBlogRepository repository,
                                   string url,
                                   int pageNo       = 1,
                                   int blogsPerPage = 12,
                                   string filterBy  = null,
                                   OrderBy orderBy  = OrderBy.PublishedDescending,
                                   bool reload      = false)
        {
            try
            {
                if (reload)
                {
                    repository.Reload();
                }

                if (url == null || url.Length == 0)
                {
                    var blogs      = repository.GetAll();
                    var collection = new BlogCollection(blogs, pageNo, blogsPerPage, filterBy, orderBy);
                    return(View("BlogList", collection));
                }
                else
                {
                    var meta    = repository.Get(url);
                    var content = repository.LoadContent(meta);
                    var blog    = new BlogWithContent
                    {
                        Meta    = meta,
                        Content = content
                    };
                    return(View("Blog", blog));
                }
            }
            catch (BlogNotFoundException ex)
            {
                _telemetry.TrackException(ex);
                return(new RedirectResult("/errors/status/404"));
            }
            catch (BlogNotEnabledException ex)
            {
                _telemetry.TrackException(ex);
                return(new RedirectResult("/errors/status/404"));
            }
            catch (Exception ex)
            {
                _telemetry.TrackException(ex);
                return(new RedirectResult("/errors/status/500"));
            }
        }
        public void BlogsGetListTest()
        {
            BlogCollection blogs = AuthInstance.BlogsGetList();

            Assert.IsNotNull(blogs, "Blogs should not be null.");

            foreach (Blog blog in blogs)
            {
                Assert.IsNotNull(blog.BlogId, "BlogId should not be null.");
                Assert.IsNotNull(blog.NeedsPassword, "NeedsPassword should not be null.");
                Assert.IsNotNull(blog.BlogName, "BlogName should not be null.");
                Assert.IsNotNull(blog.BlogUrl, "BlogUrl should not be null.");
                Assert.IsNotNull(blog.Service, "Service should not be null.");
            }
        }
Beispiel #6
0
        public async Task <IActionResult> Post([FromBody] BlogCollection coll)
        {
            if (!ModelState.IsValid)
            {
                HIHAPIUtility.HandleModalStateError(ModelState);
            }

            // User
            string usrName;

            try
            {
                usrName = HIHAPIUtility.GetUserID(this);
                if (String.IsNullOrEmpty(usrName))
                {
                    throw new UnauthorizedAccessException();
                }
                if (coll.Owner != null)
                {
                    if (String.CompareOrdinal(coll.Owner, usrName) != 0)
                    {
                        throw new UnauthorizedAccessException();
                    }
                }
                else
                {
                    coll.Owner = usrName;
                }
            }
            catch
            {
                throw new UnauthorizedAccessException();
            }

            // Check setting
            var setting = _context.BlogUserSettings.SingleOrDefault(p => p.Owner == usrName);

            if (setting == null)
            {
                throw new BadRequestException(" User has no setting ");
            }

            _context.BlogCollections.Add(coll);
            await _context.SaveChangesAsync();

            return(Created(coll));
        }
        private void TestsThemeEditWindow_Loaded(object sender, RoutedEventArgs e)
        {
            Loaded -= TestsThemeEditWindow_Loaded;
            //创建数据源
            DateTime       dt   = DateTime.Now.AddHours(-12);
            BlogCollection b    = new BlogCollection();
            Random         rand = new Random();

            for (int i = 1; i <= 100; i++)
            {
                AyBlog ay = new AyBlog();
                ay.Name       = "wpf" + i;
                ay.Content    = "正在更新,已经过去了第" + i + "天";
                ay.CreateTime = dt.AddMinutes(i);
                ay.ReadCount  = rand.Next(100, 1000000);
                b.Add(ay);
            }
        }
Beispiel #8
0
 public IActionResult CreateBlog([FromBody] BlogRequestBody blogRequest)
 {
     try
     {
         _blogDataService.CreateCollectionData(blogRequest.data);
         var newBlog = new BlogCollection()
         {
             UserEmail = blogRequest.UserEmail,
             BlogName  = blogRequest.data.BlogDocument.BlogDetails.Title
         };
         _blogsService.CreateBlog(newBlog);
         return(NoContent());
     } catch (Exception e)
     {
         Log.Warning($"Incorred Request - error: {e.Message}");
         return(BadRequest(e.Message));
     }
 }
Beispiel #9
0
        internal static void Update_BlogIndexGroup_BlogSourceForSummary(BlogIndexGroup blogIndexGroup, BlogCollection localCollection, BlogCollection masterCollection)
        {
            if (localCollection == null)
            {
                localCollection = BlogCollection.CreateDefault();
            }
            localCollection.CollectionContent.Clear();
            var limitDateTime = DateTime.UtcNow.AddMonths(-3);
            var relevantBlogs =
                masterCollection.CollectionContent.Where(blog => blog.Published >= limitDateTime).OrderByDescending(blog => blog.Published).Take(10).ToArray();
            var blogsByAuthor = relevantBlogs.GroupBy(blog => blog.Author).OrderBy(grpItem => grpItem.Key).ToArray();

            if (blogIndexGroup.GroupedByAuthor == null)
            {
                blogIndexGroup.GroupedByAuthor = GroupedInformationCollection.CreateDefault();
            }
            blogIndexGroup.GroupedByAuthor.CollectionContent.Clear();
            blogIndexGroup.GroupedByAuthor.CollectionContent.AddRange(blogsByAuthor.Select(blogGroupToGroupedInformation));

            if (blogIndexGroup.GroupedByCategory == null)
            {
                blogIndexGroup.GroupedByCategory = GroupedInformationCollection.CreateDefault();
            }
            if (blogIndexGroup.GroupedByDate == null)
            {
                blogIndexGroup.GroupedByDate = GroupedInformationCollection.CreateDefault();
            }
            if (blogIndexGroup.GroupedByLocation == null)
            {
                blogIndexGroup.GroupedByLocation = GroupedInformationCollection.CreateDefault();
            }

            var archiveSeq = masterCollection.CollectionContent.OrderByDescending(blog => blog.Published)
                             .ThenBy(blog => blog.Title)
                             .Select(blog => blog.ReferenceToInformation);

            if (blogIndexGroup.FullBlogArchive == null)
            {
                blogIndexGroup.FullBlogArchive = ReferenceCollection.CreateDefault();
            }
            blogIndexGroup.FullBlogArchive.CollectionContent.Clear();
            blogIndexGroup.FullBlogArchive.CollectionContent.AddRange(archiveSeq);
        }
Beispiel #10
0
        public int CreateBlogPage(int profileid)
        {
            var blogpagecontext       = _theContext.BlogPages;
            var archivecontext        = _theContext.Archives;
            var blogcollectioncontext = _theContext.BlogCollections;
            var timestamp             = DateTime.Now;
            var blogitem = new BlogPage
            {
                ProfileID         = profileid,
                TagID             = 1,
                DateArchiveID     = 1,
                CategoryArchiveID = 1,
                HeaderTitle       = "Fill Title",
                HeaderImage       = "/img/testimonial-2.jpg",
                CreationDate      = timestamp,
                LastEditDate      = DateTime.Now,
                Text = "<h2 class=\"dfree-header mce-content-body\" contenteditable=\"true\" style=\"position: relative;\" spellcheck=\"false\">Add a Title</h2><br/><div class=\"dfree-body mce-content-body\" contenteditable=\"true\" style=\"position: relative;\" spellcheck=\"false\"><p><img src=\"\" style=\"display: block; margin-left: auto; margin-right: auto; width: 100%;\" data-mce-style=\"display: block; margin-left: auto; margin-right: auto;\" data-mce-selected=\"1\">Add Image</p><br/><h2>Add header.</h2><p>Have you heard about Tiny Cloud?   It’s the first step in our journey to help you deliver great content creation experiences, no matter your level of expertise. 50,000 developers already agree. They get free access to our global CDN, image proxy services and auto updates to the TinyMCE editor. They’re also ready for some exciting updates coming soon.</p>  <p>One of these enhancements is <strong>Tiny Drive</strong>: imagine file management for TinyMCE, in the cloud, made super easy. Learn more at <a href='https://www.tiny.cloud/tinydrive/'>tiny.cloud/tinydrive</a>, where you’ll find a working demo and an opportunity to provide feedback to the product team. </p><h3>An editor for every project</h3> <p>  Here are some of our customer’s most common use cases for TinyMCE:  <ul><li>Content Management Systems (<em>e.g. WordPress, Umbraco</em>)</li> <li>Learning Management Systems (<em>e.g. Blackboard</em>)</li>  <li>Customer Relationship Management and marketing automation (<em>e.g. Marketo</em>)</li> <li>Email marketing (<em>e.g. Constant Contact</em>)</li><li>Content creation in SaaS systems (<em>e.g. Eventbrite, Evernote, GoFundMe, Zendesk</em>)</li></ul> </p> <p>  And those use cases are just the start. TinyMCE is incredibly flexible, and with hundreds of APIs there’s likely a solution for your editor project.    If you haven’t experienced Tiny Cloud, get started today.   You’ll even get a free trial of our premium plugins – no credit card required! </p></div>"
            };

            blogpagecontext.Add(blogitem);
            _theContext.SaveChanges();
            var newpage = _theContext.BlogPages.Where(s => s.CreationDate == timestamp).FirstOrDefault <BlogPage>();


            var blogCollection = new BlogCollection
            {
                ProfileID         = profileid,
                BlogPageID        = newpage.BlogPageID,
                PersonalStatement = "Statement",
                ArchiveID         = 1
            };

            blogcollectioncontext.Add(blogCollection);
            _theContext.SaveChanges();


            return(newpage.BlogPageID);
        }
 internal static void Update_RecentBlogSummary_RecentBlogCollection(RecentBlogSummary recentBlogSummary, BlogCollection localCollection, BlogCollection masterCollection)
 {
     localCollection.CollectionContent = masterCollection.CollectionContent.OrderByDescending(blog => blog.Published).Take(3).ToList();
     if(localCollection.OrderFilterIDList == null)
         localCollection.OrderFilterIDList = new List<string>();
 }
        public async Task TestCase1(string user)
        {
            var context = this.fixture.GetCurrentDataContext();

            fixture.InitBlogTestData(context);

            var control   = new BlogCollectionsController(context);
            var userclaim = DataSetupUtility.GetClaimForUser(user);
            var httpctx   = UnitTestUtility.GetDefaultHttpContext(provider, userclaim);

            control.ControllerContext = new ControllerContext()
            {
                HttpContext = httpctx
            };

            var existedamt = (from coll in context.BlogCollections where coll.Owner == user select coll).ToList().Count();

            // Step 1. Read all
            var rsts    = control.Get();
            var rstscnt = await rsts.CountAsync();

            Assert.Equal(existedamt, rstscnt);

            // Step 2. Create one new collection
            var newcoll = new BlogCollection()
            {
                Owner   = user,
                Name    = "TestCase1_Add_" + user,
                Comment = "TestCase1_Add_" + user,
            };
            var rst = await control.Post(newcoll);

            Assert.NotNull(rst);
            var rst2 = Assert.IsType <CreatedODataResult <BlogCollection> >(rst);

            objectsCreated.Add(rst2.Entity.ID);
            newcoll.ID = rst2.Entity.ID;
            Assert.Equal(rst2.Entity.Name, newcoll.Name);
            Assert.Equal(rst2.Entity.Comment, newcoll.Comment);
            Assert.Equal(rst2.Entity.Owner, user);

            // Step 3. Read all
            rsts    = control.Get();
            rstscnt = await rsts.CountAsync();

            Assert.Equal(existedamt + 1, rstscnt);

            // Step 4. Change it
            newcoll.Name = "Tobe Delteed";
            var rst3 = await control.Put(newcoll.ID, newcoll);

            Assert.NotNull(rst3);
            var rst3a = Assert.IsType <UpdatedODataResult <BlogCollection> >(rst3);

            Assert.Equal(newcoll.Name, rst3a.Entity.Name);

            // Step 5. Delete it
            var rst5 = await control.Delete(newcoll.ID);

            Assert.NotNull(rst5);
            objectsCreated.Remove(newcoll.ID);
            var rst5a = Assert.IsType <StatusCodeResult>(rst5);

            Assert.Equal(204, rst5a.StatusCode);

            // Step 6. Read it again
            rsts    = control.Get();
            rstscnt = await rsts.CountAsync();

            Assert.Equal(existedamt, rstscnt);

            await context.DisposeAsync();
        }
Beispiel #13
0
        internal static void Update_NodeSummaryContainer_NodeSourceBlogs(NodeSummaryContainer nodeSummaryContainer, BlogCollection localCollection, BlogCollection masterCollection)
        {
            var nodes = nodeSummaryContainer.Nodes;

            nodes.CollectionContent.RemoveAll(node => node.TechnicalSource == NodeSourceTypeBlog);
            var blogNodes = masterCollection.CollectionContent.Select(getNodeFromBlog).ToArray();

            nodes.CollectionContent.AddRange(blogNodes);
            cleanUpRenderedNodes(nodes);
        }
Beispiel #14
0
 internal static void Update_RecentBlogSummary_RecentBlogCollection(RecentBlogSummary recentBlogSummary, BlogCollection localCollection, BlogCollection masterCollection)
 {
     localCollection.CollectionContent = masterCollection.CollectionContent.Where(blog => blog.Published >= DateTime.UtcNow.AddMonths(-3)).OrderByDescending(blog => blog.Published).Take(10).ToList();
     //localCollection.CollectionContent = masterCollection.CollectionContent;
     if (localCollection.OrderFilterIDList == null)
     {
         localCollection.OrderFilterIDList = new List <string>();
     }
     localCollection.IsCollectionFiltered = false;
 }
Beispiel #15
0
        internal static void Update_MapContainer_MarkerSourceBlogs(MapContainer mapContainer, BlogCollection localCollection, BlogCollection masterCollection)
        {
            mapContainer.MapMarkers.CollectionContent.RemoveAll(
                marker => marker.MarkerSource == MapMarker.MarkerSourceBlogValue);
            var locationBlogs =
                masterCollection.CollectionContent.Select(
                    blog => new { Blog = blog, Locations = blog.LocationCollection.GetIDSelectedArray() });
            Dictionary <string, LocationSpot> locDict = new Dictionary <string, LocationSpot>();

            foreach (var locBlog in locationBlogs)
            {
                foreach (var location in locBlog.Locations)
                {
                    string       key = location.Location.GetLocationText();
                    LocationSpot locSpot;
                    locDict.TryGetValue(key, out locSpot);
                    if (locSpot == null)
                    {
                        locSpot = new LocationSpot {
                            LocationText = key, Location = location.Location
                        };
                        locDict.Add(key, locSpot);
                    }
                    locSpot.AddBlog(locBlog.Blog);
                }
            }
            List <MapMarker> markers = new List <MapMarker>();

            foreach (var dictItem in locDict)
            {
                var       locSpot = dictItem.Value;
                MapMarker marker  = MapMarker.CreateDefault();
                marker.Location     = locSpot.Location;
                marker.MarkerSource = MapMarker.MarkerSourceBlogValue;
                marker.IconUrl      = GetIconUrlForCategory("News");
                marker.CategoryName = GetMarkerCategoryName("News");
                marker.LocationText = locSpot.LocationText;
                marker.SetLocationTextFromLocation(locSpot.Location);
                marker.PopupTitle = "News";
                StringBuilder strBuilder = new StringBuilder();
                foreach (var blogItem in locSpot.Blogs)
                {
                    ReferenceToInformation referenceToInformation = blogItem.ReferenceToInformation;
                    appendMarkerLink(strBuilder, referenceToInformation);
                }
                marker.PopupContent = strBuilder.ToString();
                markers.Add(marker);
            }

            mapContainer.MapMarkers.CollectionContent.AddRange(markers);
        }
Beispiel #16
0
 // create new blog
 public void CreateBlog(BlogCollection blogsCollection)
 {
     _blogs.InsertOne(blogsCollection);
 }
 internal static void Update_RecentBlogSummary_RecentBlogCollection(RecentBlogSummary recentBlogSummary, BlogCollection localCollection, BlogCollection masterCollection)
 {
     localCollection.CollectionContent = masterCollection.CollectionContent.Where(blog => blog.Published >= DateTime.UtcNow.AddMonths(-3)).OrderByDescending(blog => blog.Published).Take(10).ToList();
     //localCollection.CollectionContent = masterCollection.CollectionContent;
     if(localCollection.OrderFilterIDList == null)
         localCollection.OrderFilterIDList = new List<string>();
     localCollection.IsCollectionFiltered = false;
 }
 internal static void Update_NodeSummaryContainer_NodeSourceBlogs(NodeSummaryContainer nodeSummaryContainer, BlogCollection localCollection, BlogCollection masterCollection)
 {
     var nodes = nodeSummaryContainer.Nodes;
     nodes.CollectionContent.RemoveAll(node => node.TechnicalSource == NodeSourceTypeBlog);
     var blogNodes = masterCollection.CollectionContent.Select(getNodeFromBlog).ToArray();
     nodes.CollectionContent.AddRange(blogNodes);
     cleanUpRenderedNodes(nodes);
 }
        internal static void Update_MapContainer_MarkerSourceBlogs(MapContainer mapContainer, BlogCollection localCollection, BlogCollection masterCollection)
        {
            mapContainer.MapMarkers.CollectionContent.RemoveAll(
                marker => marker.MarkerSource == MapMarker.MarkerSourceBlogValue);
            var locationBlogs =
                masterCollection.CollectionContent.Select(
                    blog => new { Blog = blog, Locations = blog.LocationCollection.GetIDSelectedArray() });
            Dictionary<string, LocationSpot> locDict = new Dictionary<string, LocationSpot>();
            foreach (var locBlog in locationBlogs)
            {
                foreach (var location in locBlog.Locations)
                {
                    string key = location.Location.GetLocationText();
                    LocationSpot locSpot;
                    locDict.TryGetValue(key, out locSpot);
                    if (locSpot == null)
                    {
                        locSpot = new LocationSpot { LocationText = key, Location = location.Location };
                        locDict.Add(key, locSpot);
                    }
                    locSpot.AddBlog(locBlog.Blog);
                }
            }
            List<MapMarker> markers = new List<MapMarker>();
            foreach (var dictItem in locDict)
            {
                var locSpot = dictItem.Value;
                MapMarker marker = MapMarker.CreateDefault();
                marker.Location = locSpot.Location;
                marker.MarkerSource = MapMarker.MarkerSourceBlogValue;
                marker.IconUrl = GetIconUrlForCategory("News");
                marker.CategoryName = GetMarkerCategoryName("News");
                marker.LocationText = locSpot.LocationText;
                marker.SetLocationTextFromLocation(locSpot.Location);
                marker.PopupTitle = "News";
                StringBuilder strBuilder = new StringBuilder();
                foreach (var blogItem in locSpot.Blogs)
                {
                    ReferenceToInformation referenceToInformation = blogItem.ReferenceToInformation;
                    appendMarkerLink(strBuilder, referenceToInformation);
                }
                marker.PopupContent = strBuilder.ToString();
                markers.Add(marker);
            }

            mapContainer.MapMarkers.CollectionContent.AddRange(markers);
        }
        internal static void Update_BlogIndexGroup_BlogSourceForSummary(BlogIndexGroup blogIndexGroup, BlogCollection localCollection, BlogCollection masterCollection)
        {
            if(localCollection == null)
                localCollection = BlogCollection.CreateDefault();
            localCollection.CollectionContent.Clear();
            var limitDateTime = DateTime.UtcNow.AddMonths(-3);
            var relevantBlogs =
                masterCollection.CollectionContent.Where(blog => blog.Published >= limitDateTime).OrderByDescending(blog => blog.Published).Take(10).ToArray();
            var blogsByAuthor = relevantBlogs.GroupBy(blog => blog.Author).OrderBy(grpItem => grpItem.Key).ToArray();
            if(blogIndexGroup.GroupedByAuthor == null)
                blogIndexGroup.GroupedByAuthor = GroupedInformationCollection.CreateDefault();
            blogIndexGroup.GroupedByAuthor.CollectionContent.Clear();
            blogIndexGroup.GroupedByAuthor.CollectionContent.AddRange(blogsByAuthor.Select(blogGroupToGroupedInformation));

            if (blogIndexGroup.GroupedByCategory == null)
                blogIndexGroup.GroupedByCategory = GroupedInformationCollection.CreateDefault();
            if (blogIndexGroup.GroupedByDate == null)
                blogIndexGroup.GroupedByDate = GroupedInformationCollection.CreateDefault();
            if (blogIndexGroup.GroupedByLocation == null)
                blogIndexGroup.GroupedByLocation = GroupedInformationCollection.CreateDefault();

            var archiveSeq = masterCollection.CollectionContent.OrderByDescending(blog => blog.Published)
                    .ThenBy(blog => blog.Title)
                    .Select(blog => blog.ReferenceToInformation);
            if(blogIndexGroup.FullBlogArchive == null)
                blogIndexGroup.FullBlogArchive = ReferenceCollection.CreateDefault();
            blogIndexGroup.FullBlogArchive.CollectionContent.Clear();
            blogIndexGroup.FullBlogArchive.CollectionContent.AddRange(archiveSeq);
        }