private ContentListType ManageContentListType(Dictionary<string, FieldDescriptor> fieldInfoList, Dictionary<string, List<string>> oldBindings, bool modify, out List<FieldSetting> fieldSettings)
{
fieldSettings = new List<FieldSetting>();
if (!modify)
{
//-- Load
foreach (string name in fieldInfoList.Keys)
fieldSettings.Add(FieldSetting.Create(fieldInfoList[name], oldBindings[name]));
return this.ContentListType;
}
SchemaEditor editor = new SchemaEditor();
editor.Load();
bool hasChanges = false;
var listType = this.ContentListType;
Dictionary<string, List<string>> newBindings = new Dictionary<string, List<string>>();
SlotTable slotTable = new SlotTable(oldBindings);
if (listType == null)
{
//-- new
listType = editor.CreateContentListType(Guid.NewGuid().ToString());
foreach (string name in fieldInfoList.Keys)
fieldSettings.Add(CreateNewFieldType(fieldInfoList[name], newBindings, listType, slotTable, editor));
hasChanges = true;
}
else
{
//-- merge
listType = editor.ContentListTypes[listType.Name];
hasChanges |= RemoveUnusedFields(fieldInfoList, oldBindings, listType, editor);
foreach (string name in fieldInfoList.Keys)
{
FieldSetting origField = GetFieldTypeByName(name, _fieldSettings);
if (origField == null)
{
fieldSettings.Add(CreateNewFieldType(fieldInfoList[name], newBindings, listType, slotTable, editor));
hasChanges = true;
}
else
{
List<string> bindList = new List<string>(origField.Bindings.ToArray());
fieldSettings.Add(FieldSetting.Create(fieldInfoList[name], bindList));
newBindings.Add(name, bindList);
}
}
}
if (hasChanges)
editor.Register();
this.ContentListBindings = newBindings;
return ActiveSchema.ContentListTypes[listType.Name];
}
private FieldSetting CreateNewFieldType(FieldDescriptor fieldInfo, Dictionary<string, List<string>> newBindings, ContentListType listType, SlotTable slotTable, SchemaEditor editor)