Last active
October 2, 2021 23:34
-
-
Save gerhart92/c921cad66e19eced2d742801d1788922 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace Feature.Serialization.Services | |
{ | |
using System; | |
using System.Collections.Generic; | |
using Sitecore.Abstractions.Serialization; | |
/// <summary> | |
/// Serialization service for sitecore roles manager | |
/// </summary> | |
public class RoleSerializationService : IRoleSerializationService | |
{ | |
private readonly BaseSecuritySerializationManager<IRoleData> _roleSerializationManager; | |
/// <summary> | |
/// Constructor for service | |
/// </summary> | |
/// <param name="roleSerializationManager">Role serialization manager</param> | |
public RoleSerializationService(BaseSecuritySerializationManager<IRoleData> roleSerializationManager) | |
{ | |
_roleSerializationManager = roleSerializationManager; | |
} | |
/// <summary> | |
/// Method which dumps the role to the file system. | |
/// This will replace the following method from obsolete Manager: Sitecore.Data.Serialization.Manager.DumpRole(roleName) | |
/// </summary> | |
/// <returns> Status codes based on action result </returns> | |
public void DumpRole(string roleName) | |
{ | |
try | |
{ | |
_roleSerializationManager.DumpEntity(roleName); | |
} | |
catch (Exception ex) | |
{ | |
Sitecore.Diagnostics.Log.Error("Error dumping role: " + roleName, ex, this); | |
} | |
} | |
/// <summary> | |
/// Method which dumps the collection of roles to the file system. | |
/// </summary> | |
/// <returns> Status codes based on action result </returns> | |
public void DumpRoles(IEnumerable<string> roleNames) | |
{ | |
try | |
{ | |
_roleSerializationManager.DumpEntities(roleNames); | |
} | |
catch (Exception ex) | |
{ | |
Sitecore.Diagnostics.Log.Error("Error dumping roles: " + string.Join(",", roleNames), ex, this); | |
} | |
} | |
/// <summary> | |
/// Method which loads the role from the specified file. | |
/// This will replace the following method from obsolete Manager: Sitecore.Data.Serialization.Manager.LoadRole(path) | |
/// </summary> | |
/// <returns> Status code in case of fail or the result object in case of success </returns> | |
public IRoleData LoadRole(string serializationPath) | |
{ | |
try | |
{ | |
return _roleSerializationManager.LoadEntity(serializationPath); | |
} | |
catch (Exception ex) | |
{ | |
Sitecore.Diagnostics.Log.Error("Error loading the role: " + serializationPath, ex, this); | |
return null; | |
} | |
} | |
/// <summary> | |
/// Method which loads all roles from serialization | |
/// This will replace the following method from obsolete Manager: Sitecore.Data.Serialization.Manager.LoadAllRoles() | |
/// </summary> | |
/// <returns> Status codes based on action result </returns> | |
public void LoadAllRoles() | |
{ | |
try | |
{ | |
_roleSerializationManager.LoadAllEntities(); | |
} | |
catch (Exception ex) | |
{ | |
Sitecore.Diagnostics.Log.Error("Error de-serializing roles.", ex, this); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment