Esempio n. 1
1
 public override void RenderWebPart(HtmlTextWriter writer, WebPart webPart)
 {
     if (webPart == null)
     {
         throw new ArgumentNullException("webPart");
     }
     base.Zone.PartChromeStyle.AddAttributesToRender(writer, base.Zone);
     writer.AddAttribute(HtmlTextWriterAttribute.Cellspacing, "0");
     writer.AddAttribute(HtmlTextWriterAttribute.Cellpadding, "0");
     writer.AddAttribute(HtmlTextWriterAttribute.Border, "0");
     writer.AddStyleAttribute(HtmlTextWriterStyle.Width, "100%");
     if (webPart.Hidden && !base.WebPartManager.DisplayMode.ShowHiddenWebParts)
     {
         writer.AddStyleAttribute(HtmlTextWriterStyle.Display, "none");
     }
     writer.RenderBeginTag(HtmlTextWriterTag.Table);
     writer.RenderBeginTag(HtmlTextWriterTag.Tr);
     writer.RenderBeginTag(HtmlTextWriterTag.Td);
     if (base.WebPartManager.DisplayMode == WebPartManager.EditDisplayMode || webPart.ChromeType != PartChromeType.None)
     {
         this.RenderTitleBar(writer, webPart);
     }
     writer.RenderEndTag();
     writer.RenderEndTag();
     writer.RenderBeginTag(HtmlTextWriterTag.Tr);
     base.Zone.PartStyle.AddAttributesToRender(writer, base.Zone);
     writer.AddStyleAttribute(HtmlTextWriterStyle.Padding, base.Zone.PartChromePadding.ToString());
     writer.RenderBeginTag(HtmlTextWriterTag.Td);
     this.RenderPartContents(writer, webPart);
     writer.RenderEndTag();
     writer.RenderEndTag();
     writer.RenderEndTag();
 }
Esempio n. 2
0
        protected override void InternalProcessRecord()
        {
            bool test = false;
            ShouldProcessReason reason;

            if (!base.ShouldProcess(null, null, null, out reason))
            {
                if (reason == ShouldProcessReason.WhatIf)
                {
                    test = true;
                }
            }

            string sourceFileUrl = SourceFile.FileUrl;
            string targetFileUrl = TargetFile.FileUrl;

            string  zone          = null;
            WebPart sourceWebPart = GetSourceWebPart(sourceFileUrl, WebPartTitle, WebPartId, out zone);

            if (string.IsNullOrEmpty(Zone))
            {
                Zone = zone;
            }

            SetWebPart(sourceWebPart, targetFileUrl, Zone, ZoneIndex, Publish, test);

            base.InternalProcessRecord();
        }
Esempio n. 3
0
        internal void AddOtherWebPart(string pageUrl, string wpID)
        {
            Guid          wpGuid = ProductPage.GetGuid(wpID.Replace('_', '-').Substring(2));
            SystemWebPart wp     = null;

            wpMan2 = web.GetLimitedWebPartManager(pageUrl, PersonalizationScope.Shared);
            try {
                wp = wpMan2.WebParts [wpID];
            } catch (Exception ex) {
                if (Guid.Empty.Equals(wpGuid))
                {
                    Errors.Add(ex);
                }
                else
                {
                    try {
                        wp = wpMan2.WebParts [wpGuid];
                    } catch (Exception ex2) {
                        Errors.Add(ex2);
                    }
                }
            }
            if (wp != null)
            {
                if (string.IsNullOrEmpty(Title))
                {
                    Title = wp.Title;
                }
                InitWebPart(wp);
                MainWebPart.Controls.Add(wp);
                PhVals ["Context_Title"] = PhVals ["WebPart_Title"] = wp.DisplayTitle;
            }
        }
        public override void SyncChanges()
        {
            WebPart webPartToEdit = base.WebPartToEdit;

            if (webPartToEdit != null)
            {
                bool allowLayoutChange = webPartToEdit.Zone.AllowLayoutChange;
                this.EnsureChildControls();
                this._allowClose.Checked       = webPartToEdit.AllowClose;
                this._allowClose.Enabled       = allowLayoutChange;
                this._allowConnect.Checked     = webPartToEdit.AllowConnect;
                this._allowHide.Checked        = webPartToEdit.AllowHide;
                this._allowHide.Enabled        = allowLayoutChange;
                this._allowMinimize.Checked    = webPartToEdit.AllowMinimize;
                this._allowMinimize.Enabled    = allowLayoutChange;
                this._allowZoneChange.Checked  = webPartToEdit.AllowZoneChange;
                this._allowZoneChange.Enabled  = allowLayoutChange;
                this._exportMode.SelectedValue = TypeDescriptor.GetConverter(typeof(WebPartExportMode)).ConvertToString(webPartToEdit.ExportMode);
                this._helpMode.SelectedValue   = TypeDescriptor.GetConverter(typeof(WebPartHelpMode)).ConvertToString(webPartToEdit.HelpMode);
                this._description.Text         = webPartToEdit.Description;
                this._titleUrl.Text            = webPartToEdit.TitleUrl;
                this._titleIconImageUrl.Text   = webPartToEdit.TitleIconImageUrl;
                this._catalogIconImageUrl.Text = webPartToEdit.CatalogIconImageUrl;
                this._helpUrl.Text             = webPartToEdit.HelpUrl;
                this._importErrorMessage.Text  = webPartToEdit.ImportErrorMessage;
                this._authorizationFilter.Text = webPartToEdit.AuthorizationFilter;
                this._allowEdit.Checked        = webPartToEdit.AllowEdit;
            }
        }
Esempio n. 5
0
        public override void SyncChanges()
        {
            WebPart webPart = WebPartToEdit;

            Debug.Assert(webPart != null);
            if (webPart != null)
            {
                bool allowLayoutChange = webPart.Zone.AllowLayoutChange;

                EnsureChildControls();
                _title.Text = webPart.Title;

                TypeConverter chromeTypeConverter = TypeDescriptor.GetConverter(typeof(PartChromeType));
                _chromeType.SelectedValue = chromeTypeConverter.ConvertToString(webPart.ChromeType);
                _chromeType.Enabled       = allowLayoutChange;

                TypeConverter directionConverter = TypeDescriptor.GetConverter(typeof(ContentDirection));
                _direction.SelectedValue = directionConverter.ConvertToString(webPart.Direction);

                _height.Unit    = webPart.Height;
                _height.Enabled = allowLayoutChange;

                _width.Unit    = webPart.Width;
                _width.Enabled = allowLayoutChange;

                _hidden.Checked = webPart.Hidden;
                _hidden.Enabled = allowLayoutChange && webPart.AllowHide;
            }
        }
