Exemplo n.º 1
0
 public PingbackAPI()
 {
     siteConfig = SiteConfig.GetSiteConfig();
     logDataService = LoggingDataServiceFactory.GetService(SiteConfig.GetLogPathFromCurrentContext());
     dataService = BlogDataServiceFactory.GetService(SiteConfig.GetContentPathFromCurrentContext(), logDataService);
     
 }
Exemplo n.º 2
0
        public void SetUpForTests()
        {
            // This method will be run each and every time a test method is run.
            // Place common initialization steps here that should be run before
            // every test.

            DirectoryInfo root = new DirectoryInfo(ReflectionHelper.CodeBase());

            testContent = new DirectoryInfo(Path.Combine(root.Parent.FullName, "TestContent"));
            Assert.IsTrue(testContent.Exists);

            testLogs = new DirectoryInfo(Path.Combine(root.Parent.FullName, "TestLogs"));
            Assert.IsTrue(testLogs.Exists);

            loggingService = LoggingDataServiceFactory.GetService(
                testLogs.FullName);
            Assert.IsNotNull(loggingService);

            blogService = BlogDataServiceFactory.GetService(
                testContent.FullName,
                loggingService);
            Assert.IsNotNull(blogService);

            loggingService.AddEvent(new EventDataItem(EventCodes.ApplicationStartup, "", ""));
        }
Exemplo n.º 3
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="contentLocation"></param>
        /// <returns></returns>
        public static IBlogDataService GetService(string contentLocation, ILoggingDataService loggingService)
        {
            IBlogDataService service;

            lock (services.SyncRoot)
            {
                service = services[contentLocation.ToUpper()] as IBlogDataService;
                if (service == null)
                {
                    service = new BlogDataServiceXml(contentLocation, loggingService);
                    services.Add(contentLocation.ToUpper(), service);
                }
            }
            return service;
        }
Exemplo n.º 4
0
        public void SetUpForTests()
        {
            // This method will be run each and every time a test method is run.
            // Place common initialization steps here that should be run before
            // every test.

            DirectoryInfo root = new DirectoryInfo(ReflectionHelper.CodeBase());
            testLogs = new DirectoryInfo(Path.Combine(root.Parent.FullName, "TestLogs"));
            Assert.IsTrue(testLogs.Exists);

            loggingService = LoggingDataServiceFactory.GetService(
                testLogs.FullName);
            Assert.IsNotNull(loggingService);

            dasBlogContent = new DirectoryInfo("../../../newtelligence.DasBlog.Web/content");
            localhostBlogService = GetDataService();
        }
Exemplo n.º 5
0
 public static void SaveEntry(Entry entry, SiteConfig siteConfig, ILoggingDataService logService, IBlogDataService dataService)
 {
     SiteUtilities.SaveEntry(entry,siteConfig,logService,dataService);
 }
Exemplo n.º 6
0
 public static void DeleteEntry(string entryId, SiteConfig siteConfig, ILoggingDataService logService, IBlogDataService dataService)
 {
     SiteUtilities.DeleteEntry(entryId,siteConfig,logService,dataService);
 }
Exemplo n.º 7
0
 public BloggerAPI()
 {
     this.siteConfig = SiteConfig.GetSiteConfig();
     this.logService = LoggingDataServiceFactory.GetService(SiteConfig.GetLogPathFromCurrentContext());
     this.dataService = BlogDataServiceFactory.GetService(SiteConfig.GetContentPathFromCurrentContext(), logService );
 }
Exemplo n.º 8
0
 public BloggerAPI(IDasBlogSettings settings)
 {
     _dasBlogSettings    = settings;
     _loggingDataService = LoggingDataServiceFactory.GetService(_dasBlogSettings.WebRootDirectory + _dasBlogSettings.SiteConfiguration.LogDir);
     _dataService        = BlogDataServiceFactory.GetService(_dasBlogSettings.WebRootDirectory + _dasBlogSettings.SiteConfiguration.ContentDir, _loggingDataService);
 }
Exemplo n.º 9
0
 public SyndicationServiceBase(SiteConfig siteConfig, IBlogDataService dataService, ILoggingDataService loggingService)
 {
     InitializeComponent();
     this.dataService    = dataService;
     this.loggingService = loggingService;
     this.siteConfig     = siteConfig;
 }
Exemplo n.º 10
0
 /// <summary>
 /// Send an email notification that an entry has been made.
 /// </summary>
 /// <param name="siteConfig">The page making the request.</param>
 /// <param name="entry">The entry being added.</param>
 internal static void SendEmail(Entry entry, SiteConfig siteConfig, ILoggingDataService logService)
 {
     SiteUtilities.SendEmail(entry,siteConfig,logService);
 }
Exemplo n.º 11
0
        public static void SaveEntry(Entry entry, TrackbackInfoCollection trackbackList, CrosspostInfoCollection crosspostList, SiteConfig siteConfig, ILoggingDataService logService, IBlogDataService dataService)
        {
            InternalSaveEntry(entry, trackbackList, crosspostList, siteConfig, logService, dataService);

            logService.AddEvent(
                new EventDataItem(
                    EventCodes.EntryAdded, entry.Title,
                    SiteUtilities.GetPermaLinkUrl(siteConfig, entry.EntryId)));
        }
