/// <summary>
        /// handles updating the module settings for this control
        /// </summary>
        public override void UpdateSettings()
        {
            try {
                var settings = new DocumRollerSettings (this.ModuleId, this.TabModuleId);
                //settings.Template = txtTemplate.Text;

                settings.ItemToShow = int.Parse(txtItemToShow.Text);

                settings.SortOrder = chkSortOrder.Checked;

                settings.SortField = ddlSortField.SelectedValue;

            } catch (Exception ex) {
                Exceptions.ProcessModuleLoadException (this, ex);
            }
        }
        /// <summary>
        /// Handles the loading of the module setting for this control
        /// </summary>
        public override void LoadSettings()
        {
            try {
                if (!IsPostBack) {
                    Localize ();

                    var settings = new DocumRollerSettings (this.ModuleId, this.TabModuleId);

                    if (!string.IsNullOrWhiteSpace (settings.Template)) {
                        //txtTemplate.Text = settings.Template;
                    }

                    txtItemToShow.Text = settings.ItemToShow.ToString ();
                    chkSortOrder.Checked = settings.SortOrder;
                    Utils.SetIndexByValue (ddlSortField,settings.SortField,0);

                }

            } catch (Exception ex) {
                Exceptions.ProcessModuleLoadException (this, ex);
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            //throw (new Exception("I'm working!"));
            if (!IsPostBack)
            {
                #region RSS OPTIONS
                /*
                if (!String.IsNullOrEmpty(Request.QueryString["records"]))
                {
                    records = int.Parse(Request.QueryString["records"]);
                }*/
                // PortalSettings.PortalAlias;
                string title = new ModuleController().GetTabModule(TabModuleId).ModuleTitle;
                string description = "descr";

                var settings = new DocumRollerSettings (this.ModuleId, this.TabModuleId);
                int records = settings.ItemToShow;

            //int.TryParse((string)Settings["rss_records"], out records);

                // определяем язык запроса
                // PortalSettings.CultureCode
                string language = PortalSettings.CultureCode; // язык по-умолчанию - русский
                /*
                if (!String.IsNullOrEmpty(Request.QueryString["language"]))
                    language = Request.QueryString["language"].ToLower();
                */
                #endregion

                if (records > 0)
                {
                    // проверяем, существует ли директория с кешем rss
                    // если нет, создаем
                    //string rss_dname = Path.Combine(PortalSettings.HomeDirectoryMapPath, "Cache");
                    //if (!Directory.Exists(rss_dname))
                    //	Directory.CreateDirectory(rss_dname);

                    //Directory.SetCurrentDirectory(rss_dname);

                    // формируем имя файла кеша rss для нашего модуля
                    /*string rssfile_fullname = Path.Combine(
                        rss_dname,
                        String.Format("Feed_{0}.rss", ModuleId));
            */
                    // устанавливаем, нужно ли обновлять rss канал?
                    // в данном случае время устаревания - cachetime часов
            /*					bool
                        need_regen = !File.Exists(rssfile_fullname);
                    if (!need_regen) need_regen =
                        // актуальность канала - cachetime часов
                        File.GetLastWriteTime(rssfile_fullname) + new TimeSpan(cachetime, 0, 0) < DateTime.Now;

                    // для отладки!!!
                    //need_regen = true;

            */					// если нужна перегенерация, формируем xml-файл в кеше rss
                    //if (true) //need_regen)
                    {
                        var ctrl = new DocumRollerController ();
                        //var items = ctrl.GetList<DocumRollerInfo> (this.ModuleId);
                        var docrollers = ctrl.GetObjects<DocRollerInfo> (System.Data.CommandType.StoredProcedure,
                                                                         "dbo.Aggregator_GetContent" , settings.ItemToShow, settings.SortOrder);

                    string rss_dname = Path.Combine(PortalSettings.HomeDirectoryMapPath, "Cache");
                    if (!Directory.Exists(rss_dname))
                        Directory.CreateDirectory(rss_dname);

                    // формируем имя файла кеша rss для нашего модуля
                    string rssfile_fullname = Path.Combine(
                        rss_dname,
                        String.Format("Feed_{0}.xml", ModuleId));

                        File.WriteAllText(rssfile_fullname, ToRss(docrollers, language, title, description));

                        Response.Redirect("http://" + PortalSettings.PortalAlias.HTTPAlias +
                            "/Portals/"+ PortalId +"/Cache/" + string.Format("Feed_{0}.xml", ModuleId), true);
                        // labe.11st.Text = Server.HtmlEncode(ToRss (language, title, description));
                    /*
                        Response.Clear ();
                        Response.ContentType = "application/rss+xml";
                        Response.Write (ToRss(docrollers, language, title, description));
                        Response.Flush ();
                        Response.Close ();*/

                    }
                }
            }
        }
        /// <summary>
        /// Handles the items being bound to the datalist control. In this method we merge the data with the
        /// template defined for this control to produce the result to display to the user
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void lstContent_ItemDataBound(object sender, System.Web.UI.WebControls.DataListItemEventArgs e)
        {
            // use e.Item.DataItem as object of DocumRollerInfo class,
            // as we really know it is:
            var item = e.Item.DataItem as DocRollerInfo;

            var contentLabel = e.Item.FindControl ("lblContent") as Label;
            var createdondateLabel = e.Item.FindControl ("lblCreatedOnDate") as Label;
            var createdbyuseridLabel = e.Item.FindControl ("lblCreatedByUserID") as Label;
            var lastmodifiedondateLabel = e.Item.FindControl ("lblLastModifiedOnDate") as Label;
            var modifiedbyuseridLabel = e.Item.FindControl ("lblLastModifiedByUserID") as Label;
            var titlelink = e.Item.FindControl ("lnkDocument") as HyperLink;

            // find controls in DataList item template
            //var contentLabel = e.Item.FindControl ("lblContent") as Label;
            /*var urlLabel = e.Item.FindControl ("lblURL") as Label;
            var titleLabel = e.Item.FindControl ("lblTitle") as Label;
            var categoryLabel = e.Item.FindControl ("lblCategory") as Label;
            var createdbyuseridLabel = e.Item.FindControl ("lblCreatedByUserId") as Label;
            var ownedbyuseridLabel = e.Item.FindControl ("lblOwnedByUserId") as Label;
            var modifiedbyuseridLabel = e.Item.FindControl ("lblModifiedByUserId") as Label;
            var sortorderindexLabel = e.Item.FindControl ("lblSortOrderIndex") as Label;
            var descriptionLabel = e.Item.FindControl ("lblDescription") as Label;
            var createddateLabel = e.Item.FindControl ("lblCreatedDate") as Label;
            var modifieddateLabel = e.Item.FindControl ("lblModifiedDate") as Label;
            */
            // setting default values
            //			var contentValue = string.Empty;

            // read module settings
            var settings = new DocumRollerSettings (this.ModuleId, this.TabModuleId);

            contentLabel.Text = Server.HtmlDecode(item.Content);
            createdondateLabel.Text = item.CreatedOnDate.ToLongDateString();

            lastmodifiedondateLabel.Text = item.LastModifiedOnDate.ToLongDateString();

            //titlelink.NavigateUrl = FileManager.Instance.GetUrl (
                //FileManager.Instance.GetFile(int.Parse(item.URL.ToUpper().Replace("FILEID=",""))));
            titlelink.Target = "_blank";
            if (item.Tab != null)
            titlelink.NavigateUrl ="/default.aspx?TabId="+ item.Tab.TabID;
            if (item.DesktopModule != null)
                titlelink.NavigateUrl ="/default.aspx?DesktopModuleId="+ item.DesktopModule.DesktopModuleID;
            if (item.TabModule != null)
                titlelink.NavigateUrl =string.Format ("/default.aspx?tabid={0}&mid={1}", item.TabModule.TabID, item.TabModule.ModuleID);
            if (item.Journal != null)
                titlelink.NavigateUrl ="/default.aspx?JournalId="+ item.Journal.JournalID;
            if (item.Blog != null)
                titlelink.NavigateUrl ="/default.aspx?ContentItemId="+ item.Blog.ContentItemId;

            /*			urlLabel.Text = Server.HtmlDecode(item.URL);
            titleLabel.Text = Server.HtmlDecode(item.Title);
            categoryLabel.Text = Server.HtmlDecode(item.Category);
            createdbyuseridLabel.Text = item.CreatedByUserId.ToString();
            ownedbyuseridLabel.Text = item.OwnedByUserId.ToString();
            modifiedbyuseridLabel.Text = item.ModifiedByUserId.ToString();
            sortorderindexLabel.Text = item.SortOrderIndex.ToString();
            descriptionLabel.Text = Server.HtmlDecode(item.Description);
            createddateLabel.Text = item.CreatedDate.ToLongDateString();
            modifieddateLabel.Text = item.ModifiedDate.ToLongDateString();
            */
        }
        /// <summary>
        /// Handles Page_Load event for a control
        /// </summary>
        /// <param name='sender'>
        /// Sender.
        /// </param>
        /// <param name='e'>
        /// Event args.
        /// </param>
        protected void Page_Load(object sender, EventArgs e)
        {
            try {
                if (!IsPostBack) {

                    linkRss.NavigateUrl = EditUrl("Rss");

                    var ctrl = new DocumRollerController ();
                    //var items = ctrl.GetList<DocumRollerInfo> (this.ModuleId);
                    var settings = new DocumRollerSettings (this.ModuleId, this.TabModuleId);
                    var docrollers = ctrl.GetObjects<DocRollerInfo> (System.Data.CommandType.StoredProcedure,
                               "dbo.Aggregator_GetContent" , settings.ItemToShow, settings.SortOrder);

                    // check if we have some content to display,
                    // otherwise display a sample default content from the resources
                    /*if (items.Count == 0) {
                        var item = new DocumRollerInfo () {
                            ModuleID = this.ModuleId,
                            CreatedByUser = this.UserId,
                            Content = Localization.GetString ("DefaultContent", LocalResourceFile)
                        };

                        items.Add (item);
                    }*/

                    // bind the data
                    lstContent.DataSource = docrollers;
                    lstContent.DataBind ();
                }
            } catch (Exception ex) {
                Exceptions.ProcessModuleLoadException (this, ex);
            }
        }