Пример #1
0
        newtelligence.DasBlog.Web.Services.Blogger.Post[] IBlogger.blogger_getRecentPosts(string appKey,
                                                                                          string blogid,
                                                                                          string username,
                                                                                          string password,
                                                                                          int numberOfPosts)
        {
            if (!siteConfig.EnableBloggerApi)
            {
                throw new ServiceDisabledException();
            }
            UserToken token = SiteSecurity.Login(username, password);

            if (token == null)
            {
                throw new System.Security.SecurityException();
            }

            EntryCollection entries = dataService.GetEntriesForDay(DateTime.Now.ToUniversalTime(), new Util.UTCTimeZone(), null, SiteConfig.GetSiteConfig().RssDayCount, numberOfPosts, null);
            List <newtelligence.DasBlog.Web.Services.Blogger.Post> arrayList = new List <newtelligence.DasBlog.Web.Services.Blogger.Post>();

            foreach (Entry entry in entries)
            {
                newtelligence.DasBlog.Web.Services.Blogger.Post post = new newtelligence.DasBlog.Web.Services.Blogger.Post();
                FillBloggerPostFromEntry(entry, ref post);
                arrayList.Add(post);
            }
            return(arrayList.ToArray());
        }
Пример #2
0
        public MoveableType.PostTitle[] mt_getRecentPostTitles(string blogid, string username, string password, int numberOfPosts)
        {
            if (!dasBlogSettings.SiteConfiguration.EnableBloggerApi)
            {
                throw new ServiceDisabledException();
            }

            if (!VerifyLogin(username, password))
            {
                throw new SecurityException();
            }

            EntryCollection entries = dataService.GetEntriesForDay(DateTime.Now.ToUniversalTime(), dasBlogSettings.GetConfiguredTimeZone(), null,
                                                                   dasBlogSettings.SiteConfiguration.RssDayCount, numberOfPosts, null);
            List <MoveableType.PostTitle> arrayList = new List <MoveableType.PostTitle>();

            foreach (Entry entry in entries)
            {
                MoveableType.PostTitle post = new MoveableType.PostTitle();
                post.title       = NoNull(entry.Title);
                post.dateCreated = entry.CreatedUtc;
                post.postid      = NoNull(entry.EntryId);
                post.userid      = username;
                arrayList.Add(post);
            }
            return(arrayList.ToArray());
        }
Пример #3
0
        /// <param name="dt">if non-null then the post must be dated on that date</param>
        public Entry GetBlogPost(string postid, DateTime?dt)
        {
            if (dt == null)
            {
                return(dataService.GetEntry(postid));
            }
            else
            {
                var entries = dataService.GetEntriesForDay(dt.Value, null, null, 1, 10, null);

                return(entries.FirstOrDefault(e => SettingsUtils.GetPermaTitle(e.CompressedTitle, opts.TitlePermalinkSpaceReplacement)
                                              .Replace(opts.TitlePermalinkSpaceReplacement, string.Empty) == postid));
            }
        }
Пример #4
0
 /// <param name="dt">if non-null then the post must be dated on that date</param>
 public Entry GetBlogPost(string postid, DateTime?dt)
 {
     if (dt == null)
     {
         return(dataService.GetEntry(postid));
     }
     else
     {
         EntryCollection entries = dataService.GetEntriesForDay(dt.Value, null, null, 1, 10, null);
         return(entries.FirstOrDefault(e =>
                                       Pass(() => dasBlogSettings.GetPermaTitle(e.CompressedTitle), () => SettingsUtils.GetPermaTitle(e.CompressedTitle, opts.TitlePermalinkSpaceReplacement))
                                       .Replace(Pass(() => dasBlogSettings.SiteConfiguration.TitlePermalinkSpaceReplacement, () => opts.TitlePermalinkSpaceReplacement), string.Empty)
                                       == postid));
     }
 }