Exemplo n.º 12
0
        public static void SaveEntry(Entry entry, string trackbackUrl, CrosspostInfoCollection crosspostList, SiteConfig siteConfig, ILoggingDataService logService, IBlogDataService dataService)
        {
            TrackbackInfoCollection trackbackList = null;
            if (trackbackUrl != null && trackbackUrl.Length > 0)
            {
                trackbackList = new TrackbackInfoCollection();
                trackbackList.Add(new TrackbackInfo(
                    trackbackUrl,
                    SiteUtilities.GetPermaLinkUrl(siteConfig, entry),
                    entry.Title,
                    entry.Description,
                    siteConfig.Title));
            }
            InternalSaveEntry(entry, trackbackList, crosspostList, siteConfig, logService, dataService);

            logService.AddEvent(
                new EventDataItem(
                EventCodes.EntryAdded, entry.Title,
                SiteUtilities.GetPermaLinkUrl(siteConfig, entry.EntryId)));
        }
Exemplo n.º 13
0
 public static void SaveEntry(Entry entry, CrosspostInfoCollection crosspostList, SiteConfig siteConfig, ILoggingDataService logService, IBlogDataService dataService)
 {
     SaveEntry(entry, string.Empty, crosspostList, siteConfig, logService, dataService);
 }
Exemplo n.º 14
0
 public static void SaveEntry(Entry entry, SiteConfig siteConfig, ILoggingDataService logService, IBlogDataService dataService)
 {
     SaveEntry(entry, string.Empty, null, siteConfig, logService, dataService);
 }
Exemplo n.º 15
0
 public ArchiveManager(IDasBlogSettings settings)
 {
     dasBlogSettings    = settings;
     loggingDataService = LoggingDataServiceFactory.GetService(dasBlogSettings.WebRootDirectory + dasBlogSettings.SiteConfiguration.LogDir);
     dataService        = BlogDataServiceFactory.GetService(dasBlogSettings.WebRootDirectory + dasBlogSettings.SiteConfiguration.ContentDir, loggingDataService);
 }
Exemplo n.º 16
0
 public BloggerAPI()
 {
     this.siteConfig  = SiteConfig.GetSiteConfig();
     this.logService  = LoggingDataServiceFactory.GetService(SiteConfig.GetLogPathFromCurrentContext());
     this.dataService = BlogDataServiceFactory.GetService(SiteConfig.GetContentPathFromCurrentContext(), logService);
 }
 public SyndicationServiceImplementation(SiteConfig siteConfig, IBlogDataService dataService, ILoggingDataService loggingService) :
     base(siteConfig, dataService, loggingService)
 {
     //CODEGEN: This call is required by the ASP.NET Web Services Designer
     InitializeComponent();
 }
Exemplo n.º 18
0
 public static void SaveEntry(Entry entry, TrackbackInfoCollection trackbackList, CrosspostInfoCollection crosspostList, SiteConfig siteConfig, ILoggingDataService logService, IBlogDataService dataService)
 {
     SiteUtilities.SaveEntry(entry,trackbackList,crosspostList,siteConfig,logService,dataService);
 }
Exemplo n.º 19
0
 public static EntrySaveState UpdateEntry(Entry entry, string trackbackUrl, CrosspostInfoCollection crosspostList, SiteConfig siteConfig, ILoggingDataService logService, IBlogDataService dataService)
 {
     return SiteUtilities.UpdateEntry(entry,trackbackUrl,crosspostList,siteConfig,logService,dataService);
 }
 public SyndicationServiceExperimentalImplementation(SiteConfig siteConfig, IBlogDataService dataService, ILoggingDataService loggingService):
     base( siteConfig, dataService, loggingService )
 {
     //CODEGEN: This call is required by the ASP.NET Web Services Designer
     InitializeComponent();
 }
Exemplo n.º 21
0
        public static EntrySaveState UpdateEntry(Entry entry, string trackbackUrl, CrosspostInfoCollection crosspostList, SiteConfig siteConfig, ILoggingDataService logService, IBlogDataService dataService)
        {
            EntrySaveState rtn = EntrySaveState.Failed;

            entry.ModifiedLocalTime = DateTime.Now;

            TrackbackInfoCollection trackbackList = null;
            if (trackbackUrl != null && trackbackUrl.Length > 0)
            {
                trackbackList = new TrackbackInfoCollection();
                trackbackList.Add(new TrackbackInfo(
                    trackbackUrl,
                    SiteUtilities.GetPermaLinkUrl(siteConfig, entry),
                    entry.Title,
                    entry.Description,
                    siteConfig.Title));
            }

            rtn = InternalSaveEntry(entry, trackbackList, crosspostList, siteConfig, logService, dataService);

            logService.AddEvent(
                new EventDataItem(
                    EventCodes.EntryChanged, entry.Title,
                    SiteUtilities.GetPermaLinkUrl(entry.EntryId)));

            return rtn;
        }
