Beispiel #1
0
        private void ProcessFieldValue(ListItemFieldValueModelHost modelHost, ListItem listItem, ListItemFieldValueDefinition fieldValue)
        {
            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model            = null,
                EventType        = ModelEventType.OnProvisioning,
                Object           = listItem,
                ObjectType       = typeof(ListItem),
                ObjectDefinition = fieldValue,
                ModelHost        = modelHost
            });

            if (!string.IsNullOrEmpty(fieldValue.FieldName))
            {
                listItem[fieldValue.FieldName] = fieldValue.Value;
            }

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model            = null,
                EventType        = ModelEventType.OnProvisioned,
                Object           = listItem,
                ObjectType       = typeof(ListItem),
                ObjectDefinition = fieldValue,
                ModelHost        = modelHost
            });
        }
        public override void WithResolvingModelHost(object modelHost, DefinitionBase model, Type childModelType, Action <object> action)
        {
            var list          = modelHost.WithAssertAndCast <List>("modelHost", value => value.RequireNotNull());
            var listItemModel = model.WithAssertAndCast <ListItemDefinition>("model", value => value.RequireNotNull());

            var item    = EnsureListItem(list, listItemModel);
            var context = list.Context;

            if (childModelType == typeof(ListItemFieldValueDefinition))
            {
                // naaaaah, just gonna get a new one list item
                // keep it simple and safe, really really really safe with all that SharePoint stuff...
                var currentItem = list.GetItemById(item.Id);

                context.Load(currentItem);
                context.ExecuteQuery();

                var listItemPropertyHost = new ListItemFieldValueModelHost
                {
                    CurrentItem = currentItem
                };

                action(listItemPropertyHost);

                currentItem.Update();

                context.ExecuteQuery();
            }
        }
Beispiel #3
0
        public override void WithResolvingModelHost(object modelHost, DefinitionBase model, Type childModelType, Action <object> action)
        {
            var listModeHost  = modelHost.WithAssertAndCast <ListModelHost>("modelHost", value => value.RequireNotNull());
            var listItemModel = model.WithAssertAndCast <ListItemDefinition>("model", value => value.RequireNotNull());

            List   list       = null;
            Folder rootFolder = null;

            if (modelHost is ListModelHost)
            {
                list       = (modelHost as ListModelHost).HostList;
                rootFolder = (modelHost as ListModelHost).HostList.RootFolder;

                if (!rootFolder.IsPropertyAvailable("ServerRelativeUrl"))
                {
                    rootFolder.Context.Load(rootFolder, f => f.ServerRelativeUrl);
                    rootFolder.Context.ExecuteQueryWithTrace();
                }
            }
            else if (modelHost is FolderModelHost)
            {
                list       = (modelHost as FolderModelHost).CurrentList;
                rootFolder = (modelHost as FolderModelHost).CurrentListItem.Folder;

                if (!rootFolder.IsPropertyAvailable("ServerRelativeUrl"))
                {
                    rootFolder.Context.Load(rootFolder, f => f.ServerRelativeUrl);
                    rootFolder.Context.ExecuteQueryWithTrace();
                }
            }

            var item    = EnsureListItem(list, rootFolder, listItemModel);
            var context = list.Context;

            // naaaaah, just gonna get a new one list item
            // keep it simple and safe, really really really safe with all that SharePoint stuff...
            // var currentItem = list.GetItemById(item.Id);

            //context.Load(currentItem);
            //context.ExecuteQueryWithTrace();

            if (childModelType == typeof(ListItemFieldValueDefinition))
            {
                var listItemPropertyHost = new ListItemFieldValueModelHost
                {
                    CurrentItem = item
                };

                action(listItemPropertyHost);
            }
            else
            {
                action(item);
            }

            item.Update();
            context.ExecuteQueryWithTrace();
        }
        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.ExecuteQueryWithTrace();

                var list = fileListItem.ParentList;
                var item = list.GetItemById(fileListItem.Id);

                context.ExecuteQueryWithTrace();

                var listItemPropertyHost = new ListItemFieldValueModelHost
                {
                    CurrentItem = item
                };

                action(listItemPropertyHost);

                item.Update();

                context.ExecuteQueryWithTrace();
            }
            else if (childModelType == typeof(PropertyDefinition))
            {
                var propModelHost = new PropertyModelHost
                {
                    CurrentFile = file
                };

                action(propModelHost);

                context.ExecuteQueryWithTrace();
            }
            else
            {
                action(file);

                context.ExecuteQueryWithTrace();
            }
        }
Beispiel #5
0
        private void ProcessFieldValue(ListItemFieldValueModelHost modelHost, ListItem listItem, ListItemFieldValueDefinition fieldValue)
        {
            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model            = null,
                EventType        = ModelEventType.OnProvisioning,
                Object           = listItem,
                ObjectType       = typeof(ListItem),
                ObjectDefinition = fieldValue,
                ModelHost        = modelHost
            });

            if (!string.IsNullOrEmpty(fieldValue.FieldName))
            {
                TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Processing field value with Name: [{0}] and value: [{1}]",
                                           new object[]
                {
                    fieldValue.FieldName,
                    fieldValue.Value
                });

                listItem[fieldValue.FieldName] = fieldValue.Value;
            }

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