Пример #5
0
        MovableType.PostTitle[] MovableType.IMovableType.mt_getRecentPostTitles(string blogid, string username, string password, int numberOfPosts)
        {
            if (!_dasBlogSettings.SiteConfiguration.EnableBloggerApi)
            {
                throw new ServiceDisabledException();
            }
            UserToken token = SiteSecurity.Login(username, password);

            if (token == null)
            {
                throw new System.Security.SecurityException();
            }
            EntryCollection entries = _dataService.GetEntriesForDay(DateTime.Now.ToUniversalTime(), TimeZone.CurrentTimeZone, null,
                                                                    _dasBlogSettings.SiteConfiguration.RssDayCount, numberOfPosts, null);
            List <MovableType.PostTitle> arrayList = new List <MovableType.PostTitle>();

            foreach (Entry entry in entries)
            {
                MovableType.PostTitle post = new MovableType.PostTitle();
                post.title       = noNull(entry.Title);
                post.dateCreated = entry.CreatedUtc;
                post.postid      = noNull(entry.EntryId);
                post.userid      = username;
                arrayList.Add(post);
            }
            return(arrayList.ToArray());
        }
Пример #6
0
        public void BlogDataService_SearchEntries_Successful(IBlogDataService blogdataservice)
        {
            ////
            var entries = blogdataservice.GetEntriesForDay(DateTime.MaxValue.AddDays(-2), DateTimeZone.Utc, string.Empty, int.MaxValue, int.MaxValue, string.Empty);

            Assert.NotNull(entries);
        }
Пример #7
0
        public void ProcessRequest(HttpContext context)
        {
            ILoggingDataService logService = LoggingDataServiceFactory.GetService(SiteConfig.GetLogPathFromCurrentContext());

            try
            {
                IBlogDataService dataService = BlogDataServiceFactory.GetService(SiteConfig.GetContentPathFromCurrentContext(), logService);
                SiteConfig       siteConfig  = SiteConfig.GetSiteConfig();

                string languageFilter = context.Request.Headers["Accept-Language"];
                if (SiteSecurity.IsInRole("admin"))
                {
                    languageFilter = "";
                }

                EntryCollection entries = dataService.GetEntriesForDay(DateTime.UtcNow, siteConfig.GetConfiguredTimeZone(), languageFilter, 1, 1, String.Empty);

                if (entries != null && entries.Count > 0)
                {
                    Entry e = entries[0];
                    context.Response.Write(e.Title);
                }
            }
            catch (Exception ex)
            {
                logService.AddEvent(new EventDataItem(EventCodes.Error, "Error generating Microsummary: " + ex.ToString(), String.Empty));
            }
        }
Пример #8
0
        /// <param name="dt">if non-null then the post must be dated on that date</param>
        public Entry GetBlogPost(string posttitle, DateTime?dt)
        {
            posttitle = posttitle.Replace(dasBlogSettings.SiteConfiguration.TitlePermalinkSpaceReplacement, string.Empty);

            if (dt == null)
            {
                return(dataService.GetEntry(posttitle));
            }
            else
            {
                var entries = dataService.GetEntriesForDay(dt.Value, null, null, 1, 10, null);

                return(entries.FirstOrDefault(e => dasBlogSettings.GetPermaTitle(e.CompressedTitle)
                                              .Replace(dasBlogSettings.SiteConfiguration.TitlePermalinkSpaceReplacement, string.Empty) == posttitle));
            }
        }
        public void GetEntriesForDay()
        {
            IBlogDataService dataService = BlogDataServiceFactory.GetService(createEntries.FullName, null);

            // this will create an entry for each hour of the day in local time
            for (int i = 0; i < 24; i++)
            {
                Entry entry = TestEntry.CreateEntry(String.Format("Test Entry {0}", i), 5, 2);
                entry.CreatedUtc = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, i, 0, 0).ToUniversalTime();
                dataService.SaveEntry(entry, null);
            }

            EntryCollection entries = dataService.GetEntriesForDay(DateTime.Now, TimeZone.CurrentTimeZone, String.Empty, int.MaxValue, int.MaxValue, String.Empty);

            Assert.AreEqual(24, entries.Count);

            foreach (Entry entry in entries)
            {
                // this test will make sure that the entries are all in the right day
                Entry lookup = dataService.GetEntry(entry.EntryId);
                Assert.IsNotNull(lookup);
                Assert.AreEqual(0, lookup.CompareTo(entry));
                Assert.AreEqual(DateTime.Now.Date, entry.CreatedLocalTime.Date);
            }
        }
