protected virtual void ValidateProperties(SPListItem item, ListItemDefinition definition)
 {
     var assert = ServiceFactory.AssertService
                   .NewAssert(definition, item)
                         .ShouldNotBeNull(item)
                         .ShouldBeEqual(m => m.Title, o => o.Title);
 }
Пример #2
0
        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 override void MapListItemProperties(SPListItem 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;
        }
Пример #4
0
        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);
        }
Пример #5
0
        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());
        }
Пример #7
0
        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);
        }
        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 ListItem FindListItem(List list, Folder folder, ListItemDefinition definition)
        {
            var context = list.Context;

            // by name
            var items = list.GetItems(new CamlQuery
            {
                FolderServerRelativeUrl = folder.ServerRelativeUrl,
                ViewXml = string.Format(@"<View>
                                          <Query>
                                             <Where>
                                                 <Eq>
                                                     <FieldRef Name='Name'/>
                                                     <Value Type='Text'>{0}</Value>
                                                 </Eq>
                                                </Where>
                                            </Query>
                                         </View>", definition.Title)
            });

            context.Load(items);
            context.ExecuteQueryWithTrace();

            if (items.Count > 0)
                return items[0];

            // by title
            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;
        }
        protected override void ValidateProperties(ListItem 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());
        }
Пример #11
0
        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<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;

        }
Пример #13
0
        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 ValidateProperties(SPListItem 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 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;
        }
