Merge origin/dev-v8 into dev-v8-ExamineV2
This commit is contained in:
+5
-1
@@ -16,6 +16,10 @@ IF [%2] NEQ [] (SET comment=%2) ELSE (IF [%1] NEQ [] (SET "comment="))
|
||||
|
||||
SET version=%release%
|
||||
|
||||
REM SET MSBUILD="%windir%\Microsoft.NET\Framework\v4.0.30319\msbuild.exe"
|
||||
SET MSBUILD="C:\Program Files (x86)\MSBuild\14.0\Bin\MsBuild.exe"
|
||||
SET PATH=C:\Program Files (x86)\MSBuild\14.0\Bin;%PATH%
|
||||
|
||||
IF [%comment%] EQU [] (SET version=%release%) ELSE (SET version=%release%-%comment%)
|
||||
ECHO Building Umbraco %version%
|
||||
|
||||
@@ -35,7 +39,7 @@ DEL /F /Q webpihash.txt
|
||||
ECHO Making sure Git is in the path so that the build can succeed
|
||||
CALL InstallGit.cmd
|
||||
ECHO Performing MSBuild and producing Umbraco binaries zip files
|
||||
%windir%\Microsoft.NET\Framework\v4.0.30319\msbuild.exe "Build.proj" /p:BUILD_RELEASE=%release% /p:BUILD_COMMENT=%comment% /verbosity:minimal
|
||||
%MSBUILD% "Build.proj" /p:BUILD_RELEASE=%release% /p:BUILD_COMMENT=%comment% /verbosity:minimal
|
||||
|
||||
ECHO Setting node_modules folder to hidden to prevent VS13 from crashing on it while loading the websites project
|
||||
attrib +h ..\src\Umbraco.Web.UI.Client\node_modules
|
||||
|
||||
+346
-346
@@ -1,347 +1,347 @@
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
|
||||
<!--
|
||||
****************************************************
|
||||
INCLUDES
|
||||
*****************************************************
|
||||
-->
|
||||
|
||||
<PropertyGroup>
|
||||
<MSBuildCommunityTasksPath>..\MSBuildCommunityTasks</MSBuildCommunityTasksPath>
|
||||
<UmbracoMSBuildTasksPath>..\UmbracoMSBuildTasks</UmbracoMSBuildTasksPath>
|
||||
</PropertyGroup>
|
||||
|
||||
<Import Project="..\tools\UmbracoMSBuildTasks\Umbraco.MSBuild.Tasks.Targets" />
|
||||
<Import Project="..\tools\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets" />
|
||||
|
||||
<UsingTask TaskName="GenerateHash" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
|
||||
<ParameterGroup>
|
||||
<InputFiles ParameterType="Microsoft.Build.Framework.ITaskItem[]" Required="true" />
|
||||
<OutputFile ParameterType="System.String" Required="true" />
|
||||
</ParameterGroup>
|
||||
<Task>
|
||||
<Using Namespace="System.IO" />
|
||||
<Using Namespace="System.Linq" />
|
||||
<Using Namespace="System.Security.Cryptography" />
|
||||
<Code Type="Fragment" Language="cs">
|
||||
<![CDATA[
|
||||
using (var ms = new MemoryStream())
|
||||
{
|
||||
foreach (var item in InputFiles)
|
||||
{
|
||||
string path = item.ItemSpec;
|
||||
|
||||
using (FileStream stream = new FileStream(path, FileMode.Open))
|
||||
{
|
||||
using (var cryptoProvider = new SHA1CryptoServiceProvider())
|
||||
{
|
||||
|
||||
var fileHash = cryptoProvider.ComputeHash(stream);
|
||||
|
||||
using (TextWriter w = new StreamWriter(OutputFile, false))
|
||||
{
|
||||
w.WriteLine(string.Join("", fileHash.Select(b => b.ToString("x2"))));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</Code>
|
||||
</Task>
|
||||
</UsingTask>
|
||||
|
||||
|
||||
<!--
|
||||
****************************************************
|
||||
VARIABLES
|
||||
*****************************************************
|
||||
-->
|
||||
|
||||
<!-- NB: BUILD_NUMBER is passed in by the build server -->
|
||||
<PropertyGroup Condition="'$(BUILD_NUMBER)'!=''">
|
||||
<DECIMAL_BUILD_NUMBER>.$(BUILD_NUMBER)</DECIMAL_BUILD_NUMBER>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(BUILD_RELEASE)'!=''">
|
||||
<DECIMAL_BUILD_NUMBER>.$(BUILD_RELEASE)</DECIMAL_BUILD_NUMBER>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(BUILD_RELEASE)'!='' AND '$(BUILD_COMMENT)'!=''">
|
||||
<DECIMAL_BUILD_NUMBER>.$(BUILD_RELEASE)-$(BUILD_COMMENT)</DECIMAL_BUILD_NUMBER>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(BUILD_RELEASE)'!='' AND '$(BUILD_NIGHTLY)'!=''">
|
||||
<DECIMAL_BUILD_NUMBER>.$(BUILD_RELEASE)-$(BUILD_NIGHTLY)</DECIMAL_BUILD_NUMBER>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(BUILD_RELEASE)'!='' AND '$(BUILD_COMMENT)'!='' AND '$(BUILD_NIGHTLY)'!=''">
|
||||
<DECIMAL_BUILD_NUMBER>.$(BUILD_RELEASE)-$(BUILD_COMMENT)-$(BUILD_NIGHTLY)</DECIMAL_BUILD_NUMBER>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<BuildConfiguration>Release</BuildConfiguration>
|
||||
<BuildFolder>_BuildOutput\</BuildFolder>
|
||||
<BuildZipFileName>UmbracoCms$(DECIMAL_BUILD_NUMBER).zip</BuildZipFileName>
|
||||
<BuildZipFileNameBin>UmbracoCms.AllBinaries$(DECIMAL_BUILD_NUMBER).zip</BuildZipFileNameBin>
|
||||
<BuildZipFileNameWebPi>UmbracoCms.WebPI$(DECIMAL_BUILD_NUMBER).zip</BuildZipFileNameWebPi>
|
||||
<IncludeSymbols>False</IncludeSymbols>
|
||||
<BuildFolderRelativeToProjects>..\..\build\$(BuildFolder)</BuildFolderRelativeToProjects>
|
||||
<BuildFolderAbsolutePath>$(MSBuildProjectDirectory)\$(BuildFolder)</BuildFolderAbsolutePath>
|
||||
<SolutionBinFolder>$(BuildFolder)bin\</SolutionBinFolder>
|
||||
<WebAppFolder>$(BuildFolder)WebApp\</WebAppFolder>
|
||||
<WebPiFolder>$(BuildFolder)WebPi\</WebPiFolder>
|
||||
<ConfigsFolder>$(BuildFolder)Configs\</ConfigsFolder>
|
||||
<SolutionBinFolderRelativeToProjects>$(BuildFolderRelativeToProjects)bin\</SolutionBinFolderRelativeToProjects>
|
||||
<SolutionBinFolderAbsolutePath>$(BuildFolderAbsolutePath)bin\</SolutionBinFolderAbsolutePath>
|
||||
<WebAppFolderRelativeToProjects>$(BuildFolderRelativeToProjects)WebApp\</WebAppFolderRelativeToProjects>
|
||||
<WebAppFolderAbsolutePath>$(BuildFolderAbsolutePath)WebApp\</WebAppFolderAbsolutePath>
|
||||
<WebPiFolderRelativeToProjects>$(BuildFolderRelativeToProjects)WebPi\</WebPiFolderRelativeToProjects>
|
||||
<WebPiFolderAbsolutePath>$(BuildFolderAbsolutePath)WebPi\</WebPiFolderAbsolutePath>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<SystemFolders Include="$(WebAppFolder)App_Data" />
|
||||
<SystemFolders Include="$(WebAppFolder)Media" />
|
||||
<SystemFolders Include="$(WebAppFolder)Views" />
|
||||
</ItemGroup>
|
||||
|
||||
<!--
|
||||
****************************************************
|
||||
TARGETS
|
||||
*****************************************************
|
||||
-->
|
||||
|
||||
<Target Name="Build" DependsOnTargets="GenerateWebPiHash">
|
||||
<Message Text="Build finished" />
|
||||
</Target>
|
||||
|
||||
<Target Name="GenerateWebPiHash" DependsOnTargets="ZipWebPiApp">
|
||||
<ItemGroup>
|
||||
<WebPiFile Include="$(BuildZipFileNameWebPi)" />
|
||||
</ItemGroup>
|
||||
<Message Text="Calculating hash for $(BuildZipFileNameWebPi)" />
|
||||
<GenerateHash InputFiles="@(WebPiFile)" OutputFile="webpihash.txt" />
|
||||
</Target>
|
||||
|
||||
<Target Name="CleanUp" DependsOnTargets="ZipWebPiApp">
|
||||
<Message Text="Deleting $(BuildFolder)" Importance="high" />
|
||||
<RemoveDir Directories="$(BuildFolder)" />
|
||||
<Message Text="Finished deleting $(BuildFolder)" Importance="high" />
|
||||
</Target>
|
||||
|
||||
<Target Name="ZipWebPiApp" DependsOnTargets="ZipWebApp" >
|
||||
<!-- Clean folders -->
|
||||
<RemoveDir Directories="$(WebPiFolder)" />
|
||||
<MakeDir Directories="$(WebPiFolder)" />
|
||||
<MakeDir Directories="$(WebPiFolder)umbraco" />
|
||||
|
||||
<!-- Copy fresh built umbraco files -->
|
||||
<Exec Command="xcopy %22$(WebAppFolderAbsolutePath)*%22 %22$(WebPiFolderAbsolutePath)umbraco%22 /S /E /Y /I" />
|
||||
|
||||
<!-- Copy Web Pi template files -->
|
||||
<ItemGroup>
|
||||
<WebPiFiles Include="..\src\WebPi\**\*.*" />
|
||||
</ItemGroup>
|
||||
|
||||
<Copy SourceFiles="@(WebPiFiles)"
|
||||
DestinationFiles="@(WebPiFiles->'$(WebPiFolder)%(RecursiveDir)%(Filename)%(Extension)')" />
|
||||
|
||||
<!-- Zip the files -->
|
||||
<Exec Command="..\tools\7zip\7za.exe a -r %22$(BuildZipFileNameWebPi)%22 %22$(WebPiFolderAbsolutePath)*%22 -x!dotLess.Core.dll -x![Content_Types].xml >NUL" />
|
||||
</Target>
|
||||
|
||||
<Target Name="ZipWebApp" DependsOnTargets="CreateSystemFolders" >
|
||||
<Message Text="Starting to zip to $(buildDate)-$(BuildZipFileName)" Importance="high" />
|
||||
|
||||
<Exec Command="..\tools\7zip\7za.exe a -r %22$(BuildZipFileNameBin)%22 %22$(SolutionBinFolderAbsolutePath)*%22 -x!dotLess.Core.dll >NUL" />
|
||||
<Exec Command="..\tools\7zip\7za.exe a -r %22$(BuildZipFileName)%22 %22$(WebAppFolderAbsolutePath)*%22 -x!dotLess.Core.dll -x![Content_Types].xml >NUL" />
|
||||
|
||||
<Message Text="Finished zipping to build\$(BuildFolder)\$(buildDate)-$(BuildZipFileName)" Importance="high" />
|
||||
</Target>
|
||||
|
||||
<Target Name="CreateSystemFolders" DependsOnTargets="CopyBelleBuild" Inputs="@(SystemFolders)" Outputs="%(Identity).Dummy">
|
||||
<MakeDir Directories="@(SystemFolders)" />
|
||||
</Target>
|
||||
|
||||
<Target Name="CopyBelleBuild" DependsOnTargets="CopyLibraries" >
|
||||
<ItemGroup>
|
||||
<BelleFiles Include="..\src\Umbraco.Web.UI.Client\build\belle\**\*.*" Exclude="..\src\Umbraco.Web.UI.Client\build\belle\index.html" />
|
||||
</ItemGroup>
|
||||
|
||||
<Copy SourceFiles="@(BelleFiles)"
|
||||
DestinationFiles="@(BelleFiles->'$(WebAppFolder)umbraco\%(RecursiveDir)%(Filename)%(Extension)')"
|
||||
OverwriteReadOnlyFiles="true"
|
||||
SkipUnchangedFiles="false" />
|
||||
</Target>
|
||||
|
||||
<Target Name="CopyLibraries" DependsOnTargets="OffsetTimestamps" >
|
||||
<!-- Copy SQL CE -->
|
||||
<ItemGroup>
|
||||
<SQLCE4Files
|
||||
Include="..\src\packages\SqlServerCE.4.0.0.1\**\*.*"
|
||||
Exclude="..\src\packages\SqlServerCE.4.0.0.1\lib\**\*;..\src\packages\SqlServerCE.4.0.0.1\**\*.nu*"
|
||||
/>
|
||||
</ItemGroup>
|
||||
|
||||
<Copy SourceFiles="@(SQLCE4Files)"
|
||||
DestinationFiles="@(SQLCE4Files->'$(SolutionBinFolder)%(RecursiveDir)%(Filename)%(Extension)')"
|
||||
OverwriteReadOnlyFiles="true"
|
||||
SkipUnchangedFiles="false" />
|
||||
|
||||
<Copy SourceFiles="@(SQLCE4Files)"
|
||||
DestinationFiles="@(SQLCE4Files->'$(WebAppFolder)bin\%(RecursiveDir)%(Filename)%(Extension)')"
|
||||
OverwriteReadOnlyFiles="true"
|
||||
SkipUnchangedFiles="false" />
|
||||
|
||||
</Target>
|
||||
|
||||
<!-- Offset the modified timestamps on all umbraco dlls, as WebResources break if date is in the future, which, due to timezone offsets can happen. -->
|
||||
<Target Name="OffsetTimestamps" DependsOnTargets="CopyTransformedWebConfig">
|
||||
<CreateItem Include="$(BuildFolder)**\umbraco.*.dll">
|
||||
<Output TaskParameter="Include" ItemName="FilesToOffsetTimestamp" />
|
||||
</CreateItem>
|
||||
<Message Text="Starting to offset timestamps" Importance="high" />
|
||||
<Umbraco.MSBuild.Tasks.TimestampOffset Files="@(FilesToOffsetTimestamp)" Offset="-11" />
|
||||
<Message Text="Finished offsetting timestamps" Importance="high" />
|
||||
</Target>
|
||||
|
||||
<!-- Copy the transformed web.config file to the root -->
|
||||
<Target Name="CopyTransformedWebConfig" DependsOnTargets="CopyTransformedConfig">
|
||||
<ItemGroup>
|
||||
<WebConfigFile Include="..\src\Umbraco.Web.UI\web.$(BuildConfiguration).Config.transformed" />
|
||||
</ItemGroup>
|
||||
|
||||
<Copy SourceFiles="@(WebConfigFile)"
|
||||
DestinationFiles="$(WebAppFolder)Web.config"
|
||||
OverwriteReadOnlyFiles="true"
|
||||
SkipUnchangedFiles="false" />
|
||||
</Target>
|
||||
|
||||
<!-- Copy the config files and rename them to *.config.transform -->
|
||||
<Target Name="CopyTransformedConfig" DependsOnTargets="CopyXmlDocumentation">
|
||||
<ItemGroup>
|
||||
<ConfigFiles Include="$(WebAppFolder)config\*.config;$(WebAppFolder)config\*.js" />
|
||||
<CustomLanguageFiles Include="$(WebAppFolder)config\lang\*.xml" />
|
||||
<WebConfigTransformFile Include="$(WebAppFolder)Web.config" />
|
||||
</ItemGroup>
|
||||
|
||||
<Copy SourceFiles="@(ConfigFiles)"
|
||||
DestinationFiles="@(ConfigFiles->'$(ConfigsFolder)\%(RecursiveDir)%(Filename)%(Extension)')"
|
||||
OverwriteReadOnlyFiles="true"
|
||||
SkipUnchangedFiles="false" />
|
||||
|
||||
<Copy SourceFiles="@(CustomLanguageFiles)"
|
||||
DestinationFiles="@(CustomLanguageFiles->'$(ConfigsFolder)Lang\%(RecursiveDir)%(Filename)%(Extension)')"
|
||||
OverwriteReadOnlyFiles="true"
|
||||
SkipUnchangedFiles="false" />
|
||||
|
||||
<Copy SourceFiles="@(WebConfigTransformFile)"
|
||||
DestinationFiles="$(ConfigsFolder)Web.config.transform"
|
||||
OverwriteReadOnlyFiles="true"
|
||||
SkipUnchangedFiles="false" />
|
||||
</Target>
|
||||
|
||||
<!-- Copy the xml documentation to the bin folder -->
|
||||
<Target Name="CopyXmlDocumentation" DependsOnTargets="CleanupPresentation">
|
||||
<ItemGroup>
|
||||
<XmlDocumentationFiles Include="$(SolutionBinFolder)*.xml" />
|
||||
</ItemGroup>
|
||||
|
||||
<Copy SourceFiles="@(XmlDocumentationFiles)"
|
||||
DestinationFiles="@(XmlDocumentationFiles->'$(WebAppFolder)bin\%(RecursiveDir)%(Filename)%(Extension)')"
|
||||
OverwriteReadOnlyFiles="true"
|
||||
SkipUnchangedFiles="false" />
|
||||
<Message Text="CopyXmlDocumentation" />
|
||||
</Target>
|
||||
|
||||
<!-- Unlike 2010, the VS2012 build targets file doesn't clean up the umbraco.presentation dir, do it manually -->
|
||||
<Target Name="CleanupPresentation" DependsOnTargets="CompileProjects">
|
||||
<ItemGroup>
|
||||
<PresentationFolderToDelete Include="$(WebAppFolder)umbraco.presentation" />
|
||||
</ItemGroup>
|
||||
<RemoveDir Directories="@(PresentationFolderToDelete)" />
|
||||
</Target>
|
||||
|
||||
<Target Name="CompileProjects" DependsOnTargets="SetVersionNumber">
|
||||
|
||||
<Message Text="Compiling web project to build\$(BuildFolder)" Importance="high" />
|
||||
<!-- For UseWPP_CopyWebApplication=True see http://stackoverflow.com/questions/1983575/copywebapplication-with-web-config-transformations -->
|
||||
<!-- Build the Umbraco.Web.UI project -->
|
||||
<MSBuild Projects="..\src\Umbraco.Web.UI\Umbraco.Web.UI.csproj" Properties="WarningLevel=0;Configuration=$(BuildConfiguration);UseWPP_CopyWebApplication=True;PipelineDependsOnBuild=False;OutDir=$(SolutionBinFolderAbsolutePath);WebProjectOutputDir=$(WebAppFolderAbsolutePath);Verbosity=minimal" Targets="Clean;Rebuild;" BuildInParallel="False" ToolsVersion="4.0" UnloadProjectsOnCompletion="False">
|
||||
</MSBuild>
|
||||
|
||||
<!-- DONE -->
|
||||
<Message Text="Finished compiling projects" Importance="high" />
|
||||
</Target>
|
||||
|
||||
|
||||
<Target Name="SetVersionNumber" Condition="'$(BUILD_RELEASE)'!=''">
|
||||
<PropertyGroup>
|
||||
<NewVersion>$(BUILD_RELEASE)</NewVersion>
|
||||
<NewVersion Condition="'$(BUILD_COMMENT)'!=''">$(BUILD_RELEASE)-$(BUILD_COMMENT)</NewVersion>
|
||||
<NewVersion Condition="'$(BUILD_NIGHTLY)'!=''">$(BUILD_RELEASE)-$(BUILD_NIGHTLY)</NewVersion>
|
||||
<NewVersion Condition="'$(BUILD_COMMENT)'!='' And '$(BUILD_NIGHTLY)'!=''">$(BUILD_RELEASE)-$(BUILD_COMMENT)-$(BUILD_NIGHTLY)</NewVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<!-- Match & replace 3 and 4 digit version numbers and -beta and +nightly (if they're there) -->
|
||||
<FileUpdate
|
||||
Files="..\src\Umbraco.Core\Configuration\UmbracoVersion.cs"
|
||||
Regex="(\d+)\.(\d+)\.(\d+)(.(\d+))?"
|
||||
ReplacementText="$(BUILD_RELEASE)"/>
|
||||
|
||||
<FileUpdate Files="..\src\Umbraco.Core\Configuration\UmbracoVersion.cs"
|
||||
Regex="CurrentComment { get { return "(.+)?""
|
||||
ReplacementText="CurrentComment { get { return "$(BUILD_COMMENT)""/>
|
||||
|
||||
<FileUpdate Files="..\src\Umbraco.Core\Configuration\UmbracoVersion.cs"
|
||||
Condition="'$(BUILD_NIGHTLY)'!=''"
|
||||
Regex="CurrentComment { get { return "(.+)?""
|
||||
ReplacementText="CurrentComment { get { return "$(BUILD_NIGHTLY)""/>
|
||||
|
||||
<FileUpdate Files="..\src\Umbraco.Core\Configuration\UmbracoVersion.cs"
|
||||
Condition="'$(BUILD_COMMENT)'!='' AND '$(BUILD_NIGHTLY)'!=''"
|
||||
Regex="CurrentComment { get { return "(.+)?""
|
||||
ReplacementText="CurrentComment { get { return "$(BUILD_COMMENT)-$(BUILD_NIGHTLY)""/>
|
||||
|
||||
<!--This updates the AssemblyFileVersion for the solution to the umbraco version-->
|
||||
<FileUpdate
|
||||
Files="..\src\SolutionInfo.cs"
|
||||
Regex="AssemblyFileVersion\("(.+)?"\)"
|
||||
ReplacementText="AssemblyFileVersion("$(BUILD_RELEASE)")"/>
|
||||
|
||||
<!--This updates the AssemblyInformationalVersion for the solution to the umbraco version and comment-->
|
||||
<FileUpdate
|
||||
Condition="'$(BUILD_COMMENT)'!=''"
|
||||
Files="..\src\SolutionInfo.cs"
|
||||
Regex="AssemblyInformationalVersion\("(.+)?"\)"
|
||||
ReplacementText="AssemblyInformationalVersion("$(BUILD_RELEASE)-$(BUILD_COMMENT)")"/>
|
||||
<FileUpdate
|
||||
Condition="'$(BUILD_COMMENT)'==''"
|
||||
Files="..\src\SolutionInfo.cs"
|
||||
Regex="AssemblyInformationalVersion\("(.+)?"\)"
|
||||
ReplacementText="AssemblyInformationalVersion("$(BUILD_RELEASE)")"/>
|
||||
<FileUpdate
|
||||
Condition="'$(BUILD_NIGHTLY)'!=''"
|
||||
Files="..\src\SolutionInfo.cs"
|
||||
Regex="AssemblyInformationalVersion\("(.+)?"\)"
|
||||
ReplacementText="AssemblyInformationalVersion("$(BUILD_RELEASE)-$(BUILD_NIGHTLY)")"/>
|
||||
<FileUpdate
|
||||
Condition="'$(BUILD_COMMENT)'!='' AND '$(BUILD_NIGHTLY)'!=''"
|
||||
Files="..\src\SolutionInfo.cs"
|
||||
Regex="AssemblyInformationalVersion\("(.+)?"\)"
|
||||
ReplacementText="AssemblyInformationalVersion("$(BUILD_RELEASE)-$(BUILD_COMMENT)-$(BUILD_NIGHTLY)")"/>
|
||||
<FileUpdate
|
||||
Condition="'$(BUILD_COMMENT)'=='' AND '$(BUILD_NIGHTLY)'==''"
|
||||
Files="..\src\SolutionInfo.cs"
|
||||
Regex="AssemblyInformationalVersion\("(.+)?"\)"
|
||||
ReplacementText="AssemblyInformationalVersion("$(BUILD_RELEASE)")"/>
|
||||
|
||||
<!--This updates the copyright year-->
|
||||
<FileUpdate
|
||||
Files="..\src\SolutionInfo.cs"
|
||||
Regex="AssemblyCopyright\("Copyright © Umbraco (\d{4})"\)"
|
||||
ReplacementText="AssemblyCopyright("Copyright © Umbraco $([System.DateTime]::Now.ToString(`yyyy`))")"/>
|
||||
|
||||
<XmlPoke XmlInputPath=".\NuSpecs\build\UmbracoCms.props"
|
||||
Namespaces="<Namespace Prefix='x' Uri='http://schemas.microsoft.com/developer/msbuild/2003' />"
|
||||
Query="//x:UmbracoVersion"
|
||||
Value="$(NewVersion)" />
|
||||
</Target>
|
||||
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
|
||||
<!--
|
||||
****************************************************
|
||||
INCLUDES
|
||||
*****************************************************
|
||||
-->
|
||||
|
||||
<PropertyGroup>
|
||||
<MSBuildCommunityTasksPath>..\MSBuildCommunityTasks</MSBuildCommunityTasksPath>
|
||||
<UmbracoMSBuildTasksPath>..\UmbracoMSBuildTasks</UmbracoMSBuildTasksPath>
|
||||
</PropertyGroup>
|
||||
|
||||
<Import Project="..\tools\UmbracoMSBuildTasks\Umbraco.MSBuild.Tasks.Targets" />
|
||||
<Import Project="..\tools\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets" />
|
||||
|
||||
<UsingTask TaskName="GenerateHash" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
|
||||
<ParameterGroup>
|
||||
<InputFiles ParameterType="Microsoft.Build.Framework.ITaskItem[]" Required="true" />
|
||||
<OutputFile ParameterType="System.String" Required="true" />
|
||||
</ParameterGroup>
|
||||
<Task>
|
||||
<Using Namespace="System.IO" />
|
||||
<Using Namespace="System.Linq" />
|
||||
<Using Namespace="System.Security.Cryptography" />
|
||||
<Code Type="Fragment" Language="cs">
|
||||
<![CDATA[
|
||||
using (var ms = new MemoryStream())
|
||||
{
|
||||
foreach (var item in InputFiles)
|
||||
{
|
||||
string path = item.ItemSpec;
|
||||
|
||||
using (FileStream stream = new FileStream(path, FileMode.Open))
|
||||
{
|
||||
using (var cryptoProvider = new SHA1CryptoServiceProvider())
|
||||
{
|
||||
|
||||
var fileHash = cryptoProvider.ComputeHash(stream);
|
||||
|
||||
using (TextWriter w = new StreamWriter(OutputFile, false))
|
||||
{
|
||||
w.WriteLine(string.Join("", fileHash.Select(b => b.ToString("x2"))));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</Code>
|
||||
</Task>
|
||||
</UsingTask>
|
||||
|
||||
|
||||
<!--
|
||||
****************************************************
|
||||
VARIABLES
|
||||
*****************************************************
|
||||
-->
|
||||
|
||||
<!-- NB: BUILD_NUMBER is passed in by the build server -->
|
||||
<PropertyGroup Condition="'$(BUILD_NUMBER)'!=''">
|
||||
<DECIMAL_BUILD_NUMBER>.$(BUILD_NUMBER)</DECIMAL_BUILD_NUMBER>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(BUILD_RELEASE)'!=''">
|
||||
<DECIMAL_BUILD_NUMBER>.$(BUILD_RELEASE)</DECIMAL_BUILD_NUMBER>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(BUILD_RELEASE)'!='' AND '$(BUILD_COMMENT)'!=''">
|
||||
<DECIMAL_BUILD_NUMBER>.$(BUILD_RELEASE)-$(BUILD_COMMENT)</DECIMAL_BUILD_NUMBER>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(BUILD_RELEASE)'!='' AND '$(BUILD_NIGHTLY)'!=''">
|
||||
<DECIMAL_BUILD_NUMBER>.$(BUILD_RELEASE)-$(BUILD_NIGHTLY)</DECIMAL_BUILD_NUMBER>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(BUILD_RELEASE)'!='' AND '$(BUILD_COMMENT)'!='' AND '$(BUILD_NIGHTLY)'!=''">
|
||||
<DECIMAL_BUILD_NUMBER>.$(BUILD_RELEASE)-$(BUILD_COMMENT)-$(BUILD_NIGHTLY)</DECIMAL_BUILD_NUMBER>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<BuildConfiguration>Release</BuildConfiguration>
|
||||
<BuildFolder>_BuildOutput\</BuildFolder>
|
||||
<BuildZipFileName>UmbracoCms$(DECIMAL_BUILD_NUMBER).zip</BuildZipFileName>
|
||||
<BuildZipFileNameBin>UmbracoCms.AllBinaries$(DECIMAL_BUILD_NUMBER).zip</BuildZipFileNameBin>
|
||||
<BuildZipFileNameWebPi>UmbracoCms.WebPI$(DECIMAL_BUILD_NUMBER).zip</BuildZipFileNameWebPi>
|
||||
<IncludeSymbols>False</IncludeSymbols>
|
||||
<BuildFolderRelativeToProjects>..\..\build\$(BuildFolder)</BuildFolderRelativeToProjects>
|
||||
<BuildFolderAbsolutePath>$(MSBuildProjectDirectory)\$(BuildFolder)</BuildFolderAbsolutePath>
|
||||
<SolutionBinFolder>$(BuildFolder)bin\</SolutionBinFolder>
|
||||
<WebAppFolder>$(BuildFolder)WebApp\</WebAppFolder>
|
||||
<WebPiFolder>$(BuildFolder)WebPi\</WebPiFolder>
|
||||
<ConfigsFolder>$(BuildFolder)Configs\</ConfigsFolder>
|
||||
<SolutionBinFolderRelativeToProjects>$(BuildFolderRelativeToProjects)bin\</SolutionBinFolderRelativeToProjects>
|
||||
<SolutionBinFolderAbsolutePath>$(BuildFolderAbsolutePath)bin\</SolutionBinFolderAbsolutePath>
|
||||
<WebAppFolderRelativeToProjects>$(BuildFolderRelativeToProjects)WebApp\</WebAppFolderRelativeToProjects>
|
||||
<WebAppFolderAbsolutePath>$(BuildFolderAbsolutePath)WebApp\</WebAppFolderAbsolutePath>
|
||||
<WebPiFolderRelativeToProjects>$(BuildFolderRelativeToProjects)WebPi\</WebPiFolderRelativeToProjects>
|
||||
<WebPiFolderAbsolutePath>$(BuildFolderAbsolutePath)WebPi\</WebPiFolderAbsolutePath>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<SystemFolders Include="$(WebAppFolder)App_Data" />
|
||||
<SystemFolders Include="$(WebAppFolder)Media" />
|
||||
<SystemFolders Include="$(WebAppFolder)Views" />
|
||||
</ItemGroup>
|
||||
|
||||
<!--
|
||||
****************************************************
|
||||
TARGETS
|
||||
*****************************************************
|
||||
-->
|
||||
|
||||
<Target Name="Build" DependsOnTargets="GenerateWebPiHash">
|
||||
<Message Text="Build finished" />
|
||||
</Target>
|
||||
|
||||
<Target Name="GenerateWebPiHash" DependsOnTargets="ZipWebPiApp">
|
||||
<ItemGroup>
|
||||
<WebPiFile Include="$(BuildZipFileNameWebPi)" />
|
||||
</ItemGroup>
|
||||
<Message Text="Calculating hash for $(BuildZipFileNameWebPi)" />
|
||||
<GenerateHash InputFiles="@(WebPiFile)" OutputFile="webpihash.txt" />
|
||||
</Target>
|
||||
|
||||
<Target Name="CleanUp" DependsOnTargets="ZipWebPiApp">
|
||||
<Message Text="Deleting $(BuildFolder)" Importance="high" />
|
||||
<RemoveDir Directories="$(BuildFolder)" />
|
||||
<Message Text="Finished deleting $(BuildFolder)" Importance="high" />
|
||||
</Target>
|
||||
|
||||
<Target Name="ZipWebPiApp" DependsOnTargets="ZipWebApp" >
|
||||
<!-- Clean folders -->
|
||||
<RemoveDir Directories="$(WebPiFolder)" />
|
||||
<MakeDir Directories="$(WebPiFolder)" />
|
||||
<MakeDir Directories="$(WebPiFolder)umbraco" />
|
||||
|
||||
<!-- Copy fresh built umbraco files -->
|
||||
<Exec Command="xcopy %22$(WebAppFolderAbsolutePath)*%22 %22$(WebPiFolderAbsolutePath)umbraco%22 /S /E /Y /I" />
|
||||
|
||||
<!-- Copy Web Pi template files -->
|
||||
<ItemGroup>
|
||||
<WebPiFiles Include="..\src\WebPi\**\*.*" />
|
||||
</ItemGroup>
|
||||
|
||||
<Copy SourceFiles="@(WebPiFiles)"
|
||||
DestinationFiles="@(WebPiFiles->'$(WebPiFolder)%(RecursiveDir)%(Filename)%(Extension)')" />
|
||||
|
||||
<!-- Zip the files -->
|
||||
<Exec Command="..\tools\7zip\7za.exe a -r %22$(BuildZipFileNameWebPi)%22 %22$(WebPiFolderAbsolutePath)*%22 -x!dotLess.Core.dll -x![Content_Types].xml >NUL" />
|
||||
</Target>
|
||||
|
||||
<Target Name="ZipWebApp" DependsOnTargets="CreateSystemFolders" >
|
||||
<Message Text="Starting to zip to $(buildDate)-$(BuildZipFileName)" Importance="high" />
|
||||
|
||||
<Exec Command="..\tools\7zip\7za.exe a -r %22$(BuildZipFileNameBin)%22 %22$(SolutionBinFolderAbsolutePath)*%22 -x!dotLess.Core.dll >NUL" />
|
||||
<Exec Command="..\tools\7zip\7za.exe a -r %22$(BuildZipFileName)%22 %22$(WebAppFolderAbsolutePath)*%22 -x!dotLess.Core.dll -x![Content_Types].xml >NUL" />
|
||||
|
||||
<Message Text="Finished zipping to build\$(BuildFolder)\$(buildDate)-$(BuildZipFileName)" Importance="high" />
|
||||
</Target>
|
||||
|
||||
<Target Name="CreateSystemFolders" DependsOnTargets="CopyBelleBuild" Inputs="@(SystemFolders)" Outputs="%(Identity).Dummy">
|
||||
<MakeDir Directories="@(SystemFolders)" />
|
||||
</Target>
|
||||
|
||||
<Target Name="CopyBelleBuild" DependsOnTargets="CopyLibraries" >
|
||||
<ItemGroup>
|
||||
<BelleFiles Include="..\src\Umbraco.Web.UI.Client\build\belle\**\*.*" Exclude="..\src\Umbraco.Web.UI.Client\build\belle\index.html" />
|
||||
</ItemGroup>
|
||||
|
||||
<Copy SourceFiles="@(BelleFiles)"
|
||||
DestinationFiles="@(BelleFiles->'$(WebAppFolder)umbraco\%(RecursiveDir)%(Filename)%(Extension)')"
|
||||
OverwriteReadOnlyFiles="true"
|
||||
SkipUnchangedFiles="false" />
|
||||
</Target>
|
||||
|
||||
<Target Name="CopyLibraries" DependsOnTargets="OffsetTimestamps" >
|
||||
<!-- Copy SQL CE -->
|
||||
<ItemGroup>
|
||||
<SQLCE4Files
|
||||
Include="..\src\packages\SqlServerCE.4.0.0.1\**\*.*"
|
||||
Exclude="..\src\packages\SqlServerCE.4.0.0.1\lib\**\*;..\src\packages\SqlServerCE.4.0.0.1\**\*.nu*"
|
||||
/>
|
||||
</ItemGroup>
|
||||
|
||||
<Copy SourceFiles="@(SQLCE4Files)"
|
||||
DestinationFiles="@(SQLCE4Files->'$(SolutionBinFolder)%(RecursiveDir)%(Filename)%(Extension)')"
|
||||
OverwriteReadOnlyFiles="true"
|
||||
SkipUnchangedFiles="false" />
|
||||
|
||||
<Copy SourceFiles="@(SQLCE4Files)"
|
||||
DestinationFiles="@(SQLCE4Files->'$(WebAppFolder)bin\%(RecursiveDir)%(Filename)%(Extension)')"
|
||||
OverwriteReadOnlyFiles="true"
|
||||
SkipUnchangedFiles="false" />
|
||||
|
||||
</Target>
|
||||
|
||||
<!-- Offset the modified timestamps on all umbraco dlls, as WebResources break if date is in the future, which, due to timezone offsets can happen. -->
|
||||
<Target Name="OffsetTimestamps" DependsOnTargets="CopyTransformedWebConfig">
|
||||
<CreateItem Include="$(BuildFolder)**\umbraco.*.dll">
|
||||
<Output TaskParameter="Include" ItemName="FilesToOffsetTimestamp" />
|
||||
</CreateItem>
|
||||
<Message Text="Starting to offset timestamps" Importance="high" />
|
||||
<Umbraco.MSBuild.Tasks.TimestampOffset Files="@(FilesToOffsetTimestamp)" Offset="-11" />
|
||||
<Message Text="Finished offsetting timestamps" Importance="high" />
|
||||
</Target>
|
||||
|
||||
<!-- Copy the transformed web.config file to the root -->
|
||||
<Target Name="CopyTransformedWebConfig" DependsOnTargets="CopyTransformedConfig">
|
||||
<ItemGroup>
|
||||
<WebConfigFile Include="..\src\Umbraco.Web.UI\web.$(BuildConfiguration).Config.transformed" />
|
||||
</ItemGroup>
|
||||
|
||||
<Copy SourceFiles="@(WebConfigFile)"
|
||||
DestinationFiles="$(WebAppFolder)Web.config"
|
||||
OverwriteReadOnlyFiles="true"
|
||||
SkipUnchangedFiles="false" />
|
||||
</Target>
|
||||
|
||||
<!-- Copy the config files and rename them to *.config.transform -->
|
||||
<Target Name="CopyTransformedConfig" DependsOnTargets="CopyXmlDocumentation">
|
||||
<ItemGroup>
|
||||
<ConfigFiles Include="$(WebAppFolder)config\*.config;$(WebAppFolder)config\*.js" />
|
||||
<CustomLanguageFiles Include="$(WebAppFolder)config\lang\*.xml" />
|
||||
<WebConfigTransformFile Include="$(WebAppFolder)Web.config" />
|
||||
</ItemGroup>
|
||||
|
||||
<Copy SourceFiles="@(ConfigFiles)"
|
||||
DestinationFiles="@(ConfigFiles->'$(ConfigsFolder)\%(RecursiveDir)%(Filename)%(Extension)')"
|
||||
OverwriteReadOnlyFiles="true"
|
||||
SkipUnchangedFiles="false" />
|
||||
|
||||
<Copy SourceFiles="@(CustomLanguageFiles)"
|
||||
DestinationFiles="@(CustomLanguageFiles->'$(ConfigsFolder)Lang\%(RecursiveDir)%(Filename)%(Extension)')"
|
||||
OverwriteReadOnlyFiles="true"
|
||||
SkipUnchangedFiles="false" />
|
||||
|
||||
<Copy SourceFiles="@(WebConfigTransformFile)"
|
||||
DestinationFiles="$(ConfigsFolder)Web.config.transform"
|
||||
OverwriteReadOnlyFiles="true"
|
||||
SkipUnchangedFiles="false" />
|
||||
</Target>
|
||||
|
||||
<!-- Copy the xml documentation to the bin folder -->
|
||||
<Target Name="CopyXmlDocumentation" DependsOnTargets="CleanupPresentation">
|
||||
<ItemGroup>
|
||||
<XmlDocumentationFiles Include="$(SolutionBinFolder)*.xml" />
|
||||
</ItemGroup>
|
||||
|
||||
<Copy SourceFiles="@(XmlDocumentationFiles)"
|
||||
DestinationFiles="@(XmlDocumentationFiles->'$(WebAppFolder)bin\%(RecursiveDir)%(Filename)%(Extension)')"
|
||||
OverwriteReadOnlyFiles="true"
|
||||
SkipUnchangedFiles="false" />
|
||||
<Message Text="CopyXmlDocumentation" />
|
||||
</Target>
|
||||
|
||||
<!-- Unlike 2010, the VS2012 build targets file doesn't clean up the umbraco.presentation dir, do it manually -->
|
||||
<Target Name="CleanupPresentation" DependsOnTargets="CompileProjects">
|
||||
<ItemGroup>
|
||||
<PresentationFolderToDelete Include="$(WebAppFolder)umbraco.presentation" />
|
||||
</ItemGroup>
|
||||
<RemoveDir Directories="@(PresentationFolderToDelete)" />
|
||||
</Target>
|
||||
|
||||
<Target Name="CompileProjects" DependsOnTargets="SetVersionNumber">
|
||||
|
||||
<Message Text="Compiling web project to build\$(BuildFolder)" Importance="high" />
|
||||
<!-- For UseWPP_CopyWebApplication=True see http://stackoverflow.com/questions/1983575/copywebapplication-with-web-config-transformations -->
|
||||
<!-- Build the Umbraco.Web.UI project -->
|
||||
<MSBuild Projects="..\src\Umbraco.Web.UI\Umbraco.Web.UI.csproj" Properties="WarningLevel=0;Configuration=$(BuildConfiguration);UseWPP_CopyWebApplication=True;PipelineDependsOnBuild=False;OutDir=$(SolutionBinFolderAbsolutePath);WebProjectOutputDir=$(WebAppFolderAbsolutePath);Verbosity=minimal" Targets="Clean;Rebuild;" BuildInParallel="False" ToolsVersion="14.0" UnloadProjectsOnCompletion="False">
|
||||
</MSBuild>
|
||||
|
||||
<!-- DONE -->
|
||||
<Message Text="Finished compiling projects" Importance="high" />
|
||||
</Target>
|
||||
|
||||
|
||||
<Target Name="SetVersionNumber" Condition="'$(BUILD_RELEASE)'!=''">
|
||||
<PropertyGroup>
|
||||
<NewVersion>$(BUILD_RELEASE)</NewVersion>
|
||||
<NewVersion Condition="'$(BUILD_COMMENT)'!=''">$(BUILD_RELEASE)-$(BUILD_COMMENT)</NewVersion>
|
||||
<NewVersion Condition="'$(BUILD_NIGHTLY)'!=''">$(BUILD_RELEASE)-$(BUILD_NIGHTLY)</NewVersion>
|
||||
<NewVersion Condition="'$(BUILD_COMMENT)'!='' And '$(BUILD_NIGHTLY)'!=''">$(BUILD_RELEASE)-$(BUILD_COMMENT)-$(BUILD_NIGHTLY)</NewVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<!-- Match & replace 3 and 4 digit version numbers and -beta and +nightly (if they're there) -->
|
||||
<FileUpdate
|
||||
Files="..\src\Umbraco.Core\Configuration\UmbracoVersion.cs"
|
||||
Regex="(\d+)\.(\d+)\.(\d+)(.(\d+))?"
|
||||
ReplacementText="$(BUILD_RELEASE)"/>
|
||||
|
||||
<FileUpdate Files="..\src\Umbraco.Core\Configuration\UmbracoVersion.cs"
|
||||
Regex="CurrentComment => "(.+)?""
|
||||
ReplacementText="CurrentComment => "$(BUILD_COMMENT)""/>
|
||||
|
||||
<FileUpdate Files="..\src\Umbraco.Core\Configuration\UmbracoVersion.cs"
|
||||
Condition="'$(BUILD_NIGHTLY)'!=''"
|
||||
Regex="CurrentComment => "(.+)?""
|
||||
ReplacementText="CurrentComment => "$(BUILD_NIGHTLY)""/>
|
||||
|
||||
<FileUpdate Files="..\src\Umbraco.Core\Configuration\UmbracoVersion.cs"
|
||||
Condition="'$(BUILD_COMMENT)'!='' AND '$(BUILD_NIGHTLY)'!=''"
|
||||
Regex="CurrentComment => "(.+)?""
|
||||
ReplacementText="CurrentComment => "$(BUILD_COMMENT)-$(BUILD_NIGHTLY)""/>
|
||||
|
||||
<!--This updates the AssemblyFileVersion for the solution to the umbraco version-->
|
||||
<FileUpdate
|
||||
Files="..\src\SolutionInfo.cs"
|
||||
Regex="AssemblyFileVersion\("(.+)?"\)"
|
||||
ReplacementText="AssemblyFileVersion("$(BUILD_RELEASE)")"/>
|
||||
|
||||
<!--This updates the AssemblyInformationalVersion for the solution to the umbraco version and comment-->
|
||||
<FileUpdate
|
||||
Condition="'$(BUILD_COMMENT)'!=''"
|
||||
Files="..\src\SolutionInfo.cs"
|
||||
Regex="AssemblyInformationalVersion\("(.+)?"\)"
|
||||
ReplacementText="AssemblyInformationalVersion("$(BUILD_RELEASE)-$(BUILD_COMMENT)")"/>
|
||||
<FileUpdate
|
||||
Condition="'$(BUILD_COMMENT)'==''"
|
||||
Files="..\src\SolutionInfo.cs"
|
||||
Regex="AssemblyInformationalVersion\("(.+)?"\)"
|
||||
ReplacementText="AssemblyInformationalVersion("$(BUILD_RELEASE)")"/>
|
||||
<FileUpdate
|
||||
Condition="'$(BUILD_NIGHTLY)'!=''"
|
||||
Files="..\src\SolutionInfo.cs"
|
||||
Regex="AssemblyInformationalVersion\("(.+)?"\)"
|
||||
ReplacementText="AssemblyInformationalVersion("$(BUILD_RELEASE)-$(BUILD_NIGHTLY)")"/>
|
||||
<FileUpdate
|
||||
Condition="'$(BUILD_COMMENT)'!='' AND '$(BUILD_NIGHTLY)'!=''"
|
||||
Files="..\src\SolutionInfo.cs"
|
||||
Regex="AssemblyInformationalVersion\("(.+)?"\)"
|
||||
ReplacementText="AssemblyInformationalVersion("$(BUILD_RELEASE)-$(BUILD_COMMENT)-$(BUILD_NIGHTLY)")"/>
|
||||
<FileUpdate
|
||||
Condition="'$(BUILD_COMMENT)'=='' AND '$(BUILD_NIGHTLY)'==''"
|
||||
Files="..\src\SolutionInfo.cs"
|
||||
Regex="AssemblyInformationalVersion\("(.+)?"\)"
|
||||
ReplacementText="AssemblyInformationalVersion("$(BUILD_RELEASE)")"/>
|
||||
|
||||
<!--This updates the copyright year-->
|
||||
<FileUpdate
|
||||
Files="..\src\SolutionInfo.cs"
|
||||
Regex="AssemblyCopyright\("Copyright © Umbraco (\d{4})"\)"
|
||||
ReplacementText="AssemblyCopyright("Copyright © Umbraco $([System.DateTime]::Now.ToString(`yyyy`))")"/>
|
||||
|
||||
<XmlPoke XmlInputPath=".\NuSpecs\build\UmbracoCms.props"
|
||||
Namespaces="<Namespace Prefix='x' Uri='http://schemas.microsoft.com/developer/msbuild/2003' />"
|
||||
Query="//x:UmbracoVersion"
|
||||
Value="$(NewVersion)" />
|
||||
</Target>
|
||||
</Project>
|
||||
@@ -1,17 +0,0 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace Umbraco.Core.Auditing
|
||||
{
|
||||
[Obsolete("Use Umbraco.Core.Services.IAuditService instead")]
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
public static class Audit
|
||||
{
|
||||
public static void Add(Umbraco.Core.Auditing.AuditTypes type, string comment, int userId, int objectId)
|
||||
{
|
||||
ApplicationContext.Current.Services.AuditService.Add(
|
||||
Enum<Umbraco.Core.Models.AuditType>.Parse(type.ToString()),
|
||||
comment, userId, objectId);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,87 +0,0 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace Umbraco.Core.Auditing
|
||||
{
|
||||
[Obsolete("Use Umbraco.Core.Models.AuditType instead")]
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
public enum AuditTypes
|
||||
{
|
||||
/// <summary>
|
||||
/// Used when new nodes are added
|
||||
/// </summary>
|
||||
New,
|
||||
/// <summary>
|
||||
/// Used when nodes are saved
|
||||
/// </summary>
|
||||
Save,
|
||||
/// <summary>
|
||||
/// Used when nodes are opened
|
||||
/// </summary>
|
||||
Open,
|
||||
/// <summary>
|
||||
/// Used when nodes are deleted
|
||||
/// </summary>
|
||||
Delete,
|
||||
/// <summary>
|
||||
/// Used when nodes are published
|
||||
/// </summary>
|
||||
Publish,
|
||||
/// <summary>
|
||||
/// Used when nodes are send to publishing
|
||||
/// </summary>
|
||||
SendToPublish,
|
||||
/// <summary>
|
||||
/// Used when nodes are unpublished
|
||||
/// </summary>
|
||||
UnPublish,
|
||||
/// <summary>
|
||||
/// Used when nodes are moved
|
||||
/// </summary>
|
||||
Move,
|
||||
/// <summary>
|
||||
/// Used when nodes are copied
|
||||
/// </summary>
|
||||
Copy,
|
||||
/// <summary>
|
||||
/// Used when nodes are assígned a domain
|
||||
/// </summary>
|
||||
AssignDomain,
|
||||
/// <summary>
|
||||
/// Used when public access are changed for a node
|
||||
/// </summary>
|
||||
PublicAccess,
|
||||
/// <summary>
|
||||
/// Used when nodes are sorted
|
||||
/// </summary>
|
||||
Sort,
|
||||
/// <summary>
|
||||
/// Used when a notification are send to a user
|
||||
/// </summary>
|
||||
Notify,
|
||||
/// <summary>
|
||||
/// General system notification
|
||||
/// </summary>
|
||||
System,
|
||||
/// <summary>
|
||||
/// Used when a node's content is rolled back to a previous version
|
||||
/// </summary>
|
||||
RollBack,
|
||||
/// <summary>
|
||||
/// Used when a package is installed
|
||||
/// </summary>
|
||||
PackagerInstall,
|
||||
/// <summary>
|
||||
/// Used when a package is uninstalled
|
||||
/// </summary>
|
||||
PackagerUninstall,
|
||||
/// <summary>
|
||||
/// Used when a node is send to translation
|
||||
/// </summary>
|
||||
SendToTranslate,
|
||||
/// <summary>
|
||||
/// Use this log action for custom log messages that should be shown in the audit trail
|
||||
/// </summary>
|
||||
Custom
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
using System.Runtime.Remoting.Messaging;
|
||||
|
||||
namespace Umbraco.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// A place to get/retrieve data in a current context (i.e. http, thread, etc...)
|
||||
/// </summary>
|
||||
internal class CallContextScope : IScopeContext
|
||||
{
|
||||
public object GetData(string key)
|
||||
{
|
||||
return CallContext.GetData(key);
|
||||
}
|
||||
|
||||
public void SetData(string key, object data)
|
||||
{
|
||||
CallContext.SetData(key, data);
|
||||
}
|
||||
|
||||
public void ClearData(string key)
|
||||
{
|
||||
CallContext.FreeNamedDataSlot(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,9 @@ namespace Umbraco.Core.Configuration
|
||||
{
|
||||
public class UmbracoVersion
|
||||
{
|
||||
private static readonly Version Version = new Version("8.0.0");
|
||||
// BEWARE!
|
||||
// This class is parsed and updated by the build scripts.
|
||||
// Do NOT modify it unless you understand what you are doing.
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current version of Umbraco.
|
||||
@@ -15,27 +17,24 @@ namespace Umbraco.Core.Configuration
|
||||
/// <remarks>
|
||||
/// CURRENT UMBRACO VERSION ID.
|
||||
/// </remarks>
|
||||
public static Version Current
|
||||
{
|
||||
get { return Version; }
|
||||
}
|
||||
public static Version Current { get; } = new Version("8.0.0");
|
||||
|
||||
/// <summary>
|
||||
/// Gets the version comment (like beta or RC).
|
||||
/// </summary>
|
||||
/// <value>The version comment.</value>
|
||||
public static string CurrentComment { get { return "beta"; } }
|
||||
public static string CurrentComment => "alpha0001";
|
||||
|
||||
// Get the version of the Umbraco.Core.dll by looking at a class in that dll
|
||||
// Had to do it like this due to medium trust issues, see: http://haacked.com/archive/2010/11/04/assembly-location-and-medium-trust.aspx
|
||||
public static string AssemblyVersion { get { return new AssemblyName(typeof(UmbracoVersion).Assembly.FullName).Version.ToString(); } }
|
||||
public static string AssemblyVersion => new AssemblyName(typeof(UmbracoVersion).Assembly.FullName).Version.ToString();
|
||||
|
||||
public static SemVersion GetSemanticVersion()
|
||||
{
|
||||
return new SemVersion(
|
||||
Current.Major,
|
||||
Current.Major,
|
||||
Current.Minor,
|
||||
Current.Build,
|
||||
Current.Build,
|
||||
CurrentComment.IsNullOrWhiteSpace() ? null : CurrentComment,
|
||||
Current.Revision > 0 ? Current.Revision.ToInvariantString() : null);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
using System.Runtime.Remoting.Messaging;
|
||||
using System.Web;
|
||||
|
||||
namespace Umbraco.Core
|
||||
{
|
||||
internal class DefaultScopeContextAdapter : IScopeContextAdapter
|
||||
{
|
||||
// note
|
||||
// CallContext stuff will flow downwards in async but not upwards ie an async call will receive the values
|
||||
// but any changes it makes will *not* modify the caller's CallContext, so we should be careful when using
|
||||
// this for caches and stuff
|
||||
//
|
||||
// also might have to look for another solution for .NET Core as CallContext prob won't be available.
|
||||
|
||||
public object Get(string key)
|
||||
{
|
||||
return HttpContext.Current == null
|
||||
? CallContext.LogicalGetData(key)
|
||||
: HttpContext.Current.Items[key];
|
||||
}
|
||||
|
||||
public void Set(string key, object value)
|
||||
{
|
||||
if (HttpContext.Current == null)
|
||||
{
|
||||
if (value != null)
|
||||
CallContext.LogicalSetData(key, value);
|
||||
else
|
||||
CallContext.FreeNamedDataSlot(key);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (value != null)
|
||||
HttpContext.Current.Items[key] = value;
|
||||
else
|
||||
HttpContext.Current.Items.Remove(key);
|
||||
}
|
||||
}
|
||||
|
||||
public void Clear(string key)
|
||||
{
|
||||
if (HttpContext.Current == null)
|
||||
CallContext.FreeNamedDataSlot(key);
|
||||
else
|
||||
HttpContext.Current.Items.Remove(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
using System.Web;
|
||||
using Umbraco.Core.Persistence;
|
||||
|
||||
namespace Umbraco.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Default scope context factory
|
||||
/// </summary>
|
||||
internal class DefaultScopeContextFactory : IScopeContextFactory
|
||||
{
|
||||
public IScopeContext GetContext()
|
||||
{
|
||||
return HttpContext.Current == null ? (IScopeContext)new CallContextScope() : new HttpContextScope();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
using System;
|
||||
using LightInject;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Logging;
|
||||
@@ -24,7 +23,7 @@ namespace Umbraco.Core.DependencyInjection
|
||||
container.Register<ISqlSyntaxProvider, SqlCeSyntaxProvider>("SqlCeSyntaxProvider");
|
||||
container.Register<ISqlSyntaxProvider, SqlServerSyntaxProvider>("SqlServerSyntaxProvider");
|
||||
|
||||
container.RegisterSingleton<IScopeContextFactory, DefaultScopeContextFactory>();
|
||||
container.RegisterSingleton<IScopeContextAdapter, DefaultScopeContextAdapter>();
|
||||
|
||||
// register database factory
|
||||
// will be initialized with syntax providers and a logger, and will try to configure
|
||||
@@ -36,11 +35,8 @@ namespace Umbraco.Core.DependencyInjection
|
||||
container.RegisterSingleton<DatabaseContext>();
|
||||
|
||||
// register IUnitOfWork providers
|
||||
// using a factory for NPocoUnitOfWorkProvider because it has another ctor accepting
|
||||
// one single parameter - we should get rid of it but it is used hundreds of times in
|
||||
// unit tests and I am lazy
|
||||
container.RegisterSingleton<IUnitOfWorkProvider, FileUnitOfWorkProvider>();
|
||||
container.RegisterSingleton<IDatabaseUnitOfWorkProvider>(factory => new NPocoUnitOfWorkProvider(factory.GetInstance<IDatabaseFactory>()));
|
||||
container.RegisterSingleton<IDatabaseUnitOfWorkProvider, NPocoUnitOfWorkProvider>();
|
||||
|
||||
// register mapping resover
|
||||
// using a factory because... no time to clean it up at the moment
|
||||
@@ -65,10 +61,14 @@ namespace Umbraco.Core.DependencyInjection
|
||||
// the disabled one is used by those repositories that have an annotated ctor parameter
|
||||
container.RegisterSingleton(factory => CacheHelper.CreateDisabledCacheHelper(), DisabledCache);
|
||||
|
||||
// register IDatabaseUnitOfWork
|
||||
// resolve ctor dependency from GetInstance() runtimeArguments if possible
|
||||
container.RegisterConstructorDependency((factory, info, runtimeArguments) =>
|
||||
runtimeArguments.Length > 0 ? runtimeArguments[0] as IDatabaseUnitOfWork : null);
|
||||
// resolve ctor dependency from GetInstance() runtimeArguments, if possible - 'factory' is
|
||||
// the container, 'info' describes the ctor argument, and 'args' contains the args that
|
||||
// were passed to GetInstance() - use first arg if it is the right type,
|
||||
//
|
||||
// for IDatabaseUnitOfWork
|
||||
container.RegisterConstructorDependency((factory, info, args) => args.Length > 0 ? args[0] as IDatabaseUnitOfWork : null);
|
||||
// for IUnitOfWork
|
||||
container.RegisterConstructorDependency((factory, info, args) => args.Length > 0 ? args[0] as IUnitOfWork : null);
|
||||
|
||||
// register repositories
|
||||
// repos depend on various things, and a IDatabaseUnitOfWork (registered above)
|
||||
@@ -95,7 +95,6 @@ namespace Umbraco.Core.DependencyInjection
|
||||
container.Register<IMemberGroupRepository, MemberGroupRepository>();
|
||||
container.Register<IEntityRepository, EntityRepository>();
|
||||
container.Register<IDomainRepository, DomainRepository>();
|
||||
container.Register<EntityContainerRepository, EntityContainerRepository>();
|
||||
container.Register<ITaskRepository, TaskRepository>();
|
||||
container.Register<ITaskTypeRepository,TaskTypeRepository>();
|
||||
container.Register<IAuditRepository, AuditRepository>();
|
||||
@@ -103,12 +102,15 @@ namespace Umbraco.Core.DependencyInjection
|
||||
container.Register<IRelationTypeRepository, RelationTypeRepository>();
|
||||
container.Register<IMigrationEntryRepository, MigrationEntryRepository>();
|
||||
container.Register<IServerRegistrationRepository, ServerRegistrationRepository>();
|
||||
container.Register<IDocumentTypeContainerRepository, DocumentTypeContainerRepository>();
|
||||
container.Register<IMediaTypeContainerRepository, MediaTypeContainerRepository>();
|
||||
container.Register<IDataTypeContainerRepository, DataTypeContainerRepository>();
|
||||
|
||||
// repositories that depend on a filesystem
|
||||
// these have an annotated ctor parameter to pick the right file system
|
||||
container.Register<IScriptRepository, ScriptRepository>();
|
||||
container.Register<IPartialViewRepository, PartialViewRepository>("PartialViewRepository");
|
||||
container.Register<IPartialViewRepository, PartialViewMacroRepository>("PartialViewMacroRepository");
|
||||
container.Register<IPartialViewRepository, PartialViewRepository>();
|
||||
container.Register<IPartialViewMacroRepository, PartialViewMacroRepository>();
|
||||
container.Register<IStylesheetRepository, StylesheetRepository>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using Umbraco.Core.Packaging.Models;
|
||||
using Umbraco.Core.Models.Packaging;
|
||||
|
||||
namespace Umbraco.Core.Events
|
||||
{
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
using System.Web;
|
||||
|
||||
namespace Umbraco.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// A place to get/retrieve data in a current context (i.e. http, thread, etc...)
|
||||
/// </summary>
|
||||
internal class HttpContextScope : IScopeContext
|
||||
{
|
||||
public object GetData(string key)
|
||||
{
|
||||
return HttpContext.Current.Items[key];
|
||||
}
|
||||
|
||||
public void SetData(string key, object data)
|
||||
{
|
||||
HttpContext.Current.Items[key] = data;
|
||||
}
|
||||
|
||||
public void ClearData(string key)
|
||||
{
|
||||
HttpContext.Current.Items.Remove(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
namespace Umbraco.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// A place to get/retrieve data in a current context (i.e. http, thread, etc...)
|
||||
/// </summary>
|
||||
internal interface IScopeContext
|
||||
{
|
||||
object GetData(string key);
|
||||
void SetData(string key, object data);
|
||||
void ClearData(string key);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace Umbraco.Core
|
||||
{
|
||||
internal interface IScopeContextAdapter
|
||||
{
|
||||
// ok to get a non-existing key, returns null
|
||||
|
||||
object Get(string key);
|
||||
void Set(string key, object value);
|
||||
void Clear(string key);
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
namespace Umbraco.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets an IScopedContext
|
||||
/// </summary>
|
||||
internal interface IScopeContextFactory
|
||||
{
|
||||
IScopeContext GetContext();
|
||||
}
|
||||
}
|
||||
+42
-43
@@ -1,44 +1,43 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.Serialization;
|
||||
using Umbraco.Core.Models;
|
||||
|
||||
namespace Umbraco.Core.Packaging.Models
|
||||
{
|
||||
[Serializable]
|
||||
[DataContract(IsReference = true)]
|
||||
internal class InstallationSummary
|
||||
{
|
||||
public MetaData MetaData { get; set; }
|
||||
public IEnumerable<IDataTypeDefinition> DataTypesInstalled { get; set; }
|
||||
public IEnumerable<ILanguage> LanguagesInstalled { get; set; }
|
||||
public IEnumerable<IDictionaryItem> DictionaryItemsInstalled { get; set; }
|
||||
public IEnumerable<IMacro> MacrosInstalled { get; set; }
|
||||
public IEnumerable<string> FilesInstalled { get; set; }
|
||||
public IEnumerable<ITemplate> TemplatesInstalled { get; set; }
|
||||
public IEnumerable<IContentType> ContentTypesInstalled { get; set; }
|
||||
public IEnumerable<IFile> StylesheetsInstalled { get; set; }
|
||||
public IEnumerable<IContent> ContentInstalled { get; set; }
|
||||
public IEnumerable<PackageAction> Actions { get; set; }
|
||||
public bool PackageInstalled { get; set; }
|
||||
}
|
||||
|
||||
internal static class InstallationSummaryExtentions
|
||||
{
|
||||
public static InstallationSummary InitEmpty(this InstallationSummary summary)
|
||||
{
|
||||
summary.Actions = new List<PackageAction>();
|
||||
summary.ContentInstalled = new List<IContent>();
|
||||
summary.ContentTypesInstalled = new List<IContentType>();
|
||||
summary.DataTypesInstalled = new List<IDataTypeDefinition>();
|
||||
summary.DictionaryItemsInstalled = new List<IDictionaryItem>();
|
||||
summary.FilesInstalled = new List<string>();
|
||||
summary.LanguagesInstalled = new List<ILanguage>();
|
||||
summary.MacrosInstalled = new List<IMacro>();
|
||||
summary.MetaData = new MetaData();
|
||||
summary.TemplatesInstalled = new List<ITemplate>();
|
||||
summary.PackageInstalled = false;
|
||||
return summary;
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace Umbraco.Core.Models.Packaging
|
||||
{
|
||||
[Serializable]
|
||||
[DataContract(IsReference = true)]
|
||||
internal class InstallationSummary
|
||||
{
|
||||
public MetaData MetaData { get; set; }
|
||||
public IEnumerable<IDataTypeDefinition> DataTypesInstalled { get; set; }
|
||||
public IEnumerable<ILanguage> LanguagesInstalled { get; set; }
|
||||
public IEnumerable<IDictionaryItem> DictionaryItemsInstalled { get; set; }
|
||||
public IEnumerable<IMacro> MacrosInstalled { get; set; }
|
||||
public IEnumerable<string> FilesInstalled { get; set; }
|
||||
public IEnumerable<ITemplate> TemplatesInstalled { get; set; }
|
||||
public IEnumerable<IContentType> ContentTypesInstalled { get; set; }
|
||||
public IEnumerable<IFile> StylesheetsInstalled { get; set; }
|
||||
public IEnumerable<IContent> ContentInstalled { get; set; }
|
||||
public IEnumerable<PackageAction> Actions { get; set; }
|
||||
public bool PackageInstalled { get; set; }
|
||||
}
|
||||
|
||||
internal static class InstallationSummaryExtentions
|
||||
{
|
||||
public static InstallationSummary InitEmpty(this InstallationSummary summary)
|
||||
{
|
||||
summary.Actions = new List<PackageAction>();
|
||||
summary.ContentInstalled = new List<IContent>();
|
||||
summary.ContentTypesInstalled = new List<IContentType>();
|
||||
summary.DataTypesInstalled = new List<IDataTypeDefinition>();
|
||||
summary.DictionaryItemsInstalled = new List<IDictionaryItem>();
|
||||
summary.FilesInstalled = new List<string>();
|
||||
summary.LanguagesInstalled = new List<ILanguage>();
|
||||
summary.MacrosInstalled = new List<IMacro>();
|
||||
summary.MetaData = new MetaData();
|
||||
summary.TemplatesInstalled = new List<ITemplate>();
|
||||
summary.PackageInstalled = false;
|
||||
return summary;
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace Umbraco.Core.Packaging.Models
|
||||
namespace Umbraco.Core.Models.Packaging
|
||||
{
|
||||
[Serializable]
|
||||
[DataContract(IsReference = true)]
|
||||
+37
-37
@@ -1,38 +1,38 @@
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Umbraco.Core.Packaging.Models
|
||||
{
|
||||
internal enum ActionRunAt
|
||||
{
|
||||
Undefined = 0,
|
||||
Install,
|
||||
Uninstall
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
[DataContract(IsReference = true)]
|
||||
internal class PackageAction
|
||||
{
|
||||
private ActionRunAt _runAt;
|
||||
private bool? _undo;
|
||||
public string Alias { get; set; }
|
||||
|
||||
public string PackageName { get; set; }
|
||||
|
||||
public ActionRunAt RunAt
|
||||
{
|
||||
get { return _runAt == ActionRunAt.Undefined ? ActionRunAt.Install : _runAt; }
|
||||
set { _runAt = value; }
|
||||
}
|
||||
|
||||
public bool Undo //NOTE: Should thid default to "False"? but the documentation says default "True" (http://our.umbraco.org/wiki/reference/packaging/package-actions)
|
||||
{
|
||||
get { return _undo ?? true; }
|
||||
set { _undo = value; }
|
||||
}
|
||||
|
||||
public XElement XmlData { get; set; }
|
||||
}
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Umbraco.Core.Models.Packaging
|
||||
{
|
||||
internal enum ActionRunAt
|
||||
{
|
||||
Undefined = 0,
|
||||
Install,
|
||||
Uninstall
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
[DataContract(IsReference = true)]
|
||||
internal class PackageAction
|
||||
{
|
||||
private ActionRunAt _runAt;
|
||||
private bool? _undo;
|
||||
public string Alias { get; set; }
|
||||
|
||||
public string PackageName { get; set; }
|
||||
|
||||
public ActionRunAt RunAt
|
||||
{
|
||||
get { return _runAt == ActionRunAt.Undefined ? ActionRunAt.Install : _runAt; }
|
||||
set { _runAt = value; }
|
||||
}
|
||||
|
||||
public bool Undo //NOTE: Should thid default to "False"? but the documentation says default "True" (http://our.umbraco.org/wiki/reference/packaging/package-actions)
|
||||
{
|
||||
get { return _undo ?? true; }
|
||||
set { _undo = value; }
|
||||
}
|
||||
|
||||
public XElement XmlData { get; set; }
|
||||
}
|
||||
}
|
||||
+16
-17
@@ -1,18 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.Serialization;
|
||||
using Umbraco.Core.Models;
|
||||
|
||||
namespace Umbraco.Core.Packaging.Models
|
||||
{
|
||||
[Serializable]
|
||||
[DataContract(IsReference = true)]
|
||||
internal class PreInstallWarnings
|
||||
{
|
||||
public KeyValuePair<string, string>[] UnsecureFiles { get; set; }
|
||||
public KeyValuePair<string, string>[] FilesReplaced { get; set; }
|
||||
public IEnumerable<IMacro> ConflictingMacroAliases { get; set; }
|
||||
public IEnumerable<ITemplate> ConflictingTemplateAliases { get; set; }
|
||||
public IEnumerable<IFile> ConflictingStylesheetNames { get; set; }
|
||||
}
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace Umbraco.Core.Models.Packaging
|
||||
{
|
||||
[Serializable]
|
||||
[DataContract(IsReference = true)]
|
||||
internal class PreInstallWarnings
|
||||
{
|
||||
public KeyValuePair<string, string>[] UnsecureFiles { get; set; }
|
||||
public KeyValuePair<string, string>[] FilesReplaced { get; set; }
|
||||
public IEnumerable<IMacro> ConflictingMacroAliases { get; set; }
|
||||
public IEnumerable<ITemplate> ConflictingTemplateAliases { get; set; }
|
||||
public IEnumerable<IFile> ConflictingStylesheetNames { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
using System.Xml.Linq;
|
||||
using Umbraco.Core.Packaging.Models;
|
||||
using Umbraco.Core.Models.Packaging;
|
||||
|
||||
namespace Umbraco.Core.Packaging
|
||||
{
|
||||
|
||||
@@ -8,7 +8,7 @@ using System.Xml.XPath;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Packaging.Models;
|
||||
using Umbraco.Core.Models.Packaging;
|
||||
using Umbraco.Core.Services;
|
||||
using File = System.IO.File;
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace Umbraco.Core.Persistence
|
||||
internal class DefaultDatabaseFactory : DisposableObject, IDatabaseFactory
|
||||
{
|
||||
private readonly IMappingResolver _mappingResolver;
|
||||
private readonly IScopeContextFactory _scopeContextFactory;
|
||||
private readonly IScopeContextAdapter _scopeContextAdapter;
|
||||
private readonly ISqlSyntaxProvider[] _sqlSyntaxProviders;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
@@ -69,12 +69,12 @@ namespace Umbraco.Core.Persistence
|
||||
/// </summary>
|
||||
/// <param name="sqlSyntaxProviders">The collection of available sql syntax providers.</param>
|
||||
/// <param name="logger">A logger.</param>
|
||||
/// <param name="scopeContextFactory"></param>
|
||||
/// <param name="scopeContextAdapter"></param>
|
||||
/// <param name="mappingResolver"></param>
|
||||
/// <remarks>Used by LightInject.</remarks>
|
||||
public DefaultDatabaseFactory(IEnumerable<ISqlSyntaxProvider> sqlSyntaxProviders, ILogger logger, IScopeContextFactory scopeContextFactory, IMappingResolver mappingResolver)
|
||||
: this(GlobalSettings.UmbracoConnectionName, sqlSyntaxProviders, logger, scopeContextFactory, mappingResolver)
|
||||
{
|
||||
public DefaultDatabaseFactory(IEnumerable<ISqlSyntaxProvider> sqlSyntaxProviders, ILogger logger, IScopeContextAdapter scopeContextAdapter, IMappingResolver mappingResolver)
|
||||
: this(GlobalSettings.UmbracoConnectionName, sqlSyntaxProviders, logger, scopeContextAdapter, mappingResolver)
|
||||
{
|
||||
if (Configured == false)
|
||||
DatabaseContext.GiveLegacyAChance(this, logger);
|
||||
}
|
||||
@@ -85,21 +85,21 @@ namespace Umbraco.Core.Persistence
|
||||
/// <param name="connectionStringName">The name of the connection string in web.config.</param>
|
||||
/// <param name="sqlSyntaxProviders">The collection of available sql syntax providers.</param>
|
||||
/// <param name="logger">A logger</param>
|
||||
/// <param name="scopeContextFactory"></param>
|
||||
/// <param name="scopeContextAdapter"></param>
|
||||
/// <param name="mappingResolver"></param>
|
||||
/// <remarks>Used by the other ctor and in tests.</remarks>
|
||||
public DefaultDatabaseFactory(string connectionStringName, IEnumerable<ISqlSyntaxProvider> sqlSyntaxProviders, ILogger logger, IScopeContextFactory scopeContextFactory, IMappingResolver mappingResolver)
|
||||
public DefaultDatabaseFactory(string connectionStringName, IEnumerable<ISqlSyntaxProvider> sqlSyntaxProviders, ILogger logger, IScopeContextAdapter scopeContextAdapter, IMappingResolver mappingResolver)
|
||||
{
|
||||
if (sqlSyntaxProviders == null) throw new ArgumentNullException(nameof(sqlSyntaxProviders));
|
||||
if (logger == null) throw new ArgumentNullException(nameof(logger));
|
||||
if (scopeContextFactory == null) throw new ArgumentNullException(nameof(scopeContextFactory));
|
||||
if (scopeContextAdapter == null) throw new ArgumentNullException(nameof(scopeContextAdapter));
|
||||
if (string.IsNullOrWhiteSpace(connectionStringName)) throw new ArgumentException("Value cannot be null nor empty.", nameof(connectionStringName));
|
||||
if (mappingResolver == null) throw new ArgumentNullException(nameof(mappingResolver));
|
||||
|
||||
_mappingResolver = mappingResolver;
|
||||
_sqlSyntaxProviders = sqlSyntaxProviders.ToArray();
|
||||
_logger = logger;
|
||||
_scopeContextFactory = scopeContextFactory;
|
||||
_scopeContextAdapter = scopeContextAdapter;
|
||||
|
||||
_logger.Debug<DefaultDatabaseFactory>("Created!");
|
||||
|
||||
@@ -117,20 +117,20 @@ namespace Umbraco.Core.Persistence
|
||||
/// <param name="providerName">The name of the database provider.</param>
|
||||
/// <param name="sqlSyntaxProviders">The collection of available sql syntax providers.</param>
|
||||
/// <param name="logger">A logger.</param>
|
||||
/// <param name="scopeContextFactory"></param>
|
||||
/// <param name="scopeContextAdapter"></param>
|
||||
/// <param name="mappingResolver"></param>
|
||||
/// <remarks>Used in tests.</remarks>
|
||||
public DefaultDatabaseFactory(string connectionString, string providerName, IEnumerable<ISqlSyntaxProvider> sqlSyntaxProviders, ILogger logger, IScopeContextFactory scopeContextFactory, IMappingResolver mappingResolver)
|
||||
public DefaultDatabaseFactory(string connectionString, string providerName, IEnumerable<ISqlSyntaxProvider> sqlSyntaxProviders, ILogger logger, IScopeContextAdapter scopeContextAdapter, IMappingResolver mappingResolver)
|
||||
{
|
||||
if (sqlSyntaxProviders == null) throw new ArgumentNullException(nameof(sqlSyntaxProviders));
|
||||
if (logger == null) throw new ArgumentNullException(nameof(logger));
|
||||
if (scopeContextFactory == null) throw new ArgumentNullException(nameof(scopeContextFactory));
|
||||
if (scopeContextAdapter == null) throw new ArgumentNullException(nameof(scopeContextAdapter));
|
||||
if (mappingResolver == null) throw new ArgumentNullException(nameof(mappingResolver));
|
||||
|
||||
_mappingResolver = mappingResolver;
|
||||
_sqlSyntaxProviders = sqlSyntaxProviders.ToArray();
|
||||
_logger = logger;
|
||||
_scopeContextFactory = scopeContextFactory;
|
||||
_scopeContextAdapter = scopeContextAdapter;
|
||||
|
||||
_logger.Debug<DefaultDatabaseFactory>("Created!");
|
||||
|
||||
@@ -181,7 +181,7 @@ namespace Umbraco.Core.Persistence
|
||||
.WithFluentConfig(config)); // with proper configuration
|
||||
|
||||
if (_databaseFactory == null) throw new NullReferenceException("The call to DatabaseFactory.Config yielded a null DatabaseFactory instance");
|
||||
|
||||
|
||||
_logger.Debug<DefaultDatabaseFactory>("Created _nonHttpInstance");
|
||||
Configured = true;
|
||||
}
|
||||
@@ -232,16 +232,14 @@ namespace Umbraco.Core.Persistence
|
||||
{
|
||||
EnsureConfigured();
|
||||
|
||||
var scope = _scopeContextFactory.GetContext();
|
||||
|
||||
// check if it's in scope
|
||||
var db = scope.GetData(HttpItemKey) as UmbracoDatabase;
|
||||
var db = _scopeContextAdapter.Get(HttpItemKey) as UmbracoDatabase;
|
||||
if (db != null) return db;
|
||||
db = (UmbracoDatabase) _databaseFactory.GetDatabase();
|
||||
scope.SetData(HttpItemKey, db);
|
||||
_scopeContextAdapter.Set(HttpItemKey, db);
|
||||
return db;
|
||||
}
|
||||
|
||||
|
||||
protected override void DisposeResources()
|
||||
{
|
||||
// this is weird, because _nonHttpInstance is thread-static, so we would need
|
||||
@@ -249,10 +247,9 @@ namespace Umbraco.Core.Persistence
|
||||
// it only disposes the current thread's database instance.
|
||||
//
|
||||
// besides, we don't really want to dispose the factory, which is a singleton...
|
||||
|
||||
var scope = _scopeContextFactory.GetContext();
|
||||
var db = scope.GetData(HttpItemKey) as UmbracoDatabase;
|
||||
scope.ClearData(HttpItemKey);
|
||||
|
||||
var db = _scopeContextAdapter.Get(HttpItemKey) as UmbracoDatabase;
|
||||
_scopeContextAdapter.Clear(HttpItemKey);
|
||||
db?.Dispose();
|
||||
Configured = false;
|
||||
}
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
using System;
|
||||
using NPoco;
|
||||
using Umbraco.Core.Persistence.Repositories;
|
||||
using Umbraco.Core.Persistence.UnitOfWork;
|
||||
|
||||
namespace Umbraco.Core.Persistence
|
||||
{
|
||||
internal class LockedRepository<TRepository>
|
||||
where TRepository : IDisposable, IRepository
|
||||
{
|
||||
public LockedRepository(ITransaction transaction, IDatabaseUnitOfWork unitOfWork, TRepository repository)
|
||||
{
|
||||
Transaction = transaction;
|
||||
UnitOfWork = unitOfWork;
|
||||
Repository = repository;
|
||||
}
|
||||
|
||||
public ITransaction Transaction { get; private set; }
|
||||
public IDatabaseUnitOfWork UnitOfWork { get; private set; }
|
||||
public TRepository Repository { get; private set; }
|
||||
|
||||
public void Commit()
|
||||
{
|
||||
UnitOfWork.Commit();
|
||||
Transaction.Complete();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,103 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using Umbraco.Core.Persistence.Repositories;
|
||||
using Umbraco.Core.Persistence.UnitOfWork;
|
||||
|
||||
namespace Umbraco.Core.Persistence
|
||||
{
|
||||
internal class LockingRepository<TRepository>
|
||||
where TRepository : IDisposable, IRepository
|
||||
{
|
||||
private readonly IDatabaseUnitOfWorkProvider _uowProvider;
|
||||
private readonly Func<IDatabaseUnitOfWork, TRepository> _repositoryFactory;
|
||||
private readonly int[] _readLockIds, _writeLockIds;
|
||||
|
||||
public LockingRepository(IDatabaseUnitOfWorkProvider uowProvider, Func<IDatabaseUnitOfWork, TRepository> repositoryFactory,
|
||||
IEnumerable<int> readLockIds, IEnumerable<int> writeLockIds)
|
||||
{
|
||||
Mandate.ParameterNotNull(uowProvider, "uowProvider");
|
||||
Mandate.ParameterNotNull(repositoryFactory, "repositoryFactory");
|
||||
|
||||
_uowProvider = uowProvider;
|
||||
_repositoryFactory = repositoryFactory;
|
||||
_readLockIds = readLockIds == null ? new int[0] : readLockIds.ToArray();
|
||||
_writeLockIds = writeLockIds == null ? new int[0] : writeLockIds.ToArray();
|
||||
}
|
||||
|
||||
public void WithReadLocked(Action<LockedRepository<TRepository>> action, bool autoCommit = true)
|
||||
{
|
||||
var uow = _uowProvider.GetUnitOfWork();
|
||||
using (var transaction = uow.Database.GetTransaction(IsolationLevel.RepeatableRead))
|
||||
{
|
||||
foreach (var lockId in _readLockIds)
|
||||
uow.Database.AcquireLockNodeReadLock(lockId);
|
||||
|
||||
using (var repository = _repositoryFactory(uow))
|
||||
{
|
||||
action(new LockedRepository<TRepository>(transaction, uow, repository));
|
||||
if (autoCommit == false) return;
|
||||
uow.Commit();
|
||||
transaction.Complete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public TResult WithReadLocked<TResult>(Func<LockedRepository<TRepository>, TResult> func, bool autoCommit = true)
|
||||
{
|
||||
var uow = _uowProvider.GetUnitOfWork();
|
||||
using (var transaction = uow.Database.GetTransaction(IsolationLevel.RepeatableRead))
|
||||
{
|
||||
foreach (var lockId in _readLockIds)
|
||||
uow.Database.AcquireLockNodeReadLock(lockId);
|
||||
|
||||
using (var repository = _repositoryFactory(uow))
|
||||
{
|
||||
var ret = func(new LockedRepository<TRepository>(transaction, uow, repository));
|
||||
if (autoCommit == false) return ret;
|
||||
uow.Commit();
|
||||
transaction.Complete();
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void WithWriteLocked(Action<LockedRepository<TRepository>> action, bool autoCommit = true)
|
||||
{
|
||||
var uow = _uowProvider.GetUnitOfWork();
|
||||
using (var transaction = uow.Database.GetTransaction(IsolationLevel.RepeatableRead))
|
||||
{
|
||||
foreach (var lockId in _writeLockIds)
|
||||
uow.Database.AcquireLockNodeWriteLock(lockId);
|
||||
|
||||
using (var repository = _repositoryFactory(uow))
|
||||
{
|
||||
action(new LockedRepository<TRepository>(transaction, uow, repository));
|
||||
if (autoCommit == false) return;
|
||||
uow.Commit();
|
||||
transaction.Complete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public TResult WithWriteLocked<TResult>(Func<LockedRepository<TRepository>, TResult> func, bool autoCommit = true)
|
||||
{
|
||||
var uow = _uowProvider.GetUnitOfWork();
|
||||
using (var transaction = uow.Database.GetTransaction(IsolationLevel.RepeatableRead))
|
||||
{
|
||||
foreach (var lockId in _writeLockIds)
|
||||
uow.Database.AcquireLockNodeReadLock(lockId);
|
||||
|
||||
using (var repository = _repositoryFactory(uow))
|
||||
{
|
||||
var ret = func(new LockedRepository<TRepository>(transaction, uow, repository));
|
||||
if (autoCommit == false) return ret;
|
||||
uow.Commit();
|
||||
transaction.Complete();
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -120,15 +120,6 @@ namespace Umbraco.Core.Persistence
|
||||
return sql.LeftJoin(sql.SqlContext.SqlSyntax.GetQuotedTableName(tableName));
|
||||
}
|
||||
|
||||
public static Sql<SqlContext>.SqlJoinClause<SqlContext> LeftOuterJoin<T>(this Sql<SqlContext> sql)
|
||||
{
|
||||
var type = typeof(T);
|
||||
var tableNameAttribute = type.FirstAttribute<TableNameAttribute>();
|
||||
var tableName = tableNameAttribute == null ? string.Empty : tableNameAttribute.Value;
|
||||
|
||||
return sql.LeftOuterJoin(sql.SqlContext.SqlSyntax.GetQuotedTableName(tableName));
|
||||
}
|
||||
|
||||
public static Sql<SqlContext>.SqlJoinClause<SqlContext> RightJoin<T>(this Sql<SqlContext> sql)
|
||||
{
|
||||
var type = typeof(T);
|
||||
|
||||
@@ -993,20 +993,5 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
|
||||
return currentName;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Dispose disposable properties
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Ensure the unit of work is disposed
|
||||
/// </remarks>
|
||||
protected override void DisposeResources()
|
||||
{
|
||||
_contentTypeRepository.Dispose();
|
||||
_templateRepository.Dispose();
|
||||
_tagRepository.Dispose();
|
||||
_contentPreviewRepository.Dispose();
|
||||
_contentXmlRepository.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -663,19 +663,5 @@ AND umbracoNode.id <> @id",
|
||||
return new PreValueCollection(dictionary);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Dispose disposable properties
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Ensure the unit of work is disposed
|
||||
/// </remarks>
|
||||
protected override void DisposeResources()
|
||||
{
|
||||
_contentTypeRepository.Dispose();
|
||||
_preValRepository.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -11,7 +11,6 @@ using Umbraco.Core.Models.Rdbms;
|
||||
using Umbraco.Core.Persistence.Factories;
|
||||
using Umbraco.Core.Persistence.Mappers;
|
||||
using Umbraco.Core.Persistence.Querying;
|
||||
using Umbraco.Core.Persistence.SqlSyntax;
|
||||
using Umbraco.Core.Persistence.UnitOfWork;
|
||||
|
||||
namespace Umbraco.Core.Persistence.Repositories
|
||||
@@ -30,20 +29,15 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
}
|
||||
|
||||
private IRepositoryCachePolicyFactory<IDictionaryItem, int> _cachePolicyFactory;
|
||||
protected override IRepositoryCachePolicyFactory<IDictionaryItem, int> CachePolicyFactory
|
||||
{
|
||||
get
|
||||
{
|
||||
//custom cache policy which will not cache any results for GetAll
|
||||
return _cachePolicyFactory ?? (_cachePolicyFactory = new OnlySingleItemsRepositoryCachePolicyFactory<IDictionaryItem, int>(
|
||||
RuntimeCache,
|
||||
new RepositoryCachePolicyOptions
|
||||
{
|
||||
//allow zero to be cached
|
||||
GetAllCacheAllowZeroCount = true
|
||||
}));
|
||||
}
|
||||
}
|
||||
protected override IRepositoryCachePolicyFactory<IDictionaryItem, int> CachePolicyFactory => _cachePolicyFactory ??
|
||||
// custom cache policy which will not cache any results for GetAll
|
||||
(_cachePolicyFactory = new OnlySingleItemsRepositoryCachePolicyFactory<IDictionaryItem, int>(
|
||||
RuntimeCache,
|
||||
new RepositoryCachePolicyOptions
|
||||
{
|
||||
//allow zero to be cached
|
||||
GetAllCacheAllowZeroCount = true
|
||||
}));
|
||||
|
||||
#region Overrides of RepositoryBase<int,DictionaryItem>
|
||||
|
||||
@@ -59,7 +53,7 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
|
||||
if (dto == null)
|
||||
return null;
|
||||
|
||||
|
||||
var entity = ConvertFromDto(dto);
|
||||
|
||||
//on initial construction we don't want to have dirty properties tracked
|
||||
@@ -74,12 +68,12 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
var sql = GetBaseQuery(false).Where("cmsDictionary.pk > 0");
|
||||
if (ids.Any())
|
||||
{
|
||||
sql.Where("cmsDictionary.pk in (@ids)", new { ids = ids });
|
||||
sql.Where("cmsDictionary.pk in (@ids)", new { /*ids =*/ ids });
|
||||
}
|
||||
|
||||
return Database
|
||||
.FetchOneToMany<DictionaryDto>(x => x.LanguageTextDtos, sql)
|
||||
.Select(dto => ConvertFromDto(dto));
|
||||
.Select(ConvertFromDto);
|
||||
}
|
||||
|
||||
protected override IEnumerable<IDictionaryItem> PerformGetByQuery(IQuery<IDictionaryItem> query)
|
||||
@@ -88,10 +82,10 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
var translator = new SqlTranslator<IDictionaryItem>(sqlClause, query);
|
||||
var sql = translator.Translate();
|
||||
sql.OrderBy<DictionaryDto>(x => x.UniqueId);
|
||||
|
||||
|
||||
return Database
|
||||
.FetchOneToMany<DictionaryDto>(x => x.LanguageTextDtos, sql)
|
||||
.Select(x => ConvertFromDto(x));
|
||||
.Select(ConvertFromDto);
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -158,7 +152,7 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
translation.Key = dictionaryItem.Key;
|
||||
}
|
||||
|
||||
dictionaryItem.ResetDirtyProperties();
|
||||
dictionaryItem.ResetDirtyProperties();
|
||||
}
|
||||
|
||||
protected override void PersistUpdatedItem(IDictionaryItem entity)
|
||||
@@ -230,36 +224,27 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
var factory = new DictionaryItemFactory();
|
||||
var entity = factory.BuildEntity(dto);
|
||||
|
||||
var list = new List<IDictionaryTranslation>();
|
||||
foreach (var textDto in dto.LanguageTextDtos.EmptyNull())
|
||||
{
|
||||
if (textDto.LanguageId <= 0)
|
||||
continue;
|
||||
|
||||
var translationFactory = new DictionaryTranslationFactory(dto.UniqueId);
|
||||
list.Add(translationFactory.BuildEntity(textDto));
|
||||
}
|
||||
entity.Translations = list;
|
||||
var f = new DictionaryTranslationFactory(dto.UniqueId);
|
||||
entity.Translations = dto.LanguageTextDtos.EmptyNull()
|
||||
.Where(x => x.LanguageId > 0)
|
||||
.Select(x => f.BuildEntity(x))
|
||||
.ToList();
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
public IDictionaryItem Get(Guid uniqueId)
|
||||
{
|
||||
using (var uniqueIdRepo = new DictionaryByUniqueIdRepository(this, UnitOfWork, RepositoryCache, Logger, _mappingResolver))
|
||||
{
|
||||
return uniqueIdRepo.Get(uniqueId);
|
||||
}
|
||||
var uniqueIdRepo = new DictionaryByUniqueIdRepository(this, UnitOfWork, RepositoryCache, Logger, _mappingResolver);
|
||||
return uniqueIdRepo.Get(uniqueId);
|
||||
}
|
||||
|
||||
public IDictionaryItem Get(string key)
|
||||
{
|
||||
using (var keyRepo = new DictionaryByKeyRepository(this, UnitOfWork, RepositoryCache, Logger, _mappingResolver))
|
||||
{
|
||||
return keyRepo.Get(key);
|
||||
}
|
||||
var keyRepo = new DictionaryByKeyRepository(this, UnitOfWork, RepositoryCache, Logger, _mappingResolver);
|
||||
return keyRepo.Get(key);
|
||||
}
|
||||
|
||||
|
||||
private IEnumerable<IDictionaryItem> GetRootDictionaryItems()
|
||||
{
|
||||
var query = Query.Where(x => x.ParentId == null);
|
||||
@@ -279,7 +264,7 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
{
|
||||
var sqlClause = GetBaseQuery(false)
|
||||
.Where<DictionaryDto>(x => x.Parent != null)
|
||||
.Where(string.Format("{0} IN (@parentIds)", SqlSyntax.GetQuotedColumnName("parent")), new { parentIds = @group });
|
||||
.Where($"{SqlSyntax.GetQuotedColumnName("parent")} IN (@parentIds)", new { parentIds = @group });
|
||||
|
||||
var translator = new SqlTranslator<IDictionaryItem>(sqlClause, Query);
|
||||
var sql = translator.Translate();
|
||||
@@ -341,20 +326,15 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
}
|
||||
|
||||
private IRepositoryCachePolicyFactory<IDictionaryItem, Guid> _cachePolicyFactory;
|
||||
protected override IRepositoryCachePolicyFactory<IDictionaryItem, Guid> CachePolicyFactory
|
||||
{
|
||||
get
|
||||
{
|
||||
//custom cache policy which will not cache any results for GetAll
|
||||
return _cachePolicyFactory ?? (_cachePolicyFactory = new OnlySingleItemsRepositoryCachePolicyFactory<IDictionaryItem, Guid>(
|
||||
RuntimeCache,
|
||||
new RepositoryCachePolicyOptions
|
||||
{
|
||||
//allow zero to be cached
|
||||
GetAllCacheAllowZeroCount = true
|
||||
}));
|
||||
}
|
||||
}
|
||||
protected override IRepositoryCachePolicyFactory<IDictionaryItem, Guid> CachePolicyFactory => _cachePolicyFactory ??
|
||||
// custom cache policy which will not cache any results for GetAll
|
||||
(_cachePolicyFactory = new OnlySingleItemsRepositoryCachePolicyFactory<IDictionaryItem, Guid>(
|
||||
RuntimeCache,
|
||||
new RepositoryCachePolicyOptions
|
||||
{
|
||||
//allow zero to be cached
|
||||
GetAllCacheAllowZeroCount = true
|
||||
}));
|
||||
}
|
||||
|
||||
private class DictionaryByKeyRepository : SimpleGetRepository<string, IDictionaryItem, DictionaryDto>
|
||||
@@ -399,22 +379,15 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
}
|
||||
|
||||
private IRepositoryCachePolicyFactory<IDictionaryItem, string> _cachePolicyFactory;
|
||||
protected override IRepositoryCachePolicyFactory<IDictionaryItem, string> CachePolicyFactory
|
||||
{
|
||||
get
|
||||
{
|
||||
//custom cache policy which will not cache any results for GetAll
|
||||
return _cachePolicyFactory ?? (_cachePolicyFactory = new OnlySingleItemsRepositoryCachePolicyFactory<IDictionaryItem, string>(
|
||||
RuntimeCache,
|
||||
new RepositoryCachePolicyOptions
|
||||
{
|
||||
//allow zero to be cached
|
||||
GetAllCacheAllowZeroCount = true
|
||||
}));
|
||||
}
|
||||
}
|
||||
protected override IRepositoryCachePolicyFactory<IDictionaryItem, string> CachePolicyFactory => _cachePolicyFactory ??
|
||||
// custom cache policy which will not cache any results for GetAll
|
||||
(_cachePolicyFactory = new OnlySingleItemsRepositoryCachePolicyFactory<IDictionaryItem, string>(
|
||||
RuntimeCache,
|
||||
new RepositoryCachePolicyOptions
|
||||
{
|
||||
//allow zero to be cached
|
||||
GetAllCacheAllowZeroCount = true
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -34,11 +34,6 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
/// </summary>
|
||||
protected internal IDatabaseUnitOfWork UnitOfWork { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Internal for testing purposes
|
||||
/// </summary>
|
||||
internal Guid UnitKey => (Guid) UnitOfWork.Key;
|
||||
|
||||
#region Query Methods
|
||||
|
||||
public IQuery<IUmbracoEntity> Query => _queryFactory.Create<IUmbracoEntity>();
|
||||
|
||||
@@ -36,12 +36,12 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
|
||||
public virtual void AddFolder(string folderPath)
|
||||
{
|
||||
_work.RegisterAdded(new Folder(folderPath), this);
|
||||
_work.RegisterCreated(new Folder(folderPath), this);
|
||||
}
|
||||
|
||||
public virtual void DeleteFolder(string folderPath)
|
||||
{
|
||||
_work.RegisterRemoved(new Folder(folderPath), this);
|
||||
_work.RegisterDeleted(new Folder(folderPath), this);
|
||||
}
|
||||
|
||||
#region Implementation of IRepository<TId,TEntity>
|
||||
@@ -50,11 +50,11 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
{
|
||||
if (FileSystem.FileExists(entity.OriginalPath) == false)
|
||||
{
|
||||
_work.RegisterAdded(entity, this);
|
||||
_work.RegisterCreated(entity, this);
|
||||
}
|
||||
else
|
||||
{
|
||||
_work.RegisterChanged(entity, this);
|
||||
_work.RegisterUpdated(entity, this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
{
|
||||
if (_work != null)
|
||||
{
|
||||
_work.RegisterRemoved(entity, this);
|
||||
_work.RegisterDeleted(entity, this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Persistence.Mappers;
|
||||
using Umbraco.Core.Persistence.UnitOfWork;
|
||||
|
||||
namespace Umbraco.Core.Persistence.Repositories
|
||||
{
|
||||
class DataTypeContainerRepository : EntityContainerRepository, IDataTypeContainerRepository
|
||||
{
|
||||
public DataTypeContainerRepository(IDatabaseUnitOfWork uow, CacheHelper cache, ILogger logger, IMappingResolver mappingResolver)
|
||||
: base(uow, cache, logger, mappingResolver, Constants.ObjectTypes.DataTypeContainerGuid)
|
||||
{ }
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Persistence.Mappers;
|
||||
using Umbraco.Core.Persistence.UnitOfWork;
|
||||
|
||||
namespace Umbraco.Core.Persistence.Repositories
|
||||
{
|
||||
class DocumentTypeContainerRepository : EntityContainerRepository, IDocumentTypeContainerRepository
|
||||
{
|
||||
public DocumentTypeContainerRepository(IDatabaseUnitOfWork uow, CacheHelper cache, ILogger logger, IMappingResolver mappingResolver)
|
||||
: base(uow, cache, logger, mappingResolver, Constants.ObjectTypes.DocumentTypeContainerGuid)
|
||||
{ }
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using System.Collections;
|
||||
using Umbraco.Core.Auditing;
|
||||
using Umbraco.Core.Models;
|
||||
|
||||
namespace Umbraco.Core.Persistence.Repositories
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
namespace Umbraco.Core.Persistence.Repositories
|
||||
{
|
||||
interface IDataTypeContainerRepository : IEntityContainerRepository
|
||||
{ }
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
namespace Umbraco.Core.Persistence.Repositories
|
||||
{
|
||||
interface IDocumentTypeContainerRepository : IEntityContainerRepository
|
||||
{ }
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
using Umbraco.Core.Models;
|
||||
|
||||
namespace Umbraco.Core.Persistence.Repositories
|
||||
{
|
||||
interface IEntityContainerRepository : IRepository<int, EntityContainer>
|
||||
{ }
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
namespace Umbraco.Core.Persistence.Repositories
|
||||
{
|
||||
interface IMediaTypeContainerRepository : IEntityContainerRepository
|
||||
{ }
|
||||
}
|
||||
@@ -5,7 +5,7 @@ using Umbraco.Core.Models.Membership;
|
||||
|
||||
namespace Umbraco.Core.Persistence.Repositories
|
||||
{
|
||||
public interface INotificationsRepository
|
||||
public interface INotificationsRepository : IRepository
|
||||
{
|
||||
Notification CreateNotification(IUser user, IEntity entity, string action);
|
||||
int DeleteNotifications(IUser user);
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace Umbraco.Core.Persistence.Repositories
|
||||
{
|
||||
// this only exists to differenciate with IPartialViewRepository in IoC
|
||||
// without resorting to constants, names, whatever - and IPartialViewRepository
|
||||
// is implemented by PartialViewRepository and IPartialViewMacroRepository by
|
||||
// PartialViewMacroRepository - just to inject the proper filesystem.
|
||||
internal interface IPartialViewMacroRepository : IPartialViewRepository
|
||||
{ }
|
||||
}
|
||||
@@ -10,9 +10,9 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
/// Currently this interface is empty but it is useful for flagging a repository without having generic parameters, it also might
|
||||
/// come in handy if we need to add anything to the base/non-generic repository interface.
|
||||
/// </remarks>
|
||||
public interface IRepository : IDisposable
|
||||
public interface IRepository
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
public interface IReadRepository<in TId, out TEntity> : IRepository
|
||||
|
||||
@@ -6,5 +6,8 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
public interface IServerRegistrationRepository : IRepositoryQueryable<int, IServerRegistration>
|
||||
{
|
||||
void DeactiveStaleServers(TimeSpan staleTimeout);
|
||||
|
||||
void ReadLockServers();
|
||||
void WriteLockServers();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Persistence.Mappers;
|
||||
using Umbraco.Core.Persistence.UnitOfWork;
|
||||
|
||||
namespace Umbraco.Core.Persistence.Repositories
|
||||
{
|
||||
class MediaTypeContainerRepository : EntityContainerRepository, IMediaTypeContainerRepository
|
||||
{
|
||||
public MediaTypeContainerRepository(IDatabaseUnitOfWork uow, CacheHelper cache, ILogger logger, IMappingResolver mappingResolver)
|
||||
: base(uow, cache, logger, mappingResolver, Constants.ObjectTypes.MediaTypeContainerGuid)
|
||||
{ }
|
||||
}
|
||||
}
|
||||
@@ -625,19 +625,5 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
|
||||
return currentName;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Dispose disposable properties
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Ensure the unit of work is disposed
|
||||
/// </remarks>
|
||||
protected override void DisposeResources()
|
||||
{
|
||||
_mediaTypeRepository.Dispose();
|
||||
_tagRepository.Dispose();
|
||||
_contentXmlRepository.Dispose();
|
||||
_contentPreviewRepository.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -736,21 +736,5 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
((Entity)member).ResetDirtyProperties(false);
|
||||
return member;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Dispose disposable properties
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Ensure the unit of work is disposed
|
||||
/// </remarks>
|
||||
protected override void DisposeResources()
|
||||
{
|
||||
_memberTypeRepository.Dispose();
|
||||
_tagRepository.Dispose();
|
||||
_memberGroupRepository.Dispose();
|
||||
_contentXmlRepository.Dispose();
|
||||
_contentPreviewRepository.Dispose();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ using Umbraco.Core.Persistence.UnitOfWork;
|
||||
|
||||
namespace Umbraco.Core.Persistence.Repositories
|
||||
{
|
||||
public class NotificationsRepository : INotificationsRepository
|
||||
public class NotificationsRepository : DisposableObject, INotificationsRepository
|
||||
{
|
||||
private readonly IDatabaseUnitOfWork _unitOfWork;
|
||||
|
||||
@@ -95,5 +95,8 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
_unitOfWork.Database.Insert(dto);
|
||||
return new Notification(dto.NodeId, dto.UserId, dto.Action, nodeType);
|
||||
}
|
||||
|
||||
protected override void DisposeResources()
|
||||
{ }
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ using Umbraco.Core.Persistence.UnitOfWork;
|
||||
|
||||
namespace Umbraco.Core.Persistence.Repositories
|
||||
{
|
||||
internal class PartialViewMacroRepository : PartialViewRepository
|
||||
internal class PartialViewMacroRepository : PartialViewRepository, IPartialViewMacroRepository
|
||||
{
|
||||
|
||||
public PartialViewMacroRepository(IUnitOfWork work, [Inject("PartialViewMacroFileSystem")] IFileSystem fileSystem)
|
||||
|
||||
@@ -12,7 +12,6 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
{
|
||||
internal class PartialViewRepository : FileRepository<string, IPartialView>, IPartialViewRepository
|
||||
{
|
||||
|
||||
public PartialViewRepository(IUnitOfWork work, [Inject("PartialViewFileSystem")] IFileSystem fileSystem) : base(work, fileSystem)
|
||||
{ }
|
||||
|
||||
|
||||
@@ -156,16 +156,5 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Dispose disposable properties
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Ensure the unit of work is disposed
|
||||
/// </remarks>
|
||||
protected override void DisposeResources()
|
||||
{
|
||||
_relationTypeRepository.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,7 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Collections;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models.EntityBase;
|
||||
|
||||
@@ -12,58 +10,38 @@ using Umbraco.Core.Persistence.UnitOfWork;
|
||||
|
||||
namespace Umbraco.Core.Persistence.Repositories
|
||||
{
|
||||
internal abstract class RepositoryBase : DisposableObject
|
||||
internal abstract class RepositoryBase
|
||||
{
|
||||
private readonly IUnitOfWork _work;
|
||||
private readonly CacheHelper _cache;
|
||||
|
||||
protected RepositoryBase(IUnitOfWork work, CacheHelper cache, ILogger logger)
|
||||
{
|
||||
if (work == null) throw new ArgumentNullException("work");
|
||||
if (cache == null) throw new ArgumentNullException("cache");
|
||||
if (logger == null) throw new ArgumentNullException("logger");
|
||||
if (work == null) throw new ArgumentNullException(nameof(work));
|
||||
if (cache == null) throw new ArgumentNullException(nameof(cache));
|
||||
if (logger == null) throw new ArgumentNullException(nameof(logger));
|
||||
Logger = logger;
|
||||
_work = work;
|
||||
_cache = cache;
|
||||
UnitOfWork = work;
|
||||
RepositoryCache = cache;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the Unit of Work added to the repository
|
||||
/// </summary>
|
||||
protected internal IUnitOfWork UnitOfWork
|
||||
{
|
||||
get { return _work; }
|
||||
}
|
||||
protected internal IUnitOfWork UnitOfWork { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Internal for testing purposes
|
||||
/// </summary>
|
||||
internal Guid UnitKey
|
||||
{
|
||||
get { return (Guid)_work.Key; }
|
||||
}
|
||||
|
||||
protected CacheHelper RepositoryCache
|
||||
{
|
||||
get { return _cache; }
|
||||
}
|
||||
protected CacheHelper RepositoryCache { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The runtime cache used for this repo - by standard this is the runtime cache exposed by the CacheHelper but can be overridden
|
||||
/// </summary>
|
||||
protected virtual IRuntimeCacheProvider RuntimeCache
|
||||
{
|
||||
get { return _cache.RuntimeCache; }
|
||||
}
|
||||
protected virtual IRuntimeCacheProvider RuntimeCache => RepositoryCache.RuntimeCache;
|
||||
|
||||
public static string GetCacheIdKey<T>(object id)
|
||||
{
|
||||
return string.Format("{0}{1}", GetCacheTypeKey<T>(), id);
|
||||
return $"{GetCacheTypeKey<T>()}{id}";
|
||||
}
|
||||
|
||||
public static string GetCacheTypeKey<T>()
|
||||
{
|
||||
return string.Format("uRepo_{0}_", typeof(T).Name);
|
||||
return $"uRepo_{typeof (T).Name}_";
|
||||
}
|
||||
|
||||
protected ILogger Logger { get; private set; }
|
||||
@@ -101,10 +79,7 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
/// <summary>
|
||||
/// The runtime cache used for this repo by default is the isolated cache for this type
|
||||
/// </summary>
|
||||
protected override IRuntimeCacheProvider RuntimeCache
|
||||
{
|
||||
get { return RepositoryCache.IsolatedRuntimeCache.GetOrCreateCache<TEntity>(); }
|
||||
}
|
||||
protected override IRuntimeCacheProvider RuntimeCache => RepositoryCache.IsolatedRuntimeCache.GetOrCreateCache<TEntity>();
|
||||
|
||||
private IRepositoryCachePolicyFactory<TEntity, TId> _cachePolicyFactory;
|
||||
/// <summary>
|
||||
@@ -137,11 +112,11 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
{
|
||||
if (entity.HasIdentity == false)
|
||||
{
|
||||
UnitOfWork.RegisterAdded(entity, this);
|
||||
UnitOfWork.RegisterCreated(entity, this);
|
||||
}
|
||||
else
|
||||
{
|
||||
UnitOfWork.RegisterChanged(entity, this);
|
||||
UnitOfWork.RegisterUpdated(entity, this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,10 +126,7 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
/// <param name="entity"></param>
|
||||
public virtual void Delete(TEntity entity)
|
||||
{
|
||||
if (UnitOfWork != null)
|
||||
{
|
||||
UnitOfWork.RegisterRemoved(entity, this);
|
||||
}
|
||||
UnitOfWork?.RegisterDeleted(entity, this);
|
||||
}
|
||||
|
||||
protected abstract TEntity PerformGet(TId id);
|
||||
@@ -282,17 +254,5 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
protected abstract void PersistNewItem(TEntity item);
|
||||
protected abstract void PersistUpdatedItem(TEntity item);
|
||||
protected abstract void PersistDeletedItem(TEntity item);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Dispose disposable properties
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Ensure the unit of work is disposed
|
||||
/// </remarks>
|
||||
protected override void DisposeResources()
|
||||
{
|
||||
UnitOfWork.DisposeIfDisposable();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
internal class ServerRegistrationRepository : NPocoRepositoryBase<int, IServerRegistration>, IServerRegistrationRepository
|
||||
{
|
||||
private readonly ICacheProvider _staticCache;
|
||||
private readonly int[] _lockIds = { Constants.System.ServersLock };
|
||||
|
||||
public ServerRegistrationRepository(IDatabaseUnitOfWork work, CacheHelper cacheHelper, ILogger logger, IMappingResolver mappingResolver)
|
||||
: base(work, CacheHelper.CreateDisabledCacheHelper(), logger, mappingResolver)
|
||||
@@ -146,5 +147,15 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
Database.Update<ServerRegistrationDto>("SET isActive=0, isMaster=0 WHERE lastNotifiedDate < @timeoutDate", new { /*timeoutDate =*/ timeoutDate });
|
||||
ReloadCache();
|
||||
}
|
||||
|
||||
public void ReadLockServers()
|
||||
{
|
||||
UnitOfWork.ReadLockNodes(_lockIds);
|
||||
}
|
||||
|
||||
public void WriteLockServers()
|
||||
{
|
||||
UnitOfWork.WriteLockNodes(_lockIds);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -421,16 +421,5 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
return userFactory.BuildEntity(dto);
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Dispose disposable properties
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Ensure the unit of work is disposed
|
||||
/// </remarks>
|
||||
protected override void DisposeResources()
|
||||
{
|
||||
_userTypeRepository.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,164 +22,34 @@ namespace Umbraco.Core.Persistence
|
||||
_container = container;
|
||||
}
|
||||
|
||||
public virtual INotificationsRepository CreateNotificationsRepository(IDatabaseUnitOfWork uow)
|
||||
/// <summary>
|
||||
/// Creates a repository.
|
||||
/// </summary>
|
||||
/// <typeparam name="TRepository">The type of the repository.</typeparam>
|
||||
/// <param name="uow">A unit of work.</param>
|
||||
/// <param name="name">The optional name of the repository.</param>
|
||||
/// <returns>The created repository for the unit of work.</returns>
|
||||
public virtual TRepository CreateRepository<TRepository>(IDatabaseUnitOfWork uow, string name = null)
|
||||
where TRepository : IRepository
|
||||
{
|
||||
return _container.GetInstance<IDatabaseUnitOfWork, INotificationsRepository>(uow);
|
||||
return string.IsNullOrWhiteSpace(name)
|
||||
? _container.GetInstance<IDatabaseUnitOfWork, TRepository>(uow)
|
||||
: _container.GetInstance<IDatabaseUnitOfWork, TRepository>(uow, name);
|
||||
}
|
||||
|
||||
public virtual IExternalLoginRepository CreateExternalLoginRepository(IDatabaseUnitOfWork uow)
|
||||
/// <summary>
|
||||
/// Creates a repository.
|
||||
/// </summary>
|
||||
/// <typeparam name="TRepository">The type of the repository.</typeparam>
|
||||
/// <param name="uow">A unit of work.</param>
|
||||
/// <param name="name">The optional name of the repository.</param>
|
||||
/// <returns>The created repository for the unit of work.</returns>
|
||||
internal virtual TRepository CreateRepository<TRepository>(FileUnitOfWork uow, string name = null)
|
||||
where TRepository : IRepository
|
||||
{
|
||||
return _container.GetInstance<IDatabaseUnitOfWork, IExternalLoginRepository>(uow);
|
||||
}
|
||||
|
||||
public virtual IPublicAccessRepository CreatePublicAccessRepository(IDatabaseUnitOfWork uow)
|
||||
{
|
||||
return _container.GetInstance<IDatabaseUnitOfWork, IPublicAccessRepository>(uow);
|
||||
}
|
||||
|
||||
public virtual ITaskRepository CreateTaskRepository(IDatabaseUnitOfWork uow)
|
||||
{
|
||||
return _container.GetInstance<IDatabaseUnitOfWork, ITaskRepository>(uow);
|
||||
}
|
||||
|
||||
public virtual IAuditRepository CreateAuditRepository(IDatabaseUnitOfWork uow)
|
||||
{
|
||||
return _container.GetInstance<IDatabaseUnitOfWork, IAuditRepository>(uow);
|
||||
}
|
||||
|
||||
public virtual ITagRepository CreateTagRepository(IDatabaseUnitOfWork uow)
|
||||
{
|
||||
return _container.GetInstance<IDatabaseUnitOfWork, ITagRepository>(uow);
|
||||
}
|
||||
|
||||
public virtual IContentRepository CreateContentRepository(IDatabaseUnitOfWork uow)
|
||||
{
|
||||
return _container.GetInstance<IDatabaseUnitOfWork, IContentRepository>(uow);
|
||||
}
|
||||
|
||||
public virtual IContentTypeRepository CreateContentTypeRepository(IDatabaseUnitOfWork uow)
|
||||
{
|
||||
return _container.GetInstance<IDatabaseUnitOfWork, IContentTypeRepository>(uow);
|
||||
}
|
||||
|
||||
public virtual IDataTypeDefinitionRepository CreateDataTypeDefinitionRepository(IDatabaseUnitOfWork uow)
|
||||
{
|
||||
return _container.GetInstance<IDatabaseUnitOfWork, IDataTypeDefinitionRepository>(uow);
|
||||
}
|
||||
|
||||
public virtual IDictionaryRepository CreateDictionaryRepository(IDatabaseUnitOfWork uow)
|
||||
{
|
||||
return _container.GetInstance<IDatabaseUnitOfWork, IDictionaryRepository>(uow);
|
||||
}
|
||||
|
||||
public virtual ILanguageRepository CreateLanguageRepository(IDatabaseUnitOfWork uow)
|
||||
{
|
||||
return _container.GetInstance<IDatabaseUnitOfWork, ILanguageRepository>(uow);
|
||||
}
|
||||
|
||||
public virtual IMediaRepository CreateMediaRepository(IDatabaseUnitOfWork uow)
|
||||
{
|
||||
return _container.GetInstance<IDatabaseUnitOfWork, IMediaRepository>(uow);
|
||||
}
|
||||
|
||||
public virtual IMediaTypeRepository CreateMediaTypeRepository(IDatabaseUnitOfWork uow)
|
||||
{
|
||||
return _container.GetInstance<IDatabaseUnitOfWork, IMediaTypeRepository>(uow);
|
||||
}
|
||||
|
||||
public virtual IRelationRepository CreateRelationRepository(IDatabaseUnitOfWork uow)
|
||||
{
|
||||
return _container.GetInstance<IDatabaseUnitOfWork, IRelationRepository>(uow);
|
||||
}
|
||||
|
||||
public virtual IRelationTypeRepository CreateRelationTypeRepository(IDatabaseUnitOfWork uow)
|
||||
{
|
||||
return _container.GetInstance<IDatabaseUnitOfWork, IRelationTypeRepository>(uow);
|
||||
}
|
||||
|
||||
public virtual IScriptRepository CreateScriptRepository(IUnitOfWork uow)
|
||||
{
|
||||
return _container.GetInstance<IUnitOfWork, IScriptRepository>(uow);
|
||||
}
|
||||
|
||||
internal virtual IPartialViewRepository CreatePartialViewRepository(IUnitOfWork uow)
|
||||
{
|
||||
return _container.GetInstance<IUnitOfWork, IPartialViewRepository>(uow, "PartialViewRepository");
|
||||
}
|
||||
|
||||
internal virtual IPartialViewRepository CreatePartialViewMacroRepository(IUnitOfWork uow)
|
||||
{
|
||||
return _container.GetInstance<IUnitOfWork, IPartialViewRepository>(uow, "PartialViewMacroRepository");
|
||||
}
|
||||
|
||||
public virtual IStylesheetRepository CreateStylesheetRepository(IUnitOfWork uow, IDatabaseUnitOfWork db)
|
||||
{
|
||||
return _container.GetInstance<IUnitOfWork, IStylesheetRepository>(uow);
|
||||
}
|
||||
|
||||
public virtual ITemplateRepository CreateTemplateRepository(IDatabaseUnitOfWork uow)
|
||||
{
|
||||
return _container.GetInstance<IDatabaseUnitOfWork, ITemplateRepository>(uow);
|
||||
}
|
||||
|
||||
public virtual IMigrationEntryRepository CreateMigrationEntryRepository(IDatabaseUnitOfWork uow)
|
||||
{
|
||||
return _container.GetInstance<IDatabaseUnitOfWork, IMigrationEntryRepository>(uow);
|
||||
}
|
||||
|
||||
public virtual IServerRegistrationRepository CreateServerRegistrationRepository(IDatabaseUnitOfWork uow)
|
||||
{
|
||||
return _container.GetInstance<IDatabaseUnitOfWork, IServerRegistrationRepository>(uow);
|
||||
}
|
||||
|
||||
public virtual IUserTypeRepository CreateUserTypeRepository(IDatabaseUnitOfWork uow)
|
||||
{
|
||||
return _container.GetInstance<IDatabaseUnitOfWork, IUserTypeRepository>(uow);
|
||||
}
|
||||
|
||||
public virtual IUserRepository CreateUserRepository(IDatabaseUnitOfWork uow)
|
||||
{
|
||||
return _container.GetInstance<IDatabaseUnitOfWork, IUserRepository>(uow);
|
||||
}
|
||||
|
||||
internal virtual IMacroRepository CreateMacroRepository(IDatabaseUnitOfWork uow)
|
||||
{
|
||||
return _container.GetInstance<IDatabaseUnitOfWork, IMacroRepository>(uow);
|
||||
}
|
||||
|
||||
public virtual IMemberRepository CreateMemberRepository(IDatabaseUnitOfWork uow)
|
||||
{
|
||||
return _container.GetInstance<IDatabaseUnitOfWork, IMemberRepository>(uow);
|
||||
}
|
||||
|
||||
public virtual IMemberTypeRepository CreateMemberTypeRepository(IDatabaseUnitOfWork uow)
|
||||
{
|
||||
return _container.GetInstance<IDatabaseUnitOfWork, IMemberTypeRepository>(uow);
|
||||
}
|
||||
|
||||
public virtual IMemberGroupRepository CreateMemberGroupRepository(IDatabaseUnitOfWork uow)
|
||||
{
|
||||
return _container.GetInstance<IDatabaseUnitOfWork, IMemberGroupRepository>(uow);
|
||||
}
|
||||
|
||||
public virtual IEntityRepository CreateEntityRepository(IDatabaseUnitOfWork uow)
|
||||
{
|
||||
return _container.GetInstance<IDatabaseUnitOfWork, IEntityRepository>(uow);
|
||||
}
|
||||
|
||||
public virtual IDomainRepository CreateDomainRepository(IDatabaseUnitOfWork uow)
|
||||
{
|
||||
return _container.GetInstance<IDatabaseUnitOfWork, IDomainRepository>(uow);
|
||||
}
|
||||
|
||||
public virtual ITaskTypeRepository CreateTaskTypeRepository(IDatabaseUnitOfWork uow)
|
||||
{
|
||||
return _container.GetInstance<IDatabaseUnitOfWork, ITaskTypeRepository>(uow);
|
||||
}
|
||||
|
||||
internal virtual EntityContainerRepository CreateEntityContainerRepository(IDatabaseUnitOfWork uow, Guid containerObjectType)
|
||||
{
|
||||
return _container.GetInstance<IDatabaseUnitOfWork, EntityContainerRepository>(uow);
|
||||
return string.IsNullOrWhiteSpace(name)
|
||||
? _container.GetInstance<FileUnitOfWork, TRepository>(uow)
|
||||
: _container.GetInstance<FileUnitOfWork, TRepository>(uow, name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
namespace Umbraco.Core.Persistence
|
||||
{
|
||||
/// <summary>
|
||||
/// Enum for the 3 types of transactions
|
||||
/// </summary>
|
||||
internal enum TransactionType
|
||||
{
|
||||
Insert,
|
||||
Update,
|
||||
Delete
|
||||
}
|
||||
}
|
||||
@@ -1,142 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Transactions;
|
||||
using Umbraco.Core.Models.EntityBase;
|
||||
|
||||
namespace Umbraco.Core.Persistence.UnitOfWork
|
||||
namespace Umbraco.Core.Persistence.UnitOfWork
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents the Unit of Work implementation for working with files
|
||||
/// Represents a persistence unit of work for working with files.
|
||||
/// </summary>
|
||||
internal class FileUnitOfWork : IUnitOfWork
|
||||
/// <remarks>The FileUnitOfWork does *not* implement transactions, so although it needs to be flushed or
|
||||
/// completed for operations to be executed, they are executed immediately without any commit or roll back
|
||||
/// mechanism.</remarks>
|
||||
internal class FileUnitOfWork : UnitOfWorkBase
|
||||
{
|
||||
private Guid _key;
|
||||
private readonly Queue<Operation> _operations = new Queue<Operation>();
|
||||
|
||||
public FileUnitOfWork()
|
||||
{
|
||||
_key = Guid.NewGuid();
|
||||
}
|
||||
|
||||
#region Implementation of IUnitOfWork
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="NPocoUnitOfWork"/> class with a a repository factory.
|
||||
/// </summary>
|
||||
/// <param name="factory">A repository factory.</param>
|
||||
/// <remarks>This should be used by the FileUnitOfWorkProvider exclusively.</remarks>
|
||||
public FileUnitOfWork(RepositoryFactory factory)
|
||||
: base(factory)
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
/// Registers an <see cref="IEntity" /> instance to be added through this <see cref="UnitOfWork" />
|
||||
/// Creates a repository.
|
||||
/// </summary>
|
||||
/// <param name="entity">The <see cref="IEntity" /></param>
|
||||
/// <param name="repository">The <see cref="IUnitOfWorkRepository" /> participating in the transaction</param>
|
||||
public void RegisterAdded(IEntity entity, IUnitOfWorkRepository repository)
|
||||
/// <typeparam name="TRepository">The type of the repository.</typeparam>
|
||||
/// <param name="name">The optional name of the repository.</param>
|
||||
/// <returns>The created repository for the unit of work.</returns>
|
||||
public override TRepository CreateRepository<TRepository>(string name = null)
|
||||
{
|
||||
_operations.Enqueue(
|
||||
new Operation
|
||||
{
|
||||
Entity = entity,
|
||||
Repository = repository,
|
||||
Type = TransactionType.Insert
|
||||
});
|
||||
return Factory.CreateRepository<TRepository>(this, name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Registers an <see cref="IEntity" /> instance to be changed through this <see cref="UnitOfWork" />
|
||||
/// </summary>
|
||||
/// <param name="entity">The <see cref="IEntity" /></param>
|
||||
/// <param name="repository">The <see cref="IUnitOfWorkRepository" /> participating in the transaction</param>
|
||||
public void RegisterChanged(IEntity entity, IUnitOfWorkRepository repository)
|
||||
{
|
||||
_operations.Enqueue(
|
||||
new Operation
|
||||
{
|
||||
Entity = entity,
|
||||
Repository = repository,
|
||||
Type = TransactionType.Update
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Registers an <see cref="IEntity" /> instance to be removed through this <see cref="UnitOfWork" />
|
||||
/// </summary>
|
||||
/// <param name="entity">The <see cref="IEntity" /></param>
|
||||
/// <param name="repository">The <see cref="IUnitOfWorkRepository" /> participating in the transaction</param>
|
||||
public void RegisterRemoved(IEntity entity, IUnitOfWorkRepository repository)
|
||||
{
|
||||
_operations.Enqueue(
|
||||
new Operation
|
||||
{
|
||||
Entity = entity,
|
||||
Repository = repository,
|
||||
Type = TransactionType.Delete
|
||||
});
|
||||
}
|
||||
|
||||
public void Commit()
|
||||
{
|
||||
//NOTE: I'm leaving this in here for reference, but this is useless, transaction scope + Files doesn't do anything,
|
||||
// the closest you can get is transactional NTFS, but that requires distributed transaction coordinator and some other libs/wrappers,
|
||||
// plus MS has not deprecated it anyways. To do transactional IO we'd have to write this ourselves using temporary files and then
|
||||
// on committing move them to their correct place.
|
||||
//using(var scope = new TransactionScope())
|
||||
//{
|
||||
// // Commit the transaction
|
||||
// scope.Complete();
|
||||
//}
|
||||
|
||||
while (_operations.Count > 0)
|
||||
{
|
||||
var operation = _operations.Dequeue();
|
||||
switch (operation.Type)
|
||||
{
|
||||
case TransactionType.Insert:
|
||||
operation.Repository.PersistNewItem(operation.Entity);
|
||||
break;
|
||||
case TransactionType.Delete:
|
||||
operation.Repository.PersistDeletedItem(operation.Entity);
|
||||
break;
|
||||
case TransactionType.Update:
|
||||
operation.Repository.PersistUpdatedItem(operation.Entity);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Clear everything
|
||||
_operations.Clear();
|
||||
_key = Guid.NewGuid();
|
||||
}
|
||||
|
||||
public object Key
|
||||
{
|
||||
get { return _key; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Operation
|
||||
|
||||
/// <summary>
|
||||
/// Provides a snapshot of an entity and the repository reference it belongs to.
|
||||
/// </summary>
|
||||
private sealed class Operation
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the entity.
|
||||
/// </summary>
|
||||
/// <value>The entity.</value>
|
||||
public IEntity Entity { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the repository.
|
||||
/// </summary>
|
||||
/// <value>The repository.</value>
|
||||
public IUnitOfWorkRepository Repository { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the type of operation.
|
||||
/// </summary>
|
||||
/// <value>The type of operation.</value>
|
||||
public TransactionType Type { get; set; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
@@ -5,13 +5,30 @@
|
||||
/// </summary>
|
||||
public class FileUnitOfWorkProvider : IUnitOfWorkProvider
|
||||
{
|
||||
#region Implementation of IUnitOfWorkProvider
|
||||
private readonly RepositoryFactory _repositoryFactory;
|
||||
|
||||
public IUnitOfWork GetUnitOfWork()
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="FileUnitOfWorkProvider"/> class with a repository factory.
|
||||
/// </summary>
|
||||
/// <param name="repositoryFactory">A repository factory.</param>
|
||||
public FileUnitOfWorkProvider(RepositoryFactory repositoryFactory)
|
||||
{
|
||||
return new FileUnitOfWork();
|
||||
Mandate.ParameterNotNull(repositoryFactory, nameof(repositoryFactory));
|
||||
_repositoryFactory = repositoryFactory;
|
||||
}
|
||||
|
||||
#endregion
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="FileUnitOfWorkProvider"/> class.
|
||||
/// </summary>
|
||||
/// <remarks>FOR UNIT TESTS ONLY</remarks>
|
||||
internal FileUnitOfWorkProvider()
|
||||
{
|
||||
// careful, _repositoryFactory remains null!
|
||||
}
|
||||
|
||||
public IUnitOfWork CreateUnitOfWork()
|
||||
{
|
||||
return new FileUnitOfWork(_repositoryFactory);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,13 @@
|
||||
using System;
|
||||
|
||||
namespace Umbraco.Core.Persistence.UnitOfWork
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines a unit of work when working with a database object
|
||||
/// Represents a persistence unit of work for working with a database.
|
||||
/// </summary>
|
||||
public interface IDatabaseUnitOfWork : IUnitOfWork, IDisposable
|
||||
public interface IDatabaseUnitOfWork : IUnitOfWork
|
||||
{
|
||||
UmbracoDatabase Database { get; }
|
||||
}
|
||||
|
||||
void ReadLockNodes(params int[] lockIds);
|
||||
void WriteLockNodes(params int[] lockIds);
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,14 @@
|
||||
namespace Umbraco.Core.Persistence.UnitOfWork
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines a Unit of Work Provider for working with an IDatabaseUnitOfWork
|
||||
/// </summary>
|
||||
public interface IDatabaseUnitOfWorkProvider
|
||||
/// <summary>
|
||||
/// Represents a provider that can create units of work to work on databases.
|
||||
/// </summary>
|
||||
public interface IDatabaseUnitOfWorkProvider
|
||||
{
|
||||
IDatabaseUnitOfWork GetUnitOfWork();
|
||||
/// <summary>
|
||||
/// Creates a unit of work.
|
||||
/// </summary>
|
||||
/// <returns>A new unit of work.</returns>
|
||||
IDatabaseUnitOfWork CreateUnitOfWork();
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,77 @@
|
||||
using System;
|
||||
using Umbraco.Core.Models.EntityBase;
|
||||
using Umbraco.Core.Persistence.Repositories;
|
||||
|
||||
namespace Umbraco.Core.Persistence.UnitOfWork
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines a Unit Of Work
|
||||
/// Represents a persistence unit of work.
|
||||
/// </summary>
|
||||
public interface IUnitOfWork
|
||||
{
|
||||
void RegisterAdded(IEntity entity, IUnitOfWorkRepository repository);
|
||||
void RegisterChanged(IEntity entity, IUnitOfWorkRepository repository);
|
||||
void RegisterRemoved(IEntity entity, IUnitOfWorkRepository repository);
|
||||
void Commit();
|
||||
object Key { get; }
|
||||
public interface IUnitOfWork : IDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// Registers an entity to be created as part of this unit of work.
|
||||
/// </summary>
|
||||
/// <param name="entity">The entity.</param>
|
||||
/// <param name="repository">The repository in charge of the entity.</param>
|
||||
void RegisterCreated(IEntity entity, IUnitOfWorkRepository repository);
|
||||
|
||||
/// <summary>
|
||||
/// Registers an entity to be updated as part of this unit of work.
|
||||
/// </summary>
|
||||
/// <param name="entity">The entity.</param>
|
||||
/// <param name="repository">The repository in charge of the entity.</param>
|
||||
void RegisterUpdated(IEntity entity, IUnitOfWorkRepository repository);
|
||||
|
||||
/// <summary>
|
||||
/// Registers an entity to be deleted as part of this unit of work.
|
||||
/// </summary>
|
||||
/// <param name="entity">The entity.</param>
|
||||
/// <param name="repository">The repository in charge of the entity.</param>
|
||||
void RegisterDeleted(IEntity entity, IUnitOfWorkRepository repository);
|
||||
|
||||
/// <summary>
|
||||
/// Begins the unit of work.
|
||||
/// </summary>
|
||||
/// <remarks>When a unit of work begins, a local transaction scope is created at database level.
|
||||
/// This is useful eg when reading entities before creating, updating or deleting, and the read
|
||||
/// needs to be part of the transaction. Flushing or completing the unit of work automatically
|
||||
/// begins the transaction (so no need to call Begin if not necessary).</remarks>
|
||||
void Begin();
|
||||
|
||||
/// <summary>
|
||||
/// Flushes the unit of work.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>When a unit of work is flushed, all queued operations are executed. This is useful eg
|
||||
/// when a row needs to be created in the database, so that its auto-generated ID can be retrieved.
|
||||
/// Note that it does *not* complete the unit of work, however. Completing the unit of work
|
||||
/// automatically flushes the queue (so no need to call Flush if not necessary).</para>
|
||||
/// </remarks>
|
||||
void Flush();
|
||||
|
||||
/// <summary>
|
||||
/// Completes the unit of work.
|
||||
/// </summary>
|
||||
/// <remarks>When a unit of work is completed, a local transaction scope is created at database level,
|
||||
/// all queued operations are executed, and the scope is commited. If the unit of work is not completed
|
||||
/// before it is disposed, all queued operations are cleared and the scope is rolled back (and also
|
||||
/// higher level transactions if any).
|
||||
/// Whether this actually commits or rolls back the transaction depends on whether the transaction scope
|
||||
/// is part of a higher level transactions. The database transaction is committed or rolled back only
|
||||
/// when the upper level scope is disposed.
|
||||
/// If any operation is added to the unit of work after it has been completed, then its completion
|
||||
/// status is resetted. So in a way it could be possible to always complete and never flush, but flush
|
||||
/// is preferred when appropriate to indicate that you understand what you are doing.
|
||||
/// </remarks>
|
||||
void Complete();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a repository.
|
||||
/// </summary>
|
||||
/// <typeparam name="TRepository">The type of the repository.</typeparam>
|
||||
/// <param name="name">The optional name of the repository.</param>
|
||||
/// <returns>The created repository for the unit of work.</returns>
|
||||
TRepository CreateRepository<TRepository>(string name = null) where TRepository : IRepository;
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,14 @@
|
||||
namespace Umbraco.Core.Persistence.UnitOfWork
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines a Unit of Work Provider
|
||||
/// Represents a provider that can create units of work.
|
||||
/// </summary>
|
||||
public interface IUnitOfWorkProvider
|
||||
{
|
||||
IUnitOfWork GetUnitOfWork();
|
||||
/// <summary>
|
||||
/// Creates a unit of work.
|
||||
/// </summary>
|
||||
/// <returns>A new unit of work.</returns>
|
||||
IUnitOfWork CreateUnitOfWork();
|
||||
}
|
||||
}
|
||||
@@ -1,183 +1,97 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using NPoco;
|
||||
using Umbraco.Core.Models.EntityBase;
|
||||
|
||||
namespace Umbraco.Core.Persistence.UnitOfWork
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents the Unit of Work implementation for NPoco
|
||||
/// </summary>
|
||||
internal class NPocoUnitOfWork : DisposableObject, IDatabaseUnitOfWork
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Used for testing
|
||||
/// </summary>
|
||||
internal Guid InstanceId { get; private set; }
|
||||
|
||||
private Guid _key;
|
||||
private readonly Queue<Operation> _operations = new Queue<Operation>();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new unit of work instance
|
||||
/// </summary>
|
||||
/// <param name="database"></param>
|
||||
/// <remarks>
|
||||
/// This should normally not be used directly and should be created with the UnitOfWorkProvider
|
||||
/// </remarks>
|
||||
internal NPocoUnitOfWork(UmbracoDatabase database)
|
||||
{
|
||||
Database = database;
|
||||
_key = Guid.NewGuid();
|
||||
InstanceId = Guid.NewGuid();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Registers an <see cref="IEntity" /> instance to be added through this <see cref="UnitOfWork" />
|
||||
/// </summary>
|
||||
/// <param name="entity">The <see cref="IEntity" /></param>
|
||||
/// <param name="repository">The <see cref="IUnitOfWorkRepository" /> participating in the transaction</param>
|
||||
public void RegisterAdded(IEntity entity, IUnitOfWorkRepository repository)
|
||||
{
|
||||
_operations.Enqueue(new Operation
|
||||
{
|
||||
Entity = entity,
|
||||
Repository = repository,
|
||||
Type = TransactionType.Insert
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Registers an <see cref="IEntity" /> instance to be changed through this <see cref="UnitOfWork" />
|
||||
/// </summary>
|
||||
/// <param name="entity">The <see cref="IEntity" /></param>
|
||||
/// <param name="repository">The <see cref="IUnitOfWorkRepository" /> participating in the transaction</param>
|
||||
public void RegisterChanged(IEntity entity, IUnitOfWorkRepository repository)
|
||||
{
|
||||
_operations.Enqueue(
|
||||
new Operation
|
||||
{
|
||||
Entity = entity,
|
||||
Repository = repository,
|
||||
Type = TransactionType.Update
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Registers an <see cref="IEntity" /> instance to be removed through this <see cref="UnitOfWork" />
|
||||
/// </summary>
|
||||
/// <param name="entity">The <see cref="IEntity" /></param>
|
||||
/// <param name="repository">The <see cref="IUnitOfWorkRepository" /> participating in the transaction</param>
|
||||
public void RegisterRemoved(IEntity entity, IUnitOfWorkRepository repository)
|
||||
{
|
||||
_operations.Enqueue(
|
||||
new Operation
|
||||
{
|
||||
Entity = entity,
|
||||
Repository = repository,
|
||||
Type = TransactionType.Delete
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Commits all batched changes within the scope of a NPoco <see cref="Transaction"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Unlike a typical unit of work, this UOW will let you commit more than once since a new transaction is creaed per
|
||||
/// Commit() call instead of having one transaction per UOW.
|
||||
/// </remarks>
|
||||
public void Commit()
|
||||
{
|
||||
Commit(null);
|
||||
}
|
||||
/// <summary>
|
||||
/// Implements IDatabaseUnitOfWork for NPoco.
|
||||
/// </summary>
|
||||
internal class NPocoUnitOfWork : UnitOfWorkBase, IDatabaseUnitOfWork
|
||||
{
|
||||
private ITransaction _transaction;
|
||||
|
||||
/// <summary>
|
||||
/// Commits all batched changes within the scope of a NPoco <see cref="Transaction"/>.
|
||||
/// Initializes a new instance of the <see cref="NPocoUnitOfWork"/> class with a database and a repository factory.
|
||||
/// </summary>
|
||||
/// <param name="transactionCompleting">
|
||||
/// Allows you to set a callback which is executed before the transaction is committed, allow you to add additional SQL
|
||||
/// operations to the overall commit process after the queue has been processed.
|
||||
/// </param>
|
||||
internal void Commit(Action<UmbracoDatabase> transactionCompleting)
|
||||
/// <param name="database">A database.</param>
|
||||
/// <param name="factory">A repository factory.</param>
|
||||
/// <remarks>This should be used by the NPocoUnitOfWorkProvider exclusively.</remarks>
|
||||
internal NPocoUnitOfWork(UmbracoDatabase database, RepositoryFactory factory)
|
||||
: base(factory)
|
||||
{
|
||||
using (var transaction = Database.GetTransaction())
|
||||
{
|
||||
while (_operations.Count > 0)
|
||||
{
|
||||
var operation = _operations.Dequeue();
|
||||
switch (operation.Type)
|
||||
{
|
||||
case TransactionType.Insert:
|
||||
operation.Repository.PersistNewItem(operation.Entity);
|
||||
break;
|
||||
case TransactionType.Delete:
|
||||
operation.Repository.PersistDeletedItem(operation.Entity);
|
||||
break;
|
||||
case TransactionType.Update:
|
||||
operation.Repository.PersistUpdatedItem(operation.Entity);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//Execute the callback if there is one
|
||||
if (transactionCompleting != null)
|
||||
{
|
||||
transactionCompleting(Database);
|
||||
}
|
||||
|
||||
transaction.Complete();
|
||||
}
|
||||
|
||||
// Clear everything
|
||||
_operations.Clear();
|
||||
_key = Guid.NewGuid();
|
||||
Database = database;
|
||||
}
|
||||
|
||||
public object Key
|
||||
{
|
||||
get { return _key; }
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets the unit of work underlying database.
|
||||
/// </summary>
|
||||
public UmbracoDatabase Database { get; }
|
||||
|
||||
public UmbracoDatabase Database { get; private set; }
|
||||
/// <summary>
|
||||
/// Creates a repository.
|
||||
/// </summary>
|
||||
/// <typeparam name="TRepository">The type of the repository.</typeparam>
|
||||
/// <param name="name">The optional name of the repository.</param>
|
||||
/// <returns>The created repository for the unit of work.</returns>
|
||||
public override TRepository CreateRepository<TRepository>(string name = null)
|
||||
{
|
||||
return Factory.CreateRepository<TRepository>(this, name);
|
||||
}
|
||||
|
||||
#region Operation
|
||||
/// <summary>
|
||||
/// Ensures that we have a transaction.
|
||||
/// </summary>
|
||||
/// <remarks>Isolation level is determined by the database, see UmbracoDatabase.DefaultIsolationLevel. Should be
|
||||
/// at least IsolationLevel.RepeatablRead else the node locks will not work correctly.</remarks>
|
||||
public override void Begin()
|
||||
{
|
||||
base.Begin();
|
||||
|
||||
/// <summary>
|
||||
/// Provides a snapshot of an entity and the repository reference it belongs to.
|
||||
/// </summary>
|
||||
private sealed class Operation
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the entity.
|
||||
/// </summary>
|
||||
/// <value>The entity.</value>
|
||||
public IEntity Entity { get; set; }
|
||||
if (_transaction == null)
|
||||
_transaction = Database.GetTransaction();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the repository.
|
||||
/// </summary>
|
||||
/// <value>The repository.</value>
|
||||
public IUnitOfWorkRepository Repository { get; set; }
|
||||
protected override void DisposeResources()
|
||||
{
|
||||
base.DisposeResources();
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the type of operation.
|
||||
/// </summary>
|
||||
/// <value>The type of operation.</value>
|
||||
public TransactionType Type { get; set; }
|
||||
}
|
||||
// no transaction, nothing to do
|
||||
if (_transaction == null) return;
|
||||
|
||||
#endregion
|
||||
// will either complete or abort NPoco transaction
|
||||
// which means going one level up in the transaction stack
|
||||
// and commit or rollback only if at top of stack
|
||||
if (Completed)
|
||||
_transaction.Complete(); // complete the transaction
|
||||
else
|
||||
_transaction.Dispose(); // abort the transaction
|
||||
|
||||
/// <summary>
|
||||
/// Ensures disposable objects are disposed
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Ensures that the Transaction instance is disposed of
|
||||
/// </remarks>
|
||||
protected override void DisposeResources()
|
||||
{
|
||||
_operations.Clear();
|
||||
}
|
||||
}
|
||||
_transaction = null;
|
||||
}
|
||||
|
||||
public void ReadLockNodes(params int[] lockIds)
|
||||
{
|
||||
Begin(); // we need a transaction
|
||||
|
||||
if (Database.Transaction.IsolationLevel < IsolationLevel.RepeatableRead)
|
||||
throw new InvalidOperationException("A transaction with minimum RepeatableRead isolation level is required.");
|
||||
// *not* using a unique 'WHERE IN' query here because the *order* of lockIds is important to avoid deadlocks
|
||||
foreach (var lockId in lockIds)
|
||||
Database.ExecuteScalar<int>("SELECT sortOrder FROM umbracoNode WHERE id=@id",
|
||||
new { @id = lockId });
|
||||
}
|
||||
|
||||
public void WriteLockNodes(params int[] lockIds)
|
||||
{
|
||||
Begin(); // we need a transaction
|
||||
|
||||
if (Database.Transaction.IsolationLevel < IsolationLevel.RepeatableRead)
|
||||
throw new InvalidOperationException("A transaction with minimum RepeatableRead isolation level is required.");
|
||||
// *not* using a unique 'WHERE IN' query here because the *order* of lockIds is important to avoid deadlocks
|
||||
foreach (var lockId in lockIds)
|
||||
Database.Execute("UPDATE umbracoNode SET sortOrder = (CASE WHEN (sortOrder=1) THEN -1 ELSE 1 END) WHERE id=@id",
|
||||
new { @id = lockId });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,16 +12,20 @@ namespace Umbraco.Core.Persistence.UnitOfWork
|
||||
/// </summary>
|
||||
public class NPocoUnitOfWorkProvider : IDatabaseUnitOfWorkProvider
|
||||
{
|
||||
private readonly IDatabaseFactory _dbFactory;
|
||||
private readonly IDatabaseFactory _databaseFactory;
|
||||
private readonly RepositoryFactory _repositoryFactory;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="NPocoUnitOfWorkProvider"/> class with a database factory.
|
||||
/// Initializes a new instance of the <see cref="NPocoUnitOfWorkProvider"/> class with a database factory and a repository factory.
|
||||
/// </summary>
|
||||
/// <param name="dbFactory">A database factory implementation.</param>
|
||||
public NPocoUnitOfWorkProvider(IDatabaseFactory dbFactory)
|
||||
/// <param name="databaseFactory">A database factory.</param>
|
||||
/// <param name="repositoryFactory">A repository factory.</param>
|
||||
public NPocoUnitOfWorkProvider(IDatabaseFactory databaseFactory, RepositoryFactory repositoryFactory)
|
||||
{
|
||||
Mandate.ParameterNotNull(dbFactory, nameof(dbFactory));
|
||||
_dbFactory = dbFactory;
|
||||
Mandate.ParameterNotNull(databaseFactory, nameof(databaseFactory));
|
||||
Mandate.ParameterNotNull(repositoryFactory, nameof(repositoryFactory));
|
||||
_databaseFactory = databaseFactory;
|
||||
_repositoryFactory = repositoryFactory;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -35,8 +39,10 @@ namespace Umbraco.Core.Persistence.UnitOfWork
|
||||
/// <see cref="DefaultDatabaseFactory"/> with the default connection name, and default sql syntax providers.</para>
|
||||
/// </remarks>
|
||||
internal NPocoUnitOfWorkProvider(ILogger logger, IMappingResolver mappingResolver)
|
||||
: this(new DefaultDatabaseFactory(GlobalSettings.UmbracoConnectionName, GetDefaultSqlSyntaxProviders(logger), logger, new DefaultScopeContextFactory(), mappingResolver))
|
||||
{ }
|
||||
{
|
||||
_databaseFactory = new DefaultDatabaseFactory(GlobalSettings.UmbracoConnectionName, GetDefaultSqlSyntaxProviders(logger), logger, new DefaultScopeContextAdapter(), mappingResolver);
|
||||
// careful, _repositoryFactory remains null!
|
||||
}
|
||||
|
||||
// this should NOT be here, all tests should supply the appropriate providers,
|
||||
// however the above ctor is used in hundreds of tests at the moment, so...
|
||||
@@ -58,13 +64,13 @@ namespace Umbraco.Core.Persistence.UnitOfWork
|
||||
/// </summary>
|
||||
/// <returns>A unit of work.</returns>
|
||||
/// <remarks>The unit of work will execute on the database returned by the database factory.</remarks>
|
||||
public IDatabaseUnitOfWork GetUnitOfWork()
|
||||
public IDatabaseUnitOfWork CreateUnitOfWork()
|
||||
{
|
||||
// get a database from the factory - might be the "ambient" database eg
|
||||
// the one that's enlisted with the HttpContext - so it's not always a
|
||||
// "new" database.
|
||||
var database = _dbFactory.GetDatabase();
|
||||
return new NPocoUnitOfWork(database);
|
||||
var database = _databaseFactory.GetDatabase();
|
||||
return new NPocoUnitOfWork(database, _repositoryFactory);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -0,0 +1,144 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Umbraco.Core.Models.EntityBase;
|
||||
using Umbraco.Core.Persistence.Repositories;
|
||||
|
||||
namespace Umbraco.Core.Persistence.UnitOfWork
|
||||
{
|
||||
public abstract class UnitOfWorkBase : DisposableObject, IUnitOfWork
|
||||
{
|
||||
private readonly Queue<Operation> _operations = new Queue<Operation>();
|
||||
|
||||
protected UnitOfWorkBase(RepositoryFactory factory)
|
||||
{
|
||||
Factory = factory;
|
||||
}
|
||||
|
||||
protected RepositoryFactory Factory { get; }
|
||||
|
||||
public abstract TRepository CreateRepository<TRepository>(string name = null)
|
||||
where TRepository : IRepository;
|
||||
|
||||
/// <summary>
|
||||
/// Registers an entity to be added as part of this unit of work.
|
||||
/// </summary>
|
||||
/// <param name="entity">The entity.</param>
|
||||
/// <param name="repository">The repository in charge of the entity.</param>
|
||||
public void RegisterCreated(IEntity entity, IUnitOfWorkRepository repository)
|
||||
{
|
||||
Completed = false;
|
||||
_operations.Enqueue(new Operation
|
||||
{
|
||||
Entity = entity,
|
||||
Repository = repository,
|
||||
Type = OperationType.Insert
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Registers an entity to be updated as part of this unit of work.
|
||||
/// </summary>
|
||||
/// <param name="entity">The entity.</param>
|
||||
/// <param name="repository">The repository in charge of the entity.</param>
|
||||
public void RegisterUpdated(IEntity entity, IUnitOfWorkRepository repository)
|
||||
{
|
||||
Completed = false;
|
||||
_operations.Enqueue(new Operation
|
||||
{
|
||||
Entity = entity,
|
||||
Repository = repository,
|
||||
Type = OperationType.Update
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Registers an entity to be deleted as part of this unit of work.
|
||||
/// </summary>
|
||||
/// <param name="entity">The entity.</param>
|
||||
/// <param name="repository">The repository in charge of the entity.</param>
|
||||
public void RegisterDeleted(IEntity entity, IUnitOfWorkRepository repository)
|
||||
{
|
||||
Completed = false;
|
||||
_operations.Enqueue(new Operation
|
||||
{
|
||||
Entity = entity,
|
||||
Repository = repository,
|
||||
Type = OperationType.Delete
|
||||
});
|
||||
}
|
||||
|
||||
public virtual void Begin()
|
||||
{ }
|
||||
|
||||
public virtual void Flush()
|
||||
{
|
||||
Begin();
|
||||
|
||||
while (_operations.Count > 0)
|
||||
{
|
||||
var operation = _operations.Dequeue();
|
||||
switch (operation.Type)
|
||||
{
|
||||
case OperationType.Insert:
|
||||
operation.Repository.PersistNewItem(operation.Entity);
|
||||
break;
|
||||
case OperationType.Delete:
|
||||
operation.Repository.PersistDeletedItem(operation.Entity);
|
||||
break;
|
||||
case OperationType.Update:
|
||||
operation.Repository.PersistUpdatedItem(operation.Entity);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void Complete()
|
||||
{
|
||||
Flush();
|
||||
Completed = true;
|
||||
}
|
||||
|
||||
protected bool Completed { get; private set; }
|
||||
|
||||
protected override void DisposeResources()
|
||||
{
|
||||
// whatever hasn't been commited is lost
|
||||
// not sure we need this as we are being disposed...
|
||||
_operations.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides a snapshot of an entity and the repository reference it belongs to.
|
||||
/// </summary>
|
||||
private sealed class Operation
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the entity.
|
||||
/// </summary>
|
||||
/// <value>The entity.</value>
|
||||
public IEntity Entity { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the repository.
|
||||
/// </summary>
|
||||
/// <value>The repository.</value>
|
||||
public IUnitOfWorkRepository Repository { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the type of operation.
|
||||
/// </summary>
|
||||
/// <value>The type of operation.</value>
|
||||
public OperationType Type { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The types of unit of work operation.
|
||||
/// </summary>
|
||||
private enum OperationType
|
||||
{
|
||||
Insert,
|
||||
Update,
|
||||
Delete
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Persistence.Repositories;
|
||||
using Umbraco.Core.Persistence.UnitOfWork;
|
||||
|
||||
namespace Umbraco.Core.Persistence
|
||||
{
|
||||
internal static class UnitOfWorkExtensions
|
||||
{
|
||||
public static IPartialViewRepository CreatePartialViewRepository(this IUnitOfWork uow, PartialViewType partialViewType)
|
||||
{
|
||||
switch (partialViewType)
|
||||
{
|
||||
case PartialViewType.PartialView:
|
||||
return uow.CreateRepository<IPartialViewRepository>();
|
||||
case PartialViewType.PartialViewMacro:
|
||||
return uow.CreateRepository<IPartialViewMacroRepository>();
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(partialViewType));
|
||||
}
|
||||
}
|
||||
|
||||
public static IEntityContainerRepository CreateContainerRepository(this IUnitOfWork uow, Guid containerObjectType)
|
||||
{
|
||||
if (containerObjectType == Constants.ObjectTypes.DocumentTypeContainerGuid)
|
||||
return uow.CreateRepository<IDocumentTypeContainerRepository>();
|
||||
if (containerObjectType == Constants.ObjectTypes.MediaTypeContainerGuid)
|
||||
return uow.CreateRepository<IMediaTypeContainerRepository>();
|
||||
throw new ArgumentOutOfRangeException(nameof(containerObjectType));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,32 +5,33 @@ using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Persistence.Querying;
|
||||
using Umbraco.Core.Persistence.Repositories;
|
||||
using Umbraco.Core.Persistence.UnitOfWork;
|
||||
|
||||
namespace Umbraco.Core.Services
|
||||
{
|
||||
public sealed class AuditService : RepositoryService, IAuditService
|
||||
{
|
||||
public AuditService(IDatabaseUnitOfWorkProvider provider, RepositoryFactory repositoryFactory, ILogger logger, IEventMessagesFactory eventMessagesFactory)
|
||||
: base(provider, repositoryFactory, logger, eventMessagesFactory)
|
||||
public AuditService(IDatabaseUnitOfWorkProvider provider, ILogger logger, IEventMessagesFactory eventMessagesFactory)
|
||||
: base(provider, logger, eventMessagesFactory)
|
||||
{
|
||||
}
|
||||
|
||||
public void Add(AuditType type, string comment, int userId, int objectId)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repo = RepositoryFactory.CreateAuditRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repo = uow.CreateRepository<IAuditRepository>();
|
||||
repo.AddOrUpdate(new AuditItem(objectId, comment, type, userId));
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<AuditItem> GetLogs(int objectId)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repo = RepositoryFactory.CreateAuditRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repo = uow.CreateRepository<IAuditRepository>();
|
||||
var result = repo.GetByQuery(repo.Query.Where(x => x.Id == objectId));
|
||||
return result;
|
||||
}
|
||||
@@ -38,9 +39,9 @@ namespace Umbraco.Core.Services
|
||||
|
||||
public IEnumerable<AuditItem> GetUserLogs(int userId, AuditType type, DateTime? sinceDate = null)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repo = RepositoryFactory.CreateAuditRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repo = uow.CreateRepository<IAuditRepository>();
|
||||
var result = sinceDate.HasValue == false
|
||||
? repo.GetByQuery(repo.Query.Where(x => x.UserId == userId && x.AuditType == type))
|
||||
: repo.GetByQuery(repo.Query.Where(x => x.UserId == userId && x.AuditType == type && x.CreateDate >= sinceDate.Value));
|
||||
@@ -50,9 +51,9 @@ namespace Umbraco.Core.Services
|
||||
|
||||
public IEnumerable<AuditItem> GetLogs(AuditType type, DateTime? sinceDate = null)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repo = RepositoryFactory.CreateAuditRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repo = uow.CreateRepository<IAuditRepository>();
|
||||
var result = sinceDate.HasValue == false
|
||||
? repo.GetByQuery(repo.Query.Where(x => x.AuditType == type))
|
||||
: repo.GetByQuery(repo.Query.Where(x => x.AuditType == type && x.CreateDate >= sinceDate.Value));
|
||||
@@ -62,8 +63,9 @@ namespace Umbraco.Core.Services
|
||||
|
||||
public void CleanLogs(int maximumAgeOfLogsInMinutes)
|
||||
{
|
||||
using (var repo = RepositoryFactory.CreateAuditRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repo = uow.CreateRepository<IAuditRepository>();
|
||||
repo.CleanLogs(maximumAgeOfLogsInMinutes);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Xml.Linq;
|
||||
using Umbraco.Core.Auditing;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Events;
|
||||
using Umbraco.Core.Logging;
|
||||
@@ -35,20 +34,19 @@ namespace Umbraco.Core.Services
|
||||
private readonly IUserService _userService;
|
||||
private readonly IEnumerable<IUrlSegmentProvider> _urlSegmentProviders;
|
||||
|
||||
//Support recursive locks because some of the methods that require locking call other methods that require locking.
|
||||
//Support recursive locks because some of the methods that require locking call other methods that require locking.
|
||||
//for example, the Move method needs to be locked but this calls the Save method which also needs to be locked.
|
||||
private static readonly ReaderWriterLockSlim Locker = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
|
||||
|
||||
public ContentService(
|
||||
IDatabaseUnitOfWorkProvider provider,
|
||||
RepositoryFactory repositoryFactory,
|
||||
ILogger logger,
|
||||
IEventMessagesFactory eventMessagesFactory,
|
||||
IPublishingStrategy publishingStrategy,
|
||||
IDataTypeService dataTypeService,
|
||||
IUserService userService,
|
||||
IEnumerable<IUrlSegmentProvider> urlSegmentProviders)
|
||||
: base(provider, repositoryFactory, logger, eventMessagesFactory)
|
||||
: base(provider, logger, eventMessagesFactory)
|
||||
{
|
||||
if (publishingStrategy == null) throw new ArgumentNullException("publishingStrategy");
|
||||
if (dataTypeService == null) throw new ArgumentNullException("dataTypeService");
|
||||
@@ -62,36 +60,36 @@ namespace Umbraco.Core.Services
|
||||
|
||||
public int CountPublished(string contentTypeAlias = null)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateContentRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IContentRepository>();
|
||||
return repository.CountPublished();
|
||||
}
|
||||
}
|
||||
|
||||
public int Count(string contentTypeAlias = null)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateContentRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IContentRepository>();
|
||||
return repository.Count(contentTypeAlias);
|
||||
}
|
||||
}
|
||||
|
||||
public int CountChildren(int parentId, string contentTypeAlias = null)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateContentRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IContentRepository>();
|
||||
return repository.CountChildren(parentId, contentTypeAlias);
|
||||
}
|
||||
}
|
||||
|
||||
public int CountDescendants(int parentId, string contentTypeAlias = null)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateContentRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IContentRepository>();
|
||||
return repository.CountDescendants(parentId, contentTypeAlias);
|
||||
}
|
||||
}
|
||||
@@ -103,9 +101,9 @@ namespace Umbraco.Core.Services
|
||||
/// <param name="permissionSet"></param>
|
||||
public void ReplaceContentPermissions(EntityPermissionSet permissionSet)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateContentRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IContentRepository>();
|
||||
repository.ReplaceContentPermissions(permissionSet);
|
||||
}
|
||||
}
|
||||
@@ -118,9 +116,9 @@ namespace Umbraco.Core.Services
|
||||
/// <param name="userIds"></param>
|
||||
public void AssignContentPermission(IContent entity, char permission, IEnumerable<int> userIds)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateContentRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IContentRepository>();
|
||||
repository.AssignEntityPermission(entity, permission, userIds);
|
||||
}
|
||||
}
|
||||
@@ -132,9 +130,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns></returns>
|
||||
public IEnumerable<EntityPermission> GetPermissionsForEntity(IContent content)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateContentRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IContentRepository>();
|
||||
return repository.GetPermissionsForEntity(content.Id);
|
||||
}
|
||||
}
|
||||
@@ -172,11 +170,11 @@ namespace Umbraco.Core.Services
|
||||
|
||||
Created.RaiseEvent(new NewEventArgs<IContent>(content, false, contentTypeAlias, parentId), this);
|
||||
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var auditRepo = RepositoryFactory.CreateAuditRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
auditRepo.AddOrUpdate(new AuditItem(content.Id, string.Format("Content '{0}' was created", name), AuditType.New, content.CreatorId));
|
||||
uow.Commit();
|
||||
var repo = uow.CreateRepository<IAuditRepository>();
|
||||
repo.AddOrUpdate(new AuditItem(content.Id, $"Content '{name}' was created", AuditType.New, content.CreatorId));
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
return content;
|
||||
@@ -252,22 +250,20 @@ namespace Umbraco.Core.Services
|
||||
return content;
|
||||
}
|
||||
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateContentRepository(uow))
|
||||
content.CreatorId = userId;
|
||||
content.WriterId = userId;
|
||||
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
content.CreatorId = userId;
|
||||
content.WriterId = userId;
|
||||
var repository = uow.CreateRepository<IContentRepository>();
|
||||
repository.AddOrUpdate(content);
|
||||
//Generate a new preview
|
||||
repository.AddOrUpdatePreviewXml(content, c => _entitySerializer.Serialize(this, _dataTypeService, _userService, _urlSegmentProviders, c));
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
Saved.RaiseEvent(new SaveEventArgs<IContent>(content, false), this);
|
||||
|
||||
Created.RaiseEvent(new NewEventArgs<IContent>(content, false, contentTypeAlias, parentId), this);
|
||||
|
||||
Audit(AuditType.New, string.Format("Content '{0}' was created with Id {1}", name, content.Id), content.CreatorId, content.Id);
|
||||
Audit(AuditType.New, $"Content '{name}' was created with Id {content.Id}", content.CreatorId, content.Id);
|
||||
|
||||
return content;
|
||||
}
|
||||
@@ -306,22 +302,20 @@ namespace Umbraco.Core.Services
|
||||
return content;
|
||||
}
|
||||
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateContentRepository(uow))
|
||||
content.CreatorId = userId;
|
||||
content.WriterId = userId;
|
||||
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
content.CreatorId = userId;
|
||||
content.WriterId = userId;
|
||||
var repository = uow.CreateRepository<IContentRepository>();
|
||||
repository.AddOrUpdate(content);
|
||||
//Generate a new preview
|
||||
repository.AddOrUpdatePreviewXml(content, c => _entitySerializer.Serialize(this, _dataTypeService, _userService, _urlSegmentProviders, c));
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
Saved.RaiseEvent(new SaveEventArgs<IContent>(content, false), this);
|
||||
|
||||
Created.RaiseEvent(new NewEventArgs<IContent>(content, false, contentTypeAlias, parent), this);
|
||||
|
||||
Audit(AuditType.New, string.Format("Content '{0}' was created with Id {1}", name, content.Id), content.CreatorId, content.Id);
|
||||
Audit(AuditType.New, $"Content '{name}' was created with Id {content.Id}", content.CreatorId, content.Id);
|
||||
|
||||
return content;
|
||||
}
|
||||
@@ -333,8 +327,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns><see cref="IContent"/></returns>
|
||||
public IContent GetById(int id)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateContentRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IContentRepository>();
|
||||
return repository.Get(id);
|
||||
}
|
||||
}
|
||||
@@ -348,8 +343,9 @@ namespace Umbraco.Core.Services
|
||||
{
|
||||
if (ids.Any() == false) return Enumerable.Empty<IContent>();
|
||||
|
||||
using (var repository = RepositoryFactory.CreateContentRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IContentRepository>();
|
||||
return repository.GetAll(ids.ToArray());
|
||||
}
|
||||
}
|
||||
@@ -361,8 +357,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns><see cref="IContent"/></returns>
|
||||
public IContent GetById(Guid key)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateContentRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IContentRepository>();
|
||||
var query = repository.Query.Where(x => x.Key == key);
|
||||
var contents = repository.GetByQuery(query);
|
||||
return contents.SingleOrDefault();
|
||||
@@ -376,8 +373,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>An Enumerable list of <see cref="IContent"/> objects</returns>
|
||||
public IEnumerable<IContent> GetContentOfContentType(int id)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateContentRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IContentRepository>();
|
||||
var query = repository.Query.Where(x => x.ContentTypeId == id);
|
||||
var contents = repository.GetByQuery(query);
|
||||
|
||||
@@ -387,8 +385,9 @@ namespace Umbraco.Core.Services
|
||||
|
||||
internal IEnumerable<IContent> GetPublishedContentOfContentType(int id)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateContentRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IContentRepository>();
|
||||
var query = repository.Query.Where(x => x.ContentTypeId == id);
|
||||
var contents = repository.GetByPublishedVersion(query);
|
||||
|
||||
@@ -403,8 +402,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>An Enumerable list of <see cref="IContent"/> objects</returns>
|
||||
public IEnumerable<IContent> GetByLevel(int level)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateContentRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IContentRepository>();
|
||||
var query = repository.Query.Where(x => x.Level == level && !x.Path.StartsWith(Constants.System.RecycleBinContent.ToInvariantString()));
|
||||
var contents = repository.GetByQuery(query);
|
||||
|
||||
@@ -419,8 +419,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>An <see cref="IContent"/> item</returns>
|
||||
public IContent GetByVersion(Guid versionId)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateContentRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IContentRepository>();
|
||||
return repository.GetByVersion(versionId);
|
||||
}
|
||||
}
|
||||
@@ -433,8 +434,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>An Enumerable list of <see cref="IContent"/> objects</returns>
|
||||
public IEnumerable<IContent> GetVersions(int id)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateContentRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IContentRepository>();
|
||||
var versions = repository.GetAllVersions(id);
|
||||
return versions;
|
||||
}
|
||||
@@ -465,8 +467,9 @@ namespace Umbraco.Core.Services
|
||||
if (ids.Any() == false)
|
||||
return new List<IContent>();
|
||||
|
||||
using (var repository = RepositoryFactory.CreateContentRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IContentRepository>();
|
||||
return repository.GetAll(ids);
|
||||
}
|
||||
}
|
||||
@@ -478,8 +481,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>An Enumerable list of <see cref="IContent"/> objects</returns>
|
||||
public IEnumerable<IContent> GetChildren(int id)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateContentRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IContentRepository>();
|
||||
var query = repository.Query.Where(x => x.ParentId == id);
|
||||
var contents = repository.GetByQuery(query).OrderBy(x => x.SortOrder);
|
||||
|
||||
@@ -501,8 +505,9 @@ namespace Umbraco.Core.Services
|
||||
public IEnumerable<IContent> GetPagedChildren(int id, long pageIndex, int pageSize, out long totalChildren,
|
||||
string orderBy, Direction orderDirection, string filter = "")
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateContentRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IContentRepository>();
|
||||
IQuery<IContent> filterQuery = null;
|
||||
if (filter.IsNullOrWhiteSpace() == false)
|
||||
{
|
||||
@@ -529,8 +534,9 @@ namespace Umbraco.Core.Services
|
||||
{
|
||||
Mandate.ParameterCondition(pageIndex >= 0, "pageIndex");
|
||||
Mandate.ParameterCondition(pageSize > 0, "pageSize");
|
||||
using (var repository = RepositoryFactory.CreateContentRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IContentRepository>();
|
||||
|
||||
var query = repository.Query;
|
||||
//if the id is System Root, then just get all
|
||||
@@ -555,11 +561,12 @@ namespace Umbraco.Core.Services
|
||||
/// <param name="orderBy">Field to order by</param>
|
||||
/// <param name="orderDirection">Direction to order by</param>
|
||||
/// <param name="filter">Search text filter</param>
|
||||
/// <returns>An Enumerable list of <see cref="IContent"/> objects</returns>
|
||||
/// <returns>An Enumerable list of <see cref="IContent"/> objects</returns>
|
||||
public IEnumerable<IContent> GetPagedDescendants(int id, long pageIndex, int pageSize, out long totalChildren, string orderBy = "Path", Direction orderDirection = Direction.Ascending, string filter = "")
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateContentRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IContentRepository>();
|
||||
IQuery<IContent> filterQuery = null;
|
||||
if (filter.IsNullOrWhiteSpace() == false)
|
||||
{
|
||||
@@ -579,15 +586,15 @@ namespace Umbraco.Core.Services
|
||||
/// <param name="orderBy">Field to order by</param>
|
||||
/// <param name="orderDirection">Direction to order by</param>
|
||||
/// <param name="orderBySystemField">Flag to indicate when ordering by system field</param>
|
||||
/// <param name="filter">Search text filter</param>
|
||||
/// <param name="filterArgs"></param>
|
||||
/// <returns>An Enumerable list of <see cref="IContent"/> objects</returns>
|
||||
/// <param name="filter">Search filter</param>
|
||||
/// <returns>An Enumerable list of <see cref="IContent"/> objects</returns>
|
||||
public IEnumerable<IContent> GetPagedDescendants(int id, long pageIndex, int pageSize, out long totalChildren, string orderBy, Direction orderDirection, bool orderBySystemField, IQuery<IContent> filter)
|
||||
{
|
||||
Mandate.ParameterCondition(pageIndex >= 0, "pageIndex");
|
||||
Mandate.ParameterCondition(pageSize > 0, "pageSize");
|
||||
using (var repository = RepositoryFactory.CreateContentRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IContentRepository>();
|
||||
|
||||
var query = repository.Query;
|
||||
//if the id is System Root, then just get all
|
||||
@@ -609,8 +616,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>An Enumerable list of <see cref="IContent"/> objects</returns>
|
||||
public IEnumerable<IContent> GetChildrenByName(int parentId, string name)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateContentRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IContentRepository>();
|
||||
var query = repository.Query.Where(x => x.ParentId == parentId && x.Name.Contains(name));
|
||||
var contents = repository.GetByQuery(query);
|
||||
|
||||
@@ -640,8 +648,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>An Enumerable list of <see cref="IContent"/> objects</returns>
|
||||
public IEnumerable<IContent> GetDescendants(IContent content)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateContentRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IContentRepository>();
|
||||
var pathMatch = content.Path + ",";
|
||||
var query = repository.Query.Where(x => x.Path.StartsWith(pathMatch) && x.Id != content.Id);
|
||||
var contents = repository.GetByQuery(query);
|
||||
@@ -704,8 +713,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>An Enumerable list of <see cref="IContent"/> objects</returns>
|
||||
public IEnumerable<IContent> GetRootContent()
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateContentRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IContentRepository>();
|
||||
var query = repository.Query.Where(x => x.ParentId == Constants.System.Root);
|
||||
var contents = repository.GetByQuery(query);
|
||||
|
||||
@@ -719,8 +729,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns></returns>
|
||||
internal IEnumerable<IContent> GetAllPublished()
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateContentRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IContentRepository>();
|
||||
var query = repository.Query.Where(x => x.Trashed == false);
|
||||
return repository.GetByPublishedVersion(query);
|
||||
}
|
||||
@@ -732,8 +743,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>An Enumerable list of <see cref="IContent"/> objects</returns>
|
||||
public IEnumerable<IContent> GetContentForExpiration()
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateContentRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IContentRepository>();
|
||||
var query = repository.Query.Where(x => x.Published == true && x.ExpireDate <= DateTime.Now);
|
||||
var contents = repository.GetByQuery(query);
|
||||
|
||||
@@ -747,8 +759,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>An Enumerable list of <see cref="IContent"/> objects</returns>
|
||||
public IEnumerable<IContent> GetContentForRelease()
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateContentRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IContentRepository>();
|
||||
var query = repository.Query.Where(x => x.Published == false && x.ReleaseDate <= DateTime.Now);
|
||||
var contents = repository.GetByQuery(query);
|
||||
|
||||
@@ -762,8 +775,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>An Enumerable list of <see cref="IContent"/> objects</returns>
|
||||
public IEnumerable<IContent> GetContentInRecycleBin()
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateContentRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IContentRepository>();
|
||||
var query = repository.Query.Where(x => x.Path.Contains(Constants.System.RecycleBinContent.ToInvariantString()));
|
||||
var contents = repository.GetByQuery(query);
|
||||
|
||||
@@ -785,8 +799,9 @@ namespace Umbraco.Core.Services
|
||||
|
||||
internal int CountChildren(int id)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateContentRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IContentRepository>();
|
||||
var query = repository.Query.Where(x => x.ParentId == id);
|
||||
var count = repository.Count(query);
|
||||
return count;
|
||||
@@ -800,8 +815,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>True if the content has any published version otherwise False</returns>
|
||||
public bool HasPublishedVersion(int id)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateContentRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IContentRepository>();
|
||||
var query = repository.Query.Where(x => x.Published == true && x.Id == id && x.Trashed == false);
|
||||
int count = repository.Count(query);
|
||||
return count > 0;
|
||||
@@ -827,12 +843,12 @@ namespace Umbraco.Core.Services
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This will rebuild the xml structures for content in the database.
|
||||
/// This will rebuild the xml structures for content in the database.
|
||||
/// </summary>
|
||||
/// <param name="userId">This is not used for anything</param>
|
||||
/// <returns>True if publishing succeeded, otherwise False</returns>
|
||||
/// <remarks>
|
||||
/// This is used for when a document type alias or a document type property is changed, the xml will need to
|
||||
/// This is used for when a document type alias or a document type property is changed, the xml will need to
|
||||
/// be regenerated.
|
||||
/// </remarks>
|
||||
public bool RePublishAll(int userId = 0)
|
||||
@@ -850,7 +866,7 @@ namespace Umbraco.Core.Services
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This will rebuild the xml structures for content in the database.
|
||||
/// This will rebuild the xml structures for content in the database.
|
||||
/// </summary>
|
||||
/// <param name="contentTypeIds">
|
||||
/// If specified will only rebuild the xml for the content type's specified, otherwise will update the structure
|
||||
@@ -946,28 +962,27 @@ namespace Umbraco.Core.Services
|
||||
UnPublish(descendant, userId);
|
||||
}
|
||||
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateContentRepository(uow))
|
||||
content.WriterId = userId;
|
||||
content.ChangeTrashedState(true);
|
||||
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
content.WriterId = userId;
|
||||
content.ChangeTrashedState(true);
|
||||
var repository = uow.CreateRepository<IContentRepository>();
|
||||
repository.AddOrUpdate(content);
|
||||
|
||||
//Loop through descendants to update their trash state, but ensuring structure by keeping the ParentId
|
||||
foreach (var descendant in descendants)
|
||||
{
|
||||
moveInfo.Add(new MoveEventInfo<IContent>(descendant, descendant.Path, descendant.ParentId));
|
||||
|
||||
descendant.WriterId = userId;
|
||||
descendant.ChangeTrashedState(true, descendant.ParentId);
|
||||
repository.AddOrUpdate(descendant);
|
||||
}
|
||||
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
Trashed.RaiseEvent(new MoveEventArgs<IContent>(false, evtMsgs, moveInfo.ToArray()), this);
|
||||
|
||||
Audit(AuditType.Move, "Move Content to Recycle Bin performed by user", userId, content.Id);
|
||||
|
||||
return OperationStatus.Success(evtMsgs);
|
||||
@@ -1077,10 +1092,10 @@ namespace Umbraco.Core.Services
|
||||
|
||||
/// <summary>
|
||||
/// Saves a collection of <see cref="IContent"/> objects.
|
||||
/// </summary>
|
||||
/// </summary>
|
||||
/// <param name="contents">Collection of <see cref="IContent"/> to save</param>
|
||||
/// <param name="userId">Optional Id of the User saving the Content</param>
|
||||
/// <param name="raiseEvents">Optional boolean indicating whether or not to raise events.</param>
|
||||
/// <param name="raiseEvents">Optional boolean indicating whether or not to raise events.</param>
|
||||
Attempt<OperationStatus> IContentServiceOperations.Save(IEnumerable<IContent> contents, int userId, bool raiseEvents)
|
||||
{
|
||||
var asArray = contents.ToArray();
|
||||
@@ -1100,9 +1115,9 @@ namespace Umbraco.Core.Services
|
||||
{
|
||||
var containsNew = asArray.Any(x => x.HasIdentity == false);
|
||||
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateContentRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IContentRepository>();
|
||||
if (containsNew)
|
||||
{
|
||||
foreach (var content in asArray)
|
||||
@@ -1129,12 +1144,11 @@ namespace Umbraco.Core.Services
|
||||
}
|
||||
}
|
||||
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
if (raiseEvents)
|
||||
Saved.RaiseEvent(new SaveEventArgs<IContent>(asArray, false, evtMsgs), this);
|
||||
|
||||
Audit(AuditType.Save, "Bulk Save content performed by user", userId == -1 ? 0 : userId, Constants.System.Root);
|
||||
|
||||
return OperationStatus.Success(evtMsgs);
|
||||
@@ -1176,11 +1190,11 @@ namespace Umbraco.Core.Services
|
||||
Delete(child, userId);
|
||||
}
|
||||
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateContentRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IContentRepository>();
|
||||
repository.Delete(content);
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
|
||||
var args = new DeleteEventArgs<IContent>(content, false, evtMsgs);
|
||||
Deleted.RaiseEvent(args, this);
|
||||
@@ -1240,18 +1254,18 @@ namespace Umbraco.Core.Services
|
||||
/// <param name="userId">Optional Id of the user issueing the delete operation</param>
|
||||
public void DeleteContentOfType(int contentTypeId, int userId = 0)
|
||||
{
|
||||
//TODO: This currently this is called from the ContentTypeService but that needs to change,
|
||||
//TODO: This currently this is called from the ContentTypeService but that needs to change,
|
||||
// if we are deleting a content type, we should just delete the data and do this operation slightly differently.
|
||||
// This method will recursively go lookup every content item, check if any of it's descendants are
|
||||
// of a different type, move them to the recycle bin, then permanently delete the content items.
|
||||
// of a different type, move them to the recycle bin, then permanently delete the content items.
|
||||
// The main problem with this is that for every content item being deleted, events are raised...
|
||||
// which we need for many things like keeping caches in sync, but we can surely do this MUCH better.
|
||||
|
||||
using (new WriteLock(Locker))
|
||||
{
|
||||
using (var uow = UowProvider.GetUnitOfWork())
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = RepositoryFactory.CreateContentRepository(uow);
|
||||
var repository = uow.CreateRepository<IContentRepository>();
|
||||
//NOTE What about content that has the contenttype as part of its composition?
|
||||
var query = repository.Query.Where(x => x.ContentTypeId == contentTypeId);
|
||||
var contents = repository.GetByQuery(query).ToArray();
|
||||
@@ -1309,11 +1323,11 @@ namespace Umbraco.Core.Services
|
||||
if (DeletingVersions.IsRaisedEventCancelled(new DeleteRevisionsEventArgs(id, dateToRetain: versionDate), this))
|
||||
return;
|
||||
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateContentRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IContentRepository>();
|
||||
repository.DeleteVersions(id, versionDate);
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
DeletedVersions.RaiseEvent(new DeleteRevisionsEventArgs(id, false, dateToRetain: versionDate), this);
|
||||
@@ -1342,11 +1356,11 @@ namespace Umbraco.Core.Services
|
||||
DeleteVersions(id, content.UpdateDate, userId);
|
||||
}
|
||||
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateContentRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IContentRepository>();
|
||||
repository.DeleteVersion(versionId);
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
DeletedVersions.RaiseEvent(new DeleteRevisionsEventArgs(id, false, specificVersion: versionId), this);
|
||||
@@ -1419,8 +1433,9 @@ namespace Umbraco.Core.Services
|
||||
bool success;
|
||||
var nodeObjectType = new Guid(Constants.ObjectTypes.Document);
|
||||
|
||||
using (var repository = RepositoryFactory.CreateContentRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IContentRepository>();
|
||||
//Create a dictionary of ids -> dictionary of property aliases + values
|
||||
entities = repository.GetEntitiesInRecycleBin()
|
||||
.ToDictionary(
|
||||
@@ -1444,7 +1459,7 @@ namespace Umbraco.Core.Services
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copies an <see cref="IContent"/> object by creating a new Content object of the same type and copies all data from the current
|
||||
/// Copies an <see cref="IContent"/> object by creating a new Content object of the same type and copies all data from the current
|
||||
/// to the new copy which is returned. Recursively copies all children.
|
||||
/// </summary>
|
||||
/// <param name="content">The <see cref="IContent"/> to copy</param>
|
||||
@@ -1458,7 +1473,7 @@ namespace Umbraco.Core.Services
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copies an <see cref="IContent"/> object by creating a new Content object of the same type and copies all data from the current
|
||||
/// Copies an <see cref="IContent"/> object by creating a new Content object of the same type and copies all data from the current
|
||||
/// to the new copy which is returned.
|
||||
/// </summary>
|
||||
/// <param name="content">The <see cref="IContent"/> to copy</param>
|
||||
@@ -1483,9 +1498,9 @@ namespace Umbraco.Core.Services
|
||||
if (Copying.IsRaisedEventCancelled(new CopyEventArgs<IContent>(content, copy, parentId), this))
|
||||
return null;
|
||||
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateContentRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IContentRepository>();
|
||||
// Update the create author and last edit author
|
||||
copy.CreatorId = userId;
|
||||
copy.WriterId = userId;
|
||||
@@ -1493,7 +1508,7 @@ namespace Umbraco.Core.Services
|
||||
repository.AddOrUpdate(copy);
|
||||
//add or update a preview
|
||||
repository.AddOrUpdatePreviewXml(copy, c => _entitySerializer.Serialize(this, _dataTypeService, _userService, _urlSegmentProviders, c));
|
||||
uow.Commit();
|
||||
uow.Flush(); // ensure copy has an ID
|
||||
|
||||
|
||||
//Special case for the associated tags
|
||||
@@ -1508,6 +1523,8 @@ namespace Umbraco.Core.Services
|
||||
uow.Database.Insert(new TagRelationshipDto { NodeId = copy.Id, TagId = tag.TagId, PropertyTypeId = tag.PropertyTypeId });
|
||||
}
|
||||
}
|
||||
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
if (recursive)
|
||||
@@ -1570,21 +1587,19 @@ namespace Umbraco.Core.Services
|
||||
if (RollingBack.IsRaisedEventCancelled(new RollbackEventArgs<IContent>(content), this))
|
||||
return content;
|
||||
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateContentRepository(uow))
|
||||
{
|
||||
content.WriterId = userId;
|
||||
content.CreatorId = userId;
|
||||
content.ChangePublishedState(PublishedState.Unpublished);
|
||||
content.WriterId = userId;
|
||||
content.CreatorId = userId;
|
||||
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IContentRepository>();
|
||||
content.ChangePublishedState(PublishedState.Unpublished);
|
||||
repository.AddOrUpdate(content);
|
||||
//add or update a preview
|
||||
repository.AddOrUpdatePreviewXml(content, c => _entitySerializer.Serialize(this, _dataTypeService, _userService, _urlSegmentProviders, c));
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
RolledBack.RaiseEvent(new RollbackEventArgs<IContent>(content, false), this);
|
||||
|
||||
Audit(AuditType.RollBack, "Content rollback performed by user", content.WriterId, content.Id);
|
||||
|
||||
return content;
|
||||
@@ -1616,9 +1631,9 @@ namespace Umbraco.Core.Services
|
||||
var asArray = items.ToArray();
|
||||
using (new WriteLock(Locker))
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateContentRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IContentRepository>();
|
||||
int i = 0;
|
||||
foreach (var content in asArray)
|
||||
{
|
||||
@@ -1655,7 +1670,7 @@ namespace Umbraco.Core.Services
|
||||
repository.AddOrUpdateContentXml(content, c => _entitySerializer.Serialize(this, _dataTypeService, _userService, _urlSegmentProviders, c));
|
||||
}
|
||||
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1681,9 +1696,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns></returns>
|
||||
public XElement GetContentXml(int contentId)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateContentRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IContentRepository>();
|
||||
return repository.GetContentXml(contentId);
|
||||
}
|
||||
}
|
||||
@@ -1696,9 +1711,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns></returns>
|
||||
public XElement GetContentPreviewXml(int contentId, Guid version)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateContentRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IContentRepository>();
|
||||
return repository.GetContentPreviewXml(contentId, version);
|
||||
}
|
||||
}
|
||||
@@ -1712,14 +1727,13 @@ namespace Umbraco.Core.Services
|
||||
/// </param>
|
||||
public void RebuildXmlStructures(params int[] contentTypeIds)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateContentRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IContentRepository>();
|
||||
repository.RebuildXmlStructures(
|
||||
content => _entitySerializer.Serialize(this, _dataTypeService, _userService, _urlSegmentProviders, content),
|
||||
contentTypeIds: contentTypeIds.Length == 0 ? null : contentTypeIds);
|
||||
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
Audit(AuditType.Publish, "ContentService.RebuildXmlStructures completed, the xml has been regenerated in the database", 0, Constants.System.Root);
|
||||
@@ -1735,8 +1749,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>An Enumerable list of <see cref="IContent"/> objects</returns>
|
||||
internal IEnumerable<IContent> GetPublishedDescendants(IContent content)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateContentRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IContentRepository>();
|
||||
var query = repository.Query.Where(x => x.Id != content.Id && x.Path.StartsWith(content.Path) && x.Trashed == false);
|
||||
var contents = repository.GetByPublishedVersion(query);
|
||||
|
||||
@@ -1750,11 +1765,11 @@ namespace Umbraco.Core.Services
|
||||
|
||||
private void Audit(AuditType type, string message, int userId, int objectId)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var auditRepo = RepositoryFactory.CreateAuditRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
auditRepo.AddOrUpdate(new AuditItem(objectId, message, type, userId));
|
||||
uow.Commit();
|
||||
var repo = uow.CreateRepository<IAuditRepository>();
|
||||
repo.AddOrUpdate(new AuditItem(objectId, message, type, userId));
|
||||
uow.Complete();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1802,9 +1817,9 @@ namespace Umbraco.Core.Services
|
||||
//TODO: This is raising events, probably not desirable as this costs performance for event listeners like Examine
|
||||
Save(content, false, userId);
|
||||
|
||||
//TODO: This shouldn't be here! This needs to be part of the repository logic but in order to fix this we need to
|
||||
//TODO: This shouldn't be here! This needs to be part of the repository logic but in order to fix this we need to
|
||||
// change how this method calls "Save" as it needs to save using an internal method
|
||||
using (var uow = UowProvider.GetUnitOfWork())
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var xml = _entitySerializer.Serialize(this, _dataTypeService, _userService, _urlSegmentProviders, content);
|
||||
|
||||
@@ -1840,7 +1855,7 @@ namespace Umbraco.Core.Services
|
||||
/// </summary>
|
||||
/// <param name="content">The <see cref="IContent"/> to publish along with its children</param>
|
||||
/// <param name="userId">Optional Id of the User issueing the publishing</param>
|
||||
/// <param name="includeUnpublished">If set to true, this will also publish descendants that are completely unpublished, normally this will only publish children that have previously been published</param>
|
||||
/// <param name="includeUnpublished">If set to true, this will also publish descendants that are completely unpublished, normally this will only publish children that have previously been published</param>
|
||||
/// <returns>
|
||||
/// A list of publish statues. If the parent document is not valid or cannot be published because it's parent(s) is not published
|
||||
/// then the list will only contain one status item, otherwise it will contain status items for it and all of it's descendants that
|
||||
@@ -1901,9 +1916,9 @@ namespace Umbraco.Core.Services
|
||||
.OrderBy(x => x.Result.ContentItem.Level)
|
||||
.ThenBy(x => x.Result.ContentItem.SortOrder);
|
||||
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateContentRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IContentRepository>();
|
||||
//NOTE The Publish with subpages-dialog was used more as a republish-type-thing, so we'll have to include PublishStatusType.SuccessAlreadyPublished
|
||||
//in the updated-list, so the Published event is triggered with the expected set of pages and the xml is updated.
|
||||
foreach (var item in published)
|
||||
@@ -1917,7 +1932,7 @@ namespace Umbraco.Core.Services
|
||||
updated.Add(item.Result.ContentItem);
|
||||
}
|
||||
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
|
||||
}
|
||||
//Save xml to db and call following method to fire event:
|
||||
@@ -1954,17 +1969,17 @@ namespace Umbraco.Core.Services
|
||||
var unpublished = _publishingStrategy.UnPublish(content, userId);
|
||||
if (unpublished == false) return Attempt.Fail(new UnPublishStatus(content, UnPublishedStatusType.FailedCancelledByEvent, evtMsgs));
|
||||
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateContentRepository(uow))
|
||||
content.WriterId = userId;
|
||||
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
content.WriterId = userId;
|
||||
var repository = uow.CreateRepository<IContentRepository>();
|
||||
repository.AddOrUpdate(content);
|
||||
// is published is not newest, reset the published flag on published version
|
||||
if (published.Version != content.Version)
|
||||
repository.ClearPublished(published);
|
||||
repository.DeleteContentXml(content);
|
||||
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
}
|
||||
//Delete xml from db? and call following method to fire event through PublishingStrategy to update cache
|
||||
if (omitCacheRefresh == false)
|
||||
@@ -2024,9 +2039,9 @@ namespace Umbraco.Core.Services
|
||||
//we are successfully published if our publishStatus is still Successful
|
||||
bool published = publishStatus.StatusType == PublishStatusType.Success;
|
||||
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateContentRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IContentRepository>();
|
||||
if (published == false)
|
||||
{
|
||||
content.ChangePublishedState(PublishedState.Saved);
|
||||
@@ -2049,7 +2064,7 @@ namespace Umbraco.Core.Services
|
||||
repository.AddOrUpdateContentXml(content, c => _entitySerializer.Serialize(this, _dataTypeService, _userService, _urlSegmentProviders, c));
|
||||
}
|
||||
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
if (raiseEvents)
|
||||
@@ -2098,9 +2113,9 @@ namespace Umbraco.Core.Services
|
||||
|
||||
using (new WriteLock(Locker))
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateContentRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IContentRepository>();
|
||||
if (content.HasIdentity == false)
|
||||
{
|
||||
content.CreatorId = userId;
|
||||
@@ -2116,7 +2131,7 @@ namespace Umbraco.Core.Services
|
||||
//Generate a new preview
|
||||
repository.AddOrUpdatePreviewXml(content, c => _entitySerializer.Serialize(this, _dataTypeService, _userService, _urlSegmentProviders, c));
|
||||
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
if (raiseEvents)
|
||||
@@ -2210,8 +2225,9 @@ namespace Umbraco.Core.Services
|
||||
|
||||
private IContentType FindContentTypeByAlias(string contentTypeAlias)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateContentTypeRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IContentTypeRepository>();
|
||||
var query = repository.Query.Where(x => x.Alias == contentTypeAlias);
|
||||
var types = repository.GetByQuery(query);
|
||||
|
||||
@@ -2276,7 +2292,7 @@ namespace Umbraco.Core.Services
|
||||
#region Event Handlers
|
||||
/// <summary>
|
||||
/// Occurs before Delete
|
||||
/// </summary>
|
||||
/// </summary>
|
||||
public static event TypedEventHandler<IContentService, DeleteEventArgs<IContent>> Deleting;
|
||||
|
||||
/// <summary>
|
||||
@@ -2286,7 +2302,7 @@ namespace Umbraco.Core.Services
|
||||
|
||||
/// <summary>
|
||||
/// Occurs before Delete Versions
|
||||
/// </summary>
|
||||
/// </summary>
|
||||
public static event TypedEventHandler<IContentService, DeleteRevisionsEventArgs> DeletingVersions;
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -7,7 +7,6 @@ using System.Text;
|
||||
using System.Xml.Linq;
|
||||
using System.Threading;
|
||||
using AutoMapper;
|
||||
using Umbraco.Core.Auditing;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Events;
|
||||
using Umbraco.Core.Exceptions;
|
||||
@@ -33,8 +32,8 @@ namespace Umbraco.Core.Services
|
||||
//for example, the Move method needs to be locked but this calls the Save method which also needs to be locked.
|
||||
private static readonly ReaderWriterLockSlim Locker = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
|
||||
|
||||
public ContentTypeService(IDatabaseUnitOfWorkProvider provider, RepositoryFactory repositoryFactory, ILogger logger, IEventMessagesFactory eventMessagesFactory, IContentService contentService, IMediaService mediaService)
|
||||
: base(provider, repositoryFactory, logger, eventMessagesFactory)
|
||||
public ContentTypeService(IDatabaseUnitOfWorkProvider provider, ILogger logger, IEventMessagesFactory eventMessagesFactory, IContentService contentService, IMediaService mediaService)
|
||||
: base(provider, logger, eventMessagesFactory)
|
||||
{
|
||||
if (contentService == null) throw new ArgumentNullException("contentService");
|
||||
if (mediaService == null) throw new ArgumentNullException("mediaService");
|
||||
@@ -47,9 +46,9 @@ namespace Umbraco.Core.Services
|
||||
public Attempt<OperationStatus<EntityContainer, OperationStatusType>> CreateContentTypeContainer(int parentId, string name, int userId = 0)
|
||||
{
|
||||
var evtMsgs = EventMessagesFactory.Get();
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repo = RepositoryFactory.CreateEntityContainerRepository(uow, Constants.ObjectTypes.DocumentTypeContainerGuid))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repo = uow.CreateRepository<IDocumentTypeContainerRepository>();
|
||||
try
|
||||
{
|
||||
var container = new EntityContainer(Constants.ObjectTypes.DocumentTypeGuid)
|
||||
@@ -67,7 +66,7 @@ namespace Umbraco.Core.Services
|
||||
}
|
||||
|
||||
repo.AddOrUpdate(container);
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
|
||||
SavedContentTypeContainer.RaiseEvent(new SaveEventArgs<EntityContainer>(container, evtMsgs), this);
|
||||
//TODO: Audit trail ?
|
||||
@@ -84,9 +83,9 @@ namespace Umbraco.Core.Services
|
||||
public Attempt<OperationStatus<EntityContainer, OperationStatusType>> CreateMediaTypeContainer(int parentId, string name, int userId = 0)
|
||||
{
|
||||
var evtMsgs = EventMessagesFactory.Get();
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repo = RepositoryFactory.CreateEntityContainerRepository(uow, Constants.ObjectTypes.MediaTypeContainerGuid))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repo = uow.CreateRepository<IMediaTypeContainerRepository>();
|
||||
try
|
||||
{
|
||||
var container = new EntityContainer(Constants.ObjectTypes.MediaTypeGuid)
|
||||
@@ -104,7 +103,7 @@ namespace Umbraco.Core.Services
|
||||
}
|
||||
|
||||
repo.AddOrUpdate(container);
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
|
||||
SavedMediaTypeContainer.RaiseEvent(new SaveEventArgs<EntityContainer>(container, evtMsgs), this);
|
||||
//TODO: Audit trail ?
|
||||
@@ -160,11 +159,11 @@ namespace Umbraco.Core.Services
|
||||
return OperationStatus.Cancelled(evtMsgs);
|
||||
}
|
||||
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repo = RepositoryFactory.CreateEntityContainerRepository(uow, containerObjectType))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repo = uow.CreateContainerRepository(containerObjectType);
|
||||
repo.AddOrUpdate(container);
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
savedEvent.RaiseEvent(new SaveEventArgs<EntityContainer>(container, evtMsgs), this);
|
||||
@@ -186,9 +185,9 @@ namespace Umbraco.Core.Services
|
||||
|
||||
private EntityContainer GetContainer(int containerId, Guid containerObjectType)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repo = RepositoryFactory.CreateEntityContainerRepository(uow, containerObjectType))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repo = uow.CreateContainerRepository(containerObjectType);
|
||||
var container = repo.Get(containerId);
|
||||
return container;
|
||||
}
|
||||
@@ -196,19 +195,19 @@ namespace Umbraco.Core.Services
|
||||
|
||||
public IEnumerable<EntityContainer> GetMediaTypeContainers(int[] containerIds)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repo = RepositoryFactory.CreateEntityContainerRepository(uow, Constants.ObjectTypes.MediaTypeContainerGuid))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repo = uow.CreateRepository<IMediaTypeContainerRepository>();
|
||||
return repo.GetAll(containerIds);
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<EntityContainer> GetMediaTypeContainers(string name, int level)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repo = RepositoryFactory.CreateEntityContainerRepository(uow, Constants.ObjectTypes.MediaTypeContainerGuid))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
return repo.Get(name, level);
|
||||
var repo = uow.CreateRepository<IMediaTypeContainerRepository>();
|
||||
return ((EntityContainerRepository) repo).Get(name, level);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -234,9 +233,9 @@ namespace Umbraco.Core.Services
|
||||
|
||||
public IEnumerable<EntityContainer> GetContentTypeContainers(int[] containerIds)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repo = RepositoryFactory.CreateEntityContainerRepository(uow, Constants.ObjectTypes.DocumentTypeContainerGuid))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repo = uow.CreateRepository<IDocumentTypeContainerRepository>();
|
||||
return repo.GetAll(containerIds);
|
||||
}
|
||||
}
|
||||
@@ -263,29 +262,29 @@ namespace Umbraco.Core.Services
|
||||
|
||||
private EntityContainer GetContainer(Guid containerId, Guid containerObjectType)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repo = RepositoryFactory.CreateEntityContainerRepository(uow, containerObjectType))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var container = repo.Get(containerId);
|
||||
var repo = uow.CreateContainerRepository(containerObjectType);
|
||||
var container = ((EntityContainerRepository)repo).Get(containerId);
|
||||
return container;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<EntityContainer> GetContentTypeContainers(string name, int level)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repo = RepositoryFactory.CreateEntityContainerRepository(uow, Constants.ObjectTypes.DocumentTypeContainerGuid))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
return repo.Get(name, level);
|
||||
var repo = uow.CreateRepository<IDocumentTypeContainerRepository>();
|
||||
return ((EntityContainerRepository)repo).Get(name, level);
|
||||
}
|
||||
}
|
||||
|
||||
public Attempt<OperationStatus> DeleteContentTypeContainer(int containerId, int userId = 0)
|
||||
{
|
||||
var evtMsgs = EventMessagesFactory.Get();
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repo = RepositoryFactory.CreateEntityContainerRepository(uow, Constants.ObjectTypes.DocumentTypeContainerGuid))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repo = uow.CreateRepository<IDocumentTypeContainerRepository>();
|
||||
var container = repo.Get(containerId);
|
||||
if (container == null) return OperationStatus.NoOperation(evtMsgs);
|
||||
|
||||
@@ -297,7 +296,7 @@ namespace Umbraco.Core.Services
|
||||
}
|
||||
|
||||
repo.Delete(container);
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
|
||||
DeletedContentTypeContainer.RaiseEvent(new DeleteEventArgs<EntityContainer>(container, evtMsgs), this);
|
||||
|
||||
@@ -309,9 +308,9 @@ namespace Umbraco.Core.Services
|
||||
public Attempt<OperationStatus> DeleteMediaTypeContainer(int containerId, int userId = 0)
|
||||
{
|
||||
var evtMsgs = EventMessagesFactory.Get();
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repo = RepositoryFactory.CreateEntityContainerRepository(uow, Constants.ObjectTypes.MediaTypeContainerGuid))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repo = uow.CreateRepository<IMediaTypeContainerRepository>();
|
||||
var container = repo.Get(containerId);
|
||||
if (container == null) return OperationStatus.NoOperation(evtMsgs);
|
||||
|
||||
@@ -323,7 +322,7 @@ namespace Umbraco.Core.Services
|
||||
}
|
||||
|
||||
repo.Delete(container);
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
|
||||
DeletedMediaTypeContainer.RaiseEvent(new DeleteEventArgs<EntityContainer>(container, evtMsgs), this);
|
||||
|
||||
@@ -340,8 +339,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns></returns>
|
||||
public IEnumerable<string> GetAllPropertyTypeAliases()
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateContentTypeRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IContentTypeRepository>();
|
||||
return repository.GetAllPropertyTypeAliases();
|
||||
}
|
||||
}
|
||||
@@ -356,8 +356,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns></returns>
|
||||
public IEnumerable<string> GetAllContentTypeAliases(params Guid[] objectTypes)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateContentTypeRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IContentTypeRepository>();
|
||||
return repository.GetAllContentTypeAliases(objectTypes);
|
||||
}
|
||||
}
|
||||
@@ -452,8 +453,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns><see cref="IContentType"/></returns>
|
||||
public IContentType GetContentType(int id)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateContentTypeRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IContentTypeRepository>();
|
||||
return repository.Get(id);
|
||||
}
|
||||
}
|
||||
@@ -465,8 +467,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns><see cref="IContentType"/></returns>
|
||||
public IContentType GetContentType(string alias)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateContentTypeRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IContentTypeRepository>();
|
||||
return repository.Get(alias);
|
||||
}
|
||||
}
|
||||
@@ -478,8 +481,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns><see cref="IContentType"/></returns>
|
||||
public IContentType GetContentType(Guid id)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateContentTypeRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IContentTypeRepository>();
|
||||
return repository.Get(id);
|
||||
}
|
||||
}
|
||||
@@ -491,8 +495,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>An Enumerable list of <see cref="IContentType"/> objects</returns>
|
||||
public IEnumerable<IContentType> GetAllContentTypes(params int[] ids)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateContentTypeRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IContentTypeRepository>();
|
||||
return repository.GetAll(ids);
|
||||
}
|
||||
}
|
||||
@@ -504,8 +509,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>An Enumerable list of <see cref="IContentType"/> objects</returns>
|
||||
public IEnumerable<IContentType> GetAllContentTypes(IEnumerable<Guid> ids)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateContentTypeRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IContentTypeRepository>();
|
||||
return repository.GetAll(ids.ToArray());
|
||||
}
|
||||
}
|
||||
@@ -517,8 +523,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>An Enumerable list of <see cref="IContentType"/> objects</returns>
|
||||
public IEnumerable<IContentType> GetContentTypeChildren(int id)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateContentTypeRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IContentTypeRepository>();
|
||||
var query = repository.Query.Where(x => x.ParentId == id);
|
||||
var contentTypes = repository.GetByQuery(query);
|
||||
return contentTypes;
|
||||
@@ -532,8 +539,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>An Enumerable list of <see cref="IContentType"/> objects</returns>
|
||||
public IEnumerable<IContentType> GetContentTypeChildren(Guid id)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateContentTypeRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IContentTypeRepository>();
|
||||
var found = GetContentType(id);
|
||||
if (found == null) return Enumerable.Empty<IContentType>();
|
||||
var query = repository.Query.Where(x => x.ParentId == found.Id);
|
||||
@@ -549,8 +557,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>True if the content type has any children otherwise False</returns>
|
||||
public bool HasChildren(int id)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateContentTypeRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IContentTypeRepository>();
|
||||
var query = repository.Query.Where(x => x.ParentId == id);
|
||||
int count = repository.Count(query);
|
||||
return count > 0;
|
||||
@@ -564,8 +573,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>True if the content type has any children otherwise False</returns>
|
||||
public bool HasChildren(Guid id)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateContentTypeRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IContentTypeRepository>();
|
||||
var found = GetContentType(id);
|
||||
if (found == null) return false;
|
||||
var query = repository.Query.Where(x => x.ParentId == found.Id);
|
||||
@@ -616,16 +626,18 @@ namespace Umbraco.Core.Services
|
||||
|
||||
public int CountContentTypes()
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateContentTypeRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IContentTypeRepository>();
|
||||
return repository.Count(repository.Query);
|
||||
}
|
||||
}
|
||||
|
||||
public int CountMediaTypes()
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateMediaTypeRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMediaTypeRepository>();
|
||||
return repository.Count(repository.Query);
|
||||
}
|
||||
}
|
||||
@@ -724,14 +736,14 @@ namespace Umbraco.Core.Services
|
||||
|
||||
using (new WriteLock(Locker))
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateContentTypeRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IContentTypeRepository>();
|
||||
ValidateLocked(contentType); // throws if invalid
|
||||
contentType.CreatorId = userId;
|
||||
repository.AddOrUpdate(contentType);
|
||||
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
UpdateContentXmlStructure(contentType);
|
||||
@@ -754,9 +766,9 @@ namespace Umbraco.Core.Services
|
||||
|
||||
using (new WriteLock(Locker))
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateContentTypeRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IContentTypeRepository>();
|
||||
// all-or-nothing, validate them all first
|
||||
foreach (var contentType in asArray)
|
||||
{
|
||||
@@ -769,7 +781,7 @@ namespace Umbraco.Core.Services
|
||||
}
|
||||
|
||||
//save it all in one go
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
UpdateContentXmlStructure(asArray.Cast<IContentTypeBase>().ToArray());
|
||||
@@ -800,11 +812,11 @@ namespace Umbraco.Core.Services
|
||||
|
||||
_contentService.DeleteContentOfType(contentType.Id);
|
||||
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateContentTypeRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IContentTypeRepository>();
|
||||
repository.Delete(contentType);
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
|
||||
DeletedContentType.RaiseEvent(new DeleteEventArgs<IContentType>(contentType, false), this);
|
||||
}
|
||||
@@ -835,15 +847,15 @@ namespace Umbraco.Core.Services
|
||||
_contentService.DeleteContentOfType(contentType.Id);
|
||||
}
|
||||
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateContentTypeRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IContentTypeRepository>();
|
||||
foreach (var contentType in asArray)
|
||||
{
|
||||
repository.Delete(contentType);
|
||||
}
|
||||
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
|
||||
DeletedContentType.RaiseEvent(new DeleteEventArgs<IContentType>(asArray, false), this);
|
||||
}
|
||||
@@ -859,8 +871,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns><see cref="IMediaType"/></returns>
|
||||
public IMediaType GetMediaType(int id)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateMediaTypeRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMediaTypeRepository>();
|
||||
return repository.Get(id);
|
||||
}
|
||||
}
|
||||
@@ -872,8 +885,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns><see cref="IMediaType"/></returns>
|
||||
public IMediaType GetMediaType(string alias)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateMediaTypeRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMediaTypeRepository>();
|
||||
return repository.Get(alias);
|
||||
}
|
||||
}
|
||||
@@ -885,8 +899,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns><see cref="IMediaType"/></returns>
|
||||
public IMediaType GetMediaType(Guid id)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateMediaTypeRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMediaTypeRepository>();
|
||||
return repository.Get(id);
|
||||
}
|
||||
}
|
||||
@@ -898,8 +913,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>An Enumerable list of <see cref="IMediaType"/> objects</returns>
|
||||
public IEnumerable<IMediaType> GetAllMediaTypes(params int[] ids)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateMediaTypeRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMediaTypeRepository>();
|
||||
return repository.GetAll(ids);
|
||||
}
|
||||
}
|
||||
@@ -911,8 +927,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>An Enumerable list of <see cref="IMediaType"/> objects</returns>
|
||||
public IEnumerable<IMediaType> GetAllMediaTypes(IEnumerable<Guid> ids)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateMediaTypeRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMediaTypeRepository>();
|
||||
return repository.GetAll(ids.ToArray());
|
||||
}
|
||||
}
|
||||
@@ -924,8 +941,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>An Enumerable list of <see cref="IMediaType"/> objects</returns>
|
||||
public IEnumerable<IMediaType> GetMediaTypeChildren(int id)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateMediaTypeRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMediaTypeRepository>();
|
||||
var query = repository.Query.Where(x => x.ParentId == id);
|
||||
var contentTypes = repository.GetByQuery(query);
|
||||
return contentTypes;
|
||||
@@ -939,8 +957,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>An Enumerable list of <see cref="IMediaType"/> objects</returns>
|
||||
public IEnumerable<IMediaType> GetMediaTypeChildren(Guid id)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateMediaTypeRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMediaTypeRepository>();
|
||||
var found = GetMediaType(id);
|
||||
if (found == null) return Enumerable.Empty<IMediaType>();
|
||||
var query = repository.Query.Where(x => x.ParentId == found.Id);
|
||||
@@ -956,8 +975,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>True if the media type has any children otherwise False</returns>
|
||||
public bool MediaTypeHasChildren(int id)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateMediaTypeRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMediaTypeRepository>();
|
||||
var query = repository.Query.Where(x => x.ParentId == id);
|
||||
int count = repository.Count(query);
|
||||
return count > 0;
|
||||
@@ -971,8 +991,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>True if the media type has any children otherwise False</returns>
|
||||
public bool MediaTypeHasChildren(Guid id)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateMediaTypeRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMediaTypeRepository>();
|
||||
var found = GetMediaType(id);
|
||||
if (found == null) return false;
|
||||
var query = repository.Query.Where(x => x.ParentId == found.Id);
|
||||
@@ -995,10 +1016,11 @@ namespace Umbraco.Core.Services
|
||||
}
|
||||
|
||||
var moveInfo = new List<MoveEventInfo<IMediaType>>();
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var containerRepository = RepositoryFactory.CreateEntityContainerRepository(uow, Constants.ObjectTypes.MediaTypeContainerGuid))
|
||||
using (var repository = RepositoryFactory.CreateMediaTypeRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var containerRepository = uow.CreateRepository<IMediaTypeContainerRepository>();
|
||||
var repository = uow.CreateRepository<IMediaTypeRepository>();
|
||||
|
||||
try
|
||||
{
|
||||
EntityContainer container = null;
|
||||
@@ -1015,7 +1037,7 @@ namespace Umbraco.Core.Services
|
||||
return Attempt.Fail(
|
||||
new OperationStatus<MoveOperationStatusType>(ex.Operation, evtMsgs));
|
||||
}
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
MovedMediaType.RaiseEvent(new MoveEventArgs<IMediaType>(false, evtMsgs, moveInfo.ToArray()), this);
|
||||
@@ -1038,10 +1060,11 @@ namespace Umbraco.Core.Services
|
||||
}
|
||||
|
||||
var moveInfo = new List<MoveEventInfo<IContentType>>();
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var containerRepository = RepositoryFactory.CreateEntityContainerRepository(uow, Constants.ObjectTypes.DocumentTypeContainerGuid))
|
||||
using (var repository = RepositoryFactory.CreateContentTypeRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var containerRepository = uow.CreateRepository<IDocumentTypeContainerRepository>();
|
||||
var repository = uow.CreateRepository<IContentTypeRepository>();
|
||||
|
||||
try
|
||||
{
|
||||
EntityContainer container = null;
|
||||
@@ -1058,7 +1081,7 @@ namespace Umbraco.Core.Services
|
||||
return Attempt.Fail(
|
||||
new OperationStatus<MoveOperationStatusType>(ex.Operation, evtMsgs));
|
||||
}
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
MovedContentType.RaiseEvent(new MoveEventArgs<IContentType>(false, evtMsgs, moveInfo.ToArray()), this);
|
||||
@@ -1072,10 +1095,10 @@ namespace Umbraco.Core.Services
|
||||
var evtMsgs = EventMessagesFactory.Get();
|
||||
|
||||
IMediaType copy;
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var containerRepository = RepositoryFactory.CreateEntityContainerRepository(uow, Constants.ObjectTypes.MediaTypeContainerGuid))
|
||||
using (var repository = RepositoryFactory.CreateMediaTypeRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var containerRepository = uow.CreateRepository<IMediaTypeContainerRepository>();
|
||||
var repository = uow.CreateRepository<IMediaTypeRepository>();
|
||||
try
|
||||
{
|
||||
if (containerId > 0)
|
||||
@@ -1104,7 +1127,7 @@ namespace Umbraco.Core.Services
|
||||
{
|
||||
return Attempt.Fail(new OperationStatus<IMediaType, MoveOperationStatusType>(null, ex.Operation, evtMsgs));
|
||||
}
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
return Attempt.Succeed(new OperationStatus<IMediaType, MoveOperationStatusType>(copy, MoveOperationStatusType.Success, evtMsgs));
|
||||
@@ -1115,10 +1138,10 @@ namespace Umbraco.Core.Services
|
||||
var evtMsgs = EventMessagesFactory.Get();
|
||||
|
||||
IContentType copy;
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var containerRepository = RepositoryFactory.CreateEntityContainerRepository(uow, Constants.ObjectTypes.DocumentTypeContainerGuid))
|
||||
using (var repository = RepositoryFactory.CreateContentTypeRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var containerRepository = uow.CreateRepository<IDocumentTypeContainerRepository>();
|
||||
var repository = uow.CreateRepository<IContentTypeRepository>();
|
||||
try
|
||||
{
|
||||
if (containerId > 0)
|
||||
@@ -1147,7 +1170,7 @@ namespace Umbraco.Core.Services
|
||||
{
|
||||
return Attempt.Fail(new OperationStatus<IContentType, MoveOperationStatusType>(null, ex.Operation, evtMsgs));
|
||||
}
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
return Attempt.Succeed(new OperationStatus<IContentType, MoveOperationStatusType>(copy, MoveOperationStatusType.Success, evtMsgs));
|
||||
@@ -1165,13 +1188,13 @@ namespace Umbraco.Core.Services
|
||||
|
||||
using (new WriteLock(Locker))
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateMediaTypeRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMediaTypeRepository>();
|
||||
ValidateLocked(mediaType); // throws if invalid
|
||||
mediaType.CreatorId = userId;
|
||||
repository.AddOrUpdate(mediaType);
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
|
||||
}
|
||||
|
||||
@@ -1196,9 +1219,9 @@ namespace Umbraco.Core.Services
|
||||
|
||||
using (new WriteLock(Locker))
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateMediaTypeRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMediaTypeRepository>();
|
||||
// all-or-nothing, validate them all first
|
||||
foreach (var mediaType in asArray)
|
||||
{
|
||||
@@ -1211,7 +1234,7 @@ namespace Umbraco.Core.Services
|
||||
}
|
||||
|
||||
//save it all in one go
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
UpdateContentXmlStructure(asArray.Cast<IContentTypeBase>().ToArray());
|
||||
@@ -1235,12 +1258,12 @@ namespace Umbraco.Core.Services
|
||||
{
|
||||
_mediaService.DeleteMediaOfType(mediaType.Id, userId);
|
||||
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateMediaTypeRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMediaTypeRepository>();
|
||||
|
||||
repository.Delete(mediaType);
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
|
||||
DeletedMediaType.RaiseEvent(new DeleteEventArgs<IMediaType>(mediaType, false), this);
|
||||
}
|
||||
@@ -1268,14 +1291,14 @@ namespace Umbraco.Core.Services
|
||||
_mediaService.DeleteMediaOfType(mediaType.Id);
|
||||
}
|
||||
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateMediaTypeRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMediaTypeRepository>();
|
||||
foreach (var mediaType in asArray)
|
||||
{
|
||||
repository.Delete(mediaType);
|
||||
}
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
|
||||
DeletedMediaType.RaiseEvent(new DeleteEventArgs<IMediaType>(asArray, false), this);
|
||||
}
|
||||
@@ -1333,11 +1356,11 @@ namespace Umbraco.Core.Services
|
||||
|
||||
private void Audit(AuditType type, string message, int userId, int objectId)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var auditRepo = RepositoryFactory.CreateAuditRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
auditRepo.AddOrUpdate(new AuditItem(objectId, message, type, userId));
|
||||
uow.Commit();
|
||||
var repo = uow.CreateRepository<IAuditRepository>();
|
||||
repo.AddOrUpdate(new AuditItem(objectId, message, type, userId));
|
||||
uow.Complete();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,8 +11,8 @@ namespace Umbraco.Core.Services
|
||||
{
|
||||
public class ContentTypeServiceBase : RepositoryService
|
||||
{
|
||||
public ContentTypeServiceBase(IDatabaseUnitOfWorkProvider provider, RepositoryFactory repositoryFactory, ILogger logger, IEventMessagesFactory eventMessagesFactory)
|
||||
: base(provider, repositoryFactory, logger, eventMessagesFactory)
|
||||
public ContentTypeServiceBase(IDatabaseUnitOfWorkProvider provider, ILogger logger, IEventMessagesFactory eventMessagesFactory)
|
||||
: base(provider, logger, eventMessagesFactory)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using Umbraco.Core.Auditing;
|
||||
using Umbraco.Core.Events;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models;
|
||||
@@ -12,6 +11,7 @@ using Umbraco.Core.Persistence.Querying;
|
||||
using Umbraco.Core.Persistence.UnitOfWork;
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
using Umbraco.Core.Exceptions;
|
||||
using Umbraco.Core.Persistence.Repositories;
|
||||
|
||||
namespace Umbraco.Core.Services
|
||||
{
|
||||
@@ -21,8 +21,8 @@ namespace Umbraco.Core.Services
|
||||
public class DataTypeService : RepositoryService, IDataTypeService
|
||||
{
|
||||
|
||||
public DataTypeService(IDatabaseUnitOfWorkProvider provider, RepositoryFactory repositoryFactory, ILogger logger, IEventMessagesFactory eventMessagesFactory)
|
||||
: base(provider, repositoryFactory, logger, eventMessagesFactory)
|
||||
public DataTypeService(IDatabaseUnitOfWorkProvider provider, ILogger logger, IEventMessagesFactory eventMessagesFactory)
|
||||
: base(provider, logger, eventMessagesFactory)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -31,9 +31,9 @@ namespace Umbraco.Core.Services
|
||||
public Attempt<OperationStatus<EntityContainer, OperationStatusType>> CreateContainer(int parentId, string name, int userId = 0)
|
||||
{
|
||||
var evtMsgs = EventMessagesFactory.Get();
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repo = RepositoryFactory.CreateEntityContainerRepository(uow, Constants.ObjectTypes.DataTypeContainerGuid))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repo = uow.CreateRepository<IDataTypeContainerRepository>();
|
||||
try
|
||||
{
|
||||
var container = new EntityContainer(Constants.ObjectTypes.DataTypeGuid)
|
||||
@@ -51,7 +51,7 @@ namespace Umbraco.Core.Services
|
||||
}
|
||||
|
||||
repo.AddOrUpdate(container);
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
|
||||
SavedContainer.RaiseEvent(new SaveEventArgs<EntityContainer>(container, evtMsgs), this);
|
||||
//TODO: Audit trail ?
|
||||
@@ -67,9 +67,9 @@ namespace Umbraco.Core.Services
|
||||
|
||||
public EntityContainer GetContainer(int containerId)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repo = RepositoryFactory.CreateEntityContainerRepository(uow, Constants.ObjectTypes.DataTypeContainerGuid))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repo = uow.CreateRepository<IDataTypeContainerRepository>();
|
||||
var container = repo.Get(containerId);
|
||||
return container;
|
||||
}
|
||||
@@ -77,20 +77,20 @@ namespace Umbraco.Core.Services
|
||||
|
||||
public EntityContainer GetContainer(Guid containerId)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repo = RepositoryFactory.CreateEntityContainerRepository(uow, Constants.ObjectTypes.DataTypeContainerGuid))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var container = repo.Get(containerId);
|
||||
var repo = uow.CreateRepository<IDataTypeContainerRepository>();
|
||||
var container = ((EntityContainerRepository)repo).Get(containerId);
|
||||
return container;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<EntityContainer> GetContainers(string name, int level)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repo = RepositoryFactory.CreateEntityContainerRepository(uow, Constants.ObjectTypes.DataTypeContainerGuid))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
return repo.Get(name, level);
|
||||
var repo = uow.CreateRepository<IDataTypeContainerRepository>();
|
||||
return ((EntityContainerRepository)repo).Get(name, level);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,9 +111,9 @@ namespace Umbraco.Core.Services
|
||||
|
||||
public IEnumerable<EntityContainer> GetContainers(int[] containerIds)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repo = RepositoryFactory.CreateEntityContainerRepository(uow, Constants.ObjectTypes.DataTypeContainerGuid))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repo = uow.CreateRepository<IDataTypeContainerRepository>();
|
||||
return repo.GetAll(containerIds);
|
||||
}
|
||||
}
|
||||
@@ -141,11 +141,11 @@ namespace Umbraco.Core.Services
|
||||
return OperationStatus.Cancelled(evtMsgs);
|
||||
}
|
||||
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repo = RepositoryFactory.CreateEntityContainerRepository(uow, Constants.ObjectTypes.DataTypeContainerGuid))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repo = uow.CreateRepository<IDataTypeContainerRepository>();
|
||||
repo.AddOrUpdate(container);
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
SavedContainer.RaiseEvent(new SaveEventArgs<EntityContainer>(container, evtMsgs), this);
|
||||
@@ -158,9 +158,9 @@ namespace Umbraco.Core.Services
|
||||
public Attempt<OperationStatus> DeleteContainer(int containerId, int userId = 0)
|
||||
{
|
||||
var evtMsgs = EventMessagesFactory.Get();
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repo = RepositoryFactory.CreateEntityContainerRepository(uow, Constants.ObjectTypes.DataTypeContainerGuid))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repo = uow.CreateRepository<IDataTypeContainerRepository>();
|
||||
var container = repo.Get(containerId);
|
||||
if (container == null) return OperationStatus.NoOperation(evtMsgs);
|
||||
|
||||
@@ -172,7 +172,7 @@ namespace Umbraco.Core.Services
|
||||
}
|
||||
|
||||
repo.Delete(container);
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
|
||||
DeletedContainer.RaiseEvent(new DeleteEventArgs<EntityContainer>(container, evtMsgs), this);
|
||||
|
||||
@@ -190,8 +190,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns><see cref="IDataTypeDefinition"/></returns>
|
||||
public IDataTypeDefinition GetDataTypeDefinitionByName(string name)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateDataTypeDefinitionRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IDataTypeDefinitionRepository>();
|
||||
return repository.GetByQuery(repository.Query.Where(x => x.Name == name)).FirstOrDefault();
|
||||
}
|
||||
}
|
||||
@@ -203,8 +204,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns><see cref="IDataTypeDefinition"/></returns>
|
||||
public IDataTypeDefinition GetDataTypeDefinitionById(int id)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateDataTypeDefinitionRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IDataTypeDefinitionRepository>();
|
||||
return repository.Get(id);
|
||||
}
|
||||
}
|
||||
@@ -216,8 +218,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns><see cref="IDataTypeDefinition"/></returns>
|
||||
public IDataTypeDefinition GetDataTypeDefinitionById(Guid id)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateDataTypeDefinitionRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IDataTypeDefinitionRepository>();
|
||||
var query = repository.Query.Where(x => x.Key == id);
|
||||
var definitions = repository.GetByQuery(query);
|
||||
return definitions.FirstOrDefault();
|
||||
@@ -231,8 +234,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>Collection of <see cref="IDataTypeDefinition"/> objects with a matching contorl id</returns>
|
||||
public IEnumerable<IDataTypeDefinition> GetDataTypeDefinitionByPropertyEditorAlias(string propertyEditorAlias)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateDataTypeDefinitionRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IDataTypeDefinitionRepository>();
|
||||
var query = repository.Query.Where(x => x.PropertyEditorAlias == propertyEditorAlias);
|
||||
var definitions = repository.GetByQuery(query);
|
||||
return definitions;
|
||||
@@ -246,8 +250,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>An enumerable list of <see cref="IDataTypeDefinition"/> objects</returns>
|
||||
public IEnumerable<IDataTypeDefinition> GetAllDataTypeDefinitions(params int[] ids)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateDataTypeDefinitionRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IDataTypeDefinitionRepository>();
|
||||
return repository.GetAll(ids);
|
||||
}
|
||||
}
|
||||
@@ -259,8 +264,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>An enumerable list of string values</returns>
|
||||
public IEnumerable<string> GetPreValuesByDataTypeId(int id)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateDataTypeDefinitionRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IDataTypeDefinitionRepository>();
|
||||
var collection = repository.GetPreValuesCollectionByDataTypeId(id);
|
||||
//now convert the collection to a string list
|
||||
var list = collection.FormatAsDictionary()
|
||||
@@ -269,7 +275,7 @@ namespace Umbraco.Core.Services
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Returns the PreValueCollection for the specified data type
|
||||
/// </summary>
|
||||
@@ -277,8 +283,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns></returns>
|
||||
public PreValueCollection GetPreValuesCollectionByDataTypeId(int id)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateDataTypeDefinitionRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IDataTypeDefinitionRepository>();
|
||||
return repository.GetPreValuesCollectionByDataTypeId(id);
|
||||
}
|
||||
}
|
||||
@@ -290,8 +297,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>PreValue as a string</returns>
|
||||
public string GetPreValueAsString(int id)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateDataTypeDefinitionRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IDataTypeDefinitionRepository>();
|
||||
return repository.GetPreValueAsString(id);
|
||||
}
|
||||
}
|
||||
@@ -310,10 +318,11 @@ namespace Umbraco.Core.Services
|
||||
}
|
||||
|
||||
var moveInfo = new List<MoveEventInfo<IDataTypeDefinition>>();
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var containerRepository = RepositoryFactory.CreateEntityContainerRepository(uow, Constants.ObjectTypes.DataTypeContainerGuid))
|
||||
using (var repository = RepositoryFactory.CreateDataTypeDefinitionRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var containerRepository = uow.CreateRepository<IDataTypeContainerRepository>();
|
||||
var repository = uow.CreateRepository<IDataTypeDefinitionRepository>();
|
||||
|
||||
try
|
||||
{
|
||||
EntityContainer container = null;
|
||||
@@ -330,7 +339,7 @@ namespace Umbraco.Core.Services
|
||||
return Attempt.Fail(
|
||||
new OperationStatus<MoveOperationStatusType>(ex.Operation, evtMsgs));
|
||||
}
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
Moved.RaiseEvent(new MoveEventArgs<IDataTypeDefinition>(false, evtMsgs, moveInfo.ToArray()), this);
|
||||
@@ -346,19 +355,19 @@ namespace Umbraco.Core.Services
|
||||
/// <param name="userId">Id of the user issueing the save</param>
|
||||
public void Save(IDataTypeDefinition dataTypeDefinition, int userId = 0)
|
||||
{
|
||||
if (Saving.IsRaisedEventCancelled(new SaveEventArgs<IDataTypeDefinition>(dataTypeDefinition), this))
|
||||
if (Saving.IsRaisedEventCancelled(new SaveEventArgs<IDataTypeDefinition>(dataTypeDefinition), this))
|
||||
return;
|
||||
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateDataTypeDefinitionRepository(uow))
|
||||
{
|
||||
dataTypeDefinition.CreatorId = userId;
|
||||
repository.AddOrUpdate(dataTypeDefinition);
|
||||
uow.Commit();
|
||||
dataTypeDefinition.CreatorId = userId;
|
||||
|
||||
Saved.RaiseEvent(new SaveEventArgs<IDataTypeDefinition>(dataTypeDefinition, false), this);
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IDataTypeDefinitionRepository>();
|
||||
repository.AddOrUpdate(dataTypeDefinition);
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
Saved.RaiseEvent(new SaveEventArgs<IDataTypeDefinition>(dataTypeDefinition, false), this);
|
||||
Audit(AuditType.Save, string.Format("Save DataTypeDefinition performed by user"), userId, dataTypeDefinition.Id);
|
||||
}
|
||||
|
||||
@@ -386,15 +395,15 @@ namespace Umbraco.Core.Services
|
||||
return;
|
||||
}
|
||||
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateDataTypeDefinitionRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IDataTypeDefinitionRepository>();
|
||||
foreach (var dataTypeDefinition in dataTypeDefinitions)
|
||||
{
|
||||
dataTypeDefinition.CreatorId = userId;
|
||||
repository.AddOrUpdate(dataTypeDefinition);
|
||||
}
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
|
||||
if (raiseEvents)
|
||||
Saved.RaiseEvent(new SaveEventArgs<IDataTypeDefinition>(dataTypeDefinitions, false), this);
|
||||
@@ -413,7 +422,7 @@ namespace Umbraco.Core.Services
|
||||
{
|
||||
//TODO: Should we raise an event here since we are really saving values for the data type?
|
||||
|
||||
using (var uow = UowProvider.GetUnitOfWork())
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
using (var transaction = uow.Database.GetTransaction())
|
||||
{
|
||||
@@ -470,11 +479,11 @@ namespace Umbraco.Core.Services
|
||||
{
|
||||
//TODO: Should we raise an event here since we are really saving values for the data type?
|
||||
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateDataTypeDefinitionRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IDataTypeDefinitionRepository>();
|
||||
repository.AddOrUpdatePreValues(dataTypeDefinition, values);
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -489,23 +498,18 @@ namespace Umbraco.Core.Services
|
||||
if (Saving.IsRaisedEventCancelled(new SaveEventArgs<IDataTypeDefinition>(dataTypeDefinition), this))
|
||||
return;
|
||||
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateDataTypeDefinitionRepository(uow))
|
||||
dataTypeDefinition.CreatorId = userId;
|
||||
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
dataTypeDefinition.CreatorId = userId;
|
||||
|
||||
//add/update the dtd
|
||||
repository.AddOrUpdate(dataTypeDefinition);
|
||||
|
||||
//add/update the prevalues
|
||||
repository.AddOrUpdatePreValues(dataTypeDefinition, values);
|
||||
|
||||
uow.Commit();
|
||||
|
||||
Saved.RaiseEvent(new SaveEventArgs<IDataTypeDefinition>(dataTypeDefinition, false), this);
|
||||
var repository = uow.CreateRepository<IDataTypeDefinitionRepository>();
|
||||
repository.AddOrUpdate(dataTypeDefinition); // definition
|
||||
repository.AddOrUpdatePreValues(dataTypeDefinition, values); //prevalues
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
Audit(AuditType.Save, string.Format("Save DataTypeDefinition performed by user"), userId, dataTypeDefinition.Id);
|
||||
|
||||
Saved.RaiseEvent(new SaveEventArgs<IDataTypeDefinition>(dataTypeDefinition, false), this);
|
||||
Audit(AuditType.Save, "Save DataTypeDefinition performed by user", userId, dataTypeDefinition.Id);
|
||||
}
|
||||
|
||||
|
||||
@@ -519,30 +523,29 @@ namespace Umbraco.Core.Services
|
||||
/// <param name="dataTypeDefinition"><see cref="IDataTypeDefinition"/> to delete</param>
|
||||
/// <param name="userId">Optional Id of the user issueing the deletion</param>
|
||||
public void Delete(IDataTypeDefinition dataTypeDefinition, int userId = 0)
|
||||
{
|
||||
if (Deleting.IsRaisedEventCancelled(new DeleteEventArgs<IDataTypeDefinition>(dataTypeDefinition), this))
|
||||
{
|
||||
if (Deleting.IsRaisedEventCancelled(new DeleteEventArgs<IDataTypeDefinition>(dataTypeDefinition), this))
|
||||
return;
|
||||
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateDataTypeDefinitionRepository(uow))
|
||||
{
|
||||
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IDataTypeDefinitionRepository>();
|
||||
repository.Delete(dataTypeDefinition);
|
||||
|
||||
uow.Commit();
|
||||
|
||||
Deleted.RaiseEvent(new DeleteEventArgs<IDataTypeDefinition>(dataTypeDefinition, false), this);
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
Audit(AuditType.Delete, string.Format("Delete DataTypeDefinition performed by user"), userId, dataTypeDefinition.Id);
|
||||
Deleted.RaiseEvent(new DeleteEventArgs<IDataTypeDefinition>(dataTypeDefinition, false), this);
|
||||
|
||||
Audit(AuditType.Delete, string.Format("Delete DataTypeDefinition performed by user"), userId, dataTypeDefinition.Id);
|
||||
}
|
||||
|
||||
private void Audit(AuditType type, string message, int userId, int objectId)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var auditRepo = RepositoryFactory.CreateAuditRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
auditRepo.AddOrUpdate(new AuditItem(objectId, message, type, userId));
|
||||
uow.Commit();
|
||||
var repo = uow.CreateRepository<IAuditRepository>();
|
||||
repo.AddOrUpdate(new AuditItem(objectId, message, type, userId));
|
||||
uow.Complete();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,24 +6,25 @@ using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Persistence.Querying;
|
||||
using Umbraco.Core.Persistence.Repositories;
|
||||
using Umbraco.Core.Persistence.UnitOfWork;
|
||||
|
||||
namespace Umbraco.Core.Services
|
||||
{
|
||||
public class DomainService : RepositoryService, IDomainService
|
||||
{
|
||||
public DomainService(IDatabaseUnitOfWorkProvider provider, RepositoryFactory repositoryFactory, ILogger logger, IEventMessagesFactory eventMessagesFactory)
|
||||
: base(provider, repositoryFactory, logger, eventMessagesFactory)
|
||||
public DomainService(IDatabaseUnitOfWorkProvider provider, ILogger logger, IEventMessagesFactory eventMessagesFactory)
|
||||
: base(provider, logger, eventMessagesFactory)
|
||||
{
|
||||
}
|
||||
|
||||
public bool Exists(string domainName)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repo = RepositoryFactory.CreateDomainRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repo = uow.CreateRepository<IDomainRepository>();
|
||||
return repo.Exists(domainName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Attempt<OperationStatus> Delete(IDomain domain)
|
||||
@@ -36,11 +37,11 @@ namespace Umbraco.Core.Services
|
||||
return OperationStatus.Cancelled(evtMsgs);
|
||||
}
|
||||
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateDomainRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IDomainRepository>();
|
||||
repository.Delete(domain);
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
var args = new DeleteEventArgs<IDomain>(domain, false, evtMsgs);
|
||||
@@ -50,36 +51,36 @@ namespace Umbraco.Core.Services
|
||||
|
||||
public IDomain GetByName(string name)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateDomainRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IDomainRepository>();
|
||||
return repository.GetByName(name);
|
||||
}
|
||||
}
|
||||
|
||||
public IDomain GetById(int id)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repo = RepositoryFactory.CreateDomainRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repo = uow.CreateRepository<IDomainRepository>();
|
||||
return repo.Get(id);
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<IDomain> GetAll(bool includeWildcards)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repo = RepositoryFactory.CreateDomainRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repo = uow.CreateRepository<IDomainRepository>();
|
||||
return repo.GetAll(includeWildcards);
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<IDomain> GetAssignedDomains(int contentId, bool includeWildcards)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repo = RepositoryFactory.CreateDomainRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repo = uow.CreateRepository<IDomainRepository>();
|
||||
return repo.GetAssignedDomains(contentId, includeWildcards);
|
||||
}
|
||||
}
|
||||
@@ -94,11 +95,11 @@ namespace Umbraco.Core.Services
|
||||
return OperationStatus.Cancelled(evtMsgs);
|
||||
}
|
||||
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateDomainRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IDomainRepository>();
|
||||
repository.AddOrUpdate(domainEntity);
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
Saved.RaiseEvent(new SaveEventArgs<IDomain>(domainEntity, false, evtMsgs), this);
|
||||
@@ -108,14 +109,14 @@ namespace Umbraco.Core.Services
|
||||
#region Event Handlers
|
||||
/// <summary>
|
||||
/// Occurs before Delete
|
||||
/// </summary>
|
||||
/// </summary>
|
||||
public static event TypedEventHandler<IDomainService, DeleteEventArgs<IDomain>> Deleting;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs after Delete
|
||||
/// </summary>
|
||||
public static event TypedEventHandler<IDomainService, DeleteEventArgs<IDomain>> Deleted;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Occurs before Save
|
||||
/// </summary>
|
||||
@@ -126,7 +127,7 @@ namespace Umbraco.Core.Services
|
||||
/// </summary>
|
||||
public static event TypedEventHandler<IDomainService, SaveEventArgs<IDomain>> Saved;
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ using Umbraco.Core.Models.EntityBase;
|
||||
using Umbraco.Core.Models.Rdbms;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Persistence.Querying;
|
||||
using Umbraco.Core.Persistence.Repositories;
|
||||
using Umbraco.Core.Persistence.UnitOfWork;
|
||||
|
||||
namespace Umbraco.Core.Services
|
||||
@@ -21,10 +22,10 @@ namespace Umbraco.Core.Services
|
||||
private readonly Dictionary<string, Tuple<UmbracoObjectTypes, Func<int, IUmbracoEntity>>> _supportedObjectTypes;
|
||||
|
||||
|
||||
public EntityService(IDatabaseUnitOfWorkProvider provider, RepositoryFactory repositoryFactory, ILogger logger, IEventMessagesFactory eventMessagesFactory,
|
||||
public EntityService(IDatabaseUnitOfWorkProvider provider, ILogger logger, IEventMessagesFactory eventMessagesFactory,
|
||||
IContentService contentService, IContentTypeService contentTypeService, IMediaService mediaService, IDataTypeService dataTypeService,
|
||||
IMemberService memberService, IMemberTypeService memberTypeService, IRuntimeCacheProvider runtimeCache)
|
||||
: base(provider, repositoryFactory, logger, eventMessagesFactory)
|
||||
: base(provider, logger, eventMessagesFactory)
|
||||
{
|
||||
_runtimeCache = runtimeCache;
|
||||
IContentTypeService contentTypeService1 = contentTypeService;
|
||||
@@ -73,7 +74,7 @@ namespace Umbraco.Core.Services
|
||||
{
|
||||
var result = _runtimeCache.GetCacheItem<int?>(CacheKeys.IdToKeyCacheKey + key, () =>
|
||||
{
|
||||
using (var uow = UowProvider.GetUnitOfWork())
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
switch (umbracoObjectType)
|
||||
{
|
||||
@@ -116,7 +117,7 @@ namespace Umbraco.Core.Services
|
||||
{
|
||||
var result = _runtimeCache.GetCacheItem<Guid?>(CacheKeys.KeyToIdCacheKey + id, () =>
|
||||
{
|
||||
using (var uow = UowProvider.GetUnitOfWork())
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
switch (umbracoObjectType)
|
||||
{
|
||||
@@ -152,8 +153,9 @@ namespace Umbraco.Core.Services
|
||||
{
|
||||
if (loadBaseType)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateEntityRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IEntityRepository>();
|
||||
return repository.GetByKey(key);
|
||||
}
|
||||
}
|
||||
@@ -182,8 +184,9 @@ namespace Umbraco.Core.Services
|
||||
{
|
||||
if (loadBaseType)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateEntityRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IEntityRepository>();
|
||||
return repository.Get(id);
|
||||
}
|
||||
}
|
||||
@@ -201,8 +204,9 @@ namespace Umbraco.Core.Services
|
||||
if (loadBaseType)
|
||||
{
|
||||
var objectTypeId = umbracoObjectType.GetGuid();
|
||||
using (var repository = RepositoryFactory.CreateEntityRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IEntityRepository>();
|
||||
return repository.GetByKey(key, objectTypeId);
|
||||
}
|
||||
}
|
||||
@@ -232,8 +236,9 @@ namespace Umbraco.Core.Services
|
||||
if (loadBaseType)
|
||||
{
|
||||
var objectTypeId = umbracoObjectType.GetGuid();
|
||||
using (var repository = RepositoryFactory.CreateEntityRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IEntityRepository>();
|
||||
return repository.Get(id, objectTypeId);
|
||||
}
|
||||
}
|
||||
@@ -264,8 +269,9 @@ namespace Umbraco.Core.Services
|
||||
{
|
||||
if (loadBaseType)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateEntityRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IEntityRepository>();
|
||||
return repository.Get(id);
|
||||
}
|
||||
}
|
||||
@@ -288,8 +294,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>An <see cref="IUmbracoEntity"/></returns>
|
||||
public virtual IUmbracoEntity GetParent(int id)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateEntityRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IEntityRepository>();
|
||||
var entity = repository.Get(id);
|
||||
if (entity.ParentId == -1 || entity.ParentId == -20 || entity.ParentId == -21)
|
||||
return null;
|
||||
@@ -306,8 +313,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>An <see cref="IUmbracoEntity"/></returns>
|
||||
public virtual IUmbracoEntity GetParent(int id, UmbracoObjectTypes umbracoObjectType)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateEntityRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IEntityRepository>();
|
||||
var entity = repository.Get(id);
|
||||
if (entity.ParentId == -1 || entity.ParentId == -20 || entity.ParentId == -21)
|
||||
return null;
|
||||
@@ -324,8 +332,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>An enumerable list of <see cref="IUmbracoEntity"/> objects</returns>
|
||||
public virtual IEnumerable<IUmbracoEntity> GetChildren(int parentId)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateEntityRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IEntityRepository>();
|
||||
var query = repository.Query.Where(x => x.ParentId == parentId);
|
||||
var contents = repository.GetByQuery(query);
|
||||
|
||||
@@ -342,8 +351,9 @@ namespace Umbraco.Core.Services
|
||||
public virtual IEnumerable<IUmbracoEntity> GetChildren(int parentId, UmbracoObjectTypes umbracoObjectType)
|
||||
{
|
||||
var objectTypeId = umbracoObjectType.GetGuid();
|
||||
using (var repository = RepositoryFactory.CreateEntityRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IEntityRepository>();
|
||||
var query = repository.Query.Where(x => x.ParentId == parentId);
|
||||
var contents = repository.GetByQuery(query, objectTypeId).ToList(); // run within using!
|
||||
|
||||
@@ -358,8 +368,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>An enumerable list of <see cref="IUmbracoEntity"/> objects</returns>
|
||||
public virtual IEnumerable<IUmbracoEntity> GetDescendents(int id)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateEntityRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IEntityRepository>();
|
||||
var entity = repository.Get(id);
|
||||
var pathMatch = entity.Path + ",";
|
||||
var query = repository.Query.Where(x => x.Path.StartsWith(pathMatch) && x.Id != id);
|
||||
@@ -378,8 +389,9 @@ namespace Umbraco.Core.Services
|
||||
public virtual IEnumerable<IUmbracoEntity> GetDescendents(int id, UmbracoObjectTypes umbracoObjectType)
|
||||
{
|
||||
var objectTypeId = umbracoObjectType.GetGuid();
|
||||
using (var repository = RepositoryFactory.CreateEntityRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IEntityRepository>();
|
||||
var entity = repository.Get(id);
|
||||
var query = repository.Query.Where(x => x.Path.StartsWith(entity.Path) && x.Id != id);
|
||||
var entities = repository.GetByQuery(query, objectTypeId);
|
||||
@@ -396,8 +408,9 @@ namespace Umbraco.Core.Services
|
||||
public virtual IEnumerable<IUmbracoEntity> GetRootEntities(UmbracoObjectTypes umbracoObjectType)
|
||||
{
|
||||
var objectTypeId = umbracoObjectType.GetGuid();
|
||||
using (var repository = RepositoryFactory.CreateEntityRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IEntityRepository>();
|
||||
var query = repository.Query.Where(x => x.ParentId == -1);
|
||||
var entities = repository.GetByQuery(query, objectTypeId);
|
||||
|
||||
@@ -440,8 +453,9 @@ namespace Umbraco.Core.Services
|
||||
});
|
||||
|
||||
var objectTypeId = umbracoObjectType.GetGuid();
|
||||
using (var repository = RepositoryFactory.CreateEntityRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IEntityRepository>();
|
||||
return repository.GetAll(objectTypeId, ids);
|
||||
}
|
||||
}
|
||||
@@ -457,8 +471,9 @@ namespace Umbraco.Core.Services
|
||||
});
|
||||
|
||||
var objectTypeId = umbracoObjectType.GetGuid();
|
||||
using (var repository = RepositoryFactory.CreateEntityRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IEntityRepository>();
|
||||
return repository.GetAll(objectTypeId, keys);
|
||||
}
|
||||
}
|
||||
@@ -480,8 +495,9 @@ namespace Umbraco.Core.Services
|
||||
("The passed in type is not supported");
|
||||
});
|
||||
|
||||
using (var repository = RepositoryFactory.CreateEntityRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IEntityRepository>();
|
||||
return repository.GetAll(objectTypeId, ids);
|
||||
}
|
||||
}
|
||||
@@ -493,7 +509,7 @@ namespace Umbraco.Core.Services
|
||||
/// <returns><see cref="UmbracoObjectTypes"/></returns>
|
||||
public virtual UmbracoObjectTypes GetObjectType(int id)
|
||||
{
|
||||
using (var uow = UowProvider.GetUnitOfWork())
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var sql = uow.Database.Sql()
|
||||
.Select("nodeObjectType")
|
||||
@@ -512,7 +528,7 @@ namespace Umbraco.Core.Services
|
||||
/// <returns><see cref="UmbracoObjectTypes"/></returns>
|
||||
public virtual UmbracoObjectTypes GetObjectType(Guid key)
|
||||
{
|
||||
using (var uow = UowProvider.GetUnitOfWork())
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var sql = uow.Database.Sql()
|
||||
.Select("nodeObjectType")
|
||||
|
||||
@@ -1,21 +1,19 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNet.Identity;
|
||||
using Umbraco.Core.Events;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models.Identity;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Persistence.Querying;
|
||||
using Umbraco.Core.Persistence.Repositories;
|
||||
using Umbraco.Core.Persistence.UnitOfWork;
|
||||
|
||||
namespace Umbraco.Core.Services
|
||||
{
|
||||
public class ExternalLoginService : RepositoryService, IExternalLoginService
|
||||
{
|
||||
public ExternalLoginService(IDatabaseUnitOfWorkProvider provider, RepositoryFactory repositoryFactory, ILogger logger, IEventMessagesFactory eventMessagesFactory)
|
||||
: base(provider, repositoryFactory, logger, eventMessagesFactory)
|
||||
{
|
||||
}
|
||||
public ExternalLoginService(IDatabaseUnitOfWorkProvider provider, ILogger logger, IEventMessagesFactory eventMessagesFactory)
|
||||
: base(provider, logger, eventMessagesFactory)
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
/// Returns all user logins assigned
|
||||
@@ -23,23 +21,25 @@ namespace Umbraco.Core.Services
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
public IEnumerable<IIdentityUserLogin> GetAll(int userId)
|
||||
{
|
||||
using (var repo = RepositoryFactory.CreateExternalLoginRepository(UowProvider.GetUnitOfWork()))
|
||||
{
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repo = uow.CreateRepository<IExternalLoginRepository>();
|
||||
return repo.GetByQuery(repo.Query.Where(x => x.UserId == userId));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns all logins matching the login info - generally there should only be one but in some cases
|
||||
/// Returns all logins matching the login info - generally there should only be one but in some cases
|
||||
/// there might be more than one depending on if an adminstrator has been editing/removing members
|
||||
/// </summary>
|
||||
/// <param name="login"></param>
|
||||
/// <returns></returns>
|
||||
public IEnumerable<IIdentityUserLogin> Find(UserLoginInfo login)
|
||||
{
|
||||
using (var repo = RepositoryFactory.CreateExternalLoginRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repo = uow.CreateRepository<IExternalLoginRepository>();
|
||||
return repo.GetByQuery(repo.Query
|
||||
.Where(x => x.ProviderKey == login.ProviderKey && x.LoginProvider == login.LoginProvider));
|
||||
}
|
||||
@@ -52,11 +52,11 @@ namespace Umbraco.Core.Services
|
||||
/// <param name="logins"></param>
|
||||
public void SaveUserLogins(int userId, IEnumerable<UserLoginInfo> logins)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repo = RepositoryFactory.CreateExternalLoginRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repo = uow.CreateRepository<IExternalLoginRepository>();
|
||||
repo.SaveUserLogins(userId, logins);
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,14 +66,12 @@ namespace Umbraco.Core.Services
|
||||
/// <param name="userId"></param>
|
||||
public void DeleteUserLogins(int userId)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repo = RepositoryFactory.CreateExternalLoginRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repo = uow.CreateRepository<IExternalLoginRepository>();
|
||||
repo.DeleteUserLogins(userId);
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,6 @@ using System.Linq;
|
||||
using System.Runtime.Remoting.Messaging;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Web;
|
||||
using Umbraco.Core.Auditing;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
using Umbraco.Core.Events;
|
||||
@@ -31,14 +30,13 @@ namespace Umbraco.Core.Services
|
||||
private const string PartialViewMacroHeader = "@inherits Umbraco.Web.Macros.PartialViewMacroPage";
|
||||
|
||||
public FileService(
|
||||
IUnitOfWorkProvider fileProvider,
|
||||
IDatabaseUnitOfWorkProvider dataProvider,
|
||||
RepositoryFactory repositoryFactory,
|
||||
IUnitOfWorkProvider fileProvider,
|
||||
IDatabaseUnitOfWorkProvider dataProvider,
|
||||
ILogger logger,
|
||||
IEventMessagesFactory eventMessagesFactory)
|
||||
: base(dataProvider, repositoryFactory, logger, eventMessagesFactory)
|
||||
: base(dataProvider, logger, eventMessagesFactory)
|
||||
{
|
||||
_fileUowProvider = fileProvider;
|
||||
_fileUowProvider = fileProvider;
|
||||
}
|
||||
|
||||
|
||||
@@ -50,8 +48,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>An enumerable list of <see cref="Stylesheet"/> objects</returns>
|
||||
public IEnumerable<Stylesheet> GetStylesheets(params string[] names)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateStylesheetRepository(_fileUowProvider.GetUnitOfWork(), UowProvider.GetUnitOfWork()))
|
||||
using (var uow = _fileUowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IStylesheetRepository>();
|
||||
return repository.GetAll(names);
|
||||
}
|
||||
}
|
||||
@@ -63,8 +62,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>A <see cref="Stylesheet"/> object</returns>
|
||||
public Stylesheet GetStylesheetByName(string name)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateStylesheetRepository(_fileUowProvider.GetUnitOfWork(), UowProvider.GetUnitOfWork()))
|
||||
using (var uow = _fileUowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IStylesheetRepository>();
|
||||
return repository.Get(name);
|
||||
}
|
||||
}
|
||||
@@ -79,16 +79,15 @@ namespace Umbraco.Core.Services
|
||||
if (SavingStylesheet.IsRaisedEventCancelled(new SaveEventArgs<Stylesheet>(stylesheet), this))
|
||||
return;
|
||||
|
||||
var uow = _fileUowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateStylesheetRepository(uow, UowProvider.GetUnitOfWork()))
|
||||
using (var uow = _fileUowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IStylesheetRepository>();
|
||||
repository.AddOrUpdate(stylesheet);
|
||||
uow.Commit();
|
||||
|
||||
SavedStylesheet.RaiseEvent(new SaveEventArgs<Stylesheet>(stylesheet, false), this);
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
Audit(AuditType.Save, string.Format("Save Stylesheet performed by user"), userId, -1);
|
||||
SavedStylesheet.RaiseEvent(new SaveEventArgs<Stylesheet>(stylesheet, false), this);
|
||||
Audit(AuditType.Save, "Save Stylesheet performed by user", userId, -1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -98,22 +97,22 @@ namespace Umbraco.Core.Services
|
||||
/// <param name="userId"></param>
|
||||
public void DeleteStylesheet(string path, int userId = 0)
|
||||
{
|
||||
var uow = _fileUowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateStylesheetRepository(uow, UowProvider.GetUnitOfWork()))
|
||||
Stylesheet stylesheet;
|
||||
using (var uow = _fileUowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var stylesheet = repository.Get(path);
|
||||
var repository = uow.CreateRepository<IStylesheetRepository>();
|
||||
stylesheet = repository.Get(path);
|
||||
if (stylesheet == null) return;
|
||||
|
||||
if (DeletingStylesheet.IsRaisedEventCancelled(new DeleteEventArgs<Stylesheet>(stylesheet), this))
|
||||
return;
|
||||
|
||||
repository.Delete(stylesheet);
|
||||
uow.Commit();
|
||||
|
||||
DeletedStylesheet.RaiseEvent(new DeleteEventArgs<Stylesheet>(stylesheet, false), this);
|
||||
|
||||
Audit(AuditType.Delete, string.Format("Delete Stylesheet performed by user"), userId, -1);
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
DeletedStylesheet.RaiseEvent(new DeleteEventArgs<Stylesheet>(stylesheet, false), this);
|
||||
Audit(AuditType.Delete, "Delete Stylesheet performed by user", userId, -1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -123,10 +122,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>True if Stylesheet is valid, otherwise false</returns>
|
||||
public bool ValidateStylesheet(Stylesheet stylesheet)
|
||||
{
|
||||
|
||||
var uow = _fileUowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateStylesheetRepository(uow, UowProvider.GetUnitOfWork()))
|
||||
using (var uow = _fileUowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IStylesheetRepository>();
|
||||
return repository.ValidateStylesheet(stylesheet);
|
||||
}
|
||||
}
|
||||
@@ -140,8 +138,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>An enumerable list of <see cref="Script"/> objects</returns>
|
||||
public IEnumerable<Script> GetScripts(params string[] names)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateScriptRepository(_fileUowProvider.GetUnitOfWork()))
|
||||
using (var uow = _fileUowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IScriptRepository>();
|
||||
return repository.GetAll(names);
|
||||
}
|
||||
}
|
||||
@@ -153,8 +152,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>A <see cref="Script"/> object</returns>
|
||||
public Script GetScriptByName(string name)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateScriptRepository(_fileUowProvider.GetUnitOfWork()))
|
||||
using (var uow = _fileUowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IScriptRepository>();
|
||||
return repository.Get(name);
|
||||
}
|
||||
}
|
||||
@@ -169,15 +169,14 @@ namespace Umbraco.Core.Services
|
||||
if (SavingScript.IsRaisedEventCancelled(new SaveEventArgs<Script>(script), this))
|
||||
return;
|
||||
|
||||
var uow = _fileUowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateScriptRepository(uow))
|
||||
using (var uow = _fileUowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IScriptRepository>();
|
||||
repository.AddOrUpdate(script);
|
||||
uow.Commit();
|
||||
|
||||
SavedScript.RaiseEvent(new SaveEventArgs<Script>(script, false), this);
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
SavedScript.RaiseEvent(new SaveEventArgs<Script>(script, false), this);
|
||||
Audit(AuditType.Save, string.Format("Save Script performed by user"), userId, -1);
|
||||
}
|
||||
|
||||
@@ -188,22 +187,23 @@ namespace Umbraco.Core.Services
|
||||
/// <param name="userId"></param>
|
||||
public void DeleteScript(string path, int userId = 0)
|
||||
{
|
||||
var uow = _fileUowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateScriptRepository(uow))
|
||||
Script script;
|
||||
|
||||
using (var uow = _fileUowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var script = repository.Get(path);
|
||||
var repository = uow.CreateRepository<IScriptRepository>();
|
||||
script = repository.Get(path);
|
||||
if (script == null) return;
|
||||
|
||||
if (DeletingScript.IsRaisedEventCancelled(new DeleteEventArgs<Script>(script), this))
|
||||
return; ;
|
||||
return;
|
||||
|
||||
repository.Delete(script);
|
||||
uow.Commit();
|
||||
|
||||
DeletedScript.RaiseEvent(new DeleteEventArgs<Script>(script, false), this);
|
||||
|
||||
Audit(AuditType.Delete, string.Format("Delete Script performed by user"), userId, -1);
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
DeletedScript.RaiseEvent(new DeleteEventArgs<Script>(script, false), this);
|
||||
Audit(AuditType.Delete, string.Format("Delete Script performed by user"), userId, -1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -213,30 +213,30 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>True if Script is valid, otherwise false</returns>
|
||||
public bool ValidateScript(Script script)
|
||||
{
|
||||
var uow = _fileUowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateScriptRepository(uow))
|
||||
using (var uow = _fileUowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IScriptRepository>();
|
||||
return repository.ValidateScript(script);
|
||||
}
|
||||
}
|
||||
|
||||
public void CreateScriptFolder(string folderPath)
|
||||
{
|
||||
var uow = _fileUowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateScriptRepository(uow))
|
||||
using (var uow = _fileUowProvider.CreateUnitOfWork())
|
||||
{
|
||||
((ScriptRepository)repository).AddFolder(folderPath);
|
||||
uow.Commit();
|
||||
var repository = uow.CreateRepository<IScriptRepository>();
|
||||
((ScriptRepository) repository).AddFolder(folderPath);
|
||||
uow.Complete();
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteScriptFolder(string folderPath)
|
||||
{
|
||||
var uow = _fileUowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateScriptRepository(uow))
|
||||
using (var uow = _fileUowProvider.CreateUnitOfWork())
|
||||
{
|
||||
((ScriptRepository)repository).DeleteFolder(folderPath);
|
||||
uow.Commit();
|
||||
var repository = uow.CreateRepository<IScriptRepository>();
|
||||
((ScriptRepository) repository).DeleteFolder(folderPath);
|
||||
uow.Complete();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -280,16 +280,15 @@ namespace Umbraco.Core.Services
|
||||
return Attempt.Fail(new OperationStatus<ITemplate, OperationStatusType>(template, OperationStatusType.FailedCancelledByEvent, evtMsgs));
|
||||
}
|
||||
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateTemplateRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<ITemplateRepository>();
|
||||
repository.AddOrUpdate(template);
|
||||
uow.Commit();
|
||||
|
||||
SavedTemplate.RaiseEvent(new SaveEventArgs<ITemplate>(template, false, evtMsgs), this);
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
Audit(AuditType.Save, string.Format("Save Template performed by user"), userId, template.Id);
|
||||
SavedTemplate.RaiseEvent(new SaveEventArgs<ITemplate>(template, false, evtMsgs), this);
|
||||
Audit(AuditType.Save, "Save Template performed by user", userId, template.Id);
|
||||
|
||||
return Attempt.Succeed(new OperationStatus<ITemplate, OperationStatusType>(template, OperationStatusType.Success, evtMsgs));
|
||||
}
|
||||
@@ -314,8 +313,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>An enumerable list of <see cref="ITemplate"/> objects</returns>
|
||||
public IEnumerable<ITemplate> GetTemplates(params string[] aliases)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateTemplateRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<ITemplateRepository>();
|
||||
return repository.GetAll(aliases).OrderBy(x => x.Name);
|
||||
}
|
||||
}
|
||||
@@ -326,8 +326,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>An enumerable list of <see cref="ITemplate"/> objects</returns>
|
||||
public IEnumerable<ITemplate> GetTemplates(int masterTemplateId)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateTemplateRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<ITemplateRepository>();
|
||||
return repository.GetChildren(masterTemplateId).OrderBy(x => x.Name);
|
||||
}
|
||||
}
|
||||
@@ -339,8 +340,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>The <see cref="ITemplate"/> object matching the alias, or null.</returns>
|
||||
public ITemplate GetTemplate(string alias)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateTemplateRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<ITemplateRepository>();
|
||||
return repository.Get(alias);
|
||||
}
|
||||
}
|
||||
@@ -352,8 +354,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>The <see cref="ITemplate"/> object matching the identifier, or null.</returns>
|
||||
public ITemplate GetTemplate(int id)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateTemplateRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<ITemplateRepository>();
|
||||
return repository.Get(id);
|
||||
}
|
||||
}
|
||||
@@ -365,8 +368,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>The <see cref="ITemplate"/> object matching the identifier, or null.</returns>
|
||||
public ITemplate GetTemplate(Guid id)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateTemplateRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<ITemplateRepository>();
|
||||
var query = repository.Query.Where(x => x.Key == id);
|
||||
return repository.GetByQuery(query).SingleOrDefault();
|
||||
}
|
||||
@@ -374,8 +378,9 @@ namespace Umbraco.Core.Services
|
||||
|
||||
public IEnumerable<ITemplate> GetTemplateDescendants(string alias)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateTemplateRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<ITemplateRepository>();
|
||||
return repository.GetDescendants(alias);
|
||||
}
|
||||
}
|
||||
@@ -387,8 +392,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns></returns>
|
||||
public IEnumerable<ITemplate> GetTemplateDescendants(int masterTemplateId)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateTemplateRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<ITemplateRepository>();
|
||||
return repository.GetDescendants(masterTemplateId);
|
||||
}
|
||||
}
|
||||
@@ -400,8 +406,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns></returns>
|
||||
public IEnumerable<ITemplate> GetTemplateChildren(string alias)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateTemplateRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<ITemplateRepository>();
|
||||
return repository.GetChildren(alias);
|
||||
}
|
||||
}
|
||||
@@ -413,8 +420,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns></returns>
|
||||
public IEnumerable<ITemplate> GetTemplateChildren(int masterTemplateId)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateTemplateRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<ITemplateRepository>();
|
||||
return repository.GetChildren(masterTemplateId);
|
||||
}
|
||||
}
|
||||
@@ -428,8 +436,9 @@ namespace Umbraco.Core.Services
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
public TemplateNode GetTemplateNode(string alias)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateTemplateRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<ITemplateRepository>();
|
||||
return repository.GetTemplateNode(alias);
|
||||
}
|
||||
}
|
||||
@@ -444,8 +453,9 @@ namespace Umbraco.Core.Services
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
public TemplateNode FindTemplateInTree(TemplateNode anyNode, string alias)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateTemplateRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<ITemplateRepository>();
|
||||
return repository.FindTemplateInTree(anyNode, alias);
|
||||
}
|
||||
}
|
||||
@@ -460,16 +470,15 @@ namespace Umbraco.Core.Services
|
||||
if (SavingTemplate.IsRaisedEventCancelled(new SaveEventArgs<ITemplate>(template), this))
|
||||
return;
|
||||
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateTemplateRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<ITemplateRepository>();
|
||||
repository.AddOrUpdate(template);
|
||||
uow.Commit();
|
||||
|
||||
SavedTemplate.RaiseEvent(new SaveEventArgs<ITemplate>(template, false), this);
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
Audit(AuditType.Save, string.Format("Save Template performed by user"), userId, template.Id);
|
||||
SavedTemplate.RaiseEvent(new SaveEventArgs<ITemplate>(template, false), this);
|
||||
Audit(AuditType.Save, "Save Template performed by user", userId, template.Id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -482,39 +491,36 @@ namespace Umbraco.Core.Services
|
||||
if (SavingTemplate.IsRaisedEventCancelled(new SaveEventArgs<ITemplate>(templates), this))
|
||||
return;
|
||||
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateTemplateRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<ITemplateRepository>();
|
||||
foreach (var template in templates)
|
||||
{
|
||||
repository.AddOrUpdate(template);
|
||||
}
|
||||
uow.Commit();
|
||||
|
||||
SavedTemplate.RaiseEvent(new SaveEventArgs<ITemplate>(templates, false), this);
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
Audit(AuditType.Save, string.Format("Save Template performed by user"), userId, -1);
|
||||
SavedTemplate.RaiseEvent(new SaveEventArgs<ITemplate>(templates, false), this);
|
||||
Audit(AuditType.Save, "Save Template performed by user", userId, -1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This checks what the default rendering engine is set in config but then also ensures that there isn't already
|
||||
/// a template that exists in the opposite rendering engine's template folder, then returns the appropriate
|
||||
/// This checks what the default rendering engine is set in config but then also ensures that there isn't already
|
||||
/// a template that exists in the opposite rendering engine's template folder, then returns the appropriate
|
||||
/// rendering engine to use.
|
||||
/// </summary>
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <remarks>
|
||||
/// The reason this is required is because for example, if you have a master page file already existing under ~/masterpages/Blah.aspx
|
||||
/// and then you go to create a template in the tree called Blah and the default rendering engine is MVC, it will create a Blah.cshtml
|
||||
/// empty template in ~/Views. This means every page that is using Blah will go to MVC and render an empty page.
|
||||
/// This is mostly related to installing packages since packages install file templates to the file system and then create the
|
||||
/// and then you go to create a template in the tree called Blah and the default rendering engine is MVC, it will create a Blah.cshtml
|
||||
/// empty template in ~/Views. This means every page that is using Blah will go to MVC and render an empty page.
|
||||
/// This is mostly related to installing packages since packages install file templates to the file system and then create the
|
||||
/// templates in business logic. Without this, it could cause the wrong rendering engine to be used for a package.
|
||||
/// </remarks>
|
||||
public RenderingEngine DetermineTemplateRenderingEngine(ITemplate template)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateTemplateRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<ITemplateRepository>();
|
||||
return repository.DetermineTemplateRenderingEngine(template);
|
||||
}
|
||||
}
|
||||
@@ -526,22 +532,22 @@ namespace Umbraco.Core.Services
|
||||
/// <param name="userId"></param>
|
||||
public void DeleteTemplate(string alias, int userId = 0)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateTemplateRepository(uow))
|
||||
ITemplate template;
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var template = repository.Get(alias);
|
||||
var repository = uow.CreateRepository<ITemplateRepository>();
|
||||
template = repository.Get(alias);
|
||||
if (template == null) return;
|
||||
|
||||
if (DeletingTemplate.IsRaisedEventCancelled(new DeleteEventArgs<ITemplate>(template), this))
|
||||
return;
|
||||
|
||||
repository.Delete(template);
|
||||
uow.Commit();
|
||||
|
||||
DeletedTemplate.RaiseEvent(new DeleteEventArgs<ITemplate>(template, false), this);
|
||||
|
||||
Audit(AuditType.Delete, string.Format("Delete Template performed by user"), userId, template.Id);
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
DeletedTemplate.RaiseEvent(new DeleteEventArgs<ITemplate>(template, false), this);
|
||||
Audit(AuditType.Delete, "Delete Template performed by user", userId, template.Id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -551,9 +557,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>True if Script is valid, otherwise false</returns>
|
||||
public bool ValidateTemplate(ITemplate template)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateTemplateRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<ITemplateRepository>();
|
||||
return repository.ValidateTemplate(template);
|
||||
}
|
||||
}
|
||||
@@ -576,40 +582,42 @@ namespace Umbraco.Core.Services
|
||||
.ToArray();
|
||||
|
||||
return empty.Union(files.Except(empty));
|
||||
}
|
||||
}
|
||||
|
||||
public void DeletePartialViewFolder(string folderPath)
|
||||
{
|
||||
var uow = _fileUowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreatePartialViewRepository(uow))
|
||||
using (var uow = _fileUowProvider.CreateUnitOfWork())
|
||||
{
|
||||
((PartialViewRepository)repository).DeleteFolder(folderPath);
|
||||
uow.Commit();
|
||||
var repository = uow.CreateRepository<IPartialViewRepository>();
|
||||
((PartialViewRepository) repository).DeleteFolder(folderPath);
|
||||
uow.Complete();
|
||||
}
|
||||
}
|
||||
|
||||
public void DeletePartialViewMacroFolder(string folderPath)
|
||||
{
|
||||
var uow = _fileUowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreatePartialViewMacroRepository(uow))
|
||||
using (var uow = _fileUowProvider.CreateUnitOfWork())
|
||||
{
|
||||
((PartialViewMacroRepository)repository).DeleteFolder(folderPath);
|
||||
uow.Commit();
|
||||
var repository = uow.CreateRepository<IPartialViewMacroRepository>();
|
||||
((PartialViewMacroRepository) repository).DeleteFolder(folderPath);
|
||||
uow.Complete();
|
||||
}
|
||||
}
|
||||
|
||||
public IPartialView GetPartialView(string path)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreatePartialViewRepository(_fileUowProvider.GetUnitOfWork()))
|
||||
using (var uow = _fileUowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IPartialViewRepository>();
|
||||
return repository.Get(path);
|
||||
}
|
||||
}
|
||||
|
||||
public IPartialView GetPartialViewMacro(string path)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreatePartialViewMacroRepository(_fileUowProvider.GetUnitOfWork()))
|
||||
using (var uow = _fileUowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IPartialViewMacroRepository>();
|
||||
return repository.Get(path);
|
||||
}
|
||||
}
|
||||
@@ -657,25 +665,23 @@ namespace Umbraco.Core.Services
|
||||
|
||||
//strip the @inherits if it's there
|
||||
snippetContent = StripPartialViewHeader(snippetContent);
|
||||
|
||||
|
||||
var content = string.Format("{0}{1}{2}",
|
||||
partialViewHeader,
|
||||
partialViewHeader,
|
||||
Environment.NewLine, snippetContent);
|
||||
partialView.Content = content;
|
||||
}
|
||||
}
|
||||
|
||||
var uow = _fileUowProvider.GetUnitOfWork();
|
||||
using (var repository = GetPartialViewRepository(partialViewType, uow))
|
||||
using (var uow = _fileUowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreatePartialViewRepository(partialViewType);
|
||||
repository.AddOrUpdate(partialView);
|
||||
uow.Commit();
|
||||
|
||||
CreatedPartialView.RaiseEvent(new NewEventArgs<IPartialView>(partialView, false, partialView.Alias, -1), this);
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
Audit(AuditType.Save, string.Format("Save {0} performed by user", partialViewType), userId, -1);
|
||||
|
||||
CreatedPartialView.RaiseEvent(new NewEventArgs<IPartialView>(partialView, false, partialView.Alias, -1), this);
|
||||
Audit(AuditType.Save, $"Save {partialViewType} performed by user", userId, -1);
|
||||
return Attempt<IPartialView>.Succeed(partialView);
|
||||
}
|
||||
|
||||
@@ -691,10 +697,11 @@ namespace Umbraco.Core.Services
|
||||
|
||||
private bool DeletePartialViewMacro(string path, PartialViewType partialViewType, int userId = 0)
|
||||
{
|
||||
var uow = _fileUowProvider.GetUnitOfWork();
|
||||
using (var repository = GetPartialViewRepository(partialViewType, uow))
|
||||
IPartialView partialView;
|
||||
using (var uow = _fileUowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var partialView = repository.Get(path);
|
||||
var repository = uow.CreatePartialViewRepository(partialViewType);
|
||||
partialView = repository.Get(path);
|
||||
if (partialView == null)
|
||||
return true;
|
||||
|
||||
@@ -702,15 +709,12 @@ namespace Umbraco.Core.Services
|
||||
return false;
|
||||
|
||||
repository.Delete(partialView);
|
||||
uow.Commit();
|
||||
|
||||
DeletedPartialView.RaiseEvent(new DeleteEventArgs<IPartialView>(partialView, false), this);
|
||||
|
||||
Audit(AuditType.Delete, string.Format("Delete {0} performed by user", partialViewType), userId, -1);
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
DeletedPartialView.RaiseEvent(new DeleteEventArgs<IPartialView>(partialView, false), this);
|
||||
Audit(AuditType.Delete, $"Delete {partialViewType} performed by user", userId, -1);
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
public Attempt<IPartialView> SavePartialView(IPartialView partialView, int userId = 0)
|
||||
@@ -728,34 +732,32 @@ namespace Umbraco.Core.Services
|
||||
if (SavingPartialView.IsRaisedEventCancelled(new SaveEventArgs<IPartialView>(partialView), this))
|
||||
return Attempt<IPartialView>.Fail();
|
||||
|
||||
var uow = _fileUowProvider.GetUnitOfWork();
|
||||
using (var repository = GetPartialViewRepository(partialViewType, uow))
|
||||
using (var uow = _fileUowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreatePartialViewRepository(partialViewType);
|
||||
repository.AddOrUpdate(partialView);
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
Audit(AuditType.Save, string.Format("Save {0} performed by user", partialViewType), userId, -1);
|
||||
|
||||
Audit(AuditType.Save, $"Save {partialViewType} performed by user", userId, -1);
|
||||
SavedPartialView.RaiseEvent(new SaveEventArgs<IPartialView>(partialView, false), this);
|
||||
|
||||
return Attempt.Succeed(partialView);
|
||||
}
|
||||
|
||||
public bool ValidatePartialView(PartialView partialView)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreatePartialViewRepository(uow))
|
||||
using (var uow = _fileUowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IPartialViewRepository>();
|
||||
return repository.ValidatePartialView(partialView);
|
||||
}
|
||||
}
|
||||
|
||||
public bool ValidatePartialViewMacro(PartialView partialView)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreatePartialViewMacroRepository(uow))
|
||||
using (var uow = _fileUowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IPartialViewMacroRepository>();
|
||||
return repository.ValidatePartialView(partialView);
|
||||
}
|
||||
}
|
||||
@@ -779,27 +781,15 @@ namespace Umbraco.Core.Services
|
||||
: Attempt<string>.Fail();
|
||||
}
|
||||
|
||||
private IPartialViewRepository GetPartialViewRepository(PartialViewType partialViewType, IUnitOfWork uow)
|
||||
{
|
||||
switch (partialViewType)
|
||||
{
|
||||
case PartialViewType.PartialView:
|
||||
return RepositoryFactory.CreatePartialViewRepository(uow);
|
||||
case PartialViewType.PartialViewMacro:
|
||||
return RepositoryFactory.CreatePartialViewMacroRepository(uow);
|
||||
}
|
||||
throw new ArgumentOutOfRangeException("partialViewType");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private void Audit(AuditType type, string message, int userId, int objectId)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var auditRepo = RepositoryFactory.CreateAuditRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
auditRepo.AddOrUpdate(new AuditItem(objectId, message, type, userId));
|
||||
uow.Commit();
|
||||
var repo = uow.CreateRepository<IAuditRepository>();
|
||||
repo.AddOrUpdate(new AuditItem(objectId, message, type, userId));
|
||||
uow.Complete();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -808,7 +798,7 @@ namespace Umbraco.Core.Services
|
||||
#region Event Handlers
|
||||
/// <summary>
|
||||
/// Occurs before Delete
|
||||
/// </summary>
|
||||
/// </summary>
|
||||
public static event TypedEventHandler<IFileService, DeleteEventArgs<ITemplate>> DeletingTemplate;
|
||||
|
||||
/// <summary>
|
||||
@@ -818,7 +808,7 @@ namespace Umbraco.Core.Services
|
||||
|
||||
/// <summary>
|
||||
/// Occurs before Delete
|
||||
/// </summary>
|
||||
/// </summary>
|
||||
public static event TypedEventHandler<IFileService, DeleteEventArgs<Script>> DeletingScript;
|
||||
|
||||
/// <summary>
|
||||
@@ -828,7 +818,7 @@ namespace Umbraco.Core.Services
|
||||
|
||||
/// <summary>
|
||||
/// Occurs before Delete
|
||||
/// </summary>
|
||||
/// </summary>
|
||||
public static event TypedEventHandler<IFileService, DeleteEventArgs<Stylesheet>> DeletingStylesheet;
|
||||
|
||||
/// <summary>
|
||||
@@ -875,7 +865,7 @@ namespace Umbraco.Core.Services
|
||||
/// Occurs after Save
|
||||
/// </summary>
|
||||
public static event TypedEventHandler<IFileService, SaveEventArgs<IPartialView>> SavedPartialView;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Occurs before Create
|
||||
/// </summary>
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Umbraco.Core.Auditing;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Events;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Persistence.Querying;
|
||||
using Umbraco.Core.Persistence.Repositories;
|
||||
using Umbraco.Core.Persistence.SqlSyntax;
|
||||
using Umbraco.Core.Persistence.UnitOfWork;
|
||||
|
||||
@@ -20,8 +20,8 @@ namespace Umbraco.Core.Services
|
||||
{
|
||||
|
||||
|
||||
public LocalizationService(IDatabaseUnitOfWorkProvider provider, RepositoryFactory repositoryFactory, ILogger logger, IEventMessagesFactory eventMessagesFactory)
|
||||
: base(provider, repositoryFactory, logger, eventMessagesFactory)
|
||||
public LocalizationService(IDatabaseUnitOfWorkProvider provider, ILogger logger, IEventMessagesFactory eventMessagesFactory)
|
||||
: base(provider, logger, eventMessagesFactory)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -63,9 +63,10 @@ namespace Umbraco.Core.Services
|
||||
/// <returns></returns>
|
||||
public IDictionaryItem CreateDictionaryItemWithIdentity(string key, Guid? parentId, string defaultValue = null)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateDictionaryRepository(uow))
|
||||
DictionaryItem item;
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IDictionaryRepository>();
|
||||
//validate the parent
|
||||
if (parentId.HasValue && parentId.Value != Guid.Empty)
|
||||
{
|
||||
@@ -76,7 +77,7 @@ namespace Umbraco.Core.Services
|
||||
}
|
||||
}
|
||||
|
||||
var item = new DictionaryItem(parentId, key);
|
||||
item = new DictionaryItem(parentId, key);
|
||||
|
||||
if (defaultValue.IsNullOrWhiteSpace() == false)
|
||||
{
|
||||
@@ -92,15 +93,14 @@ namespace Umbraco.Core.Services
|
||||
return item;
|
||||
|
||||
repository.AddOrUpdate(item);
|
||||
uow.Commit();
|
||||
|
||||
//ensure the lazy Language callback is assigned
|
||||
EnsureDictionaryItemLanguageCallback(item);
|
||||
|
||||
SavedDictionaryItem.RaiseEvent(new SaveEventArgs<IDictionaryItem>(item), this);
|
||||
|
||||
return item;
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
// ensure the lazy Language callback is assigned
|
||||
EnsureDictionaryItemLanguageCallback(item);
|
||||
|
||||
SavedDictionaryItem.RaiseEvent(new SaveEventArgs<IDictionaryItem>(item), this);
|
||||
return item;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -110,8 +110,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns><see cref="IDictionaryItem"/></returns>
|
||||
public IDictionaryItem GetDictionaryItemById(int id)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateDictionaryRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IDictionaryRepository>();
|
||||
var item = repository.Get(id);
|
||||
//ensure the lazy Language callback is assigned
|
||||
EnsureDictionaryItemLanguageCallback(item);
|
||||
@@ -126,8 +127,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns><see cref="DictionaryItem"/></returns>
|
||||
public IDictionaryItem GetDictionaryItemById(Guid id)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateDictionaryRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IDictionaryRepository>();
|
||||
var item = repository.Get(id);
|
||||
//ensure the lazy Language callback is assigned
|
||||
EnsureDictionaryItemLanguageCallback(item);
|
||||
@@ -142,8 +144,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns><see cref="IDictionaryItem"/></returns>
|
||||
public IDictionaryItem GetDictionaryItemByKey(string key)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateDictionaryRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IDictionaryRepository>();
|
||||
var item = repository.Get(key);
|
||||
//ensure the lazy Language callback is assigned
|
||||
EnsureDictionaryItemLanguageCallback(item);
|
||||
@@ -158,8 +161,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>An enumerable list of <see cref="IDictionaryItem"/> objects</returns>
|
||||
public IEnumerable<IDictionaryItem> GetDictionaryItemChildren(Guid parentId)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateDictionaryRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IDictionaryRepository>();
|
||||
var query = repository.Query.Where(x => x.ParentId == parentId);
|
||||
var items = repository.GetByQuery(query).ToArray();
|
||||
//ensure the lazy Language callback is assigned
|
||||
@@ -175,8 +179,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>An enumerable list of <see cref="IDictionaryItem"/> objects</returns>
|
||||
public IEnumerable<IDictionaryItem> GetDictionaryItemDescendants(Guid? parentId)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateDictionaryRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IDictionaryRepository>();
|
||||
var items = repository.GetDictionaryItemDescendants(parentId).ToArray();
|
||||
//ensure the lazy Language callback is assigned
|
||||
items.ForEach(EnsureDictionaryItemLanguageCallback);
|
||||
@@ -190,8 +195,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>An enumerable list of <see cref="IDictionaryItem"/> objects</returns>
|
||||
public IEnumerable<IDictionaryItem> GetRootDictionaryItems()
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateDictionaryRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IDictionaryRepository>();
|
||||
var query = repository.QueryFactory.Create<IDictionaryItem>().Where(x => x.ParentId == null);
|
||||
var items = repository.GetByQuery(query).ToArray();
|
||||
//ensure the lazy Language callback is assigned
|
||||
@@ -207,8 +213,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>True if a <see cref="IDictionaryItem"/> exists, otherwise false</returns>
|
||||
public bool DictionaryItemExists(string key)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateDictionaryRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IDictionaryRepository>();
|
||||
return repository.Get(key) != null;
|
||||
}
|
||||
}
|
||||
@@ -223,17 +230,17 @@ namespace Umbraco.Core.Services
|
||||
if (SavingDictionaryItem.IsRaisedEventCancelled(new SaveEventArgs<IDictionaryItem>(dictionaryItem), this))
|
||||
return;
|
||||
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateDictionaryRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IDictionaryRepository>();
|
||||
repository.AddOrUpdate(dictionaryItem);
|
||||
uow.Commit();
|
||||
//ensure the lazy Language callback is assigned
|
||||
EnsureDictionaryItemLanguageCallback(dictionaryItem);
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
SavedDictionaryItem.RaiseEvent(new SaveEventArgs<IDictionaryItem>(dictionaryItem, false), this);
|
||||
// ensure the lazy Language callback is assigned
|
||||
EnsureDictionaryItemLanguageCallback(dictionaryItem);
|
||||
|
||||
SavedDictionaryItem.RaiseEvent(new SaveEventArgs<IDictionaryItem>(dictionaryItem, false), this);
|
||||
Audit(AuditType.Save, "Save DictionaryItem performed by user", userId, dictionaryItem.Id);
|
||||
}
|
||||
|
||||
@@ -248,16 +255,14 @@ namespace Umbraco.Core.Services
|
||||
if (DeletingDictionaryItem.IsRaisedEventCancelled(new DeleteEventArgs<IDictionaryItem>(dictionaryItem), this))
|
||||
return;
|
||||
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateDictionaryRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
//NOTE: The recursive delete is done in the repository
|
||||
repository.Delete(dictionaryItem);
|
||||
uow.Commit();
|
||||
var repository = uow.CreateRepository<IDictionaryRepository>();
|
||||
repository.Delete(dictionaryItem); // recursive delete
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
DeletedDictionaryItem.RaiseEvent(new DeleteEventArgs<IDictionaryItem>(dictionaryItem, false), this);
|
||||
|
||||
Audit(AuditType.Delete, "Delete DictionaryItem performed by user", userId, dictionaryItem.Id);
|
||||
}
|
||||
|
||||
@@ -268,8 +273,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns><see cref="Language"/></returns>
|
||||
public ILanguage GetLanguageById(int id)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateLanguageRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<ILanguageRepository>();
|
||||
return repository.Get(id);
|
||||
}
|
||||
}
|
||||
@@ -281,8 +287,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns><see cref="Language"/></returns>
|
||||
public ILanguage GetLanguageByCultureCode(string cultureName)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateLanguageRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<ILanguageRepository>();
|
||||
return repository.GetByCultureName(cultureName);
|
||||
}
|
||||
}
|
||||
@@ -294,8 +301,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns><see cref="Language"/></returns>
|
||||
public ILanguage GetLanguageByIsoCode(string isoCode)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateLanguageRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<ILanguageRepository>();
|
||||
return repository.GetByIsoCode(isoCode);
|
||||
}
|
||||
}
|
||||
@@ -306,8 +314,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>An enumerable list of <see cref="ILanguage"/> objects</returns>
|
||||
public IEnumerable<ILanguage> GetAllLanguages()
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateLanguageRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<ILanguageRepository>();
|
||||
var languages = repository.GetAll();
|
||||
return languages;
|
||||
}
|
||||
@@ -323,11 +332,11 @@ namespace Umbraco.Core.Services
|
||||
if (SavingLanguage.IsRaisedEventCancelled(new SaveEventArgs<ILanguage>(language), this))
|
||||
return;
|
||||
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateLanguageRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<ILanguageRepository>();
|
||||
repository.AddOrUpdate(language);
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
SavedLanguage.RaiseEvent(new SaveEventArgs<ILanguage>(language, false), this);
|
||||
@@ -345,12 +354,12 @@ namespace Umbraco.Core.Services
|
||||
if (DeletingLanguage.IsRaisedEventCancelled(new DeleteEventArgs<ILanguage>(language), this))
|
||||
return;
|
||||
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateLanguageRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<ILanguageRepository>();
|
||||
//NOTE: There isn't any constraints in the db, so possible references aren't deleted
|
||||
repository.Delete(language);
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
DeletedLanguage.RaiseEvent(new DeleteEventArgs<ILanguage>(language, false), this);
|
||||
@@ -360,11 +369,11 @@ namespace Umbraco.Core.Services
|
||||
|
||||
private void Audit(AuditType type, string message, int userId, int objectId)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var auditRepo = RepositoryFactory.CreateAuditRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
auditRepo.AddOrUpdate(new AuditItem(objectId, message, type, userId));
|
||||
uow.Commit();
|
||||
var repo = uow.CreateRepository<IAuditRepository>();
|
||||
repo.AddOrUpdate(new AuditItem(objectId, message, type, userId));
|
||||
uow.Complete();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -381,9 +390,7 @@ namespace Umbraco.Core.Services
|
||||
|
||||
item.GetLanguage = GetLanguageById;
|
||||
foreach (var trans in item.Translations.OfType<DictionaryTranslation>())
|
||||
{
|
||||
trans.GetLanguage = GetLanguageById;
|
||||
}
|
||||
}
|
||||
|
||||
#region Event Handlers
|
||||
|
||||
@@ -2,7 +2,6 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using Umbraco.Core.Auditing;
|
||||
using Umbraco.Core.Events;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Logging;
|
||||
@@ -20,8 +19,8 @@ namespace Umbraco.Core.Services
|
||||
public class MacroService : RepositoryService, IMacroService
|
||||
{
|
||||
|
||||
public MacroService(IDatabaseUnitOfWorkProvider provider, RepositoryFactory repositoryFactory, ILogger logger, IEventMessagesFactory eventMessagesFactory)
|
||||
: base(provider, repositoryFactory, logger, eventMessagesFactory)
|
||||
public MacroService(IDatabaseUnitOfWorkProvider provider, ILogger logger, IEventMessagesFactory eventMessagesFactory)
|
||||
: base(provider, logger, eventMessagesFactory)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -52,8 +51,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>An <see cref="IMacro"/> object</returns>
|
||||
public IMacro GetByAlias(string alias)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateMacroRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMacroRepository>();
|
||||
var q = repository.Query.Where(macro => macro.Alias == alias);
|
||||
return repository.GetByQuery(q).FirstOrDefault();
|
||||
}
|
||||
@@ -79,16 +79,18 @@ namespace Umbraco.Core.Services
|
||||
|
||||
public IEnumerable<IMacro> GetAll(params int[] ids)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateMacroRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMacroRepository>();
|
||||
return repository.GetAll(ids);
|
||||
}
|
||||
}
|
||||
|
||||
public IMacro GetById(int id)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateMacroRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMacroRepository>();
|
||||
return repository.Get(id);
|
||||
}
|
||||
}
|
||||
@@ -113,16 +115,15 @@ namespace Umbraco.Core.Services
|
||||
if (Deleting.IsRaisedEventCancelled(new DeleteEventArgs<IMacro>(macro), this))
|
||||
return;
|
||||
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateMacroRepository(uow))
|
||||
{
|
||||
repository.Delete(macro);
|
||||
uow.Commit();
|
||||
|
||||
Deleted.RaiseEvent(new DeleteEventArgs<IMacro>(macro, false), this);
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMacroRepository>();
|
||||
repository.Delete(macro);
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
Audit(AuditType.Delete, "Delete Macro performed by user", userId, -1);
|
||||
Deleted.RaiseEvent(new DeleteEventArgs<IMacro>(macro, false), this);
|
||||
Audit(AuditType.Delete, "Delete Macro performed by user", userId, -1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -134,17 +135,16 @@ namespace Umbraco.Core.Services
|
||||
{
|
||||
if (Saving.IsRaisedEventCancelled(new SaveEventArgs<IMacro>(macro), this))
|
||||
return;
|
||||
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateMacroRepository(uow))
|
||||
{
|
||||
repository.AddOrUpdate(macro);
|
||||
uow.Commit();
|
||||
|
||||
Saved.RaiseEvent(new SaveEventArgs<IMacro>(macro, false), this);
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMacroRepository>();
|
||||
repository.AddOrUpdate(macro);
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
Audit(AuditType.Save, "Save Macro performed by user", userId, -1);
|
||||
Saved.RaiseEvent(new SaveEventArgs<IMacro>(macro, false), this);
|
||||
Audit(AuditType.Save, "Save Macro performed by user", userId, -1);
|
||||
}
|
||||
|
||||
///// <summary>
|
||||
@@ -168,11 +168,11 @@ namespace Umbraco.Core.Services
|
||||
|
||||
private void Audit(AuditType type, string message, int userId, int objectId)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var auditRepo = RepositoryFactory.CreateAuditRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
auditRepo.AddOrUpdate(new AuditItem(objectId, message, type, userId));
|
||||
uow.Commit();
|
||||
var repo = uow.CreateRepository<IAuditRepository>();
|
||||
repo.AddOrUpdate(new AuditItem(objectId, message, type, userId));
|
||||
uow.Complete();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using System.Xml.Linq;
|
||||
using Umbraco.Core.Auditing;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Events;
|
||||
using Umbraco.Core.Logging;
|
||||
@@ -38,8 +37,8 @@ namespace Umbraco.Core.Services
|
||||
private readonly IUserService _userService;
|
||||
private readonly IEnumerable<IUrlSegmentProvider> _urlSegmentProviders;
|
||||
|
||||
public MediaService(IDatabaseUnitOfWorkProvider provider, RepositoryFactory repositoryFactory, ILogger logger, IEventMessagesFactory eventMessagesFactory, IDataTypeService dataTypeService, IUserService userService, IEnumerable<IUrlSegmentProvider> urlSegmentProviders)
|
||||
: base(provider, repositoryFactory, logger, eventMessagesFactory)
|
||||
public MediaService(IDatabaseUnitOfWorkProvider provider, ILogger logger, IEventMessagesFactory eventMessagesFactory, IDataTypeService dataTypeService, IUserService userService, IEnumerable<IUrlSegmentProvider> urlSegmentProviders)
|
||||
: base(provider, logger, eventMessagesFactory)
|
||||
{
|
||||
if (dataTypeService == null) throw new ArgumentNullException("dataTypeService");
|
||||
if (userService == null) throw new ArgumentNullException("userService");
|
||||
@@ -153,9 +152,9 @@ namespace Umbraco.Core.Services
|
||||
return media;
|
||||
}
|
||||
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateMediaRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMediaRepository>();
|
||||
media.CreatorId = userId;
|
||||
repository.AddOrUpdate(media);
|
||||
|
||||
@@ -166,14 +165,12 @@ namespace Umbraco.Core.Services
|
||||
repository.AddOrUpdatePreviewXml(media, m => _entitySerializer.Serialize(this, _dataTypeService, _userService, _urlSegmentProviders, m));
|
||||
}
|
||||
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
Saved.RaiseEvent(new SaveEventArgs<IMedia>(media, false), this);
|
||||
|
||||
Created.RaiseEvent(new NewEventArgs<IMedia>(media, false, mediaTypeAlias, parentId), this);
|
||||
|
||||
Audit(AuditType.New, string.Format("Media '{0}' was created with Id {1}", name, media.Id), media.CreatorId, media.Id);
|
||||
Audit(AuditType.New, $"Media '{name}' was created with Id {media.Id}", media.CreatorId, media.Id);
|
||||
|
||||
return media;
|
||||
}
|
||||
@@ -212,9 +209,9 @@ namespace Umbraco.Core.Services
|
||||
return media;
|
||||
}
|
||||
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateMediaRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMediaRepository>();
|
||||
media.CreatorId = userId;
|
||||
repository.AddOrUpdate(media);
|
||||
repository.AddOrUpdateContentXml(media, m => _entitySerializer.Serialize(this, _dataTypeService, _userService, _urlSegmentProviders, m));
|
||||
@@ -224,15 +221,12 @@ namespace Umbraco.Core.Services
|
||||
repository.AddOrUpdatePreviewXml(media, m => _entitySerializer.Serialize(this, _dataTypeService, _userService, _urlSegmentProviders, m));
|
||||
}
|
||||
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
Saved.RaiseEvent(new SaveEventArgs<IMedia>(media, false), this);
|
||||
|
||||
Created.RaiseEvent(new NewEventArgs<IMedia>(media, false, mediaTypeAlias, parent), this);
|
||||
|
||||
Audit(AuditType.New, string.Format("Media '{0}' was created with Id {1}", name, media.Id), media.CreatorId, media.Id);
|
||||
|
||||
Audit(AuditType.New, $"Media '{name}' was created with Id {media.Id}", media.CreatorId, media.Id);
|
||||
return media;
|
||||
}
|
||||
|
||||
@@ -243,36 +237,36 @@ namespace Umbraco.Core.Services
|
||||
/// <returns><see cref="IMedia"/></returns>
|
||||
public IMedia GetById(int id)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateMediaRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMediaRepository>();
|
||||
return repository.Get(id);
|
||||
}
|
||||
}
|
||||
|
||||
public int Count(string contentTypeAlias = null)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateMediaRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMediaRepository>();
|
||||
return repository.Count(contentTypeAlias);
|
||||
}
|
||||
}
|
||||
|
||||
public int CountChildren(int parentId, string contentTypeAlias = null)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateMediaRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMediaRepository>();
|
||||
return repository.CountChildren(parentId, contentTypeAlias);
|
||||
}
|
||||
}
|
||||
|
||||
public int CountDescendants(int parentId, string contentTypeAlias = null)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateMediaRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMediaRepository>();
|
||||
return repository.CountDescendants(parentId, contentTypeAlias);
|
||||
}
|
||||
}
|
||||
@@ -286,8 +280,9 @@ namespace Umbraco.Core.Services
|
||||
{
|
||||
if (ids.Any() == false) return Enumerable.Empty<IMedia>();
|
||||
|
||||
using (var repository = RepositoryFactory.CreateMediaRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMediaRepository>();
|
||||
return repository.GetAll(ids.ToArray());
|
||||
}
|
||||
}
|
||||
@@ -299,8 +294,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns><see cref="IMedia"/></returns>
|
||||
public IMedia GetById(Guid key)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateMediaRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMediaRepository>();
|
||||
var query = repository.Query.Where(x => x.Key == key);
|
||||
var contents = repository.GetByQuery(query);
|
||||
return contents.SingleOrDefault();
|
||||
@@ -314,8 +310,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>An Enumerable list of <see cref="IMedia"/> objects</returns>
|
||||
public IEnumerable<IMedia> GetByLevel(int level)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateMediaRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMediaRepository>();
|
||||
var query = repository.Query.Where(x => x.Level == level && !x.Path.StartsWith("-21"));
|
||||
var contents = repository.GetByQuery(query);
|
||||
|
||||
@@ -330,8 +327,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>An <see cref="IMedia"/> item</returns>
|
||||
public IMedia GetByVersion(Guid versionId)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateMediaRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMediaRepository>();
|
||||
return repository.GetByVersion(versionId);
|
||||
}
|
||||
}
|
||||
@@ -343,8 +341,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>An Enumerable list of <see cref="IMedia"/> objects</returns>
|
||||
public IEnumerable<IMedia> GetVersions(int id)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateMediaRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMediaRepository>();
|
||||
var versions = repository.GetAllVersions(id);
|
||||
return versions;
|
||||
}
|
||||
@@ -372,8 +371,9 @@ namespace Umbraco.Core.Services
|
||||
if (ids.Any() == false)
|
||||
return new List<IMedia>();
|
||||
|
||||
using (var repository = RepositoryFactory.CreateMediaRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMediaRepository>();
|
||||
return repository.GetAll(ids);
|
||||
}
|
||||
}
|
||||
@@ -385,9 +385,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>An Enumerable list of <see cref="IMedia"/> objects</returns>
|
||||
public IEnumerable<IMedia> GetChildren(int id)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateMediaRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMediaRepository>();
|
||||
var query = repository.Query.Where(x => x.ParentId == id);
|
||||
var medias = repository.GetByQuery(query);
|
||||
|
||||
@@ -409,8 +409,9 @@ namespace Umbraco.Core.Services
|
||||
public IEnumerable<IMedia> GetPagedChildren(int id, long pageIndex, int pageSize, out long totalChildren,
|
||||
string orderBy, Direction orderDirection, string filter = "")
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateContentRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IContentRepository>();
|
||||
IQuery<IMedia> filterQuery = null;
|
||||
if (filter.IsNullOrWhiteSpace() == false)
|
||||
{
|
||||
@@ -437,8 +438,9 @@ namespace Umbraco.Core.Services
|
||||
{
|
||||
Mandate.ParameterCondition(pageIndex >= 0, "pageIndex");
|
||||
Mandate.ParameterCondition(pageSize > 0, "pageSize");
|
||||
using (var repository = RepositoryFactory.CreateMediaRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMediaRepository>();
|
||||
var query = repository.Query;
|
||||
query.Where(x => x.ParentId == id);
|
||||
|
||||
@@ -461,8 +463,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>An Enumerable list of <see cref="IContent"/> objects</returns>
|
||||
public IEnumerable<IMedia> GetPagedDescendants(int id, long pageIndex, int pageSize, out long totalChildren, string orderBy = "Path", Direction orderDirection = Direction.Ascending, string filter = "")
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateContentRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMediaRepository>();
|
||||
IQuery<IMedia> filterQuery = null;
|
||||
if (filter.IsNullOrWhiteSpace() == false)
|
||||
{
|
||||
@@ -488,8 +491,9 @@ namespace Umbraco.Core.Services
|
||||
{
|
||||
Mandate.ParameterCondition(pageIndex >= 0, "pageIndex");
|
||||
Mandate.ParameterCondition(pageSize > 0, "pageSize");
|
||||
using (var repository = RepositoryFactory.CreateMediaRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMediaRepository>();
|
||||
|
||||
var query = repository.Query;
|
||||
//if the id is -1, then just get all
|
||||
@@ -525,9 +529,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>An Enumerable flat list of <see cref="IMedia"/> objects</returns>
|
||||
public IEnumerable<IMedia> GetDescendants(IMedia media)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateMediaRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMediaRepository>();
|
||||
var pathMatch = media.Path + ",";
|
||||
var query = repository.Query.Where(x => x.Path.StartsWith(pathMatch) && x.Id != media.Id);
|
||||
var medias = repository.GetByQuery(query);
|
||||
@@ -567,9 +571,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>An Enumerable list of <see cref="IMedia"/> objects</returns>
|
||||
public IEnumerable<IMedia> GetMediaOfMediaType(int id)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateMediaRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMediaRepository>();
|
||||
var query = repository.Query.Where(x => x.ContentTypeId == id);
|
||||
var medias = repository.GetByQuery(query);
|
||||
|
||||
@@ -583,9 +587,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>An Enumerable list of <see cref="IMedia"/> objects</returns>
|
||||
public IEnumerable<IMedia> GetRootMedia()
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateMediaRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMediaRepository>();
|
||||
var query = repository.Query.Where(x => x.ParentId == -1);
|
||||
var medias = repository.GetByQuery(query);
|
||||
|
||||
@@ -599,9 +603,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>An Enumerable list of <see cref="IMedia"/> objects</returns>
|
||||
public IEnumerable<IMedia> GetMediaInRecycleBin()
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateMediaRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMediaRepository>();
|
||||
var query = repository.Query.Where(x => x.Path.Contains("-21"));
|
||||
var medias = repository.GetByQuery(query);
|
||||
|
||||
@@ -616,8 +620,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns><see cref="IMedia"/></returns>
|
||||
public IMedia GetMediaByPath(string mediaPath)
|
||||
{
|
||||
using (var repo = RepositoryFactory.CreateMediaRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repo = uow.CreateRepository<IMediaRepository>();
|
||||
return repo.GetMediaByPath(mediaPath);
|
||||
}
|
||||
}
|
||||
@@ -629,8 +634,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>True if the media has any children otherwise False</returns>
|
||||
public bool HasChildren(int id)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateMediaRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMediaRepository>();
|
||||
var query = repository.Query.Where(x => x.ParentId == id);
|
||||
int count = repository.Count(query);
|
||||
return count > 0;
|
||||
@@ -738,11 +744,11 @@ namespace Umbraco.Core.Services
|
||||
Delete(child, userId);
|
||||
}
|
||||
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateMediaRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMediaRepository>();
|
||||
repository.Delete(media);
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
|
||||
var args = new DeleteEventArgs<IMedia>(media, false, evtMsgs);
|
||||
Deleted.RaiseEvent(args, this);
|
||||
@@ -777,9 +783,9 @@ namespace Umbraco.Core.Services
|
||||
|
||||
}
|
||||
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateMediaRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMediaRepository>();
|
||||
media.CreatorId = userId;
|
||||
repository.AddOrUpdate(media);
|
||||
repository.AddOrUpdateContentXml(media, m => _entitySerializer.Serialize(this, _dataTypeService, _userService, _urlSegmentProviders, m));
|
||||
@@ -789,12 +795,11 @@ namespace Umbraco.Core.Services
|
||||
repository.AddOrUpdatePreviewXml(media, m => _entitySerializer.Serialize(this, _dataTypeService, _userService, _urlSegmentProviders, m));
|
||||
}
|
||||
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
if (raiseEvents)
|
||||
Saved.RaiseEvent(new SaveEventArgs<IMedia>(media, false, evtMsgs), this);
|
||||
|
||||
Audit(AuditType.Save, "Save Media performed by user", userId, media.Id);
|
||||
|
||||
return OperationStatus.Success(evtMsgs);
|
||||
@@ -821,9 +826,9 @@ namespace Umbraco.Core.Services
|
||||
}
|
||||
}
|
||||
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateMediaRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMediaRepository>();
|
||||
foreach (var media in asArray)
|
||||
{
|
||||
media.CreatorId = userId;
|
||||
@@ -837,12 +842,11 @@ namespace Umbraco.Core.Services
|
||||
}
|
||||
|
||||
//commit the whole lot in one go
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
if (raiseEvents)
|
||||
Saved.RaiseEvent(new SaveEventArgs<IMedia>(asArray, false, evtMsgs), this);
|
||||
|
||||
Audit(AuditType.Save, "Save Media items performed by user", userId, -1);
|
||||
|
||||
return OperationStatus.Success(evtMsgs);
|
||||
@@ -860,9 +864,9 @@ namespace Umbraco.Core.Services
|
||||
bool success;
|
||||
var nodeObjectType = new Guid(Constants.ObjectTypes.Media);
|
||||
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateMediaRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMediaRepository>();
|
||||
//Create a dictionary of ids -> dictionary of property aliases + values
|
||||
entities = repository.GetEntitiesInRecycleBin()
|
||||
.ToDictionary(
|
||||
@@ -897,9 +901,9 @@ namespace Umbraco.Core.Services
|
||||
|
||||
using (new WriteLock(Locker))
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateMediaRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMediaRepository>();
|
||||
//NOTE What about media that has the contenttype as part of its composition?
|
||||
//The ContentType has to be removed from the composition somehow as it would otherwise break
|
||||
//Dbl.check+test that the ContentType's Id is removed from the ContentType2ContentType table
|
||||
@@ -958,9 +962,9 @@ namespace Umbraco.Core.Services
|
||||
//Find Descendants, which will be moved to the recycle bin along with the parent/grandparent.
|
||||
var descendants = GetDescendants(media).OrderBy(x => x.Level).ToList();
|
||||
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateMediaRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMediaRepository>();
|
||||
//TODO: This should be part of the repo!
|
||||
|
||||
//Remove 'published' xml from the cmsContentXml table for the unpublished media
|
||||
@@ -981,12 +985,11 @@ namespace Umbraco.Core.Services
|
||||
moveInfo.Add(new MoveEventInfo<IMedia>(descendant, descendant.Path, descendant.ParentId));
|
||||
}
|
||||
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
Trashed.RaiseEvent(
|
||||
new MoveEventArgs<IMedia>(false, evtMsgs, moveInfo.ToArray()), this);
|
||||
|
||||
Audit(AuditType.Move, "Move Media to Recycle Bin performed by user", userId, media.Id);
|
||||
|
||||
return OperationStatus.Success(evtMsgs);
|
||||
@@ -1020,15 +1023,14 @@ namespace Umbraco.Core.Services
|
||||
if (DeletingVersions.IsRaisedEventCancelled(new DeleteRevisionsEventArgs(id, dateToRetain: versionDate), this))
|
||||
return;
|
||||
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateMediaRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMediaRepository>();
|
||||
repository.DeleteVersions(id, versionDate);
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
DeletedVersions.RaiseEvent(new DeleteRevisionsEventArgs(id, false, dateToRetain: versionDate), this);
|
||||
|
||||
Audit(AuditType.Delete, "Delete Media by version date performed by user", userId, -1);
|
||||
}
|
||||
|
||||
@@ -1051,15 +1053,14 @@ namespace Umbraco.Core.Services
|
||||
DeleteVersions(id, content.UpdateDate, userId);
|
||||
}
|
||||
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateMediaRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMediaRepository>();
|
||||
repository.DeleteVersion(versionId);
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
DeletedVersions.RaiseEvent(new DeleteRevisionsEventArgs(id, false, specificVersion: versionId), this);
|
||||
|
||||
Audit(AuditType.Delete, "Delete Media by version performed by user", userId, -1);
|
||||
}
|
||||
|
||||
@@ -1103,9 +1104,9 @@ namespace Umbraco.Core.Services
|
||||
return false;
|
||||
}
|
||||
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateMediaRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMediaRepository>();
|
||||
int i = 0;
|
||||
foreach (var media in asArray)
|
||||
{
|
||||
@@ -1130,12 +1131,11 @@ namespace Umbraco.Core.Services
|
||||
}
|
||||
}
|
||||
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
if (raiseEvents)
|
||||
Saved.RaiseEvent(new SaveEventArgs<IMedia>(asArray, false), this);
|
||||
|
||||
Audit(AuditType.Sort, "Sorting Media performed by user", userId, 0);
|
||||
|
||||
return true;
|
||||
@@ -1150,9 +1150,9 @@ namespace Umbraco.Core.Services
|
||||
/// </param>
|
||||
public void RebuildXmlStructures(params int[] contentTypeIds)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateMediaRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMediaRepository>();
|
||||
repository.RebuildXmlStructures(
|
||||
media => _entitySerializer.Serialize(this, _dataTypeService, _userService, _urlSegmentProviders, media),
|
||||
contentTypeIds: contentTypeIds.Length == 0 ? null : contentTypeIds);
|
||||
@@ -1207,9 +1207,9 @@ namespace Umbraco.Core.Services
|
||||
{
|
||||
Mandate.ParameterNotNullOrEmpty(mediaTypeAlias, "mediaTypeAlias");
|
||||
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateMediaTypeRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMediaTypeRepository>();
|
||||
var query = repository.QueryFactory.Create<IMediaType>().Where(x => x.Alias == mediaTypeAlias);
|
||||
var mediaTypes = repository.GetByQuery(query);
|
||||
|
||||
@@ -1229,11 +1229,11 @@ namespace Umbraco.Core.Services
|
||||
|
||||
private void Audit(AuditType type, string message, int userId, int objectId)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var auditRepo = RepositoryFactory.CreateAuditRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
auditRepo.AddOrUpdate(new AuditItem(objectId, message, type, userId));
|
||||
uow.Commit();
|
||||
var repo = uow.CreateRepository<IAuditRepository>();
|
||||
repo.AddOrUpdate(new AuditItem(objectId, message, type, userId));
|
||||
uow.Complete();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,8 +14,8 @@ namespace Umbraco.Core.Services
|
||||
public class MemberGroupService : RepositoryService, IMemberGroupService
|
||||
{
|
||||
|
||||
public MemberGroupService(IDatabaseUnitOfWorkProvider provider, RepositoryFactory repositoryFactory, ILogger logger, IEventMessagesFactory eventMessagesFactory)
|
||||
: base(provider, repositoryFactory, logger, eventMessagesFactory)
|
||||
public MemberGroupService(IDatabaseUnitOfWorkProvider provider, ILogger logger, IEventMessagesFactory eventMessagesFactory)
|
||||
: base(provider, logger, eventMessagesFactory)
|
||||
{
|
||||
//Proxy events!
|
||||
MemberGroupRepository.SavedMemberGroup += MemberGroupRepository_SavedMemberGroup;
|
||||
@@ -39,24 +39,27 @@ namespace Umbraco.Core.Services
|
||||
|
||||
public IEnumerable<IMemberGroup> GetAll()
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateMemberGroupRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMemberGroupRepository>();
|
||||
return repository.GetAll();
|
||||
}
|
||||
}
|
||||
|
||||
public IMemberGroup GetById(int id)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateMemberGroupRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMemberGroupRepository>();
|
||||
return repository.Get(id);
|
||||
}
|
||||
}
|
||||
|
||||
public IMemberGroup GetByName(string name)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateMemberGroupRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMemberGroupRepository>();
|
||||
return repository.GetByName(name);
|
||||
}
|
||||
}
|
||||
@@ -71,11 +74,11 @@ namespace Umbraco.Core.Services
|
||||
}
|
||||
}
|
||||
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateMemberGroupRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMemberGroupRepository>();
|
||||
repository.AddOrUpdate(memberGroup);
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
if (raiseEvents)
|
||||
@@ -87,11 +90,11 @@ namespace Umbraco.Core.Services
|
||||
if (Deleting.IsRaisedEventCancelled(new DeleteEventArgs<IMemberGroup>(memberGroup), this))
|
||||
return;
|
||||
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateMemberGroupRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMemberGroupRepository>();
|
||||
repository.Delete(memberGroup);
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
Deleted.RaiseEvent(new DeleteEventArgs<IMemberGroup>(memberGroup, false), this);
|
||||
|
||||
@@ -4,7 +4,6 @@ using System.ComponentModel;
|
||||
using System.Threading;
|
||||
using System.Web.Security;
|
||||
using System.Xml.Linq;
|
||||
using Umbraco.Core.Auditing;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Events;
|
||||
using Umbraco.Core.Logging;
|
||||
@@ -17,6 +16,7 @@ using Umbraco.Core.Persistence.Querying;
|
||||
using Umbraco.Core.Persistence.SqlSyntax;
|
||||
using Umbraco.Core.Persistence.UnitOfWork;
|
||||
using System.Linq;
|
||||
using Umbraco.Core.Persistence.Repositories;
|
||||
using Umbraco.Core.Security;
|
||||
|
||||
namespace Umbraco.Core.Services
|
||||
@@ -31,8 +31,8 @@ namespace Umbraco.Core.Services
|
||||
private readonly IDataTypeService _dataTypeService;
|
||||
private static readonly ReaderWriterLockSlim Locker = new ReaderWriterLockSlim();
|
||||
|
||||
public MemberService(IDatabaseUnitOfWorkProvider provider, RepositoryFactory repositoryFactory, ILogger logger, IEventMessagesFactory eventMessagesFactory, IMemberGroupService memberGroupService, IDataTypeService dataTypeService)
|
||||
: base(provider, repositoryFactory, logger, eventMessagesFactory)
|
||||
public MemberService(IDatabaseUnitOfWorkProvider provider, ILogger logger, IEventMessagesFactory eventMessagesFactory, IMemberGroupService memberGroupService, IDataTypeService dataTypeService)
|
||||
: base(provider, logger, eventMessagesFactory)
|
||||
{
|
||||
if (memberGroupService == null) throw new ArgumentNullException("memberGroupService");
|
||||
if (dataTypeService == null) throw new ArgumentNullException("dataTypeService");
|
||||
@@ -50,8 +50,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>Alias of the default MemberType</returns>
|
||||
public string GetDefaultMemberType()
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateMemberTypeRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMemberTypeRepository>();
|
||||
var types = repository.GetAll(new int[] { }).Select(x => x.Alias).ToArray();
|
||||
|
||||
if (types.Any() == false)
|
||||
@@ -75,8 +76,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns><c>True</c> if the Member exists otherwise <c>False</c></returns>
|
||||
public bool Exists(string username)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateMemberRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMemberRepository>();
|
||||
return repository.Exists(username);
|
||||
}
|
||||
}
|
||||
@@ -121,8 +123,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns><c>True</c> if the Member exists otherwise <c>False</c></returns>
|
||||
public bool Exists(int id)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateMemberRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMemberRepository>();
|
||||
return repository.Exists(id);
|
||||
}
|
||||
}
|
||||
@@ -134,8 +137,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns><see cref="IMember"/></returns>
|
||||
public IMember GetById(int id)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateMemberRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMemberRepository>();
|
||||
return repository.Get(id);
|
||||
}
|
||||
}
|
||||
@@ -149,8 +153,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns><see cref="IMember"/></returns>
|
||||
public IMember GetByKey(Guid id)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateMemberRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMemberRepository>();
|
||||
var query = repository.Query.Where(x => x.Key == id);
|
||||
var member = repository.GetByQuery(query).FirstOrDefault();
|
||||
return member;
|
||||
@@ -164,8 +169,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns><see cref="IEnumerable{IMember}"/></returns>
|
||||
public IEnumerable<IMember> GetMembersByMemberType(string memberTypeAlias)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateMemberRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMemberRepository>();
|
||||
var query = repository.Query.Where(x => x.ContentTypeAlias == memberTypeAlias);
|
||||
var members = repository.GetByQuery(query);
|
||||
return members;
|
||||
@@ -179,8 +185,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns><see cref="IEnumerable{IMember}"/></returns>
|
||||
public IEnumerable<IMember> GetMembersByMemberType(int memberTypeId)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateMemberRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMemberRepository>();
|
||||
repository.Get(memberTypeId);
|
||||
var query = repository.Query.Where(x => x.ContentTypeId == memberTypeId);
|
||||
var members = repository.GetByQuery(query);
|
||||
@@ -195,8 +202,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns><see cref="IEnumerable{IMember}"/></returns>
|
||||
public IEnumerable<IMember> GetMembersByGroup(string memberGroupName)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateMemberRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMemberRepository>();
|
||||
return repository.GetByMemberGroup(memberGroupName);
|
||||
}
|
||||
}
|
||||
@@ -209,8 +217,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns><see cref="IEnumerable{IMember}"/></returns>
|
||||
public IEnumerable<IMember> GetAllMembers(params int[] ids)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateMemberRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMemberRepository>();
|
||||
return repository.GetAll(ids);
|
||||
}
|
||||
}
|
||||
@@ -223,9 +232,9 @@ namespace Umbraco.Core.Services
|
||||
{
|
||||
using (new WriteLock(Locker))
|
||||
{
|
||||
using (var uow = UowProvider.GetUnitOfWork())
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = RepositoryFactory.CreateMemberRepository(uow);
|
||||
var repository = uow.CreateRepository<IMemberRepository>();
|
||||
//TODO: What about content that has the contenttype as part of its composition?
|
||||
var query = repository.Query.Where(x => x.ContentTypeId == memberTypeId);
|
||||
var members = repository.GetByQuery(query).ToArray();
|
||||
@@ -263,9 +272,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns><see cref="IEnumerable{IMember}"/></returns>
|
||||
public IEnumerable<IMember> FindMembersByDisplayName(string displayNameToMatch, long pageIndex, int pageSize, out long totalRecords, StringPropertyMatchType matchType = StringPropertyMatchType.StartsWith)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateMemberRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMemberRepository>();
|
||||
var query = repository.Query;
|
||||
|
||||
switch (matchType)
|
||||
@@ -314,9 +323,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns><see cref="IEnumerable{IMember}"/></returns>
|
||||
public IEnumerable<IMember> FindByEmail(string emailStringToMatch, long pageIndex, int pageSize, out long totalRecords, StringPropertyMatchType matchType = StringPropertyMatchType.StartsWith)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateMemberRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMemberRepository>();
|
||||
var query = repository.Query;
|
||||
|
||||
switch (matchType)
|
||||
@@ -365,9 +374,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns><see cref="IEnumerable{IMember}"/></returns>
|
||||
public IEnumerable<IMember> FindByUsername(string login, long pageIndex, int pageSize, out long totalRecords, StringPropertyMatchType matchType = StringPropertyMatchType.StartsWith)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateMemberRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMemberRepository>();
|
||||
var query = repository.Query;
|
||||
|
||||
switch (matchType)
|
||||
@@ -404,8 +413,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns><see cref="IEnumerable{IMember}"/></returns>
|
||||
public IEnumerable<IMember> GetMembersByPropertyValue(string propertyTypeAlias, string value, StringPropertyMatchType matchType = StringPropertyMatchType.Exact)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateMemberRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMemberRepository>();
|
||||
IQuery<IMember> query;
|
||||
|
||||
switch (matchType)
|
||||
@@ -460,8 +470,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns><see cref="IEnumerable{IMember}"/></returns>
|
||||
public IEnumerable<IMember> GetMembersByPropertyValue(string propertyTypeAlias, int value, ValuePropertyMatchType matchType = ValuePropertyMatchType.Exact)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateMemberRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMemberRepository>();
|
||||
IQuery<IMember> query;
|
||||
|
||||
switch (matchType)
|
||||
@@ -518,8 +529,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns><see cref="IEnumerable{IMember}"/></returns>
|
||||
public IEnumerable<IMember> GetMembersByPropertyValue(string propertyTypeAlias, bool value)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateMemberRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMemberRepository>();
|
||||
var query =
|
||||
repository.Query.Where(
|
||||
x =>
|
||||
@@ -540,8 +552,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns><see cref="IEnumerable{IMember}"/></returns>
|
||||
public IEnumerable<IMember> GetMembersByPropertyValue(string propertyTypeAlias, DateTime value, ValuePropertyMatchType matchType = ValuePropertyMatchType.Exact)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateMemberRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMemberRepository>();
|
||||
IQuery<IMember> query;
|
||||
|
||||
switch (matchType)
|
||||
@@ -601,9 +614,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>True if publishing succeeded, otherwise False</returns>
|
||||
public void RebuildXmlStructures(params int[] memberTypeIds)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateMemberRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMemberRepository>();
|
||||
repository.RebuildXmlStructures(
|
||||
member => _entitySerializer.Serialize(_dataTypeService, member),
|
||||
contentTypeIds: memberTypeIds.Length == 0 ? null : memberTypeIds);
|
||||
@@ -628,8 +641,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns><see cref="System.int"/> with number of Members for passed in type</returns>
|
||||
public int GetCount(MemberCountType countType)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateMemberRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMemberRepository>();
|
||||
IQuery<IMember> query;
|
||||
|
||||
switch (countType)
|
||||
@@ -685,9 +699,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns><see cref="IEnumerable{IMember}"/></returns>
|
||||
public IEnumerable<IMember> GetAll(long pageIndex, int pageSize, out long totalRecords)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateMemberRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMemberRepository>();
|
||||
return repository.GetPagedResultsByQuery(null, pageIndex, pageSize, out totalRecords, "LoginName", Direction.Ascending, true);
|
||||
}
|
||||
}
|
||||
@@ -712,9 +726,9 @@ namespace Umbraco.Core.Services
|
||||
public IEnumerable<IMember> GetAll(long pageIndex, int pageSize, out long totalRecords,
|
||||
string orderBy, Direction orderDirection, bool orderBySystemField, string memberTypeAlias, string filter)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateMemberRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMemberRepository>();
|
||||
if (memberTypeAlias == null)
|
||||
{
|
||||
return repository.GetPagedResultsByQuery(null, pageIndex, pageSize, out totalRecords, orderBy, orderDirection, orderBySystemField, filter);
|
||||
@@ -732,9 +746,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns><see cref="System.int"/> with number of Members</returns>
|
||||
public int Count(string memberTypeAlias = null)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateMemberRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMemberRepository>();
|
||||
return repository.Count(memberTypeAlias);
|
||||
}
|
||||
}
|
||||
@@ -859,9 +873,9 @@ namespace Umbraco.Core.Services
|
||||
return member;
|
||||
}
|
||||
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateMemberRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMemberRepository>();
|
||||
repository.AddOrUpdate(member);
|
||||
//insert the xml
|
||||
repository.AddOrUpdateContentXml(member, m => _entitySerializer.Serialize(_dataTypeService, m));
|
||||
@@ -871,7 +885,7 @@ namespace Umbraco.Core.Services
|
||||
repository.AddOrUpdatePreviewXml(member, m => _entitySerializer.Serialize(_dataTypeService, m));
|
||||
}
|
||||
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
Saved.RaiseEvent(new SaveEventArgs<IMember>(member, false), this);
|
||||
@@ -908,9 +922,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns><see cref="IMember"/></returns>
|
||||
public IMember GetByEmail(string email)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateMemberRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMemberRepository>();
|
||||
var query = repository.Query.Where(x => x.Email.Equals(email));
|
||||
var member = repository.GetByQuery(query).FirstOrDefault();
|
||||
|
||||
@@ -929,9 +943,9 @@ namespace Umbraco.Core.Services
|
||||
// a caching mechanism since this method is used by all the membership providers and could be
|
||||
// called quite a bit when dealing with members.
|
||||
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateMemberRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMemberRepository>();
|
||||
var query = repository.Query.Where(x => x.Username.Equals(username));
|
||||
var member = repository.GetByQuery(query).FirstOrDefault();
|
||||
|
||||
@@ -948,11 +962,11 @@ namespace Umbraco.Core.Services
|
||||
if (Deleting.IsRaisedEventCancelled(new DeleteEventArgs<IMember>(member), this))
|
||||
return;
|
||||
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateMemberRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMemberRepository>();
|
||||
repository.Delete(member);
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
|
||||
var args = new DeleteEventArgs<IMember>(member, false);
|
||||
Deleted.RaiseEvent(args, this);
|
||||
@@ -978,9 +992,9 @@ namespace Umbraco.Core.Services
|
||||
}
|
||||
}
|
||||
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateMemberRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMemberRepository>();
|
||||
repository.AddOrUpdate(entity);
|
||||
repository.AddOrUpdateContentXml(entity, m => _entitySerializer.Serialize(_dataTypeService, m));
|
||||
// generate preview for blame history?
|
||||
@@ -989,7 +1003,7 @@ namespace Umbraco.Core.Services
|
||||
repository.AddOrUpdatePreviewXml(entity, m => _entitySerializer.Serialize(_dataTypeService, m));
|
||||
}
|
||||
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
if (raiseEvents)
|
||||
@@ -1013,9 +1027,9 @@ namespace Umbraco.Core.Services
|
||||
}
|
||||
using (new WriteLock(Locker))
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateMemberRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMemberRepository>();
|
||||
foreach (var member in asArray)
|
||||
{
|
||||
repository.AddOrUpdate(member);
|
||||
@@ -1028,7 +1042,7 @@ namespace Umbraco.Core.Services
|
||||
}
|
||||
|
||||
//commit the whole lot in one go
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
if (raiseEvents)
|
||||
@@ -1042,18 +1056,18 @@ namespace Umbraco.Core.Services
|
||||
|
||||
public void AddRole(string roleName)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateMemberGroupRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMemberGroupRepository>();
|
||||
repository.CreateIfNotExists(roleName);
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<string> GetAllRoles()
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateMemberGroupRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMemberGroupRepository>();
|
||||
var result = repository.GetAll();
|
||||
return result.Select(x => x.Name).Distinct();
|
||||
}
|
||||
@@ -1061,9 +1075,9 @@ namespace Umbraco.Core.Services
|
||||
|
||||
public IEnumerable<string> GetAllRoles(int memberId)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateMemberGroupRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMemberGroupRepository>();
|
||||
var result = repository.GetMemberGroupsForMember(memberId);
|
||||
return result.Select(x => x.Name).Distinct();
|
||||
}
|
||||
@@ -1071,9 +1085,9 @@ namespace Umbraco.Core.Services
|
||||
|
||||
public IEnumerable<string> GetAllRoles(string username)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateMemberGroupRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMemberGroupRepository>();
|
||||
var result = repository.GetMemberGroupsForMember(username);
|
||||
return result.Select(x => x.Name).Distinct();
|
||||
}
|
||||
@@ -1081,18 +1095,18 @@ namespace Umbraco.Core.Services
|
||||
|
||||
public IEnumerable<IMember> GetMembersInRole(string roleName)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateMemberRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMemberRepository>();
|
||||
return repository.GetByMemberGroup(roleName);
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<IMember> FindMembersInRole(string roleName, string usernameToMatch, StringPropertyMatchType matchType = StringPropertyMatchType.StartsWith)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateMemberRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMemberRepository>();
|
||||
return repository.FindMembersInRole(roleName, usernameToMatch, matchType);
|
||||
}
|
||||
}
|
||||
@@ -1110,9 +1124,9 @@ namespace Umbraco.Core.Services
|
||||
}
|
||||
}
|
||||
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateMemberGroupRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMemberGroupRepository>();
|
||||
var qry = repository.QueryFactory.Create<IMemberGroup>().Where(g => g.Name == roleName);
|
||||
var found = repository.GetByQuery(qry).ToArray();
|
||||
|
||||
@@ -1131,9 +1145,9 @@ namespace Umbraco.Core.Services
|
||||
|
||||
public void AssignRoles(string[] usernames, string[] roleNames)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateMemberGroupRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMemberGroupRepository>();
|
||||
repository.AssignRoles(usernames, roleNames);
|
||||
}
|
||||
}
|
||||
@@ -1145,9 +1159,9 @@ namespace Umbraco.Core.Services
|
||||
|
||||
public void DissociateRoles(string[] usernames, string[] roleNames)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateMemberGroupRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMemberGroupRepository>();
|
||||
repository.DissociateRoles(usernames, roleNames);
|
||||
}
|
||||
}
|
||||
@@ -1159,9 +1173,9 @@ namespace Umbraco.Core.Services
|
||||
|
||||
public void AssignRoles(int[] memberIds, string[] roleNames)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateMemberGroupRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMemberGroupRepository>();
|
||||
repository.AssignRoles(memberIds, roleNames);
|
||||
}
|
||||
}
|
||||
@@ -1173,9 +1187,9 @@ namespace Umbraco.Core.Services
|
||||
|
||||
public void DissociateRoles(int[] memberIds, string[] roleNames)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateMemberGroupRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMemberGroupRepository>();
|
||||
repository.DissociateRoles(memberIds, roleNames);
|
||||
}
|
||||
}
|
||||
@@ -1186,8 +1200,9 @@ namespace Umbraco.Core.Services
|
||||
|
||||
private IMemberType FindMemberTypeByAlias(string memberTypeAlias)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateMemberTypeRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMemberTypeRepository>();
|
||||
var query = repository.QueryFactory.Create<IMemberType>().Where(x => x.Alias == memberTypeAlias);
|
||||
var types = repository.GetByQuery(query);
|
||||
|
||||
@@ -1208,11 +1223,11 @@ namespace Umbraco.Core.Services
|
||||
|
||||
private void Audit(AuditType type, string message, int userId, int objectId)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var auditRepo = RepositoryFactory.CreateAuditRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
auditRepo.AddOrUpdate(new AuditItem(objectId, message, type, userId));
|
||||
uow.Commit();
|
||||
var repo = uow.CreateRepository<IAuditRepository>();
|
||||
repo.AddOrUpdate(new AuditItem(objectId, message, type, userId));
|
||||
uow.Complete();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,12 +2,12 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using Umbraco.Core.Auditing;
|
||||
using Umbraco.Core.Events;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Persistence.Querying;
|
||||
using Umbraco.Core.Persistence.Repositories;
|
||||
using Umbraco.Core.Persistence.UnitOfWork;
|
||||
|
||||
namespace Umbraco.Core.Services
|
||||
@@ -18,8 +18,8 @@ namespace Umbraco.Core.Services
|
||||
|
||||
private static readonly ReaderWriterLockSlim Locker = new ReaderWriterLockSlim();
|
||||
|
||||
public MemberTypeService(IDatabaseUnitOfWorkProvider provider, RepositoryFactory repositoryFactory, ILogger logger, IEventMessagesFactory eventMessagesFactory, IMemberService memberService)
|
||||
: base(provider, repositoryFactory, logger, eventMessagesFactory)
|
||||
public MemberTypeService(IDatabaseUnitOfWorkProvider provider, ILogger logger, IEventMessagesFactory eventMessagesFactory, IMemberService memberService)
|
||||
: base(provider, logger, eventMessagesFactory)
|
||||
{
|
||||
if (memberService == null) throw new ArgumentNullException("memberService");
|
||||
_memberService = memberService;
|
||||
@@ -27,8 +27,9 @@ namespace Umbraco.Core.Services
|
||||
|
||||
public IEnumerable<IMemberType> GetAll(params int[] ids)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateMemberTypeRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMemberTypeRepository>();
|
||||
return repository.GetAll(ids);
|
||||
}
|
||||
}
|
||||
@@ -40,8 +41,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns><see cref="IMemberType"/></returns>
|
||||
public IMemberType Get(int id)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateMemberTypeRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMemberTypeRepository>();
|
||||
return repository.Get(id);
|
||||
}
|
||||
}
|
||||
@@ -53,8 +55,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns><see cref="IMemberType"/></returns>
|
||||
public IMemberType Get(Guid key)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateMemberTypeRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMemberTypeRepository>();
|
||||
return repository.Get(key);
|
||||
}
|
||||
}
|
||||
@@ -66,8 +69,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns><see cref="IMemberType"/></returns>
|
||||
public IMemberType Get(string alias)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateMemberTypeRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMemberTypeRepository>();
|
||||
return repository.Get(alias);
|
||||
}
|
||||
}
|
||||
@@ -79,13 +83,13 @@ namespace Umbraco.Core.Services
|
||||
|
||||
using (new WriteLock(Locker))
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateMemberTypeRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMemberTypeRepository>();
|
||||
memberType.CreatorId = userId;
|
||||
repository.AddOrUpdate(memberType);
|
||||
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
UpdateContentXmlStructure(memberType);
|
||||
@@ -102,9 +106,9 @@ namespace Umbraco.Core.Services
|
||||
|
||||
using (new WriteLock(Locker))
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateMemberTypeRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMemberTypeRepository>();
|
||||
foreach (var memberType in asArray)
|
||||
{
|
||||
memberType.CreatorId = userId;
|
||||
@@ -112,7 +116,7 @@ namespace Umbraco.Core.Services
|
||||
}
|
||||
|
||||
//save it all in one go
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
UpdateContentXmlStructure(asArray.Cast<IContentTypeBase>().ToArray());
|
||||
@@ -129,11 +133,11 @@ namespace Umbraco.Core.Services
|
||||
{
|
||||
_memberService.DeleteMembersOfType(memberType.Id);
|
||||
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateMemberTypeRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMemberTypeRepository>();
|
||||
repository.Delete(memberType);
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
|
||||
Deleted.RaiseEvent(new DeleteEventArgs<IMemberType>(memberType, false), this);
|
||||
}
|
||||
@@ -154,18 +158,18 @@ namespace Umbraco.Core.Services
|
||||
_memberService.DeleteMembersOfType(contentType.Id);
|
||||
}
|
||||
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateMemberTypeRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IMemberTypeRepository>();
|
||||
foreach (var memberType in asArray)
|
||||
{
|
||||
repository.Delete(memberType);
|
||||
}
|
||||
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
Deleted.RaiseEvent(new DeleteEventArgs<IMemberType>(asArray, false), this);
|
||||
}
|
||||
Deleted.RaiseEvent(new DeleteEventArgs<IMemberType>(asArray, false), this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Persistence.Querying;
|
||||
using Umbraco.Core.Persistence.Repositories;
|
||||
using Umbraco.Core.Persistence.UnitOfWork;
|
||||
|
||||
namespace Umbraco.Core.Services
|
||||
@@ -16,8 +17,8 @@ namespace Umbraco.Core.Services
|
||||
/// </summary>
|
||||
public sealed class MigrationEntryService : RepositoryService, IMigrationEntryService
|
||||
{
|
||||
public MigrationEntryService(IDatabaseUnitOfWorkProvider provider, RepositoryFactory repositoryFactory, ILogger logger, IEventMessagesFactory eventMessagesFactory)
|
||||
: base(provider, repositoryFactory, logger, eventMessagesFactory)
|
||||
public MigrationEntryService(IDatabaseUnitOfWorkProvider provider, ILogger logger, IEventMessagesFactory eventMessagesFactory)
|
||||
: base(provider, logger, eventMessagesFactory)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -35,11 +36,11 @@ namespace Umbraco.Core.Services
|
||||
Version = version
|
||||
};
|
||||
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repo = RepositoryFactory.CreateMigrationEntryRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repo = uow.CreateRepository<IMigrationEntryRepository>();
|
||||
repo.AddOrUpdate(entry);
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
return entry;
|
||||
@@ -53,9 +54,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns></returns>
|
||||
public IMigrationEntry FindEntry(string migrationName, SemVersion version)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repo = RepositoryFactory.CreateMigrationEntryRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repo = uow.CreateRepository<IMigrationEntryRepository>();
|
||||
return repo.FindEntry(migrationName, version);
|
||||
}
|
||||
}
|
||||
@@ -67,9 +68,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns></returns>
|
||||
public IEnumerable<IMigrationEntry> GetAll(string migrationName)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repo = RepositoryFactory.CreateMigrationEntryRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repo = uow.CreateRepository<IMigrationEntryRepository>();
|
||||
var query = repo.Query
|
||||
.Where(x => x.MigrationName.ToUpper() == migrationName.ToUpper());
|
||||
return repo.GetByQuery(query);
|
||||
|
||||
@@ -107,9 +107,11 @@ namespace Umbraco.Core.Services
|
||||
/// <returns></returns>
|
||||
public IEnumerable<Notification> GetUserNotifications(IUser user)
|
||||
{
|
||||
var uow = _uowProvider.GetUnitOfWork();
|
||||
var repository = _repositoryFactory.CreateNotificationsRepository(uow);
|
||||
return repository.GetUserNotifications(user);
|
||||
using (var uow = _uowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<INotificationsRepository>();
|
||||
return repository.GetUserNotifications(user);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -135,9 +137,11 @@ namespace Umbraco.Core.Services
|
||||
/// <param name="entity"></param>
|
||||
public IEnumerable<Notification> GetEntityNotifications(IEntity entity)
|
||||
{
|
||||
var uow = _uowProvider.GetUnitOfWork();
|
||||
var repository = _repositoryFactory.CreateNotificationsRepository(uow);
|
||||
return repository.GetEntityNotifications(entity);
|
||||
using (var uow = _uowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<INotificationsRepository>();
|
||||
return repository.GetEntityNotifications(entity);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -146,9 +150,11 @@ namespace Umbraco.Core.Services
|
||||
/// <param name="entity"></param>
|
||||
public void DeleteNotifications(IEntity entity)
|
||||
{
|
||||
var uow = _uowProvider.GetUnitOfWork();
|
||||
var repository = _repositoryFactory.CreateNotificationsRepository(uow);
|
||||
repository.DeleteNotifications(entity);
|
||||
using (var uow = _uowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<INotificationsRepository>();
|
||||
repository.DeleteNotifications(entity);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -157,9 +163,11 @@ namespace Umbraco.Core.Services
|
||||
/// <param name="user"></param>
|
||||
public void DeleteNotifications(IUser user)
|
||||
{
|
||||
var uow = _uowProvider.GetUnitOfWork();
|
||||
var repository = _repositoryFactory.CreateNotificationsRepository(uow);
|
||||
repository.DeleteNotifications(user);
|
||||
using (var uow = _uowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<INotificationsRepository>();
|
||||
repository.DeleteNotifications(user);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -169,9 +177,11 @@ namespace Umbraco.Core.Services
|
||||
/// <param name="entity"></param>
|
||||
public void DeleteNotifications(IUser user, IEntity entity)
|
||||
{
|
||||
var uow = _uowProvider.GetUnitOfWork();
|
||||
var repository = _repositoryFactory.CreateNotificationsRepository(uow);
|
||||
repository.DeleteNotifications(user, entity);
|
||||
using (var uow = _uowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<INotificationsRepository>();
|
||||
repository.DeleteNotifications(user, entity);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -185,9 +195,11 @@ namespace Umbraco.Core.Services
|
||||
/// </remarks>
|
||||
public IEnumerable<Notification> SetNotifications(IUser user, IEntity entity, string[] actions)
|
||||
{
|
||||
var uow = _uowProvider.GetUnitOfWork();
|
||||
var repository = _repositoryFactory.CreateNotificationsRepository(uow);
|
||||
return repository.SetNotifications(user, entity, actions);
|
||||
using (var uow = _uowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<INotificationsRepository>();
|
||||
return repository.SetNotifications(user, entity, actions);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -199,9 +211,11 @@ namespace Umbraco.Core.Services
|
||||
/// <returns></returns>
|
||||
public Notification CreateNotification(IUser user, IEntity entity, string action)
|
||||
{
|
||||
var uow = _uowProvider.GetUnitOfWork();
|
||||
var repository = _repositoryFactory.CreateNotificationsRepository(uow);
|
||||
return repository.CreateNotification(user, entity, action);
|
||||
using (var uow = _uowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<INotificationsRepository>();
|
||||
return repository.CreateNotification(user, entity, action);
|
||||
}
|
||||
}
|
||||
|
||||
#region private methods
|
||||
|
||||
@@ -14,11 +14,12 @@ using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.EntityBase;
|
||||
using Umbraco.Core.Models.Packaging;
|
||||
using Umbraco.Core.Models.Rdbms;
|
||||
using Umbraco.Core.Packaging;
|
||||
using Umbraco.Core.Packaging.Models;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Persistence.Querying;
|
||||
using Umbraco.Core.Persistence.Repositories;
|
||||
using Umbraco.Core.Persistence.UnitOfWork;
|
||||
using Content = Umbraco.Core.Models.Content;
|
||||
using Umbraco.Core.Strings;
|
||||
@@ -781,8 +782,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns></returns>
|
||||
private IContentType FindContentTypeByAlias(string contentTypeAlias)
|
||||
{
|
||||
using (var repository = _repositoryFactory.CreateContentTypeRepository(_uowProvider.GetUnitOfWork()))
|
||||
using (var uow = _uowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IContentTypeRepository>();
|
||||
var query = repository.Query.Where(x => x.Alias == contentTypeAlias);
|
||||
var types = repository.GetByQuery(query).ToArray();
|
||||
|
||||
|
||||
@@ -7,14 +7,15 @@ using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Persistence.Querying;
|
||||
using Umbraco.Core.Persistence.Repositories;
|
||||
using Umbraco.Core.Persistence.UnitOfWork;
|
||||
|
||||
namespace Umbraco.Core.Services
|
||||
{
|
||||
public class PublicAccessService : RepositoryService, IPublicAccessService
|
||||
{
|
||||
public PublicAccessService(IDatabaseUnitOfWorkProvider provider, RepositoryFactory repositoryFactory, ILogger logger, IEventMessagesFactory eventMessagesFactory)
|
||||
: base(provider, repositoryFactory, logger, eventMessagesFactory)
|
||||
public PublicAccessService(IDatabaseUnitOfWorkProvider provider, ILogger logger, IEventMessagesFactory eventMessagesFactory)
|
||||
: base(provider, logger, eventMessagesFactory)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -24,8 +25,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns></returns>
|
||||
public IEnumerable<PublicAccessEntry> GetAll()
|
||||
{
|
||||
using (var repo = RepositoryFactory.CreatePublicAccessRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repo = uow.CreateRepository<IPublicAccessRepository>();
|
||||
return repo.GetAll();
|
||||
}
|
||||
}
|
||||
@@ -68,8 +70,10 @@ namespace Umbraco.Core.Services
|
||||
//start with the deepest id
|
||||
ids.Reverse();
|
||||
|
||||
using (var repo = RepositoryFactory.CreatePublicAccessRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repo = uow.CreateRepository<IPublicAccessRepository>();
|
||||
|
||||
//This will retrieve from cache!
|
||||
var entries = repo.GetAll().ToArray();
|
||||
|
||||
@@ -115,10 +119,12 @@ namespace Umbraco.Core.Services
|
||||
public Attempt<OperationStatus<PublicAccessEntry, OperationStatusType>> AddRule(IContent content, string ruleType, string ruleValue)
|
||||
{
|
||||
var evtMsgs = EventMessagesFactory.Get();
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repo = RepositoryFactory.CreatePublicAccessRepository(uow))
|
||||
PublicAccessEntry entry;
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var entry = repo.GetAll().FirstOrDefault(x => x.ProtectedNodeId == content.Id);
|
||||
var repo = uow.CreateRepository<IPublicAccessRepository>();
|
||||
|
||||
entry = repo.GetAll().FirstOrDefault(x => x.ProtectedNodeId == content.Id);
|
||||
if (entry == null)
|
||||
return Attempt<OperationStatus<PublicAccessEntry, OperationStatusType>>.Fail();
|
||||
|
||||
@@ -144,12 +150,12 @@ namespace Umbraco.Core.Services
|
||||
|
||||
repo.AddOrUpdate(entry);
|
||||
|
||||
uow.Commit();
|
||||
|
||||
Saved.RaiseEvent(new SaveEventArgs<PublicAccessEntry>(entry, false, evtMsgs), this);
|
||||
return Attempt<OperationStatus<PublicAccessEntry, OperationStatusType>>.Succeed(
|
||||
new OperationStatus<PublicAccessEntry, OperationStatusType>(entry, OperationStatusType.Success, evtMsgs));
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
Saved.RaiseEvent(new SaveEventArgs<PublicAccessEntry>(entry, false, evtMsgs), this);
|
||||
return Attempt<OperationStatus<PublicAccessEntry, OperationStatusType>>.Succeed(
|
||||
new OperationStatus<PublicAccessEntry, OperationStatusType>(entry, OperationStatusType.Success, evtMsgs));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -161,10 +167,12 @@ namespace Umbraco.Core.Services
|
||||
public Attempt<OperationStatus> RemoveRule(IContent content, string ruleType, string ruleValue)
|
||||
{
|
||||
var evtMsgs = EventMessagesFactory.Get();
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repo = RepositoryFactory.CreatePublicAccessRepository(uow))
|
||||
PublicAccessEntry entry;
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var entry = repo.GetAll().FirstOrDefault(x => x.ProtectedNodeId == content.Id);
|
||||
var repo = uow.CreateRepository<IPublicAccessRepository>();
|
||||
|
||||
entry = repo.GetAll().FirstOrDefault(x => x.ProtectedNodeId == content.Id);
|
||||
if (entry == null) return Attempt<OperationStatus>.Fail();
|
||||
|
||||
var existingRule = entry.Rules.FirstOrDefault(x => x.RuleType == ruleType && x.RuleValue == ruleValue);
|
||||
@@ -172,21 +180,15 @@ namespace Umbraco.Core.Services
|
||||
|
||||
entry.RemoveRule(existingRule);
|
||||
|
||||
if (Saving.IsRaisedEventCancelled(
|
||||
new SaveEventArgs<PublicAccessEntry>(entry, evtMsgs),
|
||||
this))
|
||||
{
|
||||
if (Saving.IsRaisedEventCancelled(new SaveEventArgs<PublicAccessEntry>(entry, evtMsgs), this))
|
||||
return OperationStatus.Cancelled(evtMsgs);
|
||||
}
|
||||
|
||||
repo.AddOrUpdate(entry);
|
||||
|
||||
uow.Commit();
|
||||
|
||||
Saved.RaiseEvent(new SaveEventArgs<PublicAccessEntry>(entry, false, evtMsgs), this);
|
||||
return OperationStatus.Success(evtMsgs);
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
Saved.RaiseEvent(new SaveEventArgs<PublicAccessEntry>(entry, false, evtMsgs), this);
|
||||
return OperationStatus.Success(evtMsgs);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -203,11 +205,11 @@ namespace Umbraco.Core.Services
|
||||
return OperationStatus.Cancelled(evtMsgs);
|
||||
}
|
||||
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repo = RepositoryFactory.CreatePublicAccessRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repo = uow.CreateRepository<IPublicAccessRepository>();
|
||||
repo.AddOrUpdate(entry);
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
Saved.RaiseEvent(new SaveEventArgs<PublicAccessEntry>(entry, false, evtMsgs), this);
|
||||
@@ -228,11 +230,11 @@ namespace Umbraco.Core.Services
|
||||
return OperationStatus.Cancelled(evtMsgs);
|
||||
}
|
||||
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repo = RepositoryFactory.CreatePublicAccessRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repo = uow.CreateRepository<IPublicAccessRepository>();
|
||||
repo.Delete(entry);
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
Deleted.RaiseEvent(new DeleteEventArgs<PublicAccessEntry>(entry, false, evtMsgs), this);
|
||||
|
||||
@@ -7,6 +7,7 @@ using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.EntityBase;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Persistence.Querying;
|
||||
using Umbraco.Core.Persistence.Repositories;
|
||||
using Umbraco.Core.Persistence.UnitOfWork;
|
||||
|
||||
namespace Umbraco.Core.Services
|
||||
@@ -15,8 +16,8 @@ namespace Umbraco.Core.Services
|
||||
{
|
||||
private readonly IEntityService _entityService;
|
||||
|
||||
public RelationService(IDatabaseUnitOfWorkProvider uowProvider, RepositoryFactory repositoryFactory, ILogger logger, IEventMessagesFactory eventMessagesFactory, IEntityService entityService)
|
||||
: base(uowProvider, repositoryFactory, logger, eventMessagesFactory)
|
||||
public RelationService(IDatabaseUnitOfWorkProvider uowProvider, ILogger logger, IEventMessagesFactory eventMessagesFactory, IEntityService entityService)
|
||||
: base(uowProvider, logger, eventMessagesFactory)
|
||||
{
|
||||
if (entityService == null) throw new ArgumentNullException("entityService");
|
||||
_entityService = entityService;
|
||||
@@ -29,8 +30,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>A <see cref="Relation"/> object</returns>
|
||||
public IRelation GetById(int id)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateRelationRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IRelationRepository>();
|
||||
return repository.Get(id);
|
||||
}
|
||||
}
|
||||
@@ -42,8 +44,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>A <see cref="RelationType"/> object</returns>
|
||||
public IRelationType GetRelationTypeById(int id)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateRelationTypeRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IRelationTypeRepository>();
|
||||
return repository.Get(id);
|
||||
}
|
||||
}
|
||||
@@ -55,8 +58,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>A <see cref="RelationType"/> object</returns>
|
||||
public IRelationType GetRelationTypeByAlias(string alias)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateRelationTypeRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IRelationTypeRepository>();
|
||||
var query = repository.Query.Where(x => x.Alias == alias);
|
||||
return repository.GetByQuery(query).FirstOrDefault();
|
||||
}
|
||||
@@ -69,8 +73,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>An enumerable list of <see cref="Relation"/> objects</returns>
|
||||
public IEnumerable<IRelation> GetAllRelations(params int[] ids)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateRelationRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IRelationRepository>();
|
||||
return repository.GetAll(ids);
|
||||
}
|
||||
}
|
||||
@@ -92,8 +97,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>An enumerable list of <see cref="Relation"/> objects</returns>
|
||||
public IEnumerable<IRelation> GetAllRelationsByRelationType(int relationTypeId)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateRelationRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IRelationRepository>();
|
||||
var query = repository.Query.Where(x => x.RelationTypeId == relationTypeId);
|
||||
return repository.GetByQuery(query);
|
||||
}
|
||||
@@ -106,8 +112,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>An enumerable list of <see cref="RelationType"/> objects</returns>
|
||||
public IEnumerable<IRelationType> GetAllRelationTypes(params int[] ids)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateRelationTypeRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IRelationTypeRepository>();
|
||||
return repository.GetAll(ids);
|
||||
}
|
||||
}
|
||||
@@ -119,8 +126,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>An enumerable list of <see cref="Relation"/> objects</returns>
|
||||
public IEnumerable<IRelation> GetByParentId(int id)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateRelationRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IRelationRepository>();
|
||||
var query = repository.Query.Where(x => x.ParentId == id);
|
||||
return repository.GetByQuery(query);
|
||||
}
|
||||
@@ -154,8 +162,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>An enumerable list of <see cref="Relation"/> objects</returns>
|
||||
public IEnumerable<IRelation> GetByChildId(int id)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateRelationRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IRelationRepository>();
|
||||
var query = repository.Query.Where(x => x.ChildId == id);
|
||||
return repository.GetByQuery(query);
|
||||
}
|
||||
@@ -190,8 +199,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>An enumerable list of <see cref="Relation"/> objects</returns>
|
||||
public IEnumerable<IRelation> GetByParentOrChildId(int id)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateRelationRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IRelationRepository>();
|
||||
var query = repository.Query.Where(x => x.ChildId == id || x.ParentId == id);
|
||||
return repository.GetByQuery(query);
|
||||
}
|
||||
@@ -199,18 +209,17 @@ namespace Umbraco.Core.Services
|
||||
|
||||
public IEnumerable<IRelation> GetByParentOrChildId(int id, string relationTypeAlias)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateRelationTypeRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IRelationTypeRepository>();
|
||||
|
||||
var rtQuery = repository.Query.Where(x => x.Alias == relationTypeAlias);
|
||||
var relationType = repository.GetByQuery(rtQuery).FirstOrDefault();
|
||||
if (relationType == null) return Enumerable.Empty<IRelation>();
|
||||
|
||||
using (var relationRepo = RepositoryFactory.CreateRelationRepository(uow))
|
||||
{
|
||||
var query = relationRepo.Query.Where(x => (x.ChildId == id || x.ParentId == id) && x.RelationTypeId == relationType.Id);
|
||||
return relationRepo.GetByQuery(query);
|
||||
}
|
||||
var relationRepo = uow.CreateRepository<IRelationRepository>();
|
||||
var query = relationRepo.Query.Where(x => (x.ChildId == id || x.ParentId == id) && x.RelationTypeId == relationType.Id);
|
||||
return relationRepo.GetByQuery(query);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -222,8 +231,9 @@ namespace Umbraco.Core.Services
|
||||
public IEnumerable<IRelation> GetByRelationTypeName(string relationTypeName)
|
||||
{
|
||||
List<int> relationTypeIds = null;
|
||||
using (var repository = RepositoryFactory.CreateRelationTypeRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IRelationTypeRepository>();
|
||||
var query = repository.Query.Where(x => x.Name == relationTypeName);
|
||||
var relationTypes = repository.GetByQuery(query);
|
||||
if (relationTypes.Any())
|
||||
@@ -246,8 +256,9 @@ namespace Umbraco.Core.Services
|
||||
public IEnumerable<IRelation> GetByRelationTypeAlias(string relationTypeAlias)
|
||||
{
|
||||
List<int> relationTypeIds = null;
|
||||
using (var repository = RepositoryFactory.CreateRelationTypeRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IRelationTypeRepository>();
|
||||
var query = repository.Query.Where(x => x.Alias == relationTypeAlias);
|
||||
var relationTypes = repository.GetByQuery(query);
|
||||
if (relationTypes.Any())
|
||||
@@ -269,8 +280,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>An enumerable list of <see cref="Relation"/> objects</returns>
|
||||
public IEnumerable<IRelation> GetByRelationTypeId(int relationTypeId)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateRelationRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IRelationRepository>();
|
||||
var query = repository.Query.Where(x => x.RelationTypeId == relationTypeId);
|
||||
return repository.GetByQuery(query);
|
||||
}
|
||||
@@ -387,11 +399,11 @@ namespace Umbraco.Core.Services
|
||||
if (SavingRelation.IsRaisedEventCancelled(new SaveEventArgs<IRelation>(relation), this))
|
||||
return relation;
|
||||
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateRelationRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IRelationRepository>();
|
||||
repository.AddOrUpdate(relation);
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
SavedRelation.RaiseEvent(new SaveEventArgs<IRelation>(relation, false), this);
|
||||
@@ -415,11 +427,11 @@ namespace Umbraco.Core.Services
|
||||
if (SavingRelation.IsRaisedEventCancelled(new SaveEventArgs<IRelation>(relation), this))
|
||||
return relation;
|
||||
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateRelationRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IRelationRepository>();
|
||||
repository.AddOrUpdate(relation);
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
SavedRelation.RaiseEvent(new SaveEventArgs<IRelation>(relation, false), this);
|
||||
@@ -433,8 +445,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>Returns <c>True</c> if any relations exists for the given <see cref="RelationType"/>, otherwise <c>False</c></returns>
|
||||
public bool HasRelations(IRelationType relationType)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateRelationRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IRelationRepository>();
|
||||
var query = repository.Query.Where(x => x.RelationTypeId == relationType.Id);
|
||||
return repository.GetByQuery(query).Any();
|
||||
}
|
||||
@@ -447,8 +460,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>Returns <c>True</c> if any relations exists with the given Id, otherwise <c>False</c></returns>
|
||||
public bool IsRelated(int id)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateRelationRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IRelationRepository>();
|
||||
var query = repository.Query.Where(x => x.ParentId == id || x.ChildId == id);
|
||||
return repository.GetByQuery(query).Any();
|
||||
}
|
||||
@@ -462,8 +476,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>Returns <c>True</c> if any relations exists with the given Ids, otherwise <c>False</c></returns>
|
||||
public bool AreRelated(int parentId, int childId)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateRelationRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IRelationRepository>();
|
||||
var query = repository.Query.Where(x => x.ParentId == parentId && x.ChildId == childId);
|
||||
return repository.GetByQuery(query).Any();
|
||||
}
|
||||
@@ -495,8 +510,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>Returns <c>True</c> if any relations exists with the given Ids and relation type, otherwise <c>False</c></returns>
|
||||
public bool AreRelated(int parentId, int childId, IRelationType relationType)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateRelationRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IRelationRepository>();
|
||||
var query = repository.Query.Where(x => x.ParentId == parentId && x.ChildId == childId && x.RelationTypeId == relationType.Id);
|
||||
return repository.GetByQuery(query).Any();
|
||||
}
|
||||
@@ -535,11 +551,11 @@ namespace Umbraco.Core.Services
|
||||
if (SavingRelation.IsRaisedEventCancelled(new SaveEventArgs<IRelation>(relation), this))
|
||||
return;
|
||||
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateRelationRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IRelationRepository>();
|
||||
repository.AddOrUpdate(relation);
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
SavedRelation.RaiseEvent(new SaveEventArgs<IRelation>(relation, false), this);
|
||||
@@ -554,11 +570,11 @@ namespace Umbraco.Core.Services
|
||||
if (SavingRelationType.IsRaisedEventCancelled(new SaveEventArgs<IRelationType>(relationType), this))
|
||||
return;
|
||||
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateRelationTypeRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IRelationTypeRepository>();
|
||||
repository.AddOrUpdate(relationType);
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
SavedRelationType.RaiseEvent(new SaveEventArgs<IRelationType>(relationType, false), this);
|
||||
@@ -573,11 +589,11 @@ namespace Umbraco.Core.Services
|
||||
if (DeletingRelation.IsRaisedEventCancelled(new DeleteEventArgs<IRelation>(relation), this))
|
||||
return;
|
||||
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateRelationRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IRelationRepository>();
|
||||
repository.Delete(relation);
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
DeletedRelation.RaiseEvent(new DeleteEventArgs<IRelation>(relation, false), this);
|
||||
@@ -592,11 +608,11 @@ namespace Umbraco.Core.Services
|
||||
if (DeletingRelationType.IsRaisedEventCancelled(new DeleteEventArgs<IRelationType>(relationType), this))
|
||||
return;
|
||||
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateRelationTypeRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IRelationTypeRepository>();
|
||||
repository.Delete(relationType);
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
DeletedRelationType.RaiseEvent(new DeleteEventArgs<IRelationType>(relationType, false), this);
|
||||
@@ -609,17 +625,16 @@ namespace Umbraco.Core.Services
|
||||
public void DeleteRelationsOfType(IRelationType relationType)
|
||||
{
|
||||
var relations = new List<IRelation>();
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateRelationRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IRelationRepository>();
|
||||
var query = repository.Query.Where(x => x.RelationTypeId == relationType.Id);
|
||||
relations.AddRange(repository.GetByQuery(query).ToList());
|
||||
|
||||
foreach (var relation in relations)
|
||||
{
|
||||
repository.Delete(relation);
|
||||
}
|
||||
uow.Commit();
|
||||
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
DeletedRelation.RaiseEvent(new DeleteEventArgs<IRelation>(relations, false), this);
|
||||
@@ -629,8 +644,9 @@ namespace Umbraco.Core.Services
|
||||
private IEnumerable<IRelation> GetRelationsByListOfTypeIds(IEnumerable<int> relationTypeIds)
|
||||
{
|
||||
var relations = new List<IRelation>();
|
||||
using (var repository = RepositoryFactory.CreateRelationRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IRelationRepository>();
|
||||
foreach (var relationTypeId in relationTypeIds)
|
||||
{
|
||||
int id = relationTypeId;
|
||||
|
||||
@@ -2,31 +2,26 @@ using System;
|
||||
using Umbraco.Core.Events;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Persistence.Querying;
|
||||
using Umbraco.Core.Persistence.SqlSyntax;
|
||||
using Umbraco.Core.Persistence.UnitOfWork;
|
||||
|
||||
namespace Umbraco.Core.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// Base service class
|
||||
/// Represents a service that works on top of repositories.
|
||||
/// </summary>
|
||||
public abstract class RepositoryService : IService
|
||||
{
|
||||
protected ILogger Logger { get; private set; }
|
||||
protected IEventMessagesFactory EventMessagesFactory { get; private set; }
|
||||
protected RepositoryFactory RepositoryFactory { get; private set; }
|
||||
protected IDatabaseUnitOfWorkProvider UowProvider { get; private set; }
|
||||
|
||||
protected RepositoryService(IDatabaseUnitOfWorkProvider provider, RepositoryFactory repositoryFactory, ILogger logger, IEventMessagesFactory eventMessagesFactory)
|
||||
protected RepositoryService(IDatabaseUnitOfWorkProvider provider, ILogger logger, IEventMessagesFactory eventMessagesFactory)
|
||||
{
|
||||
if (provider == null) throw new ArgumentNullException("provider");
|
||||
if (repositoryFactory == null) throw new ArgumentNullException("repositoryFactory");
|
||||
if (logger == null) throw new ArgumentNullException("logger");
|
||||
if (eventMessagesFactory == null) throw new ArgumentNullException("eventMessagesFactory");
|
||||
if (provider == null) throw new ArgumentNullException(nameof(provider));
|
||||
if (logger == null) throw new ArgumentNullException(nameof(logger));
|
||||
if (eventMessagesFactory == null) throw new ArgumentNullException(nameof(eventMessagesFactory));
|
||||
Logger = logger;
|
||||
EventMessagesFactory = eventMessagesFactory;
|
||||
RepositoryFactory = repositoryFactory;
|
||||
UowProvider = provider;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,24 +20,17 @@ namespace Umbraco.Core.Services
|
||||
private readonly static string CurrentServerIdentityValue = NetworkHelper.MachineName // eg DOMAIN\SERVER
|
||||
+ "/" + HttpRuntime.AppDomainAppId; // eg /LM/S3SVC/11/ROOT
|
||||
|
||||
private static readonly int[] LockingRepositoryIds = { Constants.System.ServersLock };
|
||||
private ServerRole _currentServerRole = ServerRole.Unknown;
|
||||
private readonly LockingRepository<IServerRegistrationRepository> _lrepo;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ServerRegistrationService"/> class.
|
||||
/// </summary>
|
||||
/// <param name="uowProvider">A UnitOfWork provider.</param>
|
||||
/// <param name="repositoryFactory">A repository factory.</param>
|
||||
/// <param name="logger">A logger.</param>
|
||||
/// <param name="eventMessagesFactory"></param>
|
||||
public ServerRegistrationService(IDatabaseUnitOfWorkProvider uowProvider, RepositoryFactory repositoryFactory, ILogger logger, IEventMessagesFactory eventMessagesFactory)
|
||||
: base(uowProvider, repositoryFactory, logger, eventMessagesFactory)
|
||||
{
|
||||
_lrepo = new LockingRepository<IServerRegistrationRepository>(UowProvider,
|
||||
x => RepositoryFactory.CreateServerRegistrationRepository(x),
|
||||
LockingRepositoryIds, LockingRepositoryIds);
|
||||
}
|
||||
public ServerRegistrationService(IDatabaseUnitOfWorkProvider uowProvider, ILogger logger, IEventMessagesFactory eventMessagesFactory)
|
||||
: base(uowProvider, logger, eventMessagesFactory)
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
/// Touches a server to mark it as active; deactivate stale servers.
|
||||
@@ -47,11 +40,14 @@ namespace Umbraco.Core.Services
|
||||
/// <param name="staleTimeout">The time after which a server is considered stale.</param>
|
||||
public void TouchServer(string serverAddress, string serverIdentity, TimeSpan staleTimeout)
|
||||
{
|
||||
_lrepo.WithWriteLocked(xr =>
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
((ServerRegistrationRepository) xr.Repository).ReloadCache(); // ensure we have up-to-date cache
|
||||
var repo = uow.CreateRepository<IServerRegistrationRepository>();
|
||||
repo.WriteLockServers();
|
||||
|
||||
var regs = xr.Repository.GetAll().ToArray();
|
||||
((ServerRegistrationRepository) repo).ReloadCache(); // ensure we have up-to-date cache
|
||||
|
||||
var regs = repo.GetAll().ToArray();
|
||||
var hasMaster = regs.Any(x => ((ServerRegistration)x).IsMaster);
|
||||
var server = regs.FirstOrDefault(x => x.ServerIdentity.InvariantEquals(serverIdentity));
|
||||
|
||||
@@ -69,19 +65,21 @@ namespace Umbraco.Core.Services
|
||||
if (hasMaster == false)
|
||||
server.IsMaster = true;
|
||||
|
||||
xr.Repository.AddOrUpdate(server);
|
||||
xr.UnitOfWork.Commit(); // triggers a cache reload
|
||||
xr.Repository.DeactiveStaleServers(staleTimeout); // triggers a cache reload
|
||||
repo.AddOrUpdate(server);
|
||||
uow.Flush(); // triggers a cache reload
|
||||
repo.DeactiveStaleServers(staleTimeout); // triggers a cache reload
|
||||
|
||||
// reload - cheap, cached
|
||||
regs = xr.Repository.GetAll().ToArray();
|
||||
regs = repo.GetAll().ToArray();
|
||||
|
||||
// default role is single server, but if registrations contain more
|
||||
// than one active server, then role is master or slave
|
||||
_currentServerRole = regs.Count(x => x.IsActive) > 1
|
||||
? (server.IsMaster ? ServerRole.Master : ServerRole.Slave)
|
||||
: ServerRole.Single;
|
||||
});
|
||||
? (server.IsMaster ? ServerRole.Master : ServerRole.Slave)
|
||||
: ServerRole.Single;
|
||||
|
||||
uow.Complete();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -103,15 +101,20 @@ namespace Umbraco.Core.Services
|
||||
|
||||
// because the repository caches "all" and has queries disabled...
|
||||
|
||||
_lrepo.WithWriteLocked(xr =>
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
((ServerRegistrationRepository)xr.Repository).ReloadCache(); // ensure we have up-to-date cache
|
||||
var repo = uow.CreateRepository<IServerRegistrationRepository>();
|
||||
repo.WriteLockServers();
|
||||
|
||||
var server = xr.Repository.GetAll().FirstOrDefault(x => x.ServerIdentity.InvariantEquals(serverIdentity));
|
||||
((ServerRegistrationRepository) repo).ReloadCache(); // ensure we have up-to-date cache
|
||||
|
||||
var server = repo.GetAll().FirstOrDefault(x => x.ServerIdentity.InvariantEquals(serverIdentity));
|
||||
if (server == null) return;
|
||||
server.IsActive = server.IsMaster = false;
|
||||
xr.Repository.AddOrUpdate(server); // will trigger a cache reload
|
||||
});
|
||||
repo.AddOrUpdate(server); // will trigger a cache reload
|
||||
|
||||
uow.Complete();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -120,7 +123,13 @@ namespace Umbraco.Core.Services
|
||||
/// <param name="staleTimeout">The time after which a server is considered stale.</param>
|
||||
public void DeactiveStaleServers(TimeSpan staleTimeout)
|
||||
{
|
||||
_lrepo.WithWriteLocked(xr => xr.Repository.DeactiveStaleServers(staleTimeout));
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repo = uow.CreateRepository<IServerRegistrationRepository>();
|
||||
repo.WriteLockServers();
|
||||
|
||||
repo.DeactiveStaleServers(staleTimeout);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -129,6 +138,8 @@ namespace Umbraco.Core.Services
|
||||
/// <returns></returns>
|
||||
public IEnumerable<IServerRegistration> GetActiveServers()
|
||||
{
|
||||
// fixme - this needs to be refactored entirely now that we have repeatable read everywhere
|
||||
|
||||
//return _lrepo.WithReadLocked(xr =>
|
||||
//{
|
||||
// var query = Query<IServerRegistration>.Builder.Where(x => x.IsActive);
|
||||
@@ -152,15 +163,19 @@ namespace Umbraco.Core.Services
|
||||
// this raises a good number of questions, including whether caching anything in
|
||||
// repositories works at all in a LB environment - TODO: figure it out
|
||||
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
var repo = RepositoryFactory.CreateServerRegistrationRepository(uow);
|
||||
return repo.GetAll().Where(x => x.IsActive).ToArray(); // fast, cached
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repo = uow.CreateRepository<IServerRegistrationRepository>();
|
||||
repo.ReadLockServers();
|
||||
|
||||
return repo.GetAll().Where(x => x.IsActive).ToArray(); // fast, cached
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the local server identity.
|
||||
/// </summary>
|
||||
public string CurrentServerIdentity { get { return CurrentServerIdentityValue; } }
|
||||
public string CurrentServerIdentity => CurrentServerIdentityValue;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the role of the current server.
|
||||
|
||||
@@ -5,6 +5,7 @@ using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Persistence.Querying;
|
||||
using Umbraco.Core.Persistence.Repositories;
|
||||
using Umbraco.Core.Persistence.UnitOfWork;
|
||||
|
||||
namespace Umbraco.Core.Services
|
||||
@@ -18,23 +19,25 @@ namespace Umbraco.Core.Services
|
||||
public class TagService : RepositoryService, ITagService
|
||||
{
|
||||
|
||||
public TagService(IDatabaseUnitOfWorkProvider provider, RepositoryFactory repositoryFactory, ILogger logger, IEventMessagesFactory eventMessagesFactory)
|
||||
: base(provider, repositoryFactory, logger, eventMessagesFactory)
|
||||
public TagService(IDatabaseUnitOfWorkProvider provider, ILogger logger, IEventMessagesFactory eventMessagesFactory)
|
||||
: base(provider, logger, eventMessagesFactory)
|
||||
{
|
||||
}
|
||||
|
||||
public TaggedEntity GetTaggedEntityById(int id)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateTagRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<ITagRepository>();
|
||||
return repository.GetTaggedEntityById(id);
|
||||
}
|
||||
}
|
||||
|
||||
public TaggedEntity GetTaggedEntityByKey(Guid key)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateTagRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<ITagRepository>();
|
||||
return repository.GetTaggedEntityByKey(key);
|
||||
}
|
||||
}
|
||||
@@ -47,8 +50,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>An enumerable list of <see cref="TaggedEntity"/></returns>
|
||||
public IEnumerable<TaggedEntity> GetTaggedContentByTagGroup(string tagGroup)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateTagRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<ITagRepository>();
|
||||
return repository.GetTaggedEntitiesByTagGroup(TaggableObjectTypes.Content, tagGroup);
|
||||
}
|
||||
}
|
||||
@@ -62,8 +66,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>An enumerable list of <see cref="TaggedEntity"/></returns>
|
||||
public IEnumerable<TaggedEntity> GetTaggedContentByTag(string tag, string tagGroup = null)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateTagRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<ITagRepository>();
|
||||
return repository.GetTaggedEntitiesByTag(TaggableObjectTypes.Content, tag, tagGroup);
|
||||
}
|
||||
}
|
||||
@@ -76,8 +81,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>An enumerable list of <see cref="TaggedEntity"/></returns>
|
||||
public IEnumerable<TaggedEntity> GetTaggedMediaByTagGroup(string tagGroup)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateTagRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<ITagRepository>();
|
||||
return repository.GetTaggedEntitiesByTagGroup(TaggableObjectTypes.Media, tagGroup);
|
||||
}
|
||||
}
|
||||
@@ -91,8 +97,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>An enumerable list of <see cref="TaggedEntity"/></returns>
|
||||
public IEnumerable<TaggedEntity> GetTaggedMediaByTag(string tag, string tagGroup = null)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateTagRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<ITagRepository>();
|
||||
return repository.GetTaggedEntitiesByTag(TaggableObjectTypes.Media, tag, tagGroup);
|
||||
}
|
||||
}
|
||||
@@ -105,8 +112,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>An enumerable list of <see cref="TaggedEntity"/></returns>
|
||||
public IEnumerable<TaggedEntity> GetTaggedMembersByTagGroup(string tagGroup)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateTagRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<ITagRepository>();
|
||||
return repository.GetTaggedEntitiesByTagGroup(TaggableObjectTypes.Member, tagGroup);
|
||||
}
|
||||
}
|
||||
@@ -120,8 +128,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>An enumerable list of <see cref="TaggedEntity"/></returns>
|
||||
public IEnumerable<TaggedEntity> GetTaggedMembersByTag(string tag, string tagGroup = null)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateTagRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<ITagRepository>();
|
||||
return repository.GetTaggedEntitiesByTag(TaggableObjectTypes.Member, tag, tagGroup);
|
||||
}
|
||||
}
|
||||
@@ -133,8 +142,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>An enumerable list of <see cref="ITag"/></returns>
|
||||
public IEnumerable<ITag> GetAllTags(string tagGroup = null)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateTagRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<ITagRepository>();
|
||||
return repository.GetTagsForEntityType(TaggableObjectTypes.All, tagGroup);
|
||||
}
|
||||
}
|
||||
@@ -148,8 +158,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>An enumerable list of <see cref="ITag"/></returns>
|
||||
public IEnumerable<ITag> GetAllContentTags(string tagGroup = null)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateTagRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<ITagRepository>();
|
||||
return repository.GetTagsForEntityType(TaggableObjectTypes.Content, tagGroup);
|
||||
}
|
||||
}
|
||||
@@ -163,8 +174,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>An enumerable list of <see cref="ITag"/></returns>
|
||||
public IEnumerable<ITag> GetAllMediaTags(string tagGroup = null)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateTagRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<ITagRepository>();
|
||||
return repository.GetTagsForEntityType(TaggableObjectTypes.Media, tagGroup);
|
||||
}
|
||||
}
|
||||
@@ -178,8 +190,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>An enumerable list of <see cref="ITag"/></returns>
|
||||
public IEnumerable<ITag> GetAllMemberTags(string tagGroup = null)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateTagRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<ITagRepository>();
|
||||
return repository.GetTagsForEntityType(TaggableObjectTypes.Member, tagGroup);
|
||||
}
|
||||
}
|
||||
@@ -195,8 +208,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>An enumerable list of <see cref="ITag"/></returns>
|
||||
public IEnumerable<ITag> GetTagsForProperty(int contentId, string propertyTypeAlias, string tagGroup = null)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateTagRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<ITagRepository>();
|
||||
return repository.GetTagsForProperty(contentId, propertyTypeAlias, tagGroup);
|
||||
}
|
||||
}
|
||||
@@ -211,8 +225,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>An enumerable list of <see cref="ITag"/></returns>
|
||||
public IEnumerable<ITag> GetTagsForEntity(int contentId, string tagGroup = null)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateTagRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<ITagRepository>();
|
||||
return repository.GetTagsForEntity(contentId, tagGroup);
|
||||
}
|
||||
}
|
||||
@@ -228,8 +243,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>An enumerable list of <see cref="ITag"/></returns>
|
||||
public IEnumerable<ITag> GetTagsForProperty(Guid contentId, string propertyTypeAlias, string tagGroup = null)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateTagRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<ITagRepository>();
|
||||
return repository.GetTagsForProperty(contentId, propertyTypeAlias, tagGroup);
|
||||
}
|
||||
}
|
||||
@@ -244,8 +260,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>An enumerable list of <see cref="ITag"/></returns>
|
||||
public IEnumerable<ITag> GetTagsForEntity(Guid contentId, string tagGroup = null)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateTagRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<ITagRepository>();
|
||||
return repository.GetTagsForEntity(contentId, tagGroup);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,57 +6,61 @@ using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Persistence.Querying;
|
||||
using Umbraco.Core.Persistence.Repositories;
|
||||
using Umbraco.Core.Persistence.UnitOfWork;
|
||||
|
||||
namespace Umbraco.Core.Services
|
||||
{
|
||||
public class TaskService : RepositoryService, ITaskService
|
||||
{
|
||||
public TaskService(IDatabaseUnitOfWorkProvider provider, RepositoryFactory repositoryFactory, ILogger logger, IEventMessagesFactory eventMessagesFactory)
|
||||
: base(provider, repositoryFactory, logger, eventMessagesFactory)
|
||||
public TaskService(IDatabaseUnitOfWorkProvider provider, ILogger logger, IEventMessagesFactory eventMessagesFactory)
|
||||
: base(provider, logger, eventMessagesFactory)
|
||||
{
|
||||
}
|
||||
|
||||
public TaskType GetTaskTypeByAlias(string taskTypeAlias)
|
||||
{
|
||||
using (var repo = RepositoryFactory.CreateTaskTypeRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repo = uow.CreateRepository<ITaskTypeRepository>();
|
||||
return repo.GetByQuery(repo.Query.Where(type => type.Alias == taskTypeAlias)).FirstOrDefault();
|
||||
}
|
||||
}
|
||||
|
||||
public TaskType GetTaskTypeById(int id)
|
||||
{
|
||||
using (var repo = RepositoryFactory.CreateTaskTypeRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repo = uow.CreateRepository<ITaskTypeRepository>();
|
||||
return repo.Get(id);
|
||||
}
|
||||
}
|
||||
|
||||
public void Save(TaskType taskType)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repo = RepositoryFactory.CreateTaskTypeRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repo = uow.CreateRepository<ITaskTypeRepository>();
|
||||
repo.AddOrUpdate(taskType);
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
}
|
||||
}
|
||||
|
||||
public void Delete(TaskType taskTypeEntity)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repo = RepositoryFactory.CreateTaskTypeRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repo = uow.CreateRepository<ITaskTypeRepository>();
|
||||
repo.Delete(taskTypeEntity);
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<TaskType> GetAllTaskTypes()
|
||||
{
|
||||
using (var repo = RepositoryFactory.CreateTaskTypeRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repo = uow.CreateRepository<ITaskTypeRepository>();
|
||||
return repo.GetAll();
|
||||
}
|
||||
}
|
||||
@@ -64,8 +68,9 @@ namespace Umbraco.Core.Services
|
||||
|
||||
public IEnumerable<Task> GetTasks(int? itemId = null, int? assignedUser = null, int? ownerUser = null, string taskTypeAlias = null, bool includeClosed = false)
|
||||
{
|
||||
using (var repo = RepositoryFactory.CreateTaskRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repo = uow.CreateRepository<ITaskRepository>();
|
||||
return repo.GetTasks(itemId, assignedUser, ownerUser, taskTypeAlias);
|
||||
}
|
||||
}
|
||||
@@ -76,28 +81,29 @@ namespace Umbraco.Core.Services
|
||||
/// <param name="task"></param>
|
||||
public void Save(Task task)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repo = RepositoryFactory.CreateTaskRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repo = uow.CreateRepository<ITaskRepository>();
|
||||
repo.AddOrUpdate(task);
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
}
|
||||
}
|
||||
|
||||
public void Delete(Task task)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repo = RepositoryFactory.CreateTaskRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repo = uow.CreateRepository<ITaskRepository>();
|
||||
repo.Delete(task);
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
}
|
||||
}
|
||||
|
||||
public Task GetTaskById(int id)
|
||||
{
|
||||
using (var repo = RepositoryFactory.CreateTaskRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repo = uow.CreateRepository<ITaskRepository>();
|
||||
return repo.Get(id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models.Membership;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Persistence.Querying;
|
||||
using Umbraco.Core.Persistence.Repositories;
|
||||
using Umbraco.Core.Persistence.UnitOfWork;
|
||||
using Umbraco.Core.Security;
|
||||
|
||||
@@ -25,8 +26,8 @@ namespace Umbraco.Core.Services
|
||||
// exceptions can occur if the db is not in it's correct state.
|
||||
internal bool IsUpgrading { get; set; }
|
||||
|
||||
public UserService(IDatabaseUnitOfWorkProvider provider, RepositoryFactory repositoryFactory, ILogger logger, IEventMessagesFactory eventMessagesFactory)
|
||||
: base(provider, repositoryFactory, logger, eventMessagesFactory)
|
||||
public UserService(IDatabaseUnitOfWorkProvider provider, ILogger logger, IEventMessagesFactory eventMessagesFactory)
|
||||
: base(provider, logger, eventMessagesFactory)
|
||||
{
|
||||
IsUpgrading = false;
|
||||
}
|
||||
@@ -41,8 +42,10 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>Alias of the default MemberType</returns>
|
||||
public string GetDefaultMemberType()
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateUserTypeRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IUserTypeRepository>();
|
||||
|
||||
var types = repository.GetAll().Select(x => x.Alias).ToArray();
|
||||
|
||||
if (types.Any() == false)
|
||||
@@ -72,8 +75,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns><c>True</c> if the User exists otherwise <c>False</c></returns>
|
||||
public bool Exists(string username)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateUserRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IUserRepository>();
|
||||
return repository.Exists(username);
|
||||
}
|
||||
}
|
||||
@@ -126,14 +130,15 @@ namespace Umbraco.Core.Services
|
||||
|
||||
//TODO: PUT lock here!!
|
||||
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateUserRepository(uow))
|
||||
User user;
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IUserRepository>();
|
||||
var loginExists = uow.Database.ExecuteScalar<int>("SELECT COUNT(id) FROM umbracoUser WHERE userLogin = @Login", new { Login = username }) != 0;
|
||||
if (loginExists)
|
||||
throw new ArgumentException("Login already exists");
|
||||
|
||||
var user = new User(userType)
|
||||
user = new User(userType)
|
||||
{
|
||||
DefaultToLiveEditing = false,
|
||||
Email = email,
|
||||
@@ -155,12 +160,11 @@ namespace Umbraco.Core.Services
|
||||
return user;
|
||||
|
||||
repository.AddOrUpdate(user);
|
||||
uow.Commit();
|
||||
|
||||
SavedUser.RaiseEvent(new SaveEventArgs<IUser>(user, false), this);
|
||||
|
||||
return user;
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
SavedUser.RaiseEvent(new SaveEventArgs<IUser>(user, false), this);
|
||||
return user;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -170,8 +174,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns><see cref="IUser"/></returns>
|
||||
public IUser GetById(int id)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateUserRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IUserRepository>();
|
||||
var user = repository.Get((int)id);
|
||||
|
||||
return user;
|
||||
@@ -201,8 +206,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns><see cref="IUser"/></returns>
|
||||
public IUser GetByEmail(string email)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateUserRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IUserRepository>();
|
||||
var query = repository.Query.Where(x => x.Email.Equals(email));
|
||||
var user = repository.GetByQuery(query).FirstOrDefault();
|
||||
|
||||
@@ -217,8 +223,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns><see cref="IUser"/></returns>
|
||||
public IUser GetByUsername(string username)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateUserRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IUserRepository>();
|
||||
var query = repository.Query.Where(x => x.Username.Equals(username));
|
||||
var user = repository.GetByQuery(query).FirstOrDefault();
|
||||
return user;
|
||||
@@ -287,11 +294,11 @@ namespace Umbraco.Core.Services
|
||||
if (DeletingUser.IsRaisedEventCancelled(new DeleteEventArgs<IUser>(user), this))
|
||||
return;
|
||||
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateUserRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IUserRepository>();
|
||||
repository.Delete(user);
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
DeletedUser.RaiseEvent(new DeleteEventArgs<IUser>(user, false), this);
|
||||
@@ -312,13 +319,13 @@ namespace Umbraco.Core.Services
|
||||
return;
|
||||
}
|
||||
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateUserRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IUserRepository>();
|
||||
repository.AddOrUpdate(entity);
|
||||
try
|
||||
{
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
}
|
||||
catch (DbException ex)
|
||||
{
|
||||
@@ -348,15 +355,15 @@ namespace Umbraco.Core.Services
|
||||
return;
|
||||
}
|
||||
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateUserRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IUserRepository>();
|
||||
foreach (var member in entities)
|
||||
{
|
||||
repository.AddOrUpdate(member);
|
||||
}
|
||||
//commit the whole lot in one go
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
if (raiseEvents)
|
||||
@@ -374,9 +381,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns><see cref="IEnumerable{IUser}"/></returns>
|
||||
public IEnumerable<IUser> FindByEmail(string emailStringToMatch, int pageIndex, int pageSize, out int totalRecords, StringPropertyMatchType matchType = StringPropertyMatchType.StartsWith)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateUserRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IUserRepository>();
|
||||
var query = repository.Query;
|
||||
|
||||
switch (matchType)
|
||||
@@ -415,9 +422,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns><see cref="IEnumerable{IUser}"/></returns>
|
||||
public IEnumerable<IUser> FindByUsername(string login, int pageIndex, int pageSize, out int totalRecords, StringPropertyMatchType matchType = StringPropertyMatchType.StartsWith)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateUserRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IUserRepository>();
|
||||
var query = repository.Query;
|
||||
|
||||
switch (matchType)
|
||||
@@ -457,8 +464,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns><see cref="System.int"/> with number of Users for passed in type</returns>
|
||||
public int GetCount(MemberCountType countType)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateUserRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IUserRepository>();
|
||||
IQuery<IUser> query;
|
||||
|
||||
switch (countType)
|
||||
@@ -500,9 +508,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns><see cref="IEnumerable{IMember}"/></returns>
|
||||
public IEnumerable<IUser> GetAll(int pageIndex, int pageSize, out int totalRecords)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateUserRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IUserRepository>();
|
||||
return repository.GetPagedResultsByQuery(null, pageIndex, pageSize, out totalRecords, member => member.Username);
|
||||
}
|
||||
}
|
||||
@@ -540,8 +548,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns><see cref="IUser"/></returns>
|
||||
public IUser GetUserById(int id)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateUserRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IUserRepository>();
|
||||
return repository.Get(id);
|
||||
}
|
||||
}
|
||||
@@ -555,9 +564,9 @@ namespace Umbraco.Core.Services
|
||||
/// <param name="entityIds">Specify the nodes to replace permissions for. If nothing is specified all permissions are removed.</param>
|
||||
public void ReplaceUserPermissions(int userId, IEnumerable<char> permissions, params int[] entityIds)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateUserRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IUserRepository>();
|
||||
repository.ReplaceUserPermissions(userId, permissions, entityIds);
|
||||
}
|
||||
}
|
||||
@@ -570,9 +579,9 @@ namespace Umbraco.Core.Services
|
||||
/// <param name="entityIds">Specify the nodes to replace permissions for</param>
|
||||
public void AssignUserPermission(int userId, char permission, params int[] entityIds)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateUserRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IUserRepository>();
|
||||
repository.AssignUserPermission(userId, permission, entityIds);
|
||||
}
|
||||
}
|
||||
@@ -584,9 +593,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>An enumerable list of <see cref="IUserType"/></returns>
|
||||
public IEnumerable<IUserType> GetAllUserTypes(params int[] ids)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateUserTypeRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IUserTypeRepository>();
|
||||
return repository.GetAll(ids);
|
||||
}
|
||||
}
|
||||
@@ -598,8 +607,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns><see cref="IUserType"/></returns>
|
||||
public IUserType GetUserTypeByAlias(string alias)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateUserTypeRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IUserTypeRepository>();
|
||||
var query = repository.QueryFactory.Create<IUserType>().Where(x => x.Alias == alias);
|
||||
var contents = repository.GetByQuery(query);
|
||||
return contents.SingleOrDefault();
|
||||
@@ -613,8 +623,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns><see cref="IUserType"/></returns>
|
||||
public IUserType GetUserTypeById(int id)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateUserTypeRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IUserTypeRepository>();
|
||||
return repository.Get(id);
|
||||
}
|
||||
}
|
||||
@@ -626,8 +637,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns><see cref="IUserType"/></returns>
|
||||
public IUserType GetUserTypeByName(string name)
|
||||
{
|
||||
using (var repository = RepositoryFactory.CreateUserTypeRepository(UowProvider.GetUnitOfWork()))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IUserTypeRepository>();
|
||||
var query = repository.QueryFactory.Create<IUserType>().Where(x => x.Name == name);
|
||||
var contents = repository.GetByQuery(query);
|
||||
return contents.SingleOrDefault();
|
||||
@@ -648,11 +660,11 @@ namespace Umbraco.Core.Services
|
||||
return;
|
||||
}
|
||||
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateUserTypeRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IUserTypeRepository>();
|
||||
repository.AddOrUpdate(userType);
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
if (raiseEvents)
|
||||
@@ -668,11 +680,11 @@ namespace Umbraco.Core.Services
|
||||
if (DeletingUserType.IsRaisedEventCancelled(new DeleteEventArgs<IUserType>(userType), this))
|
||||
return;
|
||||
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateUserTypeRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IUserTypeRepository>();
|
||||
repository.Delete(userType);
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
DeletedUserType.RaiseEvent(new DeleteEventArgs<IUserType>(userType, false), this);
|
||||
@@ -685,9 +697,9 @@ namespace Umbraco.Core.Services
|
||||
/// <param name="sectionAlias">Alias of the section to remove</param>
|
||||
public void DeleteSectionFromAllUsers(string sectionAlias)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateUserRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IUserRepository>();
|
||||
var assignedUsers = repository.GetUsersAssignedToSection(sectionAlias);
|
||||
foreach (var user in assignedUsers)
|
||||
{
|
||||
@@ -695,7 +707,7 @@ namespace Umbraco.Core.Services
|
||||
user.RemoveAllowedSection(sectionAlias);
|
||||
repository.AddOrUpdate(user);
|
||||
}
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -707,9 +719,9 @@ namespace Umbraco.Core.Services
|
||||
/// <param name="userIds">Specifiying nothing will add the section to all user</param>
|
||||
public void AddSectionToAllUsers(string sectionAlias, params int[] userIds)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateUserRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IUserRepository>();
|
||||
IEnumerable<IUser> users;
|
||||
if (userIds.Any())
|
||||
{
|
||||
@@ -725,7 +737,7 @@ namespace Umbraco.Core.Services
|
||||
user.AddAllowedSection(sectionAlias);
|
||||
repository.AddOrUpdate(user);
|
||||
}
|
||||
uow.Commit();
|
||||
uow.Complete();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -738,9 +750,9 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>An enumerable list of <see cref="EntityPermission"/></returns>
|
||||
public IEnumerable<EntityPermission> GetPermissions(IUser user, params int[] nodeIds)
|
||||
{
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repository = RepositoryFactory.CreateUserRepository(uow))
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = uow.CreateRepository<IUserRepository>();
|
||||
var explicitPermissions = repository.GetUserPermissionsForEntities(user.Id, nodeIds);
|
||||
|
||||
//if no permissions are assigned to a particular node then we will fill in those permissions with the user's defaults
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using Umbraco.Core.Auditing;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Services;
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Umbraco.Core.Auditing;
|
||||
using Umbraco.Core.Events;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Services;
|
||||
|
||||
@@ -140,8 +140,8 @@
|
||||
<HintPath>..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="NPoco, Version=3.1.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NPoco.3.1.0-u005\lib\net45\NPoco.dll</HintPath>
|
||||
<Reference Include="NPoco, Version=3.3.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NPoco.3.3.0-beta3\lib\net45\NPoco.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Owin">
|
||||
@@ -192,8 +192,6 @@
|
||||
<Compile Include="AssemblyExtensions.cs" />
|
||||
<Compile Include="AsyncLock.cs" />
|
||||
<Compile Include="Attempt{T}.cs" />
|
||||
<Compile Include="Auditing\Audit.cs" />
|
||||
<Compile Include="Auditing\AuditTypes.cs" />
|
||||
<Compile Include="CacheHelper.cs" />
|
||||
<Compile Include="Cache\CacheKeys.cs" />
|
||||
<Compile Include="Cache\CacheProviderExtensions.cs" />
|
||||
@@ -334,6 +332,7 @@
|
||||
<Compile Include="DatabaseContext.cs" />
|
||||
<Compile Include="DataTableExtensions.cs" />
|
||||
<Compile Include="DateTimeExtensions.cs" />
|
||||
<Compile Include="DefaultScopeContextAdapter.cs" />
|
||||
<Compile Include="DelegateExtensions.cs" />
|
||||
<Compile Include="DependencyInjection\ConfigurationCompositionRoot.cs" />
|
||||
<Compile Include="DependencyInjection\CoreModelMappersCompositionRoot.cs" />
|
||||
@@ -385,6 +384,7 @@
|
||||
<Compile Include="IApplicationEventHandler.cs" />
|
||||
<Compile Include="IDisposeOnRequestEnd.cs" />
|
||||
<Compile Include="DependencyInjection\LightInjectExtensions.cs" />
|
||||
<Compile Include="IScopeContextAdapter.cs" />
|
||||
<Compile Include="ListExtensions.cs" />
|
||||
<Compile Include="Logging\AsyncForwardingAppenderBase.cs" />
|
||||
<Compile Include="Logging\LoggingEventContext.cs" />
|
||||
@@ -421,16 +421,12 @@
|
||||
<Compile Include="Models\PublishedContent\PublishedContentWithKeyWrapped.cs" />
|
||||
<Compile Include="Models\Rdbms\AccessDto.cs" />
|
||||
<Compile Include="ObjectResolution\ContainerSingleObjectResolver.cs" />
|
||||
<Compile Include="CallContextScope.cs" />
|
||||
<Compile Include="Persistence\Constants-DbProviderNames.cs" />
|
||||
<Compile Include="DefaultScopeContextFactory.cs" />
|
||||
<Compile Include="Persistence\FaultHandling\RetryDbConnection.cs">
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
<Compile Include="HttpContextScope.cs" />
|
||||
<Compile Include="IScopeContext.cs" />
|
||||
<Compile Include="IScopeContextFactory.cs" />
|
||||
<Compile Include="Persistence\IUmbracoDatabaseConfig.cs" />
|
||||
<Compile Include="Persistence\UnitOfWorkExtensions.cs" />
|
||||
<Compile Include="Persistence\Mappers\AuditItemMapper.cs" />
|
||||
<Compile Include="Persistence\Mappers\IMappingResolver.cs" />
|
||||
<Compile Include="Persistence\Migrations\IMigrationResolver.cs" />
|
||||
@@ -464,8 +460,6 @@
|
||||
<Compile Include="Persistence\Factories\PublicAccessEntryFactory.cs" />
|
||||
<Compile Include="Persistence\Factories\TaskFactory.cs" />
|
||||
<Compile Include="Persistence\Factories\TaskTypeFactory.cs" />
|
||||
<Compile Include="Persistence\LockedRepository.cs" />
|
||||
<Compile Include="Persistence\LockingRepository.cs" />
|
||||
<Compile Include="Persistence\Mappers\AccessMapper.cs" />
|
||||
<Compile Include="Persistence\Mappers\DomainMapper.cs" />
|
||||
<Compile Include="Persistence\Mappers\MigrationEntryMapper.cs" />
|
||||
@@ -514,17 +508,25 @@
|
||||
<Compile Include="Persistence\Repositories\EntityContainerRepository.cs" />
|
||||
<Compile Include="Persistence\Repositories\DomainRepository.cs" />
|
||||
<Compile Include="Persistence\Repositories\ExternalLoginRepository.cs" />
|
||||
<Compile Include="Persistence\Repositories\Interfaces\DataTypeContainerRepository.cs" />
|
||||
<Compile Include="Persistence\Repositories\Interfaces\DocumentTypeContainerRepository.cs" />
|
||||
<Compile Include="Persistence\Repositories\Interfaces\IDataTypeContainerRepository.cs" />
|
||||
<Compile Include="Persistence\Repositories\Interfaces\IDocumentTypeContainerRepository.cs" />
|
||||
<Compile Include="Persistence\Repositories\Interfaces\IEntityContainerRepository.cs" />
|
||||
<Compile Include="Persistence\Repositories\Interfaces\IMediaTypeContainerRepository.cs" />
|
||||
<Compile Include="Persistence\Repositories\Interfaces\INotificationsRepository.cs" />
|
||||
<Compile Include="Persistence\Repositories\Interfaces\IAuditRepository.cs" />
|
||||
<Compile Include="Persistence\Repositories\Interfaces\IContentTypeCompositionRepository.cs" />
|
||||
<Compile Include="Persistence\Repositories\Interfaces\IDomainRepository.cs" />
|
||||
<Compile Include="Persistence\Repositories\Interfaces\IExternalLoginRepository.cs" />
|
||||
<Compile Include="Persistence\Repositories\Interfaces\IMigrationEntryRepository.cs" />
|
||||
<Compile Include="Persistence\Repositories\Interfaces\IPartialViewMacroRepository.cs" />
|
||||
<Compile Include="Persistence\Repositories\Interfaces\IPublicAccessRepository.cs" />
|
||||
<Compile Include="Persistence\Repositories\Interfaces\IServerRegistrationRepository.cs" />
|
||||
<Compile Include="Persistence\Repositories\Interfaces\IDeleteMediaFilesRepository.cs" />
|
||||
<Compile Include="Persistence\Repositories\Interfaces\ITaskRepository.cs" />
|
||||
<Compile Include="Persistence\Repositories\Interfaces\ITaskTypeRepository.cs" />
|
||||
<Compile Include="Persistence\Repositories\Interfaces\MediaTypeContainerRepository.cs" />
|
||||
<Compile Include="Persistence\Repositories\MigrationEntryRepository.cs" />
|
||||
<Compile Include="Persistence\Repositories\PublicAccessRepository.cs" />
|
||||
<Compile Include="Persistence\Repositories\TaskRepository.cs" />
|
||||
@@ -532,6 +534,7 @@
|
||||
<Compile Include="Persistence\Repositories\TupleExtensions.cs" />
|
||||
<Compile Include="Persistence\SqlContext.cs" />
|
||||
<Compile Include="Persistence\NPocoSqlExtensions.cs" />
|
||||
<Compile Include="Persistence\UnitOfWork\UnitOfWorkBase.cs" />
|
||||
<Compile Include="PropertyEditors\DecimalValidator.cs" />
|
||||
<Compile Include="PropertyEditors\ValueConverters\GridValueConverter.cs" />
|
||||
<Compile Include="PropertyEditors\ValueConverters\DecimalValueConverter.cs" />
|
||||
@@ -652,10 +655,10 @@
|
||||
<Compile Include="Models\UmbracoEntityExtensions.cs" />
|
||||
<Compile Include="Packaging\IPackageExtraction.cs" />
|
||||
<Compile Include="Packaging\IPackageInstallation.cs" />
|
||||
<Compile Include="Packaging\Models\PreInstallWarnings.cs" />
|
||||
<Compile Include="Packaging\Models\InstallationSummary.cs" />
|
||||
<Compile Include="Packaging\Models\MetaData.cs" />
|
||||
<Compile Include="Packaging\Models\PackageAction.cs" />
|
||||
<Compile Include="Models\Packaging\PreInstallWarnings.cs" />
|
||||
<Compile Include="Models\Packaging\InstallationSummary.cs" />
|
||||
<Compile Include="Models\Packaging\MetaData.cs" />
|
||||
<Compile Include="Models\Packaging\PackageAction.cs" />
|
||||
<Compile Include="Packaging\PackageExtraction.cs" />
|
||||
<Compile Include="Packaging\PackageInstallation.cs" />
|
||||
<Compile Include="Packaging\PackageBinaryInspector.cs" />
|
||||
@@ -1094,7 +1097,6 @@
|
||||
<Compile Include="Persistence\SqlSyntax\SqlServerSyntaxProvider.cs" />
|
||||
<Compile Include="Persistence\SqlSyntax\SqlSyntaxProviderAttribute.cs" />
|
||||
<Compile Include="Persistence\SqlSyntax\SqlSyntaxProviderBase.cs" />
|
||||
<Compile Include="Persistence\TransactionType.cs" />
|
||||
<Compile Include="Persistence\UmbracoDatabase.cs" />
|
||||
<Compile Include="Persistence\UnitOfWork\FileUnitOfWork.cs" />
|
||||
<Compile Include="Persistence\UnitOfWork\FileUnitOfWorkProvider.cs" />
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
<package id="MiniProfiler" version="3.2.0.157" targetFramework="net461" />
|
||||
<package id="MySql.Data" version="6.9.8" targetFramework="net45" />
|
||||
<package id="Newtonsoft.Json" version="8.0.3" targetFramework="net461" />
|
||||
<package id="NPoco" version="3.1.0-u005" targetFramework="net461" />
|
||||
<package id="NPoco" version="3.3.0-beta3" targetFramework="net461" />
|
||||
<package id="Owin" version="1.0" targetFramework="net45" />
|
||||
<package id="semver" version="1.1.2" targetFramework="net461" />
|
||||
<package id="SharpZipLib" version="0.86.0" targetFramework="net4" />
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Models.Packaging;
|
||||
using Umbraco.Core.Packaging;
|
||||
using Umbraco.Core.Packaging.Models;
|
||||
using Umbraco.Core.Services;
|
||||
|
||||
namespace Umbraco.Tests.Packaging
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace Umbraco.Tests.Persistence
|
||||
_sqlCeSyntaxProvider = new SqlCeSyntaxProvider();
|
||||
_sqlSyntaxProviders = new[] { (ISqlSyntaxProvider) _sqlCeSyntaxProvider };
|
||||
_logger = Mock.Of<ILogger>();
|
||||
var dbFactory = new DefaultDatabaseFactory(Core.Configuration.GlobalSettings.UmbracoConnectionName, _sqlSyntaxProviders, _logger, new TestScopeContextFactory(), Mock.Of<IMappingResolver>());
|
||||
var dbFactory = new DefaultDatabaseFactory(Core.Configuration.GlobalSettings.UmbracoConnectionName, _sqlSyntaxProviders, _logger, new TestScopeContextAdapter(), Mock.Of<IMappingResolver>());
|
||||
_dbContext = new DatabaseContext(dbFactory, _logger);
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ namespace Umbraco.Tests.Persistence
|
||||
engine.CreateDatabase();
|
||||
|
||||
// re-create the database factory and database context with proper connection string
|
||||
var dbFactory = new DefaultDatabaseFactory(engine.LocalConnectionString, Constants.DbProviderNames.SqlCe, _sqlSyntaxProviders, _logger, new TestScopeContextFactory(), Mock.Of<IMappingResolver>());
|
||||
var dbFactory = new DefaultDatabaseFactory(engine.LocalConnectionString, Constants.DbProviderNames.SqlCe, _sqlSyntaxProviders, _logger, new TestScopeContextAdapter(), Mock.Of<IMappingResolver>());
|
||||
_dbContext = new DatabaseContext(dbFactory, _logger);
|
||||
|
||||
// create application context
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace Umbraco.Tests.Persistence.FaultHandling
|
||||
const string connectionString = @"server=.\SQLEXPRESS;database=EmptyForTest;user id=x;password=umbraco";
|
||||
const string providerName = Constants.DbProviderNames.SqlServer;
|
||||
var sqlSyntax = new[] { new SqlServerSyntaxProvider(new Lazy<IDatabaseFactory>(() => null)) };
|
||||
var factory = new DefaultDatabaseFactory(connectionString, providerName, sqlSyntax, Mock.Of<ILogger>(), new TestScopeContextFactory(), Mock.Of<IMappingResolver>());
|
||||
var factory = new DefaultDatabaseFactory(connectionString, providerName, sqlSyntax, Mock.Of<ILogger>(), new TestScopeContextAdapter(), Mock.Of<IMappingResolver>());
|
||||
var database = factory.GetDatabase();
|
||||
|
||||
//Act
|
||||
@@ -36,7 +36,7 @@ namespace Umbraco.Tests.Persistence.FaultHandling
|
||||
const string connectionString = @"server=.\SQLEXPRESS;database=EmptyForTest;user id=umbraco;password=umbraco";
|
||||
const string providerName = Constants.DbProviderNames.SqlServer;
|
||||
var sqlSyntax = new[] { new SqlServerSyntaxProvider(new Lazy<IDatabaseFactory>(() => null)) };
|
||||
var factory = new DefaultDatabaseFactory(connectionString, providerName, sqlSyntax, Mock.Of<ILogger>(), new TestScopeContextFactory(), Mock.Of<IMappingResolver>());
|
||||
var factory = new DefaultDatabaseFactory(connectionString, providerName, sqlSyntax, Mock.Of<ILogger>(), new TestScopeContextAdapter(), Mock.Of<IMappingResolver>());
|
||||
var database = factory.GetDatabase();
|
||||
|
||||
//Act
|
||||
|
||||
@@ -16,11 +16,11 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
public void Can_Add_Audit_Entry()
|
||||
{
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
using (var repo = new AuditRepository(unitOfWork, CacheHelper, Logger, MappingResolver))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
var repo = new AuditRepository(unitOfWork, CacheHelper, Logger, MappingResolver);
|
||||
repo.AddOrUpdate(new AuditItem(-1, "This is a System audit trail", AuditType.System, 0));
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Complete();
|
||||
}
|
||||
|
||||
var dtos = DatabaseContext.Database.Fetch<LogDto>("WHERE id > -1");
|
||||
|
||||
@@ -61,10 +61,11 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
public void Rebuild_Xml_Structures_With_Non_Latest_Version()
|
||||
{
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
ContentTypeRepository contentTypeRepository;
|
||||
using (var repository = CreateRepository(unitOfWork, out contentTypeRepository))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
ContentTypeRepository contentTypeRepository;
|
||||
var repository = CreateRepository(unitOfWork, out contentTypeRepository);
|
||||
|
||||
var contentType1 = MockedContentTypes.CreateSimpleContentType("Textpage1", "Textpage1");
|
||||
contentTypeRepository.AddOrUpdate(contentType1);
|
||||
|
||||
@@ -85,27 +86,29 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
repository.AddOrUpdate(c1);
|
||||
allCreated.Add(c1);
|
||||
}
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
|
||||
//now create some versions of this content - this shouldn't affect the xml structures saved
|
||||
for (int i = 0; i < allCreated.Count; i++)
|
||||
{
|
||||
allCreated[i].Name = "blah" + i;
|
||||
//IMPORTANT testing note here: We need to changed the published state here so that
|
||||
//IMPORTANT testing note here: We need to changed the published state here so that
|
||||
// it doesn't automatically think this is simply publishing again - this forces the latest
|
||||
// version to be Saved and not published
|
||||
allCreated[i].ChangePublishedState(PublishedState.Saved);
|
||||
repository.AddOrUpdate(allCreated[i]);
|
||||
}
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
|
||||
//delete all xml
|
||||
//delete all xml
|
||||
unitOfWork.Database.Execute("DELETE FROM cmsContentXml");
|
||||
Assert.AreEqual(0, unitOfWork.Database.ExecuteScalar<int>("SELECT COUNT(*) FROM cmsContentXml"));
|
||||
|
||||
repository.RebuildXmlStructures(media => new XElement("test"), 10);
|
||||
|
||||
Assert.AreEqual(100, unitOfWork.Database.ExecuteScalar<int>("SELECT COUNT(*) FROM cmsContentXml"));
|
||||
|
||||
unitOfWork.Complete();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,10 +116,10 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
public void Rebuild_All_Xml_Structures()
|
||||
{
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
ContentTypeRepository contentTypeRepository;
|
||||
using (var repository = CreateRepository(unitOfWork, out contentTypeRepository))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
ContentTypeRepository contentTypeRepository;
|
||||
var repository = CreateRepository(unitOfWork, out contentTypeRepository);
|
||||
|
||||
var contentType1 = MockedContentTypes.CreateSimpleContentType("Textpage1", "Textpage1");
|
||||
contentTypeRepository.AddOrUpdate(contentType1);
|
||||
@@ -136,7 +139,7 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
repository.AddOrUpdate(c1);
|
||||
allCreated.Add(c1);
|
||||
}
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
|
||||
//now create some versions of this content - this shouldn't affect the xml structures saved
|
||||
for (int i = 0; i < allCreated.Count; i++)
|
||||
@@ -144,15 +147,17 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
allCreated[i].Name = "blah" + i;
|
||||
repository.AddOrUpdate(allCreated[i]);
|
||||
}
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
|
||||
//delete all xml
|
||||
//delete all xml
|
||||
unitOfWork.Database.Execute("DELETE FROM cmsContentXml");
|
||||
Assert.AreEqual(0, unitOfWork.Database.ExecuteScalar<int>("SELECT COUNT(*) FROM cmsContentXml"));
|
||||
|
||||
repository.RebuildXmlStructures(media => new XElement("test"), 10);
|
||||
|
||||
Assert.AreEqual(100, unitOfWork.Database.ExecuteScalar<int>("SELECT COUNT(*) FROM cmsContentXml"));
|
||||
|
||||
unitOfWork.Complete();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,10 +165,10 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
public void Rebuild_All_Xml_Structures_For_Content_Type()
|
||||
{
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
ContentTypeRepository contentTypeRepository;
|
||||
using (var repository = CreateRepository(unitOfWork, out contentTypeRepository))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
ContentTypeRepository contentTypeRepository;
|
||||
var repository = CreateRepository(unitOfWork, out contentTypeRepository);
|
||||
var contentType1 = MockedContentTypes.CreateSimpleContentType("Textpage1", "Textpage1");
|
||||
var contentType2 = MockedContentTypes.CreateSimpleContentType("Textpage2", "Textpage2");
|
||||
var contentType3 = MockedContentTypes.CreateSimpleContentType("Textpage3", "Textpage3");
|
||||
@@ -201,7 +206,7 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
repository.AddOrUpdate(c1);
|
||||
allCreated.Add(c1);
|
||||
}
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
|
||||
//now create some versions of this content - this shouldn't affect the xml structures saved
|
||||
for (int i = 0; i < allCreated.Count; i++)
|
||||
@@ -209,15 +214,17 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
allCreated[i].Name = "blah" + i;
|
||||
repository.AddOrUpdate(allCreated[i]);
|
||||
}
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
|
||||
//delete all xml
|
||||
//delete all xml
|
||||
unitOfWork.Database.Execute("DELETE FROM cmsContentXml");
|
||||
Assert.AreEqual(0, unitOfWork.Database.ExecuteScalar<int>("SELECT COUNT(*) FROM cmsContentXml"));
|
||||
|
||||
repository.RebuildXmlStructures(media => new XElement("test"), 10, contentTypeIds: new[] { contentType1.Id, contentType2.Id });
|
||||
|
||||
Assert.AreEqual(60, unitOfWork.Database.ExecuteScalar<int>("SELECT COUNT(*) FROM cmsContentXml"));
|
||||
|
||||
unitOfWork.Complete();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -226,11 +233,10 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
// Arrange
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
|
||||
ContentTypeRepository contentTypeRepository;
|
||||
using (var repository = CreateRepository(unitOfWork, out contentTypeRepository))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
ContentTypeRepository contentTypeRepository;
|
||||
var repository = CreateRepository(unitOfWork, out contentTypeRepository);
|
||||
var contentType = MockedContentTypes.CreateSimpleContentType("umbTextpage1", "Textpage");
|
||||
contentType.AllowedContentTypes = new List<ContentTypeSort>
|
||||
{
|
||||
@@ -239,20 +245,21 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
var parentPage = MockedContent.CreateSimpleContent(contentType);
|
||||
contentTypeRepository.AddOrUpdate(contentType);
|
||||
repository.AddOrUpdate(parentPage);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
|
||||
// Act
|
||||
repository.AssignEntityPermission(parentPage, 'A', new int[] { 0 });
|
||||
var childPage = MockedContent.CreateSimpleContent(contentType, "child", parentPage);
|
||||
repository.AddOrUpdate(childPage);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
|
||||
// Assert
|
||||
var permissions = repository.GetPermissionsForEntity(childPage.Id);
|
||||
Assert.AreEqual(1, permissions.Count());
|
||||
Assert.AreEqual("A", permissions.Single().AssignedPermissions.First());
|
||||
}
|
||||
|
||||
unitOfWork.Complete();
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -260,17 +267,17 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
// Arrange
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
ContentTypeRepository contentTypeRepository;
|
||||
using (var repository = CreateRepository(unitOfWork, out contentTypeRepository))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
ContentTypeRepository contentTypeRepository;
|
||||
var repository = CreateRepository(unitOfWork, out contentTypeRepository);
|
||||
ContentType contentType = MockedContentTypes.CreateSimpleContentType("umbTextpage2", "Textpage");
|
||||
Content textpage = MockedContent.CreateSimpleContent(contentType);
|
||||
|
||||
// Act
|
||||
contentTypeRepository.AddOrUpdate(contentType);
|
||||
repository.AddOrUpdate(textpage);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Complete();
|
||||
|
||||
// Assert
|
||||
Assert.That(contentType.HasIdentity, Is.True);
|
||||
@@ -284,14 +291,15 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
// Arrange
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
ContentTypeRepository contentTypeRepository;
|
||||
TemplateRepository templateRepository;
|
||||
using (var repository = CreateRepository(unitOfWork, out contentTypeRepository, out templateRepository))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
ContentTypeRepository contentTypeRepository;
|
||||
TemplateRepository templateRepository;
|
||||
var repository = CreateRepository(unitOfWork, out contentTypeRepository, out templateRepository);
|
||||
|
||||
var template = new Template("hello", "hello");
|
||||
templateRepository.AddOrUpdate(template);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
|
||||
ContentType contentType = MockedContentTypes.CreateSimpleContentType("umbTextpage2", "Textpage");
|
||||
contentType.AllowedTemplates = Enumerable.Empty<ITemplate>(); // because CreateSimple... assigns one
|
||||
@@ -302,11 +310,13 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
|
||||
contentTypeRepository.AddOrUpdate(contentType);
|
||||
repository.AddOrUpdate(textpage);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
|
||||
// Assert
|
||||
Assert.That(textpage.Template, Is.Not.Null);
|
||||
Assert.That(textpage.Template, Is.EqualTo(contentType.DefaultTemplate));
|
||||
|
||||
unitOfWork.Complete();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -316,13 +326,13 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
// Arrange
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
ContentTypeRepository contentTypeRepository;
|
||||
using (var repository = CreateRepository(unitOfWork, out contentTypeRepository))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
ContentTypeRepository contentTypeRepository;
|
||||
var repository = CreateRepository(unitOfWork, out contentTypeRepository);
|
||||
var contentType = MockedContentTypes.CreateSimpleContentType("umbTextpage1", "Textpage");
|
||||
contentTypeRepository.AddOrUpdate(contentType);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
|
||||
var textpage = MockedContent.CreateSimpleContent(contentType, "test@umbraco.org", -1);
|
||||
var anotherTextpage = MockedContent.CreateSimpleContent(contentType, "@lightgiants", -1);
|
||||
@@ -331,7 +341,7 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
|
||||
repository.AddOrUpdate(textpage);
|
||||
repository.AddOrUpdate(anotherTextpage);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
|
||||
// Assert
|
||||
Assert.That(contentType.HasIdentity, Is.True);
|
||||
@@ -342,6 +352,8 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
|
||||
var content2 = repository.Get(anotherTextpage.Id);
|
||||
Assert.That(content2.Name, Is.EqualTo(anotherTextpage.Name));
|
||||
|
||||
unitOfWork.Complete();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -350,21 +362,21 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
// Arrange
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
ContentTypeRepository contentTypeRepository;
|
||||
using (var repository = CreateRepository(unitOfWork, out contentTypeRepository))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
ContentTypeRepository contentTypeRepository;
|
||||
var repository = CreateRepository(unitOfWork, out contentTypeRepository);
|
||||
ContentType contentType = MockedContentTypes.CreateSimpleContentType("umbTextpage1", "Textpage");
|
||||
Content textpage = MockedContent.CreateSimpleContent(contentType);
|
||||
|
||||
// Act
|
||||
contentTypeRepository.AddOrUpdate(contentType);
|
||||
repository.AddOrUpdate(textpage);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
|
||||
Content subpage = MockedContent.CreateSimpleContent(contentType, "Text Page 1", textpage.Id);
|
||||
repository.AddOrUpdate(subpage);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
|
||||
// Assert
|
||||
Assert.That(contentType.HasIdentity, Is.True);
|
||||
@@ -381,10 +393,10 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
// Arrange
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
ContentTypeRepository contentTypeRepository;
|
||||
using (var repository = CreateRepository(unitOfWork, out contentTypeRepository))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
ContentTypeRepository contentTypeRepository;
|
||||
var repository = CreateRepository(unitOfWork, out contentTypeRepository);
|
||||
// Act
|
||||
var content = repository.Get(NodeDto.NodeIdSeed + 3);
|
||||
bool dirty = ((Content)content).IsDirty();
|
||||
@@ -399,15 +411,15 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
// Arrange
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
ContentTypeRepository contentTypeRepository;
|
||||
using (var repository = CreateRepository(unitOfWork, out contentTypeRepository))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
ContentTypeRepository contentTypeRepository;
|
||||
var repository = CreateRepository(unitOfWork, out contentTypeRepository);
|
||||
// Act
|
||||
var content = repository.Get(NodeDto.NodeIdSeed + 2);
|
||||
content.Name = "About 2";
|
||||
repository.AddOrUpdate(content);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
var updatedContent = repository.Get(NodeDto.NodeIdSeed + 2);
|
||||
|
||||
// Assert
|
||||
@@ -422,15 +434,15 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
// Arrange
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
ContentTypeRepository contentTypeRepository;
|
||||
using (var repository = CreateRepository(unitOfWork, out contentTypeRepository))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
ContentTypeRepository contentTypeRepository;
|
||||
var repository = CreateRepository(unitOfWork, out contentTypeRepository);
|
||||
// Act
|
||||
var content = repository.Get(NodeDto.NodeIdSeed + 2);
|
||||
content.Template = null;
|
||||
repository.AddOrUpdate(content);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
var updatedContent = repository.Get(NodeDto.NodeIdSeed + 2);
|
||||
|
||||
// Assert
|
||||
@@ -444,10 +456,10 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
// Arrange
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
ContentTypeRepository contentTypeRepository;
|
||||
using (var repository = CreateRepository(unitOfWork, out contentTypeRepository))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
ContentTypeRepository contentTypeRepository;
|
||||
var repository = CreateRepository(unitOfWork, out contentTypeRepository);
|
||||
var contentType = contentTypeRepository.Get(NodeDto.NodeIdSeed);
|
||||
var content = new Content("Textpage 2 Child Node", NodeDto.NodeIdSeed + 3, contentType);
|
||||
content.CreatorId = 0;
|
||||
@@ -455,11 +467,11 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
|
||||
// Act
|
||||
repository.AddOrUpdate(content);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
var id = content.Id;
|
||||
|
||||
repository.Delete(content);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
|
||||
var content1 = repository.Get(id);
|
||||
|
||||
@@ -473,10 +485,10 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
// Arrange
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
ContentTypeRepository contentTypeRepository;
|
||||
using (var repository = CreateRepository(unitOfWork, out contentTypeRepository))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
ContentTypeRepository contentTypeRepository;
|
||||
var repository = CreateRepository(unitOfWork, out contentTypeRepository);
|
||||
// Act
|
||||
var content = repository.Get(NodeDto.NodeIdSeed + 3);
|
||||
|
||||
@@ -499,10 +511,10 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
// Arrange
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
ContentTypeRepository contentTypeRepository;
|
||||
using (var repository = CreateRepository(unitOfWork, out contentTypeRepository))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
ContentTypeRepository contentTypeRepository;
|
||||
var repository = CreateRepository(unitOfWork, out contentTypeRepository);
|
||||
// Act
|
||||
var query = repository.Query.Where(x => x.Level == 2);
|
||||
var result = repository.GetByQuery(query);
|
||||
@@ -517,23 +529,23 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
// Arrange
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
ContentTypeRepository contentTypeRepository;
|
||||
using (var repository = CreateRepository(unitOfWork, out contentTypeRepository))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
ContentTypeRepository contentTypeRepository;
|
||||
var repository = CreateRepository(unitOfWork, out contentTypeRepository);
|
||||
var result = repository.GetAll().ToArray();
|
||||
foreach (var content in result)
|
||||
{
|
||||
content.ChangePublishedState(PublishedState.Saved);
|
||||
repository.AddOrUpdate(content);
|
||||
}
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
foreach (var content in result)
|
||||
{
|
||||
content.ChangePublishedState(PublishedState.Published);
|
||||
repository.AddOrUpdate(content);
|
||||
}
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
|
||||
//re-get
|
||||
|
||||
@@ -562,16 +574,16 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
// Arrange
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
ContentTypeRepository contentTypeRepository;
|
||||
using (var repository = CreateRepository(unitOfWork, out contentTypeRepository))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
ContentTypeRepository contentTypeRepository;
|
||||
var repository = CreateRepository(unitOfWork, out contentTypeRepository);
|
||||
// Act
|
||||
var query = repository.Query.Where(x => x.Name.Contains("Text"));
|
||||
long totalRecords;
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
{
|
||||
DatabaseContext.Database.EnableSqlTrace = true;
|
||||
DatabaseContext.Database.EnableSqlCount();
|
||||
|
||||
@@ -581,14 +593,14 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
Assert.AreEqual(2, result.Count());
|
||||
|
||||
result = repository.GetPagedResultsByQuery(query, 1, 2, out totalRecords, "title", Direction.Ascending, false);
|
||||
|
||||
|
||||
Assert.AreEqual(1, result.Count());
|
||||
}
|
||||
finally
|
||||
{
|
||||
{
|
||||
DatabaseContext.Database.EnableSqlTrace = false;
|
||||
DatabaseContext.Database.DisableSqlCount();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -597,10 +609,10 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
// Arrange
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
ContentTypeRepository contentTypeRepository;
|
||||
using (var repository = CreateRepository(unitOfWork, out contentTypeRepository))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
ContentTypeRepository contentTypeRepository;
|
||||
var repository = CreateRepository(unitOfWork, out contentTypeRepository);
|
||||
// Act
|
||||
var query = repository.Query.Where(x => x.Level == 2);
|
||||
long totalRecords;
|
||||
@@ -629,10 +641,10 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
// Arrange
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
ContentTypeRepository contentTypeRepository;
|
||||
using (var repository = CreateRepository(unitOfWork, out contentTypeRepository))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
ContentTypeRepository contentTypeRepository;
|
||||
var repository = CreateRepository(unitOfWork, out contentTypeRepository);
|
||||
// Act
|
||||
var query = repository.Query.Where(x => x.Level == 2);
|
||||
long totalRecords;
|
||||
@@ -650,10 +662,10 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
// Arrange
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
ContentTypeRepository contentTypeRepository;
|
||||
using (var repository = CreateRepository(unitOfWork, out contentTypeRepository))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
ContentTypeRepository contentTypeRepository;
|
||||
var repository = CreateRepository(unitOfWork, out contentTypeRepository);
|
||||
// Act
|
||||
var query = repository.Query.Where(x => x.Level == 2);
|
||||
long totalRecords;
|
||||
@@ -671,10 +683,10 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
// Arrange
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
ContentTypeRepository contentTypeRepository;
|
||||
using (var repository = CreateRepository(unitOfWork, out contentTypeRepository))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
ContentTypeRepository contentTypeRepository;
|
||||
var repository = CreateRepository(unitOfWork, out contentTypeRepository);
|
||||
// Act
|
||||
var query = repository.Query.Where(x => x.Level == 2);
|
||||
long totalRecords;
|
||||
@@ -692,10 +704,10 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
// Arrange
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
ContentTypeRepository contentTypeRepository;
|
||||
using (var repository = CreateRepository(unitOfWork, out contentTypeRepository))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
ContentTypeRepository contentTypeRepository;
|
||||
var repository = CreateRepository(unitOfWork, out contentTypeRepository);
|
||||
// Act
|
||||
var query = repository.Query.Where(x => x.Level == 2);
|
||||
long totalRecords;
|
||||
@@ -716,10 +728,10 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
// Arrange
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
ContentTypeRepository contentTypeRepository;
|
||||
using (var repository = CreateRepository(unitOfWork, out contentTypeRepository))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
ContentTypeRepository contentTypeRepository;
|
||||
var repository = CreateRepository(unitOfWork, out contentTypeRepository);
|
||||
// Act
|
||||
var query = repository.Query.Where(x => x.Level == 2);
|
||||
long totalRecords;
|
||||
@@ -740,10 +752,10 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
// Arrange
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
ContentTypeRepository contentTypeRepository;
|
||||
using (var repository = CreateRepository(unitOfWork, out contentTypeRepository))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
ContentTypeRepository contentTypeRepository;
|
||||
var repository = CreateRepository(unitOfWork, out contentTypeRepository);
|
||||
// Act
|
||||
var contents = repository.GetAll(NodeDto.NodeIdSeed + 2, NodeDto.NodeIdSeed + 3);
|
||||
|
||||
@@ -759,10 +771,10 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
// Arrange
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
ContentTypeRepository contentTypeRepository;
|
||||
using (var repository = CreateRepository(unitOfWork, out contentTypeRepository))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
ContentTypeRepository contentTypeRepository;
|
||||
var repository = CreateRepository(unitOfWork, out contentTypeRepository);
|
||||
// Act
|
||||
var contents = repository.GetAll();
|
||||
|
||||
@@ -780,10 +792,10 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
// Arrange
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
ContentTypeRepository contentTypeRepository;
|
||||
using (var repository = CreateRepository(unitOfWork, out contentTypeRepository))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
ContentTypeRepository contentTypeRepository;
|
||||
var repository = CreateRepository(unitOfWork, out contentTypeRepository);
|
||||
// Act
|
||||
var exists = repository.Exists(NodeDto.NodeIdSeed + 1);
|
||||
|
||||
@@ -799,10 +811,10 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
// Arrange
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
ContentTypeRepository contentTypeRepository;
|
||||
using (var repository = CreateRepository(unitOfWork, out contentTypeRepository))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
ContentTypeRepository contentTypeRepository;
|
||||
var repository = CreateRepository(unitOfWork, out contentTypeRepository);
|
||||
// Act
|
||||
int level = 2;
|
||||
var query = repository.Query.Where(x => x.Level == level);
|
||||
@@ -818,10 +830,10 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
// Arrange
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
ContentTypeRepository contentTypeRepository;
|
||||
using (var repository = CreateRepository(unitOfWork, out contentTypeRepository))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
ContentTypeRepository contentTypeRepository;
|
||||
var repository = CreateRepository(unitOfWork, out contentTypeRepository);
|
||||
// Act
|
||||
var textpage = repository.Get(NodeDto.NodeIdSeed + 1);
|
||||
var subpage = repository.Get(NodeDto.NodeIdSeed + 2);
|
||||
@@ -839,10 +851,10 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
// Arrange
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
ContentTypeRepository contentTypeRepository;
|
||||
using (var repository = CreateRepository(unitOfWork, out contentTypeRepository))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
ContentTypeRepository contentTypeRepository;
|
||||
var repository = CreateRepository(unitOfWork, out contentTypeRepository);
|
||||
// Act
|
||||
var query = repository.Query.Where(x => x.Key == new Guid("B58B3AD4-62C2-4E27-B1BE-837BD7C533E0"));
|
||||
var content = repository.GetByQuery(query).SingleOrDefault();
|
||||
|
||||
@@ -76,10 +76,10 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
// Arrange
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
using (var templateRepo = new TemplateRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Logger, Mock.Of<IFileSystem>(), Mock.Of<IFileSystem>(), Mock.Of<ITemplatesSection>(), MappingResolver))
|
||||
using (var repository = CreateRepository(unitOfWork))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
var templateRepo = new TemplateRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Logger, Mock.Of<IFileSystem>(), Mock.Of<IFileSystem>(), Mock.Of<ITemplatesSection>(), MappingResolver);
|
||||
var repository = CreateRepository(unitOfWork);
|
||||
var templates = new[]
|
||||
{
|
||||
new Template("test1", "test1"),
|
||||
@@ -90,13 +90,13 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
templateRepo.AddOrUpdate(template);
|
||||
}
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
|
||||
var contentType = MockedContentTypes.CreateSimpleContentType();
|
||||
contentType.AllowedTemplates = new[] {templates[0], templates[1]};
|
||||
contentType.AllowedTemplates = new[] { templates[0], templates[1] };
|
||||
contentType.SetDefaultTemplate(templates[0]);
|
||||
repository.AddOrUpdate(contentType);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
|
||||
//re-get
|
||||
var result = repository.Get(contentType.Id);
|
||||
@@ -111,22 +111,22 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
public void Can_Move()
|
||||
{
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
using (var containerRepository = CreateContainerRepository(unitOfWork, Constants.ObjectTypes.DocumentTypeContainerGuid))
|
||||
using (var repository = CreateRepository(unitOfWork))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
var containerRepository = CreateContainerRepository(unitOfWork, Constants.ObjectTypes.DocumentTypeContainerGuid);
|
||||
var repository = CreateRepository(unitOfWork);
|
||||
var container1 = new EntityContainer(Constants.ObjectTypes.DocumentTypeGuid) { Name = "blah1" };
|
||||
containerRepository.AddOrUpdate(container1);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
|
||||
var container2 = new EntityContainer(Constants.ObjectTypes.DocumentTypeGuid) { Name = "blah2", ParentId = container1.Id };
|
||||
containerRepository.AddOrUpdate(container2);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
|
||||
var contentType = (IContentType) MockedContentTypes.CreateBasicContentType("asdfasdf");
|
||||
var contentType = (IContentType)MockedContentTypes.CreateBasicContentType("asdfasdf");
|
||||
contentType.ParentId = container2.Id;
|
||||
repository.AddOrUpdate(contentType);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
|
||||
//create a
|
||||
var contentType2 = (IContentType)new ContentType(contentType, "hello")
|
||||
@@ -135,10 +135,10 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
};
|
||||
contentType.ParentId = contentType.Id;
|
||||
repository.AddOrUpdate(contentType2);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
|
||||
var result = repository.Move(contentType, container1).ToArray();
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
|
||||
Assert.AreEqual(2, result.Count());
|
||||
|
||||
@@ -157,17 +157,14 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
public void Can_Create_Container()
|
||||
{
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
EntityContainer container;
|
||||
using (var containerRepository = CreateContainerRepository(unitOfWork, Constants.ObjectTypes.DocumentTypeContainerGuid))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
container = new EntityContainer(Constants.ObjectTypes.DocumentTypeGuid) { Name = "blah" };
|
||||
var containerRepository = CreateContainerRepository(unitOfWork, Constants.ObjectTypes.DocumentTypeContainerGuid);
|
||||
var container = new EntityContainer(Constants.ObjectTypes.DocumentTypeGuid) { Name = "blah" };
|
||||
containerRepository.AddOrUpdate(container);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
Assert.That(container.Id, Is.GreaterThan(0));
|
||||
}
|
||||
using (var containerRepository = CreateContainerRepository(unitOfWork, Constants.ObjectTypes.DocumentTypeContainerGuid))
|
||||
{
|
||||
|
||||
var found = containerRepository.Get(container.Id);
|
||||
Assert.IsNotNull(found);
|
||||
}
|
||||
@@ -177,22 +174,17 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
public void Can_Delete_Container()
|
||||
{
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
EntityContainer container;
|
||||
using (var containerRepository = CreateContainerRepository(unitOfWork, Constants.ObjectTypes.DocumentTypeContainerGuid))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
container = new EntityContainer(Constants.ObjectTypes.DocumentTypeGuid) { Name = "blah" };
|
||||
var containerRepository = CreateContainerRepository(unitOfWork, Constants.ObjectTypes.DocumentTypeContainerGuid);
|
||||
var container = new EntityContainer(Constants.ObjectTypes.DocumentTypeGuid) { Name = "blah" };
|
||||
containerRepository.AddOrUpdate(container);
|
||||
unitOfWork.Commit();
|
||||
}
|
||||
using (var containerRepository = CreateContainerRepository(unitOfWork, Constants.ObjectTypes.DocumentTypeContainerGuid))
|
||||
{
|
||||
unitOfWork.Flush();
|
||||
|
||||
// Act
|
||||
containerRepository.Delete(container);
|
||||
unitOfWork.Commit();
|
||||
}
|
||||
using (var containerRepository = CreateContainerRepository(unitOfWork, Constants.ObjectTypes.DocumentTypeContainerGuid))
|
||||
{
|
||||
unitOfWork.Flush();
|
||||
|
||||
var found = containerRepository.Get(container.Id);
|
||||
Assert.IsNull(found);
|
||||
}
|
||||
@@ -202,18 +194,18 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
public void Can_Create_Container_Containing_Media_Types()
|
||||
{
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
using (var containerRepository = CreateContainerRepository(unitOfWork, Constants.ObjectTypes.MediaTypeContainerGuid))
|
||||
using (var repository = CreateRepository(unitOfWork))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
var containerRepository = CreateContainerRepository(unitOfWork, Constants.ObjectTypes.MediaTypeContainerGuid);
|
||||
var repository = CreateRepository(unitOfWork);
|
||||
var container = new EntityContainer(Constants.ObjectTypes.MediaTypeGuid) { Name = "blah" };
|
||||
containerRepository.AddOrUpdate(container);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
|
||||
var contentType = MockedContentTypes.CreateSimpleContentType("test", "Test", propertyGroupName: "testGroup");
|
||||
contentType.ParentId = container.Id;
|
||||
repository.AddOrUpdate(contentType);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
|
||||
Assert.AreEqual(container.Id, contentType.ParentId);
|
||||
}
|
||||
@@ -223,27 +215,22 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
public void Can_Delete_Container_Containing_Media_Types()
|
||||
{
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
EntityContainer container;
|
||||
IMediaType contentType;
|
||||
using (var containerRepository = CreateContainerRepository(unitOfWork, Constants.ObjectTypes.MediaTypeContainerGuid))
|
||||
using (var repository = CreateMediaTypeRepository(unitOfWork))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
container = new EntityContainer(Constants.ObjectTypes.MediaTypeGuid) { Name = "blah" };
|
||||
var containerRepository = CreateContainerRepository(unitOfWork, Constants.ObjectTypes.MediaTypeContainerGuid);
|
||||
var repository = CreateMediaTypeRepository(unitOfWork);
|
||||
var container = new EntityContainer(Constants.ObjectTypes.MediaTypeGuid) { Name = "blah" };
|
||||
containerRepository.AddOrUpdate(container);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
|
||||
contentType = MockedContentTypes.CreateSimpleMediaType("test", "Test", propertyGroupName: "testGroup");
|
||||
IMediaType contentType = MockedContentTypes.CreateSimpleMediaType("test", "Test", propertyGroupName: "testGroup");
|
||||
contentType.ParentId = container.Id;
|
||||
repository.AddOrUpdate(contentType);
|
||||
unitOfWork.Commit();
|
||||
}
|
||||
using (var containerRepository = CreateContainerRepository(unitOfWork, Constants.ObjectTypes.MediaTypeContainerGuid))
|
||||
using (var repository = CreateMediaTypeRepository(unitOfWork))
|
||||
{
|
||||
unitOfWork.Flush();
|
||||
|
||||
// Act
|
||||
containerRepository.Delete(container);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
|
||||
var found = containerRepository.Get(container.Id);
|
||||
Assert.IsNull(found);
|
||||
@@ -259,13 +246,13 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
// Arrange
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
using (var repository = CreateRepository(unitOfWork))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = CreateRepository(unitOfWork);
|
||||
// Act
|
||||
var contentType = MockedContentTypes.CreateSimpleContentType("test", "Test", propertyGroupName: "testGroup");
|
||||
repository.AddOrUpdate(contentType);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
|
||||
// Assert
|
||||
Assert.That(contentType.HasIdentity, Is.True);
|
||||
@@ -290,9 +277,9 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
// Arrange
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
using (var repository = CreateRepository(unitOfWork))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = CreateRepository(unitOfWork);
|
||||
// Act
|
||||
var contentType = (IContentType)MockedContentTypes.CreateSimpleContentType2("test", "Test", propertyGroupName: "testGroup");
|
||||
|
||||
@@ -307,7 +294,7 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
Assert.AreEqual(4, mapped.PropertyTypes.Count());
|
||||
|
||||
repository.AddOrUpdate(mapped);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
|
||||
Assert.AreEqual(4, mapped.PropertyTypes.Count());
|
||||
|
||||
@@ -339,14 +326,14 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
// Arrange
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
using (var repository = CreateRepository(unitOfWork))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = CreateRepository(unitOfWork);
|
||||
// Act
|
||||
var contentType = repository.Get(NodeDto.NodeIdSeed + 1);
|
||||
|
||||
contentType.Thumbnail = "Doc2.png";
|
||||
contentType.PropertyGroups["Content"].PropertyTypes.Add(new PropertyType("test", DataTypeDatabaseType.Ntext, "subtitle")
|
||||
contentType.PropertyGroups["Content"].PropertyTypes.Add(new PropertyType("test", DataTypeDatabaseType.Ntext, "subtitle")
|
||||
{
|
||||
Name = "Subtitle",
|
||||
Description = "Optional Subtitle",
|
||||
@@ -355,7 +342,7 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
DataTypeDefinitionId = -88
|
||||
});
|
||||
repository.AddOrUpdate(contentType);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
|
||||
var dirty = ((ICanBeDirty)contentType).IsDirty();
|
||||
|
||||
@@ -415,9 +402,9 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
// Arrange
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
using (var repository = CreateRepository(unitOfWork))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = CreateRepository(unitOfWork);
|
||||
// Act
|
||||
var contentType = repository.Get(NodeDto.NodeIdSeed + 1);
|
||||
|
||||
@@ -453,7 +440,7 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
Assert.IsTrue(mapped.PropertyTypes.Any(x => x.Alias == "subtitle"));
|
||||
|
||||
repository.AddOrUpdate(mapped);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
|
||||
var dirty = mapped.IsDirty();
|
||||
|
||||
@@ -478,17 +465,17 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
// Arrange
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
using (var repository = CreateRepository(unitOfWork))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = CreateRepository(unitOfWork);
|
||||
// Act
|
||||
var contentType = MockedContentTypes.CreateSimpleContentType();
|
||||
repository.AddOrUpdate(contentType);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
|
||||
var contentType2 = repository.Get(contentType.Id);
|
||||
repository.Delete(contentType2);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
|
||||
var exists = repository.Exists(contentType.Id);
|
||||
|
||||
@@ -502,9 +489,9 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
// Arrange
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
using (var repository = CreateRepository(unitOfWork))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = CreateRepository(unitOfWork);
|
||||
var ctMain = MockedContentTypes.CreateSimpleContentType();
|
||||
var ctChild1 = MockedContentTypes.CreateSimpleContentType("child1", "Child 1", ctMain, true);
|
||||
var ctChild2 = MockedContentTypes.CreateSimpleContentType("child2", "Child 2", ctChild1, true);
|
||||
@@ -512,13 +499,13 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
repository.AddOrUpdate(ctMain);
|
||||
repository.AddOrUpdate(ctChild1);
|
||||
repository.AddOrUpdate(ctChild2);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
|
||||
// Act
|
||||
|
||||
var resolvedParent = repository.Get(ctMain.Id);
|
||||
repository.Delete(resolvedParent);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
|
||||
// Assert
|
||||
Assert.That(repository.Exists(ctMain.Id), Is.False);
|
||||
@@ -532,9 +519,9 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
// Arrange
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
using (var repository = CreateRepository(unitOfWork))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = CreateRepository(unitOfWork);
|
||||
var contentType = repository.Get(NodeDto.NodeIdSeed + 1);
|
||||
var child1 = MockedContentTypes.CreateSimpleContentType("aabc", "aabc", contentType, randomizeAliases: true);
|
||||
repository.AddOrUpdate(child1);
|
||||
@@ -542,7 +529,7 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
repository.AddOrUpdate(child3);
|
||||
var child2 = MockedContentTypes.CreateSimpleContentType("a123", "a123", contentType, randomizeAliases: true);
|
||||
repository.AddOrUpdate(child2);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
|
||||
// Act
|
||||
var contentTypes = repository.GetByQuery(repository.Query.Where(x => x.ParentId == contentType.Id));
|
||||
@@ -561,9 +548,9 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
// Arrange
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
using (var repository = CreateRepository(unitOfWork))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = CreateRepository(unitOfWork);
|
||||
|
||||
// Act
|
||||
var contentType = repository.Get(NodeDto.NodeIdSeed + 1);
|
||||
@@ -579,13 +566,13 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
// Arrange
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
using (var repository = CreateRepository(unitOfWork))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = CreateRepository(unitOfWork);
|
||||
var contentType = repository.Get(NodeDto.NodeIdSeed + 1);
|
||||
var childContentType = MockedContentTypes.CreateSimpleContentType("blah", "Blah", contentType, randomizeAliases:true);
|
||||
repository.AddOrUpdate(childContentType);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
|
||||
// Act
|
||||
var result = repository.Get(childContentType.Key);
|
||||
@@ -601,9 +588,9 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
// Arrange
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
using (var repository = CreateRepository(unitOfWork))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = CreateRepository(unitOfWork);
|
||||
// Act
|
||||
var result = repository.Get(Guid.NewGuid());
|
||||
|
||||
@@ -617,9 +604,9 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
// Arrange
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
using (var repository = CreateRepository(unitOfWork))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = CreateRepository(unitOfWork);
|
||||
|
||||
// Act
|
||||
var contentTypes = repository.GetAll();
|
||||
@@ -639,9 +626,9 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
// Arrange
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
using (var repository = CreateRepository(unitOfWork))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = CreateRepository(unitOfWork);
|
||||
var allGuidIds = repository.GetAll().Select(x => x.Key).ToArray();
|
||||
|
||||
// Act
|
||||
@@ -662,9 +649,9 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
// Arrange
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
using (var repository = CreateRepository(unitOfWork))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = CreateRepository(unitOfWork);
|
||||
|
||||
// Act
|
||||
var exists = repository.Exists(NodeDto.NodeIdSeed);
|
||||
@@ -679,15 +666,15 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
// Arrange
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
using (var repository = CreateRepository(unitOfWork))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = CreateRepository(unitOfWork);
|
||||
var contentType = repository.Get(NodeDto.NodeIdSeed + 1);
|
||||
|
||||
// Act
|
||||
contentType.PropertyGroups["Meta"].PropertyTypes.Remove("description");
|
||||
repository.AddOrUpdate(contentType);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
|
||||
var result = repository.Get(NodeDto.NodeIdSeed + 1);
|
||||
|
||||
@@ -703,9 +690,9 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
// Arrange
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
using (var repository = CreateRepository(unitOfWork))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = CreateRepository(unitOfWork);
|
||||
|
||||
// Act
|
||||
var contentType = repository.Get(NodeDto.NodeIdSeed);
|
||||
@@ -721,9 +708,9 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
// Arrange
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
using (var repository = CreateRepository(unitOfWork))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = CreateRepository(unitOfWork);
|
||||
|
||||
// Act
|
||||
var contentType = repository.Get(NodeDto.NodeIdSeed + 1);
|
||||
@@ -739,9 +726,9 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
// Arrange
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
using (var repository = CreateRepository(unitOfWork))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = CreateRepository(unitOfWork);
|
||||
var contentType = repository.Get(NodeDto.NodeIdSeed + 1);
|
||||
|
||||
// Act
|
||||
@@ -756,7 +743,7 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
|
||||
var addedPropertyType = contentType.AddPropertyType(urlAlias);
|
||||
repository.AddOrUpdate(contentType);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
|
||||
// Assert
|
||||
var updated = repository.Get(NodeDto.NodeIdSeed + 1);
|
||||
@@ -773,15 +760,15 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
// Arrange
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
using (var repository = CreateRepository(unitOfWork))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = CreateRepository(unitOfWork);
|
||||
|
||||
var subpageContentType = MockedContentTypes.CreateSimpleContentType("umbSubpage", "Subpage");
|
||||
var simpleSubpageContentType = MockedContentTypes.CreateSimpleContentType("umbSimpleSubpage", "Simple Subpage");
|
||||
repository.AddOrUpdate(subpageContentType);
|
||||
repository.AddOrUpdate(simpleSubpageContentType);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
|
||||
// Act
|
||||
var contentType = repository.Get(NodeDto.NodeIdSeed);
|
||||
@@ -791,7 +778,7 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
new ContentTypeSort(new Lazy<int>(() => simpleSubpageContentType.Id), 1, simpleSubpageContentType.Alias)
|
||||
};
|
||||
repository.AddOrUpdate(contentType);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
|
||||
//Assert
|
||||
var updated = repository.Get(NodeDto.NodeIdSeed);
|
||||
@@ -807,20 +794,20 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
// Arrange
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
ContentTypeRepository repository;
|
||||
using (var contentRepository = CreateRepository(unitOfWork, out repository))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
ContentTypeRepository repository;
|
||||
var contentRepository = CreateRepository(unitOfWork, out repository);
|
||||
var contentType = repository.Get(NodeDto.NodeIdSeed + 1);
|
||||
|
||||
var subpage = MockedContent.CreateTextpageContent(contentType, "Text Page 1", contentType.Id);
|
||||
contentRepository.AddOrUpdate(subpage);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
|
||||
// Act
|
||||
contentType.RemovePropertyType("keywords");
|
||||
repository.AddOrUpdate(contentType);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
|
||||
// Assert
|
||||
Assert.That(contentType.PropertyTypes.Count(), Is.EqualTo(3));
|
||||
@@ -834,21 +821,21 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
// Arrange
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
ContentTypeRepository repository;
|
||||
using (var contentRepository = CreateRepository(unitOfWork, out repository))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
ContentTypeRepository repository;
|
||||
var contentRepository = CreateRepository(unitOfWork, out repository);
|
||||
var contentType = repository.Get(NodeDto.NodeIdSeed + 1);
|
||||
|
||||
var subpage = MockedContent.CreateTextpageContent(contentType, "Text Page 1", contentType.Id);
|
||||
contentRepository.AddOrUpdate(subpage);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
|
||||
// Act
|
||||
var propertyGroup = contentType.PropertyGroups.First(x => x.Name == "Meta");
|
||||
propertyGroup.PropertyTypes.Add(new PropertyType("test", DataTypeDatabaseType.Ntext, "metaAuthor") { Name = "Meta Author", Description = "", Mandatory = false, SortOrder = 1, DataTypeDefinitionId = -88 });
|
||||
repository.AddOrUpdate(contentType);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
|
||||
// Assert
|
||||
Assert.That(contentType.PropertyTypes.Count(), Is.EqualTo(5));
|
||||
@@ -862,26 +849,26 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
// Arrange
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
ContentTypeRepository repository;
|
||||
using (var contentRepository = CreateRepository(unitOfWork, out repository))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
ContentTypeRepository repository;
|
||||
var contentRepository = CreateRepository(unitOfWork, out repository);
|
||||
var contentType = repository.Get(NodeDto.NodeIdSeed + 1);
|
||||
|
||||
var subpage = MockedContent.CreateTextpageContent(contentType, "Text Page 1", contentType.Id);
|
||||
contentRepository.AddOrUpdate(subpage);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
|
||||
var propertyGroup = contentType.PropertyGroups.First(x => x.Name == "Meta");
|
||||
propertyGroup.PropertyTypes.Add(new PropertyType("test", DataTypeDatabaseType.Ntext, "metaAuthor") { Name = "Meta Author", Description = "", Mandatory = false, SortOrder = 1, DataTypeDefinitionId = -88 });
|
||||
repository.AddOrUpdate(contentType);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
|
||||
// Act
|
||||
var content = contentRepository.Get(subpage.Id);
|
||||
content.SetValue("metaAuthor", "John Doe");
|
||||
contentRepository.AddOrUpdate(content);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
|
||||
//Assert
|
||||
var updated = contentRepository.Get(subpage.Id);
|
||||
@@ -892,21 +879,19 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void
|
||||
Can_Verify_That_A_Combination_Of_Adding_And_Deleting_PropertyTypes_Doesnt_Cause_Issues_For_Content_And_ContentType
|
||||
()
|
||||
public void Can_Verify_That_A_Combination_Of_Adding_And_Deleting_PropertyTypes_Doesnt_Cause_Issues_For_Content_And_ContentType()
|
||||
{
|
||||
// Arrange
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
ContentTypeRepository repository;
|
||||
using (var contentRepository = CreateRepository(unitOfWork, out repository))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
ContentTypeRepository repository;
|
||||
var contentRepository = CreateRepository(unitOfWork, out repository);
|
||||
var contentType = repository.Get(NodeDto.NodeIdSeed + 1);
|
||||
|
||||
var subpage = MockedContent.CreateTextpageContent(contentType, "Text Page 1", contentType.Id);
|
||||
contentRepository.AddOrUpdate(subpage);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
|
||||
//Remove PropertyType
|
||||
contentType.RemovePropertyType("keywords");
|
||||
@@ -914,13 +899,13 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
var propertyGroup = contentType.PropertyGroups.First(x => x.Name == "Meta");
|
||||
propertyGroup.PropertyTypes.Add(new PropertyType("test", DataTypeDatabaseType.Ntext, "metaAuthor") { Name = "Meta Author", Description = "", Mandatory = false, SortOrder = 1, DataTypeDefinitionId = -88 });
|
||||
repository.AddOrUpdate(contentType);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
|
||||
// Act
|
||||
var content = contentRepository.Get(subpage.Id);
|
||||
content.SetValue("metaAuthor", "John Doe");
|
||||
contentRepository.AddOrUpdate(content);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
|
||||
//Assert
|
||||
var updated = contentRepository.Get(subpage.Id);
|
||||
|
||||
@@ -16,6 +16,7 @@ using Umbraco.Core.Models.Membership;
|
||||
using Umbraco.Core.Models.Rdbms;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Persistence.Mappers;
|
||||
using Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSeven;
|
||||
using Umbraco.Core.Persistence.Querying;
|
||||
using Umbraco.Core.Persistence.Repositories;
|
||||
using Umbraco.Core.Persistence.UnitOfWork;
|
||||
@@ -82,24 +83,24 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
public void Can_Move()
|
||||
{
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
using (var containerRepository = CreateContainerRepository(unitOfWork))
|
||||
using (var repository = CreateRepository(unitOfWork))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
var containerRepository = CreateContainerRepository(unitOfWork);
|
||||
var repository = CreateRepository(unitOfWork);
|
||||
var container1 = new EntityContainer(Constants.ObjectTypes.DataTypeGuid) { Name = "blah1" };
|
||||
containerRepository.AddOrUpdate(container1);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
|
||||
var container2 = new EntityContainer(Constants.ObjectTypes.DataTypeGuid) { Name = "blah2", ParentId = container1.Id };
|
||||
containerRepository.AddOrUpdate(container2);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
|
||||
var dataType = (IDataTypeDefinition) new DataTypeDefinition(container2.Id, Constants.PropertyEditors.RadioButtonListAlias)
|
||||
var dataType = (IDataTypeDefinition)new DataTypeDefinition(container2.Id, Constants.PropertyEditors.RadioButtonListAlias)
|
||||
{
|
||||
Name = "dt1"
|
||||
};
|
||||
repository.AddOrUpdate(dataType);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
|
||||
//create a
|
||||
var dataType2 = (IDataTypeDefinition)new DataTypeDefinition(dataType.Id, Constants.PropertyEditors.RadioButtonListAlias)
|
||||
@@ -107,10 +108,10 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
Name = "dt2"
|
||||
};
|
||||
repository.AddOrUpdate(dataType2);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
|
||||
var result = repository.Move(dataType, container1).ToArray();
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
|
||||
Assert.AreEqual(2, result.Count());
|
||||
|
||||
@@ -129,17 +130,14 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
public void Can_Create_Container()
|
||||
{
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
EntityContainer container;
|
||||
using (var containerRepository = CreateContainerRepository(unitOfWork))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
container = new EntityContainer(Constants.ObjectTypes.DataTypeGuid) { Name = "blah" };
|
||||
var containerRepository = CreateContainerRepository(unitOfWork);
|
||||
var container = new EntityContainer(Constants.ObjectTypes.DataTypeGuid) { Name = "blah" };
|
||||
containerRepository.AddOrUpdate(container);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
Assert.That(container.Id, Is.GreaterThan(0));
|
||||
}
|
||||
using (var containerRepository = CreateContainerRepository(unitOfWork))
|
||||
{
|
||||
|
||||
var found = containerRepository.Get(container.Id);
|
||||
Assert.IsNotNull(found);
|
||||
}
|
||||
@@ -149,22 +147,17 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
public void Can_Delete_Container()
|
||||
{
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
EntityContainer container;
|
||||
using (var containerRepository = CreateContainerRepository(unitOfWork))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
container = new EntityContainer(Constants.ObjectTypes.DataTypeGuid) { Name = "blah" };
|
||||
var containerRepository = CreateContainerRepository(unitOfWork);
|
||||
var container = new EntityContainer(Constants.ObjectTypes.DataTypeGuid) { Name = "blah" };
|
||||
containerRepository.AddOrUpdate(container);
|
||||
unitOfWork.Commit();
|
||||
}
|
||||
using (var containerRepository = CreateContainerRepository(unitOfWork))
|
||||
{
|
||||
unitOfWork.Flush();
|
||||
|
||||
// Act
|
||||
containerRepository.Delete(container);
|
||||
unitOfWork.Commit();
|
||||
}
|
||||
using (var containerRepository = CreateContainerRepository(unitOfWork))
|
||||
{
|
||||
unitOfWork.Flush();
|
||||
|
||||
var found = containerRepository.Get(container.Id);
|
||||
Assert.IsNull(found);
|
||||
}
|
||||
@@ -174,17 +167,17 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
public void Can_Create_Container_Containing_Data_Types()
|
||||
{
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
using (var containerRepository = CreateContainerRepository(unitOfWork))
|
||||
using (var repository = CreateRepository(unitOfWork))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
var containerRepository = CreateContainerRepository(unitOfWork);
|
||||
var repository = CreateRepository(unitOfWork);
|
||||
var container = new EntityContainer(Constants.ObjectTypes.DataTypeGuid) { Name = "blah" };
|
||||
containerRepository.AddOrUpdate(container);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
|
||||
var dataTypeDefinition = new DataTypeDefinition(container.Id, Constants.PropertyEditors.RadioButtonListAlias) { Name = "test" };
|
||||
repository.AddOrUpdate(dataTypeDefinition);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
|
||||
Assert.AreEqual(container.Id, dataTypeDefinition.ParentId);
|
||||
}
|
||||
@@ -194,26 +187,21 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
public void Can_Delete_Container_Containing_Data_Types()
|
||||
{
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
EntityContainer container;
|
||||
IDataTypeDefinition dataType;
|
||||
using (var containerRepository = CreateContainerRepository(unitOfWork))
|
||||
using (var repository = CreateRepository(unitOfWork))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
container = new EntityContainer(Constants.ObjectTypes.DataTypeGuid) { Name = "blah" };
|
||||
var containerRepository = CreateContainerRepository(unitOfWork);
|
||||
var repository = CreateRepository(unitOfWork);
|
||||
var container = new EntityContainer(Constants.ObjectTypes.DataTypeGuid) { Name = "blah" };
|
||||
containerRepository.AddOrUpdate(container);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
|
||||
dataType = new DataTypeDefinition(container.Id, Constants.PropertyEditors.RadioButtonListAlias) { Name = "test" };
|
||||
IDataTypeDefinition dataType = new DataTypeDefinition(container.Id, Constants.PropertyEditors.RadioButtonListAlias) { Name = "test" };
|
||||
repository.AddOrUpdate(dataType);
|
||||
unitOfWork.Commit();
|
||||
}
|
||||
using (var containerRepository = CreateContainerRepository(unitOfWork))
|
||||
using (var repository = CreateRepository(unitOfWork))
|
||||
{
|
||||
unitOfWork.Flush();
|
||||
|
||||
// Act
|
||||
containerRepository.Delete(container);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
|
||||
var found = containerRepository.Get(container.Id);
|
||||
Assert.IsNull(found);
|
||||
@@ -228,22 +216,19 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
public void Can_Create()
|
||||
{
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
int id;
|
||||
using (var repository = CreateRepository(unitOfWork))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
var dataTypeDefinition = new DataTypeDefinition(-1, Constants.PropertyEditors.RadioButtonListAlias) {Name = "test"};
|
||||
var repository = CreateRepository(unitOfWork);
|
||||
IDataTypeDefinition dataTypeDefinition = new DataTypeDefinition(-1, Constants.PropertyEditors.RadioButtonListAlias) {Name = "test"};
|
||||
|
||||
repository.AddOrUpdate(dataTypeDefinition);
|
||||
|
||||
unitOfWork.Commit();
|
||||
id = dataTypeDefinition.Id;
|
||||
unitOfWork.Flush();
|
||||
var id = dataTypeDefinition.Id;
|
||||
Assert.That(id, Is.GreaterThan(0));
|
||||
}
|
||||
using (var repository = CreateRepository(unitOfWork))
|
||||
{
|
||||
|
||||
// Act
|
||||
var dataTypeDefinition = repository.Get(id);
|
||||
dataTypeDefinition = repository.Get(id);
|
||||
|
||||
// Assert
|
||||
Assert.That(dataTypeDefinition, Is.Not.Null);
|
||||
@@ -257,9 +242,9 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
// Arrange
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
using (var repository = CreateRepository(unitOfWork))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = CreateRepository(unitOfWork);
|
||||
// Act
|
||||
var dataTypeDefinition = repository.Get(-42);
|
||||
|
||||
@@ -268,7 +253,6 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
Assert.That(dataTypeDefinition.HasIdentity, Is.True);
|
||||
Assert.That(dataTypeDefinition.Name, Is.EqualTo("Dropdown"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -276,9 +260,9 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
// Arrange
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
using (var repository = CreateRepository(unitOfWork))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = CreateRepository(unitOfWork);
|
||||
|
||||
// Act
|
||||
var dataTypeDefinitions = repository.GetAll();
|
||||
@@ -296,9 +280,9 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
// Arrange
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
using (var repository = CreateRepository(unitOfWork))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = CreateRepository(unitOfWork);
|
||||
|
||||
// Act
|
||||
var dataTypeDefinitions = repository.GetAll(-40, -41, -42);
|
||||
@@ -316,9 +300,9 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
// Arrange
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
using (var repository = CreateRepository(unitOfWork))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = CreateRepository(unitOfWork);
|
||||
|
||||
// Act
|
||||
var query = new Query<IDataTypeDefinition>(SqlSyntax, MappingResolver).Where(x => x.PropertyEditorAlias == Constants.PropertyEditors.RadioButtonListAlias);
|
||||
@@ -336,9 +320,9 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
// Arrange
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
using (var repository = CreateRepository(unitOfWork))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = CreateRepository(unitOfWork);
|
||||
|
||||
// Act
|
||||
var query = new Query<IDataTypeDefinition>(SqlSyntax, MappingResolver).Where(x => x.Name.StartsWith("D"));
|
||||
@@ -354,20 +338,19 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
// Arrange
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
using (var repository = CreateRepository(unitOfWork))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
|
||||
var dataTypeDefinition = new DataTypeDefinition("Test.TestEditor")
|
||||
{
|
||||
DatabaseType = DataTypeDatabaseType.Integer,
|
||||
Name = "AgeDataType",
|
||||
CreatorId = 0
|
||||
};
|
||||
var repository = CreateRepository(unitOfWork);
|
||||
var dataTypeDefinition = new DataTypeDefinition("Test.TestEditor")
|
||||
{
|
||||
DatabaseType = DataTypeDatabaseType.Integer,
|
||||
Name = "AgeDataType",
|
||||
CreatorId = 0
|
||||
};
|
||||
|
||||
// Act
|
||||
repository.AddOrUpdate(dataTypeDefinition);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
var exists = repository.Exists(dataTypeDefinition.Id);
|
||||
|
||||
// Assert
|
||||
@@ -381,32 +364,31 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
// Arrange
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
using (var repository = CreateRepository(unitOfWork))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
|
||||
var dataTypeDefinition = new DataTypeDefinition("Test.blah")
|
||||
{
|
||||
DatabaseType = DataTypeDatabaseType.Integer,
|
||||
Name = "AgeDataType",
|
||||
CreatorId = 0
|
||||
};
|
||||
var repository = CreateRepository(unitOfWork);
|
||||
var dataTypeDefinition = new DataTypeDefinition("Test.blah")
|
||||
{
|
||||
DatabaseType = DataTypeDatabaseType.Integer,
|
||||
Name = "AgeDataType",
|
||||
CreatorId = 0
|
||||
};
|
||||
repository.AddOrUpdate(dataTypeDefinition);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
|
||||
// Act
|
||||
var definition = repository.Get(dataTypeDefinition.Id);
|
||||
definition.Name = "AgeDataType Updated";
|
||||
definition.PropertyEditorAlias = "Test.TestEditor"; //change
|
||||
definition.PropertyEditorAlias = "Test.TestEditor"; //change
|
||||
repository.AddOrUpdate(definition);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
|
||||
var definitionUpdated = repository.Get(dataTypeDefinition.Id);
|
||||
|
||||
// Assert
|
||||
Assert.That(definitionUpdated, Is.Not.Null);
|
||||
Assert.That(definitionUpdated.Name, Is.EqualTo("AgeDataType Updated"));
|
||||
Assert.That(definitionUpdated.PropertyEditorAlias, Is.EqualTo("Test.TestEditor"));
|
||||
Assert.That(definitionUpdated.PropertyEditorAlias, Is.EqualTo("Test.TestEditor"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -415,24 +397,23 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
// Arrange
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
using (var repository = CreateRepository(unitOfWork))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
|
||||
var dataTypeDefinition = new DataTypeDefinition("Test.TestEditor")
|
||||
{
|
||||
DatabaseType = DataTypeDatabaseType.Integer,
|
||||
Name = "AgeDataType",
|
||||
CreatorId = 0
|
||||
};
|
||||
var repository = CreateRepository(unitOfWork);
|
||||
var dataTypeDefinition = new DataTypeDefinition("Test.TestEditor")
|
||||
{
|
||||
DatabaseType = DataTypeDatabaseType.Integer,
|
||||
Name = "AgeDataType",
|
||||
CreatorId = 0
|
||||
};
|
||||
|
||||
// Act
|
||||
repository.AddOrUpdate(dataTypeDefinition);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
var existsBefore = repository.Exists(dataTypeDefinition.Id);
|
||||
|
||||
repository.Delete(dataTypeDefinition);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
|
||||
var existsAfter = repository.Exists(dataTypeDefinition.Id);
|
||||
|
||||
@@ -447,9 +428,9 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
// Arrange
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
using (var repository = CreateRepository(unitOfWork))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = CreateRepository(unitOfWork);
|
||||
|
||||
// Act
|
||||
var exists = repository.Exists(1034); //Content picker
|
||||
@@ -465,22 +446,17 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
public void Can_Get_Pre_Value_Collection()
|
||||
{
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
|
||||
int dtid;
|
||||
using (var repository = CreateRepository(unitOfWork))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = CreateRepository(unitOfWork);
|
||||
var dataTypeDefinition = new DataTypeDefinition(-1, Constants.PropertyEditors.RadioButtonListAlias) { Name = "test" };
|
||||
repository.AddOrUpdate(dataTypeDefinition);
|
||||
unitOfWork.Commit();
|
||||
dtid = dataTypeDefinition.Id;
|
||||
}
|
||||
unitOfWork.Flush();
|
||||
var dtid = dataTypeDefinition.Id;
|
||||
|
||||
DatabaseContext.Database.Insert(new DataTypePreValueDto() { DataTypeNodeId = dtid, SortOrder = 0, Value = "test1"});
|
||||
DatabaseContext.Database.Insert(new DataTypePreValueDto() { DataTypeNodeId = dtid, SortOrder = 1, Value = "test2" });
|
||||
unitOfWork.Database.Insert(new DataTypePreValueDto { DataTypeNodeId = dtid, SortOrder = 0, Value = "test1"});
|
||||
unitOfWork.Database.Insert(new DataTypePreValueDto { DataTypeNodeId = dtid, SortOrder = 1, Value = "test2" });
|
||||
|
||||
using (var repository = CreateRepository(unitOfWork))
|
||||
{
|
||||
var collection = repository.GetPreValuesCollectionByDataTypeId(dtid);
|
||||
Assert.AreEqual(2, collection.PreValuesAsArray.Count());
|
||||
}
|
||||
@@ -490,22 +466,17 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
public void Can_Get_Pre_Value_As_String()
|
||||
{
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
|
||||
int dtid;
|
||||
using (var repository = CreateRepository(unitOfWork))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = CreateRepository(unitOfWork);
|
||||
var dataTypeDefinition = new DataTypeDefinition(-1, Constants.PropertyEditors.RadioButtonListAlias) { Name = "test" };
|
||||
repository.AddOrUpdate(dataTypeDefinition);
|
||||
unitOfWork.Commit();
|
||||
dtid = dataTypeDefinition.Id;
|
||||
}
|
||||
unitOfWork.Flush();
|
||||
var dtid = dataTypeDefinition.Id;
|
||||
|
||||
var id = DatabaseContext.Database.Insert(new DataTypePreValueDto() { DataTypeNodeId = dtid, SortOrder = 0, Value = "test1" });
|
||||
DatabaseContext.Database.Insert(new DataTypePreValueDto() { DataTypeNodeId = dtid, SortOrder = 1, Value = "test2" });
|
||||
var id = unitOfWork.Database.Insert(new DataTypePreValueDto { DataTypeNodeId = dtid, SortOrder = 0, Value = "test1" });
|
||||
unitOfWork.Database.Insert(new DataTypePreValueDto { DataTypeNodeId = dtid, SortOrder = 1, Value = "test2" });
|
||||
|
||||
using (var repository = CreateRepository(unitOfWork))
|
||||
{
|
||||
var val = repository.GetPreValueAsString(Convert.ToInt32(id));
|
||||
Assert.AreEqual("test1", val);
|
||||
}
|
||||
@@ -515,22 +486,18 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
public void Can_Get_Pre_Value_Collection_With_Cache()
|
||||
{
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
|
||||
DataTypeDefinition dtd;
|
||||
using (var repository = Container.GetInstance<IDatabaseUnitOfWork, IDataTypeDefinitionRepository>(unitOfWork))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
dtd = new DataTypeDefinition(-1, Constants.PropertyEditors.RadioButtonListAlias) { Name = "test" };
|
||||
var repository = Container.GetInstance<IDatabaseUnitOfWork, IDataTypeDefinitionRepository>(unitOfWork);
|
||||
dtd = new DataTypeDefinition(-1, Constants.PropertyEditors.RadioButtonListAlias) { Name = "test" };
|
||||
repository.AddOrUpdate(dtd);
|
||||
unitOfWork.Commit();
|
||||
}
|
||||
unitOfWork.Flush();
|
||||
|
||||
DatabaseContext.Database.Insert(new DataTypePreValueDto() { DataTypeNodeId = dtd.Id, SortOrder = 0, Value = "test1" });
|
||||
DatabaseContext.Database.Insert(new DataTypePreValueDto() { DataTypeNodeId = dtd.Id, SortOrder = 1, Value = "test2" });
|
||||
unitOfWork.Database.Insert(new DataTypePreValueDto() { DataTypeNodeId = dtd.Id, SortOrder = 0, Value = "test1" });
|
||||
unitOfWork.Database.Insert(new DataTypePreValueDto() { DataTypeNodeId = dtd.Id, SortOrder = 1, Value = "test2" });
|
||||
|
||||
//this will cache the result
|
||||
using (var repository = Container.GetInstance<IDatabaseUnitOfWork, IDataTypeDefinitionRepository>(unitOfWork))
|
||||
{
|
||||
//this will cache the result
|
||||
var collection = repository.GetPreValuesCollectionByDataTypeId(dtd.Id);
|
||||
}
|
||||
|
||||
@@ -549,22 +516,19 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
public void Can_Get_Pre_Value_As_String_With_Cache()
|
||||
{
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
|
||||
DataTypeDefinition dtd;
|
||||
using (var repository = Container.GetInstance<IDatabaseUnitOfWork, IDataTypeDefinitionRepository>(unitOfWork))
|
||||
object id;
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = Container.GetInstance<IDatabaseUnitOfWork, IDataTypeDefinitionRepository>(unitOfWork);
|
||||
dtd = new DataTypeDefinition(-1, Constants.PropertyEditors.RadioButtonListAlias) { Name = "test" };
|
||||
repository.AddOrUpdate(dtd);
|
||||
unitOfWork.Commit();
|
||||
}
|
||||
unitOfWork.Flush();
|
||||
|
||||
var id = DatabaseContext.Database.Insert(new DataTypePreValueDto() { DataTypeNodeId = dtd.Id, SortOrder = 0, Value = "test1" });
|
||||
DatabaseContext.Database.Insert(new DataTypePreValueDto() { DataTypeNodeId = dtd.Id, SortOrder = 1, Value = "test2" });
|
||||
id = unitOfWork.Database.Insert(new DataTypePreValueDto() { DataTypeNodeId = dtd.Id, SortOrder = 0, Value = "test1" });
|
||||
unitOfWork.Database.Insert(new DataTypePreValueDto() { DataTypeNodeId = dtd.Id, SortOrder = 1, Value = "test2" });
|
||||
|
||||
//this will cache the result
|
||||
using (var repository = Container.GetInstance<IDatabaseUnitOfWork, IDataTypeDefinitionRepository>(unitOfWork))
|
||||
{
|
||||
//this will cache the result
|
||||
var val = repository.GetPreValueAsString(Convert.ToInt32(id));
|
||||
}
|
||||
|
||||
@@ -578,8 +542,9 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
Assert.AreEqual(1, cached.Count());
|
||||
Assert.AreEqual(2, cached.Single().FormatAsDictionary().Count);
|
||||
|
||||
using (var repository = Container.GetInstance<IDatabaseUnitOfWork, IDataTypeDefinitionRepository>(unitOfWork))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = Container.GetInstance<IDatabaseUnitOfWork, IDataTypeDefinitionRepository>(unitOfWork);
|
||||
//ensure it still gets resolved!
|
||||
var val = repository.GetPreValueAsString(Convert.ToInt32(id));
|
||||
Assert.AreEqual("test1", val);
|
||||
|
||||
@@ -37,10 +37,9 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
// Arrange
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
|
||||
using (var repository = CreateRepository(unitOfWork))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = CreateRepository(unitOfWork);
|
||||
var dictionaryItem = (IDictionaryItem)new DictionaryItem("Testing1235")
|
||||
{
|
||||
Translations = new List<IDictionaryTranslation>
|
||||
@@ -50,7 +49,7 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
};
|
||||
|
||||
repository.AddOrUpdate(dictionaryItem);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
|
||||
//re-get
|
||||
dictionaryItem = repository.Get("Testing1235");
|
||||
@@ -70,10 +69,9 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
// Arrange
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
|
||||
using (var repository = CreateRepository(unitOfWork))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = CreateRepository(unitOfWork);
|
||||
var dictionaryItem = (IDictionaryItem)new DictionaryItem("Testing1235")
|
||||
{
|
||||
Translations = new List<IDictionaryTranslation>
|
||||
@@ -83,7 +81,7 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
};
|
||||
|
||||
repository.AddOrUpdate(dictionaryItem);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
|
||||
//re-get
|
||||
dictionaryItem = repository.Get(dictionaryItem.Key);
|
||||
@@ -103,10 +101,9 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
// Arrange
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
|
||||
using (var repository = CreateRepository(unitOfWork))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = CreateRepository(unitOfWork);
|
||||
var dictionaryItem = (IDictionaryItem)new DictionaryItem("Testing1235")
|
||||
{
|
||||
Translations = new List<IDictionaryTranslation>
|
||||
@@ -116,7 +113,7 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
};
|
||||
|
||||
repository.AddOrUpdate(dictionaryItem);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
|
||||
//re-get
|
||||
dictionaryItem = repository.Get(dictionaryItem.Id);
|
||||
@@ -137,14 +134,13 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
// Arrange
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
|
||||
using (var repository = CreateRepository(unitOfWork))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = CreateRepository(unitOfWork);
|
||||
var dictionaryItem = (IDictionaryItem) new DictionaryItem("Testing1235");
|
||||
|
||||
repository.AddOrUpdate(dictionaryItem);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
|
||||
//re-get
|
||||
dictionaryItem = repository.Get(dictionaryItem.Id);
|
||||
@@ -164,9 +160,9 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
// Arrange
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
using (var repository = CreateRepository(unitOfWork))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = CreateRepository(unitOfWork);
|
||||
|
||||
// Act
|
||||
var dictionaryItem = repository.Get(1);
|
||||
@@ -185,9 +181,9 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
// Arrange
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
using (var repository = CreateRepository(unitOfWork))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = CreateRepository(unitOfWork);
|
||||
|
||||
// Act
|
||||
var dictionaryItems = repository.GetAll(1, 2);
|
||||
@@ -205,9 +201,9 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
// Arrange
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
using (var repository = CreateRepository(unitOfWork))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = CreateRepository(unitOfWork);
|
||||
|
||||
// Act
|
||||
var query = new Query<IDictionaryItem>(SqlSyntax, MappingResolver).Where(x => x.ItemKey == "Article");
|
||||
@@ -225,9 +221,9 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
// Arrange
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
using (var repository = CreateRepository(unitOfWork))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = CreateRepository(unitOfWork);
|
||||
|
||||
// Act
|
||||
var query = new Query<IDictionaryItem>(SqlSyntax, MappingResolver).Where(x => x.ItemKey.StartsWith("Read"));
|
||||
@@ -243,10 +239,10 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
// Arrange
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
using (var languageRepository = Container.GetInstance<IDatabaseUnitOfWork, ILanguageRepository>(unitOfWork))
|
||||
using (var repository = CreateRepository(unitOfWork))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
var languageRepository = Container.GetInstance<IDatabaseUnitOfWork, ILanguageRepository>(unitOfWork);
|
||||
var repository = CreateRepository(unitOfWork);
|
||||
|
||||
var language = languageRepository.Get(1);
|
||||
|
||||
@@ -259,7 +255,7 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
|
||||
// Act
|
||||
repository.AddOrUpdate(read);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
|
||||
var exists = repository.Exists(read.Id);
|
||||
|
||||
@@ -274,9 +270,9 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
// Arrange
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
using (var repository = CreateRepository(unitOfWork))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = CreateRepository(unitOfWork);
|
||||
|
||||
// Act
|
||||
var item = repository.Get(1);
|
||||
@@ -285,7 +281,7 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
item.Translations = translations;
|
||||
|
||||
repository.AddOrUpdate(item);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
|
||||
var dictionaryItem = repository.Get(1);
|
||||
|
||||
@@ -301,27 +297,29 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
// Arrange
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
var repository = CreateRepository(unitOfWork);
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = CreateRepository(unitOfWork);
|
||||
|
||||
var languageNo = new Language("nb-NO") { CultureName = "nb-NO" };
|
||||
ServiceContext.LocalizationService.Save(languageNo);
|
||||
var languageNo = new Language("nb-NO") { CultureName = "nb-NO" };
|
||||
ServiceContext.LocalizationService.Save(languageNo);
|
||||
|
||||
// Act
|
||||
var item = repository.Get(1);
|
||||
var translations = item.Translations.ToList();
|
||||
translations.Add(new DictionaryTranslation(languageNo, "Les mer"));
|
||||
item.Translations = translations;
|
||||
// Act
|
||||
var item = repository.Get(1);
|
||||
var translations = item.Translations.ToList();
|
||||
translations.Add(new DictionaryTranslation(languageNo, "Les mer"));
|
||||
item.Translations = translations;
|
||||
|
||||
repository.AddOrUpdate(item);
|
||||
unitOfWork.Commit();
|
||||
repository.AddOrUpdate(item);
|
||||
unitOfWork.Flush();
|
||||
|
||||
var dictionaryItem = (DictionaryItem)repository.Get(1);
|
||||
|
||||
// Assert
|
||||
Assert.That(dictionaryItem, Is.Not.Null);
|
||||
Assert.That(dictionaryItem.Translations.Count(), Is.EqualTo(3));
|
||||
Assert.That(dictionaryItem.Translations.Single(t => t.LanguageId == languageNo.Id).Value, Is.EqualTo("Les mer"));
|
||||
var dictionaryItem = (DictionaryItem) repository.Get(1);
|
||||
|
||||
// Assert
|
||||
Assert.That(dictionaryItem, Is.Not.Null);
|
||||
Assert.That(dictionaryItem.Translations.Count(), Is.EqualTo(3));
|
||||
Assert.That(dictionaryItem.Translations.Single(t => t.LanguageId == languageNo.Id).Value, Is.EqualTo("Les mer"));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -329,14 +327,14 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
// Arrange
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
using (var repository = CreateRepository(unitOfWork))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = CreateRepository(unitOfWork);
|
||||
|
||||
// Act
|
||||
var item = repository.Get(1);
|
||||
repository.Delete(item);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
|
||||
var exists = repository.Exists(1);
|
||||
|
||||
@@ -350,9 +348,9 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
// Arrange
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
using (var repository = CreateRepository(unitOfWork))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = CreateRepository(unitOfWork);
|
||||
|
||||
// Act
|
||||
var exists = repository.Exists(1);
|
||||
|
||||
@@ -31,14 +31,14 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
private int CreateTestData(string isoName, out ContentType ct)
|
||||
{
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
|
||||
ContentRepository contentRepo;
|
||||
LanguageRepository langRepo;
|
||||
ContentTypeRepository contentTypeRepo;
|
||||
|
||||
using (var repo = CreateRepository(unitOfWork, out contentTypeRepo, out contentRepo, out langRepo))
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
ContentRepository contentRepo;
|
||||
LanguageRepository langRepo;
|
||||
ContentTypeRepository contentTypeRepo;
|
||||
|
||||
var repo = CreateRepository(unitOfWork, out contentTypeRepo, out contentRepo, out langRepo);
|
||||
|
||||
var lang = new Language(isoName);
|
||||
langRepo.AddOrUpdate(lang);
|
||||
|
||||
@@ -46,7 +46,7 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
contentTypeRepo.AddOrUpdate(ct);
|
||||
var content = new Content("test", -1, ct) { CreatorId = 0, WriterId = 0 };
|
||||
contentRepo.AddOrUpdate(content);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Complete();
|
||||
return content.Id;
|
||||
}
|
||||
}
|
||||
@@ -54,24 +54,24 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
[Test]
|
||||
public void Can_Create_And_Get_By_Id()
|
||||
{
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
|
||||
ContentType ct;
|
||||
var contentId = CreateTestData("en-AU", out ct);
|
||||
|
||||
ContentRepository contentRepo;
|
||||
LanguageRepository langRepo;
|
||||
ContentTypeRepository contentTypeRepo;
|
||||
|
||||
using (var repo = CreateRepository(unitOfWork, out contentTypeRepo, out contentRepo, out langRepo))
|
||||
var provider = CreateUowProvider();
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
ContentRepository contentRepo;
|
||||
LanguageRepository langRepo;
|
||||
ContentTypeRepository contentTypeRepo;
|
||||
|
||||
var repo = CreateRepository(unitOfWork, out contentTypeRepo, out contentRepo, out langRepo);
|
||||
|
||||
var lang = langRepo.GetByIsoCode("en-AU");
|
||||
var content = contentRepo.Get(contentId);
|
||||
|
||||
var domain = (IDomain)new UmbracoDomain("test.com") { RootContentId = content.Id, LanguageId = lang.Id };
|
||||
repo.AddOrUpdate(domain);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
|
||||
//re-get
|
||||
domain = repo.Get(domain.Id);
|
||||
@@ -89,23 +89,23 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
[Test]
|
||||
public void Can_Create_And_Get_By_Id_Empty_lang()
|
||||
{
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
|
||||
ContentType ct;
|
||||
var contentId = CreateTestData("en-AU", out ct);
|
||||
|
||||
ContentRepository contentRepo;
|
||||
LanguageRepository langRepo;
|
||||
ContentTypeRepository contentTypeRepo;
|
||||
|
||||
using (var repo = CreateRepository(unitOfWork, out contentTypeRepo, out contentRepo, out langRepo))
|
||||
var provider = CreateUowProvider();
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
ContentRepository contentRepo;
|
||||
LanguageRepository langRepo;
|
||||
ContentTypeRepository contentTypeRepo;
|
||||
|
||||
var repo = CreateRepository(unitOfWork, out contentTypeRepo, out contentRepo, out langRepo);
|
||||
|
||||
var content = contentRepo.Get(contentId);
|
||||
|
||||
var domain = (IDomain)new UmbracoDomain("test.com") { RootContentId = content.Id };
|
||||
repo.AddOrUpdate(domain);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
|
||||
//re-get
|
||||
domain = repo.Get(domain.Id);
|
||||
@@ -122,86 +122,80 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
[Test]
|
||||
public void Cant_Create_Duplicate_Domain_Name()
|
||||
{
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
|
||||
ContentType ct;
|
||||
var contentId = CreateTestData("en-AU", out ct);
|
||||
|
||||
ContentRepository contentRepo;
|
||||
LanguageRepository langRepo;
|
||||
ContentTypeRepository contentTypeRepo;
|
||||
|
||||
using (var repo = CreateRepository(unitOfWork, out contentTypeRepo, out contentRepo, out langRepo))
|
||||
var provider = CreateUowProvider();
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
ContentRepository contentRepo;
|
||||
LanguageRepository langRepo;
|
||||
ContentTypeRepository contentTypeRepo;
|
||||
|
||||
var repo = CreateRepository(unitOfWork, out contentTypeRepo, out contentRepo, out langRepo);
|
||||
|
||||
var lang = langRepo.GetByIsoCode("en-AU");
|
||||
var content = contentRepo.Get(contentId);
|
||||
|
||||
var domain1 = (IDomain)new UmbracoDomain("test.com") { RootContentId = content.Id, LanguageId = lang.Id };
|
||||
repo.AddOrUpdate(domain1);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
|
||||
var domain2 = (IDomain)new UmbracoDomain("test.com") { RootContentId = content.Id, LanguageId = lang.Id };
|
||||
repo.AddOrUpdate(domain2);
|
||||
|
||||
Assert.Throws<DuplicateNameException>(unitOfWork.Commit);
|
||||
|
||||
|
||||
Assert.Throws<DuplicateNameException>(unitOfWork.Flush);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Delete()
|
||||
{
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
|
||||
ContentType ct;
|
||||
var contentId = CreateTestData("en-AU", out ct);
|
||||
|
||||
ContentRepository contentRepo;
|
||||
LanguageRepository langRepo;
|
||||
ContentTypeRepository contentTypeRepo;
|
||||
|
||||
using (var repo = CreateRepository(unitOfWork, out contentTypeRepo, out contentRepo, out langRepo))
|
||||
var provider = CreateUowProvider();
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
ContentRepository contentRepo;
|
||||
LanguageRepository langRepo;
|
||||
ContentTypeRepository contentTypeRepo;
|
||||
|
||||
var repo = CreateRepository(unitOfWork, out contentTypeRepo, out contentRepo, out langRepo);
|
||||
|
||||
var lang = langRepo.GetByIsoCode("en-AU");
|
||||
var content = contentRepo.Get(contentId);
|
||||
|
||||
var domain = (IDomain)new UmbracoDomain("test.com") { RootContentId = content.Id, LanguageId = lang.Id };
|
||||
repo.AddOrUpdate(domain);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
|
||||
repo.Delete(domain);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
|
||||
//re-get
|
||||
domain = repo.Get(domain.Id);
|
||||
|
||||
|
||||
Assert.IsNull(domain);
|
||||
Assert.IsNull(domain);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Update()
|
||||
{
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
|
||||
ContentType ct;
|
||||
var contentId1 = CreateTestData("en-AU", out ct);
|
||||
|
||||
ContentRepository contentRepo;
|
||||
LanguageRepository langRepo;
|
||||
ContentTypeRepository contentTypeRepo;
|
||||
|
||||
using (var repo = CreateRepository(unitOfWork, out contentTypeRepo, out contentRepo, out langRepo))
|
||||
var provider = CreateUowProvider();
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
ContentRepository contentRepo;
|
||||
LanguageRepository langRepo;
|
||||
ContentTypeRepository contentTypeRepo;
|
||||
|
||||
var repo = CreateRepository(unitOfWork, out contentTypeRepo, out contentRepo, out langRepo);
|
||||
|
||||
var content1 = contentRepo.Get(contentId1);
|
||||
|
||||
//more test data
|
||||
@@ -210,12 +204,12 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
langRepo.AddOrUpdate(lang2);
|
||||
var content2 = new Content("test", -1, ct) { CreatorId = 0, WriterId = 0 };
|
||||
contentRepo.AddOrUpdate(content2);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
|
||||
|
||||
var domain = (IDomain)new UmbracoDomain("test.com") { RootContentId = content1.Id, LanguageId = lang1.Id };
|
||||
repo.AddOrUpdate(domain);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
|
||||
//re-get
|
||||
domain = repo.Get(domain.Id);
|
||||
@@ -224,7 +218,7 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
domain.RootContentId = content2.Id;
|
||||
domain.LanguageId = lang2.Id;
|
||||
repo.AddOrUpdate(domain);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
|
||||
//re-get
|
||||
domain = repo.Get(domain.Id);
|
||||
@@ -234,26 +228,24 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
Assert.AreEqual(lang2.Id, domain.LanguageId);
|
||||
Assert.AreEqual(lang2.IsoCode, domain.LanguageIsoCode);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void Exists()
|
||||
{
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
|
||||
ContentType ct;
|
||||
var contentId = CreateTestData("en-AU", out ct);
|
||||
|
||||
ContentRepository contentRepo;
|
||||
LanguageRepository langRepo;
|
||||
ContentTypeRepository contentTypeRepo;
|
||||
|
||||
using (var repo = CreateRepository(unitOfWork, out contentTypeRepo, out contentRepo, out langRepo))
|
||||
var provider = CreateUowProvider();
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
ContentRepository contentRepo;
|
||||
LanguageRepository langRepo;
|
||||
ContentTypeRepository contentTypeRepo;
|
||||
|
||||
var repo = CreateRepository(unitOfWork, out contentTypeRepo, out contentRepo, out langRepo);
|
||||
|
||||
var lang = langRepo.GetByIsoCode("en-AU");
|
||||
var content = contentRepo.Get(contentId);
|
||||
|
||||
@@ -261,7 +253,7 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
var domain = (IDomain)new UmbracoDomain("test" + i + ".com") { RootContentId = content.Id, LanguageId = lang.Id };
|
||||
repo.AddOrUpdate(domain);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
}
|
||||
|
||||
var found = repo.Exists("test1.com");
|
||||
@@ -273,18 +265,18 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
[Test]
|
||||
public void Get_By_Name()
|
||||
{
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
|
||||
ContentType ct;
|
||||
var contentId = CreateTestData("en-AU", out ct);
|
||||
|
||||
ContentRepository contentRepo;
|
||||
LanguageRepository langRepo;
|
||||
ContentTypeRepository contentTypeRepo;
|
||||
|
||||
using (var repo = CreateRepository(unitOfWork, out contentTypeRepo, out contentRepo, out langRepo))
|
||||
var provider = CreateUowProvider();
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
ContentRepository contentRepo;
|
||||
LanguageRepository langRepo;
|
||||
ContentTypeRepository contentTypeRepo;
|
||||
|
||||
var repo = CreateRepository(unitOfWork, out contentTypeRepo, out contentRepo, out langRepo);
|
||||
|
||||
var lang = langRepo.GetByIsoCode("en-AU");
|
||||
var content = contentRepo.Get(contentId);
|
||||
|
||||
@@ -292,7 +284,7 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
var domain = (IDomain)new UmbracoDomain("test" + i + ".com") { RootContentId = content.Id, LanguageId = lang.Id };
|
||||
repo.AddOrUpdate(domain);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
}
|
||||
|
||||
var found = repo.GetByName("test1.com");
|
||||
@@ -304,18 +296,18 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
[Test]
|
||||
public void Get_All()
|
||||
{
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
|
||||
ContentType ct;
|
||||
var contentId = CreateTestData("en-AU", out ct);
|
||||
|
||||
ContentRepository contentRepo;
|
||||
LanguageRepository langRepo;
|
||||
ContentTypeRepository contentTypeRepo;
|
||||
|
||||
using (var repo = CreateRepository(unitOfWork, out contentTypeRepo, out contentRepo, out langRepo))
|
||||
var provider = CreateUowProvider();
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
ContentRepository contentRepo;
|
||||
LanguageRepository langRepo;
|
||||
ContentTypeRepository contentTypeRepo;
|
||||
|
||||
var repo = CreateRepository(unitOfWork, out contentTypeRepo, out contentRepo, out langRepo);
|
||||
|
||||
var lang = langRepo.GetByIsoCode("en-AU");
|
||||
var content = contentRepo.Get(contentId);
|
||||
|
||||
@@ -323,7 +315,7 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
var domain = (IDomain)new UmbracoDomain("test " + i + ".com") { RootContentId = content.Id, LanguageId = lang.Id };
|
||||
repo.AddOrUpdate(domain);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
}
|
||||
|
||||
var all = repo.GetAll();
|
||||
@@ -335,18 +327,18 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
[Test]
|
||||
public void Get_All_Ids()
|
||||
{
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
|
||||
ContentType ct;
|
||||
var contentId = CreateTestData("en-AU", out ct);
|
||||
|
||||
ContentRepository contentRepo;
|
||||
LanguageRepository langRepo;
|
||||
ContentTypeRepository contentTypeRepo;
|
||||
|
||||
using (var repo = CreateRepository(unitOfWork, out contentTypeRepo, out contentRepo, out langRepo))
|
||||
var provider = CreateUowProvider();
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
ContentRepository contentRepo;
|
||||
LanguageRepository langRepo;
|
||||
ContentTypeRepository contentTypeRepo;
|
||||
|
||||
var repo = CreateRepository(unitOfWork, out contentTypeRepo, out contentRepo, out langRepo);
|
||||
|
||||
var lang = langRepo.GetByIsoCode("en-AU");
|
||||
var content = contentRepo.Get(contentId);
|
||||
|
||||
@@ -355,7 +347,7 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
var domain = (IDomain)new UmbracoDomain("test " + i + ".com") { RootContentId = content.Id, LanguageId = lang.Id };
|
||||
repo.AddOrUpdate(domain);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
ids.Add(domain.Id);
|
||||
}
|
||||
|
||||
@@ -368,18 +360,18 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
[Test]
|
||||
public void Get_All_Without_Wildcards()
|
||||
{
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
|
||||
ContentType ct;
|
||||
var contentId = CreateTestData("en-AU", out ct);
|
||||
|
||||
ContentRepository contentRepo;
|
||||
LanguageRepository langRepo;
|
||||
ContentTypeRepository contentTypeRepo;
|
||||
|
||||
using (var repo = CreateRepository(unitOfWork, out contentTypeRepo, out contentRepo, out langRepo))
|
||||
var provider = CreateUowProvider();
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
ContentRepository contentRepo;
|
||||
LanguageRepository langRepo;
|
||||
ContentTypeRepository contentTypeRepo;
|
||||
|
||||
var repo = CreateRepository(unitOfWork, out contentTypeRepo, out contentRepo, out langRepo);
|
||||
|
||||
var lang = langRepo.GetByIsoCode("en-AU");
|
||||
var content = contentRepo.Get(contentId);
|
||||
|
||||
@@ -391,7 +383,7 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
LanguageId = lang.Id
|
||||
};
|
||||
repo.AddOrUpdate(domain);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
}
|
||||
|
||||
var all = repo.GetAll(false);
|
||||
@@ -403,32 +395,32 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
[Test]
|
||||
public void Get_All_For_Content()
|
||||
{
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
|
||||
ContentType ct;
|
||||
var contentId = CreateTestData("en-AU", out ct);
|
||||
|
||||
ContentRepository contentRepo;
|
||||
LanguageRepository langRepo;
|
||||
ContentTypeRepository contentTypeRepo;
|
||||
|
||||
using (var repo = CreateRepository(unitOfWork, out contentTypeRepo, out contentRepo, out langRepo))
|
||||
var provider = CreateUowProvider();
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
ContentRepository contentRepo;
|
||||
LanguageRepository langRepo;
|
||||
ContentTypeRepository contentTypeRepo;
|
||||
|
||||
var repo = CreateRepository(unitOfWork, out contentTypeRepo, out contentRepo, out langRepo);
|
||||
|
||||
var contentItems = new List<IContent>();
|
||||
|
||||
var lang = langRepo.GetByIsoCode("en-AU");
|
||||
contentItems.Add(contentRepo.Get(contentId));
|
||||
|
||||
|
||||
//more test data (3 content items total)
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
var c = new Content("test" + i, -1, ct) { CreatorId = 0, WriterId = 0 };
|
||||
contentRepo.AddOrUpdate(c);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
contentItems.Add(c);
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
var domain = (IDomain)new UmbracoDomain((i % 2 == 0) ? "test " + i + ".com" : ("*" + i))
|
||||
@@ -437,12 +429,12 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
LanguageId = lang.Id
|
||||
};
|
||||
repo.AddOrUpdate(domain);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
}
|
||||
|
||||
var all1 = repo.GetAssignedDomains(contentItems[0].Id, true);
|
||||
Assert.AreEqual(5, all1.Count());
|
||||
|
||||
|
||||
var all2 = repo.GetAssignedDomains(contentItems[1].Id, true);
|
||||
Assert.AreEqual(5, all2.Count());
|
||||
|
||||
@@ -454,18 +446,18 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
[Test]
|
||||
public void Get_All_For_Content_Without_Wildcards()
|
||||
{
|
||||
var provider = CreateUowProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
|
||||
ContentType ct;
|
||||
var contentId = CreateTestData("en-AU", out ct);
|
||||
|
||||
ContentRepository contentRepo;
|
||||
LanguageRepository langRepo;
|
||||
ContentTypeRepository contentTypeRepo;
|
||||
|
||||
using (var repo = CreateRepository(unitOfWork, out contentTypeRepo, out contentRepo, out langRepo))
|
||||
var provider = CreateUowProvider();
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
ContentRepository contentRepo;
|
||||
LanguageRepository langRepo;
|
||||
ContentTypeRepository contentTypeRepo;
|
||||
|
||||
var repo = CreateRepository(unitOfWork, out contentTypeRepo, out contentRepo, out langRepo);
|
||||
|
||||
var contentItems = new List<IContent>();
|
||||
|
||||
var lang = langRepo.GetByIsoCode("en-AU");
|
||||
@@ -476,7 +468,7 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
var c = new Content("test" + i, -1, ct) { CreatorId = 0, WriterId = 0 };
|
||||
contentRepo.AddOrUpdate(c);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
contentItems.Add(c);
|
||||
}
|
||||
|
||||
@@ -488,7 +480,7 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
LanguageId = lang.Id
|
||||
};
|
||||
repo.AddOrUpdate(domain);
|
||||
unitOfWork.Commit();
|
||||
unitOfWork.Flush();
|
||||
}
|
||||
|
||||
var all1 = repo.GetAssignedDomains(contentItems[0].Id, false);
|
||||
@@ -496,9 +488,7 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
|
||||
var all2 = repo.GetAssignedDomains(contentItems[1].Id, false);
|
||||
Assert.AreEqual(0, all2.Count());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user