Beispiel #1
0
        private void AddWebPartToList(WebPartCollection webParts, Control control)
        {
            WebPart part = control as WebPart;

            // We used to throw an exception if the template contained a non-whitespace literal.
            // However, sometimes Venus would insert <br /> tags between the server controls
            // in the template.  So, we now just ignore all literals.
            if ((part == null) && !(control is LiteralControl))
            {
                WebPartManager manager = WebPartManager;
                if (manager != null)
                {
                    part = manager.CreateWebPart(control);
                }
                else
                {
                    part = WebPartManager.CreateWebPartStatic(control);
                }
            }

            if (part != null)
            {
                webParts.Add(part);
            }
        }
 protected internal override WebPartCollection GetInitialWebParts()
 {
     WebPartCollection webParts = new WebPartCollection();
     if (this.ZoneTemplate != null)
     {
         Control container = new NonParentingControl();
         this.ZoneTemplate.InstantiateIn(container);
         if (!container.HasControls())
         {
             return webParts;
         }
         foreach (Control control2 in container.Controls)
         {
             if (control2 is ContentPlaceHolder)
             {
                 if (control2.HasControls())
                 {
                     Control[] array = new Control[control2.Controls.Count];
                     control2.Controls.CopyTo(array, 0);
                     foreach (Control control3 in array)
                     {
                         this.AddWebPartToList(webParts, control3);
                     }
                 }
             }
             else
             {
                 this.AddWebPartToList(webParts, control2);
             }
         }
     }
     return webParts;
 }
        protected internal override WebPartCollection GetInitialWebParts() {
            WebPartCollection webParts = new WebPartCollection();

            if (ZoneTemplate != null) {
                // PERF: Instantiate the template into a special control, that does nothing when a child control
                // is added.  This is more performant because the child control is never parented to the temporary
                // control, it's ID is never generated, etc.
                Control container = new NonParentingControl();
                ZoneTemplate.InstantiateIn(container);

                if (container.HasControls()) {
                    ControlCollection controls = container.Controls;
                    foreach (Control control in controls) {
                        if (control is ContentPlaceHolder) {
                            if (control.HasControls()) {
                                Control[] children = new Control[control.Controls.Count];
                                control.Controls.CopyTo(children, 0);
                                foreach (Control child in children) {
                                    AddWebPartToList(webParts, child);
                                }
                            }
                        }
                        else {
                            AddWebPartToList(webParts, control);
                        }
                    }
                }
            }

            return webParts;
        }