Esempio n. 6
0
        public WebPartTracker(WebPart webPart, ProviderConnectionPoint providerConnectionPoint)
        {
            if (webPart == null)
            {
                throw new ArgumentNullException("webPart");
            }

            if (providerConnectionPoint == null)
            {
                throw new ArgumentNullException("providerConnectionPoint");
            }

            if (providerConnectionPoint.ControlType != webPart.GetType())
            {
                throw new ArgumentException(SR.GetString(SR.WebPartManager_InvalidConnectionPoint), "providerConnectionPoint");
            }

            _webPart = webPart;
            _providerConnectionPoint = providerConnectionPoint;

            if (++Count > 1)
            {
                webPart.SetConnectErrorMessage(SR.GetString(SR.WebPartTracker_CircularConnection, _providerConnectionPoint.DisplayName));
            }
        }
 public override WebPart GetWebPart(WebPartDescription description)
 {
     if (description == null)
     {
         throw new ArgumentNullException("description");
     }
     if (!this.GetAvailableWebPartDescriptions().Contains(description))
     {
         throw new ArgumentException(System.Web.SR.GetString("CatalogPart_UnknownDescription"), "description");
     }
     if (this._availableWebPart == null)
     {
         using (XmlTextReader reader = new XmlTextReader(new StringReader(this._importedPartDescription)))
         {
             if ((reader != null) && (base.WebPartManager != null))
             {
                 this._availableWebPart = base.WebPartManager.ImportWebPart(reader, out this._importErrorMessage);
             }
         }
         if (this._availableWebPart == null)
         {
             this._importedPartDescription      = null;
             this._availableWebPartDescriptions = null;
         }
     }
     return(this._availableWebPart);
 }
        internal void OnUpload(object sender, EventArgs e)
        {
            string fileName    = this._upload.FileName;
            Stream fileContent = this._upload.FileContent;

            if (!string.IsNullOrEmpty(fileName) && (fileContent != null))
            {
                using (StreamReader reader = new StreamReader(fileContent, true))
                {
                    this._importedPartDescription      = reader.ReadToEnd();
                    this._availableWebPart             = null;
                    this._availableWebPartDescriptions = null;
                    this._importErrorMessage           = null;
                    if (string.IsNullOrEmpty(this._importedPartDescription))
                    {
                        this._importErrorMessage = System.Web.SR.GetString("ImportCatalogPart_NoFileName");
                    }
                    else
                    {
                        this.GetAvailableWebPartDescriptions();
                    }
                    return;
                }
            }
            this._importErrorMessage = System.Web.SR.GetString("ImportCatalogPart_NoFileName");
        }
 public WebPartConnectionsEventArgs(WebPart provider, System.Web.UI.WebControls.WebParts.ProviderConnectionPoint providerConnectionPoint, WebPart consumer, System.Web.UI.WebControls.WebParts.ConsumerConnectionPoint consumerConnectionPoint)
 {
     this._provider = provider;
     this._providerConnectionPoint = providerConnectionPoint;
     this._consumer = consumer;
     this._consumerConnectionPoint = consumerConnectionPoint;
 }
Esempio n. 10
0
        public static AspWebPart.WebPart MakeSize(this AspWebPart.WebPart webpart, int widthInPixels, int heightInPixels)
        {
            webpart.Width  = new System.Web.UI.WebControls.Unit(widthInPixels, System.Web.UI.WebControls.UnitType.Pixel);
            webpart.Height = new System.Web.UI.WebControls.Unit(heightInPixels, System.Web.UI.WebControls.UnitType.Pixel);

            return(webpart);
        }
        /// <devdoc>
        /// This method allows a non-WebPart control to mark its personalization as dirty.
        /// </devdoc>
        public static void SetPersonalizationDirty(Control control)
        {
            if (control == null)
            {
                throw new ArgumentNullException("control");
            }
            if (control.Page == null)
            {
                throw new ArgumentException(SR.GetString(SR.PropertyCannotBeNull, "Page"), "control");
            }

            WebPartManager wpm = WebPartManager.GetCurrentWebPartManager(control.Page);

            if (wpm == null)
            {
                throw new InvalidOperationException(SR.GetString(SR.WebPartManagerRequired));
            }

            WebPart webPart = wpm.GetGenericWebPart(control);

            if (webPart == null)
            {
                throw new ArgumentException(SR.GetString(SR.WebPart_NonWebPart), "control");
            }

            webPart.SetPersonalizationDirty();
        }
        public WebPartDescription(WebPart part)
        {
            string id = part.ID;

            if (String.IsNullOrEmpty(id))
            {
                throw new ArgumentException(SR.GetString(SR.WebPartManager_NoWebPartID), "part");
            }

            _id = id;

            string displayTitle = part.DisplayTitle;

            _title = (displayTitle != null) ? displayTitle : String.Empty;

            string description = part.Description;

            _description = (description != null) ? description : String.Empty;

            string imageUrl = part.CatalogIconImageUrl;

            _imageUrl = (imageUrl != null) ? imageUrl : String.Empty;

            _part = part;
        }
Esempio n. 13
0
        private void RenderVerbsInTitleBar(HtmlTextWriter writer, WebPart webPart, int colspan)
        {
            WebPartVerbCollection webPartVerbs = this.GetWebPartVerbs(webPart);

            webPartVerbs = this.FilterWebPartVerbs(webPartVerbs, webPart);
            if ((webPartVerbs != null) && (webPartVerbs.Count > 0))
            {
                writer.AddStyleAttribute(HtmlTextWriterStyle.WhiteSpace, "nowrap");
                colspan++;
                writer.RenderBeginTag(HtmlTextWriterTag.Td);
                if ((this.Zone.RenderClientScript && (this.Zone.WebPartVerbRenderMode == WebPartVerbRenderMode.Menu)) && (this.Zone.Menu != null))
                {
                    if (this._designMode)
                    {
                        this.Zone.Menu.Render(writer, webPart.WholePartID + "Verbs");
                    }
                    else
                    {
                        this.Zone.Menu.Render(writer, webPartVerbs, webPart.WholePartID + "Verbs", webPart, this.WebPartManager);
                    }
                }
                else
                {
                    this.RenderVerbs(writer, webPart, webPartVerbs);
                }
                writer.RenderEndTag();
            }
        }
        internal static bool IsPartSupported(IDictionary action, SystemWebPart wp, bool isPeop, SPList list, out bool origPage)
        {
            string flag;
            Type   wpType = null;

            try {
                wpType = wp.GetType();
            } catch {
            }
            if ((wpType != null) && ("Microsoft.SharePoint.WebPartPages.XsltListFormWebPart".Equals(wpType.FullName) || (wp is ListFormWebPart)))
            {
                origPage = "o".Equals(flag = action ["mlf"] + string.Empty);
                return(!"n".Equals(flag));
            }
            if (list != null)
            {
                origPage = "o".Equals(flag = action [(list.BaseTemplate == SPListTemplateType.Events) ? "mcv" : "mlv"] + string.Empty);
                return(!"n".Equals(flag));
            }
            if (isPeop)
            {
                origPage = "o".Equals(flag = action ["mpz"] + string.Empty);
                return(!"n".Equals(flag));
            }
            origPage = "o".Equals(flag = action ["mwp"] + string.Empty);
            return((!(wp is TitleBarWebPart)) && !"n".Equals(flag));
        }
Esempio n. 15
0
        public static string AddWebPart(SPWeb web, string pageUrl, WebPart webPart, string zoneId, int zoneIndex)
        {
            if (string.IsNullOrEmpty(webPart.Title))
            {
                throw new ArgumentException("The WebPart must be has title.");
            }

            var page = web.GetFile(pageUrl);

            using (var webPartManager = page.GetLimitedWebPartManager(PersonalizationScope.Shared))
            {
                try
                {
                    var oldWebParts = webPartManager.WebParts.Cast <WebPart>().Where(wp => wp.Title == webPart.Title).ToList();
                    foreach (var oldWebPart in oldWebParts)
                    {
                        webPartManager.DeleteWebPart(oldWebPart);
                    }

                    webPartManager.AddWebPart(webPart, zoneId, zoneIndex);

                    return(webPart.ID);
                }
                finally
                {
                    webPartManager.Web.Dispose();
                }
            }
        }
Esempio n. 16
0
 private void RenderTitleIcon(HtmlTextWriter writer, WebPart webPart)
 {
     writer.AddAttribute(HtmlTextWriterAttribute.Src, this.Zone.ResolveClientUrl(webPart.TitleIconImageUrl));
     writer.AddAttribute(HtmlTextWriterAttribute.Alt, this.GenerateDescriptionText(webPart));
     writer.RenderBeginTag(HtmlTextWriterTag.Img);
     writer.RenderEndTag();
 }
        public static string AddWebPartToPage(
            SPWeb web,
            string pageUrl,
            string webPartName,
            string zoneID,
            int zoneIndex)
        {
            using (WebPart webPart = CreateWebPart(web, webPartName)) {
                using (SPLimitedWebPartManager manager = web.GetLimitedWebPartManager(pageUrl, PersonalizationScope.Shared)) {
                    manager.AddWebPart(webPart, zoneID, zoneIndex);
                    //TODO: Will the list always be index = 0?
                    foreach (WebPart listWebPart in manager.WebParts)
                    {
                        if (listWebPart is ListViewWebPart)
                        {
                            //AddWebPartConnectionAspNet (web, pageUrl, webPart.ID, listWebPart.ID, "Send values as filters to", "Get Sort/Filter From");
                            AddWebPartConnectionWss(web, pageUrl, webPart.ID, listWebPart.ID);
                            break;
                        }
                    }

                    return(webPart.ID);
                }
            }
        }