Пример #17
0
        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 override void ValidateProperties(SPListItem item, ListItemDefinition definition)
        {
            base.ValidateProperties(item, definition);

            var typedDefinition = definition as ComposedLookItemDefinition;

            var assert = ServiceFactory.AssertService
                        .NewAssert(typedDefinition, item)
                        .ShouldNotBeNull(item)
                        .ShouldBeEqual(m => m.Name, o => o.GetComposedLookName());

            if (typedDefinition.DisplayOrder.HasValue)
                assert.ShouldBeEqual(m => m.DisplayOrder, o => o.GetComposedLookDisplayOrder());
            else
                assert.SkipProperty(m => m.DisplayOrder, "DisplayOrder is NULL");

            // master page
            if (!string.IsNullOrEmpty(typedDefinition.MasterPageUrl))
            {
                var urlValue = item.GetComposedLookMasterPageUrl();

                assert.ShouldBeEqual((p, s, d) =>
                {
                    var srcProp = s.GetExpressionValue(m => m.MasterPageUrl);
                    var isValid = (urlValue != null) && (urlValue.Url == s.MasterPageUrl);

                    return new PropertyValidationResult
                    {
                        Tag = p.Tag,
                        Src = srcProp,
                        Dst = null,
                        IsValid = isValid
                    };
                });

                assert.ShouldBeEqual((p, s, d) =>
                {
                    var srcProp = s.GetExpressionValue(m => m.MasterPageDescription);
                    var isValid = (urlValue != null) && (urlValue.Description == s.MasterPageDescription);

                    return new PropertyValidationResult
                    {
                        Tag = p.Tag,
                        Src = srcProp,
                        Dst = null,
                        IsValid = isValid
                    };
                });
            }
            else
            {
                assert.SkipProperty(m => m.MasterPageUrl, "MasterPageUrl is NULL");
                assert.SkipProperty(m => m.MasterPageDescription, "MasterPageDescription is NULL");
            }

            // font scheme
            if (!string.IsNullOrEmpty(typedDefinition.FontSchemeUrl))
            {
                var urlValue = item.GetComposedLookFontSchemeUrl();

                assert.ShouldBeEqual((p, s, d) =>
                {
                    var srcProp = s.GetExpressionValue(m => m.FontSchemeUrl);
                    var isValid = (urlValue != null) && (urlValue.Url == s.FontSchemeUrl);

                    return new PropertyValidationResult
                    {
                        Tag = p.Tag,
                        Src = srcProp,
                        Dst = null,
                        IsValid = isValid
                    };
                });

                assert.ShouldBeEqual((p, s, d) =>
                {
                    var srcProp = s.GetExpressionValue(m => m.FontSchemeDescription);
                    var isValid = (urlValue != null) && (urlValue.Description == s.FontSchemeDescription);

                    return new PropertyValidationResult
                    {
                        Tag = p.Tag,
                        Src = srcProp,
                        Dst = null,
                        IsValid = isValid
                    };
                });
            }
            else
            {
                assert.SkipProperty(m => m.FontSchemeUrl, "MasterPageUrl is NULL");
                assert.SkipProperty(m => m.FontSchemeDescription, "MasterPageDescription is NULL");
            }

            // image url
            if (!string.IsNullOrEmpty(typedDefinition.ImageUrl))
            {
                var urlValue = item.GetComposedLookImageUrl();

                assert.ShouldBeEqual((p, s, d) =>
                {
                    var srcProp = s.GetExpressionValue(m => m.ImageUrl);
                    var isValid = (urlValue != null) && (urlValue.Url == s.ImageUrl);

                    return new PropertyValidationResult
                    {
                        Tag = p.Tag,
                        Src = srcProp,
                        Dst = null,
                        IsValid = isValid
                    };
                });

                assert.ShouldBeEqual((p, s, d) =>
                {
                    var srcProp = s.GetExpressionValue(m => m.ImageDescription);
                    var isValid = (urlValue != null) && (urlValue.Description == s.ImageDescription);

                    return new PropertyValidationResult
                    {
                        Tag = p.Tag,
                        Src = srcProp,
                        Dst = null,
                        IsValid = isValid
                    };
                });
            }
            else
            {
                assert.SkipProperty(m => m.ImageUrl, "ImageUrl is NULL");
                assert.SkipProperty(m => m.ImageDescription, "ImageDescription is NULL");
            }

            // theme url
            if (!string.IsNullOrEmpty(typedDefinition.ThemeUrl))
            {
                var urlValue = item.GetComposedLookThemeUrl();

                assert.ShouldBeEqual((p, s, d) =>
                {
                    var srcProp = s.GetExpressionValue(m => m.ThemeUrl);
                    var isValid = (urlValue != null) && (urlValue.Url == s.ThemeUrl);

                    return new PropertyValidationResult
                    {
                        Tag = p.Tag,
                        Src = srcProp,
                        Dst = null,
                        IsValid = isValid
                    };
                });

                assert.ShouldBeEqual((p, s, d) =>
                {
                    var srcProp = s.GetExpressionValue(m => m.ThemeDescription);
                    var isValid = (urlValue != null) && (urlValue.Description == s.ThemeDescription);

                    return new PropertyValidationResult
                    {
                        Tag = p.Tag,
                        Src = srcProp,
                        Dst = null,
                        IsValid = isValid
                    };
                });
            }
            else
            {
                assert.SkipProperty(m => m.ThemeUrl, "ThemeUrl is NULL");
                assert.SkipProperty(m => m.ThemeDescription, "ThemeDescription is NULL");
            }
        }
        protected virtual void ValidateProperties(SPListItem item, ListItemDefinition definition)
        {
            var assert = ServiceFactory.AssertService
                          .NewAssert(definition, item)
                                .ShouldNotBeNull(item)
                                .ShouldBeEqual(m => m.Title, o => o.Title);


            if (!string.IsNullOrEmpty(definition.ContentTypeId))
            {

            }
            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"] as string;

                    var isValis = s.ContentTypeName == 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.Any())
            {
                assert.ShouldBeEqual((p, s, d) =>
                {
                    var srcProp = s.GetExpressionValue(m => m.DefaultValues);

                    var isValid = true;

                    foreach (var value in definition.DefaultValues)
                    {
                        object itemValue = null;

                        if (value.FieldId.HasValue)
                            itemValue = item[value.FieldId.Value];
                        else
                            itemValue = item[value.FieldName];

                        if (!Equals(itemValue, value.Value))
                        {
                            isValid = false;
                        }
                    }

                    return new PropertyValidationResult
                    {
                        Tag = p.Tag,
                        Src = srcProp,
                        Dst = null,
                        IsValid = isValid
                    };
                });
            }
            else
            {
                assert.SkipProperty(m => m.DefaultValues, "DefaultValues is empty. Skipping.");
            }

            if (definition.Values.Count > 0)
            {
                assert.ShouldBeEqual((p, s, d) =>
                {
                    var srcProp = s.GetExpressionValue(m => m.Values);

                    var isValid = true;

                    foreach (var value in definition.Values)
                    {
                        object itemValue = null;

                        if (value.FieldId.HasValue)
                            itemValue = item[value.FieldId.Value];
                        else
                            itemValue = item[value.FieldName];

                        if (!Equals(itemValue, value.Value))
                        {
                            isValid = false;
                        }
                    }

                    return new PropertyValidationResult
                    {
                        Tag = p.Tag,
                        Src = srcProp,
                        Dst = null,
                        IsValid = isValid
                    };
                });
            }
            else
            {
                assert.SkipProperty(m => m.Values, "Values.Count == 0. Skipping.");
            }
        }
