Added Messaging and Email modules

--HG--
branch : dev
This commit is contained in:
Sebastien Ros
2010-08-30 15:06:52 -07:00
parent 2095121a4d
commit 7c5640692e
32 changed files with 930 additions and 0 deletions

View File

@@ -0,0 +1,14 @@
using Orchard.Data.Migration;
namespace Orchard.Core.Messaging.DataMigrations {
public class MessagingDataMigration : DataMigrationImpl {
public int Create() {
SchemaBuilder.CreateTable("MessageSettingsPartRecord", table => table
.ContentPartRecord()
.Column<string>("DefaultChannelService")
);
return 1;
}
}
}

View File

@@ -0,0 +1,48 @@
using JetBrains.Annotations;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Drivers;
using Orchard.Core.ContentsLocation.Models;
using Orchard.Core.Messaging.Models;
using Orchard.Core.Messaging.Services;
using Orchard.Core.Messaging.ViewModels;
using Orchard.Localization;
using Orchard.Messaging.Services;
namespace Orchard.Core.Messaging.Drivers {
[UsedImplicitly]
public class ContentSubscriptionPartDriver : ContentPartDriver<MessageSettingsPart> {
private readonly IMessageManager _messageQueueManager;
public IOrchardServices Services { get; set; }
public ContentSubscriptionPartDriver(IOrchardServices services, IMessageManager messageQueueManager) {
_messageQueueManager = messageQueueManager;
Services = services;
T = NullLocalizer.Instance;
}
public Localizer T { get; set; }
protected override string Prefix { get { return "MessageSettings"; } }
protected override DriverResult Editor(MessageSettingsPart part) {
var model = new ContentSubscriptionPartViewModel {
ChannelServices = _messageQueueManager.GetAvailableChannelServices(),
MessageSettings = part
};
return ContentPartTemplate(model, "Parts/Messaging.MessageSettings");
}
protected override DriverResult Editor(MessageSettingsPart part, IUpdateModel updater) {
var model = new ContentSubscriptionPartViewModel {
MessageSettings = part
};
if (updater.TryUpdateModel(model, Prefix, null, null)) {
}
return ContentPartTemplate(model, "Parts/Messaging.MessageSettings");
}
}
}

View File

@@ -0,0 +1,14 @@
using JetBrains.Annotations;
using Orchard.Core.Messaging.Models;
using Orchard.Data;
using Orchard.ContentManagement.Handlers;
namespace Orchard.Core.Messaging.Handlers {
[UsedImplicitly]
public class SmtpSettingsPartHandler : ContentHandler {
public SmtpSettingsPartHandler(IRepository<MessageSettingsPartRecord> repository) {
Filters.Add(new ActivatingFilter<MessageSettingsPart>("Site"));
Filters.Add(StorageFilter.For(repository));
}
}
}

View File

@@ -0,0 +1,11 @@
using Orchard.ContentManagement;
namespace Orchard.Core.Messaging.Models {
public class MessageSettingsPart : ContentPart<MessageSettingsPartRecord> {
public string DefaultChannelService {
get { return Record.DefaultChannelService; }
set { Record.DefaultChannelService = value; }
}
}
}

View File

@@ -0,0 +1,11 @@
using Orchard.ContentManagement.Records;
namespace Orchard.Core.Messaging.Models {
public class MessageSettingsPartRecord : ContentPartRecord {
/// <summary>
/// Default service used for messages
/// </summary>
public virtual string DefaultChannelService { get; set; }
}
}

View File

@@ -0,0 +1,12 @@
Name: Messaging
antiforgery: enabled
author: The Orchard Team
website: http://orchardproject.net
version: 0.1.0
orchardversion: 0.6.0
description: The Messaging module adds messaging functionalities.
features:
Messaging:
Description: Messaging services.
Category: Messaging
Dependencies: Settings

View File

