Custom Modules for Sitefinity 4.0

Because the documentation in the developer's guide covers the latest version of Sitefinity, this topic is intended to introduce you to the specifics of creating a custom module for Sitefinity 4.0.

NOTE: The procedures and the steps that are not mentioned here are similar to the ones for the latest version of Sitefinity.

When creating modules for Sitefinity 4.0, there are several things that you must take in consideration:

Integrating the OpenAccess enhancer

To integrate the OpenAccess enhancer you must perform the following:

  1. From the context menu of the module's project, click Unload Project.
  2. From the context menu of the unloaded project, click Edit ModuleName.csproj.
  3. Find the following line:

    <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  4. Import the following lines of code after the aforementioned line:

    <!-- Telerik OpenAccess enhancement -->
      <Target Name="EnhanceAssembly" Condition="'$(_AssemblyTimestampBeforeCompile)'!='$(_AssemblyTimestampAfterCompile)'">
        <Copy SourceFiles="$(TargetPath)" DestinationFiles="$(TargetPath).notenhanced" />
        <Copy SourceFiles="$(PdbFile)" DestinationFiles="$(PdbFile).notenhanced" ContinueOnError="true" />
        <Message Text="$(TargetDir)" Importance="high" />
        <Message Text="Solution = $(SolutionDir)" Importance="high" />
        <Exec IgnoreExitCode="false" WorkingDirectory="$(SolutionDir)" Command=""C:\Program Files (x86)\Telerik\Sitefinity 4.0\Libraries\VEnhance.exe" -verboseMode:2 "-config:$(ProjectDir)App.config" -signAssembly "-keyFile:$(ProjectDir)$(AssemblyOriginatorKeyFile)" "-assembly:$(TargetPath)"" Condition="'$(AssemblyOriginatorKeyFile)'!=''" />
        <Exec IgnoreExitCode="false" WorkingDirectory="$(SolutionDir)" Command=""C:\Program Files (x86)\Telerik\Sitefinity 4.0\Libraries\VEnhance.exe" -verboseMode:2 "-config:$(ProjectDir)App.config" "-assembly:$(TargetPath)"" Condition="'$(AssemblyOriginatorKeyFile)'==''" />
        <Copy SourceFiles="$(TargetPath)" DestinationFolder="$(IntermediateOutputPath)" />
        <Copy SourceFiles="$(PdbFile)" DestinationFolder="$(IntermediateOutputPath)" ContinueOnError="true" />
      </Target>
      <Target Name="PeVerify" Condition="'$(_AssemblyTimestampBeforeCompile)'!='$(_AssemblyTimestampAfterCompile)'">
        <GetFrameworkSdkPath>
          <Output TaskParameter="Path" PropertyName="SdkPath" />
        </GetFrameworkSdkPath>
        <Exec WorkingDirectory="$(SdkPath)bin" Command="peverify.exe /nologo "$(TargetPath)"" />
      </Target>
      <PropertyGroup>
        <PdbFile>$(OutDir)\$(AssemblyName).pdb</PdbFile>
        <RunPostBuildEvent>OnOutputUpdated</RunPostBuildEvent>
        <PrepareForRunDependsOn>
          $(PrepareForRunDependsOn);
          EnhanceAssembly;
          <!-- PeVerify --></PrepareForRunDependsOn>
      </PropertyGroup>

    In this code snippet you must take note at the following things:

    • The path to the VEnhance.exe

      The VEnhance.exe is shipped with the Sitefinity SDK. It can be found in the installation directory of the Sitefinity 4.0 SDK under \Libraries. Before reusing the code snippet, ensure that your Venhance.exe file is placed in C:\Program Files (x86)\Telerik\Sitefinity 4.0\Libraries\VEnhance.exe

    • The path to the App.config file in your module's project

      The code snippet assumes that the file is placed in the root of your project and the path to it is defined as $(ProjectDir)App.config. For more information about the App.config file, see Creating an App.config file.

Creating the App.config file

The App.config file contains information about the OpenAccess configuration and the mappings it creates for the model class.

To create and implement the App.config file, perform the following:

  1. From the context menu of the module's project, click Add » New Item.
  2. From the dialog click Visual C# Items » Data » XML File.

  3. Name the file App.config and click Add.
  4. Open the App.config file.
  5. In it create the following sections:

    <?xml version="1.0"?>
    <configuration>
      <configSections>
        <section name="openaccess" type="Telerik.OpenAccess.Config.ConfigSectionHandler, Telerik.OpenAccess.Config, Version=1.0.0.0, Culture=neutral, PublicKeyToken=7ce17eeaf1d59342" requirePermission="false" />
      </configSections>
      <openaccess xmlns="http://www.telerik.com/OpenAccess">
        <references>
          <!-- Do not add any references here, as they are added dynamically by Sitefinity
          and it will be duplicated-->
        </references>
        <connections>
          <connection id="DatabaseConnection1">
            <databasename>Database1</databasename>
            <servername>(local)\SQLEXPRESS</servername>
            <integratedSecurity>True</integratedSecurity>
            <backendconfigurationname>mssqlConfiguration</backendconfigurationname>
          </connection>
        </connections>
        <backendconfigurations>
          <backendconfiguration id="mssqlConfiguration" backend="mssql">
            <mappingname>mssqlMapping</mappingname>
          </backendconfiguration>
        </backendconfigurations>
        <mappings current="mssqlMapping">
        </mappings>
      </openaccess>
    </configuration>

Creating the OpenAccess mappings

The OpenAccess mappings are defined in the App.config file. To define the mappings, perform the following:

  1. Open the App.config file.
  2. Find the mappings section.
  3. In it define the mappings for the model classes in your module.

    Following is the code for a class named ProductItem:

    <mapping id="mssqlMapping">
      <namespace name="ProductCatalogSample.Model">
        <class name="ProductItem">
          <extension key="db-table-name" value="sfex_product_item" />       
          <field name="permissions">
            <collection>              
              <extension key="db-link-table" />
            </collection>
          </field>           
          <field name="urls">
            <collection>
              <extension key="inverse" value="parent" />
              <extension key="managed" value="true" />
            </collection>
          </field>
          <field name="permissionChildren">
            <collection>
              <extension key="db-link-table" />
            </collection>
          </field>
        </class>
        <class name="ProductItemUrlData">
          <field name="parent">
            <extension key="db-ref" value="Telerik.Sitefinity.GenericContent.Model.Content.contentId">
              <extension key="db-column">
                <extension key="db-column-name" value="content_id" />
              </extension>
            </extension>
          </field>
        </class>
      </namespace>
    </mapping>

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