Esempio n. 1
0
        internal static UpdatePropertyBagRequest GetUpdatePropertyBagRequest <T>(T propertyValueContainer) where T : IDataModelWithContext
        {
            UpdatePropertyBagRequest result = new UpdatePropertyBagRequest();

            if ((propertyValueContainer as IDataModelParent).Parent is IFolder)
            {
                result = new FolderPropertyBagUpdateRequest(((propertyValueContainer as IDataModelParent).Parent as IFolder).UniqueId.ToString());
            }
            else if ((propertyValueContainer as IDataModelParent).Parent is IFile)
            {
                if (((propertyValueContainer as IDataModelParent).Parent as IFile).IsPropertyAvailable(p => p.ServerRelativeUrl))
                {
                    result = new FilePropertyBagUpdateRequest(((propertyValueContainer as IDataModelParent).Parent as IFile).ServerRelativeUrl);
                }
                else
                {
                    throw new ClientException(ErrorType.Unsupported, PnPCoreResources.Exception_Unsupported_FileServerRelativeUrlNotLoaded);
                }
            }

            result.SiteId = propertyValueContainer.PnPContext.Site.Id.ToString();
            result.WebId  = propertyValueContainer.PnPContext.Web.Id.ToString();

            return(result);
        }
        public void UpdatePropertyBag_Test_BuildUpdateWebProperty()
        {
            UpdatePropertyBagRequest updatePropertyBagRequest = new UpdatePropertyBagRequest()
            {
                SiteId = "test-site-id",
                WebId  = "test-web-id"
            };

            updatePropertyBagRequest.FieldsToUpdate.Add(new CSOMItemField()
            {
                FieldName  = "TestProperty",
                FieldValue = "TestPropertyValue",
                FieldType  = "String"
            });
            IIdProvider idProvider = new IteratorIdProvider();
            var         request    = updatePropertyBagRequest.GetRequest(idProvider);

            var firstPart  = request[0];
            var secondPart = request[1];

            string setValuePart           = "<Method Name=\"SetFieldValue\" Id=\"1\" ObjectPathId=\"3\"><Parameters><Parameter Type=\"String\">TestProperty</Parameter><Parameter Type=\"String\">TestPropertyValue</Parameter></Parameters></Method>";
            string allPropertiesPath      = "<Property Id=\"3\" ParentId=\"2\" Name=\"AllProperties\" />";
            string updatePropertiesMethod = "<Method Name=\"Update\" Id=\"1\" ObjectPathId=\"2\"></Method>";
            string webIdentity            = "<Identity Id=\"2\" Name=\"121a659f-e03e-2000-4281-1212829d67dd|740c6a0b-85e2-48a0-a494-e0f1759d4aa7:site:test-site-id:web:test-web-id\" />";

            Assert.AreEqual(setValuePart, firstPart.Action.ToString());
            Assert.AreEqual(allPropertiesPath, firstPart.ObjectPath.ToString());
            Assert.AreEqual(updatePropertiesMethod, secondPart.Action.ToString());
            Assert.AreEqual(webIdentity, secondPart.ObjectPath.ToString());
        }