Пример #10
0
        /// <param name="dt">if non-null then the post must be dated on that date</param>
        public Entry GetBlogPost(string posttitle, DateTime?dt)
        {
            if (dt == null)
            {
                posttitle = posttitle.Replace(dasBlogSettings.SiteConfiguration.TitlePermalinkSpaceReplacement, string.Empty)
                            .Replace(".aspx", string.Empty);

                return(dataService.GetEntry(posttitle));
            }
            else
            {
                var entries = dataService.GetEntriesForDay(dt.Value, null, null, 1, 10, null);

                return(entries.FirstOrDefault(e => dasBlogSettings.GeneratePostUrl(e)
                                              .EndsWith(posttitle, StringComparison.OrdinalIgnoreCase)));
            }
        }
Пример #11
0
        public static void FixDays(string path)
        {
            ContentPath = path;

            IBlogDataService dataService = BlogDataServiceFactory.GetService(ContentPath, null);

            EntryCollection entries = dataService.GetEntriesForDay(
                DateTime.MaxValue.AddDays(-2),
                TimeZone.CurrentTimeZone,
                String.Empty,
                int.MaxValue,
                int.MaxValue,
                String.Empty);

            Hashtable DayEntries = new Hashtable();

            foreach (Entry entry in entries)
            {
                DayEntry dayEntry = new DayEntry();
                dayEntry.DateUtc = entry.CreatedUtc;

                if (DayEntries.ContainsKey(entry.CreatedUtc.Date))
                {
                    dayEntry = DayEntries[entry.CreatedUtc.Date] as DayEntry;
                }
                dayEntry.Entries.Add(entry);
                DayEntries[entry.CreatedUtc.Date] = dayEntry;
            }

            DirectoryInfo directoryInfo = new DirectoryInfo(path);

            foreach (FileInfo fileInfo in directoryInfo.GetFiles("*.dayentry.xml"))
            {
                // backup the old file
                try
                {
                    DirectoryInfo backup = new DirectoryInfo(Path.Combine(directoryInfo.FullName, "backup"));

                    if (!backup.Exists)
                    {
                        backup.Create();
                    }

                    fileInfo.MoveTo(Path.Combine(backup.FullName, fileInfo.Name));
                }
                catch (Exception e)
                {
                    ErrorTrace.Trace(TraceLevel.Error, e);
                }
            }

            foreach (DayEntry dayEntry in DayEntries.Values)
            {
                Save(dayEntry, path);
            }
        }
Пример #12
0
        public MoveableType.PostTitle[] mt_getRecentPostTitles(string blogid, string username, string password, int numberOfPosts)
        {
            VerifyAccess(username, password);

            var entries = dataService.GetEntriesForDay(DateTime.Now.ToUniversalTime(), dasBlogSettings.GetConfiguredTimeZone(), null,
                                                       numberOfPosts, numberOfPosts, null);
            var arrayList = new List <MoveableType.PostTitle>();

            foreach (Entry entry in entries)
            {
                var post = new MoveableType.PostTitle();
                post.title       = NoNull(entry.Title);
                post.dateCreated = entry.CreatedUtc;
                post.postid      = NoNull(entry.EntryId);
                post.userid      = username;
                arrayList.Add(post);
            }
            return(arrayList.ToArray());
        }
Пример #13
0
        public EntryCollection GetFrontPagePosts()
        {
            DateTime fpDayUtc;
            TimeZone tz;

            //Need to insert the Request.Headers["Accept-Language"];
            string languageFilter = "en-US"; // Request.Headers["Accept-Language"];

            fpDayUtc = DateTime.UtcNow.AddDays(_dasBlogSettings.SiteConfiguration.ContentLookaheadDays);

            if (_dasBlogSettings.SiteConfiguration.AdjustDisplayTimeZone)
            {
                tz = WindowsTimeZone.TimeZones.GetByZoneIndex(_dasBlogSettings.SiteConfiguration.DisplayTimeZoneIndex);
            }
            else
            {
                tz = new UTCTimeZone();
            }

            return(_dataService.GetEntriesForDay(fpDayUtc, TimeZone.CurrentTimeZone,
                                                 languageFilter,
                                                 _dasBlogSettings.SiteConfiguration.FrontPageDayCount, _dasBlogSettings.SiteConfiguration.FrontPageEntryCount, string.Empty));
        }