@@ -0,0 +1,75 @@
using System;
using System.Collections.Generic;
using System.Linq;
using JetBrains.Annotations;
using Orchard.ContentManagement;
using Orchard.Core.Messaging.Models;
using Orchard.Data;
using Orchard.Logging;
using Orchard.Messaging.Events;
using Orchard.Messaging.Models;
using Orchard.Messaging.Services;
using Orchard.Settings;
namespace Orchard.Core.Messaging.Services {
public class DefaultMessageManager : IMessageManager {
private readonly IMessageEventHandler _messageEventHandler;
private readonly IEnumerable<IMessagingChannel> _channels;
private readonly IRepository<Message> _messageRepository;
protected virtual ISite CurrentSite { get; [UsedImplicitly] private set; }
public ILogger Logger { get; set; }
public DefaultMessageManager(
IMessageEventHandler messageEventHandler,
IEnumerable<IMessagingChannel> channels,
IRepository<Message> messageRepository) {
_messageEventHandler = messageEventHandler;
_channels = channels;
_messageRepository = messageRepository;
}
public void Send(Message message) {
if ( !HasChannels() )
return;
var messageSettings = CurrentSite.As<MessageSettingsPart>().Record;
if ( messageSettings == null || String.IsNullOrWhiteSpace(messageSettings.DefaultChannelService) ) {
return;
}
Logger.Information("Sending message {0}", message.Type);
try {
// if the service is not explicit, use the default one, as per settings configuration
if ( String.IsNullOrWhiteSpace(message.Service) ) {
message.Service = messageSettings.DefaultChannelService;
}
var context = new MessageContext(message);
_messageEventHandler.Sending(context);
foreach ( var channel in _channels ) {
channel.SendMessage(context);
}
_messageEventHandler.Sent(context);
Logger.Information("Message {0} sent", message.Type);
}
catch ( Exception e ) {
Logger.Error(e, "An error occured while sending the message {0}", message.Type);
}
}
public bool HasChannels() {
return _channels.Any();
}
public IEnumerable<string> GetAvailableChannelServices() {
return _channels.SelectMany(c => c.GetAvailableServices());
}
}
}

View File

@@ -0,0 +1,10 @@
using Orchard.Core.Messaging.Models;
using Orchard.Mvc.ViewModels;
using System.Collections.Generic;
namespace Orchard.Core.Messaging.ViewModels {
public class ContentSubscriptionPartViewModel : BaseViewModel {
public MessageSettingsPart MessageSettings { get; set; }
public IEnumerable<string> ChannelServices { get; set; }
}
}

View File

@@ -0,0 +1,20 @@
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<ContentSubscriptionPartViewModel>" %>
<%@ Import Namespace="Orchard.Core.Messaging.Models"%>
<%@ Import Namespace="Orchard.Core.Messaging.ViewModels"%>
<fieldset>
<legend><%: T("Messaging")%></legend>
<div>
<label for="<%: Html.FieldIdFor(m => m.MessageSettings.DefaultChannelService)%>"><%: T("Default channel service for messages")%></label>
<% if ( Model.ChannelServices.Any() ) { %>
<select id="<%:Html.FieldIdFor(m => m.MessageSettings.DefaultChannelService) %>" name="<%:Html.FieldNameFor(m => m.MessageSettings.DefaultChannelService) %>">
<% foreach ( var service in Model.ChannelServices ) {%>
<option <%: Model.MessageSettings.DefaultChannelService == service ? "selected=\"selected\"" : "" %> value="<%: service %>"><%: service%></option>
<% }
}
else {%>
<span class="hint"><%: T("You must enable a messaging channel (e.g., Orchard.Email) before being able to send messages.") %></span>
<% }%>
</select>
</div>
</fieldset>

View File

@@ -0,0 +1,34 @@
<?xml version="1.0"?>
<configuration>
<system.web>
<httpHandlers>
<add path="*" verb="*"
type="System.Web.HttpNotFoundHandler"/>
</httpHandlers>
<!--
Enabling request validation in view pages would cause validation to occur
after the input has already been processed by the controller. By default
MVC performs request validation before a controller processes the input.
To change this behavior apply the ValidateInputAttribute to a
controller or action.
-->
<pages
validateRequest="false"
pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<controls>
<add assembly="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
</controls>
</pages>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<handlers>
<remove name="BlockViewHandler"/>
<add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler"/>
</handlers>
</system.webServer>
</configuration>

View File