Пример #20
0
 public static ModelNode AddHostListItem(this ModelNode model, ListItemDefinition definition)
 {
     return AddHostListItem(model, definition, null);
 }
Пример #21
0
 public static ModelNode AddHostListItem(this ModelNode model, ListItemDefinition definition, Action<ModelNode> action)
 {
     return model.AddDefinitionNodeWithOptions(definition, action, ModelNodeOptions.New().NoSelfProcessing());
 }
Пример #22
0
        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);
        }
Пример #23
0
 public static ModelNode AddListItem(this ModelNode model, ListItemDefinition definition, Action<ModelNode> action)
 {
     return model.AddDefinitionNode(definition, action);
 }
 private void ValidateModel(List list, ListItemDefinition listItemModel)
 {
 }
Пример #25
0
        private ListItem EnsureListItem(List list, ListItemDefinition listItemModel)
        {
            var context = list.Context;

            // TODO, lazy to query
            var items = list.GetItems(CamlQuery.CreateAllItemsQuery());

            context.Load(items);
            context.ExecuteQuery();

            // BIG TODO, don't tell me, I know that
            var currentItem = items.FirstOrDefault(i => i["Title"] != null &&
                    (i["Title"].ToString() == listItemModel.Title));

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model = null,
                EventType = ModelEventType.OnProvisioning,
                Object = currentItem,
                ObjectType = typeof(ListItem),
                ObjectDefinition = listItemModel,
                ModelHost = list
            });

            if (currentItem == null)
            {
                var newItem = list.AddItem(new ListItemCreationInformation());

                newItem["Title"] = listItemModel.Title;

                InvokeOnModelEvent(this, new ModelEventArgs
                {
                    CurrentModelNode = null,
                    Model = null,
                    EventType = ModelEventType.OnProvisioned,
                    Object = newItem,
                    ObjectType = typeof(ListItem),
                    ObjectDefinition = listItemModel,
                    ModelHost = list
                });

                newItem.Update();

                context.ExecuteQuery();

                return newItem;
            }
            else
            {
                currentItem["Title"] = listItemModel.Title;

                InvokeOnModelEvent(this, new ModelEventArgs
                {
                    CurrentModelNode = null,
                    Model = null,
                    EventType = ModelEventType.OnProvisioned,
                    Object = currentItem,
                    ObjectType = typeof(ListItem),
                    ObjectDefinition = listItemModel,
                    ModelHost = list
                });

                currentItem.Update();

                context.ExecuteQuery();

                return currentItem;
            }
        }
        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.");
            }
        }
 private void ValidateListItem(SPList list, ListItemDefinition listItemModel)
 {
     // TODO
 }
Пример #28
0
        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;
            }
        }
Пример #29
0
 protected virtual void MapListItemProperties(SPListItem newItem, ListItemDefinition listItemModel)
 {
     newItem[BuiltInInternalFieldNames.Title] = listItemModel.Title;
 }
Пример #30
0
        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;
            }
        }