Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
art-alexeyenko committed Mar 30, 2017
1 parent 3216b20 commit 7070fbf
Show file tree
Hide file tree
Showing 8 changed files with 569 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/Sitecore.Support.95158.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25123.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{CE871B41-FB3B-4F88-91C2-B7F4C3B0105D}") = "Sitecore.Support.95158", "Sitecore.Support.95158\Sitecore.Support.95158.csproj", "{1941A4FF-2693-4906-9F3C-120F6A2C83A2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{1941A4FF-2693-4906-9F3C-120F6A2C83A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1941A4FF-2693-4906-9F3C-120F6A2C83A2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1941A4FF-2693-4906-9F3C-120F6A2C83A2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1941A4FF-2693-4906-9F3C-120F6A2C83A2}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<pipelines>
<insertRenderings>
<processor type="Sitecore.Support.Pipelines.InsertRenderings.Processors.EvaluateSorting, Sitecore.Support.95158" />
</insertRenderings>
</pipelines>
</sitecore>
</configuration>
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
using Sitecore.Data.Fields;
using Sitecore.Data.Items;
using Sitecore.Diagnostics;
using Sitecore.Layouts;
using Sitecore.Pipelines.InsertRenderings;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml;

namespace Sitecore.Support.Pipelines.InsertRenderings.Processors
{
internal class EvaluateSorting : InsertRenderingsProcessor
{
protected virtual void Evaluate(InsertRenderingsArgs args, Item item)
{
new List<RenderingReference>(args.Renderings);
if (item == null)
{
return;
}
LayoutField layoutField = item.Fields[FieldIDs.LayoutField];
if (!layoutField.InnerField.ContainsStandardValue && !string.IsNullOrEmpty(layoutField.InnerField.Value))
{
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.LoadXml(layoutField.InnerField.Value);
string deviceId = Context.Device.ID.ToString();
XmlNode xmlNode = null;
this.GetDevice(xmlDocument, deviceId, ref xmlNode);
if (xmlNode != null)
{
List<KeyValuePair<string, string>> sorting = this.GetSorting(xmlNode);
sorting.Sort(new Comparison<KeyValuePair<string, string>>(this.CompareByKey));
Dictionary<string, string> sortingDictionary = sorting.ToDictionary((KeyValuePair<string, string> keyItem) => keyItem.Key, (KeyValuePair<string, string> valueItem) => valueItem.Value);
using (Dictionary<string, string>.KeyCollection.Enumerator enumerator = sortingDictionary.Keys.GetEnumerator())
{
while (enumerator.MoveNext())
{
string key = enumerator.Current;
RenderingReference renderingReference = args.Renderings.Find((RenderingReference x) => x.UniqueId == key);
RenderingReference renderingReference2 = args.Renderings.Find((RenderingReference x) => x.UniqueId == sortingDictionary[key]);
if (renderingReference != null && renderingReference2 != null)
{
args.Renderings.Remove(renderingReference);
int index = args.Renderings.IndexOf(renderingReference2);
args.Renderings.Insert(index, renderingReference);
}
}
}
}
}
}

private int CompareByKey(KeyValuePair<string, string> x, KeyValuePair<string, string> y)
{
if (!(x.Key == y.Value))
{
return 0;
}
return 1;
}

protected virtual void GetDevice(XmlNode parentNode, string deviceId, ref XmlNode device)
{
if (parentNode.Name == "d")
{
device = parentNode;
return;
}
foreach (XmlNode parentNode2 in parentNode.ChildNodes)
{
this.GetDevice(parentNode2, deviceId, ref device);
}
}

protected virtual List<KeyValuePair<string, string>> GetSorting(XmlNode device)
{
List<KeyValuePair<string, string>> list = new List<KeyValuePair<string, string>>();
foreach (XmlNode xmlNode in device.ChildNodes)
{
if (xmlNode.Attributes != null)
{
string text = (xmlNode.Attributes["p:before"] != null) ? xmlNode.Attributes["p:before"].Value : null;
string text2 = (xmlNode.Attributes["uid"] != null) ? xmlNode.Attributes["uid"].Value : null;
if (!string.IsNullOrEmpty(text) && !string.IsNullOrEmpty(text2))
{
int num = text.IndexOf('{');
int num2 = text.IndexOf('}');
if (num > 0 && num2 > num)
{
text = text.Substring(num, num2 - num + 1);
list.Add(new KeyValuePair<string, string>(text2, text));
}
}
}
}
return list;
}

public override void Process(InsertRenderingsArgs args)
{
Assert.ArgumentNotNull(args, "args");
if (args.HasRenderings && Context.Database != Client.CoreDatabase)
{
Item contextItem = args.ContextItem;
if (contextItem != null)
{
this.Evaluate(args, contextItem);
}
}
}
}
}
6 changes: 6 additions & 0 deletions src/Sitecore.Support.95158/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
using System.Reflection;
using System.Runtime.InteropServices;

[assembly: AssemblyTitle("Sitecore.Support.95158")]
[assembly: AssemblyProduct("Sitecore.Support.95158")]
[assembly: ComVisible(false)]
90 changes: 90 additions & 0 deletions src/Sitecore.Support.95158/Sitecore.Support.95158.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.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>
<ProductVersion>
</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{1941A4FF-2693-4906-9F3C-120F6A2C83A2}</ProjectGuid>
<ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Sitecore.Support</RootNamespace>
<AssemblyName>Sitecore.Support.95158</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<UseIISExpress>true</UseIISExpress>
<IISExpressSSLPort />
<IISExpressAnonymousAuthentication />
<IISExpressWindowsAuthentication />
<IISExpressUseClassicPipelineMode />
<UseGlobalApplicationHostFile />
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\</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\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Sitecore.Kernel">
<HintPath>..\packages\SC.Sitecore.Kernel.7.2.5\lib\Sitecore.Kernel.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Drawing" />
<Reference Include="System.Web" />
<Reference Include="System.Xml" />
<Reference Include="System.Configuration" />
</ItemGroup>
<ItemGroup>
<Compile Include="Pipelines\InsertRenderings\Processors\EvaluateSorting.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="App_Config\Include\zzz\Sitecore.Support.95158.config" />
<Content Include="sitecore\shell\Applications\Page Modes\LayoutDefinition.js" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
<None Include="web.config" />
</ItemGroup>
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" Condition="false" />
<ProjectExtensions>
<VisualStudio>
<FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
<WebProjectProperties>
<UseIIS>True</UseIIS>
<AutoAssignPort>True</AutoAssignPort>
<DevelopmentServerPort>0</DevelopmentServerPort>
<DevelopmentServerVPath>/</DevelopmentServerVPath>
<IISUrl>http://localhost:49605/</IISUrl>
<NTLMAuthentication>False</NTLMAuthentication>
<UseCustomServer>False</UseCustomServer>
<CustomServerUrl>
</CustomServerUrl>
<SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
</WebProjectProperties>
</FlavorProperties>
</VisualStudio>
</ProjectExtensions>
</Project>
4 changes: 4 additions & 0 deletions src/Sitecore.Support.95158/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="SC.Sitecore.Kernel" version="7.2.5" targetFramework="net45" />
</packages>
Loading

0 comments on commit 7070fbf

Please sign in to comment.