@@ -90,6 +90,13 @@
<Compile Include="Contents\Settings\ContentPartSettings.cs" />
<Compile Include="Contents\ViewModels\PublishContentViewModel.cs" />
<Compile Include="Localization\ViewModels\EditLocalizationViewModel.cs" />
<Compile Include="Messaging\DataMigrations\MessagingDataMigration.cs" />
<Compile Include="Messaging\Drivers\MessageSettingsPartDriver.cs" />
<Compile Include="Messaging\Handlers\MessageSettingsPartHandler.cs" />
<Compile Include="Messaging\Models\MessageSettingsPart.cs" />
<Compile Include="Messaging\Models\MessageSettingsPartRecord.cs" />
<Compile Include="Messaging\Services\DefaultMessageManager.cs" />
<Compile Include="Messaging\ViewModels\MessageSettingsPartViewModel.cs" />
<Compile Include="PublishLater\DataMigrations\PublishLaterDataMigration.cs" />
<Compile Include="PublishLater\Drivers\PublishLaterPartDriver.cs" />
<Compile Include="PublishLater\Models\PublishLaterPart.cs" />
@@ -247,6 +254,8 @@
<Content Include="Contents\Views\DisplayTemplates\Parts\Contents.Publish.SummaryAdmin.ascx" />
<Content Include="Contents\Views\DisplayTemplates\Parts\Contents.Publish.ascx" />
<Content Include="Localization\Views\EditorTemplates\Parts\Localization.Translation.ascx" />
<Content Include="Messaging\Module.txt" />
<Content Include="Messaging\Views\EditorTemplates\Parts\Messaging.MessageSettings.ascx" />
<Content Include="PublishLater\Content\Admin\images\draft.gif" />
<Content Include="PublishLater\Content\Admin\images\offline.gif" />
<Content Include="PublishLater\Content\Admin\images\online.gif" />
@@ -366,6 +375,7 @@
<Content Include="Reports\Views\Web.config" />
<Content Include="PublishLater\Views\Web.config" />
<Content Include="ContentsLocation\Views\Web.config" />
<Content Include="Messaging\Views\Web.config" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />

View File

@@ -0,0 +1,22 @@
using Orchard.Data.Migration;
namespace Orchard.Email.DataMigrations {
public class EmailDataMigration : DataMigrationImpl {
public int Create() {
SchemaBuilder.CreateTable("SmtpSettingsPartRecord", table => table
.ContentPartRecord()
.Column<string>("Address")
.Column<string>("Host")
.Column<int>("Port")
.Column<bool>("EnableSsl")
.Column<bool>("RequireCredentials")
.Column<string>("UserName")
.Column<string>("Password")
);
return 1;
}
}
}

View File

@@ -0,0 +1,15 @@
using JetBrains.Annotations;
using Orchard.Email.Models;
using Orchard.Data;
using Orchard.ContentManagement.Handlers;
namespace Orchard.Email.Handlers {
[UsedImplicitly]
public class SmtpSettingsPartHandler : ContentHandler {
public SmtpSettingsPartHandler(IRepository<SmtpSettingsPartRecord> repository) {
Filters.Add(new ActivatingFilter<SmtpSettingsPart>("Site"));
Filters.Add(StorageFilter.For(repository));
Filters.Add(new TemplateFilterForRecord<SmtpSettingsPartRecord>("SmtpSettings", "Parts/Smtp.SiteSettings"));
}
}
}

View File

@@ -0,0 +1,47 @@
using Orchard.ContentManagement;
using System;
namespace Orchard.Email.Models {
public class SmtpSettingsPart : ContentPart<SmtpSettingsPartRecord> {
public bool IsValid() {
return !String.IsNullOrWhiteSpace(Record.Host)
&& Record.Port > 0
&& !String.IsNullOrWhiteSpace(Record.Address);
}
public string Address {
get { return Record.Address; }
set { Record.Address = value; }
}
public string Host {
get { return Record.Host; }
set { Record.Host = value; }
}
public int Port {
get { return Record.Port; }
set { Record.Port = value; }
}
public bool EnableSsl {
get { return Record.EnableSsl; }
set { Record.EnableSsl = value; }
}
public bool RequireCredentials {
get { return Record.RequireCredentials; }
set { Record.RequireCredentials = value; }
}
public string UserName {
get { return Record.UserName; }
set { Record.UserName = value; }
}
public string Password {
get { return Record.Password; }
set { Record.Password = value; }
}
}
}