Beispiel #4
0
        protected internal override WebPartCollection GetInitialWebParts()
        {
            WebPartCollection webParts = new WebPartCollection();

            if (this.ZoneTemplate != null)
            {
                Control container = new NonParentingControl();
                this.ZoneTemplate.InstantiateIn(container);
                if (!container.HasControls())
                {
                    return(webParts);
                }
                foreach (Control control2 in container.Controls)
                {
                    if (control2 is ContentPlaceHolder)
                    {
                        if (control2.HasControls())
                        {
                            Control[] array = new Control[control2.Controls.Count];
                            control2.Controls.CopyTo(array, 0);
                            foreach (Control control3 in array)
                            {
                                this.AddWebPartToList(webParts, control3);
                            }
                        }
                    }
                    else
                    {
                        this.AddWebPartToList(webParts, control2);
                    }
                }
            }
            return(webParts);
        }
        protected override void Render(System.Web.UI.HtmlTextWriter writer)
        {
            bool inEditMode = false;
            var webpartZone = Control as Microsoft.SharePoint.WebPartPages.WebPartZone;
            if (webpartZone != null)
            {
                var wpManager = (SPWebPartManager)WebPartManager.GetCurrentWebPartManager(webpartZone.Page);
                if (wpManager != null)
                {
                    inEditMode = wpManager.GetDisplayMode().AllowPageDesign;
                }
            }

            if (!inEditMode)
            {
                if (webpartZone.WebParts.Count > 0)
                {
                    WebPartCollection wpColl = new WebPartCollection(webpartZone.WebParts);
                    foreach (System.Web.UI.WebControls.WebParts.WebPart wp in wpColl)
                    {
                        wp.RenderControl(writer);
                    }
                }
            }
            else
            {
                base.Render(writer);
            }
        }
        private WebPartCollection GetClosedWebParts()
        {
            ArrayList         webParts = new ArrayList();
            WebPartCollection parts    = base.WebPartManager.WebParts;

            if (parts != null)
            {
                foreach (WebPart part in parts)
                {
                    if (part.IsClosed)
                    {
                        webParts.Add(part);
                    }
                }
            }
            return(new WebPartCollection(webParts));
        }
        public override WebPartDescriptionCollection GetAvailableWebPartDescriptions()
        {
            if (DesignMode)
            {
                return(DesignModeAvailableWebParts);
            }

            if (_availableWebPartDescriptions == null)
            {
                WebPartCollection availableWebParts;
                if (WebPartManager != null)
                {
                    WebPartCollection closedWebParts = GetClosedWebParts();
                    if (closedWebParts != null)
                    {
                        availableWebParts = closedWebParts;
                    }
                    else
                    {
                        availableWebParts = new WebPartCollection();
                    }
                }
                else
                {
                    availableWebParts = new WebPartCollection();
                }

                ArrayList descriptions = new ArrayList();
                foreach (WebPart part in availableWebParts)
                {
                    // Do not show UnauthorizedWebParts (VSWhidbey 429514)
                    if (part is UnauthorizedWebPart)
                    {
                        continue;
                    }

                    WebPartDescription description = new WebPartDescription(part);
                    descriptions.Add(description);
                }

                _availableWebPartDescriptions = new WebPartDescriptionCollection(descriptions);
            }

            return(_availableWebPartDescriptions);
        }
 private void AddWebPartToList(WebPartCollection webParts, Control control)
 {
     WebPart part = control as WebPart;
     if ((part == null) && !(control is LiteralControl))
     {
         WebPartManager webPartManager = base.WebPartManager;
         if (webPartManager != null)
         {
             part = webPartManager.CreateWebPart(control);
         }
         else
         {
             part = WebPartManager.CreateWebPartStatic(control);
         }
     }
     if (part != null)
     {
         webParts.Add(part);
     }
 }
        private void AddWebPartToList(WebPartCollection webParts, Control control) {
            WebPart part = control as WebPart;

            // We used to throw an exception if the template contained a non-whitespace literal.
            // However, sometimes Venus would insert <br /> tags between the server controls
            // in the template.  So, we now just ignore all literals.
            if ((part == null) && !(control is LiteralControl)) {
                WebPartManager manager = WebPartManager;
                if (manager != null) {
                    part = manager.CreateWebPart(control);
                }
                else {
                    part = WebPartManager.CreateWebPartStatic(control);
                }
            }

            if (part != null) {
                webParts.Add(part);
            }
        }
Beispiel #10
0
        private void AddWebPartToList(WebPartCollection webParts, Control control)
        {
            WebPart part = control as WebPart;

            if ((part == null) && !(control is LiteralControl))
            {
                WebPartManager webPartManager = base.WebPartManager;
                if (webPartManager != null)
                {
                    part = webPartManager.CreateWebPart(control);
                }
                else
                {
                    part = WebPartManager.CreateWebPartStatic(control);
                }
            }
            if (part != null)
            {
                webParts.Add(part);
            }
        }
