ListService.cs

Version InfoThis topic applies to Episerver.ConnectForMarketingAutomation 4.0.0 and lower. For later versions, see Sample Connector - IMarketingConnector

using System.Collections.Generic;
using EPiServer.MarketingAutomationIntegration.Domain;
using EPiServer.MarketingAutomationIntegration.Services;
using DemoConnector.Models;
using System.Linq;

namespace DemoConnector.Services
{
    /// <summary>
    /// Reference IListService implementation that manages a single IDataList for marketing automation interface integration.
    /// </summary>
    public class ListService : IListService
    {
        private List<IDataList> _dblist = new List<IDataList>();
        private List<KeyValuePair<string, string>> _defaultDataListFields = new List<KeyValuePair<string, string>>();

        /// <summary>
        /// Note: When you create a database object, it is stored in the Episerver database in the tblSystemBigTable table. 
        /// You can use the following query to view the object:
        /// SELECT TOP 1000 [pkId], * FROM [AlloyWithSharePoint].[dbo].[tblSystemBigTable] where StoreName = 'XFormFolders'
        /// </summary>
        private DataList _defaultDataList = new DataList() { Id = 1, Name = "DemoConnectorDataBase",
            ParentName = "" };

        private List<IDataList> _profilelist = new List<IDataList>();
        private List<KeyValuePair<string, string>> _profileListFields = new List<KeyValuePair<string, string>>();
        private DataList _profileDataList = new DataList() { Id = 2, Name = "DemoConnectorProfileList",
            ParentName = "DemoConnectorDataBase" };

        /// <summary>
        /// Default constructor builds the default list and associated metadata.
        /// </summary>
        public ListService()
        {
           _dblist.Add(_defaultDataList);

            _defaultDataListFields.Add(new KeyValuePair<string, string>("Name", "democonnector_name"));
            _defaultDataListFields.Add(new KeyValuePair<string, string>("Email", "democonnector_email"));
            _defaultDataListFields.Add(new KeyValuePair<string, string>("Message", "democonnector_message"));
            _defaultDataListFields.Add(new KeyValuePair<string, string>("Role", "democonnector_role"));
            _defaultDataListFields.Add(new KeyValuePair<string, string>("State", "democonnector_state"));

            _profilelist.Add(_profileDataList);
            _profileListFields.Add(new KeyValuePair<string, string>("Name", "democonnector_profilename"));
            _profileListFields.Add(new KeyValuePair<string, string>("Description", "democonnector_profiledescription"));
            _profileListFields.Add(new KeyValuePair<string, string>("Owner", "democonnector_profileowner"));
        }

        /// <summary>
        /// Gets a list of IDataList objects that represent Database instances that this connector supports. 
        /// </summary>
        /// <returns>a list of IDatalist objects, in this case a list of one.</returns>
        public IEnumerable<IDataList> GetDatabases()
        {
            return _dblist;
        }

        /// <summary>
        /// Gets a list of column names which belongs to a specified list, with possible filtered-out columns.
        /// </summary>
        /// <param name="listId">The list identifier.</param>
        /// <returns>List of columns.</returns>
        /// <remarks>
        /// Use this when getting columns (fields) for dynamic contents. 
        /// This implementation does not filter out any columns.
        /// </remarks>
        public IEnumerable<string> GetFilteredListColumns(int listId)
        {
            return GetListColumns(listId);
        }

        /// <summary>
        /// Gets a list of column names that belong to specified list.
        /// </summary>
        /// <param name="listId">The list identifier.</param>
        /// <returns>
        /// List of columns. Each column is represented by a KeyValuePair object
        /// where key is the column name and value is possibly the column display name.
        /// </returns>
        public IEnumerable<KeyValuePair<string, string>> GetListColumnRecords(int listId)
        {
            if (listId == _defaultDataList.Id)
                return _defaultDataListFields;
            else if (listId == _profileDataList.Id)
                return _profileListFields;
            else
                return Enumerable.Empty<KeyValuePair<string, string>>();
        }

        /// <summary>
        /// Gets a list of column names that belong to specified list.
        /// </summary>
        /// <param name="listId">The list identifier.</param>
        /// <returns>List of columns.</returns>
        public IEnumerable<string> GetListColumns(int listId)
        {
            if (listId == _defaultDataList.Id)
            {
                var list = new List<string>();
                foreach (var item in _defaultDataListFields)
                {
                    list.Add(item.Key);
                }
                return list;
            }
            else if (listId ==_profileDataList.Id)
            {
                var list = new List<string>();
                foreach (var item in _profileListFields)
                {
                    list.Add(item.Key);
                }
                return list;
            }
            else
                return Enumerable.Empty<string>();
        }

        /// <summary>
        /// Gets lists of IDataLists that represent the Profiles. 
        /// </summary>
        /// <returns>Gets lists.</returns>
        public IEnumerable<IDataList> GetLists()
        {
            return _profilelist;
        }
    }
}

Related topics

Last updated: Dec 14, 2015