View File

@@ -0,0 +1,48 @@
using System.Net.Mail;
using Orchard.ContentManagement.Records;
using System.ComponentModel.DataAnnotations;
namespace Orchard.Email.Models {
public class SmtpSettingsPartRecord : ContentPartRecord {
/// <summary>
/// From address in the mail message
/// </summary>
public virtual string Address { get; set; }
/// <summary>
/// Server name hosting the SMTP service
/// </summary>
public virtual string Host { get; set; }
/// <summary>
/// Port number on which SMTP service runs
/// </summary>
public virtual int Port { get; set; }
/// <summary>
/// Whether to enable SSL communications with the server
/// </summary>
public virtual bool EnableSsl { get; set; }
/// <summary>
/// Whether specific credentials should be used
/// </summary>
public virtual bool RequireCredentials { get; set; }
/// <summary>
/// The username to connect to the SMTP server if DefaultCredentials is False
/// </summary>
public virtual string UserName { get; set; }
/// <summary>
/// The password to connect to the SMTP server if DefaultCredentials is False
/// </summary>
public virtual string Password { get; set; }
public SmtpSettingsPartRecord() {
Port = 25;
RequireCredentials = false;
EnableSsl = false;
}
}
}

View File

@@ -0,0 +1,12 @@
Name: Email Messaging
antiforgery: enabled
author: The Orchard Team
website: http://orchardproject.net
version: 0.1.0
orchardversion: 0.6.0
description: The Email Messaging module adds Email sending functionalities.
features:
Orchard.Email:
Description: Email Messaging services.
Category: Messaging
Dependencies: Messaging

View File

