private void ProcessProperty(PropertyModelHost host, PropertyDefinition property) { if (host.CurrentListItem != null) ProcessListItemProperty(host.CurrentListItem, property); else if (host.CurrentList != null) ProcessListProperty(host.CurrentList, property); else if (host.CurrentWeb != null) ProcessWebProperty(host.CurrentWeb, property); }
public override void WithResolvingModelHost(object modelHost, DefinitionBase model, Type childModelType, Action<object> action) { var folderHost = modelHost.WithAssertAndCast<FolderModelHost>("modelHost", value => value.RequireNotNull()); var moduleFile = model.WithAssertAndCast<ModuleFileDefinition>("model", value => value.RequireNotNull()); var web = folderHost.CurrentWeb; var file = ProcessFile(folderHost, moduleFile); var context = file.Context; if (childModelType == typeof(ListItemFieldValueDefinition)) { var fileListItem = file.ListItemAllFields; context.Load(fileListItem, i => i.Id, i => i.ParentList); context.ExecuteQuery(); var list = fileListItem.ParentList; var item = list.GetItemById(fileListItem.Id); context.ExecuteQuery(); var listItemPropertyHost = new ListItemFieldValueModelHost { CurrentItem = item }; action(listItemPropertyHost); item.Update(); context.ExecuteQuery(); } else if (childModelType == typeof(PropertyDefinition)) { var propModelHost = new PropertyModelHost { CurrentFile = file }; action(propModelHost); context.ExecuteQuery(); } else { action(file); context.ExecuteQuery(); } }