in MySql.Web/src/ProfileProvider.cs [545:602]
private int EncodeProfileData(SettingsPropertyValueCollection collection, bool isAuthenticated,
ref string index, ref string stringData, ref byte[] binaryData)
{
bool itemsToSave = false;
// first we need to determine if there are any items that need saving
// this is an optimization
foreach (SettingsPropertyValue value in collection)
{
if (!value.IsDirty) continue;
if (value.Property.Attributes["AllowAnonymous"].Equals(false) &&
!isAuthenticated) continue;
itemsToSave = true;
break;
}
if (!itemsToSave) return 0;
StringBuilder indexBuilder = new StringBuilder();
StringBuilder stringDataBuilder = new StringBuilder();
MemoryStream binaryBuilder = new MemoryStream();
int count = 0;
// ok, we have some values that need to be saved so we go back through
foreach (SettingsPropertyValue value in collection)
{
// if the value has not been written to and is still using the default value
// no need to save it
if (value.UsingDefaultValue && !value.IsDirty) continue;
// we don't save properties that require the user to be authenticated when the
// current user is not authenticated.
if (value.Property.Attributes["AllowAnonymous"].Equals(false) &&
!isAuthenticated) continue;
count++;
object propValue = value.SerializedValue;
if ((value.Deserialized && value.PropertyValue == null) ||
value.SerializedValue == null)
indexBuilder.AppendFormat("{0}//0/-1:", value.Name);
else if (propValue is string)
{
indexBuilder.AppendFormat("{0}/0/{1}/{2}:", value.Name,
stringDataBuilder.Length, (propValue as string).Length);
stringDataBuilder.Append(propValue);
}
else
{
byte[] binaryValue = (byte[])propValue;
indexBuilder.AppendFormat("{0}/1/{1}/{2}:", value.Name,
binaryBuilder.Position, binaryValue.Length);
binaryBuilder.Write(binaryValue, 0, binaryValue.Length);
}
}
index = indexBuilder.ToString();
stringData = stringDataBuilder.ToString();
binaryData = binaryBuilder.ToArray();
return count;
}