Пример #14
0
        public static void FixIsPublic(string path)
        {
            ContentPath = path;

            BlogDataServiceFactory.RemoveService(path);
            IBlogDataService dataService = BlogDataServiceFactory.GetService(ContentPath, null);
            EntryCollection  entries     = dataService.GetEntriesForDay(
                DateTime.MaxValue.AddDays(-2),
                TimeZone.CurrentTimeZone,
                String.Empty,
                int.MaxValue,
                int.MaxValue,
                String.Empty);

            foreach (Entry e in entries)
            {
                //if (e.IsPublic == false)
                {
                    try
                    {
                        Entry edit = dataService.GetEntryForEdit(e.EntryId);
                        edit.IsPublic = true;

                        if (edit.Categories == String.Empty)
                        {
                            edit.Categories = "Main";
                        }
                        EntrySaveState saved = dataService.SaveEntry(edit);

                        if (saved == EntrySaveState.Failed)
                        {
                            WriteLine(String.Format("Failed saving {0}", e.Title));
                        }
                        else
                        {
                            WriteLine(String.Format("Saved {0}", e.Title));
                        }
                    }
                    catch (Exception e1)
                    {
                        WriteLine(String.Format("Failed saving {0}, {1}", e.Title, e1.ToString()));
                    }
                }
            }
        }
Пример #15
0
        protected EntryCollection BuildEntries(string category, int maxDayCount, int maxEntryCount)
        {
            var entryList = new EntryCollection();

            if (category != null)
            {
                int entryCount = dasBlogSettings.SiteConfiguration.RssEntryCount;
                category = category.Replace(dasBlogSettings.SiteConfiguration.TitlePermalinkSpaceReplacement, " ");
                foreach (var catEntry in dataService.GetCategories())
                {
                    if (string.Compare(catEntry.Name, category, CultureInfo.CurrentCulture, CompareOptions.IgnoreCase | CompareOptions.IgnoreSymbols) == 0)
                    {
                        foreach (CategoryCacheEntryDetail detail in catEntry.EntryDetails)
                        {
                            Entry entry = dataService.GetEntry(detail.EntryId);
                            if (entry != null)
                            {
                                entryList.Add(entry);
                                entryCount--;
                            }
                            if (entryCount <= 0)
                            {
                                break;
                            }
                        } // foreach (CategoryCacheEntryDetail
                    }
                    if (entryCount <= 0)
                    {
                        break;
                    }
                } // foreach (CategoryCacheEntry
            }
            else
            {
                entryList = dataService.GetEntriesForDay(dasBlogSettings.GetContentLookAhead(), dasBlogSettings.GetConfiguredTimeZone(), null, maxDayCount, maxEntryCount, null);
            }
            entryList.Sort(new EntrySorter());
            return(entryList);
        }
        protected EntryCollection BuildEntries(string category, int maxDayCount, int maxEntryCount)
        {
            EntryCollection entryList = new EntryCollection();

            if (category != null)
            {
                int entryCount = _dasBlogSettings.SiteConfiguration.RssEntryCount;
                category = category.ToUpper();
                foreach (CategoryCacheEntry catEntry in _dataService.GetCategories())
                {
                    if (catEntry.Name.ToUpper() == category)
                    {
                        foreach (CategoryCacheEntryDetail detail in catEntry.EntryDetails)
                        {
                            Entry entry = _dataService.GetEntry(detail.EntryId);
                            if (entry != null)
                            {
                                entryList.Add(entry);
                                entryCount--;
                            }
                            if (entryCount <= 0)
                            {
                                break;
                            }
                        } // foreach (CategoryCacheEntryDetail
                    }
                    if (entryCount <= 0)
                    {
                        break;
                    }
                } // foreach (CategoryCacheEntry
            }
            else
            {
                entryList = _dataService.GetEntriesForDay(DateTime.Now.AddDays(_dasBlogSettings.SiteConfiguration.ContentLookaheadDays).ToUniversalTime(), new newtelligence.DasBlog.Util.UTCTimeZone(), null, maxDayCount, maxEntryCount, null);
            }
            entryList.Sort(new EntrySorter());
            return(entryList);
        }
        protected EntryCollection BuildEntries(string category, int maxDayCount, int maxEntryCount)
        {
            EntryCollection entryList = new EntryCollection();

            if (category != null)
            {
                int entryCount = dasBlogSettings.SiteConfiguration.RssEntryCount;
                category = category.ToUpper();
                foreach (CategoryCacheEntry catEntry in dataService.GetCategories())
                {
                    if (catEntry.Name.ToUpper() == category)
                    {
                        foreach (CategoryCacheEntryDetail detail in catEntry.EntryDetails)
                        {
                            Entry entry = dataService.GetEntry(detail.EntryId);
                            if (entry != null)
                            {
                                entryList.Add(entry);
                                entryCount--;
                            }
                            if (entryCount <= 0)
                            {
                                break;
                            }
                        } // foreach (CategoryCacheEntryDetail
                    }
                    if (entryCount <= 0)
                    {
                        break;
                    }
                } // foreach (CategoryCacheEntry
            }
            else
            {
                entryList = dataService.GetEntriesForDay(dasBlogSettings.GetContentLookAhead(), dasBlogSettings.GetConfiguredTimeZone(), null, maxDayCount, maxEntryCount, null);
            }
            entryList.Sort(new EntrySorter());
            return(entryList);
        }
