Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
namespace Sitecore.DataExchange.Examples.Sitecore.LoggerPipelineStep
{
using System;
using System.Linq;
using global::Sitecore.DataExchange.Converters.PipelineSteps;
using global::Sitecore.DataExchange.DataAccess;
using global::Sitecore.DataExchange.Models;
using global::Sitecore.DataExchange.Repositories;
using global::Sitecore.Services.Core.Model;

public class LoggerPipelineStepConverter : BasePipelineStepConverter
{
public const string ValueAccessors = "ValueAccessors";
public const string ObjectLocation = "ObjectLocation";

private static readonly Guid TemplateId = Guid.Parse("{CCC46873-79B8-4DE0-9061-81715C9B9847}");

public LoggerPipelineStepConverter(IItemModelRepository repository) : base(repository)
{
SupportedTemplateIds.Add(TemplateId);
}
protected override void AddPlugins(ItemModel source, PipelineStep pipelineStep)
{
AddSelfieSettings(source, pipelineStep);
}

private void AddSelfieSettings(ItemModel source, PipelineStep pipelineStep)
{
var settings = new LoggerSettings
{
ObjectLocation = GetStringValue(source, ObjectLocation)
};

var accessors = ConvertReferencesToModels<IValueAccessor>(source, ValueAccessors);
if (accessors != null)
{
settings.ValueAccessors = accessors.ToList();
}

pipelineStep.AddPlugin(settings);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace Sitecore.DataExchange.Examples.Sitecore.LoggerPipelineStep
{
using System.Collections.Generic;
using DataAccess;

public class LoggerSettings : IPlugin
{
public List<IValueAccessor> ValueAccessors { get; set; }
public string ObjectLocation { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
namespace Sitecore.DataExchange.Examples.Sitecore.LoggerPipelineStep
{
using System;
using System.Linq;
using Contexts;
using DataAccess;
using Models;
using Processors.PipelineSteps;
using Services.Core.Diagnostics;

public class LoggerStepProcessor : BasePipelineStepProcessor
{

public override void Process(PipelineStep pipelineStep, PipelineContext pipelineContext, ILogger logger)
{
if (pipelineStep == null)
{
throw new ArgumentNullException(nameof(pipelineStep));
}

if (pipelineContext == null)
{
throw new ArgumentNullException(nameof(pipelineContext));
}

var loggerSettings = pipelineStep.GetPlugin<LoggerSettings>();

if (loggerSettings == null)
{
return;
}

var logMessage = String.Empty;

logMessage += DateTime.Now.ToString("t") + " : ";

var objectLocation = loggerSettings.ObjectLocation;
var objectModel = GetObjectFromPipelineContext(objectLocation, pipelineContext, logger);

if ((objectLocation == null) || (objectLocation == String.Empty) || (objectModel == null))
{
logMessage += "No object set;";
}
else
{
if (loggerSettings.ValueAccessors.Any())
{
var i = 0;
foreach (var valueAccessor in loggerSettings.ValueAccessors)
{
var data = valueAccessor.ValueReader.Read(objectModel, new DataAccessContext());
if (data.WasValueRead)
{
logMessage += (i > 0 ? ", " : String.Empty) + data.ReadValue;
}
i++;
}
}
}
logger.Info(logMessage + Environment.NewLine);
return;

}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
namespace Sitecore.DataExchange.Examples.Sitecore.SelfieLogger
{
using System;
using System.Linq;
using Converters.PipelineSteps;
using DataAccess;
using Extensions;
using Models;
using Plugins;
using Repositories;
using Services.Core.Model;

public class SelfieLoggerPipelineStepConverter : BasePipelineStepConverter
{
public const string EndpointTo = "EndpointTo";
public const string ValueAccessors = "ValueAccessors";
public const string ObjectLocation = "ObjectLocation";

private static readonly Guid TemplateId = Guid.Parse("{B4B7D23D-1994-4B4F-B512-53305AFAAE07}");

public SelfieLoggerPipelineStepConverter(IItemModelRepository repository) : base(repository)
{
SupportedTemplateIds.Add(TemplateId);
}
protected override void AddPlugins(ItemModel source, PipelineStep pipelineStep)
{
AddEndpointSettings(source,pipelineStep);
AddSelfieSettings(source, pipelineStep);
}
private void AddEndpointSettings(ItemModel source, PipelineStep pipelineStep)
{
var settings = new EndpointSettings();
var endpointTo = ConvertReferenceToModel<Endpoint>(source, EndpointTo);
if (endpointTo != null)
{
settings.EndpointTo = endpointTo;
}
pipelineStep.AddPlugin(settings);
}

private void AddSelfieSettings(ItemModel source, PipelineStep pipelineStep)
{
var settings = new SelfieLoggerSettings
{
ObjectLocation = GetStringValue(source, ObjectLocation),
SelfItemId = source.GetItemId()
};

var accessors = ConvertReferencesToModels<IValueAccessor>(source, ValueAccessors);
if (accessors != null)
{
settings.ValueAccessors = accessors.ToList();
}

pipelineStep.AddPlugin(settings);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace Sitecore.DataExchange.Examples.Sitecore.SelfieLogger
{
using System;
using System.Collections.Generic;
using DataAccess;

public class SelfieLoggerSettings : IPlugin
{
public List<IValueAccessor> ValueAccessors { get; set; }
public string ObjectLocation { get; set; }
public Guid SelfItemId { get; set; }
public const string SelfieField = "SelfieField";

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
namespace Sitecore.DataExchange.Examples.Sitecore.SelfieLogger
{
using System;
using System.Linq;
using Contexts;
using DataAccess;
using Extensions;
using Models;
using Processors.PipelineSteps;
using Providers.Sc.Plugins;
using Services.Core.Diagnostics;

public class SelfieLoggerStepProcessor : BasePipelineStepProcessor
{

public override void Process(PipelineStep pipelineStep, PipelineContext pipelineContext, ILogger logger)
{
if (pipelineStep == null)
{
throw new ArgumentNullException(nameof(pipelineStep));
}

if (pipelineContext == null)
{
throw new ArgumentNullException(nameof(pipelineContext));
}

var endpointSettings = pipelineStep.GetEndpointSettings();

if (endpointSettings == null)
{
return;
}

var repositorySettings = endpointSettings.EndpointTo.GetPlugin<ItemModelRepositorySettings>();
var repository = repositorySettings?.ItemModelRepository;

if (repository == null)
{
return;
}
var selfieLoggerSettings = pipelineStep.GetPlugin<SelfieLoggerSettings>();

if (selfieLoggerSettings == null)
{
return;
}

var itemId = selfieLoggerSettings.SelfItemId;
var itemModel = repository.Get(itemId);

itemModel[SelfieLoggerSettings.SelfieField] += Environment.NewLine + DateTime.Now.ToString("t") + " : ";

var objectLocation = selfieLoggerSettings.ObjectLocation;
var objectModel = GetObjectFromPipelineContext(objectLocation, pipelineContext, logger);

if ((objectLocation == null) || (objectLocation == String.Empty) || (objectModel == null))
{
itemModel[SelfieLoggerSettings.SelfieField] += "No object set;";
repository.Update(itemId, itemModel);
return;
}
if (selfieLoggerSettings.ValueAccessors.Any())
{
var i = 0;
foreach (var valueAccessor in selfieLoggerSettings.ValueAccessors)
{
var data = valueAccessor.ValueReader.Read(objectModel, new DataAccessContext());
if (data.WasValueRead)
{
itemModel[SelfieLoggerSettings.SelfieField] += ( i > 0 ? ", " : String.Empty) + data.ReadValue;
}
i++;
}
repository.Update(itemId, itemModel);
}
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{583CD139-3B8E-479C-9F29-43BA41501324}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Sitecore.DataExchange.Examples.Sitecore</RootNamespace>
<AssemblyName>Sitecore.DataExchange.Examples.Sitecore</AssemblyName>
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Sitecore.DataExchange">
<HintPath>..\lib\Sitecore.DataExchange.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Sitecore.DataExchange.DataAccess">
<HintPath>..\lib\Sitecore.DataExchange.DataAccess.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Sitecore.DataExchange.Providers.Sc">
<HintPath>..\lib\Sitecore.DataExchange.Providers.Sc.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Sitecore.Services.Core, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Sitecore.Services.Core.8.1.151003\lib\NET45\Sitecore.Services.Core.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Compile Include="LoggerPipelineStep\LoggerPipelineStepConverter.cs" />
<Compile Include="LoggerPipelineStep\LoggerSettings.cs" />
<Compile Include="LoggerPipelineStep\LoggerStepProcessor.cs" />
<Compile Include="SelfieLogger\SelfieLoggerPipelineStepConverter.cs" />
<Compile Include="SelfieLogger\SelfieLoggerSettings.cs" />
<Compile Include="SelfieLogger\SelfieLoggerStepProcessor.cs" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.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>
<Target Name="AfterBuild">
</Target>
-->
</Project>
4 changes: 4 additions & 0 deletions Sitecore.DataExchange.Examples.Sitecore/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Sitecore.Services.Core" version="8.1.151003" targetFramework="net452" developmentDependency="true" />
</packages>
Loading