Beispiel #11
0
        protected internal override WebPartCollection GetInitialWebParts()
        {
            WebPartCollection webParts = new WebPartCollection();

            if (ZoneTemplate != null)
            {
                // PERF: Instantiate the template into a special control, that does nothing when a child control
                // is added.  This is more performant because the child control is never parented to the temporary
                // control, it's ID is never generated, etc.
                Control container = new NonParentingControl();
                ZoneTemplate.InstantiateIn(container);

                if (container.HasControls())
                {
                    ControlCollection controls = container.Controls;
                    foreach (Control control in controls)
                    {
                        if (control is ContentPlaceHolder)
                        {
                            if (control.HasControls())
                            {
                                Control[] children = new Control[control.Controls.Count];
                                control.Controls.CopyTo(children, 0);
                                foreach (Control child in children)
                                {
                                    AddWebPartToList(webParts, child);
                                }
                            }
                        }
                        else
                        {
                            AddWebPartToList(webParts, control);
                        }
                    }
                }
            }

            return(webParts);
        }
        private WebPartCollection GetClosedWebParts()
        {
            // WebPartManager is checked for null in calling code
            Debug.Assert(WebPartManager != null);

            ArrayList closedWebParts = new ArrayList();

            WebPartCollection webParts = WebPartManager.WebParts;

            if (webParts != null)
            {
                foreach (WebPart part in webParts)
                {
                    if (part.IsClosed)
                    {
                        closedWebParts.Add(part);
                    }
                }
            }

            return(new WebPartCollection(closedWebParts));
        }
 public override WebPartDescriptionCollection GetAvailableWebPartDescriptions()
 {
     if (base.DesignMode)
     {
         return(DesignModeAvailableWebParts);
     }
     if (this._availableWebPartDescriptions == null)
     {
         WebPartCollection parts;
         if (base.WebPartManager != null)
         {
             WebPartCollection closedWebParts = this.GetClosedWebParts();
             if (closedWebParts != null)
             {
                 parts = closedWebParts;
             }
             else
             {
                 parts = new WebPartCollection();
             }
         }
         else
         {
             parts = new WebPartCollection();
         }
         ArrayList webPartDescriptions = new ArrayList();
         foreach (WebPart part in parts)
         {
             if (!(part is UnauthorizedWebPart))
             {
                 WebPartDescription description = new WebPartDescription(part);
                 webPartDescriptions.Add(description);
             }
         }
         this._availableWebPartDescriptions = new WebPartDescriptionCollection(webPartDescriptions);
     }
     return(this._availableWebPartDescriptions);
 }
        public override WebPartDescriptionCollection GetAvailableWebPartDescriptions() {
            if (DesignMode) {
                return DesignModeAvailableWebParts;
            }

            if (_availableWebPartDescriptions == null) {
                WebPartCollection availableWebParts;
                if (WebPartManager != null) {
                    WebPartCollection closedWebParts = GetClosedWebParts();
                    if (closedWebParts != null) {
                        availableWebParts = closedWebParts;
                    }
                    else {
                        availableWebParts = new WebPartCollection();
                    }
                }
                else {
                    availableWebParts = new WebPartCollection();
                }

                ArrayList descriptions = new ArrayList();
                foreach(WebPart part in availableWebParts) {
                    // Do not show UnauthorizedWebParts (VSWhidbey 429514)
                    if (part is UnauthorizedWebPart) {
                        continue;
                    }

                    WebPartDescription description = new WebPartDescription(part);
                    descriptions.Add(description);
                }

                _availableWebPartDescriptions = new WebPartDescriptionCollection(descriptions);
            }

            return _availableWebPartDescriptions;
        }
 internal void AddWebPartsFromZone(WebPartZoneBase zone, WebPartCollection webParts)
 {
     if ((webParts != null) && (webParts.Count != 0))
     {
         string errorMsg = base.SetCollectionReadOnly(null);
         try
         {
             try
             {
                 string iD = zone.ID;
                 int zoneIndex = 0;
                 foreach (WebPart part in webParts)
                 {
                     this._manager.Internals.SetIsShared(part, true);
                     WebPart webPart = part;
                     if (!this._manager.IsAuthorized(part))
                     {
                         webPart = new UnauthorizedWebPart(part);
                     }
                     this._manager.Internals.SetIsStatic(webPart, true);
                     this._manager.Internals.SetIsShared(webPart, true);
                     this._manager.Internals.SetZoneID(webPart, iD);
                     this._manager.Internals.SetZoneIndex(webPart, zoneIndex);
                     this.AddWebPartHelper(webPart);
                     zoneIndex++;
                 }
             }
             finally
             {
                 base.SetCollectionReadOnly(errorMsg);
             }
         }
         catch
         {
             throw;
         }
     }
 }
 internal WebPartCollection GetWebPartsForZone(WebPartZoneBase zone)
 {
     if (zone == null)
     {
         throw new ArgumentNullException("zone");
     }
     if (!this._webPartZones.Contains(zone))
     {
         throw new ArgumentException(System.Web.SR.GetString("WebPartManager_MustRegister"), "zone");
     }
     IList allWebPartsForZone = this.GetAllWebPartsForZone(zone);
     WebPartCollection parts = new WebPartCollection();
     if (allWebPartsForZone.Count > 0)
     {
         foreach (WebPart part in allWebPartsForZone)
         {
             if (this.ShouldRenderWebPartInZone(part, zone))
             {
                 parts.Add(part);
             }
         }
     }
     return parts;
 }
        private IDictionary GetValidProviders(WebPart consumer, ConsumerConnectionPoint consumerConnectionPoint,
                                              WebPartCollection webParts) {
            HybridDictionary validProviders = new HybridDictionary();

            // ConnectionsZone must check the AllowConnect property, since it only affects the UI
            // and is not checked by CanConnectWebParts()
            if (consumerConnectionPoint == null || consumer == null || !consumer.AllowConnect) {
                return validProviders;
            }

            // PERF: Skip if consumer is already connected, and does not allow multiple connections
            if (!consumerConnectionPoint.AllowsMultipleConnections &&
                WebPartManager.IsConsumerConnected(consumer, consumerConnectionPoint)) {
                return validProviders;
            }

            foreach (WebPart provider in webParts) {
                // ConnectionsZone must check the AllowConnect property, since it only affects the UI
                // and is not checked by CanConnectWebParts()
                if (!provider.AllowConnect) {
                    continue;
                }

                // PERF: Skip provider if it equals consumer or is closed
                if (provider == consumer || provider.IsClosed) {
                    continue;
                }

                foreach (ProviderConnectionPoint providerConnectionPoint in WebPartManager.GetProviderConnectionPoints(provider)) {
                    if (WebPartManager.CanConnectWebParts(provider, providerConnectionPoint,
                                                          consumer, consumerConnectionPoint)) {
                        validProviders.Add(provider.ID + ID_SEPARATOR + providerConnectionPoint.ID,
                            new ProviderInfo(provider, providerConnectionPoint));
                    }
                    else {
                        foreach (WebPartTransformer transformer in AvailableTransformers) {
                            if (WebPartManager.CanConnectWebParts(provider, providerConnectionPoint,
                                                                  consumer, consumerConnectionPoint, transformer)) {
                                validProviders.Add(provider.ID + ID_SEPARATOR + providerConnectionPoint.ID,
                                    new ProviderInfo(provider, providerConnectionPoint, transformer.GetType()));
                                break;
                            }
                        }
                    }
                }
            }

            return validProviders;
        }
 private IDictionary GetValidProviders(WebPart consumer, ConsumerConnectionPoint consumerConnectionPoint, WebPartCollection webParts)
 {
     HybridDictionary dictionary = new HybridDictionary();
     if ((((consumerConnectionPoint != null) && (consumer != null)) && consumer.AllowConnect) && (consumerConnectionPoint.AllowsMultipleConnections || !base.WebPartManager.IsConsumerConnected(consumer, consumerConnectionPoint)))
     {
         foreach (WebPart part in webParts)
         {
             if ((part.AllowConnect && (part != consumer)) && !part.IsClosed)
             {
                 foreach (ProviderConnectionPoint point in base.WebPartManager.GetProviderConnectionPoints(part))
                 {
                     if (base.WebPartManager.CanConnectWebParts(part, point, consumer, consumerConnectionPoint))
                     {
                         dictionary.Add(part.ID + '$' + point.ID, new ProviderInfo(part, point));
                     }
                     else
                     {
                         foreach (WebPartTransformer transformer in this.AvailableTransformers)
                         {
                             if (base.WebPartManager.CanConnectWebParts(part, point, consumer, consumerConnectionPoint, transformer))
                             {
                                 dictionary.Add(part.ID + '$' + point.ID, new ProviderInfo(part, point, transformer.GetType()));
                                 break;
                             }
                         }
                     }
                 }
             }
         }
     }
     return dictionary;
 }
            internal void AddWebPartsFromZone(WebPartZoneBase zone, WebPartCollection webParts) {
                if ((webParts != null) && (webParts.Count != 0)) {
                    string originalError = SetCollectionReadOnly(null);

                    // Extra try-catch block to prevent elevation of privilege attack via exception filter
                    try {
                        try {
                            string zoneID = zone.ID;
                            int index = 0;

                            foreach (WebPart webPart in webParts) {
                                // Need to set IsShared before calling IsAuthorized
                                _manager.Internals.SetIsShared(webPart, true);

                                WebPart webPartOrProxy = webPart;
                                if (!_manager.IsAuthorized(webPart)) {
                                    webPartOrProxy = new UnauthorizedWebPart(webPart);
                                }

                                _manager.Internals.SetIsStatic(webPartOrProxy, true);
                                _manager.Internals.SetIsShared(webPartOrProxy, true);
                                _manager.Internals.SetZoneID(webPartOrProxy, zoneID);
                                _manager.Internals.SetZoneIndex(webPartOrProxy, index);

                                AddWebPartHelper(webPartOrProxy);
                                index++;
                            }
                        }
                        finally {
                            SetCollectionReadOnly(originalError);
                        }
                    } catch {
                        throw;
                    }
                }
            }