private SPListItem EnsureListItem(SPList list, ListItemDefinition listItemModel) { // TODO, lazy to query // BIG TODO, don't tell me, I know that var currentItem = list.Items .OfType <SPListItem>() .FirstOrDefault(i => i.Title == listItemModel.Title); InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioning, Object = currentItem, ObjectType = typeof(SPListItem), ObjectDefinition = listItemModel, ModelHost = list }); if (currentItem == null) { var newItem = list.AddItem(); newItem["Title"] = listItemModel.Title; InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioned, Object = newItem, ObjectType = typeof(SPListItem), ObjectDefinition = listItemModel, ModelHost = list }); newItem.Update(); return(newItem); } else { currentItem["Title"] = listItemModel.Title; InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioned, Object = currentItem, ObjectType = typeof(SPListItem), ObjectDefinition = listItemModel, ModelHost = list }); currentItem.Update(); return(currentItem); } }
protected virtual void ValidateProperties(SPListItem item, ListItemDefinition definition) { var assert = ServiceFactory.AssertService .NewAssert(definition, item) .ShouldNotBeNull(item) .ShouldBeEqual(m => m.Title, o => o.Title); }
protected virtual ListItem FindListItem(List list, Folder folder, ListItemDefinition definition) { var context = list.Context; var items = list.GetItems(new CamlQuery { FolderServerRelativeUrl = folder.ServerRelativeUrl, ViewXml = string.Format(@"<View> <Query> <Where> <Eq> <FieldRef Name='Title'/> <Value Type='Text'>{0}</Value> </Eq> </Where> </Query> </View>", definition.Title) }); context.Load(items); context.ExecuteQueryWithTrace(); if (items.Count > 0) { return(items[0]); } return(null); }
private SPListItem EnsureListItem(SPList list, SPFolder folder, ListItemDefinition listItemModel) { var currentItem = FindListItem(list, folder, listItemModel); InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioning, Object = currentItem, ObjectType = typeof(SPListItem), ObjectDefinition = listItemModel, ModelHost = folder }); if (currentItem == null) { TraceService.Information((int)LogEventId.ModelProvisionProcessingNewObject, "Processing new list item"); var newItem = list.Items.Add(folder.ServerRelativeUrl, SPFileSystemObjectType.File, null); MapListItemProperties(newItem, listItemModel); InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioned, Object = newItem, ObjectType = typeof(SPListItem), ObjectDefinition = listItemModel, ModelHost = folder }); newItem.Update(); return(newItem); } else { TraceService.Information((int)LogEventId.ModelProvisionProcessingExistingObject, "Processing existing list item"); MapListItemProperties(currentItem, listItemModel); InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioned, Object = currentItem, ObjectType = typeof(SPListItem), ObjectDefinition = listItemModel, ModelHost = folder }); currentItem.Update(); return(currentItem); } }
public static ListModelNode AddDemoItem(this ListModelNode node, ListItemDefinition DemoItemDefinition, ListItemFieldValuesDefinition DemoItemValues) { node.AddListItem(DemoItemDefinition, item => { item.AddListItemFieldValues(DemoItemValues); }); return(node); }
protected override void MapListItemProperties(ListItem newItem, ListItemDefinition listItemModel) { base.MapListItemProperties(newItem, listItemModel); var definition = listItemModel.WithAssertAndCast <ReusableTextItemDefinition>("model", value => value.RequireNotNull()); newItem[BuiltInInternalFieldNames.ContentTypeId] = BuiltInPublishingContentTypeId.ReusableText; newItem["ReusableText"] = definition.ReusableText; }
private void DeployInternall(SPList list, ListItemDefinition listItemModel) { if (IsDocumentLibray(list)) { throw new NotImplementedException("Please use ModuleFileDefinition to deploy files to the document libraries"); } EnsureListItem(list, listItemModel); }
private void DeployInternall(SPList list, SPFolder folder, ListItemDefinition listItemModel) { if (IsDocumentLibray(list)) { TraceService.Error((int)LogEventId.ModelProvisionCoreCall, "Please use ModuleFileDefinition to deploy files to the document libraries. Throwing SPMeta2NotImplementedException"); throw new SPMeta2NotImplementedException("Please use ModuleFileDefinition to deploy files to the document libraries"); } EnsureListItem(list, folder, listItemModel); }
protected override void ValidateProperties(ListItem item, ListItemDefinition definition) { base.ValidateProperties(item, definition); var typedDefinition = definition as ReusableTextItemDefinition; var assert = ServiceFactory.AssertService.NewAssert(typedDefinition, item); assert .ShouldNotBeNull(item) .ShouldBeEqualIfNotNullOrEmpty(m => m.ReusableText, o => o.GetReusableText()); }
private void DeployInternall(List list, ListItemDefinition listItemModel) { if (IsDocumentLibray(list)) { throw new NotImplementedException("Please use ModuleFileDefinition to deploy files to the document libraries"); } ListItem currentItem = null; InvokeOnModelEvent <ListItemDefinition, ListItem>(currentItem, ModelEventType.OnUpdating); currentItem = EnsureListItem(list, listItemModel); InvokeOnModelEvent <ListItemDefinition, ListItem>(currentItem, ModelEventType.OnUpdated); }
private void DeployInternall(List list, Folder folder, ListItemDefinition listItemModel) { if (IsDocumentLibray(list)) { TraceService.Error((int)LogEventId.ModelProvisionCoreCall, "Please use ModuleFileDefinition to deploy files to the document libraries. Throwing SPMeta2NotImplementedException"); throw new SPMeta2NotImplementedException("Please use ModuleFileDefinition to deploy files to the document libraries"); } ListItem currentItem = null; InvokeOnModelEvent <ListItemDefinition, ListItem>(currentItem, ModelEventType.OnUpdating); currentItem = EnsureListItem(list, folder, listItemModel); InvokeOnModelEvent <ListItemDefinition, ListItem>(currentItem, ModelEventType.OnUpdated); }
protected override void MapListItemProperties(ListItem newItem, ListItemDefinition listItemModel) { base.MapListItemProperties(newItem, listItemModel); var definition = listItemModel.WithAssertAndCast <ReusableItemDefinitionBase>("model", value => value.RequireNotNull()); newItem["Comments"] = definition.Comments ?? string.Empty; if (!string.IsNullOrEmpty(definition.ContentCategory)) { newItem["ContentCategory"] = definition.ContentCategory; } newItem["AutomaticUpdate"] = definition.AutomaticUpdate; newItem["ShowInRibbon"] = definition.ShowInDropDownMenu; }
protected override void ValidateProperties(SPListItem item, ListItemDefinition definition) { base.ValidateProperties(item, definition); var typedDefinition = definition as ReusableTextItemDefinition; var assert = ServiceFactory.AssertService .NewAssert(typedDefinition, item) .ShouldNotBeNull(item); if (!string.IsNullOrEmpty(typedDefinition.ReusableText)) { assert.SkipProperty(m => m.ReusableText); } else { assert.ShouldBeEqual(m => m.Title, o => o.GetReusableText()); } }
protected override void MapListItemProperties(ListItem newItem, ListItemDefinition listItemModel) { base.MapListItemProperties(newItem, listItemModel); var definition = listItemModel.WithAssertAndCast <ComposedLookItemDefinition>("model", value => value.RequireNotNull()); newItem[BuiltInInternalFieldNames.ContentTypeId] = BuiltInContentTypeId.ComposedLook; newItem["Name"] = definition.Name; SetUrlFieldValue(newItem, "MasterPageUrl", definition.MasterPageUrl, definition.MasterPageDescription); SetUrlFieldValue(newItem, "ThemeUrl", definition.ThemeUrl, definition.ThemeDescription); SetUrlFieldValue(newItem, "ImageUrl", definition.ImageUrl, definition.ImageDescription); SetUrlFieldValue(newItem, "FontSchemeUrl", definition.FontSchemeUrl, definition.FontSchemeDescription); if (definition.DisplayOrder.HasValue) { newItem["DisplayOrder"] = definition.DisplayOrder.Value; } }
protected virtual void MapListItemProperties(ListItem currentItem, ListItemDefinition definition) { if (!string.IsNullOrEmpty(definition.ContentTypeId)) { currentItem[BuiltInInternalFieldNames.ContentTypeId] = definition.ContentTypeId; } else if (!string.IsNullOrEmpty(definition.ContentTypeName)) { currentItem[BuiltInInternalFieldNames.ContentTypeId] = ContentTypeLookupService .LookupContentTypeByName(currentItem.ParentList, definition.ContentTypeName) .Id.ToString(); } FieldLookupService.EnsureDefaultValues(currentItem, definition.DefaultValues); currentItem[BuiltInInternalFieldNames.Title] = definition.Title; FieldLookupService.EnsureValues(currentItem, definition.Values, true); }
protected virtual SPListItem FindListItem(SPList list, SPFolder folder, ListItemDefinition listItemModel) { var items = list.GetItems(new SPQuery { Folder = folder, Query = string.Format(@"<Where> <Eq> <FieldRef Name='Title'/> <Value Type='Text'>{0}</Value> </Eq> </Where>", listItemModel.Title) }); if (items.Count > 0) { return(items[0]); } return(null); }
protected override void MapListItemProperties(SPListItem newItem, ListItemDefinition listItemModel) { base.MapListItemProperties(newItem, listItemModel); var definition = listItemModel.WithAssertAndCast <ComposedLookItemDefinition>("model", value => value.RequireNotNull()); // composed look // 0x00EBB0D5D32C733345B0AA3C79625DD501 newItem[SPBuiltInFieldId.ContentTypeId] = "0x00EBB0D5D32C733345B0AA3C79625DD501"; newItem["Name"] = definition.Name; SetUrlFieldValue(newItem, "MasterPageUrl", definition.MasterPageUrl, definition.MasterPageDescription); SetUrlFieldValue(newItem, "ThemeUrl", definition.ThemeUrl, definition.ThemeDescription); SetUrlFieldValue(newItem, "ImageUrl", definition.ImageUrl, definition.ImageDescription); SetUrlFieldValue(newItem, "FontSchemeUrl", definition.FontSchemeUrl, definition.FontSchemeDescription); if (definition.DisplayOrder.HasValue) { newItem["DisplayOrder"] = definition.DisplayOrder.Value; } }
protected override SPListItem FindListItem(SPList list, SPFolder folder, ListItemDefinition listItemModel) { var definition = listItemModel.WithAssertAndCast <ComposedLookItemDefinition>("model", value => value.RequireNotNull()); // first by Name var items = list.GetItems(new SPQuery { Folder = folder, Query = string.Format(@"<Where> <Eq> <FieldRef Name='Name'/> <Value Type='Text'>{0}</Value> </Eq> </Where>", definition.Name) }); if (items.Count > 0) { return(items[0]); } // by Title? items = list.GetItems(new SPQuery { Folder = folder, Query = string.Format(@"<Where> <Eq> <FieldRef Name='Title'/> <Value Type='Text'>{0}</Value> </Eq> </Where>", definition.Title) }); if (items.Count > 0) { return(items[0]); } return(null); }
protected override void ValidateProperties(ListItem item, ListItemDefinition definition) { base.ValidateProperties(item, definition); var typedDefinition = definition as ReusableItemDefinitionBase; var assert = ServiceFactory.AssertService .NewAssert(typedDefinition, item) .ShouldNotBeNull(item); if (!string.IsNullOrEmpty(typedDefinition.ContentCategory)) { assert.ShouldBeEqual(m => m.ContentCategory, o => o.GetContentCategory()); } else { assert.SkipProperty(m => m.ContentCategory); } assert .ShouldBeEqual(m => m.Comments, o => o.GetComments()) .ShouldBeEqual(m => m.AutomaticUpdate, o => o.GetAutomaticUpdate()) .ShouldBeEqual(m => m.ShowInDropDownMenu, o => o.GetShowInRibbon()); }
protected virtual void MapListItemProperties(SPListItem item, ListItemDefinition definition) { FieldLookupService.EnsureDefaultValues(item, definition.DefaultValues); if (!string.IsNullOrEmpty(definition.ContentTypeId) || !string.IsNullOrEmpty(definition.ContentTypeName)) { var list = item.ParentList; if (!string.IsNullOrEmpty(definition.ContentTypeId)) { item["ContentTypeId"] = ContentTypeLookupService.LookupListContentTypeById(list, definition.ContentTypeId); } if (!string.IsNullOrEmpty(definition.ContentTypeName)) { item["ContentTypeId"] = ContentTypeLookupService.LookupContentTypeByName(list, definition.ContentTypeName); } } item[BuiltInInternalFieldNames.Title] = definition.Title; FieldLookupService.EnsureValues(item, definition.Values, true); }
public static TModelNode AddHostListItem <TModelNode>(this TModelNode model, ListItemDefinition definition, Action <ListItemModelNode> action) where TModelNode : ModelNode, IListItemHostModelNode, new() { return(model.AddTypedDefinitionNodeWithOptions(definition, action, ModelNodeOptions.New().NoSelfProcessing())); }
public static TModelNode AddHostListItem <TModelNode>(this TModelNode model, ListItemDefinition definition) where TModelNode : ModelNode, IListItemHostModelNode, new() { return(AddHostListItem(model, definition, null)); }
public static TModelNode AddListItem <TModelNode>(this TModelNode model, ListItemDefinition definition, Action <ListItemModelNode> action) where TModelNode : ModelNode, IListItemHostModelNode, new() { return(model.AddTypedDefinitionNode(definition, action)); }
private void ValidateModel(List list, ListItemDefinition listItemModel) { }
private ListItem EnsureListItem(List list, Folder folder, ListItemDefinition listItemModel) { var context = list.Context; var currentItem = FindListItem(list, folder, listItemModel); InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioning, Object = currentItem, ObjectType = typeof(ListItem), ObjectDefinition = listItemModel, ModelHost = list }); if (currentItem == null) { TraceService.Information((int)LogEventId.ModelProvisionProcessingNewObject, "Processing new list item"); var newItem = list.AddItem(new ListItemCreationInformation { FolderUrl = folder.ServerRelativeUrl, UnderlyingObjectType = FileSystemObjectType.File, LeafName = null }); MapListItemProperties(newItem, listItemModel); InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioned, Object = newItem, ObjectType = typeof(ListItem), ObjectDefinition = listItemModel, ModelHost = list }); newItem.Update(); context.ExecuteQueryWithTrace(); return(newItem); } else { TraceService.Information((int)LogEventId.ModelProvisionProcessingExistingObject, "Processing existing list item"); MapListItemProperties(currentItem, listItemModel); InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioned, Object = currentItem, ObjectType = typeof(ListItem), ObjectDefinition = listItemModel, ModelHost = list }); currentItem.Update(); context.ExecuteQueryWithTrace(); return(currentItem); } }
public static ModelNode AddHostListItem(this ModelNode model, ListItemDefinition definition, Action <ModelNode> action) { return(model.AddDefinitionNodeWithOptions(definition, action, ModelNodeOptions.New().NoSelfProcessing())); }
public static ModelNode AddHostListItem(this ModelNode model, ListItemDefinition definition) { return(AddHostListItem(model, definition, null)); }
public static ModelNode AddListItem(this ModelNode model, ListItemDefinition definition, Action <ModelNode> action) { return(model.AddDefinitionNode(definition, action)); }
protected virtual void MapListItemProperties(SPListItem newItem, ListItemDefinition listItemModel) { newItem[BuiltInInternalFieldNames.Title] = listItemModel.Title; }
protected virtual void ValidateProperties(ListItem item, ListItemDefinition definition) { var stringCustomContentType = string.Empty; if (!string.IsNullOrEmpty(definition.ContentTypeName) || !string.IsNullOrEmpty(definition.ContentTypeId)) { if (!string.IsNullOrEmpty(definition.ContentTypeName)) { stringCustomContentType = ContentTypeLookupService .LookupContentTypeByName(item.ParentList, definition.ContentTypeName) .Name; } } var assert = ServiceFactory.AssertService .NewAssert(definition, item) .ShouldNotBeNull(item); assert .ShouldBeEqual(m => m.Title, o => o.DisplayName); if (!string.IsNullOrEmpty(definition.ContentTypeId)) { // TODO } else { assert.SkipProperty(m => m.ContentTypeId, "ContentTypeId is null or empty. Skipping."); } if (!string.IsNullOrEmpty(definition.ContentTypeName)) { assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(def => def.ContentTypeName); var currentContentTypeName = d.ContentType.Name; var isValis = stringCustomContentType == currentContentTypeName; return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = null, IsValid = isValis }); }); } else { assert.SkipProperty(m => m.ContentTypeName, "ContentTypeName is null or empty. Skipping."); } if (definition.DefaultValues.Count > 0) { assert.ShouldBeEqual((p, s, d) => { var isValid = true; foreach (var srcValue in s.DefaultValues) { // big TODO here for == != if (!string.IsNullOrEmpty(srcValue.FieldName)) { if (d[srcValue.FieldName].ToString() != srcValue.Value.ToString()) { isValid = false; } } if (!isValid) { break; } } var srcProp = s.GetExpressionValue(def => def.DefaultValues); return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = null, IsValid = isValid }); }); } else { assert.SkipProperty(m => m.DefaultValues, "DefaultValues.Count == 0. Skipping."); } if (definition.Values.Count > 0) { assert.ShouldBeEqual((p, s, d) => { var isValid = true; foreach (var srcValue in s.Values) { // big TODO here for == != if (!string.IsNullOrEmpty(srcValue.FieldName)) { if (d[srcValue.FieldName].ToString() != srcValue.Value.ToString()) { isValid = false; } } if (!isValid) { break; } } var srcProp = s.GetExpressionValue(def => def.Values); return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = null, IsValid = isValid }); }); } else { assert.SkipProperty(m => m.Values, "Values.Count == 0. Skipping."); } }