Esempio n. 18
0
 public override void RenderWebPart(HtmlTextWriter writer, WebPart webPart)
 {
     if (webPart == null)
     {
         throw new ArgumentNullException("webPart");
     }
     base.Zone.PartChromeStyle.AddAttributesToRender(writer, base.Zone);
     writer.AddAttribute(HtmlTextWriterAttribute.Class, "divzone_part_chrome");
     writer.RenderBeginTag(HtmlTextWriterTag.Div);
     if (base.WebPartManager.DisplayMode == WebPartManager.EditDisplayMode || webPart.ChromeType != PartChromeType.None || !webPart.Hidden)
     {
         this.RenderTitleBar(writer, webPart);
     }
     base.Zone.PartStyle.AddAttributesToRender(writer, base.Zone);
     if (webPart.Hidden && !base.WebPartManager.DisplayMode.ShowHiddenWebParts)
     {
         writer.AddAttribute(HtmlTextWriterAttribute.Class, "divzone_part_hidden");
     }
     else
     {
         writer.AddAttribute(HtmlTextWriterAttribute.Class, "divzone_part");
     }
     writer.RenderBeginTag(HtmlTextWriterTag.Div);
     this.RenderPartContents(writer, webPart);
     writer.RenderEndTag();
     writer.RenderEndTag();
 }
        internal void OnUpload(object sender, EventArgs e)
        {
            string fileName = _upload.FileName;
            Stream contents = _upload.FileContent;

            if (!String.IsNullOrEmpty(fileName) && contents != null)
            {
                using (StreamReader sr = new StreamReader(contents, true)) {
                    _importedPartDescription = sr.ReadToEnd();

                    // Clear cache
                    _availableWebPart             = null;
                    _availableWebPartDescriptions = null;
                    _importErrorMessage           = null;

                    if (String.IsNullOrEmpty(_importedPartDescription))
                    {
                        _importErrorMessage = SR.GetString(SR.ImportCatalogPart_NoFileName);
                    }
                    else
                    {
                        GetAvailableWebPartDescriptions();
                    }
                }
            }
            else
            {
                _importErrorMessage = SR.GetString(SR.ImportCatalogPart_NoFileName);
            }
        }
        public override WebPart GetWebPart(WebPartDescription description)
        {
            if (description == null)
            {
                throw new ArgumentNullException("description");
            }

            WebPartDescriptionCollection webPartDescriptions = GetAvailableWebPartDescriptions();

            if (!webPartDescriptions.Contains(description))
            {
                throw new ArgumentException(SR.GetString(SR.CatalogPart_UnknownDescription), "description");
            }

            if (_availableWebPart != null)
            {
                return(_availableWebPart);
            }
            // Import the WebPart from its saved XML description.
            using (XmlReader reader = XmlUtils.CreateXmlReader(new StringReader(_importedPartDescription))) {
                if (reader != null && WebPartManager != null)
                {
                    _availableWebPart = WebPartManager.ImportWebPart(reader, out _importErrorMessage);
                }
            }

            // If import failed, clear the cached description
            if (_availableWebPart == null)
            {
                _importedPartDescription      = null;
                _availableWebPartDescriptions = null;
            }
            return(_availableWebPart);
        }
Esempio n. 21
0
        private void btn_DeleteWPinPage_Click(object sender, EventArgs e)
        {
            using (SPSite site = new SPSite(siteUrl))
            {
                using (SPWeb web = site.OpenWeb(webUrl))
                {
                    SPFile thePage = web.GetFile(pageUrl);
                    SPLimitedWebPartManager    theWebPartManager = thePage.GetLimitedWebPartManager(System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared);
                    SPLimitedWebPartCollection webParts          = theWebPartManager.WebParts;
                    int Num = webParts.Count;
                    //foreach( System.Web.UI.WebControls.WebParts.WebPart wp inwebParts
                    for (int i = Num - 1; i >= 0; i--)
                    {
                        System.Web.UI.WebControls.WebParts.WebPart wp = webParts[i];
                        for (int j = 0; j < clBox_WebParts.Items.Count; j++)
                        {
                            if ((clBox_WebParts.GetItemChecked(j)) && (clBox_WebParts.Items[j].ToString() == wp.DisplayTitle))
                            {
                                theWebPartManager.DeleteWebPart(wp);
                                tb_Message.Text += clBox_WebParts.Items[j].ToString() + "Delete in Page Success...";
                            }
                        }
                    }

                    clBox_WebParts.Items.Clear();
                    for (int i = 0; i < webParts.Count; i++)
                    {
                        clBox_WebParts.Items.Add(webParts[i].DisplayTitle);
                    }
                }
            }
        }
 protected virtual new void RenderPartContents (System.Web.UI.HtmlTextWriter writer, WebPart webPart)
 {
   Contract.Requires (webPart != null);
   Contract.Requires (this.Zone != null);
   Contract.Requires (this.Zone.ErrorStyle != null);
   Contract.Requires (writer != null);
 }
Esempio n. 23
0
 public WebPartConnectionsEventArgs(WebPart provider, System.Web.UI.WebControls.WebParts.ProviderConnectionPoint providerConnectionPoint, WebPart consumer, System.Web.UI.WebControls.WebParts.ConsumerConnectionPoint consumerConnectionPoint)
 {
     this._provider = provider;
     this._providerConnectionPoint = providerConnectionPoint;
     this._consumer = consumer;
     this._consumerConnectionPoint = consumerConnectionPoint;
 }
 public WebPartConnectionsEventArgs(WebPart provider, ProviderConnectionPoint providerConnectionPoint,
                                    WebPart consumer, ConsumerConnectionPoint consumerConnectionPoint,
                                    WebPartConnection connection) : this(provider, providerConnectionPoint,
                                                                         consumer, consumerConnectionPoint)
 {
     _connection = connection;
 }
        private static WebPart CreateWebPart(SPWeb web, string webPartName)
        {
            SPQuery query = new SPQuery {
                Query = String.Format(
                    "<Where><Eq><FieldRef Name='FileLeafRef'/><Value Type='File'>{0}</Value></Eq></Where>",
                    webPartName)
            };

            SPList webPartGallery;

            if (null == web.ParentWeb)
            {
                // This is the root web.
                webPartGallery = web.GetCatalog(SPListTemplateType.WebPartCatalog);
            }
            else
            {
                // This is a sub-web.
                webPartGallery = web.ParentWeb.GetCatalog(SPListTemplateType.WebPartCatalog);
            }

            SPListItemCollection webParts = webPartGallery.GetItems(query);

            string       typeName      = webParts [0].GetFormattedValue("WebPartTypeName");
            string       assemblyName  = webParts [0].GetFormattedValue("WebPartAssembly");
            ObjectHandle webPartHandle = Activator.CreateInstance(assemblyName, typeName);

            if (webPartHandle != null)
            {
                WebPart webPart = (WebPart)webPartHandle.Unwrap();
                return(webPart);
            }

            return(null);
        }
Esempio n. 26
0
        private void ApplyAndSyncChanges()
        {
            WebPart webPartToEdit = WebPartToEdit;

            Debug.Assert(webPartToEdit != null);
            if (webPartToEdit != null)
            {
                EditorPartCollection editorParts = EditorParts;
                foreach (EditorPart editorPart in editorParts)
                {
                    if (editorPart.Display && editorPart.Visible && editorPart.ChromeState == PartChromeState.Normal)
                    {
                        if (!editorPart.ApplyChanges())
                        {
                            _applyError = true;
                        }
                    }
                }
                if (!_applyError)
                {
                    foreach (EditorPart editorPart in editorParts)
                    {
                        editorPart.SyncChanges();
                    }
                }
            }
        }
Esempio n. 27
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);
            }
        }
