//public ISPSTreeNode<ISPSHierarchyNode> GetAll1()
        //{
        //    SPSHierarchyODFactory factory = new SPSHierarchyODFactory(Filter);

        //    string webUrl = _webUrl;
        //    string listUrl = string.Empty;
        //    string pathUrl = string.Empty;

        //    if (!string.IsNullOrEmpty(_url))
        //    {
        //        webUrl = _url.Split('|')[0];
        //        listUrl = _url.Split('|')[1];
        //        pathUrl = _url.Split('|')[2];
        //    }

        //    //using (SPWeb web = TryGetWebToUse(_webUrl))
        //    using(SPWeb web = TryGetWebToUse(webUrl))
        //    {
        //        try
        //        {
        //            //if (!string.IsNullOrEmpty(_url))
        //            if (!string.IsNullOrEmpty(pathUrl))
        //            {
        //                try
        //                {
        //                    //Object element = web.GetObject(_url);
        //                    Object element = web.GetObject(pathUrl);

        //                    if (element is SPList)
        //                    {
        //                        _root = factory.MakeFolderNodes(((SPList) element).RootFolder);
        //                    }
        //                    else if (element is SPFolder)
        //                    {
        //                        _root = factory.MakeFolderNodes(((SPFolder) element));
        //                    }
        //                }
        //                catch (Exception ex)
        //                {
        //                    //try
        //                    //{
        //                    //    _root = factory.MakeFolderNodes(web.GetFolder(_url));
        //                    //}
        //                    //catch (Exception ex)
        //                    //{
        //                    Debug.WriteLine(webUrl);
        //                    Debug.WriteLine(pathUrl);
        //                    Debug.WriteLine(ex);

        //                    //using(SPWeb webWork = TryGetWebToUse(_url))
        //                    using(SPWeb webWork = TryGetWebToUse(webUrl))
        //                    {
        //                        _root = factory.MakeWebAndListNodes(webWork);
        //                    }
        //                    //}
        //                }
        //            }
        //            else
        //            {
        //                _root = factory.MakeWebAndListNodes(web);
        //            }
        //        }
        //        catch (Exception ex)
        //        {
        //            Debug.WriteLine("2");
        //            Debug.WriteLine(_url);
        //            Debug.WriteLine(ex);
        //            throw new ArgumentException(
        //                    string.Format(ex.Message + " " + SPSLocalization.GetResourceString("SPSFW_Err_Open_Url"),
        //                                  _url));
        //        }
        //    }

        //    return _root;
        //}

        /// <summary>
        /// Gets the web to use.
        /// </summary>
        /// <param name="webUrl">The web URL.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentException"><c>ArgumentException</c>.</exception>
        private SPWeb TryGetWebToUse(string webUrl)
        {
            SPWeb web;

            if (!string.IsNullOrEmpty(webUrl))
            {
                try
                {
                    using (SPSite site = new SPSite(webUrl))
                    {
                        web = site.OpenWeb();
                    }
                }
                catch (Exception)
                {
                    throw new ArgumentException(string.Format("<br/>{0}",
                                                              string.Format(SPSLocalization.GetResourceString("SPSFW_Err_Open_Url"),
                                                                            webUrl)));
                }
            }
            else
            {
                web = SPContext.Current.Web.Site.OpenWeb();
            }

            return(web);
        }
 /// <summary>
 /// Initializes the class for use by an inherited class instance. This constructor can be called only by an inherited class.
 /// </summary>
 public SPSCacheEditorPart()
 {
     // ReSharper disable DoNotCallOverridableMethodsInConstructor
     ID          = "CacheEditor";
     Title       = SPSLocalization.GetResourceString("SPSFW_CacheEditorPartTitle");
     ChromeState = PartChromeState.Normal;
     // ReSharper restore DoNotCallOverridableMethodsInConstructor
 }
        protected override void CreateChildControls()
        {
            chkEnableCache      = new CheckBox();
            chkEnableCache.Text = SPSLocalization.GetResourceString("SPSFW_EnableCache");
            Controls.Add(chkEnableCache);

            txtCacheTimeInSeconds       = new TextBox();
            txtCacheTimeInSeconds.Width = new Unit("100");
            Controls.Add(txtCacheTimeInSeconds);
        }
        /// <summary>
        /// Internally we must use SPSRender method
        /// </summary>
        /// <param name="writer"></param>
        protected override void Render(HtmlTextWriter writer)
        {
            // Check Design Mode
            if (DesignMode)
            {
                writer.Write(SPS_MESSAGE,
                             "blue",
                             SPSPROPARTS,
                             _spsPartName,
                             SPSLocalization.GetResourceString("SPSFW_InDesignMode"));
            }
            else
            {
                // Check SPS License
                if (Licensed)
                {
                    try
                    {
                        EnsureChildControls();
                        SPSRender(writer);

                        // Display errors if any
                        if (!string.IsNullOrEmpty(ErrorMessage))
                        {
                            writer.Write(SPS_MESSAGE, "red", SPSPROPARTS, _spsPartName, ErrorMessage);
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new SPException(
                                  string.Format("Error: {0}\nMessage: {1}\n Trace: {2}\n",
                                                ex.GetType(),
                                                ex.Message,
                                                ex));
                    }
                }
                else
                {
                    writer.Write(SPS_MESSAGE,
                                 "red",
                                 SPSPROPARTS,
                                 _spsPartName,
                                 SPSLocalization.GetResourceString("SPSFW_Err_CheckLicenseFile"));
                }
            }
            //base.Render(writer);
        }
        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.PreRender"/> event.
        /// </summary>
        /// <param name="e">An <see cref="T:System.EventArgs"/> object that contains the event data.</param>
        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);

            if (_xmlCalendar != null)
            {
                try
                {
                    _xmlCalendar.Fill(_calendarView);
                    _calendarView.DataBind();
                }
                catch (Exception ex)
                {
                    TrapError(GetType(), SPSLocalization.GetResourceString("SPSFW_Err_XmlCalendar"), ex);
                }
            }
        }
        /// <summary>
        /// Gets all.
        /// </summary>
        /// <exception cref="ArgumentException"><c>ArgumentException</c>.</exception>
        public ISPSTreeNode <ISPSHierarchyNode> GetAll()
        {
            SPSHierarchyODFactory factory = new SPSHierarchyODFactory(Filter);

            string webUrl    = _webUrl.TrimEnd('|');
            string listUrl   = string.Empty;
            string folderUrl = string.Empty;

            if (!string.IsNullOrEmpty(_url))
            {
                webUrl    = _url.Split('|')[0];
                listUrl   = _url.Split('|')[1];
                folderUrl = _url.Split('|')[2];
            }

            using (SPWeb web = TryGetWebToUse(webUrl))
            {
                try
                {
                    if (!string.IsNullOrEmpty(listUrl) && !string.IsNullOrEmpty(folderUrl))
                    {
                        SPFolder folder = web.GetFolder(webUrl + folderUrl);
                        _root = factory.MakeFolderNodes(folder);
                    }
                    else if (!string.IsNullOrEmpty(listUrl))
                    {
                        SPList list = web.Lists[listUrl];
                        _root = factory.MakeFolderNodes(list.RootFolder);
                    }
                    else
                    {
                        _root = factory.MakeWebAndListNodes(web);
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex);
                    throw new ArgumentException(string.Format(
                                                    string.Format("<br/>{0} {1}",
                                                                  ex.Message,
                                                                  SPSLocalization.GetResourceString("SPSFW_Err_Open_Url")), _url));
                }
            }

            return(_root);
        }
        internal StringWriter Transform()
        {
            StringWriter stringWriter = new StringWriter();

            try
            {
                XslCompiledTransform xslt = GetCompiled();

                XmlDocument xmlDocument = new XmlDocument();
                xmlDocument.LoadXml(XmlData);

                XmlTextWriter    xmlw = new XmlTextWriter(stringWriter);
                XsltArgumentList xal  = new XsltArgumentList();

                if (XslPage.HasValue)
                {
                    xal.AddParam("CurrentPage", String.Empty, XslPage);
                }
                if (XslOrder != null)
                {
                    xal.AddParam("CurrentOrder", String.Empty, XslOrder);
                }
                if (XslSelectedRow.HasValue)
                {
                    xal.AddParam("CurrentRow", String.Empty, XslSelectedRow);
                }

                //create custom object
                SPSXsltExtension xsltExtension = new SPSXsltExtension(Parent, Page, LastRow);

                //pass an instance of the custom object
                xal.AddExtensionObject("http://schemas.spsprofessional.com/WebParts/SPSXSLT", xsltExtension);

                xslt.Transform(xmlDocument, xal, xmlw);
            }
            catch (Exception ex)
            {
                TrapError(GetType(), SPSLocalization.GetResourceString("SPSFW_Err_XsltTransformation"), ex);
            }
            return(stringWriter);
        }
        /// <summary>
        /// Gets the XML calendar.
        /// </summary>
        /// <returns>A SPSCalendarXML definition</returns>
        private SPSCalendarXML GetCalendarXML()
        {
            XmlSerializer serializer = new XmlSerializer(typeof(SPSCalendarXML));

            _xmlTransformed = Transform().ToString();

            if (!string.IsNullOrEmpty(_xmlTransformed))
            {
                try
                {
                    TextReader     reader   = new StringReader(_xmlTransformed);
                    SPSCalendarXML calendar = (SPSCalendarXML)serializer.Deserialize(reader);
                    return(calendar);
                }
                catch (Exception ex)
                {
                    TrapError(GetType(), SPSLocalization.GetResourceString("SPSFW_Err_XmlCalendar"), ex);
                }
            }
            return(null);
        }
        protected override void RenderContents(HtmlTextWriter writer)
        {
            SPSEditorPartsTools tools = new SPSEditorPartsTools(writer);

            tools.DecorateControls(Controls);

            tools.SectionBeginTag();

            tools.SectionHeaderTag();
            chkEnableCache.RenderControl(writer);
            tools.SectionFooterTag();

            tools.SectionHeaderTag(SPSLocalization.GetResourceString("SPSFW_CacheTimeOut"));
            txtCacheTimeInSeconds.RenderControl(writer);
            tools.SectionFooterTag();

            tools.SectionEndTag();

            if (!string.IsNullOrEmpty(_errorMessage))
            {
                Zone.ErrorText += Environment.NewLine + _errorMessage;
            }
        }