Exemplo n.º 22
0
        /// <summary>
        /// Mail-To-Weblog runs in background thread and this is the thread function.
        /// </summary>
        public void Run()
        {
            IBlogDataService    dataService    = null;
            ILoggingDataService loggingService = null;

            SiteConfig siteConfig = SiteConfig.GetSiteConfig(configPath);

            loggingService = LoggingDataServiceFactory.GetService(logPath);
            dataService    = BlogDataServiceFactory.GetService(contentPath, loggingService);


            ErrorTrace.Trace(System.Diagnostics.TraceLevel.Info, "MailToWeblog thread spinning up");

            loggingService.AddEvent(new EventDataItem(EventCodes.Pop3ServiceStart, "", ""));

            do
            {
                try
                {
                    // reload on every cycle to get the current settings
                    siteConfig     = SiteConfig.GetSiteConfig(configPath);
                    loggingService = LoggingDataServiceFactory.GetService(logPath);
                    dataService    = BlogDataServiceFactory.GetService(contentPath, loggingService);


                    if (siteConfig.EnablePop3 &&
                        siteConfig.Pop3Server != null && siteConfig.Pop3Server.Length > 0 &&
                        siteConfig.Pop3Username != null && siteConfig.Pop3Username.Length > 0)
                    {
                        Pop3 pop3 = new Pop3();


                        try
                        {
                            pop3.host     = siteConfig.Pop3Server;
                            pop3.userName = siteConfig.Pop3Username;
                            pop3.password = siteConfig.Pop3Password;

                            pop3.Connect();
                            pop3.Login();
                            pop3.GetAccountStat();

                            for (int j = pop3.messageCount; j >= 1; j--)
                            {
                                Pop3Message message = pop3.GetMessage(j);

                                string messageFrom;
                                // [email protected] 1-MAR-04
                                // only delete those messages that are processed
                                bool messageWasProcessed = false;

                                // E-Mail addresses look usually like this:
                                // My Name <*****@*****.**> or simply
                                // [email protected]. This block handles
                                // both variants.
                                Regex getEmail   = new Regex(".*\\<(?<email>.*?)\\>.*");
                                Match matchEmail = getEmail.Match(message.from);
                                if (matchEmail.Success)
                                {
                                    messageFrom = matchEmail.Groups["email"].Value;
                                }
                                else
                                {
                                    messageFrom = message.from;
                                }

                                // Only if the subject of the message is prefixed (case-sensitive) with
                                // the configured subject prefix, we accept the message
                                if (message.subject.StartsWith(siteConfig.Pop3SubjectPrefix))
                                {
                                    Entry entry = new Entry();
                                    entry.Initialize();
                                    entry.Title      = message.subject.Substring(siteConfig.Pop3SubjectPrefix.Length);
                                    entry.Categories = "";
                                    entry.Content    = "";
                                    entry.Author     = messageFrom;                                 //store the email, what we have for now...

                                    // Grab the categories. Categories are defined in square brackets
                                    // in the subject line.
                                    Regex categoriesRegex = new Regex("(?<exp>\\[(?<cat>.*?)\\])");
                                    foreach (Match match in categoriesRegex.Matches(entry.Title))
                                    {
                                        entry.Title       = entry.Title.Replace(match.Groups["exp"].Value, "");
                                        entry.Categories += match.Groups["cat"].Value + ";";
                                    }
                                    entry.Title = entry.Title.Trim();

                                    string   categories = "";
                                    string[] splitted   = entry.Categories.Split(';');
                                    for (int i = 0; i < splitted.Length; i++)
                                    {
                                        categories += splitted[i].Trim() + ";";
                                    }
                                    entry.Categories = categories.TrimEnd(';');


                                    entry.CreatedUtc = RFC2822Date.Parse(message.date);

                                    #region PLain Text
                                    // plain text?
                                    if (message.contentType.StartsWith("text/plain"))
                                    {
                                        entry.Content += message.body;
                                    }
                                    #endregion

                                    #region Just HTML
                                    // Luke Latimer 16-FEB-2004 ([email protected])
                                    // HTML only emails were not appearing
                                    else if (message.contentType.StartsWith("text/html"))
                                    {
                                        string messageText = "";

                                        // Note the email may still be encoded
                                        //messageText = QuotedCoding.DecodeOne(message.charset, "Q", message.body);
                                        messageText = message.body;

                                        // Strip the <body> out of the message (using code from below)
                                        Regex bodyExtractor = new Regex("<body.*?>(?<content>.*)</body>", RegexOptions.IgnoreCase | RegexOptions.Singleline);
                                        Match match         = bodyExtractor.Match(messageText);
                                        if (match != null && match.Success && match.Groups["content"] != null)
                                        {
                                            entry.Content += match.Groups["content"].Value;
                                        }
                                        else
                                        {
                                            entry.Content += messageText;
                                        }
                                    }
                                    #endregion

                                    // HTML/Text with attachments ?
                                    else if (
                                        message.contentType.StartsWith("multipart/alternative") ||
                                        message.contentType.StartsWith("multipart/related") ||
                                        message.contentType.StartsWith("multipart/mixed"))
                                    {
                                        Hashtable embeddedFiles = new Hashtable();
                                        ArrayList attachedFiles = new ArrayList();

                                        foreach (Attachment attachment in message.attachments)
                                        {
                                            // just plain text?
                                            if (attachment.contentType.StartsWith("text/plain"))
                                            {
                                                entry.Content += StringOperations.GetString(attachment.data);
                                            }

                                            // Luke Latimer 16-FEB-2004 ([email protected])
                                            // Allow for html-only attachments
                                            else if (attachment.contentType.StartsWith("text/html"))
                                            {
                                                // Strip the <body> out of the message (using code from below)
                                                Regex  bodyExtractor = new Regex("<body.*?>(?<content>.*)</body>", RegexOptions.IgnoreCase | RegexOptions.Singleline);
                                                string htmlString    = StringOperations.GetString(attachment.data);
                                                Match  match         = bodyExtractor.Match(htmlString);

                                                //NOTE: We will BLOW AWAY any previous content in this case.
                                                // This is because most mail clients like Outlook include
                                                // plain, then HTML. We will grab plain, then blow it away if
                                                // HTML is included later.
                                                if (match != null && match.Success && match.Groups["content"] != null)
                                                {
                                                    entry.Content = match.Groups["content"].Value;
                                                }
                                                else
                                                {
                                                    entry.Content = htmlString;
                                                }
                                            }

                                            // or alternative text ?
                                            else if (attachment.contentType.StartsWith("multipart/alternative"))
                                            {
                                                bool   contentSet  = false;
                                                string textContent = null;
                                                foreach (Attachment inner_attachment in attachment.attachments)
                                                {
                                                    // we prefer HTML
                                                    if (inner_attachment.contentType.StartsWith("text/plain"))
                                                    {
                                                        textContent = StringOperations.GetString(inner_attachment.data);
                                                    }
                                                    else if (inner_attachment.contentType.StartsWith("text/html"))
                                                    {
                                                        Regex  bodyExtractor = new Regex("<body.*?>(?<content>.*)</body>", RegexOptions.IgnoreCase | RegexOptions.Singleline);
                                                        string htmlString    = StringOperations.GetString(inner_attachment.data);
                                                        Match  match         = bodyExtractor.Match(htmlString);
                                                        if (match != null && match.Success && match.Groups["content"] != null)
                                                        {
                                                            entry.Content += match.Groups["content"].Value;
                                                        }
                                                        else
                                                        {
                                                            entry.Content += htmlString;
                                                        }
                                                        contentSet = true;
                                                    }
                                                }
                                                if (!contentSet)
                                                {
                                                    entry.Content += textContent;
                                                }
                                            }
                                            // or text with embeddedFiles (in a mixed message only)
                                            else if ((message.contentType.StartsWith("multipart/mixed") || message.contentType.StartsWith("multipart/alternative")) &&
                                                     attachment.contentType.StartsWith("multipart/related"))
                                            {
                                                foreach (Attachment inner_attachment in attachment.attachments)
                                                {
                                                    // just plain text?
                                                    if (inner_attachment.contentType.StartsWith("text/plain"))
                                                    {
                                                        entry.Content += StringOperations.GetString(inner_attachment.data);
                                                    }

                                                    else if (inner_attachment.contentType.StartsWith("text/html"))
                                                    {
                                                        Regex  bodyExtractor = new Regex("<body.*?>(?<content>.*)</body>", RegexOptions.IgnoreCase | RegexOptions.Singleline);
                                                        string htmlString    = StringOperations.GetString(inner_attachment.data);
                                                        Match  match         = bodyExtractor.Match(htmlString);
                                                        if (match != null && match.Success && match.Groups["content"] != null)
                                                        {
                                                            entry.Content += match.Groups["content"].Value;
                                                        }
                                                        else
                                                        {
                                                            entry.Content += htmlString;
                                                        }
                                                    }

                                                    // or alternative text ?
                                                    else if (inner_attachment.contentType.StartsWith("multipart/alternative"))
                                                    {
                                                        bool   contentSet  = false;
                                                        string textContent = null;
                                                        foreach (Attachment inner_inner_attachment in inner_attachment.attachments)
                                                        {
                                                            // we prefer HTML
                                                            if (inner_inner_attachment.contentType.StartsWith("text/plain"))
                                                            {
                                                                textContent = StringOperations.GetString(inner_inner_attachment.data);
                                                            }
                                                            else if (inner_inner_attachment.contentType.StartsWith("text/html"))
                                                            {
                                                                Regex  bodyExtractor = new Regex("<body.*?>(?<content>.*)</body>", RegexOptions.IgnoreCase | RegexOptions.Singleline);
                                                                string htmlString    = StringOperations.GetString(inner_inner_attachment.data);
                                                                Match  match         = bodyExtractor.Match(htmlString);
                                                                if (match != null && match.Success && match.Groups["content"] != null)
                                                                {
                                                                    entry.Content += match.Groups["content"].Value;
                                                                }
                                                                else
                                                                {
                                                                    entry.Content += htmlString;
                                                                }
                                                                contentSet = true;
                                                            }
                                                        }
                                                        if (!contentSet)
                                                        {
                                                            entry.Content += textContent;
                                                        }
                                                    }
                                                    // any other inner_attachment
                                                    else if (inner_attachment.data != null &&
                                                             inner_attachment.fileName != null &&
                                                             inner_attachment.fileName.Length > 0)
                                                    {
                                                        if (inner_attachment.contentID.Length > 0)
                                                        {
                                                            embeddedFiles.Add(inner_attachment.contentID, StoreAttachment(inner_attachment, binariesPath));
                                                        }
                                                        else
                                                        {
                                                            attachedFiles.Add(StoreAttachment(inner_attachment, binariesPath));
                                                        }
                                                    }
                                                }
                                            }
                                            // any other attachment
                                            else if (attachment.data != null &&
                                                     attachment.fileName != null &&
                                                     attachment.fileName.Length > 0)
                                            {
                                                if (attachment.contentID.Length > 0 && message.contentType.StartsWith("multipart/related"))
                                                {
                                                    embeddedFiles.Add(attachment.contentID, StoreAttachment(attachment, binariesPath));
                                                }
                                                else
                                                {
                                                    attachedFiles.Add(StoreAttachment(attachment, binariesPath));
                                                }
                                            }
                                        }


                                        // check for orphaned embeddings
                                        string[] embeddedKeys = new string[embeddedFiles.Keys.Count];
                                        embeddedFiles.Keys.CopyTo(embeddedKeys, 0);
                                        foreach (string key in embeddedKeys)
                                        {
                                            if (entry.Content.IndexOf("cid:" + key.Trim('<', '>')) == -1)
                                            {
                                                object file = embeddedFiles[key];
                                                embeddedFiles.Remove(key);
                                                attachedFiles.Add(file);
                                            }
                                        }


                                        // now fix up the URIs

                                        if (siteConfig.Pop3InlineAttachedPictures)
                                        {
                                            foreach (string fileName in attachedFiles)
                                            {
                                                string fileNameU = fileName.ToUpper();
                                                if (fileNameU.EndsWith(".JPG") || fileNameU.EndsWith(".JPEG") ||
                                                    fileNameU.EndsWith(".GIF") || fileNameU.EndsWith(".PNG") ||
                                                    fileNameU.EndsWith(".BMP"))
                                                {
                                                    bool scalingSucceeded = false;

                                                    if (siteConfig.Pop3InlinedAttachedPicturesThumbHeight > 0)
                                                    {
                                                        try
                                                        {
                                                            string absoluteFileName  = Path.Combine(binariesPath, fileName);
                                                            string thumbBaseFileName = Path.GetFileNameWithoutExtension(fileName) + "-thumb.dasblog.JPG";
                                                            string thumbFileName     = Path.Combine(binariesPath, thumbBaseFileName);
                                                            Bitmap sourceBmp         = new Bitmap(absoluteFileName);
                                                            if (sourceBmp.Height > siteConfig.Pop3InlinedAttachedPicturesThumbHeight)
                                                            {
                                                                Bitmap targetBmp = new Bitmap(sourceBmp, new Size(
                                                                                                  Convert.ToInt32(Math.Round((((double)sourceBmp.Width) * (((double)siteConfig.Pop3InlinedAttachedPicturesThumbHeight) / ((double)sourceBmp.Height))), 0)),
                                                                                                  siteConfig.Pop3InlinedAttachedPicturesThumbHeight));

                                                                ImageCodecInfo    codecInfo     = GetEncoderInfo("image/jpeg");
                                                                Encoder           encoder       = Encoder.Quality;
                                                                EncoderParameters encoderParams = new EncoderParameters(1);
                                                                long             compression    = 75;
                                                                EncoderParameter encoderParam   = new EncoderParameter(encoder, compression);
                                                                encoderParams.Param[0] = encoderParam;
                                                                targetBmp.Save(thumbFileName, codecInfo, encoderParams);

                                                                string absoluteUri      = new Uri(binariesBaseUri, fileName).AbsoluteUri;
                                                                string absoluteThumbUri = new Uri(binariesBaseUri, thumbBaseFileName).AbsoluteUri;
                                                                entry.Content   += String.Format("<div class=\"inlinedMailPictureBox\"><a href=\"{0}\"><img border=\"0\" class=\"inlinedMailPicture\" src=\"{2}\"></a><br /><a class=\"inlinedMailPictureLink\" href=\"{0}\">{1}</a></div>", absoluteUri, fileName, absoluteThumbUri);
                                                                scalingSucceeded = true;
                                                            }
                                                        }
                                                        catch
                                                        {
                                                        }
                                                    }
                                                    if (!scalingSucceeded)
                                                    {
                                                        string absoluteUri = new Uri(binariesBaseUri, fileName).AbsoluteUri;
                                                        entry.Content += String.Format("<div class=\"inlinedMailPictureBox\"><img class=\"inlinedMailPicture\" src=\"{0}\"><br /><a class=\"inlinedMailPictureLink\" href=\"{0}\">{1}</a></div>", absoluteUri, fileName);
                                                    }
                                                }
                                            }
                                        }

                                        if (attachedFiles.Count > 0)
                                        {
                                            entry.Content += "<p>";
                                        }

                                        foreach (string fileName in attachedFiles)
                                        {
                                            string fileNameU = fileName.ToUpper();
                                            if (!siteConfig.Pop3InlineAttachedPictures ||
                                                (!fileNameU.EndsWith(".JPG") && !fileNameU.EndsWith(".JPEG") &&
                                                 !fileNameU.EndsWith(".GIF") && !fileNameU.EndsWith(".PNG") &&
                                                 !fileNameU.EndsWith(".BMP")))
                                            {
                                                string absoluteUri = new Uri(binariesBaseUri, fileName).AbsoluteUri;
                                                entry.Content += String.Format("Download: <a href=\"{0}\">{1}</a><br />", absoluteUri, fileName);
                                            }
                                        }
                                        if (attachedFiles.Count > 0)
                                        {
                                            entry.Content += "</p>";
                                        }

                                        foreach (string key in embeddedFiles.Keys)
                                        {
                                            entry.Content = entry.Content.Replace("cid:" + key.Trim('<', '>'), new Uri(binariesBaseUri, (string)embeddedFiles[key]).AbsoluteUri);
                                        }
                                    }

                                    loggingService.AddEvent(
                                        new EventDataItem(
                                            EventCodes.Pop3EntryReceived, entry.Title,
                                            SiteUtilities.GetPermaLinkUrl(siteConfig, entry.EntryId), messageFrom));

                                    SiteUtilities.SaveEntry(entry, siteConfig, loggingService, dataService);

                                    ErrorTrace.Trace(System.Diagnostics.TraceLevel.Info,
                                                     String.Format("Message stored. From: {0}, Title: {1} as entry {2}",
                                                                   messageFrom, entry.Title, entry.EntryId));

                                    // give the XSS upstreamer a hint that things have changed
//                                    XSSUpstreamer.TriggerUpstreaming();

                                    // [email protected] (01-MAR-04)
                                    messageWasProcessed = true;
                                }
                                else
                                {
                                    // [email protected] (01-MAR-04)
                                    // logging every ignored email is apt
                                    // to fill up the event page very quickly
                                    // especially if only processed emails are
                                    // being deleted
                                    if (siteConfig.Pop3LogIgnoredEmails)
                                    {
                                        loggingService.AddEvent(
                                            new EventDataItem(
                                                EventCodes.Pop3EntryIgnored, message.subject,
                                                null, messageFrom));
                                    }
                                }
                                // [email protected] (01-MAR-04)
                                if (siteConfig.Pop3DeleteAllMessages || messageWasProcessed)
                                {
                                    if (!messageWasProcessed)
                                    {
                                        loggingService.AddEvent(
                                            new EventDataItem(
                                                EventCodes.Pop3EntryDiscarded, message.subject,
                                                null, messageFrom));
                                    }
                                    pop3.DeleteMessage(j);
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            ErrorTrace.Trace(System.Diagnostics.TraceLevel.Error, e);
                            loggingService.AddEvent(
                                new EventDataItem(
                                    EventCodes.Pop3ServerError, e.ToString().Replace("\n", "<br />"), null, null));
                        }
                        finally
                        {
                            pop3.Close();
                        }
                    }

                    Thread.Sleep(TimeSpan.FromSeconds(siteConfig.Pop3Interval));
                }
                catch (ThreadAbortException abortException)
                {
                    ErrorTrace.Trace(System.Diagnostics.TraceLevel.Info, abortException);
                    loggingService.AddEvent(new EventDataItem(EventCodes.Pop3ServiceShutdown, "", ""));
                    break;
                }
                catch (Exception e)
                {
                    // if the siteConfig can't be read, stay running regardless
                    // default wait time is 4 minutes in that case
                    Thread.Sleep(TimeSpan.FromSeconds(240));
                    ErrorTrace.Trace(System.Diagnostics.TraceLevel.Error, e);
                }
            }while (true);
            ErrorTrace.Trace(System.Diagnostics.TraceLevel.Info, "MailToWeblog thread terminating");
            loggingService.AddEvent(new EventDataItem(EventCodes.Pop3ServiceShutdown, "", ""));
        }
Exemplo n.º 23
0
        /// <summary>
        /// The BlogDataServiceXml constructor is entrypoint for the dasBlog Runtime.
        /// </summary>
        /// <param name="contentLocation">The path of the content directory</param>
        /// <param name="loggingService">The <see cref="ILoggingDataService"/></param>
        internal BlogDataServiceXml(string contentLocation, ILoggingDataService loggingService)
        {
            contentBaseDirectory = contentLocation;
            this.loggingService = loggingService;
            if (!Directory.Exists(contentBaseDirectory))
            {
                throw new ArgumentException(
                    String.Format("Invalid directory {0}", contentBaseDirectory),
                    "contentLocation");
            }
            
            data = new DataManager();
            data.Resolver = new ResolveFileCallback(this.GetAbsolutePath);
            
            trackingQueue = new Queue();
            trackingQueueEvent = new AutoResetEvent(false);
            trackingHandlerThread = new Thread(new ThreadStart(this.TrackingHandler));
            trackingHandlerThread.IsBackground = true;
            trackingHandlerThread.Start();
            
            sendMailInfoQueue = new Queue();
            sendMailInfoQueueEvent = new AutoResetEvent(false);
            sendMailInfoHandlerThread = new Thread(new ThreadStart(this.SendMailHandler));
            sendMailInfoHandlerThread.IsBackground = true;
            sendMailInfoHandlerThread.Start();
            
            allComments = new CommentFile(contentBaseDirectory);

            //OmarS: now we want to initialize the EntryIdCache so this doesn't happen elsewhere later on
//            InitCache();
        }
Exemplo n.º 24
0
        /// <summary>
        /// Send an email notification that an entry has been made.
        /// </summary>
        /// <param name="siteConfig">The page making the request.</param>
        /// <param name="entry">The entry being added.</param>
        internal static void SendEmail(Entry entry, SiteConfig siteConfig, ILoggingDataService logService)
        {
            if (siteConfig.SendPostsByEmail &&
                siteConfig.SmtpServer != null &&
                siteConfig.SmtpServer.Length > 0)
            {
                ArrayList actions = new ArrayList();
                actions.Add(ComposeMail(entry, siteConfig));

                foreach (User user in SiteSecurity.GetSecurity().Users)
                {
                    if (user.EmailAddress == null || user.EmailAddress.Length == 0)
                        continue;

                    if (user.NotifyOnNewPost)
                    {
                        SendMailInfo sendMailInfo = ComposeMail(entry, siteConfig);
                        sendMailInfo.Message.To.Add(user.EmailAddress);
                        actions.Add(sendMailInfo);
                    }
                }

                IBlogDataService dataService = BlogDataServiceFactory.GetService(HttpContext.Current.Server.MapPath(siteConfig.ContentDir), logService);
                dataService.RunActions((object[])actions.ToArray(typeof(object)));
            }
        }
Exemplo n.º 25
0
        private static EntrySaveState InternalSaveEntry(Entry entry, TrackbackInfoCollection trackbackList, CrosspostInfoCollection crosspostList, SiteConfig siteConfig, ILoggingDataService logService, IBlogDataService dataService)
        {
            EntrySaveState rtn = EntrySaveState.Failed;
            // we want to prepopulate the cross post collection with the crosspost footer
            if (siteConfig.EnableCrossPostFooter && siteConfig.CrossPostFooter != null && siteConfig.CrossPostFooter.Length > 0)
            {
                foreach (CrosspostInfo info in crosspostList)
                {
                    info.CrossPostFooter = siteConfig.CrossPostFooter;
                }
            }

            // now save the entry, passign in all the necessary Trackback and Pingback info.
            try
            {
                // if the post is missing a title don't publish it
                if (entry.Title == null || entry.Title.Length == 0)
                {
                    entry.IsPublic = false;
                }

                // if the post is missing categories, then set the categories to empty string.
                if (entry.Categories == null)
                    entry.Categories = "";

                rtn = dataService.SaveEntry(
                    entry,
                    (siteConfig.PingServices.Count > 0) ?
                        new WeblogUpdatePingInfo(siteConfig.Title, SiteUtilities.GetBaseUrl(siteConfig), SiteUtilities.GetBaseUrl(siteConfig), SiteUtilities.GetRssUrl(siteConfig), siteConfig.PingServices) : null,
                    (entry.IsPublic) ?
                        trackbackList : null,
                    siteConfig.EnableAutoPingback && entry.IsPublic ?
                        new PingbackInfo(
                            SiteUtilities.GetPermaLinkUrl(siteConfig, entry),
                            entry.Title,
                            entry.Description,
                            siteConfig.Title) : null,
                    crosspostList);

                SendEmail(entry, siteConfig, logService);

            }
            catch (Exception ex)
            {
                StackTrace st = new StackTrace();
                logService.AddEvent(
                    new EventDataItem(EventCodes.Error, ex.ToString() + Environment.NewLine + st.ToString(), ""));
            }

            // we want to invalidate all the caches so users get the new post
            BreakCache(siteConfig, entry.GetSplitCategories());

            // give the XSS upstreamer a hint that things have changed
            //FIX:  XSSUpstreamer.TriggerUpstreaming();

            return rtn;
        }
Exemplo n.º 26
0
        /// <summary>
        /// Deletes an entry, including comments enclosures etc.
        /// </summary>
        /// <remarks>Admins can delete all, contributors only their own.</remarks>
        /// <param name="entryId">The entry to delete.</param>
        /// <param name="siteConfig"></param>
        /// <param name="logService"></param>
        /// <param name="dataService"></param>
        public static void DeleteEntry(string entryId, SiteConfig siteConfig, ILoggingDataService logService, IBlogDataService dataService)
        {
            try
            {
                IPrincipal user = HttpContext.Current.User;
                Entry entry = dataService.GetEntry(entryId);
                //fix: admins can delete all, contributors only their own
                if (!CanEdit(user, entry))
                {
                    throw new SecurityException("Current user is not allowed to delete this entry!");
                }

                string permalink = SiteUtilities.GetPermaLinkUrl(entry.EntryId);
                //string[] categories = entry.GetSplitCategories();

                dataService.DeleteEntry(entryId, siteConfig.CrosspostSites);

                BreakCache(siteConfig, entry.GetSplitCategories());

                // give the XSS upstreamer a hint that things have changed
                //FIX:    XSSUpstreamer.TriggerUpstreaming();

                // TODO: when we add support for more than just enclosures, we can't delete the entire folder
                DirectoryInfo enclosuresPath = new DirectoryInfo((Path.Combine(SiteConfig.GetBinariesPathFromCurrentContext(), entryId)));
                if (enclosuresPath.Exists) enclosuresPath.Delete(true);

                logService.AddEvent(
                    new EventDataItem(
                    EventCodes.EntryDeleted, entry.Title,
                    permalink));
            }
            catch (SecurityException)
            {
                throw;
            }
            catch (Exception ex)
            {
                StackTrace st = new StackTrace();
                logService.AddEvent(
                    new EventDataItem(EventCodes.Error, ex.ToString() + Environment.NewLine + st.ToString(), HttpContext.Current.Request.RawUrl));

                // DESIGN: We should rethrow the exception for the calling class, but this break too much for this point release.
            }
        }
Exemplo n.º 27
0
        public void SendEmailReport(DateTime reportDate, SiteConfig siteConfig, IBlogDataService dataService, ILoggingDataService loggingService)
        {
            MailMessage emailMessage = new MailMessage();
            if ( siteConfig.NotificationEMailAddress != null && siteConfig.NotificationEMailAddress.Length > 0 )
            {
                emailMessage.To.Add(siteConfig.NotificationEMailAddress);
            }
            else
            {
                emailMessage.To.Add(siteConfig.Contact);
            }

            emailMessage.Subject = String.Format("Weblog Daily Activity Report for '{0}'", reportDate.ToLongDateString());
            emailMessage.Body = GenerateReportEmailBody(reportDate);
            emailMessage.IsBodyHtml = true;
            emailMessage.BodyEncoding = System.Text.Encoding.UTF8;
            emailMessage.From = new MailAddress(siteConfig.Contact);

            SendMailInfo sendMailInfo = new SendMailInfo(emailMessage, siteConfig.SmtpServer,
                siteConfig.EnableSmtpAuthentication, siteConfig.UseSSLForSMTP, siteConfig.SmtpUserName, siteConfig.SmtpPassword, siteConfig.SmtpPort);

            dataService.AddTracking(null, sendMailInfo ); // use this with null tracking object, just to get the email sent
            loggingService.AddEvent( new EventDataItem( EventCodes.ReportMailerReportSent,"",""));
        }
Exemplo n.º 28
0
        public EntryCollection SearchEntries(string searchString)
        {
            StringCollection searchWords = new StringCollection();

            string[] splitString = Regex.Split(searchString, @"(""[^""]*"")", RegexOptions.IgnoreCase |
                                               RegexOptions.Compiled);

            for (int index = 0; index < splitString.Length; index++)
            {
                if (splitString[index] != "")
                {
                    if (index == splitString.Length - 1)
                    {
                        foreach (string s in splitString[index].Split(' '))
                        {
                            if (s != "")
                            {
                                searchWords.Add(s);
                            }
                        }
                    }
                    else
                    {
                        searchWords.Add(splitString[index].Substring(1, splitString[index].Length - 2));
                    }
                }
            }

            EntryCollection matchEntries = new EntryCollection();

            foreach (Entry entry in requestPage.DataService.GetEntriesForDay(DateTime.MaxValue.AddDays(-2), new UTCTimeZone(), Request.Headers["Accept-Language"], int.MaxValue, int.MaxValue, null))
            {
                string entryTitle       = entry.Title;
                string entryDescription = entry.Description;
                string entryContent     = entry.Content;

                foreach (string searchWord in searchWords)
                {
                    if (entryTitle != null)
                    {
                        if (searchEntryForWord(entryTitle, searchWord))
                        {
                            if (!matchEntries.Contains(entry))
                            {
                                matchEntries.Add(entry);
                            }
                            continue;
                        }
                    }
                    if (entryDescription != null)
                    {
                        if (searchEntryForWord(entryDescription, searchWord))
                        {
                            if (!matchEntries.Contains(entry))
                            {
                                matchEntries.Add(entry);
                            }
                            continue;
                        }
                    }
                    if (entryContent != null)
                    {
                        if (searchEntryForWord(entryContent, searchWord))
                        {
                            if (!matchEntries.Contains(entry))
                            {
                                matchEntries.Add(entry);
                            }
                            continue;
                        }
                    }
                }
            }

            // log the search to the event log
            ILoggingDataService logService = requestPage.LoggingService;
            string referrer = Request.UrlReferrer != null ? Request.UrlReferrer.AbsoluteUri : Request.ServerVariables["REMOTE_ADDR"];

            logService.AddEvent(
                new EventDataItem(EventCodes.Search, String.Format("{0}", searchString), referrer));

            return(matchEntries);
        }