Esempio n. 28
0
        /// <summary>
        /// Save the auto located location in the webpart settings
        /// </summary>
        private void SaveAutoLoc()
        {
            String[] Location = new String[4];

            Location = GetLocation();

            using (SPSite objSite = new SPSite(SPContext.Current.Site.Url))
            {
                using (SPWeb objWeb = objSite.OpenWeb())
                {
                    SPFile objPage = objWeb.GetFile(HttpContext.Current.Request.Url.ToString());
                    SPLimitedWebPartManager mgr = objPage.GetLimitedWebPartManager(PersonalizationScope.Shared);
                    System.Web.UI.WebControls.WebParts.WebPart objWebPart = mgr.WebParts[this.ID];

                    if (objWebPart != null)
                    {
                        if (Location[1] == null && Location[2] == null)
                        {
                            ((Sumit.Webpart.Weather.Weather.Weather)(objWebPart.WebBrowsableObject)).CityName = null;
                        }
                        else
                        {
                            ((Sumit.Webpart.Weather.Weather.Weather)(objWebPart.WebBrowsableObject)).CityName = Location[1] + " , " + Location[2];
                        }

                        mgr.SaveChanges(objWebPart);
                    }
                }
            }
        }
Esempio n. 29
0
        private void AddSelectedWebParts()
        {
            WebPartZoneBase zone = null;

            if (base.WebPartManager != null)
            {
                zone = base.WebPartManager.Zones[this._selectedZoneID];
            }
            CatalogPart selectedCatalogPart = this.SelectedCatalogPart;
            WebPartDescriptionCollection availableWebPartDescriptions = null;

            if (selectedCatalogPart != null)
            {
                availableWebPartDescriptions = selectedCatalogPart.GetAvailableWebPartDescriptions();
            }
            if (((zone != null) && zone.AllowLayoutChange) && ((this._selectedCheckBoxValues != null) && (availableWebPartDescriptions != null)))
            {
                ArrayList webParts = new ArrayList();
                for (int i = 0; i < this._selectedCheckBoxValues.Length; i++)
                {
                    string             str         = this._selectedCheckBoxValues[i];
                    WebPartDescription description = availableWebPartDescriptions[str];
                    if (description != null)
                    {
                        WebPart webPart = selectedCatalogPart.GetWebPart(description);
                        if (webPart != null)
                        {
                            webParts.Add(webPart);
                        }
                    }
                }
                this.AddWebParts(webParts, zone);
            }
        }
Esempio n. 30
0
        private void RenderTitleText(HtmlTextWriter writer, WebPart webPart)
        {
            if (this._titleTextStyle == null)
            {
                this._titleTextStyle = this.CreateTitleTextStyle(this.Zone.PartTitleStyle);
            }
            if (!this._titleTextStyle.IsEmpty)
            {
                this._titleTextStyle.AddAttributesToRender(writer, this.Zone);
            }
            writer.AddAttribute(HtmlTextWriterAttribute.Title, this.GenerateDescriptionText(webPart), true);
            string titleUrl = webPart.TitleUrl;
            string text     = this.GenerateTitleText(webPart);

            if (!string.IsNullOrEmpty(titleUrl) && !this.DragDropEnabled)
            {
                writer.AddAttribute(HtmlTextWriterAttribute.Href, this.Zone.ResolveClientUrl(titleUrl));
                writer.RenderBeginTag(HtmlTextWriterTag.A);
            }
            else
            {
                writer.RenderBeginTag(HtmlTextWriterTag.Span);
            }
            writer.WriteEncodedText(text);
            writer.RenderEndTag();
            writer.Write("&nbsp;");
        }
Esempio n. 31
0
        public static WebPart CreateWebPart(this SPWeb web, string webPartName, SPLimitedWebPartManager webPartManager, out string errorMsg)
        {
            var query = new SPQuery
            {
                Query = String.Format(CultureInfo.CurrentCulture,
                                      "<Where><Eq><FieldRef Name='FileLeafRef'/><Value Type='File'>{0}</Value></Eq></Where>",
                                      webPartName),
                RowLimit = 1
            };

            SPList webPartGallery = web.IsRootWeb
                                        ? web.GetCatalog(SPListTemplateType.WebPartCatalog)
                                        : web.Site.RootWeb.GetCatalog(SPListTemplateType.WebPartCatalog);

            SPListItemCollection webParts = webPartGallery.GetItems(query);

            if (webParts.Count == 0)
            {
                throw new SPException(string.Format("Web Part \"{0}\" not found in the gallery.", webPartName));
            }

            using (Stream stream = webParts[0].File.OpenBinaryStream())
            {
                XmlReader xmlReader = new XmlTextReader(stream);
                WebPart   webPart   = webPartManager.ImportWebPart(xmlReader, out errorMsg);
                xmlReader.Close();
                return(webPart);
            }
        }
Esempio n. 32
0
        public override void AddItemToPage(System.Web.UI.WebControls.WebParts.WebPartZoneBase zone, int zoneIndex, WebPartGalleryItem item, string wpid)
        {
            if (zone == null)
            {
                throw new ArgumentNullException("zone");
            }
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }
            System.Web.UI.WebControls.WebParts.WebPart webPart = ((WebPartGalleryItemBase)item).Instantiate();

            /*
             * if (!item.IsSafeAgainstScript)
             * {
             *  SPWebPartManager currentWebPartManager = WebPartManager.GetCurrentWebPartManager(this.Page) as SPWebPartManager;
             *  if (!CanUserScript(SPContext.Current.Web))
             *  {
             *      currentWebPartManager.SafeForScriptingManager.ProcessAllowContributorScriptPropertiesRollback(webPart);
             *  }
             * }
             */
            if (!string.IsNullOrEmpty(wpid))
            {
                webPart.ID = wpid;
                webPart.TitleIconImageUrl = webPart.CatalogIconImageUrl;
                webPart.ChromeType        = PartChromeType.None;
            }

            this.AddItemToPage(zone, zoneIndex, webPart);
        }
Esempio n. 33
0
 protected virtual void RenderTitleBar(HtmlTextWriter writer, WebPart webPart)
 {
     writer.AddAttribute(HtmlTextWriterAttribute.Cellspacing, "0");
     writer.AddAttribute(HtmlTextWriterAttribute.Cellpadding, "0");
     writer.AddAttribute(HtmlTextWriterAttribute.Border, "0");
     writer.AddStyleAttribute(HtmlTextWriterStyle.Width, "100%");
     writer.RenderBeginTag(HtmlTextWriterTag.Table);
     writer.RenderBeginTag(HtmlTextWriterTag.Tr);
     base.Zone.PartTitleStyle.AddAttributesToRender(writer, base.Zone);
     writer.RenderBeginTag(HtmlTextWriterTag.Td);
     writer.AddAttribute(HtmlTextWriterAttribute.Title, webPart.Description, true);
     writer.RenderBeginTag(HtmlTextWriterTag.Span);
     writer.WriteEncodedText(webPart.Title);
     writer.RenderEndTag();
     writer.RenderEndTag();
     base.Zone.PartTitleStyle.AddAttributesToRender(writer, base.Zone);
     writer.AddStyleAttribute(HtmlTextWriterStyle.TextAlign, TextAlign.Right.ToString());
     writer.RenderBeginTag(HtmlTextWriterTag.Td);
     if (base.WebPartManager.DisplayMode == WebPartManager.EditDisplayMode)
     {
         this.RenderVerbs(writer, webPart);
     }
     writer.RenderEndTag();
     writer.RenderEndTag();
     writer.RenderEndTag();
 }
        /// <summary>
        /// Gets the web part details.
        /// </summary>
        /// <param name="wp">The web part.</param>
        /// <param name="manager">The web part manager.</param>
        /// <returns></returns>
        internal static string GetWebPartDetails(WebPart wp, SPLimitedWebPartManager manager)
        {
            if (wp.ExportMode == WebPartExportMode.None)
            {
                Logger.WriteWarning("Unable to export {0}", wp.Title);
                return "";
            }
            StringBuilder sb = new StringBuilder();

            XmlTextWriter xmlWriter = new XmlTextWriter(new StringWriter(sb));
            xmlWriter.Formatting = Formatting.Indented;
            manager.ExportWebPart(wp, xmlWriter);
            xmlWriter.Flush();

            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(sb.ToString());

            XmlElement elem = xmlDoc.DocumentElement;
            if (xmlDoc.DocumentElement.Name == "webParts")
            {
                elem = (XmlElement)xmlDoc.DocumentElement.ChildNodes[0];

                // We've found a v3 web part but the export method does not export what the zone ID is so we
                // have to manually add that in.  Unfortunately the Zone property is always null because we are
                // using a SPLimitedWebPartManager so we have to use the helper method GetZoneID to set the zone ID.
                XmlElement property = xmlDoc.CreateElement("property");
                property.SetAttribute("name", "ZoneID");
                property.SetAttribute("type", "string");
                property.InnerText = manager.GetZoneID(wp);
                elem.ChildNodes[1].ChildNodes[0].AppendChild(property);
            }

            return elem.OuterXml.Replace(" xmlns=\"\"", ""); // Just some minor cleanup to deal with erroneous namespace tags added due to the zoneID being added manually.
        }
        public override void ExtractWebPartPersonalization(WebPart webPart)
        {
            base.ValidateWebPart(webPart);
            ProxyWebPart part = webPart as ProxyWebPart;

            if (part != null)
            {
                this.RoundTripWebPartPersonalization(part.OriginalID, part.GenericWebPartID);
            }
            else
            {
                System.Web.UI.WebControls.WebParts.PersonalizationScope personalizationScope = this.PersonalizationScope;
                if ((personalizationScope == System.Web.UI.WebControls.WebParts.PersonalizationScope.User) && !webPart.IsShared)
                {
                    personalizationScope = System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared;
                }
                bool   isStatic          = webPart.IsStatic;
                string personalizationID = this.CreatePersonalizationID(webPart, null);
                this.ExtractPersonalization(webPart, personalizationID, false, personalizationScope, isStatic, null);
                GenericWebPart associatedGenericWebPart = webPart as GenericWebPart;
                if (associatedGenericWebPart != null)
                {
                    Control childControl = associatedGenericWebPart.ChildControl;
                    personalizationID = this.CreatePersonalizationID(childControl, associatedGenericWebPart);
                    this.ExtractPersonalization(childControl, personalizationID, false, personalizationScope, isStatic, associatedGenericWebPart);
                }
            }
        }
