public void CanSetCDataV3PlainProperty()
        {
            var propName  = string.Format("prop_{0}", Guid.NewGuid().ToString("N"));
            var propValue = string.Format("{0} {1} {2}", Guid.NewGuid().ToString("N"), Guid.NewGuid().ToString("N"), Guid.NewGuid().ToString("N"));

            var updatedDef = WebpartXmlExtensions
                             .LoadWebpartXmlDocument(ResourceReaderUtils.ReadFromResourceName(GetType().Assembly, RegWebparts.V3.TeamTasks))
                             .SetOrUpdateProperty(propName, propValue, true)
                             .ToString();

            var updatedProp = WebpartXmlExtensions
                              .LoadWebpartXmlDocument(updatedDef)
                              .GetProperty(propName);

            Assert.AreEqual(propValue, updatedProp);
        }
        public void CanSetContentEditor_CDataProperty()
        {
            var propName  = "Content";
            var propValue = string.Format("{0} {1} {2}", Guid.NewGuid().ToString("N"), Guid.NewGuid().ToString("N"), Guid.NewGuid().ToString("N"));

            var updatedDef = WebpartXmlExtensions
                             .LoadWebpartXmlDocument(ResourceReaderUtils.ReadFromResourceName(GetType().Assembly, RegWebparts.Base.ContentEditor))
                             .SetOrUpdateContentEditorWebPartProperty(propName, propValue, true)
                             .ToString();

            var updatedProp = WebpartXmlExtensions
                              .LoadWebpartXmlDocument(updatedDef)
                              .GetContentEditorWebPartProperty(propName);

            Assert.AreEqual(propValue, updatedProp);
        }
Example #3
0
        protected override string GetWebpartXmlDefinition(ListItemModelHost listItemModelHost, WebPartDefinitionBase webPartModel)
        {
            var definition = webPartModel.WithAssertAndCast <RefinementScriptWebPartDefinition>("model", value => value.RequireNotNull());
            var xml        = WebpartXmlExtensions.LoadWebpartXmlDocument(ProcessCommonWebpartProperties(BuiltInWebPartTemplates.RefinementScriptWebPart, webPartModel));

            if (!string.IsNullOrEmpty(definition.SelectedRefinementControlsJson))
            {
                xml.SetOrUpdateProperty("SelectedRefinementControlsJson", definition.SelectedRefinementControlsJson);
            }

            if (!string.IsNullOrEmpty(definition.EmptyMessage))
            {
                xml.SetOrUpdateProperty("EmptyMessage", definition.EmptyMessage);
            }


            return(xml.ToString());
        }
Example #4
0
        protected override string GetWebpartXmlDefinition(ListItemModelHost listItemModelHost, WebPartDefinitionBase webPartModel)
        {
            var wpModel = webPartModel.WithAssertAndCast <ListViewWebPartDefinition>("model", value => value.RequireNotNull());

            var bindContext = LookupBindContext(listItemModelHost, wpModel);

            var webId = listItemModelHost.HostWeb.Id;

            var wpXml = WebpartXmlExtensions.LoadWebpartXmlDocument(BuiltInWebPartTemplates.ListViewWebPart)
                        .SetOrUpdateListVieweWebPartProperty("ListName", bindContext.ListId.ToString("B"))
                        .SetOrUpdateListVieweWebPartProperty("ListId", bindContext.ListId.ToString("D").ToLower())
                        .SetOrUpdateListVieweWebPartProperty("WebId", webId.ToString("D").ToLower())
                        //.SetOrUpdateListVieweWebPartProperty("ViewGuid", bindContext.ViewId.ToString("D").ToLower())
                        .SetTitleUrl(bindContext.TitleUrl)
                        .ToString();

            return(wpXml);
        }
Example #5
0
        protected override string GetWebpartXmlDefinition(ListItemModelHost listItemModelHost, WebPartDefinitionBase webPartModel)
        {
            if (!listItemModelHost.HostWeb.IsObjectPropertyInstantiated("Id"))
            {
                var webContext = listItemModelHost.HostWeb.Context;
                webContext.Load(listItemModelHost.HostWeb, w => w.Id);
                webContext.ExecuteQueryWithTrace();
            }

            var webId = listItemModelHost.HostWeb.Id.ToString();

            var wpModel = webPartModel.WithAssertAndCast <ClientWebPartDefinition>("model", value => value.RequireNotNull());
            var wpXml   = WebpartXmlExtensions
                          .LoadWebpartXmlDocument(BuiltInWebPartTemplates.ClientWebPart)
                          .SetOrUpdateProperty("FeatureId", wpModel.FeatureId.ToString())
                          .SetOrUpdateProperty("ProductId", wpModel.ProductId.ToString())
                          .SetOrUpdateProperty("WebPartName", wpModel.WebPartName)
                          .SetOrUpdateProperty("ProductWebId", webId)
                          .ToString();

            return(wpXml);
        }
