Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Table of Contents

Goal

In this article, you will find information about working with the Exporter, detailed information about the Exporter API.

Prerequisite

Info

Installed Sitefinity connector - Installing the Connector .NET SDK NuGet package

How is Export made behind the scenes?

What happens in the Hawksearch project?

In the Hawksearch Admin Panel (your-website-url/Sitefinity/Administration/hawksearchconfig), there are 2 buttons: “Run Full Export Now“ and “Run Delta Export Now“.

When one of the buttons is hit the “hawk/export/run” is called. This is a Http Post request where we pass as а parameter an integer number depending on which kind of export is being triggered. This number is later resolved from the ExportType enumerator, where:·        

  • FullExport = 0

...

  • DeltaExport = 1

Code Block
[HttpPost]
[Route("run")]
public JsonResult<OperationStatus> Run([FromBody] int exportType)
{
    var exportModel = new ExportModel();
    var result = exportModel.Run(exportType);

    return this.Json(result);
}

...

In the ExportModel there is also the GetExportDetails() method, where the information about the Full and Delta export is being resolved. After the Export, an object ExportResult is being returned to the ExportModel and this object provides the whole details about the export.

What happens in the Hawksearch.SDK project?

The further steps that are related to the export are part of the SDK project that is CMS independent, but still a .NET SDK.

...

The Writer is implementing the interface IWiteIWriter:

Code Block
using Hawksearch.SDK.Indexing;
using System.Collections.Generic;
using System.Text;

namespace Hawksearch.SDK.Export.IO
{
    public interface IWriter
    {
        void Write(ref StringBuilder itemsSb, ref StringBuilder contentSb, ref StringBuilder attributesSb, ref StringBuilder hierarchySb, List<SubmitDocument> items);
    }
}

...

You can find your files with the exported items in the folder that you’ve set in the Configurations.

Setting a Schedule Export

Setting a Schedule for Export is an important part of Export functionalities.
When Scheduling an export a HttpPost request is made.

...

Code Block
languagec#
public override void ExecuteTask()
        {
            var hawksearchConfig = Config.Get<HawkSearchConfig>();
            try
            {
                if (hawksearchConfig.RunExportTaskOnSpecifiedDomainOnly)
                {
                    this.CallFullExportApi(hawksearchConfig);
                }
                else
                {
                    var exporter = IocKernel.Get<IExporter>();

                    var exportInfo = new ExportInfo();
                    List<string> contentTypes = ContentTypeData.GetContentTypes();
                    exportInfo.ContentTypes = contentTypes;
                    exportInfo.ExportType = ExportType.Full;
                    ExportModel.GetConfig(exportInfo);

                    exporter.Export(exportInfo);
                }
            }
            catch (Exception ex)
            {
                Log.Write(ex, ConfigurationPolicy.ErrorLog);
            }

            //Schedule next run if not a "One Time Execution" instance.
            if (!this.OneTimeExecution)
            {
                SchedulingManager schedulingManager = SchedulingManager.GetManager();
                var taskKey = hawksearchConfig.ExportTaskKey;
                var hawkManager = HawkManager.GetManager();
                var exportRecord = ExportModel.GetExportInfo(hawkManager);
                var exportScheduleTime = exportRecord.ExportScheduleTime;
                var exportScheduleType = exportRecord.ExportScheduleType;
                var newTask = new FullExportTask() { Key = taskKey, ExecuteTime = SDK.Export.ExportScheduler.GetNextOccurrence(exportScheduleType, exportScheduleTime).ToUniversalTime() };
                
                schedulingManager.AddTask(newTask);
                schedulingManager.SaveChanges();
            }
        }

How to integrate the Hawksearch.SDK with any CMS?

The power of the Export now is that it can be used with all kind of CMS. The Export functionality is part of the SDK and does not depend on Sitefinity.

...

Code Block
protected virtual List<SubmitDocument> GetPageNodes(ISite site, DateTime? lastModified = null)
        {
            var pageList = new List<IDataItem>();
            var pageManager = PageManager.GetManager();

            pageList = pageManager
                   .GetPageDataList()
                   .ToList()
                   .Where(pData => pData.Status == ContentLifecycleStatus.Live)
                   .Select(pData => pData.NavigationNode)
                   .Where(pNode => !pNode.IsBackend && !pNode.IsDeleted && pNode.RootNodeId == site.SiteMapRootNodeId)
                   .Cast<IDataItem>()
                   .ToList();

            if (lastModified != null)
            {
                pageList = pageList.Where(p => p.LastModified >= lastModified).ToList();
                var deletedItems = this.hawkManager.GetRemovedDataItems().Where(di => di.LastModified >= lastModified).ToList();
                pageList.AddRange(deletedItems);
            }

            var submitDocuments = this.Convert(pageList, SDK.Export.Constants.ExportConstants.FullExport);

            return submitDocuments;
        }

Creating SubmitDocument

The SubmitDocuments are the items that the Exporter expects and can process. These Documents contain the base information about an record. A document can be initialized with an empty constructor and different Fields can be added. An SubmitDocument can have IdentityFields and List<SubmitFields>.

...