public virtual void WriteSerializedRole(IRoleData roleData, Stream outputStream) { Assert.ArgumentNotNull(roleData, nameof(roleData)); Assert.ArgumentNotNull(outputStream, "outputStream"); var memberOfRoles = roleData.MemberOfRoles; using (var writer = new YamlWriter(outputStream, 4096, true)) { writer.WriteMap("Role", roleData.RoleName); if (memberOfRoles.Any()) { writer.WriteMap("MemberOf"); writer.IncreaseIndent(); foreach (var memberOfRole in memberOfRoles) { writer.WriteMap("Role", memberOfRole); } writer.DecreaseIndent(); } } }
public virtual void WriteSerializedUser(SyncUser userData, Stream outputStream) { Assert.ArgumentNotNull(userData, nameof(userData)); Assert.ArgumentNotNull(outputStream, "outputStream"); using (var writer = new YamlWriter(outputStream, 4096, true)) { writer.WriteMap("Username", userData.UserName); writer.WriteMap("Email", userData.Email ?? string.Empty); writer.WriteMap("Comment", userData.Comment ?? string.Empty); writer.WriteMap("Created", userData.CreationDate.ToString("O")); writer.WriteMap("IsApproved", userData.IsApproved.ToString()); if (userData.ProfileProperties.Any()) { writer.WriteMap("Properties"); writer.IncreaseIndent(); userData.ProfileProperties.Sort((x, y) => string.Compare(x.Name, y.Name, StringComparison.Ordinal)); userData.ProfileProperties.ForEach(profileProperty => { writer.WriteBeginListItem("Key", profileProperty.Name); writer.WriteMap("Value", GetSerializedProfileContent(profileProperty)); writer.WriteMap("ValueType", profileProperty.Content.GetType().AssemblyQualifiedName); writer.WriteMap("IsCustom", profileProperty.IsCustomProperty.ToString()); }); writer.DecreaseIndent(); } if (userData.Roles.Any()) { userData.Roles.Sort(); writer.WriteMap("Roles"); writer.IncreaseIndent(); userData.Roles.ForEach(roleName => { writer.WriteMap("MemberOf", roleName); }); writer.DecreaseIndent(); } } }