@@ -0,0 +1,141 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{05660F47-D649-48BD-9DED-DF4E01E7CFF9}</ProjectGuid>
<ProjectTypeGuids>{F85E285D-A4E0-4152-9332-AB1D724D3325};{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Orchard.Email</RootNamespace>
<AssemblyName>Orchard.Email</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<MvcBuildViews>false</MvcBuildViews>
<FileUpgradeFlags>
</FileUpgradeFlags>
<OldToolsVersion>3.5</OldToolsVersion>
<UpgradeBackupLocation />
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.ComponentModel.DataAnnotations">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Web.ApplicationServices" />
<Reference Include="System.Web.DynamicData" />
<Reference Include="System.Web.Entity" />
<Reference Include="System.Web.Extensions" />
<Reference Include="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\lib\aspnetmvc\System.Web.Mvc.dll</HintPath>
</Reference>
<Reference Include="System.Drawing" />
<Reference Include="System.Web" />
<Reference Include="System.Web.Abstractions" />
<Reference Include="System.Web.Routing" />
<Reference Include="System.Xml" />
<Reference Include="System.Configuration" />
<Reference Include="System.Web.Services" />
<Reference Include="System.EnterpriseServices" />
<Reference Include="System.Web.Mobile" />
<Reference Include="System.Xml.Linq" />
</ItemGroup>
<ItemGroup>
<Compile Include="DataMigrations\EmailDataMigration.cs" />
<Compile Include="Handlers\SmtpSettingsPartHandler.cs" />
<Compile Include="Models\SmtpSettingsPart.cs" />
<Compile Include="Models\SmtpSettingsPartRecord.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Services\EmailMessageEventHandler.cs" />
<Compile Include="Services\EmailMessagingChannel.cs" />
<Compile Include="Services\MissingSettingsBanner.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="Module.txt" />
<Content Include="Views\EditorTemplates\Parts\Smtp.SiteSettings.ascx" />
<Content Include="Web.config" />
<Content Include="Views\Web.config" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
<ProjectReference Include="..\..\..\Orchard\Orchard.Framework.csproj">
<Project>{2D1D92BB-4555-4CBE-8D0E-63563D6CE4C6}</Project>
<Name>Orchard.Framework</Name>
</ProjectReference>
<ProjectReference Include="..\..\Core\Orchard.Core.csproj">
<Project>{9916839C-39FC-4CEB-A5AF-89CA7E87119F}</Project>
<Name>Orchard.Core</Name>
</ProjectReference>
<ProjectReference Include="..\Orchard.Users\Orchard.Users.csproj">
<Project>{79AED36E-ABD0-4747-93D3-8722B042454B}</Project>
<Name>Orchard.Users</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target> -->
<!-- To enable MVC area subproject support, uncomment the following two lines:
<UsingTask TaskName="Microsoft.Web.Mvc.Build.CreateAreaManifest" AssemblyName="Microsoft.Web.Mvc.Build, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<UsingTask TaskName="Microsoft.Web.Mvc.Build.CopyAreaManifests" AssemblyName="Microsoft.Web.Mvc.Build, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
-->
<Target Name="AfterBuild" DependsOnTargets="AfterBuildCompiler">
<PropertyGroup>
<AreasManifestDir>$(ProjectDir)\..\Manifests</AreasManifestDir>
</PropertyGroup>
<!-- If this is an area child project, uncomment the following line:
<CreateAreaManifest AreaName="$(AssemblyName)" AreaType="Child" AreaPath="$(ProjectDir)" ManifestPath="$(AreasManifestDir)" ContentFiles="@(Content)" />
-->
<!-- If this is an area parent project, uncomment the following lines:
<CreateAreaManifest AreaName="$(AssemblyName)" AreaType="Parent" AreaPath="$(ProjectDir)" ManifestPath="$(AreasManifestDir)" ContentFiles="@(Content)" />
<CopyAreaManifests ManifestPath="$(AreasManifestDir)" CrossCopy="false" RenameViews="true" />
-->
</Target>
<Target Name="AfterBuildCompiler" Condition="'$(MvcBuildViews)'=='true'">
<AspNetCompiler VirtualPath="temp" PhysicalPath="$(ProjectDir)\..\$(ProjectName)" />
</Target>
<ProjectExtensions>
<VisualStudio>
<FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
<WebProjectProperties>
<UseIIS>False</UseIIS>
<AutoAssignPort>True</AutoAssignPort>
<DevelopmentServerPort>45979</DevelopmentServerPort>
<DevelopmentServerVPath>/</DevelopmentServerVPath>
<IISUrl>
</IISUrl>
<NTLMAuthentication>False</NTLMAuthentication>
<UseCustomServer>True</UseCustomServer>
<CustomServerUrl>http://orchard.codeplex.com</CustomServerUrl>
<SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
</WebProjectProperties>
</FlavorProperties>
</VisualStudio>
</ProjectExtensions>
</Project>

View File

@@ -0,0 +1,35 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Orchard.Messaging.Email")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Orchard")]
[assembly: AssemblyCopyright("Copyright © CodePlex Foundation 2009")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("9c778ece-c759-47fb-95b6-e73c03d9e969")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("0.5.0")]
[assembly: AssemblyFileVersion("0.5.0")]

View File

@@ -0,0 +1,30 @@
using Orchard.Messaging.Events;
using Orchard.Core.Messaging.Models;
using Orchard.ContentManagement;
using Orchard.Users.Models;
using Orchard.Messaging.Models;
namespace Orchard.Email.Services {
public class EmailMessageEventHandler : IMessageEventHandler {
private readonly IContentManager _contentManager;
public EmailMessageEventHandler(IContentManager contentManager) {
_contentManager = contentManager;
}
public void Sending(MessageContext context) {
var contentItem = _contentManager.Get(context.Message.Recipient.Id);
if ( contentItem == null )
return;
var recipient = contentItem.As<UserPart>();
if ( recipient == null )
return;
context.Properties.Add(EmailMessagingChannel.EmailAddress, recipient.Email);
}
public void Sent(MessageContext context) {
}
}
}

View File