Example #6
0
        protected override string GetWebpartXmlDefinition(ListItemModelHost listItemModelHost, WebPartDefinitionBase webPartModel)
        {
            var typedDefinition = webPartModel.WithAssertAndCast <ContentByQueryWebPartDefinition>("model", value => value.RequireNotNull());
            var wpXml           = WebpartXmlExtensions.LoadWebpartXmlDocument(this.ProcessCommonWebpartProperties(BuiltInWebPartTemplates.ContentByQueryWebPart, webPartModel));

            // reset SortBy initially
            // it is set to {8c06beca-0777-48f7-91c7-6da68bc07b69} initially
            //wpXml.SetOrUpdateProperty("SortBy", string.Empty);

            var context = listItemModelHost.HostClientContext;

            // xslt links
            if (!string.IsNullOrEmpty(typedDefinition.MainXslLink))
            {
                var linkValue = typedDefinition.MainXslLink;

                TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Original MainXslLink: [{0}]", linkValue);

                linkValue = TokenReplacementService.ReplaceTokens(new TokenReplacementContext
                {
                    Value   = linkValue,
                    Context = listItemModelHost
                }).Value;

                TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Token replaced MainXslLink: [{0}]", linkValue);

                wpXml.SetOrUpdateProperty("MainXslLink", linkValue);
            }

            if (!string.IsNullOrEmpty(typedDefinition.ItemXslLink))
            {
                var linkValue = typedDefinition.ItemXslLink;

                TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Original ItemXslLink: [{0}]", linkValue);

                linkValue = TokenReplacementService.ReplaceTokens(new TokenReplacementContext
                {
                    Value   = linkValue,
                    Context = listItemModelHost
                }).Value;

                TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Token replaced ItemXslLink: [{0}]", linkValue);

                wpXml.SetOrUpdateProperty("ItemXslLink", linkValue);
            }

            if (!string.IsNullOrEmpty(typedDefinition.HeaderXslLink))
            {
                var linkValue = typedDefinition.HeaderXslLink;

                TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Original HeaderXslLink: [{0}]", linkValue);

                linkValue = TokenReplacementService.ReplaceTokens(new TokenReplacementContext
                {
                    Value   = linkValue,
                    Context = listItemModelHost
                }).Value;

                TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Token replaced HeaderXslLink: [{0}]", linkValue);

                wpXml.SetOrUpdateProperty("HeaderXslLink", linkValue);
            }

            // styles
            if (!string.IsNullOrEmpty(typedDefinition.ItemStyle))
            {
                wpXml.SetItemStyle(typedDefinition.ItemStyle);
            }

            if (!string.IsNullOrEmpty(typedDefinition.GroupStyle))
            {
                wpXml.SetGroupStyle(typedDefinition.GroupStyle);
            }


            // cache settings
            if (typedDefinition.UseCache.HasValue)
            {
                wpXml.SetUseCache(typedDefinition.UseCache.ToString());
            }

            if (typedDefinition.CacheXslStorage.HasValue)
            {
                wpXml.SetOrUpdateProperty("CacheXslStorage", typedDefinition.CacheXslStorage.ToString());
            }

            if (typedDefinition.CacheXslTimeOut.HasValue)
            {
                wpXml.SetOrUpdateProperty("CacheXslTimeOut", typedDefinition.CacheXslTimeOut.ToString());
            }

            // item limit
            if (typedDefinition.ItemLimit.HasValue)
            {
                wpXml.SetOrUpdateProperty("ItemLimit", typedDefinition.ItemLimit.ToString());
            }

            // mappings
            if (!string.IsNullOrEmpty(typedDefinition.DataMappings))
            {
                wpXml.SetOrUpdateProperty("DataMappings", typedDefinition.DataMappings);
            }

            if (!string.IsNullOrEmpty(typedDefinition.DataMappingViewFields))
            {
                wpXml.SetOrUpdateProperty("DataMappingViewFields", typedDefinition.DataMappingViewFields);
            }

            // misc
            if (typedDefinition.ShowUntargetedItems.HasValue)
            {
                wpXml.SetOrUpdateProperty("ShowUntargetedItems", typedDefinition.ShowUntargetedItems.ToString());
            }

            if (typedDefinition.PlayMediaInBrowser.HasValue)
            {
                wpXml.SetOrUpdateProperty("PlayMediaInBrowser", typedDefinition.PlayMediaInBrowser.ToString());
            }

            if (typedDefinition.UseCopyUtil.HasValue)
            {
                wpXml.SetOrUpdateProperty("UseCopyUtil", typedDefinition.UseCopyUtil.ToString());
            }

            // FilterTypeXXX
            if (!string.IsNullOrEmpty(typedDefinition.FilterType1))
            {
                wpXml.SetOrUpdateProperty("FilterType1", typedDefinition.FilterType1);
            }

            if (!string.IsNullOrEmpty(typedDefinition.FilterType2))
            {
                wpXml.SetOrUpdateProperty("FilterType2", typedDefinition.FilterType2);
            }

            if (!string.IsNullOrEmpty(typedDefinition.FilterType3))
            {
                wpXml.SetOrUpdateProperty("FilterType3", typedDefinition.FilterType3);
            }

            // FilterFieldXXX
            if (!string.IsNullOrEmpty(typedDefinition.FilterField1))
            {
                wpXml.SetOrUpdateProperty("FilterField1", typedDefinition.FilterField1);
            }

            if (!string.IsNullOrEmpty(typedDefinition.FilterField2))
            {
                wpXml.SetOrUpdateProperty("FilterField2", typedDefinition.FilterField2);
            }

            if (!string.IsNullOrEmpty(typedDefinition.FilterField3))
            {
                wpXml.SetOrUpdateProperty("FilterField3", typedDefinition.FilterField3);
            }

            // FilterXXXIsCustomValue
            if (typedDefinition.Filter1IsCustomValue.HasValue)
            {
                wpXml.SetOrUpdateProperty("Filter1IsCustomValue", typedDefinition.Filter1IsCustomValue.ToString());
            }

            if (typedDefinition.Filter2IsCustomValue.HasValue)
            {
                wpXml.SetOrUpdateProperty("Filter2IsCustomValue", typedDefinition.Filter2IsCustomValue.ToString());
            }

            if (typedDefinition.Filter3IsCustomValue.HasValue)
            {
                wpXml.SetOrUpdateProperty("Filter3IsCustomValue", typedDefinition.Filter3IsCustomValue.ToString());
            }

            // FilterValueXXX
            if (!string.IsNullOrEmpty(typedDefinition.FilterValue1))
            {
                wpXml.SetOrUpdateProperty("FilterValue1", typedDefinition.FilterValue1);
            }

            if (!string.IsNullOrEmpty(typedDefinition.FilterValue2))
            {
                wpXml.SetOrUpdateProperty("FilterValue2", typedDefinition.FilterValue2);
            }

            if (!string.IsNullOrEmpty(typedDefinition.FilterValue3))
            {
                wpXml.SetOrUpdateProperty("FilterValue3", typedDefinition.FilterValue3);
            }

            var filterChainingOperatorType = "Microsoft.SharePoint.Publishing.WebControls.ContentByQueryWebPart+FilterChainingOperator, Microsoft.SharePoint.Publishing, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c";

            if (!string.IsNullOrEmpty(typedDefinition.Filter1ChainingOperator))
            {
                wpXml.SetTypedProperty("Filter1ChainingOperator", typedDefinition.Filter1ChainingOperator, filterChainingOperatorType);
            }

            if (!string.IsNullOrEmpty(typedDefinition.Filter2ChainingOperator))
            {
                wpXml.SetTypedProperty("Filter2ChainingOperator", typedDefinition.Filter2ChainingOperator, filterChainingOperatorType);
            }


            // sorting
            if (!string.IsNullOrEmpty(typedDefinition.SortBy))
            {
                wpXml.SetOrUpdateProperty("SortBy", typedDefinition.SortBy);
            }

            if (!string.IsNullOrEmpty(typedDefinition.SortByDirection))
            {
                wpXml.SetTypedProperty("SortByDirection", typedDefinition.SortByDirection, "Microsoft.SharePoint.Publishing.WebControls.ContentByQueryWebPart+SortDirection, Microsoft.SharePoint.Publishing, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c");
            }

            if (!string.IsNullOrEmpty(typedDefinition.SortByFieldType))
            {
                wpXml.SetOrUpdateProperty("SortByFieldType", typedDefinition.SortByFieldType);
            }

            if (!string.IsNullOrEmpty(typedDefinition.GroupByDirection))
            {
                wpXml.SetTypedProperty("GroupByDirection", typedDefinition.GroupByDirection, "Microsoft.SharePoint.Publishing.WebControls.ContentByQueryWebPart+SortDirection, Microsoft.SharePoint.Publishing, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c");
            }

            var filterOperatorType = "Microsoft.SharePoint.Publishing.WebControls.ContentByQueryWebPart+FilterFieldQueryOperator, Microsoft.SharePoint.Publishing, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c";


            // FilterOperatorXXX
            if (!string.IsNullOrEmpty(typedDefinition.FilterOperator1))
            {
                wpXml.SetTypedProperty("FilterOperator1", typedDefinition.FilterOperator1, filterOperatorType);
            }

            if (!string.IsNullOrEmpty(typedDefinition.FilterOperator2))
            {
                wpXml.SetTypedProperty("FilterOperator2", typedDefinition.FilterOperator2, filterOperatorType);
            }

            if (!string.IsNullOrEmpty(typedDefinition.FilterOperator3))
            {
                wpXml.SetTypedProperty("FilterOperator3", typedDefinition.FilterOperator3, filterOperatorType);
            }

            // FilterDisplayValueXXX

            if (!string.IsNullOrEmpty(typedDefinition.FilterDisplayValue1))
            {
                wpXml.SetOrUpdateProperty("FilterDisplayValue1", typedDefinition.FilterDisplayValue1);
            }

            if (!string.IsNullOrEmpty(typedDefinition.FilterDisplayValue2))
            {
                wpXml.SetOrUpdateProperty("FilterDisplayValue2", typedDefinition.FilterDisplayValue2);
            }

            if (!string.IsNullOrEmpty(typedDefinition.FilterDisplayValue3))
            {
                wpXml.SetOrUpdateProperty("FilterDisplayValue3", typedDefinition.FilterDisplayValue3);
            }


            // bindings
            if (typedDefinition.ServerTemplate.HasValue)
            {
                wpXml.SetOrUpdateProperty("ServerTemplate", typedDefinition.ServerTemplate.ToString());
            }

            if (!string.IsNullOrEmpty(typedDefinition.ContentTypeName))
            {
                wpXml.SetOrUpdateProperty("ContentTypeName", typedDefinition.ContentTypeName);
            }

            if (!string.IsNullOrEmpty(typedDefinition.ContentTypeBeginsWithId))
            {
                wpXml.SetOrUpdateProperty("ContentTypeBeginsWithId", typedDefinition.ContentTypeBeginsWithId);
            }

            if (typedDefinition.ListId.HasGuidValue())
            {
                wpXml.SetTypedProperty("ListId", typedDefinition.ListId.Value.ToString("D"), "Microsoft.SharePoint.Publishing.WebControls.ContentByQueryWebPart+FilterChainingOperator, Microsoft.SharePoint.Publishing, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c");
            }

            if (typedDefinition.ListGuid.HasGuidValue())
            {
                wpXml.SetOrUpdateProperty("ListGuid", typedDefinition.ListGuid.Value.ToString("D"));
            }

            if (!string.IsNullOrEmpty(typedDefinition.ListName))
            {
                // ServerTemplate

                var webLookup = new LookupFieldModelHandler();

                var targetWeb = webLookup.GetTargetWeb(listItemModelHost.HostSite,
                                                       typedDefinition.WebUrl,
                                                       typedDefinition.WebId);

                var list = targetWeb.QueryAndGetListByTitle(typedDefinition.ListName);
                wpXml.SetOrUpdateProperty("ListGuid", list.Id.ToString("D"));

#if !NET35
                var folder = list.RootFolder;

                context.Load(folder, f => f.Properties);
                context.ExecuteQueryWithTrace();

                var serverTemplate = ConvertUtils.ToString(list.RootFolder.Properties["vti_listservertemplate"]);

                if (string.IsNullOrEmpty(serverTemplate))
                {
                    throw new SPMeta2Exception(
                              string.Format("Cannot find vti_listservertemplate property for the list name:[{0}]",
                                            typedDefinition.ListName));
                }

                wpXml.SetOrUpdateProperty("ServerTemplate", serverTemplate);
#endif
            }

            if (!string.IsNullOrEmpty(typedDefinition.ListUrl))
            {
                var webLookup = new LookupFieldModelHandler();

                var targetWeb = webLookup.GetTargetWeb(listItemModelHost.HostSite,
                                                       typedDefinition.WebUrl,
                                                       typedDefinition.WebId);

                var list = targetWeb.QueryAndGetListByUrl(typedDefinition.ListUrl);
                wpXml.SetOrUpdateProperty("ListGuid", list.Id.ToString("D"));

#if !NET35
                var folder = list.RootFolder;

                context.Load(folder, f => f.Properties);
                context.ExecuteQueryWithTrace();

                var serverTemplate = ConvertUtils.ToString(list.RootFolder.Properties["vti_listservertemplate"]);

                if (string.IsNullOrEmpty(serverTemplate))
                {
                    throw new SPMeta2Exception(
                              string.Format("Cannot find vti_listservertemplate property for the list url:[{0}]",
                                            typedDefinition.ListUrl));
                }

                wpXml.SetOrUpdateProperty("ServerTemplate", serverTemplate);
#endif
            }

            if (!string.IsNullOrEmpty(typedDefinition.WebUrl))
            {
                wpXml.SetOrUpdateProperty("WebUrl", typedDefinition.WebUrl);
            }

            // overrides
            if (!string.IsNullOrEmpty(typedDefinition.ListsOverride))
            {
                wpXml.SetOrUpdateProperty("ListsOverride", typedDefinition.ListsOverride);
            }

            if (!string.IsNullOrEmpty(typedDefinition.ViewFieldsOverride))
            {
                wpXml.SetOrUpdateProperty("ViewFieldsOverride", typedDefinition.ViewFieldsOverride);
            }

            if (!string.IsNullOrEmpty(typedDefinition.QueryOverride))
            {
                wpXml.SetOrUpdateProperty("QueryOverride", typedDefinition.QueryOverride);
            }

            if (!string.IsNullOrEmpty(typedDefinition.CommonViewFields))
            {
                wpXml.SetOrUpdateProperty("CommonViewFields", typedDefinition.CommonViewFields);
            }

            if (typedDefinition.FilterByAudience.HasValue)
            {
                wpXml.SetOrUpdateProperty("FilterByAudience", typedDefinition.FilterByAudience.ToString());
            }

            // misc
            if (!string.IsNullOrEmpty(typedDefinition.GroupBy))
            {
                wpXml.SetOrUpdateProperty("GroupBy", typedDefinition.GroupBy);
            }

            if (typedDefinition.DisplayColumns.HasValue)
            {
                wpXml.SetOrUpdateProperty("DisplayColumns", typedDefinition.DisplayColumns.ToString());
            }

            return(wpXml.ToString());
        }
        public override void DeployModel(object modelHost, DefinitionBase model)
        {
            var listItemModelHost = modelHost.WithAssertAndCast <ListItemModelHost>("modelHost", value => value.RequireNotNull());
            var definition        = model.WithAssertAndCast <WebPartDefinition>("model", value => value.RequireNotNull());

            var pageFile = listItemModelHost.HostFile;
            var context  = pageFile.Context;

            context.Load(pageFile);
            context.ExecuteQueryWithTrace();

            var siteServerUrl = listItemModelHost.HostSite.ServerRelativeUrl;
            var webUrl        = listItemModelHost.HostWeb.Url;

            var serverUrl = context.Url;

            if (siteServerUrl != "/")
            {
                serverUrl = context.Url.Split(new string[] { siteServerUrl }, StringSplitOptions.RemoveEmptyEntries)[0];
            }

            var absItemUrl = UrlUtility.CombineUrl(serverUrl, pageFile.ServerRelativeUrl);

            WithExistingWebPart(pageFile, definition, (spObject, spObjectDefintion) =>
            {
                var webpartExportUrl = UrlUtility.CombineUrl(new[] {
                    webUrl,
                    "_vti_bin/exportwp.aspx?pageurl=" + absItemUrl + "&" + "guidstring=" + spObjectDefintion.Id.ToString()
                });

                var assert = ServiceFactory.AssertService
                             .NewAssert(model, definition, spObject)
                             .ShouldNotBeNull(spObject);

                var webClient = new WebClient();

                if (context.Credentials != null)
                {
                    webClient.Credentials = context.Credentials;
                    webClient.Headers.Add("X-FORMS_BASED_AUTH_ACCEPTED", "f");
                }
                else
                {
                    webClient.UseDefaultCredentials = true;
                }

                var webPartXmlString = webClient.DownloadString(webpartExportUrl);
                CurrentWebPartXml    = WebpartXmlExtensions.LoadWebpartXmlDocument(webPartXmlString);


                assert.ShouldBeEqual(m => m.Title, o => o.Title);

                // checking the web part type, shoul be as expected
                // Add regression on 'expected' web part type #690

                var currentType      = CurrentWebPartXml.GetWebPartAssemblyQualifiedName();
                var currentClassName = currentType.Split(',').First().Trim();

                var expectedTypeAttr = (definition.GetType().GetCustomAttributes(typeof(ExpectWebpartType))
                                        .FirstOrDefault() as ExpectWebpartType);

                // NULL can be on generic web part
                // test should not care about that case, there other tests to enfore that attr usage
                if (expectedTypeAttr != null)
                {
                    var expectedType = expectedTypeAttr.WebPartType;

                    var expectedClassName = expectedType.Split(',').First().Trim();

                    assert.ShouldBeEqual((p, s, d) =>
                    {
                        var isValid = true;

                        isValid = currentClassName.ToUpper() == expectedClassName.ToUpper();

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

                // props

                if (definition.Properties.Count > 0)
                {
                    assert.ShouldBeEqual((p, s, d) =>
                    {
                        var isValid = true;

                        foreach (var prop in definition.Properties)
                        {
                            // returns correct one depending on the V2/V3
                            var value = CurrentWebPartXml.GetProperty(prop.Name);

                            // that True / true issue give a pain
                            // toLower for the time being
                            isValid = value.ToLower() == prop.Value.ToLower();

                            if (!isValid)
                            {
                                break;
                            }
                        }

                        var srcProp = s.GetExpressionValue(m => m.Properties);

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


                if (!string.IsNullOrEmpty(definition.ExportMode))
                {
                    var value = CurrentWebPartXml.GetExportMode();

                    assert.ShouldBeEqual((p, s, d) =>
                    {
                        var srcProp = s.GetExpressionValue(m => m.ExportMode);
                        var isValid = definition.ExportMode == value;

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

                if (!string.IsNullOrEmpty(definition.ChromeState))
                {
                    var value = CurrentWebPartXml.GetChromeState();

                    assert.ShouldBeEqual((p, s, d) =>
                    {
                        var srcProp = s.GetExpressionValue(m => m.ChromeState);
                        var isValid = definition.ChromeState == value;

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

                if (!string.IsNullOrEmpty(definition.ChromeType))
                {
                    // returns correct one depending on the V2/V3
                    var value = CurrentWebPartXml.GetChromeType();

                    var chromeType = string.Empty;

                    if (CurrentWebPartXml.IsV3version())
                    {
                        chromeType = WebPartChromeTypesConvertService.NormilizeValueToPartChromeTypes(definition.ChromeType);
                    }
                    else if (CurrentWebPartXml.IsV2version())
                    {
                        chromeType = WebPartChromeTypesConvertService.NormilizeValueToFrameTypes(definition.ChromeType);
                    }

                    assert.ShouldBeEqual((p, s, d) =>
                    {
                        var srcProp = s.GetExpressionValue(m => m.ChromeType);
                        var isValid = chromeType == value;

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

                if (!string.IsNullOrEmpty(definition.Description))
                {
                    var value = CurrentWebPartXml.GetProperty("Description");

                    assert.ShouldBeEqual((p, s, d) =>
                    {
                        var srcProp = s.GetExpressionValue(m => m.Description);
                        var isValid = (srcProp.Value as string) == value;

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

                if (definition.Height.HasValue)
                {
                    var value = ConvertUtils.ToInt(CurrentWebPartXml.GetProperty("Height").Replace("px", string.Empty));

                    assert.ShouldBeEqual((p, s, d) =>
                    {
                        var srcProp = s.GetExpressionValue(m => m.Height);
                        var isValid = definition.Height == value;

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

                if (definition.Width.HasValue)
                {
                    var value = ConvertUtils.ToInt(CurrentWebPartXml.GetProperty("Width").Replace("px", string.Empty));

                    assert.ShouldBeEqual((p, s, d) =>
                    {
                        var srcProp = s.GetExpressionValue(m => m.Width);
                        var isValid = definition.Width == value;

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

                if (!string.IsNullOrEmpty(definition.ImportErrorMessage))
                {
                    var value = CurrentWebPartXml.GetImportErrorMessage();

                    assert.ShouldBeEqual((p, s, d) =>
                    {
                        var srcProp = s.GetExpressionValue(m => m.ImportErrorMessage);
                        var isValid = definition.ImportErrorMessage == value;

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

                if (!string.IsNullOrEmpty(definition.TitleIconImageUrl))
                {
                    var value = CurrentWebPartXml.GetTitleIconImageUrl();

                    assert.ShouldBeEqual((p, s, d) =>
                    {
                        var srcProp = s.GetExpressionValue(m => m.TitleIconImageUrl);
                        var isValid = definition.TitleIconImageUrl == value;

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

                if (!string.IsNullOrEmpty(definition.TitleUrl))
                {
                    var value    = CurrentWebPartXml.GetTitleUrl();
                    var defValue = TokenReplacementService.ReplaceTokens(new TokenReplacementContext
                    {
                        Context = listItemModelHost.HostClientContext,
                        Value   = value
                    }).Value;

                    var isValid = defValue.ToUpper() == value.ToUpper();

                    assert.ShouldBeEqual((p, s, d) =>
                    {
                        var srcProp = s.GetExpressionValue(m => m.TitleUrl);

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


                assert.SkipProperty(m => m.WebpartFileName, "WebpartFileName is null or empty. Skipping.");
                assert.SkipProperty(m => m.WebpartType, "WebpartType is null or empty. Skipping.");
                assert.SkipProperty(m => m.WebpartXmlTemplate, "WebpartXmlTemplate is null or empty. Skipping.");

                assert.SkipProperty(m => m.ZoneId, "ZoneId is null or empty. Skipping.");
                assert.SkipProperty(m => m.ZoneIndex, "ZoneIndex is null or empty. Skipping.");

                assert.SkipProperty(m => m.Id, "Id is null or empty. Skipping.");

                if (definition.ParameterBindings.Count == 0)
                {
                    assert.SkipProperty(m => m.ParameterBindings, "ParameterBindings is null or empty. Skipping.");
                }
                else
                {
                    // TODO
                }
            });
        }
 public void CanLoadWebpartDefinitionV3()
 {
     var def = WebpartXmlExtensions
               .LoadWebpartXmlDocument(ResourceReaderUtils.ReadFromResourceName(GetType().Assembly, RegWebparts.V3.TeamTasks))
               .ToString();
 }
        public override object GetNewPropValue(ExpectUpdate attr, object obj, PropertyInfo prop)
        {
            object newValue = null;

            if (prop.PropertyType == typeof(byte[]))
            {
                if (obj is WebPartGalleryFileDefinition && prop.Name == "Content")
                {
                    // change web part
                    var webPartXmlString = Encoding.UTF8.GetString(prop.GetValue(obj) as byte[]);
                    var webPartXml       = WebpartXmlExtensions.LoadWebpartXmlDocument(webPartXmlString);

                    webPartXml.SetTitleUrl(RndService.HttpUrl());

                    newValue = Encoding.UTF8.GetBytes(webPartXml.ToString());
                }
                else
                {
                    newValue = RndService.Content();
                }
            }
            else if (prop.PropertyType == typeof(string))
            {
                newValue = RndService.String();
            }
            else if (prop.PropertyType == typeof(bool))
            {
                newValue = RndService.Bool();
            }
            else if (prop.PropertyType == typeof(bool?))
            {
                var oldValue = prop.GetValue(obj) as bool?;

                if (oldValue == null)
                {
                    newValue = RndService.Bool();
                }
                else
                {
                    newValue = !oldValue.Value;
                }
            }
            else if (prop.PropertyType == typeof(int))
            {
                newValue = RndService.Int();
            }
            else if (prop.PropertyType == typeof(int?))
            {
                newValue = RndService.Bool()
                    ? (int?)null
                    : RndService.Int();
            }
            else if (prop.PropertyType == typeof(uint))
            {
                newValue = (uint)RndService.Int();
            }
            else if (prop.PropertyType == typeof(uint?))
            {
                newValue = RndService.Bool()
                            ? null
                            : (uint?)RndService.Int();
            }
            else if (prop.PropertyType == typeof(Collection <string>))
            {
                var resultLength = RndService.Int(10);
                var result       = new Collection <string>();

                for (var index = 0; index < resultLength; index++)
                {
                    result.Add(RndService.String());
                }

                newValue = result;
            }
            else if (prop.PropertyType == typeof(List <string>))
            {
                var resultLength = RndService.Int(10);
                var result       = new List <string>();

                for (var index = 0; index < resultLength; index++)
                {
                    result.Add(RndService.String());
                }

                newValue = result;
            }
            else if (prop.PropertyType == typeof(double?) || prop.PropertyType == typeof(double))
            {
                newValue = (double)RndService.Int();
            }
            else
            {
                throw new SPMeta2NotImplementedException(string.Format("Update validation for type: [{0}] is not supported yet", prop.PropertyType));
            }

            return(newValue);
        }
        protected override string GetWebpartXmlDefinition(ListItemModelHost listItemModelHost, WebPartDefinitionBase webPartModel)
        {
            var wpModel     = webPartModel.WithAssertAndCast <XsltListViewWebPartDefinition>("model", value => value.RequireNotNull());
            var bindContext = LookupBindContext(listItemModelHost, wpModel);

            var wpXml = WebpartXmlExtensions.LoadWebpartXmlDocument(BuiltInWebPartTemplates.XsltListViewWebPart)
                        .SetListName(bindContext.ListId.ToString())
                        .SetListId(bindContext.ListId.ToString())
                        .SetTitleUrl(bindContext.TitleUrl)
                        .SetJSLink(wpModel.JSLink);

            if (wpModel.CacheXslStorage.HasValue)
            {
                wpXml.SetOrUpdateProperty("CacheXslStorage", wpModel.CacheXslStorage.Value.ToString());
            }

            if (wpModel.CacheXslTimeOut.HasValue)
            {
                wpXml.SetOrUpdateProperty("CacheXslTimeOut", wpModel.CacheXslTimeOut.Value.ToString());
            }

            if (!string.IsNullOrEmpty(wpModel.BaseXsltHashKey))
            {
                wpXml.SetOrUpdateProperty("BaseXsltHashKey", wpModel.BaseXsltHashKey);
            }

            // xsl
            if (!string.IsNullOrEmpty(wpModel.Xsl))
            {
                wpXml.SetOrUpdateCDataProperty("Xsl", wpModel.Xsl);
            }

            if (!string.IsNullOrEmpty(wpModel.XslLink))
            {
                wpXml.SetOrUpdateProperty("XslLink", wpModel.XslLink);
            }

            if (!string.IsNullOrEmpty(wpModel.GhostedXslLink))
            {
                wpXml.SetOrUpdateProperty("GhostedXslLink", wpModel.GhostedXslLink);
            }

            // xml
            if (!string.IsNullOrEmpty(wpModel.XmlDefinition))
            {
                wpXml.SetOrUpdateCDataProperty("XmlDefinition", wpModel.XmlDefinition);
            }

            if (!string.IsNullOrEmpty(wpModel.XmlDefinitionLink))
            {
                wpXml.SetOrUpdateProperty("XmlDefinitionLink", wpModel.XmlDefinitionLink);
            }

#if !NET35
            if (wpModel.ShowTimelineIfAvailable.HasValue)
            {
                wpXml.SetOrUpdateProperty("ShowTimelineIfAvailable", wpModel.ShowTimelineIfAvailable.Value.ToString());
            }
#endif

            return(wpXml.ToString());
        }
        public override void DeployModel(object modelHost, DefinitionBase model)
        {
            var listItemModelHost = modelHost.WithAssertAndCast <ListItemModelHost>("modelHost", value => value.RequireNotNull());
            var definition        = model.WithAssertAndCast <WebPartDefinition>("model", value => value.RequireNotNull());

            var pageItem = listItemModelHost.HostListItem;

            var context = pageItem.Context;

            var siteServerUrl = listItemModelHost.HostSite.ServerRelativeUrl;
            var webUrl        = listItemModelHost.HostWeb.Url;

            var serverUrl = context.Url;

            if (siteServerUrl != "/")
            {
                serverUrl = context.Url.Split(new string[] { siteServerUrl }, StringSplitOptions.RemoveEmptyEntries)[0];
            }

            var absItemUrl = UrlUtility.CombineUrl(serverUrl, pageItem["FileRef"].ToString());

            WithWithExistingWebPart(pageItem, definition, (spObject, spObjectDefintion) =>
            {
                var webpartExportUrl = UrlUtility.CombineUrl(new[] {
                    webUrl,
                    "_vti_bin/exportwp.aspx?pageurl=" + absItemUrl + "&" + "guidstring=" + spObjectDefintion.Id.ToString()
                });

                var assert = ServiceFactory.AssertService
                             .NewAssert(model, definition, spObject)
                             .ShouldNotBeNull(spObject);

                var webClient = new WebClient();

                if (context.Credentials != null)
                {
                    webClient.Credentials = context.Credentials;
                }
                else
                {
                    webClient.UseDefaultCredentials = true;
                }

                var webPartXmlString = webClient.DownloadString(webpartExportUrl);
                CurrentWebPartXml    = WebpartXmlExtensions.LoadWebpartXmlDocument(webPartXmlString);


                assert.ShouldBeEqual(m => m.Title, o => o.Title);

                if (!string.IsNullOrEmpty(definition.ExportMode))
                {
                    var value = CurrentWebPartXml.GetExportMode();

                    assert.ShouldBeEqual((p, s, d) =>
                    {
                        var srcProp = s.GetExpressionValue(m => m.ExportMode);
                        var isValid = definition.ExportMode == value;

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

                if (!string.IsNullOrEmpty(definition.ChromeState))
                {
                    var value = CurrentWebPartXml.GetChromeState();

                    assert.ShouldBeEqual((p, s, d) =>
                    {
                        var srcProp = s.GetExpressionValue(m => m.ChromeState);
                        var isValid = definition.ChromeState == value;

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

                if (!string.IsNullOrEmpty(definition.ChromeType))
                {
                    // returns correct one depending on the V2/V3
                    var value = CurrentWebPartXml.GetChromeType();

                    var chromeType = string.Empty;

                    if (CurrentWebPartXml.IsV3version())
                    {
                        chromeType = WebPartChromeTypesConvertService.NormilizeValueToPartChromeTypes(definition.ChromeType);
                    }
                    else if (CurrentWebPartXml.IsV2version())
                    {
                        chromeType = WebPartChromeTypesConvertService.NormilizeValueToFrameTypes(definition.ChromeType);
                    }

                    assert.ShouldBeEqual((p, s, d) =>
                    {
                        var srcProp = s.GetExpressionValue(m => m.ChromeType);
                        var isValid = chromeType == value;

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

                if (!string.IsNullOrEmpty(definition.Description))
                {
                }
                else
                {
                    assert.SkipProperty(m => m.Description, "Description is null or empty. Skipping.");
                }

                if (definition.Height.HasValue)
                {
                    var value = ConvertUtils.ToInt(CurrentWebPartXml.GetProperty("Height").Replace("px", string.Empty));

                    assert.ShouldBeEqual((p, s, d) =>
                    {
                        var srcProp = s.GetExpressionValue(m => m.Height);
                        var isValid = definition.Height == value;

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

                if (definition.Width.HasValue)
                {
                    var value = ConvertUtils.ToInt(CurrentWebPartXml.GetProperty("Width").Replace("px", string.Empty));

                    assert.ShouldBeEqual((p, s, d) =>
                    {
                        var srcProp = s.GetExpressionValue(m => m.Width);
                        var isValid = definition.Width == value;

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

                if (!string.IsNullOrEmpty(definition.ImportErrorMessage))
                {
                    var value = CurrentWebPartXml.GetImportErrorMessage();

                    assert.ShouldBeEqual((p, s, d) =>
                    {
                        var srcProp = s.GetExpressionValue(m => m.ImportErrorMessage);
                        var isValid = definition.ImportErrorMessage == value;

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

                if (!string.IsNullOrEmpty(definition.TitleIconImageUrl))
                {
                    var value = CurrentWebPartXml.GetTitleIconImageUrl();

                    assert.ShouldBeEqual((p, s, d) =>
                    {
                        var srcProp = s.GetExpressionValue(m => m.TitleIconImageUrl);
                        var isValid = definition.TitleIconImageUrl == value;

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

                if (!string.IsNullOrEmpty(definition.TitleUrl))
                {
                    var value = CurrentWebPartXml.GetTitleUrl();

                    assert.ShouldBeEqual((p, s, d) =>
                    {
                        var srcProp = s.GetExpressionValue(m => m.TitleIconImageUrl);
                        var isValid = definition.TitleIconImageUrl == value;

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


                assert.SkipProperty(m => m.WebpartFileName, "WebpartFileName is null or empty. Skipping.");
                assert.SkipProperty(m => m.WebpartType, "WebpartType is null or empty. Skipping.");
                assert.SkipProperty(m => m.WebpartXmlTemplate, "WebpartXmlTemplate is null or empty. Skipping.");

                assert.SkipProperty(m => m.ZoneId, "ZoneId is null or empty. Skipping.");
                assert.SkipProperty(m => m.ZoneIndex, "ZoneIndex is null or empty. Skipping.");

                assert.SkipProperty(m => m.Id, "Id is null or empty. Skipping.");

                if (definition.ParameterBindings.Count == 0)
                {
                    assert.SkipProperty(m => m.ParameterBindings, "ParameterBindings is null or empty. Skipping.");
                }
                else
                {
                    // TODO
                }
            });
        }
        private void ProcessDefinitionsPropertyUpdateValidation(DefinitionBase def)
        {
            var updatableProps = def.GetType()
                                 .GetProperties()
                                 .Where(p => p.GetCustomAttributes(typeof(ExpectUpdate), true).Count() > 0);


            TraceUtils.WithScope(trace =>
            {
                trace.WriteLine("");

                trace.WriteLine(string.Format("[INF]\tPROPERTY UPDATE VALIDATION"));
                trace.WriteLine(string.Format("[INF]\tModel of type: [{0}] - [{1}]", def.GetType(), def));

                if (updatableProps.Count() == 0)
                {
                    trace.WriteLine(string.Format("[INF]\tNo properties to be validated. Skipping."));
                }
                else
                {
                    foreach (var prop in updatableProps)
                    {
                        object newValue = null;

                        var attrs = prop.GetCustomAttributes(typeof(ExpectUpdate), true);

                        if (attrs.Count(a => a is ExpectUpdateAsLCID) > 0)
                        {
                            var newLocaleIdValue = 1033 + RegressionService.RndService.Int(5);

                            if (prop.PropertyType == typeof(int))
                            {
                                newValue = newLocaleIdValue;
                            }
                            else if (prop.PropertyType == typeof(int?))
                            {
                                newValue = RegressionService.RndService.Bool() ? (int?)null : newLocaleIdValue;
                            }
                            else if (prop.PropertyType == typeof(uint))
                            {
                                newValue = (uint)newLocaleIdValue;
                            }
                            else if (prop.PropertyType == typeof(uint?))
                            {
                                newValue = (uint?)(RegressionService.RndService.Bool() ? (uint?)null : (uint?)newLocaleIdValue);
                            }
                        }
                        else if (attrs.Count(a => a is ExpectUpdateAsUser) > 0)
                        {
                            var newUserValue = RegressionService.RndService.UserLogin();
                            newValue         = newUserValue;
                        }
                        else if (attrs.Count(a => a is ExpectUpdateAsTargetControlType) > 0)
                        {
                            var values = new List <string>();

                            values.Add(BuiltInTargetControlType.ContentWebParts);
                            values.Add(BuiltInTargetControlType.Custom);
                            values.Add(BuiltInTargetControlType.Refinement);
                            values.Add(BuiltInTargetControlType.SearchBox);
                            values.Add(BuiltInTargetControlType.SearchHoverPanel);
                            values.Add(BuiltInTargetControlType.SearchResults);

                            if (prop.PropertyType == typeof(string))
                            {
                                newValue = values[RegressionService.RndService.Int(values.Count - 1)];
                            }

                            if (prop.PropertyType == typeof(List <string>))
                            {
                                var result       = new List <string>();
                                var resultLength = RegressionService.RndService.Int(values.Count - 1);

                                for (var index = 0; index < resultLength; index++)
                                {
                                    result.Add(values[index]);
                                }

                                newValue = result;
                            }
                        }
                        else if (attrs.Count(a => a is ExpectUpdateAsWebPartPageLayoutTemplate) > 0)
                        {
                            var values = new List <int>();

                            values.Add(BuiltInWebpartPageTemplateId.spstd1);
                            values.Add(BuiltInWebpartPageTemplateId.spstd2);
                            values.Add(BuiltInWebpartPageTemplateId.spstd3);
                            values.Add(BuiltInWebpartPageTemplateId.spstd4);
                            values.Add(BuiltInWebpartPageTemplateId.spstd5);
                            values.Add(BuiltInWebpartPageTemplateId.spstd6);
                            values.Add(BuiltInWebpartPageTemplateId.spstd7);

                            if (prop.PropertyType == typeof(int))
                            {
                                newValue = values[RegressionService.RndService.Int(values.Count - 1)];
                            }
                        }
                        else if (attrs.Count(a => a is ExpectUpdateAsDateTimeFieldCalendarType) > 0)
                        {
                            var values = new List <string>();

                            values.Add(BuiltInCalendarType.Gregorian);
                            values.Add(BuiltInCalendarType.Korea);
                            values.Add(BuiltInCalendarType.Hebrew);
                            values.Add(BuiltInCalendarType.GregorianArabic);
                            values.Add(BuiltInCalendarType.SakaEra);

                            if (prop.PropertyType == typeof(string))
                            {
                                newValue = values[RegressionService.RndService.Int(values.Count - 1)];
                            }
                        }
                        else if (attrs.Count(a => a is ExpectUpdateAsFieldUserSelectionMode) > 0)
                        {
                            var curentValue = prop.GetValue(def) as string;

                            if (curentValue == BuiltInFieldUserSelectionMode.PeopleAndGroups)
                            {
                                newValue = BuiltInFieldUserSelectionMode.PeopleOnly;
                            }
                            else
                            {
                                newValue = BuiltInFieldUserSelectionMode.PeopleAndGroups;
                            }
                        }
                        else if (attrs.Count(a => a is ExpectUpdateAsDateTimeFieldCalendarType) > 0)
                        {
                            var values = new List <string>();

                            values.Add(BuiltInCalendarType.Gregorian);
                            values.Add(BuiltInCalendarType.Korea);
                            values.Add(BuiltInCalendarType.Hebrew);
                            values.Add(BuiltInCalendarType.GregorianArabic);
                            values.Add(BuiltInCalendarType.SakaEra);

                            if (prop.PropertyType == typeof(string))
                            {
                                newValue = values[RegressionService.RndService.Int(values.Count - 1)];
                            }
                        }
                        else if (attrs.Count(a => a is ExpectUpdateAsDateTimeFieldDisplayFormat) > 0)
                        {
                            var curentValue = prop.GetValue(def) as string;

                            if (curentValue == BuiltInDateTimeFieldFormatType.DateOnly)
                            {
                                newValue = BuiltInDateTimeFieldFormatType.DateTime;
                            }
                            else
                            {
                                newValue = BuiltInDateTimeFieldFormatType.DateOnly;
                            }
                        }
                        else if (attrs.Count(a => a is ExpectUpdateAsDateTimeFieldFriendlyDisplayFormat) > 0)
                        {
                            var curentValue = prop.GetValue(def) as string;

                            if (curentValue == BuiltInDateTimeFieldFriendlyFormatType.Disabled)
                            {
                                newValue = BuiltInDateTimeFieldFriendlyFormatType.Relative;
                            }
                            else if (curentValue == BuiltInDateTimeFieldFriendlyFormatType.Relative)
                            {
                                newValue = BuiltInDateTimeFieldFriendlyFormatType.Unspecified;
                            }
                            else if (curentValue == BuiltInDateTimeFieldFriendlyFormatType.Unspecified)
                            {
                                newValue = BuiltInDateTimeFieldFriendlyFormatType.Disabled;
                            }
                        }
                        else if (attrs.Count(a => a is ExpectUpdateAsByte) > 0)
                        {
                            if (prop.PropertyType == typeof(int?) ||
                                prop.PropertyType == typeof(int?))
                            {
                                newValue = Convert.ToInt32(RegressionService.RndService.Byte().ToString());
                            }
                            else
                            {
                                // TODO, as per case
                                newValue = RegressionService.RndService.Byte();
                            }
                        }
                        else if (attrs.Count(a => a is ExpectUpdateAsCamlQuery) > 0)
                        {
                            newValue =
                                string.Format(
                                    "<Where><Eq><FieldRef Name=\"Title\" /><Value Type=\"Text\">{0}</Value></Eq></Where>",
                                    RegressionService.RndService.String());
                        }
                        else if (attrs.Count(a => a is ExpectUpdateAsIntRange) > 0)
                        {
                            var attr =
                                attrs.FirstOrDefault(a => a is ExpectUpdateAsIntRange) as ExpectUpdateAsIntRange;

                            var minValue = attr.MinValue;
                            var maxValue = attr.MaxValue;

                            var tmpValue = minValue + RegressionService.RndService.Int(maxValue - minValue);

                            if (prop.PropertyType == typeof(double?) ||
                                prop.PropertyType == typeof(double))
                            {
                                newValue = Convert.ToDouble(tmpValue);
                            }
                            else
                            {
                                // TODO, as per case
                                newValue = tmpValue;
                            }
                        }

                        else if (attrs.Count(a => a is ExpectUpdateAsUrl) > 0)
                        {
                            var attr =
                                attrs.FirstOrDefault(a => a is ExpectUpdateAsUrl) as ExpectUpdateAsUrl;
                            var fileExtension = attr.Extension;

                            if (!fileExtension.StartsWith("."))
                            {
                                fileExtension = "." + fileExtension;
                            }

                            newValue = string.Format("http://regression-ci.com/{0}{1}", RegressionService.RndService.String(), fileExtension);
                        }
                        else if (attrs.Count(a => a is ExpectUpdateAsFileName) > 0)
                        {
                            var attr =
                                attrs.FirstOrDefault(a => a is ExpectUpdateAsFileName) as ExpectUpdateAsFileName;
                            var fileExtension = attr.Extension;

                            if (!fileExtension.StartsWith("."))
                            {
                                fileExtension = "." + fileExtension;
                            }

                            newValue = string.Format("{0}{1}", RegressionService.RndService.String(), fileExtension);
                        }
                        else if (attrs.Count(a => a is ExpectUpdateAsInternalFieldName) > 0)
                        {
                            var values = new List <string>();

                            values.Add(BuiltInInternalFieldNames.ID);
                            values.Add(BuiltInInternalFieldNames.Edit);
                            values.Add(BuiltInInternalFieldNames.Created);
                            values.Add(BuiltInInternalFieldNames._Author);

                            if (prop.PropertyType == typeof(string))
                            {
                                newValue = values[RegressionService.RndService.Int(values.Count - 1)];
                            }

                            if (prop.PropertyType == typeof(Collection <string>))
                            {
                                var result       = new Collection <string>();
                                var resultLength = RegressionService.RndService.Int(values.Count - 1);

                                for (var index = 0; index < resultLength; index++)
                                {
                                    result.Add(values[index]);
                                }

                                newValue = result;
                            }
                        }
                        else if (attrs.Count(a => a is ExpectUpdateAsPageLayoutFileName) > 0)
                        {
                            var values = new List <string>();

                            values.Add(BuiltInPublishingPageLayoutNames.ArticleLeft);
                            values.Add(BuiltInPublishingPageLayoutNames.ArticleLinks);
                            values.Add(BuiltInPublishingPageLayoutNames.ArticleRight);
                            values.Add(BuiltInPublishingPageLayoutNames.BlankWebPartPage);
                            values.Add(BuiltInPublishingPageLayoutNames.CatalogArticle);
                            values.Add(BuiltInPublishingPageLayoutNames.CatalogWelcome);
                            values.Add(BuiltInPublishingPageLayoutNames.EnterpriseWiki);

                            if (prop.PropertyType == typeof(string))
                            {
                                newValue = values[RegressionService.RndService.Int(values.Count - 1)];
                            }

                            if (prop.PropertyType == typeof(Collection <string>))
                            {
                                var result       = new Collection <string>();
                                var resultLength = RegressionService.RndService.Int(values.Count - 1);

                                for (var index = 0; index < resultLength; index++)
                                {
                                    result.Add(values[index]);
                                }

                                newValue = result;
                            }
                        }
                        else if (attrs.Count(a => a is ExpectUpdateAsUrlFieldFormat) > 0)
                        {
                            var curentValue = prop.GetValue(def) as string;

                            if (curentValue == BuiltInUrlFieldFormatType.Hyperlink)
                            {
                                newValue = BuiltInUrlFieldFormatType.Image;
                            }
                            else
                            {
                                newValue = BuiltInUrlFieldFormatType.Hyperlink;
                            }
                        }
                        else if (attrs.Count(a => a is ExpectUpdateAsCalculatedFieldFormula) > 0)
                        {
                            newValue = string.Format("=ID*{0}", RegressionService.RndService.Int(100));
                        }
                        else if (attrs.Count(a => a is ExpectUpdateAssCalculatedFieldOutputType) > 0)
                        {
                            var curentValue = prop.GetValue(def) as string;

                            if (curentValue == BuiltInFieldTypes.Number)
                            {
                                newValue = BuiltInFieldTypes.Text;
                            }
                            else
                            {
                                newValue = BuiltInFieldTypes.Number;
                            }
                        }
                        else if (attrs.Count(a => a is ExpectUpdateAssCalculatedFieldReferences) > 0)
                        {
                            var values = new List <string>();

                            values.Add(BuiltInInternalFieldNames.ID);
                            values.Add(BuiltInInternalFieldNames.FileRef);
                            values.Add(BuiltInInternalFieldNames.FileType);
                            values.Add(BuiltInInternalFieldNames.File_x0020_Size);
                            values.Add(BuiltInInternalFieldNames.FirstName);

                            if (prop.PropertyType == typeof(string))
                            {
                                newValue = values[RegressionService.RndService.Int(values.Count - 1)];
                            }

                            if (prop.PropertyType == typeof(Collection <string>))
                            {
                                var result       = new Collection <string>();
                                var resultLength = RegressionService.RndService.Int(values.Count - 1);

                                for (var index = 0; index < resultLength; index++)
                                {
                                    result.Add(values[index]);
                                }

                                newValue = result;
                            }
                        }
                        else if (attrs.Count(a => a is ExpectUpdateAsBasePermission) > 0)
                        {
                            var values = new List <string>();

                            values.Add(BuiltInBasePermissions.AddAndCustomizePages);
                            values.Add(BuiltInBasePermissions.AnonymousSearchAccessWebLists);
                            values.Add(BuiltInBasePermissions.ApproveItems);
                            values.Add(BuiltInBasePermissions.CancelCheckout);
                            values.Add(BuiltInBasePermissions.CreateSSCSite);
                            values.Add(BuiltInBasePermissions.EditMyUserInfo);

                            if (prop.PropertyType == typeof(string))
                            {
                                newValue = values[RegressionService.RndService.Int(values.Count - 1)];
                            }

                            if (prop.PropertyType == typeof(Collection <string>))
                            {
                                var result       = new Collection <string>();
                                var resultLength = RegressionService.RndService.Int(values.Count - 1);

                                for (var index = 0; index < resultLength; index++)
                                {
                                    result.Add(values[index]);
                                }

                                newValue = result;
                            }
                        }
                        else if (attrs.Count(a => a is ExpectUpdateAsPublishingPageContentType) > 0)
                        {
                            var values = new List <string>();

                            values.Add(BuiltInPublishingContentTypeId.ArticlePage);
                            values.Add(BuiltInPublishingContentTypeId.EnterpriseWikiPage);
                            values.Add(BuiltInPublishingContentTypeId.ErrorPage);
                            values.Add(BuiltInPublishingContentTypeId.RedirectPage);

                            if (prop.PropertyType == typeof(string))
                            {
                                newValue = values[RegressionService.RndService.Int(values.Count - 1)];
                            }

                            if (prop.PropertyType == typeof(Collection <string>))
                            {
                                var result       = new Collection <string>();
                                var resultLength = RegressionService.RndService.Int(values.Count - 1);

                                for (var index = 0; index < resultLength; index++)
                                {
                                    result.Add(values[index]);
                                }

                                newValue = result;
                            }
                        }
                        else if (attrs.Count(a => a is ExpectUpdateAsUIVersion) > 0)
                        {
                            var values = new List <string>();

                            values.Add("4");
                            values.Add("15");

                            if (prop.PropertyType == typeof(string))
                            {
                                newValue = values[RegressionService.RndService.Int(values.Count - 1)];
                            }

                            if (prop.PropertyType == typeof(Collection <string>))
                            {
                                var result       = new Collection <string>();
                                var resultLength = RegressionService.RndService.Int(values.Count - 1);

                                for (var index = 0; index < resultLength; index++)
                                {
                                    result.Add(values[index]);
                                }

                                newValue = result;
                            }

                            if (prop.PropertyType == typeof(List <string>))
                            {
                                var result       = new List <string>();
                                var resultLength = RegressionService.RndService.Int(values.Count - 1);

                                for (var index = 0; index < resultLength; index++)
                                {
                                    result.Add(values[index]);
                                }

                                newValue = result;
                            }
                        }
                        else
                        {
                            // all this needs to be refactored, we know

                            if (prop.PropertyType == typeof(byte[]))
                            {
                                if (def is WebPartGalleryFileDefinition &&
                                    prop.Name == "Content")
                                {
                                    // change web part
                                    var webPartXmlString = Encoding.UTF8.GetString(prop.GetValue(def) as byte[]);
                                    var webPartXml       = WebpartXmlExtensions.LoadWebpartXmlDocument(webPartXmlString);

                                    webPartXml.SetTitleUrl(RegressionService.RndService.HttpUrl());

                                    newValue = Encoding.UTF8.GetBytes(webPartXml.ToString());
                                }
                                else
                                {
                                    newValue = RegressionService.RndService.Content();
                                }
                            }
                            else if (prop.PropertyType == typeof(string))
                            {
                                newValue = RegressionService.RndService.String();
                            }
                            else if (prop.PropertyType == typeof(bool))
                            {
                                newValue = RegressionService.RndService.Bool();
                            }
                            else if (prop.PropertyType == typeof(bool?))
                            {
                                var oldValue = prop.GetValue(def) as bool?;

                                if (oldValue == null || !oldValue.HasValue)
                                {
                                    newValue = RegressionService.RndService.Bool();
                                }
                                else
                                {
                                    newValue = !oldValue.Value;
                                }
                            }
                            else if (prop.PropertyType == typeof(int))
                            {
                                newValue = RegressionService.RndService.Int();
                            }
                            else if (prop.PropertyType == typeof(int?))
                            {
                                newValue = RegressionService.RndService.Bool()
                                    ? (int?)null
                                    : RegressionService.RndService.Int();
                            }
                            else if (prop.PropertyType == typeof(uint))
                            {
                                newValue = (uint)RegressionService.RndService.Int();
                            }
                            else if (prop.PropertyType == typeof(uint?))
                            {
                                newValue =
                                    (uint?)
                                    (RegressionService.RndService.Bool()
                                            ? (uint?)null
                                            : (uint?)RegressionService.RndService.Int());
                            }
                            else if (prop.PropertyType == typeof(Collection <string>))
                            {
                                var resultLength = RegressionService.RndService.Int(10);
                                var values       = new List <string>();

                                var result = new Collection <string>();

                                for (var index = 0; index < resultLength; index++)
                                {
                                    result.Add(RegressionService.RndService.String());
                                }

                                newValue = result;
                            }
                            else if (prop.PropertyType == typeof(List <string>))
                            {
                                var resultLength = RegressionService.RndService.Int(10);
                                var values       = new List <string>();

                                var result = new List <string>();

                                for (var index = 0; index < resultLength; index++)
                                {
                                    result.Add(RegressionService.RndService.String());
                                }

                                newValue = result;
                            }


                            else if (prop.PropertyType == typeof(double?) ||
                                     prop.PropertyType == typeof(double))
                            {
                                newValue = (double)RegressionService.RndService.Int();
                            }
                            else
                            {
                                throw new NotImplementedException(
                                    string.Format("Update validation for type: [{0}] is not supported yet",
                                                  prop.PropertyType));
                            }
                        }

                        trace.WriteLine(string.Format("[INF]\t\tChanging property [{0}] from [{1}] to [{2}]", prop.Name, prop.GetValue(def), newValue));
                        prop.SetValue(def, newValue);
                    }
                }

                trace.WriteLine("");
            });
        }
Example #13
0
        protected virtual string ProcessCommonWebpartProperties(string webPartXml, WebPartDefinitionBase definition)
        {
            var xml = WebpartXmlExtensions.LoadWebpartXmlDocument(webPartXml)
                      .SetTitle(definition.Title)
                      .SetID(definition.Id);

            if (definition.Width.HasValue)
            {
                xml.SetWidth(definition.Width.Value);
            }

            if (definition.Height.HasValue)
            {
                xml.SetHeight(definition.Height.Value);
            }

            if (!string.IsNullOrEmpty(definition.Description))
            {
                xml.SetDescription(definition.Description);
            }

            if (!string.IsNullOrEmpty(definition.ImportErrorMessage))
            {
                xml.SetImportErrorMessage(definition.ImportErrorMessage);
            }

            if (!string.IsNullOrEmpty(definition.TitleUrl))
            {
                xml.SetTitleUrl(definition.TitleUrl);
            }

            if (!string.IsNullOrEmpty(definition.TitleIconImageUrl))
            {
                xml.SetTitleIconImageUrl(definition.TitleIconImageUrl);
            }

            if (!string.IsNullOrEmpty(definition.ChromeState))
            {
                xml.SetChromeState(definition.ChromeState);
            }

            if (!string.IsNullOrEmpty(definition.ChromeType))
            {
                var chromeType = string.Empty;

                if (xml.IsV3version())
                {
                    chromeType = WebPartChromeTypesConvertService.NormilizeValueToPartChromeTypes(definition.ChromeType);
                }
                else if (xml.IsV2version())
                {
                    chromeType = WebPartChromeTypesConvertService.NormilizeValueToFrameTypes(definition.ChromeType);
                }

                // SetChromeType() sets correct XML props depending on V2/V3 web part XML
                xml.SetChromeType(chromeType);
            }

            if (!string.IsNullOrEmpty(definition.ExportMode))
            {
                xml.SetExportMode(definition.ExportMode);
            }

            if (definition.ParameterBindings != null && definition.ParameterBindings.Count > 0)
            {
                var parameterBinder = new WebPartParameterBindingsOptions();

                foreach (var binding in definition.ParameterBindings)
                {
                    parameterBinder.AddParameterBinding(binding.Name, binding.Location);
                }

                var parameterBindingValue = SecurityElement.Escape(parameterBinder.ParameterBinding);
                xml.SetOrUpdateProperty("ParameterBindings", parameterBindingValue);
            }

            return(xml.ToString());
        }
Example #14
0
        protected override string GetWebpartXmlDefinition(ListItemModelHost listItemModelHost, WebPartDefinitionBase webPartModel)
        {
            var typedDefinition = webPartModel.WithAssertAndCast <ContentByQueryWebPartDefinition>("model", value => value.RequireNotNull());
            var wpXml           = WebpartXmlExtensions.LoadWebpartXmlDocument(this.ProcessCommonWebpartProperties(BuiltInWebPartTemplates.ContentByQueryWebPart, webPartModel));

            // xslt links
            if (!string.IsNullOrEmpty(typedDefinition.MainXslLink))
            {
                var linkValue = typedDefinition.MainXslLink;

                TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Original MainXslLink: [{0}]", linkValue);

                linkValue = TokenReplacementService.ReplaceTokens(new TokenReplacementContext
                {
                    Value   = linkValue,
                    Context = listItemModelHost.HostClientContext
                }).Value;

                TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Token replaced MainXslLink: [{0}]", linkValue);

                wpXml.SetOrUpdateProperty("MainXslLink", linkValue);
            }

            if (!string.IsNullOrEmpty(typedDefinition.ItemXslLink))
            {
                var linkValue = typedDefinition.ItemXslLink;

                TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Original ItemXslLink: [{0}]", linkValue);

                linkValue = TokenReplacementService.ReplaceTokens(new TokenReplacementContext
                {
                    Value   = linkValue,
                    Context = listItemModelHost.HostClientContext
                }).Value;

                TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Token replaced ItemXslLink: [{0}]", linkValue);

                wpXml.SetOrUpdateProperty("ItemXslLink", linkValue);
            }

            if (!string.IsNullOrEmpty(typedDefinition.HeaderXslLink))
            {
                var linkValue = typedDefinition.HeaderXslLink;

                TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Original HeaderXslLink: [{0}]", linkValue);

                linkValue = TokenReplacementService.ReplaceTokens(new TokenReplacementContext
                {
                    Value   = linkValue,
                    Context = listItemModelHost.HostClientContext
                }).Value;

                TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Token replaced HeaderXslLink: [{0}]", linkValue);

                wpXml.SetOrUpdateProperty("HeaderXslLink", linkValue);
            }

            // styles
            if (!string.IsNullOrEmpty(typedDefinition.ItemStyle))
            {
                wpXml.SetItemStyle(typedDefinition.ItemStyle);
            }

            if (!string.IsNullOrEmpty(typedDefinition.GroupStyle))
            {
                wpXml.SetGroupStyle(typedDefinition.GroupStyle);
            }


            // cache settings
            if (typedDefinition.UseCache.HasValue)
            {
                wpXml.SetUseCache(typedDefinition.UseCache.ToString());
            }

            if (typedDefinition.CacheXslStorage.HasValue)
            {
                wpXml.SetOrUpdateProperty("CacheXslStorage", typedDefinition.CacheXslStorage.ToString());
            }

            if (typedDefinition.CacheXslTimeOut.HasValue)
            {
                wpXml.SetOrUpdateProperty("CacheXslTimeOut", typedDefinition.CacheXslTimeOut.ToString());
            }

            // item limit
            if (typedDefinition.ItemLimit.HasValue)
            {
                wpXml.SetOrUpdateProperty("ItemLimit", typedDefinition.ItemLimit.ToString());
            }

            // mappings
            if (!string.IsNullOrEmpty(typedDefinition.DataMappings))
            {
                wpXml.SetOrUpdateProperty("DataMappings", typedDefinition.DataMappings);
            }

            if (!string.IsNullOrEmpty(typedDefinition.DataMappingViewFields))
            {
                wpXml.SetOrUpdateProperty("DataMappingViewFields", typedDefinition.DataMappingViewFields);
            }

            // misc
            if (typedDefinition.ShowUntargetedItems.HasValue)
            {
                wpXml.SetOrUpdateProperty("ShowUntargetedItems", typedDefinition.ShowUntargetedItems.ToString());
            }

            if (typedDefinition.PlayMediaInBrowser.HasValue)
            {
                wpXml.SetOrUpdateProperty("PlayMediaInBrowser", typedDefinition.PlayMediaInBrowser.ToString());
            }

            // FilterTypeXXX
            if (!string.IsNullOrEmpty(typedDefinition.FilterType1))
            {
                wpXml.SetOrUpdateProperty("FilterType1", typedDefinition.FilterType1);
            }

            if (!string.IsNullOrEmpty(typedDefinition.FilterType2))
            {
                wpXml.SetOrUpdateProperty("FilterType2", typedDefinition.FilterType2);
            }

            if (!string.IsNullOrEmpty(typedDefinition.FilterType3))
            {
                wpXml.SetOrUpdateProperty("FilterType3", typedDefinition.FilterType3);
            }

            // FilterFieldXXX
            if (!string.IsNullOrEmpty(typedDefinition.FilterField1))
            {
                wpXml.SetOrUpdateProperty("FilterField1", typedDefinition.FilterField1);
            }

            if (!string.IsNullOrEmpty(typedDefinition.FilterField2))
            {
                wpXml.SetOrUpdateProperty("FilterField2", typedDefinition.FilterField2);
            }

            if (!string.IsNullOrEmpty(typedDefinition.FilterField3))
            {
                wpXml.SetOrUpdateProperty("FilterField3", typedDefinition.FilterField3);
            }

            // FilterXXXIsCustomValue
            if (typedDefinition.Filter1IsCustomValue.HasValue)
            {
                wpXml.SetOrUpdateProperty("Filter1IsCustomValue", typedDefinition.Filter1IsCustomValue.ToString());
            }

            if (typedDefinition.Filter2IsCustomValue.HasValue)
            {
                wpXml.SetOrUpdateProperty("Filter2IsCustomValue", typedDefinition.Filter2IsCustomValue.ToString());
            }

            if (typedDefinition.Filter3IsCustomValue.HasValue)
            {
                wpXml.SetOrUpdateProperty("Filter3IsCustomValue", typedDefinition.Filter3IsCustomValue.ToString());
            }

            // FilterValueXXX
            if (!string.IsNullOrEmpty(typedDefinition.FilterValue1))
            {
                wpXml.SetOrUpdateProperty("FilterValue1", typedDefinition.FilterValue1);
            }

            if (!string.IsNullOrEmpty(typedDefinition.FilterValue2))
            {
                wpXml.SetOrUpdateProperty("FilterValue2", typedDefinition.FilterValue2);
            }

            if (!string.IsNullOrEmpty(typedDefinition.FilterValue3))
            {
                wpXml.SetOrUpdateProperty("FilterValue3", typedDefinition.FilterValue3);
            }

            var filterChainingOperatorType = "Microsoft.SharePoint.Publishing.WebControls.ContentByQueryWebPart+FilterChainingOperator, Microsoft.SharePoint.Publishing, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c";

            if (!string.IsNullOrEmpty(typedDefinition.Filter1ChainingOperator))
            {
                wpXml.SetTypedProperty("Filter1ChainingOperator", typedDefinition.Filter1ChainingOperator, filterChainingOperatorType);
            }

            if (!string.IsNullOrEmpty(typedDefinition.Filter2ChainingOperator))
            {
                wpXml.SetTypedProperty("Filter2ChainingOperator", typedDefinition.Filter2ChainingOperator, filterChainingOperatorType);
            }


            // sorting
            if (!string.IsNullOrEmpty(typedDefinition.SortBy))
            {
                wpXml.SetOrUpdateProperty("SortBy", typedDefinition.SortBy);
            }

            if (!string.IsNullOrEmpty(typedDefinition.SortByDirection))
            {
                wpXml.SetTypedProperty("SortByDirection", typedDefinition.SortByDirection, "Microsoft.SharePoint.Publishing.WebControls.ContentByQueryWebPart+SortDirection, Microsoft.SharePoint.Publishing, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c");
            }

            if (!string.IsNullOrEmpty(typedDefinition.SortByFieldType))
            {
                wpXml.SetOrUpdateProperty("SortByFieldType", typedDefinition.SortByFieldType);
            }

            if (!string.IsNullOrEmpty(typedDefinition.GroupByDirection))
            {
                wpXml.SetTypedProperty("GroupByDirection", typedDefinition.GroupByDirection, "Microsoft.SharePoint.Publishing.WebControls.ContentByQueryWebPart+SortDirection, Microsoft.SharePoint.Publishing, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c");
            }

            var filterOperatorType = "Microsoft.SharePoint.Publishing.WebControls.ContentByQueryWebPart+FilterFieldQueryOperator, Microsoft.SharePoint.Publishing, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c";


            // FilterOperatorXXX
            if (!string.IsNullOrEmpty(typedDefinition.FilterOperator1))
            {
                wpXml.SetTypedProperty("FilterOperator1", typedDefinition.FilterOperator1, filterOperatorType);
            }

            if (!string.IsNullOrEmpty(typedDefinition.FilterOperator2))
            {
                wpXml.SetTypedProperty("FilterOperator2", typedDefinition.FilterOperator2, filterOperatorType);
            }

            if (!string.IsNullOrEmpty(typedDefinition.FilterOperator3))
            {
                wpXml.SetTypedProperty("FilterOperator3", typedDefinition.FilterOperator3, filterOperatorType);
            }

            // FilterDisplayValueXXX

            if (!string.IsNullOrEmpty(typedDefinition.FilterDisplayValue1))
            {
                wpXml.SetOrUpdateProperty("FilterDisplayValue1", typedDefinition.FilterDisplayValue1);
            }

            if (!string.IsNullOrEmpty(typedDefinition.FilterDisplayValue2))
            {
                wpXml.SetOrUpdateProperty("FilterDisplayValue2", typedDefinition.FilterDisplayValue2);
            }

            if (!string.IsNullOrEmpty(typedDefinition.FilterDisplayValue3))
            {
                wpXml.SetOrUpdateProperty("FilterDisplayValue3", typedDefinition.FilterDisplayValue3);
            }


            // bindings
            if (typedDefinition.ServerTemplate.HasValue)
            {
                wpXml.SetOrUpdateProperty("ServerTemplate", typedDefinition.ServerTemplate.ToString());
            }

            if (!string.IsNullOrEmpty(typedDefinition.ContentTypeName))
            {
                wpXml.SetOrUpdateProperty("ContentTypeName", typedDefinition.ContentTypeName);
            }

            if (!string.IsNullOrEmpty(typedDefinition.ContentTypeBeginsWithId))
            {
                wpXml.SetOrUpdateProperty("ContentTypeBeginsWithId", typedDefinition.ContentTypeBeginsWithId);
            }

            if (typedDefinition.ListId.HasGuidValue())
            {
                wpXml.SetTypedProperty("ListId", typedDefinition.ListId.Value.ToString("D"), "Microsoft.SharePoint.Publishing.WebControls.ContentByQueryWebPart+FilterChainingOperator, Microsoft.SharePoint.Publishing, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c");
            }

            if (typedDefinition.ListGuid.HasGuidValue())
            {
                wpXml.SetOrUpdateProperty("ListGuid", typedDefinition.ListGuid.Value.ToString("D"));
            }

            if (!string.IsNullOrEmpty(typedDefinition.ListName))
            {
                wpXml.SetOrUpdateProperty("ListName", typedDefinition.ListName);
            }

            if (!string.IsNullOrEmpty(typedDefinition.WebUrl))
            {
                wpXml.SetOrUpdateProperty("WebUrl", typedDefinition.WebUrl);
            }

            // overrides
            if (!string.IsNullOrEmpty(typedDefinition.ListsOverride))
            {
                wpXml.SetOrUpdateProperty("ListsOverride", typedDefinition.ListsOverride);
            }

            if (!string.IsNullOrEmpty(typedDefinition.ViewFieldsOverride))
            {
                wpXml.SetOrUpdateProperty("ViewFieldsOverride", typedDefinition.ViewFieldsOverride);
            }

            if (!string.IsNullOrEmpty(typedDefinition.QueryOverride))
            {
                wpXml.SetOrUpdateProperty("QueryOverride", typedDefinition.QueryOverride);
            }

            if (!string.IsNullOrEmpty(typedDefinition.CommonViewFields))
            {
                wpXml.SetOrUpdateProperty("CommonViewFields", typedDefinition.CommonViewFields);
            }

            if (typedDefinition.FilterByAudience.HasValue)
            {
                wpXml.SetOrUpdateProperty("FilterByAudience", typedDefinition.FilterByAudience.ToString());
            }


            return(wpXml.ToString());
        }
        protected override string GetWebpartXmlDefinition(ListItemModelHost listItemModelHost, WebPartDefinitionBase webPartModel)
        {
            var typedModel = webPartModel.WithAssertAndCast <AdvancedSearchBoxDefinition>("model", value => value.RequireNotNull());
            var wpXml      = WebpartXmlExtensions
                             .LoadWebpartXmlDocument(BuiltInWebPartTemplates.AdvancedSearchBox);

            if (!string.IsNullOrEmpty(typedModel.AndQueryTextBoxLabelText))
            {
                wpXml.SetOrUpdateAdvancedSearchBoxWebPartProperty("AndQueryTextBoxLabelText", typedModel.AndQueryTextBoxLabelText);
            }

            if (!string.IsNullOrEmpty(typedModel.DisplayGroup))
            {
                wpXml.SetOrUpdateAdvancedSearchBoxWebPartProperty("DisplayGroup", typedModel.DisplayGroup);
            }

            if (!string.IsNullOrEmpty(typedModel.LanguagesLabelText))
            {
                wpXml.SetOrUpdateAdvancedSearchBoxWebPartProperty("LanguagesLabelText", typedModel.LanguagesLabelText);
            }

            if (!string.IsNullOrEmpty(typedModel.NotQueryTextBoxLabelText))
            {
                wpXml.SetOrUpdateAdvancedSearchBoxWebPartProperty("NotQueryTextBoxLabelText", typedModel.NotQueryTextBoxLabelText);
            }

            if (!string.IsNullOrEmpty(typedModel.OrQueryTextBoxLabelText))
            {
                wpXml.SetOrUpdateAdvancedSearchBoxWebPartProperty("OrQueryTextBoxLabelText", typedModel.OrQueryTextBoxLabelText);
            }

            if (!string.IsNullOrEmpty(typedModel.PhraseQueryTextBoxLabelText))
            {
                wpXml.SetOrUpdateAdvancedSearchBoxWebPartProperty("PhraseQueryTextBoxLabelText", typedModel.PhraseQueryTextBoxLabelText);
            }

            if (!string.IsNullOrEmpty(typedModel.AdvancedSearchBoxProperties))
            {
                wpXml.SetOrUpdateAdvancedSearchBoxWebPartProperty("Properties", typedModel.AdvancedSearchBoxProperties);
            }

            if (!string.IsNullOrEmpty(typedModel.PropertiesSectionLabelText))
            {
                wpXml.SetOrUpdateAdvancedSearchBoxWebPartProperty("PropertiesSectionLabelText", typedModel.PropertiesSectionLabelText);
            }

            if (!string.IsNullOrEmpty(typedModel.ResultTypeLabelText))
            {
                wpXml.SetOrUpdateAdvancedSearchBoxWebPartProperty("ResultTypeLabelText", typedModel.ResultTypeLabelText);
            }

            if (!string.IsNullOrEmpty(typedModel.ScopeLabelText))
            {
                wpXml.SetOrUpdateAdvancedSearchBoxWebPartProperty("ScopeLabelText", typedModel.ScopeLabelText);
            }

            if (!string.IsNullOrEmpty(typedModel.ScopeSectionLabelText))
            {
                wpXml.SetOrUpdateAdvancedSearchBoxWebPartProperty("ScopeSectionLabelText", typedModel.ScopeSectionLabelText);
            }

            if (!string.IsNullOrEmpty(typedModel.SearchResultPageURL))
            {
                wpXml.SetOrUpdateAdvancedSearchBoxWebPartProperty("SearchResultPageURL", typedModel.SearchResultPageURL);
            }

            if (typedModel.ShowAndQueryTextBox.HasValue)
            {
                wpXml.SetOrUpdateAdvancedSearchBoxWebPartProperty("ShowAndQueryTextBox", typedModel.ShowAndQueryTextBox.Value.ToString().ToLower());
            }

            if (typedModel.ShowLanguageOptions.HasValue)
            {
                wpXml.SetOrUpdateAdvancedSearchBoxWebPartProperty("ShowLanguageOptions", typedModel.ShowLanguageOptions.Value.ToString().ToLower());
            }

            if (typedModel.ShowNotQueryTextBox.HasValue)
            {
                wpXml.SetOrUpdateAdvancedSearchBoxWebPartProperty("ShowNotQueryTextBox", typedModel.ShowNotQueryTextBox.Value.ToString().ToLower());
            }

            if (typedModel.ShowOrQueryTextBox.HasValue)
            {
                wpXml.SetOrUpdateAdvancedSearchBoxWebPartProperty("ShowOrQueryTextBox", typedModel.ShowOrQueryTextBox.Value.ToString().ToLower());
            }

            if (typedModel.ShowPhraseQueryTextBox.HasValue)
            {
                wpXml.SetOrUpdateAdvancedSearchBoxWebPartProperty("ShowPhraseQueryTextBox", typedModel.ShowPhraseQueryTextBox.Value.ToString().ToLower());
            }

            if (typedModel.ShowPropertiesSection.HasValue)
            {
                wpXml.SetOrUpdateAdvancedSearchBoxWebPartProperty("ShowPropertiesSection", typedModel.ShowPropertiesSection.Value.ToString().ToLower());
            }

            if (typedModel.ShowResultTypePicker.HasValue)
            {
                wpXml.SetOrUpdateAdvancedSearchBoxWebPartProperty("ShowResultTypePicker", typedModel.ShowResultTypePicker.Value.ToString().ToLower());
            }

            if (typedModel.ShowScopes.HasValue)
            {
                wpXml.SetOrUpdateAdvancedSearchBoxWebPartProperty("ShowScopes", typedModel.ShowScopes.Value.ToString().ToLower());
            }

            if (!string.IsNullOrEmpty(typedModel.TextQuerySectionLabelText))
            {
                wpXml.SetOrUpdateAdvancedSearchBoxWebPartProperty("TextQuerySectionLabelText", typedModel.TextQuerySectionLabelText);
            }

            return(wpXml.ToString());
        }
        protected override string GetWebpartXmlDefinition(ListItemModelHost listItemModelHost, WebPartDefinitionBase webPartModel)
        {
            var definition = webPartModel.WithAssertAndCast <ContentBySearchWebPartDefinition>("model", value => value.RequireNotNull());
            var xml        = WebpartXmlExtensions.LoadWebpartXmlDocument(BuiltInWebPartTemplates.ContentBySearchWebPart);

            // JSON
            if (!string.IsNullOrEmpty(definition.DataProviderJSON))
            {
                xml.SetDataProviderJSON(definition.DataProviderJSON);
            }

            // templates
            if (!string.IsNullOrEmpty(definition.GroupTemplateId))
            {
                xml.SetGroupTemplateId(definition.GroupTemplateId);
            }

            if (!string.IsNullOrEmpty(definition.ItemTemplateId))
            {
                xml.SetItemTemplateId(definition.ItemTemplateId);
            }

            if (!string.IsNullOrEmpty(definition.RenderTemplateId))
            {
                xml.SetRenderTemplateId(definition.RenderTemplateId);
            }

            // item counts
            if (definition.NumberOfItems.HasValue)
            {
                xml.SetNumberOfItems(definition.NumberOfItems.Value);
            }

            if (definition.ResultsPerPage.HasValue)
            {
                xml.SetResultsPerPage(definition.ResultsPerPage.Value);
            }

            // misc
            if (!string.IsNullOrEmpty(definition.PropertyMappings))
            {
                xml.SetPropertyMappings(definition.PropertyMappings);
            }

            if (definition.OverwriteResultPath.HasValue)
            {
                xml.SetOverwriteResultPath(definition.OverwriteResultPath.Value);
            }

            if (definition.ShouldHideControlWhenEmpty.HasValue)
            {
                xml.SetShouldHideControlWhenEmpty(definition.ShouldHideControlWhenEmpty.Value);
            }

            if (definition.LogAnalyticsViewEvent.HasValue)
            {
                xml.SetLogAnalyticsViewEvent(definition.LogAnalyticsViewEvent.Value);
            }

            if (definition.AddSEOPropertiesFromSearch.HasValue)
            {
                xml.SetAddSEOPropertiesFromSearch(definition.AddSEOPropertiesFromSearch.Value);
            }

            if (definition.StartingItemIndex.HasValue)
            {
                xml.SetStartingItemIndex(definition.StartingItemIndex.Value);
            }

            return(xml.ToString());
        }
Example #17
0
        protected virtual string ProcessCommonWebpartProperties(string webPartXml, WebPartDefinitionBase definition)
        {
            var xml = WebpartXmlExtensions.LoadWebpartXmlDocument(webPartXml)
                      .SetTitle(definition.Title)
                      .SetID(definition.Id);

            if (definition.Width.HasValue)
            {
                xml.SetWidth(definition.Width.Value);
            }

            if (definition.Height.HasValue)
            {
                xml.SetHeight(definition.Height.Value);
            }

            if (!string.IsNullOrEmpty(definition.Description))
            {
                xml.SetDescription(definition.Description);
            }

            if (!string.IsNullOrEmpty(definition.ImportErrorMessage))
            {
                xml.SetImportErrorMessage(definition.ImportErrorMessage);
            }

            if (!string.IsNullOrEmpty(definition.TitleUrl))
            {
                var urlValue = definition.TitleUrl ?? string.Empty;

                TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Original value: [{0}]", urlValue);

                urlValue = TokenReplacementService.ReplaceTokens(new TokenReplacementContext
                {
                    Value   = urlValue,
                    Context = CurrentClientContext
                }).Value;

                TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Token replaced value: [{0}]", urlValue);

                xml.SetTitleUrl(urlValue);
            }

            if (!string.IsNullOrEmpty(definition.TitleIconImageUrl))
            {
                xml.SetTitleIconImageUrl(definition.TitleIconImageUrl);
            }

            if (!string.IsNullOrEmpty(definition.ChromeState))
            {
                xml.SetChromeState(definition.ChromeState);
            }

            if (!string.IsNullOrEmpty(definition.ChromeType))
            {
                var chromeType = string.Empty;

                if (xml.IsV3version())
                {
                    chromeType = WebPartChromeTypesConvertService.NormilizeValueToPartChromeTypes(definition.ChromeType);
                }
                else if (xml.IsV2version())
                {
                    chromeType = WebPartChromeTypesConvertService.NormilizeValueToFrameTypes(definition.ChromeType);
                }

                // SetChromeType() sets correct XML props depending on V2/V3 web part XML
                xml.SetChromeType(chromeType);
            }

            if (!string.IsNullOrEmpty(definition.ExportMode))
            {
                xml.SetExportMode(definition.ExportMode);
            }

            // bindings
            ProcessParameterBindings(definition, xml);

            // properties
            ProcessWebpartProperties(definition, xml);


            return(xml.ToString());
        }
        public override void DeployModel(object modelHost, DefinitionBase model)
        {
            var folderModelHost = modelHost.WithAssertAndCast <FolderModelHost>("modelHost", value => value.RequireNotNull());

            var folder     = folderModelHost.CurrentLibraryFolder;
            var definition = model.WithAssertAndCast <WebPartGalleryFileDefinition>("model", value => value.RequireNotNull());

            CurrentModel = definition;

            var spObject = GetCurrentObject(folder, definition);
            var file     = spObject.File;

            var assert = ServiceFactory.AssertService
                         .NewAssert(definition, spObject)
                         .ShouldNotBeNull(spObject)
                         .ShouldBeEqual(m => m.Title, o => o.Title)
                         .ShouldBeEqual(m => m.FileName, o => o.Name)

                         .ShouldBeEqual(m => m.Description, o => o.GetWebPartGalleryFileDescription())
                         .ShouldBeEqual(m => m.Group, o => o.GetWebPartGalleryFileGroup())
            ;


            assert.ShouldBeEqual((p, s, d) =>
            {
                var srcProp = s.GetExpressionValue(m => m.Content);
                //var dstProp = d.GetExpressionValue(ct => ct.GetId());

                var isContentValid = true;

                var srcStringContent = Encoding.UTF8.GetString(s.Content);
                var dstStringContent = Encoding.UTF8.GetString(file.GetContent());

                srcStringContent = WebpartXmlExtensions
                                   .LoadWebpartXmlDocument(srcStringContent)
                                   .SetTitle(s.Title)
                                   .SetOrUpdateProperty("Description", s.Description)
                                   .ToString();


                dstStringContent = WebpartXmlExtensions.LoadWebpartXmlDocument(dstStringContent).ToString();

                isContentValid = dstStringContent.Contains(srcStringContent);

                return(new PropertyValidationResult
                {
                    Tag = p.Tag,
                    Src = srcProp,
                    // Dst = dstProp,
                    IsValid = isContentValid
                });
            });

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

                    var targetControlTypeValue  = d.GetWebPartGalleryFileRecommendationSettings();
                    var targetControlTypeValues = new List <string>();

                    for (var i = 0; i < targetControlTypeValue.Count; i++)
                    {
                        targetControlTypeValues.Add(targetControlTypeValue[i].ToUpper());
                    }

                    foreach (var v in s.RecommendationSettings)
                    {
                        if (!targetControlTypeValues.Contains(v.ToUpper()))
                        {
                            isValid = false;
                        }
                    }

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

            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 = spObject[value.FieldId.Value];
                        }
                        else
                        {
                            itemValue = spObject[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.Any())
            {
                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 = spObject[value.FieldId.Value];
                        }
                        else
                        {
                            itemValue = spObject[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 is empty. Skipping.");
            }
        }
        public override void DeployModel(object modelHost, DefinitionBase model)
        {
            var folderModelHost = modelHost.WithAssertAndCast <FolderModelHost>("modelHost", value => value.RequireNotNull());

            var folder     = folderModelHost.CurrentListFolder;
            var definition = model.WithAssertAndCast <WebPartGalleryFileDefinition>("model", value => value.RequireNotNull());

            var file     = GetItemFile(folderModelHost.CurrentList, folder, definition.FileName);
            var spObject = file.ListItemAllFields;

            var context = spObject.Context;

            context.Load(file, f => f.ServerRelativeUrl);
            context.Load(spObject);
            context.ExecuteQueryWithTrace();

            var assert = ServiceFactory.AssertService
                         .NewAssert(definition, spObject)
                         .ShouldNotBeNull(spObject)
                         .ShouldBeEqual(m => m.Title, o => o.GetTitle())
                         .ShouldBeEqual(m => m.FileName, o => o.GetName())

                         .ShouldBeEqual(m => m.Description, o => o.GetWebPartGalleryFileDescription())
                         .ShouldBeEqual(m => m.Group, o => o.GetWebPartGalleryFileGroup())
            ;

            assert.ShouldBeEqual((p, s, d) =>
            {
                var srcProp = s.GetExpressionValue(m => m.Content);
                //var dstProp = d.GetExpressionValue(ct => ct.GetId());

                var isContentValid = true;

                byte[] dstContent = null;

                using (var stream = File.OpenBinaryDirect(folderModelHost.HostClientContext, file.ServerRelativeUrl).Stream)
                    dstContent = ModuleFileUtils.ReadFully(stream);

                var srcStringContent = Encoding.UTF8.GetString(s.Content);
                var dstStringContent = Encoding.UTF8.GetString(dstContent);

                srcStringContent = WebpartXmlExtensions
                                   .LoadWebpartXmlDocument(srcStringContent)
                                   .SetTitle(s.Title)
                                   .SetOrUpdateProperty("Description", s.Description)
                                   .ToString();


                dstStringContent = WebpartXmlExtensions.LoadWebpartXmlDocument(dstStringContent).ToString();


                isContentValid = dstStringContent.Contains(srcStringContent);

                return(new PropertyValidationResult
                {
                    Tag = p.Tag,
                    Src = srcProp,
                    // Dst = dstProp,
                    IsValid = isContentValid
                });
            });

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

                    // TODO
                    //var targetControlTypeValue = d.GetWebPartGalleryFileRecommendationSettings();
                    //var targetControlTypeValues = new List<string>();

                    //for (var i = 0; i < targetControlTypeValue.Count; i++)
                    //    targetControlTypeValues.Add(targetControlTypeValue[i].ToUpper());

                    //foreach (var v in s.RecommendationSettings)
                    //{
                    //    if (!targetControlTypeValues.Contains(v.ToUpper()))
                    //        isValid = false;
                    //}

                    return(new PropertyValidationResult
                    {
                        Tag = p.Tag,
                        Src = srcProp,
                        Dst = null,
                        IsValid = isValid
                    });
                });
            }
            else
            {
                assert.SkipProperty(m => m.RecommendationSettings, "RecommendationSettings is empty. Skipping.");
            }
        }
        protected override string GetWebpartXmlDefinition(ListItemModelHost listItemModelHost, WebPartDefinitionBase webPartModel)
        {
            var definition = webPartModel.WithAssertAndCast <ResultScriptWebPartDefinition>("model", value => value.RequireNotNull());
            var xml        = WebpartXmlExtensions.LoadWebpartXmlDocument(ProcessCommonWebpartProperties(BuiltInWebPartTemplates.ResultScriptWebPart, webPartModel));

            if (!string.IsNullOrEmpty(definition.DataProviderJSON))
            {
                xml.SetOrUpdateProperty("DataProviderJSON", definition.DataProviderJSON);
            }

            if (!string.IsNullOrEmpty(definition.EmptyMessage))
            {
                xml.SetOrUpdateProperty("EmptyMessage", definition.EmptyMessage);
            }

            if (definition.ResultsPerPage.HasValue)
            {
                xml.SetOrUpdateProperty("ResultsPerPage", definition.ResultsPerPage.Value.ToString());
            }

            if (definition.ShowResultCount.HasValue)
            {
                xml.SetOrUpdateProperty("ShowResultCount", definition.ShowResultCount.Value.ToString());
            }

            if (definition.MaxPagesBeforeCurrent.HasValue)
            {
                xml.SetOrUpdateProperty("MaxPagesBeforeCurrent", definition.MaxPagesBeforeCurrent.Value.ToString());
            }

            if (definition.ShowBestBets.HasValue)
            {
                xml.SetOrUpdateProperty("ShowBestBets", definition.ShowBestBets.Value.ToString());
            }

            if (definition.ShowViewDuplicates.HasValue)
            {
                xml.SetOrUpdateProperty("ShowViewDuplicates", definition.ShowViewDuplicates.Value.ToString());
            }

            if (definition.Height.HasValue)
            {
                xml.SetOrUpdateProperty("Height", definition.Height.Value.ToString());
            }

            if (!string.IsNullOrEmpty(definition.AdvancedSearchPageAddress))
            {
                xml.SetOrUpdateProperty("AdvancedSearchPageAddress", definition.AdvancedSearchPageAddress);
            }

            if (definition.UseSharedDataProvider.HasValue)
            {
                xml.SetOrUpdateProperty("UseSharedDataProvider", definition.UseSharedDataProvider.Value.ToString());
            }

            if (definition.ShowPreferencesLink.HasValue)
            {
                xml.SetOrUpdateProperty("ShowPreferencesLink", definition.ShowPreferencesLink.Value.ToString());
            }

            if (definition.RepositionLanguageDropDown.HasValue)
            {
                xml.SetOrUpdateProperty("RepositionLanguageDropDown", definition.RepositionLanguageDropDown.Value.ToString());
            }

            if (!string.IsNullOrEmpty(definition.PreloadedItemTemplateIdsJson))
            {
                xml.SetOrUpdateProperty("PreloadedItemTemplateIdsJson", definition.PreloadedItemTemplateIdsJson);
            }

            if (definition.ShowPaging.HasValue)
            {
                xml.SetOrUpdateProperty("ShowPaging", definition.ShowPaging.Value.ToString());
            }

            if (!string.IsNullOrEmpty(definition.ResultTypeId))
            {
                xml.SetOrUpdateProperty("ResultTypeId", definition.ResultTypeId);
            }

            if (!string.IsNullOrEmpty(definition.Title))
            {
                xml.SetOrUpdateProperty("Title", definition.Title);
            }

            if (definition.ShowResults.HasValue)
            {
                xml.SetOrUpdateProperty("ShowResults", definition.ShowResults.Value.ToString());
            }

            if (definition.Hidden.HasValue)
            {
                xml.SetOrUpdateProperty("Hidden", definition.Hidden.Value.ToString());
            }

            if (!string.IsNullOrEmpty(definition.ItemTemplateId))
            {
                xml.SetOrUpdateProperty("ItemTemplateId", definition.ItemTemplateId);
            }

            if (!string.IsNullOrEmpty(definition.ItemBodyTemplateId))
            {
                xml.SetOrUpdateProperty("ItemBodyTemplateId", definition.ItemBodyTemplateId);
            }

            if (!string.IsNullOrEmpty(definition.HitHighlightedPropertiesJson))
            {
                xml.SetOrUpdateProperty("HitHighlightedPropertiesJson", definition.HitHighlightedPropertiesJson);
            }

            if (!string.IsNullOrEmpty(definition.AvailableSortsJson))
            {
                xml.SetOrUpdateProperty("AvailableSortsJson", definition.AvailableSortsJson);
            }

            if (!string.IsNullOrEmpty(definition.RenderTemplateId))
            {
                xml.SetOrUpdateProperty("RenderTemplateId", definition.RenderTemplateId);
            }

            if (definition.ShowPersonalFavorites.HasValue)
            {
                xml.SetOrUpdateProperty("ShowPersonalFavorites", definition.ShowPersonalFavorites.Value.ToString());
            }

            if (definition.ShowSortOptions.HasValue)
            {
                xml.SetOrUpdateProperty("ShowSortOptions", definition.ShowSortOptions.Value.ToString());
            }

            if (definition.ShowLanguageOptions.HasValue)
            {
                xml.SetOrUpdateProperty("ShowLanguageOptions", definition.ShowLanguageOptions.Value.ToString());
            }

            if (!string.IsNullOrEmpty(definition.Description))
            {
                xml.SetOrUpdateProperty("Description", definition.Description);
            }

            if (!string.IsNullOrEmpty(definition.TitleUrl))
            {
                xml.SetOrUpdateProperty("TitleUrl", definition.TitleUrl);
            }

            if (definition.ShowAlertMe.HasValue)
            {
                xml.SetOrUpdateProperty("ShowAlertMe", definition.ShowAlertMe.Value.ToString());
            }

            if (definition.ShowDidYouMean.HasValue)
            {
                xml.SetOrUpdateProperty("ShowDidYouMean", definition.ShowDidYouMean.Value.ToString());
            }

            if (!string.IsNullOrEmpty(definition.QueryGroupName))
            {
                xml.SetOrUpdateProperty("QueryGroupName", definition.QueryGroupName);
            }

            if (definition.Width.HasValue)
            {
                xml.SetOrUpdateProperty("Width", definition.Width.Value.ToString());
            }

            if (definition.ShowAdvancedLink.HasValue)
            {
                xml.SetOrUpdateProperty("ShowAdvancedLink", definition.ShowAdvancedLink.Value.ToString());
            }

            if (definition.BypassResultTypes.HasValue)
            {
                xml.SetOrUpdateProperty("BypassResultTypes", definition.BypassResultTypes.Value.ToString());
            }

            if (!string.IsNullOrEmpty(definition.GroupTemplateId))
            {
                xml.SetOrUpdateProperty("GroupTemplateId", definition.GroupTemplateId);
            }

            if (!string.IsNullOrEmpty(definition.TitleIconImageUrl))
            {
                xml.SetOrUpdateProperty("TitleIconImageUrl", definition.TitleIconImageUrl);
            }

            return(xml.ToString());
        }