Esempio n. 36
0
        private void RenderVerbsInTitleBar(HtmlTextWriter writer, WebPart webPart, int colspan)
        {
            WebPartVerbCollection verbs = GetWebPartVerbs(webPart);

            verbs = FilterWebPartVerbs(verbs, webPart);

            if (verbs != null && verbs.Count > 0)
            {
                writer.AddStyleAttribute(HtmlTextWriterStyle.WhiteSpace, "nowrap");
                colspan++;

                writer.RenderBeginTag(HtmlTextWriterTag.Td);
                if (Zone.RenderClientScript && (Zone.WebPartVerbRenderMode == WebPartVerbRenderMode.Menu) && Zone.Menu != null)
                {
                    if (_designMode)
                    {
                        Zone.Menu.Render(writer, webPart.WholePartID + "Verbs");
                    }
                    else
                    {
                        // If Zone.RenderClientScript, then WebPartManager must not be null
                        Debug.Assert(WebPartManager != null);
                        Zone.Menu.Render(writer, verbs, webPart.WholePartID + "Verbs", webPart, WebPartManager);
                    }
                }
                else
                {
                    RenderVerbs(writer, webPart, verbs);
                }

                writer.RenderEndTag();  // Td
            }
        }
 public WebPartConnectionsEventArgs(WebPart provider, ProviderConnectionPoint providerConnectionPoint,
                                    WebPart consumer, ConsumerConnectionPoint consumerConnectionPoint) {
     // Arguments may be null, when deleting a connection because a part is no longer on the page
     _provider = provider;
     _providerConnectionPoint = providerConnectionPoint;
     _consumer = consumer;
     _consumerConnectionPoint = consumerConnectionPoint;
 }
 internal bool ContainsProvider(WebPart provider) {
     foreach (WebPartConnection connection in List) {
         if (connection.Provider == provider) {
             return true;
         }
     }
     return false;
 }
    public virtual new WebPartConnection ConnectWebParts (WebPart provider, ProviderConnectionPoint providerConnectionPoint, WebPart consumer, ConsumerConnectionPoint consumerConnectionPoint, WebPartTransformer transformer)
    {
      Contract.Requires (provider != null);
      Contract.Requires (consumer != null);
      Contract.Requires (providerConnectionPoint != null);
      Contract.Requires (consumerConnectionPoint != null);

      return default(WebPartConnection);
    }
Esempio n. 40
0
        public override void RenderWebPart(HtmlTextWriter writer, WebPart webPart)
        {
            var chromeType = this.Zone.GetEffectiveChromeType(webPart);
            AddPortletSkinCss(writer, webPart, chromeType.ToString().ToLower());
            writer.AddAttribute(HtmlTextWriterAttribute.Id, this.GetWebPartChromeClientID(webPart));
            writer.RenderBeginTag(HtmlTextWriterTag.Div);

            var currentDisplayMode = this.WebPartManager.DisplayMode;

            if (currentDisplayMode == WebPartManager.EditDisplayMode || currentDisplayMode == WebPartManager.DesignDisplayMode)
            {
                RenderVerbs(writer, webPart);
            }

            if (chromeType == PartChromeType.TitleAndBorder || chromeType == PartChromeType.BorderOnly)
            {
                writer.AddAttribute(HtmlTextWriterAttribute.Class, "sn-pt-border ui-widget-content ui-corner-all");
                writer.RenderBeginTag(HtmlTextWriterTag.Div);
            }

            if ((chromeType == PartChromeType.TitleOnly) || (chromeType == PartChromeType.TitleAndBorder))
                RenderTitleBar(writer, webPart);

            if (chromeType == PartChromeType.TitleAndBorder || chromeType == PartChromeType.BorderOnly)
            {
                RenderPortletBodyBeginTag(writer);
            }
            else
            {
                writer.AddAttribute(HtmlTextWriterAttribute.Class, "sn-pt-body-borderless");
                writer.RenderBeginTag(HtmlTextWriterTag.Div);
            }

            RenderPartContents(writer, webPart);

            if (chromeType == PartChromeType.TitleAndBorder || chromeType == PartChromeType.BorderOnly)
            {
                RenderPortletBodyEndTag(writer);
            }
            else
            {
                writer.RenderEndTag(); // sn-pt-body-borderless
            }

            if (chromeType == PartChromeType.TitleAndBorder)
                RenderChromeFooter(writer);

            if (chromeType == PartChromeType.TitleAndBorder || chromeType == PartChromeType.BorderOnly)
                writer.RenderEndTag(); // sn-pt-border

            if (this.WebPartManager.DisplayMode == WebPartManager.DesignDisplayMode)
                RenderMaskTag(writer);

            writer.RenderEndTag();
        }
 protected void ValidateWebPart(WebPart webPart)
 {
     if (webPart == null)
     {
         throw new ArgumentNullException("webPart");
     }
     if (!this._webPartManager.WebParts.Contains(webPart))
     {
         throw new ArgumentException(System.Web.SR.GetString("UnknownWebPart"), "webPart");
     }
 }
        /// <summary>
        /// Gets the web part details.
        /// </summary>
        /// <param name="wp">The web part.</param>
        /// <param name="manager">The web part manager.</param>
        internal static string GetWebPartDetailsMinimal(WebPart wp, SPLimitedWebPartManager manager)
        {
            XmlDocument xmlDoc = new XmlDocument();

            XmlElement wpXml = xmlDoc.CreateElement("WebPart");
            xmlDoc.AppendChild(wpXml);

            wpXml.SetAttribute("id", wp.ID);

            XmlElement prop = xmlDoc.CreateElement("Title");
            prop.InnerText = wp.Title;
            wpXml.AppendChild(prop);

            prop = xmlDoc.CreateElement("Description");
            prop.InnerText = wp.Description;
            wpXml.AppendChild(prop);

            prop = xmlDoc.CreateElement("DisplayTitle");
            prop.InnerText = wp.DisplayTitle;
            wpXml.AppendChild(prop);

            prop = xmlDoc.CreateElement("Hidden");
            prop.InnerText = wp.Hidden.ToString();
            wpXml.AppendChild(prop);

            prop = xmlDoc.CreateElement("IsClosed");
            prop.InnerText = wp.IsClosed.ToString();
            wpXml.AppendChild(prop);

            prop = xmlDoc.CreateElement("IsShared");
            prop.InnerText = wp.IsShared.ToString();
            wpXml.AppendChild(prop);

            prop = xmlDoc.CreateElement("IsStandalone");
            prop.InnerText = wp.IsStandalone.ToString();
            wpXml.AppendChild(prop);

            prop = xmlDoc.CreateElement("IsStatic");
            prop.InnerText = wp.IsStatic.ToString();
            wpXml.AppendChild(prop);

            prop = xmlDoc.CreateElement("Zone");
            if (wp.Zone != null)
                prop.InnerText = wp.Zone.ToString();
            else
                prop.InnerText = manager.GetZoneID(wp);
            wpXml.AppendChild(prop);

            prop = xmlDoc.CreateElement("ZoneIndex");
            prop.InnerText = wp.ZoneIndex.ToString();
            wpXml.AppendChild(prop);

            return Utilities.GetFormattedXml(xmlDoc);
        }
 protected internal virtual void ApplyPersonalizationState(WebPart webPart)
 {
     if (webPart == null)
     {
         throw new ArgumentNullException("webPart");
     }
     if (this.IsEnabled)
     {
         this.EnsurePersonalizationState();
         this._personalizationState.ApplyWebPartPersonalization(webPart);
     }
 }
 private void ClearPendingConnection()
 {
     this._pendingConnectionType = ConnectionType.None;
     this._pendingConnectionPointID = string.Empty;
     this._pendingSelectedValue = null;
     this._pendingConsumerID = string.Empty;
     this._pendingConsumer = null;
     this._pendingConsumerConnectionPoint = null;
     this._pendingProvider = null;
     this._pendingProviderConnectionPoint = null;
     this._pendingTransformerConfigurationControlTypeName = null;
     this._pendingConnectionID = null;
 }