@@ -0,0 +1,93 @@
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Mail;
using System.Web;
using System.Web.Hosting;
using JetBrains.Annotations;
using Orchard.ContentManagement;
using Orchard.Localization;
using Orchard.Logging;
using Orchard.Core.Messaging.Models;
using Orchard.Core.Messaging.Services;
using Orchard.Email.Models;
using Orchard.Settings;
using Orchard.Messaging.Services;
using Orchard.Messaging.Models;
namespace Orchard.Email.Services {
public class EmailMessagingChannel : IMessagingChannel {
public const string EmailService = "Email";
public const string EmailAddress = "EmailAddress";
public EmailMessagingChannel() {
Logger = NullLogger.Instance;
}
protected virtual ISite CurrentSite { get; [UsedImplicitly] private set; }
public ILogger Logger { get; set; }
public Localizer T { get; set; }
public void SendMessage(MessageContext context) {
if ( context.Message.Service.ToLower() != EmailService )
return;
var smtpSettings = CurrentSite.As<SmtpSettingsPart>();
// can't process emails if the Smtp settings have not yet been set
if ( smtpSettings == null || !smtpSettings.IsValid() ) {
return;
}
var smtpClient = new SmtpClient { UseDefaultCredentials = !smtpSettings.RequireCredentials };
if ( !smtpClient.UseDefaultCredentials && !String.IsNullOrWhiteSpace(smtpSettings.UserName) ) {
smtpClient.Credentials = new NetworkCredential(smtpSettings.UserName, smtpSettings.Password);
}
var emailAddress = context.Properties[EmailAddress];
if(String.IsNullOrWhiteSpace(emailAddress)) {
Logger.Error("Recipient is missing an email address");
return;
}
if ( smtpSettings.Host != null )
smtpClient.Host = smtpSettings.Host;
smtpClient.Port = smtpSettings.Port;
smtpClient.EnableSsl = smtpSettings.EnableSsl;
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
var message = new MailMessage {
From = new MailAddress(smtpSettings.Address),
Subject = context.Message.Subject ?? "",
Body = context.Message.Body ?? "",
IsBodyHtml = context.Message.Body != null && context.Message.Body.Contains("<") && context.Message.Body.Contains(">")
};
message.To.Add(emailAddress);
try {
smtpClient.Send(message);
Logger.Debug("Message sent to {0}: {1}", emailAddress, context.Message.Subject);
}
catch(Exception e) {
Logger.Error(e, "An unexpected error while sending a message to {0}: {1}", emailAddress, context.Message.Subject);
}
}
public bool IsRecipientValidated(ContentItem contentItem) {
return false;
}
public void ValidateRecipient(ContentItem contentItem) {
var context = new MessageContext(new Message { Recipient = contentItem.Record, Body = "Please validate your account", Service = "email", Subject = "Validate your account" } );
SendMessage(context);
}
public IEnumerable<string> GetAvailableServices() {
return new[] {EmailService};
}
}
}

View File

@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using JetBrains.Annotations;
using Orchard.ContentManagement;
using Orchard.Core.Messaging.Models;
using Orchard.Localization;
using Orchard.Email.Models;
using Orchard.Settings;
using Orchard.UI.Admin.Notification;
using Orchard.UI.Notify;
namespace Orchard.Email.Services {
public class MissingSettingsBanner: INotificationProvider {
public MissingSettingsBanner() {
T = NullLocalizer.Instance;
}
protected virtual ISite CurrentSite { get; [UsedImplicitly] private set; }
public Localizer T { get; set; }
public IEnumerable<NotifyEntry> GetNotifications() {
var smtpSettings = CurrentSite.As<SmtpSettingsPart>();
if ( smtpSettings == null || !smtpSettings.IsValid() ) {
yield return new NotifyEntry { Message = T("The SMTP settings needs to be configured." ), Type = NotifyType.Warning};
}
var messageSettings = CurrentSite.As<MessageSettingsPart>().Record;
if ( messageSettings == null || String.IsNullOrWhiteSpace(messageSettings.DefaultChannelService) ) {
yield return new NotifyEntry { Message = T("The default channel service needs to be configured."), Type = NotifyType.Warning };
}
}
}
}

View File