Пример #18
0
        static void Main(string[] args)
        {
            logger.Info("Starting");
            // we need to set the role to admin so we get public entries
            System.Threading.Thread.CurrentPrincipal = new GenericPrincipal(System.Threading.Thread.CurrentPrincipal.Identity, new string[] { "admin" });

            if (args.Length != 1)
            {
                logger.Error(@"Usage: DasBlogGraffitiExporter ""c:\mydasblog\content""");
                Environment.Exit(1);
                return;
            }

            Console.WriteLine("Press ENTER to continue...");
            Console.ReadLine();

            string path = args[0];

            if (Directory.Exists(path))
            {
                // Check all the files again for bad xml which can happen during multithreaded FTP downloads with SmartFTP,
                // plus it doesn't hurt and can catch corruption you don't know you have!
                foreach (string file in Directory.GetFiles(path, "*.xml"))
                {
                    try
                    {
                        XmlDocument x = new XmlDocument();
                        x.Load(file);
                    }
                    catch (XmlException ex)
                    {
                        logger.FatalFormat("ERROR: Malformed Xml in file: {0}", file);
                        logger.Fatal("XmlException", ex);
                    }
                }

                IBlogDataService dataService = BlogDataServiceFactory.GetService(path, null);

                List <UrlMap> categoryMap = new List <UrlMap>();
                CategoryCacheEntryCollection categories = dataService.GetCategories();
                logger.InfoFormat("Found {0} Categories", categories.Count);

                foreach (CategoryCacheEntry entry in categories)
                {
                    string name    = HttpHelper.GetURLSafeString(entry.Name);
                    UrlMap mapping = new UrlMap(name, InternalCompressTitle(entry.DisplayName));
                    categoryMap.Add(mapping);
                    logger.InfoFormat("Adding category name:{0}, display name:{1}", entry.Name, entry.DisplayName);
                }

                UrlMap.Save(categoryMap, Path.Combine(GetDasBlog301Folder(), "CategoryMapping.xml"));

                EntryCollection entries = dataService.GetEntriesForDay(
                    DateTime.MaxValue.AddDays(-2),
                    TimeZone.CurrentTimeZone,
                    String.Empty,
                    int.MaxValue,
                    int.MaxValue,
                    String.Empty);
                logger.InfoFormat("Found {0} entries", entries.Count);

                List <UrlMap> permalinkMapping = new List <UrlMap>();

                foreach (Entry entry in entries)
                {
                    string title   = entry.CompressedTitle;
                    UrlMap mapping = new UrlMap(entry.EntryId, title);
                    permalinkMapping.Add(mapping);
                    logger.InfoFormat("Adding entry id:{0} title:{1}", entry.EntryId, entry.CompressedTitle);
                }

                UrlMap.Save(permalinkMapping, Path.Combine(GetDasBlog301Folder(), "PermalinkMapping.xml"));
            }
        }
