Beispiel #1
0
        protected override void ProcessWebpartProperties(WebPart webpartInstance, WebPartDefinition webpartModel)
        {
            base.ProcessWebpartProperties(webpartInstance, webpartModel);

            var typedWebpart = webpartInstance.WithAssertAndCast <SPUserCodeWebPart>("webpartInstance", value => value.RequireNotNull());
            var typedModel   = webpartModel.WithAssertAndCast <UserCodeWebPartDefinition>("webpartModel", value => value.RequireNotNull());


            // TODO
            typedWebpart.SolutionId       = typedModel.SolutionId;
            typedWebpart.AssemblyFullName = typedModel.AssemblyFullName;
            typedWebpart.TypeFullName     = typedModel.TypeFullName;

            foreach (var prop in typedModel.UserCodeProperties)
            {
                var currentProperty = typedWebpart.Properties
                                      .OfType <SPUserCodeProperty>()
                                      .FirstOrDefault(p => p.Name.ToUpper() == prop.Name.ToUpper());

                if (currentProperty == null)
                {
                    currentProperty      = new SPUserCodeProperty();
                    currentProperty.Name = prop.Name;

                    typedWebpart.Properties.Add(currentProperty);
                }

                currentProperty.Value = prop.Value;
            }
        }
        protected override void ProcessWebpartProperties(WebPart webpartInstance, WebPartDefinition webpartModel)
        {
            base.ProcessWebpartProperties(webpartInstance, webpartModel);

            var typedWebpart = webpartInstance.WithAssertAndCast<SPUserCodeWebPart>("webpartInstance", value => value.RequireNotNull());
            var typedModel = webpartModel.WithAssertAndCast<UserCodeWebPartDefinition>("webpartModel", value => value.RequireNotNull());


            // TODO
            typedWebpart.SolutionId = typedModel.SolutionId;
            typedWebpart.AssemblyFullName = typedModel.AssemblyFullName;
            typedWebpart.TypeFullName = typedModel.TypeFullName;

            foreach (var prop in typedModel.UserCodeProperties)
            {
                var currentProperty = typedWebpart.Properties
                    .OfType<SPUserCodeProperty>()
                    .FirstOrDefault(p => p.Name.ToUpper() == prop.Name.ToUpper());

                if (currentProperty == null)
                {
                    currentProperty = new SPUserCodeProperty();
                    currentProperty.Name = prop.Name;

                    typedWebpart.Properties.Add(currentProperty);
                }

                currentProperty.Value = prop.Value;
            }
        }
        protected override void ProcessWebpartProperties(WebPart webpartInstance, WebPartDefinition webpartModel)
        {
            base.ProcessWebpartProperties(webpartInstance, webpartModel);

            var typedWebpart = webpartInstance.WithAssertAndCast<SPUserCodeWebPart>("webpartInstance", value => value.RequireNotNull());
            var typedModel = webpartModel.WithAssertAndCast<UserCodeWebPartDefinition>("webpartModel", value => value.RequireNotNull());


            // TODO
            typedWebpart.SolutionId = typedModel.SolutionId;
            typedWebpart.AssemblyFullName = typedModel.AssemblyFullName;
            typedWebpart.TypeFullName = typedModel.TypeFullName;

            foreach (var prop in typedModel.UserCodeProperties)
            {
                var currentProperty = typedWebpart.Properties
                    .OfType<SPUserCodeProperty>()
                    .FirstOrDefault(p => p.Name.ToUpper() == prop.Name.ToUpper());

                if (currentProperty == null)
                {
                    currentProperty = new SPUserCodeProperty
                    {
                        Name = prop.Name
                    };

                    typedWebpart.Properties.Add(currentProperty);
                }

                if (prop.IsTokenisable.HasValue && prop.IsTokenisable.Value)
                {
                    // Enhance 'UserCodeWebPartDefinition' 
                    // UserCodeProperty should support ~sitecollection/~site tokens #485

                    var value = TokenReplacementService.ReplaceTokens(new TokenReplacementContext
                    {
                        Value = prop.Value,
                        Context = CurrentHost.HostFile.Web
                    }).Value;

                    currentProperty.Value = value;
                }
                else
                {
                    currentProperty.Value = prop.Value;
                }
            }
        }
        protected override void ProcessWebpartProperties(WebPart webpartInstance, WebPartDefinition webpartModel)
        {
            base.ProcessWebpartProperties(webpartInstance, webpartModel);

            var typedWebpart = webpartInstance.WithAssertAndCast <SPUserCodeWebPart>("webpartInstance", value => value.RequireNotNull());
            var typedModel   = webpartModel.WithAssertAndCast <UserCodeWebPartDefinition>("webpartModel", value => value.RequireNotNull());


            // TODO
            typedWebpart.SolutionId       = typedModel.SolutionId;
            typedWebpart.AssemblyFullName = typedModel.AssemblyFullName;
            typedWebpart.TypeFullName     = typedModel.TypeFullName;

            foreach (var prop in typedModel.UserCodeProperties)
            {
                var currentProperty = typedWebpart.Properties
                                      .OfType <SPUserCodeProperty>()
                                      .FirstOrDefault(p => p.Name.ToUpper() == prop.Name.ToUpper());

                if (currentProperty == null)
                {
                    currentProperty = new SPUserCodeProperty
                    {
                        Name = prop.Name
                    };

                    typedWebpart.Properties.Add(currentProperty);
                }

                if (prop.IsTokenisable.HasValue && prop.IsTokenisable.Value)
                {
                    // Enhance 'UserCodeWebPartDefinition'
                    // UserCodeProperty should support ~sitecollection/~site tokens #485

                    var value = TokenReplacementService.ReplaceTokens(new TokenReplacementContext
                    {
                        Value   = prop.Value,
                        Context = CurrentHost.HostFile.Web
                    }).Value;

                    currentProperty.Value = value;
                }
                else
                {
                    currentProperty.Value = prop.Value;
                }
            }
        }