@@ -0,0 +1,43 @@
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<SmtpSettingsPartRecord>" %>
<%@ Import Namespace="Orchard.Email.Models"%>
<%@ Import Namespace="System.Net.Mail" %>
<fieldset>
<legend><%: T("SMTP")%></legend>
<div>
<label for="<%: Html.FieldIdFor(m => m.Address)%>"><%: T("Sender email address")%></label>
<%: Html.EditorFor(m => m.Address)%>
<%: Html.ValidationMessage("Address", "*")%>
</div>
<div>
<label for="<%: Html.FieldIdFor(m => m.Host)%>"><%: T("Host name")%></label>
<%: Html.EditorFor(m => m.Host)%>
<%: Html.ValidationMessage("Host", "*")%>
</div>
<div>
<label for="<%: Html.FieldIdFor(m => m.Port)%>"><%: T("Port number")%></label>
<%: Html.EditorFor(m => m.Port)%>
<%: Html.ValidationMessage("Port", "*")%>
</div>
<div>
<%: Html.EditorFor(m => m.EnableSsl)%>
<label for="<%: Html.FieldIdFor(m => m.EnableSsl)%>" class="forcheckbox"><%: T("Enable SSL communications")%></label>
<%: Html.ValidationMessage("EnableSsl", "*")%>
</div>
<div>
<%: Html.EditorFor(m => m.RequireCredentials)%>
<label for="<%: Html.FieldIdFor(m => m.RequireCredentials)%>" class="forcheckbox"><%: T("Require credentials")%></label>
<%: Html.ValidationMessage("RequireCredentials", "*")%>
</div>
<div data-controllerid="<%: Html.FieldIdFor(m => m.RequireCredentials)%>">
<div>
<label for="<%: Html.FieldIdFor(m => m.UserName)%>"><%: T("User name")%></label>
<%: Html.EditorFor(m => m.UserName)%>
<%: Html.ValidationMessage("UserName", "*")%>
</div>
<div>
<label for="<%: Html.FieldIdFor(m => m.Password)%>"><%: T("Password")%></label>
<%: Html.PasswordFor(m => m.Password)%>
<%: Html.ValidationMessage("Password", "*")%>
</div>
</div>
</fieldset>

View File

@@ -0,0 +1,34 @@
<?xml version="1.0"?>
<configuration>
<system.web>
<httpHandlers>
<add path="*" verb="*"
type="System.Web.HttpNotFoundHandler"/>
</httpHandlers>
<!--
Enabling request validation in view pages would cause validation to occur
after the input has already been processed by the controller. By default
MVC performs request validation before a controller processes the input.
To change this behavior apply the ValidateInputAttribute to a
controller or action.
-->
<pages
validateRequest="false"
pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<controls>
<add assembly="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
</controls>
</pages>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<handlers>
<remove name="BlockViewHandler"/>
<add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler"/>
</handlers>
</system.webServer>
</configuration>

View File

@@ -0,0 +1,22 @@
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</assemblies>
</compilation>
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID">
<namespaces>
<add namespace="System.Web.Mvc"/>
<add namespace="System.Web.Mvc.Ajax"/>
<add namespace="System.Web.Mvc.Html"/>
<add namespace="System.Web.Routing"/>
<add namespace="System.Linq"/>
<add namespace="System.Collections.Generic"/>
<add namespace="Orchard.Mvc.Html"/>
</namespaces>
</pages>
</system.web>
<system.web.extensions/>
</configuration>

View File