Пример #19
0
        public static int Import(string userId, string contentDirectory, string commentServer)
        {
            if (commentServer == null || commentServer.Length == 0)
            {
                // Set default comment server
                commentServer = DefaultCommentServer;
            }

            if (commentServer == null || userId == null || contentDirectory == null ||
                commentServer.Length == 0 || userId.Length == 0 || contentDirectory.Length == 0)
            {
                throw new ArgumentException("commentServer, userId and contentDirectory are required.");
            }

            //This  tool assumes that you have already imported your radio data
            //  Those imported posts have a "non-guid" entryid
            //   We'll enumerate those posts and check the radio comment service
            //   collecting (scraping) comments and injecting them into AllComments.xml in your
            //   dasBlog content directory.

            ArrayList entriesWithCommentsToFetch = new ArrayList();

            Console.WriteLine("Importing entries...");
            IBlogDataService dataService = BlogDataServiceFactory.GetService(contentDirectory, null);
            EntryCollection  entries     = dataService.GetEntriesForDay(DateTime.MaxValue.AddDays(-2), TimeZone.CurrentTimeZone, String.Empty, int.MaxValue, int.MaxValue, String.Empty);

            foreach (Entry e in      entries)
            {
                //Since	Radio Entries are numbers,	NOT	Guids, we'll try to	Parse them
                //	as longs, and if it	fails, it's	arguably a Guid.
                try
                {
                    long.Parse(e.EntryId);
                    Console.WriteLine(String.Format("Found  Imported Radio Entry: {0}", e.EntryId));
                    entriesWithCommentsToFetch.Add(e.EntryId);
                }
                catch {}
            }


            foreach (string entryId in      entriesWithCommentsToFetch)
            {
                string commentHtml = FetchRadioCommentHtml(commentServer, userId, entryId);

                if (commentHtml.IndexOf("No comments found.") == -1)
                {
                    Regex commentRegex = new Regex(@"class=""comment"">(?<comment>\r\n(.*[^<]))", RegexOptions.Multiline | RegexOptions.IgnoreCase | RegexOptions.Compiled);
                    Regex datesRegex   = new Regex(@"(?<month>\d+)/(?<day>\d+)/(?<year>\d+); (?<hour>\d+):(?<min>\d+):(?<sec>\d+) (?<meridian>[A|P]M)</div>", RegexOptions.Multiline | RegexOptions.IgnoreCase | RegexOptions.Compiled);
                    Regex namesRegex   = new Regex(@"<div class=""date"">(?<name>.*)( &#0149;)", RegexOptions.Multiline | RegexOptions.IgnoreCase | RegexOptions.Compiled);

                    MatchCollection commentMatches = commentRegex.Matches(commentHtml);
                    MatchCollection datesMatches   = datesRegex.Matches(commentHtml);
                    MatchCollection namesMatches   = namesRegex.Matches(commentHtml);
                    if (commentMatches.Count != datesMatches.Count || datesMatches.Count != namesMatches.Count)
                    {
                        continue;
                    }

                    //Now we've got "n" parallel arrays...

                    //"For each comment we've found"
                    for (int i = 0; i < commentMatches.Count; i++)
                    {
                        //Get the raw data
                        string content      = commentMatches[i].Groups["comment"].Value;
                        string unparsedDate = datesMatches[i].Value;
                        string name         = namesMatches[i].Groups["name"].Value;
                        string homepage     = String.Empty;

                        //Parse the Date...yank the end div (I'm not good at RegEx)
                        int divLoc = unparsedDate.IndexOf("</div>");
                        if (divLoc != -1)
                        {
                            unparsedDate = unparsedDate.Remove(divLoc, 6);
                        }
                        DateTime date = DateTime.ParseExact(unparsedDate, @"M/d/yy; h:mm:ss tt", CultureInfo.InvariantCulture);

                        //Their captured name may be surrounded in an href...
                        // the href is their homepage
                        int hrefLoc = name.IndexOf(@"""");
                        if (hrefLoc != -1)
                        {
                            //Get their HomePage URL
                            int hrefLen = name.LastIndexOf(@"""") - hrefLoc;
                            homepage = name.Substring(hrefLoc + 1, hrefLen - 1);

                            //Get their name
                            int nameLoc = name.IndexOf(@">");
                            if (nameLoc != -1)
                            {
                                int nameLen = name.LastIndexOf(@"</") - nameLoc;
                                name = name.Substring(nameLoc + 1, nameLen - 1);
                            }
                        }
                        //else it's just the name, so leave "name" as-is

                        Comment comment = new Comment();
                        comment.Content = content.Trim();
                        comment.Author  = name;
                        //comment.EntryId = entryId;
                        comment.TargetEntryId    = entryId;
                        comment.AuthorHomepage   = homepage;
                        comment.AuthorEmail      = String.Empty;
                        comment.CreatedLocalTime = date;
                        comment.CreatedUtc       = date.ToUniversalTime();

                        Console.WriteLine(String.Format("Fetched	comment {0} from Radio:", comment.EntryId));
                        Console.WriteLine(String.Format("  Author:   {0}", comment.Author));
                        Console.WriteLine(String.Format("  Site:	 {0}", comment.AuthorHomepage));
                        Console.WriteLine(String.Format("  Date:	 {0}", comment.CreatedLocalTime));
                        Console.WriteLine(String.Format("  Content:  {0}", comment.Content));
                        dataService.AddComment(comment);
                    }
                }
                else
                {
                    Console.WriteLine(String.Format("No comments for Radio Post {0}", entryId));
                }
            }
            return(0);
        }
