Creating the module class

The module described in this section registers the resources class and the inbound and outbound pipes.

To implement the module, perform the following:

  1. In the context menu of the project, click Add » Class...

  2. In the Name input field, enter FacebookEventsImportModule.

  3. Open the file FacebookEventsImportModule.cs and add the following namespaces:

    using System.Diagnostics.CodeAnalysis;
    using FacebookEventsImport.PublishingSystem;
    using Telerik.Sitefinity.Abstractions;
    using Telerik.Sitefinity.Abstractions.VirtualPath;
    using Telerik.Sitefinity.Abstractions.VirtualPath.Configuration;
    using Telerik.Sitefinity.Configuration;
    using Telerik.Sitefinity.Data;
    using Telerik.Sitefinity.Localization;
    using Telerik.Sitefinity.Publishing;
    using Telerik.Sitefinity.Publishing.Model;
    using Telerik.Sitefinity.Services;

  4. Change the class definition to:

    public class FacebookEventsImportModule : ModuleBase
    {
    }

  5. Define the module name by pasting the following code:

    public static string ModuleName = "FacebookEventsImport";

  6. Add the following properties:

    public static readonly string PublishingVirtualPath = "~/SFPublishing/";
     
    public override Guid LandingPageId
    {
        get
        {
            return Guid.Empty;
        }
    }
     
    public override Type[] Managers
    {
        get
        {
            return new Type[ 0 ];
        }
    }

  7. Override the Initialize method of the ModuleBase class, by adding the following code:

    [SuppressMessage( "Microsoft.StyleCop.CSharp.NamingRules", "SA1300:ElementMustBeginWithUpperCaseLetter", Justification = "This method is obsolete" )]
    [SuppressMessage( "Microsoft.StyleCop.CSharp.DocumentationRules", "SA1600:ElementsMustBeDocumented", Justification = "This method is obsolete" )]
    public override void Initialize( ModuleSettings settings )
    {
        base.Initialize( settings );
        Res.RegisterResource<FacebookEventsImportResources>();
        this.RegisterFacebookEventsInboundPipe();
        this.RegisterFacebookEventsOutboundPipe();
    }

  8. To register the pipes, add the following methods:

    private void RegisterFacebookEventsInboundPipe()
    {
        PublishingSystemFactory.RegisterPipe( FacebookEventsInboundPipe.PipeName, typeof( FacebookEventsInboundPipe ) );
     
        var mappingsList = FacebookEventsInboundPipe.GetDefaultMapping();
        PublishingSystemFactory.RegisterPipeMappings( FacebookEventsInboundPipe.PipeName, true, mappingsList );
     
        SitefinityContentPipeSettings pipeSettings = new SitefinityContentPipeSettings();
        pipeSettings.IsInbound = true;
        pipeSettings.IsActive = true;
        pipeSettings.MaxItems = 25;
        pipeSettings.InvocationMode = PipeInvokationMode.Push;
        pipeSettings.ContentTypeName = typeof( Telerik.Sitefinity.Events.Model.Event ).FullName;
        pipeSettings.UIName = "FacebookEventsInboundPipeName";
        pipeSettings.PipeName = FacebookEventsInboundPipe.PipeName;
        pipeSettings.ResourceClassId = typeof( FacebookEventsImportResources ).Name;
     
        PublishingSystemFactory.RegisterPipeSettings( FacebookEventsInboundPipe.PipeName, pipeSettings );
     
        var definitions = FacebookEventsInboundPipe.CreateDefaultPipeDefinitions();
        PublishingSystemFactory.RegisterPipeDefinitions( FacebookEventsInboundPipe.PipeName, definitions );
    }
     
    private void RegisterFacebookEventsOutboundPipe()
    {
        PublishingSystemFactory.RegisterPipe( FacebookEventsOutboundPipe.PipeName, typeof( FacebookEventsOutboundPipe ) );
     
        var mappingsListOutbound = FacebookEventsOutboundPipe.GetDefaultMapping();
        PublishingSystemFactory.RegisterPipeMappings( FacebookEventsOutboundPipe.PipeName, false, mappingsListOutbound );
     
        SitefinityContentPipeSettings pipeSettingsOutbound = new SitefinityContentPipeSettings();
        pipeSettingsOutbound.IsInbound = false;
        pipeSettingsOutbound.IsActive = true;
        pipeSettingsOutbound.MaxItems = 0;
        pipeSettingsOutbound.InvocationMode = PipeInvokationMode.Push;
        pipeSettingsOutbound.ContentTypeName = typeof( Telerik.Sitefinity.Events.Model.Event ).FullName;
        pipeSettingsOutbound.UIName = "FacebookEventsOutboundPipeName";
        pipeSettingsOutbound.PipeName = FacebookEventsOutboundPipe.PipeName;
        pipeSettingsOutbound.ResourceClassId = typeof( FacebookEventsImportResources ).Name;
     
        PublishingSystemFactory.RegisterPipeSettings( FacebookEventsOutboundPipe.PipeName, pipeSettingsOutbound );
     
        var definitionsOutbound = FacebookEventsOutboundPipe.CreateDefaultPipeDefinitions();
        PublishingSystemFactory.RegisterPipeDefinitions( FacebookEventsOutboundPipe.PipeName, definitionsOutbound );
    }

  9. Override the Install method of the ModuleBase class.

    The method installs the module in Sitefinity system.

    public override void Install( SiteInitializer initializer )
    {
        this.InstallCustomVirtualPaths( initializer );
    }
     
    private void InstallCustomVirtualPaths( SiteInitializer initializer )
    {
        var virtualPathConfig = initializer.Context.GetConfig<VirtualPathSettingsConfig>();
        ConfigManager.Executed += new EventHandler<ExecutedEventArgs>( ConfigManager_Executed );
        var productsModuleVirtualPathConfig = new VirtualPathElement( virtualPathConfig.VirtualPaths )
        {
            VirtualPath = FacebookEventsImportModule.PublishingVirtualPath + "*",
            ResolverName = "EmbeddedResourceResolver",
            ResourceLocation = "FacebookEventsImport"
        };
        if ( !virtualPathConfig.VirtualPaths.ContainsKey( FacebookEventsImportModule.PublishingVirtualPath + "*" ) )
            virtualPathConfig.VirtualPaths.Add( productsModuleVirtualPathConfig );
    }
     
    private void ConfigManager_Executed( object sender, Telerik.Sitefinity.Data.ExecutedEventArgs args )
    {
        if ( args.CommandName == "SaveSection" )
        {
            var section = args.CommandArguments as VirtualPathSettingsConfig;
            if ( section != null )
            {
                VirtualPathManager.Reset();
            }
        }
    }

  10. Implement the ModuleBase by pasting the following code:

    protected override ConfigSection GetModuleConfig()
    {
        return null;
    }
     
    public override void Upgrade( SiteInitializer initializer, Version upgradeFrom )
    {
    }

FacebookEventsImportModule inherits from ModuleBase. The Initialize method registers the resources class and the pipes. When registering the pipe, you register all of its components.

Next steps

+1-888-365-2779
sales@sitefinity.com

Related topics:

Feedback

How useful is this article?

Tell us more

Submit
Your message was successfully sent.

We appreciate your feedback.

Your message could not be sent.

OK