Esempio n. 45
0
        protected virtual void ProcessWebpartProperties(WebPart instance, WebPartDefinition definition)
        {
            if (definition.Width.HasValue)
                instance.Width = new Unit(definition.Width.Value);

            if (definition.Height.HasValue)
                instance.Height = new Unit(definition.Height.Value);

            if (!string.IsNullOrEmpty(definition.ChromeState))
                instance.ChromeState = (PartChromeState)Enum.Parse(typeof(PartChromeState), definition.ChromeState);

            if (!string.IsNullOrEmpty(definition.ChromeType))
            {
                var chromeType = WebPartChromeTypesConvertService.NormilizeValueToPartChromeTypes(definition.ChromeType);
                instance.ChromeType = (PartChromeType)Enum.Parse(typeof(PartChromeType), chromeType);
            }

            if (!string.IsNullOrEmpty(definition.ImportErrorMessage))
                instance.ImportErrorMessage = definition.ImportErrorMessage;

            if (!string.IsNullOrEmpty(definition.Description))
                instance.Description = definition.Description;

            if (!string.IsNullOrEmpty(definition.TitleIconImageUrl))
                instance.TitleIconImageUrl = definition.TitleIconImageUrl;

            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 = CurrentHost.HostFile.Web
                }).Value;

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

                instance.TitleUrl = urlValue;
            }

            if (!string.IsNullOrEmpty(definition.ExportMode))
                instance.ExportMode = (WebPartExportMode)Enum.Parse(typeof(WebPartExportMode), definition.ExportMode);

            ProcessWebpartCustomProperties(instance, definition);
            ProcessParameterBindings(instance, definition);
        }
        protected override void ProcessWebpartProperties(WebPart webpartInstance, WebPartDefinition definition)
        {
            base.ProcessWebpartProperties(webpartInstance, definition);

            var typedWebpart = webpartInstance.WithAssertAndCast<RefinementScriptWebPart>("webpartInstance", value => value.RequireNotNull());
            var typedModel = definition.WithAssertAndCast<RefinementScriptWebPartDefinition>("webpartModel", value => value.RequireNotNull());


            if (!string.IsNullOrEmpty(typedModel.SelectedRefinementControlsJson))
                typedWebpart.SelectedRefinementControlsJson = typedModel.SelectedRefinementControlsJson;

            if (!string.IsNullOrEmpty(typedModel.EmptyMessage))
                typedWebpart.EmptyMessage = typedModel.EmptyMessage;
        }
 protected ProxyWebPart(WebPart webPart)
 {
     if (webPart == null)
     {
         throw new ArgumentNullException("webPart");
     }
     GenericWebPart part = webPart as GenericWebPart;
     if (part != null)
     {
         Type type;
         Control childControl = part.ChildControl;
         if (childControl == null)
         {
             throw new ArgumentException(System.Web.SR.GetString("PropertyCannotBeNull", new object[] { "ChildControl" }), "webPart");
         }
         this._originalID = childControl.ID;
         if (string.IsNullOrEmpty(this._originalID))
         {
             throw new ArgumentException(System.Web.SR.GetString("PropertyCannotBeNullOrEmptyString", new object[] { "ChildControl.ID" }), "webPart");
         }
         UserControl control2 = childControl as UserControl;
         if (control2 != null)
         {
             type = typeof(UserControl);
             this._originalPath = control2.AppRelativeVirtualPath;
         }
         else
         {
             type = childControl.GetType();
         }
         this._originalTypeName = WebPartUtil.SerializeType(type);
         this._genericWebPartID = part.ID;
         if (string.IsNullOrEmpty(this._genericWebPartID))
         {
             throw new ArgumentException(System.Web.SR.GetString("PropertyCannotBeNullOrEmptyString", new object[] { "ID" }), "webPart");
         }
         this.ID = this._genericWebPartID;
     }
     else
     {
         this._originalID = webPart.ID;
         if (string.IsNullOrEmpty(this._originalID))
         {
             throw new ArgumentException(System.Web.SR.GetString("PropertyCannotBeNullOrEmptyString", new object[] { "ID" }), "webPart");
         }
         this._originalTypeName = WebPartUtil.SerializeType(webPart.GetType());
         this.ID = this._originalID;
     }
 }
Esempio n. 48
0
        public void AddDynamicWebPart(
            WebPart webPart,
            Microsoft.Web.Preview.UI.Controls.WebParts.WebPartZone webPartZone,
            int zoneIndex, bool isShared)
        {
            if (!this.WebParts.Contains(webPart))
            {
                Internals.SetZoneID(webPart, webPartZone.ID);
                Internals.SetIsShared(webPart, isShared);
                Internals.SetZoneIndex(webPart, zoneIndex);
                Internals.AddWebPart(webPart);
                this.SetPersonalizationDirty();

            }
        }