Пример #20
0
        static int Main(string[] args)
        {
            try
            {
                #region Command Line Parsing
                string inputdir  = null;
                string outputdir = null;
                for (int i = 0; i < args.Length; ++i)
                {
                    if (args[i] == "-inputdir")
                    {
                        inputdir = args[++i];
                    }
                    else if (args[i] == "-outputdir")
                    {
                        outputdir = args[++i];
                    }
                }

                if (inputdir == null || outputdir == null)
                {
                    PrintUsage();
                    return(ERRORWRONGUSAGE);
                }

                // Canonicalize and expand path to full path
                inputdir  = Path.GetFullPath(inputdir);
                outputdir = Path.GetFullPath(outputdir);

                if (!Directory.Exists(inputdir))
                {
                    Console.WriteLine(inputdir + " does not exist or is not a directory");
                    return(ERRORINPUTDIRNOTFOUND);
                }

                if (!Directory.Exists(outputdir))
                {
                    Console.WriteLine(outputdir + " does not exist or is not a directory");
                    return(ERROROUTPUTDIRNOTFOUND);
                }

                #endregion Command Line Parsing

                IBlogDataService dsInput  = BlogDataServiceFactory.GetService(inputdir, null);
                IBlogDataService dsOutput = BlogDataServiceFactory.GetService(outputdir, null);

                Console.WriteLine("Porting posts");
                // Copy all dayentry files to output directory
                // This shouldn't require any conversion, since the format and naming convention matches
                // between BlogX and dasBlog
                EntryCollection entries = dsInput.GetEntriesForDay(
                    DateTime.MaxValue.AddDays(-2),
                    TimeZone.CurrentTimeZone,
                    String.Empty,
                    int.MaxValue,
                    int.MaxValue,
                    String.Empty);

                //Hashtable lookup = new Hashtable();
                foreach (Entry e in entries)
                {
                    //lookup[e.EntryId] = e;
                    dsOutput.SaveEntry(e);
                    Console.Write(".");
                }

                Console.WriteLine();
                Console.WriteLine("Posts successfully ported");

                Console.WriteLine("Porting comments");

                // TODO: Read in all dayextra files from input directory
                int      commentCount = 0;
                string[] commentFiles = Directory.GetFiles(inputdir, "*.dayextra.xml");
                foreach (string commentFile in commentFiles)
                {
                    // TODO: Match up comments with DayEntry, emit comment
                    XPathDocument     doc          = new XPathDocument(Path.Combine(inputdir, commentFile));
                    XPathNavigator    nav          = doc.CreateNavigator();
                    XPathNodeIterator commentNodes = nav.Select("//Comment");

                    while (commentNodes.MoveNext())
                    {
                        Comment comment = new Comment();

                        XPathNavigator commentNode = commentNodes.Current;

                        comment.Content        = (string)commentNode.Evaluate("string(Content)");
                        comment.CreatedUtc     = DateTime.Parse((string)commentNode.Evaluate("string(Created)"));
                        comment.ModifiedUtc    = DateTime.Parse((string)commentNode.Evaluate("string(Modified)"));
                        comment.EntryId        = (string)commentNode.Evaluate("string(EntryId)");
                        comment.TargetEntryId  = (string)commentNode.Evaluate("string(TargetEntryId)");
                        comment.Author         = (string)commentNode.Evaluate("string(Author)");
                        comment.AuthorEmail    = (string)commentNode.Evaluate("string(AuthorEmail)");
                        comment.AuthorHomepage = (string)commentNode.Evaluate("string(AuthorHomepage)");

                        dsOutput.AddComment(comment);
                        Console.Write(".");
                        ++commentCount;
                    }
                }

                Console.WriteLine();
                Console.WriteLine("{0} comments successfully imported!", commentCount);
            }
            catch (Exception e)
            {
                // Return nonzero so automated tools can tell it failed
                Console.WriteLine(e.ToString());
                return(ERROREXCEPTION);
            }

            return(SUCCESS);
        }