@@ -80,6 +80,7 @@ namespace Orchard.Setup.Services {
"Routable",
"Settings",
"XmlRpc",
"Messaging",
"Orchard.Users",
"Orchard.Roles",
"TinyMce",

View File

@@ -77,6 +77,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Orchard.Tests", "Tools\Orch
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Orchard.ArchiveLater", "Orchard.Web\Modules\Orchard.ArchiveLater\Orchard.ArchiveLater.csproj", "{1C981BB3-26F7-494C-9005-CC27A5144233}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Orchard.Email", "Orchard.Web\Modules\Orchard.Email\Orchard.Email.csproj", "{05660F47-D649-48BD-9DED-DF4E01E7CFF9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -219,6 +221,10 @@ Global
{1C981BB3-26F7-494C-9005-CC27A5144233}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1C981BB3-26F7-494C-9005-CC27A5144233}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1C981BB3-26F7-494C-9005-CC27A5144233}.Release|Any CPU.Build.0 = Release|Any CPU
{05660F47-D649-48BD-9DED-DF4E01E7CFF9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{05660F47-D649-48BD-9DED-DF4E01E7CFF9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{05660F47-D649-48BD-9DED-DF4E01E7CFF9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{05660F47-D649-48BD-9DED-DF4E01E7CFF9}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -243,6 +249,7 @@ Global
{D5D447D7-EF8E-43A6-B9A4-3B025DD9F45D} = {E9C9F120-07BA-4DFB-B9C3-3AFB9D44C9D5}
{DFD137A2-DDB5-4D22-BE0D-FA9AD4C8B059} = {E9C9F120-07BA-4DFB-B9C3-3AFB9D44C9D5}
{1C981BB3-26F7-494C-9005-CC27A5144233} = {E9C9F120-07BA-4DFB-B9C3-3AFB9D44C9D5}
{05660F47-D649-48BD-9DED-DF4E01E7CFF9} = {E9C9F120-07BA-4DFB-B9C3-3AFB9D44C9D5}
{ABC826D4-2FA1-4F2F-87DE-E6095F653810} = {74E681ED-FECC-4034-B9BD-01B0BB1BDECA}
{F112851D-B023-4746-B6B1-8D2E5AD8F7AA} = {74E681ED-FECC-4034-B9BD-01B0BB1BDECA}
{6CB3EB30-F725-45C0-9742-42599BA8E8D2} = {74E681ED-FECC-4034-B9BD-01B0BB1BDECA}

View File

@@ -0,0 +1,9 @@
using Orchard.Events;
using Orchard.Messaging.Models;
namespace Orchard.Messaging.Events {
public interface IMessageEventHandler : IEventHandler {
void Sending(MessageContext context);
void Sent(MessageContext context);
}
}

View File

@@ -0,0 +1,11 @@
using Orchard.ContentManagement.Records;
namespace Orchard.Messaging.Models {
public class Message {
public string Service { get; set; }
public string Subject { get; set; }
public string Body { get; set; }
public string Type { get; set; }
public ContentItemRecord Recipient { get; set; }
}
}

View File

@@ -0,0 +1,16 @@
using System.Collections.Generic;
using System.Net.Mail;
namespace Orchard.Messaging.Models {
public class MessageContext {
public Dictionary<string, string> Properties { get; private set; }
public Message Message { get; private set; }
public MailMessage MailMessage { get; private set; }
public MessageContext(Message message) {
Properties = new Dictionary<string, string>();
Message = message;
MailMessage = new MailMessage {Body = message.Body, Subject = message.Subject};
}
}
}

View File

@@ -0,0 +1,21 @@
using System.Collections.Generic;
using Orchard.Messaging.Models;
namespace Orchard.Messaging.Services {
public interface IMessageManager : IDependency {
/// <summary>
/// Sends a message without using the queue
/// </summary>
void Send(Message message);
/// <summary>
/// Wether at least one channel is active on the current site
/// </summary>
bool HasChannels();
/// <summary>
/// Provides a list of all the current available channel services
/// </summary>
IEnumerable<string> GetAvailableChannelServices();
}
}

View File

@@ -0,0 +1,22 @@
using System.Collections.Generic;
using Orchard.ContentManagement;
using Orchard.Messaging.Models;
namespace Orchard.Messaging.Services {
public interface IMessagingChannel : IDependency {
/// <summary>
/// Actually sends the message though this channel
/// </summary>
void SendMessage(MessageContext message);
/// <summary>
/// Sends a message to the recipient to validate his account
/// </summary>
void ValidateRecipient(ContentItem recipient);
/// <summary>
/// Provides all the handled services, the user can choose from when receving messages
/// </summary>
IEnumerable<string> GetAvailableServices();
}
}

View File

@@ -371,6 +371,11 @@
<Compile Include="Environment\IHostLocalRestart.cs" />
<Compile Include="Environment\IShellContainerRegistrations.cs" />
<Compile Include="FileSystems\Dependencies\DynamicModuleVirtualPathProvider.cs" />
<Compile Include="Messaging\Events\IMessageEventHandler.cs" />
<Compile Include="Messaging\Models\Message.cs" />
<Compile Include="Messaging\Models\MessageContext.cs" />
<Compile Include="Messaging\Services\IMessageManager.cs" />
<Compile Include="Messaging\Services\IMessagingChannel.cs" />
<Compile Include="Services\IHtmlFilter.cs" />
<Compile Include="Utility\Hash.cs" />
<Compile Include="Data\ISessionConfigurationCache.cs" />