Esempio n. 49
0
        protected virtual void ProcessWebpartProperties(WebPart instance, WebPartDefinition definition)
        {
            if (definition.Width.HasValue)
                instance.Width = new Unit(definition.Width.Value);

            if (definition.Height.HasValue)
                instance.Height = new Unit(definition.Height.Value);

            if (!string.IsNullOrEmpty(definition.ChromeState))
                instance.ChromeState = (PartChromeState)Enum.Parse(typeof(PartChromeState), definition.ChromeState);

            if (!string.IsNullOrEmpty(definition.ChromeType))
            {
                var chromeType = WebPartChromeTypesConvertService.NormilizeValueToPartChromeTypes(definition.ChromeType);
                instance.ChromeType = (PartChromeType)Enum.Parse(typeof(PartChromeType), chromeType);
            }

            if (!string.IsNullOrEmpty(definition.ImportErrorMessage))
                instance.ImportErrorMessage = definition.ImportErrorMessage;

            if (!string.IsNullOrEmpty(definition.Description))
                instance.Description = definition.Description;

            if (!string.IsNullOrEmpty(definition.TitleIconImageUrl))
                instance.TitleIconImageUrl = definition.TitleIconImageUrl;

            if (!string.IsNullOrEmpty(definition.TitleUrl))
                instance.TitleUrl = definition.TitleUrl;

            if (!string.IsNullOrEmpty(definition.ExportMode))
                instance.ExportMode = (WebPartExportMode)Enum.Parse(typeof(WebPartExportMode), definition.ExportMode);


            var dataFomWebPart = instance as DataFormWebPart;

            if (dataFomWebPart != null
                && 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);
                dataFomWebPart.ParameterBindings = parameterBindingValue;
            }
        }
        public WebPartDescription(WebPart part) {
            string id = part.ID;
            if (String.IsNullOrEmpty(id)) {
                throw new ArgumentException(SR.GetString(SR.WebPartManager_NoWebPartID), "part");
            }

            _id = id;

            string displayTitle = part.DisplayTitle;
            _title = (displayTitle != null) ? displayTitle : String.Empty;

            string description = part.Description;
            _description = (description != null) ? description : String.Empty;

            string imageUrl = part.CatalogIconImageUrl;
            _imageUrl = (imageUrl != null) ? imageUrl : String.Empty;

            _part = part;
        }
        protected override void ProcessWebpartProperties(WebPart webpartInstance, WebPartDefinition webpartModel)
        {
            base.ProcessWebpartProperties(webpartInstance, webpartModel);

            var typedWebpart = webpartInstance.WithAssertAndCast<ResultScriptWebPart>("webpartInstance", value => value.RequireNotNull());
            var definition = webpartModel.WithAssertAndCast<ResultScriptWebPartDefinition>("webpartModel", value => value.RequireNotNull());

            if (!string.IsNullOrEmpty(definition.DataProviderJSON))
                typedWebpart.DataProviderJSON = definition.DataProviderJSON;

            if (!string.IsNullOrEmpty(definition.EmptyMessage))
                typedWebpart.EmptyMessage = definition.EmptyMessage;

            if (definition.ResultsPerPage.HasValue)
                typedWebpart.ResultsPerPage = definition.ResultsPerPage.Value;

            if (definition.ShowResultCount.HasValue)
                typedWebpart.ShowResultCount = definition.ShowResultCount.Value;
        }
Esempio n. 52
0
        protected ProxyWebPart(WebPart webPart) {
            if (webPart == null) {
                throw new ArgumentNullException("webPart");
            }

            GenericWebPart genericWebPart = webPart as GenericWebPart;
            if (genericWebPart != null) {
                Control childControl = genericWebPart.ChildControl;
                if (childControl == null) {
                    throw new ArgumentException(SR.GetString(SR.PropertyCannotBeNull, "ChildControl"), "webPart");
                }

                _originalID = childControl.ID;
                if (String.IsNullOrEmpty(_originalID)) {
                    throw new ArgumentException(SR.GetString(SR.PropertyCannotBeNullOrEmptyString, "ChildControl.ID"), "webPart");
                }

                Type originalType;
                UserControl childUserControl = childControl as UserControl;
                if (childUserControl != null) {
                    originalType = typeof(UserControl);
                    _originalPath = childUserControl.AppRelativeVirtualPath;
                }
                else {
                    originalType = childControl.GetType();
                }
                _originalTypeName = WebPartUtil.SerializeType(originalType);
                _genericWebPartID = genericWebPart.ID;
                if (String.IsNullOrEmpty(_genericWebPartID)) {
                    throw new ArgumentException(SR.GetString(SR.PropertyCannotBeNullOrEmptyString, "ID"), "webPart");
                }
                ID = _genericWebPartID;
            }
            else {
                _originalID = webPart.ID;
                if (String.IsNullOrEmpty(_originalID)) {
                    throw new ArgumentException(SR.GetString(SR.PropertyCannotBeNullOrEmptyString, "ID"), "webPart");
                }
                _originalTypeName = WebPartUtil.SerializeType(webPart.GetType());
                ID = _originalID;
            }
        }