Пример #21
0
        public void ProcessRequest(HttpContext context)
        {
            SiteConfig          siteConfig     = SiteConfig.GetSiteConfig();
            ILoggingDataService loggingService = LoggingDataServiceFactory.GetService(SiteConfig.GetLogPathFromCurrentContext());
            IBlogDataService    dataService    = BlogDataServiceFactory.GetService(SiteConfig.GetContentPathFromCurrentContext(), loggingService);


            string referrer = context.Request.UrlReferrer != null?context.Request.UrlReferrer.AbsoluteUri:"";

            if (ReferralBlackList.IsBlockedReferrer(referrer))
            {
                if (siteConfig.EnableReferralUrlBlackList404s)
                {
                    context.Response.StatusCode = 404;
                    context.Response.End();
                    return;
                }
            }
            else
            {
                loggingService.AddReferral(
                    new LogDataItem(
                        context.Request.RawUrl,
                        referrer,
                        context.Request.UserAgent,
                        context.Request.UserHostName));
            }
            context.Response.ContentType = "application/x-cdf";

            //Create the XmlWriter around the Response
            XmlTextWriter xw = new XmlTextWriter(context.Response.Output);

            xw.Formatting = Formatting.Indented;

            EntryCollection entriesAll = dataService.GetEntriesForDay(
                DateTime.Now.ToUniversalTime(), new Util.UTCTimeZone(),
                null, siteConfig.RssDayCount, siteConfig.RssMainEntryCount, null);
            EntryCollection entries = new EntryCollection();

            foreach (Entry e in entriesAll)
            {
                if (e.IsPublic == true)
                {
                    entries.Add(e);
                }
            }
            entries.Sort(new EntrySorter());

            //Write out the boilerplate CDF
            xw.WriteStartDocument();

            xw.WriteStartElement("CHANNEL");
            xw.WriteAttributeString("HREF", SiteUtilities.GetBaseUrl(siteConfig));

            foreach (Entry current in entries)
            {
                xw.WriteAttributeString("LASTMOD",
                                        FormatLastMod(current.ModifiedLocalTime));
            }

            /*IEnumerator enumerator = entries.GetEnumerator();
             * if(enumerator.MoveNext())
             * {
             *      xw.WriteAttributeString("LASTMOD",
             *              FormatLastMod(((Entry)enumerator.Current).ModifiedLocalTime));
             * }*/
            xw.WriteAttributeString("LEVEL", "1");
            xw.WriteAttributeString("PRECACHE", "YES");

            xw.WriteElementString("TITLE", siteConfig.Title);
            xw.WriteElementString("ABSTRACT", siteConfig.Subtitle);

            foreach (Entry entry in entries)
            {
                xw.WriteStartElement("ITEM");
                xw.WriteAttributeString("HREF", SiteUtilities.GetPermaLinkUrl(siteConfig, (ITitledEntry)entry));
                xw.WriteAttributeString("LASTMOD", FormatLastMod(entry.ModifiedLocalTime));
                xw.WriteAttributeString("LEVEL", "1");
                xw.WriteAttributeString("PRECACHE", "YES");

                xw.WriteElementString("TITLE", entry.Title);

                if (entry.Description != null && entry.Description.Length > 0)
                {
                    xw.WriteElementString("ABSTRACT", entry.Description);
                }

                xw.WriteEndElement();
            }

            xw.WriteEndElement(); //channel
            xw.WriteEndDocument();
        }
Пример #22
0
 public EntryCollection GetEntriesForDay(DateTime date, string acceptLanguages)
 {
     return(dataService.GetEntriesForDay(date, dasBlogSettings.GetConfiguredTimeZone(), acceptLanguages,
                                         dasBlogSettings.SiteConfiguration.FrontPageDayCount, dasBlogSettings.SiteConfiguration.FrontPageDayCount, ""));
 }
Пример #23
0
        public void BlogDataService_GetPublicEntriesForDayMaxValue_Successful(IBlogDataService blogdataservice)
        {
            var entries = blogdataservice.GetEntriesForDay(DateTime.MaxValue.AddDays(-2), DateTimeZone.Utc, string.Empty, int.MaxValue, int.MaxValue, string.Empty);

            Assert.Equal(19, entries.Count);
        }