Esempio n. 53
0
 protected override void RenderTitleBar(HtmlTextWriter writer, WebPart webPart)
 {
     writer.AddAttribute(HtmlTextWriterAttribute.Class, "divzone_part_title");
     writer.RenderBeginTag(HtmlTextWriterTag.Div);
     base.Zone.PartTitleStyle.AddAttributesToRender(writer, base.Zone);
     writer.AddAttribute(HtmlTextWriterAttribute.Class, "divzone_part_title_text");
     writer.RenderBeginTag(HtmlTextWriterTag.Div);
     writer.AddAttribute(HtmlTextWriterAttribute.Title, webPart.Description, true);
     writer.WriteEncodedText(webPart.Title);
     writer.RenderEndTag();
     base.Zone.PartTitleStyle.AddAttributesToRender(writer, base.Zone);
     writer.AddAttribute(HtmlTextWriterAttribute.Class, "divzone_part_title_verbs");
     writer.RenderBeginTag(HtmlTextWriterTag.Div);
     if (base.WebPartManager.DisplayMode == WebPartManager.EditDisplayMode)
     {
         this.RenderVerbs(writer, webPart);
     }
     writer.RenderEndTag();
     writer.RenderEndTag();
 }
        public WebPartTracker(WebPart webPart, ProviderConnectionPoint providerConnectionPoint) {
            if (webPart == null) {
                throw new ArgumentNullException("webPart");
            }

            if (providerConnectionPoint == null) {
                throw new ArgumentNullException("providerConnectionPoint");
            }

            if (providerConnectionPoint.ControlType != webPart.GetType()) {
                throw new ArgumentException(SR.GetString(SR.WebPartManager_InvalidConnectionPoint), "providerConnectionPoint");
            }

            _webPart = webPart;
            _providerConnectionPoint = providerConnectionPoint;

            if (++Count > 1) {
                webPart.SetConnectErrorMessage(SR.GetString(SR.WebPartTracker_CircularConnection, _providerConnectionPoint.DisplayName));
            }
        }
 public WebPartTracker(WebPart webPart, ProviderConnectionPoint providerConnectionPoint)
 {
     if (webPart == null)
     {
         throw new ArgumentNullException("webPart");
     }
     if (providerConnectionPoint == null)
     {
         throw new ArgumentNullException("providerConnectionPoint");
     }
     if (providerConnectionPoint.ControlType != webPart.GetType())
     {
         throw new ArgumentException(System.Web.SR.GetString("WebPartManager_InvalidConnectionPoint"), "providerConnectionPoint");
     }
     this._webPart = webPart;
     this._providerConnectionPoint = providerConnectionPoint;
     if (++this.Count > 1)
     {
         webPart.SetConnectErrorMessage(System.Web.SR.GetString("WebPartTracker_CircularConnection", new object[] { this._providerConnectionPoint.DisplayName }));
     }
 }
 public void CloseWebPart(WebPart webPart)
 {
     this.CloseOrDeleteWebPart(webPart, false);
 }
 private void CloseOrDeleteWebPart(WebPart webPart, bool delete)
 {
     this.Personalization.EnsureEnabled(true);
     if (webPart == null)
     {
         throw new ArgumentNullException("webPart");
     }
     if (!this.Controls.Contains(webPart))
     {
         throw new ArgumentException(System.Web.SR.GetString("UnknownWebPart"), "webPart");
     }
     if (!delete && webPart.IsClosed)
     {
         throw new ArgumentException(System.Web.SR.GetString("WebPartManager_AlreadyClosed"), "webPart");
     }
     if (delete)
     {
         if (webPart.IsStatic)
         {
             throw new ArgumentException(System.Web.SR.GetString("WebPartManager_CantDeleteStatic"), "webPart");
         }
         if (webPart.IsShared && (this.Personalization.Scope == PersonalizationScope.User))
         {
             throw new ArgumentException(System.Web.SR.GetString("WebPartManager_CantDeleteSharedInUserScope"), "webPart");
         }
     }
     WebPartCancelEventArgs e = new WebPartCancelEventArgs(webPart);
     if (delete)
     {
         this.OnWebPartDeleting(e);
     }
     else
     {
         this.OnWebPartClosing(e);
     }
     if (!this._allowEventCancellation || !e.Cancel)
     {
         if ((this.DisplayMode == ConnectDisplayMode) && (webPart == this.SelectedWebPart))
         {
             this.EndWebPartConnecting();
             if (this.SelectedWebPart != null)
             {
                 return;
             }
         }
         if ((this.DisplayMode == EditDisplayMode) && (webPart == this.SelectedWebPart))
         {
             this.EndWebPartEditing();
             if (this.SelectedWebPart != null)
             {
                 return;
             }
         }
         if (delete)
         {
             this.Internals.CallOnDeleting(webPart);
         }
         else
         {
             this.Internals.CallOnClosing(webPart);
         }
         if (!webPart.IsClosed)
         {
             this.RemoveWebPartFromZone(webPart);
         }
         this.DisconnectWebPart(webPart);
         if (delete)
         {
             this.Internals.RemoveWebPart(webPart);
             this.OnWebPartDeleted(new WebPartEventArgs(webPart));
         }
         else
         {
             this.OnWebPartClosed(new WebPartEventArgs(webPart));
         }
     }
 }
 private bool CanConnectWebPartsCore(WebPart provider, ProviderConnectionPoint providerConnectionPoint, WebPart consumer, ConsumerConnectionPoint consumerConnectionPoint, WebPartTransformer transformer, bool throwOnError)
 {
     if (!this.Personalization.IsModifiable)
     {
         if (!throwOnError)
         {
             return false;
         }
         this.Personalization.EnsureEnabled(true);
     }
     if (provider == null)
     {
         throw new ArgumentNullException("provider");
     }
     if (!this.Controls.Contains(provider))
     {
         throw new ArgumentException(System.Web.SR.GetString("UnknownWebPart"), "provider");
     }
     if (consumer == null)
     {
         throw new ArgumentNullException("consumer");
     }
     if (!this.Controls.Contains(consumer))
     {
         throw new ArgumentException(System.Web.SR.GetString("UnknownWebPart"), "consumer");
     }
     if (providerConnectionPoint == null)
     {
         throw new ArgumentNullException("providerConnectionPoint");
     }
     if (consumerConnectionPoint == null)
     {
         throw new ArgumentNullException("consumerConnectionPoint");
     }
     Control control = provider.ToControl();
     Control control2 = consumer.ToControl();
     if (providerConnectionPoint.ControlType != control.GetType())
     {
         throw new ArgumentException(System.Web.SR.GetString("WebPartManager_InvalidConnectionPoint"), "providerConnectionPoint");
     }
     if (consumerConnectionPoint.ControlType != control2.GetType())
     {
         throw new ArgumentException(System.Web.SR.GetString("WebPartManager_InvalidConnectionPoint"), "consumerConnectionPoint");
     }
     if (provider == consumer)
     {
         if (throwOnError)
         {
             throw new InvalidOperationException(System.Web.SR.GetString("WebPartManager_CantConnectToSelf"));
         }
         return false;
     }
     if (provider.IsClosed)
     {
         if (throwOnError)
         {
             throw new InvalidOperationException(System.Web.SR.GetString("WebPartManager_CantConnectClosed", new object[] { provider.ID }));
         }
         return false;
     }
     if (consumer.IsClosed)
     {
         if (throwOnError)
         {
             throw new InvalidOperationException(System.Web.SR.GetString("WebPartManager_CantConnectClosed", new object[] { consumer.ID }));
         }
         return false;
     }
     if (!providerConnectionPoint.GetEnabled(control))
     {
         if (throwOnError)
         {
             throw new InvalidOperationException(System.Web.SR.GetString("WebPartConnection_DisabledConnectionPoint", new object[] { providerConnectionPoint.ID, provider.ID }));
         }
         return false;
     }
     if (!consumerConnectionPoint.GetEnabled(control2))
     {
         if (throwOnError)
         {
             throw new InvalidOperationException(System.Web.SR.GetString("WebPartConnection_DisabledConnectionPoint", new object[] { consumerConnectionPoint.ID, consumer.ID }));
         }
         return false;
     }
     if (!providerConnectionPoint.AllowsMultipleConnections)
     {
         foreach (WebPartConnection connection in this.Connections)
         {
             if ((connection.Provider == provider) && (connection.ProviderConnectionPoint == providerConnectionPoint))
             {
                 if (throwOnError)
                 {
                     throw new InvalidOperationException(System.Web.SR.GetString("WebPartConnection_Duplicate", new object[] { providerConnectionPoint.ID, provider.ID }));
                 }
                 return false;
             }
         }
     }
     if (!consumerConnectionPoint.AllowsMultipleConnections)
     {
         foreach (WebPartConnection connection2 in this.Connections)
         {
             if ((connection2.Consumer == consumer) && (connection2.ConsumerConnectionPoint == consumerConnectionPoint))
             {
                 if (throwOnError)
                 {
                     throw new InvalidOperationException(System.Web.SR.GetString("WebPartConnection_Duplicate", new object[] { consumerConnectionPoint.ID, consumer.ID }));
                 }
                 return false;
             }
         }
     }
     if (transformer == null)
     {
         if (providerConnectionPoint.InterfaceType != consumerConnectionPoint.InterfaceType)
         {
             if (throwOnError)
             {
                 throw new InvalidOperationException(System.Web.SR.GetString("WebPartConnection_NoCommonInterface", new string[] { providerConnectionPoint.DisplayName, provider.ID, consumerConnectionPoint.DisplayName, consumer.ID }));
             }
             return false;
         }
         ConnectionInterfaceCollection secondaryInterfaces = providerConnectionPoint.GetSecondaryInterfaces(control);
         if (!consumerConnectionPoint.SupportsConnection(control2, secondaryInterfaces))
         {
             if (throwOnError)
             {
                 throw new InvalidOperationException(System.Web.SR.GetString("WebPartConnection_IncompatibleSecondaryInterfaces", new string[] { consumerConnectionPoint.DisplayName, consumer.ID, providerConnectionPoint.DisplayName, provider.ID }));
             }
             return false;
         }
     }
     else
     {
         Type type = transformer.GetType();
         if (!this.AvailableTransformers.Contains(type))
         {
             throw new InvalidOperationException(System.Web.SR.GetString("WebPartConnection_TransformerNotAvailable", new object[] { type.FullName }));
         }
         Type consumerType = WebPartTransformerAttribute.GetConsumerType(type);
         Type providerType = WebPartTransformerAttribute.GetProviderType(type);
         if (providerConnectionPoint.InterfaceType != consumerType)
         {
             if (throwOnError)
             {
                 throw new InvalidOperationException(System.Web.SR.GetString("WebPartConnection_IncompatibleProviderTransformer", new object[] { providerConnectionPoint.DisplayName, provider.ID, type.FullName }));
             }
             return false;
         }
         if (providerType != consumerConnectionPoint.InterfaceType)
         {
             if (throwOnError)
             {
                 throw new InvalidOperationException(System.Web.SR.GetString("WebPartConnection_IncompatibleConsumerTransformer", new object[] { type.FullName, consumerConnectionPoint.DisplayName, consumer.ID }));
             }
             return false;
         }
         if (!consumerConnectionPoint.SupportsConnection(control2, ConnectionInterfaceCollection.Empty))
         {
             if (throwOnError)
             {
                 throw new InvalidOperationException(System.Web.SR.GetString("WebPartConnection_ConsumerRequiresSecondaryInterfaces", new object[] { consumerConnectionPoint.DisplayName, consumer.ID }));
             }
             return false;
         }
     }
     return true;
 }
 public virtual bool CanConnectWebParts(WebPart provider, ProviderConnectionPoint providerConnectionPoint, WebPart consumer, ConsumerConnectionPoint consumerConnectionPoint, WebPartTransformer transformer)
 {
     return this.CanConnectWebPartsCore(provider, providerConnectionPoint, consumer, consumerConnectionPoint, transformer, false);
 }
 public bool CanConnectWebParts(WebPart provider, ProviderConnectionPoint providerConnectionPoint, WebPart consumer, ConsumerConnectionPoint consumerConnectionPoint)
 {
     return this.CanConnectWebParts(provider, providerConnectionPoint, consumer, consumerConnectionPoint, null);
 }