Example #1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (WebUtil.PrepareEnvironment(this,
                                       ref app,
                                       ref sessioninfo) == false)
        {
            return;
        }

        // 是否登录?
        if (sessioninfo.UserID == "")
        {
            sessioninfo.LoginCallStack.Push(Request.RawUrl);
            Response.Redirect("login.aspx", true);
            return;
        }

        if (this.IsPostBack == false)
        {
            string strResultsetFilename = CacheBuilder.GetMyBookshelfFilename(
                app,
                sessioninfo);
            if (File.Exists(strResultsetFilename) == true)
            {
                long lHitCount = CacheBuilder.GetCount(app, strResultsetFilename, true);

                this.BrowseSearchResultControl1.ResultsetFilename = strResultsetFilename;
                this.BrowseSearchResultControl1.ResultCount       = (int)lHitCount;
            }
            else
            {
                this.BrowseSearchResultControl1.Title = "我的书架 目前 内容为空";
            }
        }

        this.BrowseSearchResultControl1.Title = (string)this.GetLocalResourceObject("我的书架");
    }
Example #2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        this.BiblioSearchControl1.Location = this.TitleBarControl1.SelectedLibraryCode;

        if (WebUtil.PrepareEnvironment(this,
                                       ref app,
                                       ref sessioninfo) == false)
        {
            return;
        }

        string strSideBarFile = Server.MapPath("./search_sidebar.xml");

        if (File.Exists(strSideBarFile) == true)
        {
            this.SideBarControl1.CfgFile = strSideBarFile;
        }
        else
        {
            this.SideBarControl1.Visible = false;
        }

        SetSideBarVisible();

        /*
         * // 是否登录?
         * if (sessioninfo.UserID == "")
         * {
         *  sessioninfo.LoginCallStack.Push(Request.RawUrl);
         *  Response.Redirect("login.aspx", true);
         *  return;
         * }
         * */

        if (this.BrowseSearchResultControl1.ResultCount > 0)
        {
            this.BrowseSearchResultControl1.Visible = true;
#if FILTER
            VisibleFilter(true);
#endif
        }

        // 是否登录?
        if (sessioninfo.UserID == "")
        {
            if (this.Page.Request["forcelogin"] == "on")
            {
                sessioninfo.LoginCallStack.Push(Request.RawUrl);
                Response.Redirect("login.aspx", true);
                return;
            }
            if (this.Page.Request["forcelogin"] == "userid")
            {
                sessioninfo.LoginCallStack.Push(Request.RawUrl);
                Response.Redirect("login.aspx?loginstyle=librarian", true);
                return;
            }
            sessioninfo.UserID   = "public";
            sessioninfo.IsReader = false;

            /*
             * sessioninfo.LoginCallStack.Push(Request.RawUrl);
             * Response.Redirect("login.aspx", true);
             * return;
             * */
        }

        string strError = "";
        int    nRet     = 0;

#if NO
        string strAction = this.Request["action"];
        if (strAction == "getdblist")
        {
            DoGetDbNameList();
            return;
        }
#endif

        // 如果有参数
        string strWord = this.Request["word"];
        if (String.IsNullOrEmpty(strWord) == false &&
            this.IsPostBack == false)
        {
            string strXml = "";

            // string strWord = "";
            string strDbName     = "";
            string strFrom       = "";
            string strMatchStyle = "";

            GetSearchParams(out strWord,
                            out strDbName,
                            out strFrom,
                            out strMatchStyle);

            // 根据检索参数创建XML检索式
            nRet = OpacApplication.BuildQueryXml(
                this.app,
                strDbName,     // this.Request["dbname"],
                strWord,
                strFrom,       // this.Request["from"],
                strMatchStyle, // this.Request["matchstyle"],
                null,
                null,
                app.SearchMaxResultCount,
                this.BiblioSearchControl1.SearchStyle, // strSearchStyle
                out strXml,
                out strError);
            if (nRet == -1)
            {
                goto ERROR1;
            }

            string strResultSetNamePrefix = "";

            strResultSetNamePrefix = this.Request["resultsetname"];
            if (String.IsNullOrEmpty(strResultSetNamePrefix) == true)
            {
                strResultSetNamePrefix = Session.SessionID + "_opac_1";
            }
            else
            {
                strResultSetNamePrefix = Session.SessionID + "_" + strResultSetNamePrefix;
            }

            string strResultSetName = GetResultSetName(strResultSetNamePrefix);

            LibraryChannel channel = sessioninfo.GetChannel(true);
            //sessioninfo.Channel.
            channel.Idle += new IdleEventHandler(channel_Idle);
            try
            {
                long lRet = // sessioninfo.Channel.
                            channel.Search(
                    null,
                    strXml,
                    strResultSetName,
                    "", // strOutputStyle
                    out strError);
                if (lRet == -1)
                {
                    goto ERROR1;
                }
#if FILTER
                app.SetFilterTask(strResultSetName, null);
#endif

                if (app.SearchLog != null)
                {
                    SearchLogItem log = new SearchLogItem();
                    log.IP    = this.Request.UserHostAddress.ToString();
                    log.Query = SearchLog.BuildLogQueryString(
                        this.Request["dbname"],
                        strWord,
                        this.Request["from"],
                        this.Request["matchstyle"]);
                    log.Time     = DateTime.UtcNow;
                    log.HitCount = nRet;
                    log.Format   = "searchcount";
                    app.SearchLog.AddLogItem(log);
                }

                // not found
                if (lRet == 0)
                {
                    this.BrowseSearchResultControl1.Visible = false;
#if FILTER
                    this.filter.Visible = false;
#endif
                    strError = "没有找到";
                    goto ERROR1;
                }

                this.BrowseSearchResultControl1.Clear();
                this.BrowseSearchResultControl1.Visible = true;
#if FILTER
                VisibleFilter(true);
#endif

                this.BrowseSearchResultControl1.ResultSetName = strResultSetName;
                this.BrowseSearchResultControl1.ResultCount   = (int)lRet;
                this.BrowseSearchResultControl1.StartIndex    = 0; // 2008/12/15

#if FILTER
                this.filter.ResultSetName = strResultSetName;
#endif

                string strFormat = this.Request["format"];
                if (String.IsNullOrEmpty(strFormat) == false)
                {
                    this.BrowseSearchResultControl1.FormatName = strFormat;
                }
                return;
            }
            finally
            {
                // sessioninfo.Channel.
                channel.Idle -= new IdleEventHandler(channel_Idle);
                sessioninfo.ReturnChannel(channel);
            }
        }

        // 观察特定的结果集
        if (this.IsPostBack == false)
        {
            string strResultSet     = this.Request["resultset"];
            string strBaseResultSet = this.Request["base"];
            string strTitle         = this.Request["title"];
            if (string.IsNullOrEmpty(strResultSet) == false)
            {
                string strResultsetFilename = PathUtil.MergePath(app.TempDir,   // sessioninfo.GetTempDir(), // ??
                                                                 strResultSet);
                if (File.Exists(strResultsetFilename) == true)
                {
                    long lHitCount = CacheBuilder.GetCount(app, strResultsetFilename, true);

                    this.BrowseSearchResultControl1.ResultsetFilename = strResultsetFilename;

                    this.BrowseSearchResultControl1.Visible = true;
#if FILTER
                    VisibleFilter(true);

                    this.filter.ResultSetName = strBaseResultSet;
#endif

                    string strOffset = this.Request["offset"];
                    this.BrowseSearchResultControl1.ResultsetOffset = strOffset;

#if FILTER
                    this.filter.SelectedNodePath = MakeSelectedPath(strResultSet, strOffset);
#endif
                    if (string.IsNullOrEmpty(strOffset) == false)
                    {
                        int nStart  = 0;
                        int nLength = -1;
                        BrowseSearchResultControl.ParseOffsetString(strOffset,
                                                                    out nStart,
                                                                    out nLength);
                        if (nLength == -1)
                        {
                            nLength = (int)lHitCount - nStart;
                        }
                        this.BrowseSearchResultControl1.ResultCount = nLength;
                    }
                    else
                    {
                        this.BrowseSearchResultControl1.ResultCount = (int)lHitCount;
                    }

                    if (string.IsNullOrEmpty(strTitle) == false)
                    {
                        this.BrowseSearchResultControl1.Title = strTitle;
                    }
                }
                else
                {
                    strError = "结果集文件 '" + strResultSet + "' 不存在";
                    goto ERROR1;
                }
            }
            else if (string.IsNullOrEmpty(strBaseResultSet) == false)
            {
                // 只用了base参数
                this.BrowseSearchResultControl1.Clear();
                this.BrowseSearchResultControl1.Visible = true;
#if FILTER
                VisibleFilter(true);
#endif

                this.BrowseSearchResultControl1.ResultSetName = strBaseResultSet;
                this.BrowseSearchResultControl1.ResultCount   = (int)MyWebPage.GetServerResultCount(sessioninfo, strBaseResultSet);
                this.BrowseSearchResultControl1.StartIndex    = 0;

#if FILTER
                this.filter.ResultSetName = strBaseResultSet;
#endif
            }
        }

        //this.AdvanceSearchControl1.Channels = sessioninfo.Channels;
        //this.AdvanceSearchControl1.ServerUrl = app.WsUrl;

        // this.HeadBarControl1.CurrentColumn = HeaderColumn.Search;
        return;

ERROR1:
        Response.Write(HttpUtility.HtmlEncode(strError));
        Response.End();
    }
Example #3
0
    void DisplayNode(string strDataFileName, string strNodePath)
    {
        int    nRet     = 0;
        string strError = "";

        this.BrowseSearchResultControl1.SelectAll(false);

        string      strXmlFilePath = app.DataDir + "/browse/" + strDataFileName;
        XmlDocument dom            = new XmlDocument();

        dom.Load(strXmlFilePath);

        // 2014/12/2
        // 兑现宏
        nRet = CacheBuilder.MacroDom(dom,
                                     new List <string> {
            "name", "command"
        },
                                     out strError);
        if (nRet == -1)
        {
            goto ERROR1;
        }

        XmlNode node = null;

        if (string.IsNullOrEmpty(strNodePath) == true)
        {
            // 找到第一个节点
            node = GetFirstNode(dom.DocumentElement);
            if (node == null)
            {
                return;
            }
            strNodePath = CacheBuilder.MakeNodePath(node);
        }
        else
        {
            // TODO: 也可以用节点文字名字来选定
            node = CacheBuilder.GetDataNode(dom.DocumentElement, strNodePath);
            if (node == null)
            {
                return;
            }
        }

        this.TreeView1.SelectedNodePath = "";

        this.SelectingNodePath = strNodePath;
        string strPureCaption = DomUtil.GetAttr(node, "name");

        string strDescription = DomUtil.GetAttr(node, "description");

        if (String.IsNullOrEmpty(strDescription) == true)
        {
            this.Description1.Text = "";
        }
        else
        {
            this.Description1.Text = "<div class='text'>" + strDescription + "</div>";
        }

        string strCommand = DomUtil.GetAttr(node, "command");

        bool   bRss         = false;
        long   nMaxCount    = -1;
        string strDirection = "";

        // parameters:
        //      nMaxCount   -1表示无穷多
        //      strDirection    head/tail
        CacheBuilder.GetRssParam(node,
                                 out bRss,
                                 out nMaxCount,
                                 out strDirection);

        // this.HyperLink_rss.Visible = bRss;

        if (strCommand == "~hidelist~")
        {
            //
            this.BrowseSearchResultControl1.ResultSetName     = "";
            this.BrowseSearchResultControl1.ResultsetFilename = "";
            this.BrowseSearchResultControl1.ResultCount       = 0;
            this.BrowseSearchResultControl1.StartIndex        = 0;
            this.BrowseSearchResultControl1.Visible           = false;
            return;
        }

        this.BrowseSearchResultControl1.Visible = true;

        if (strCommand == "~none~")
        {
            //
            this.BrowseSearchResultControl1.ResultSetName     = "";
            this.BrowseSearchResultControl1.ResultsetFilename = "";
            this.BrowseSearchResultControl1.ResultCount       = 0;
            this.BrowseSearchResultControl1.StartIndex        = 0;
            return;
        }

#if NO
        string strPureCaption = this.TreeView1.SelectedNode.Text;
        nRet = strPureCaption.IndexOf("(");
        if (nRet != -1)
        {
            strPureCaption = strPureCaption.Substring(0, nRet).Trim();
        }
#endif

        string strDataFile = strDataFileName;  //  PathUtil.PureName(strDataFile);

        string strPrefix   = CacheBuilder.MakeNodePath(node);
        string strCacheDir = app.DataDir + "/browse/cache/" + strDataFile;

        PathUtil.TryCreateDir(strCacheDir);
        string strResultsetFilename = strCacheDir + "/" + strPrefix;

        string strRssString = "datafile=" + strDataFile + "&node=" + strPrefix;
        // this.HyperLink_rss.NavigateUrl = "browse.aspx?action=rss&" + strRssString;
        string strRssNavigateUrl = "browse.aspx?action=rss&" + strRssString;

        bool bRedo = false;

REDO:
        // 如果文件已经存在,就不要从 dp2library 获取了
        try
        {
            app.ResultsetLocks.LockForRead(strResultsetFilename, 500);
            try
            {
                if (this.Response.IsClientConnected == false)
                {
                    return;
                }

                if (File.Exists(strResultsetFilename) == true)
                {
                    // 2010/12/21
                    // 看看是否为每日强制更新的节点
                    // 获得Build相关参数
                    // parameters:
                    //      strBuildStyle    创建风格 perday / perhour
                    CacheBuilder.GetBuildParam(node,
                                               out string strBuildStyle);
                    if (String.IsNullOrEmpty(strBuildStyle) == false &&
                        strBuildStyle.ToLower() != "disable")
                    {
                        // 比较文件创建时间和当前时间,看看是否超过重建周期
                        if (CacheBuilder.HasExpired(strResultsetFilename,
                                                    strBuildStyle) == true)
                        {
                            goto DO_REBUILD;
                        }
                    }

                    long lHitCount = CacheBuilder.GetCount(app, strResultsetFilename, false);

                    // 记忆下来
                    app.SetBrowseNodeCount(strDataFile, strNodePath, lHitCount.ToString());

                    this.BrowseSearchResultControl1.ResultsetFilename = strResultsetFilename;
                    this.BrowseSearchResultControl1.ResultCount       = (int)lHitCount;
                    this.BrowseSearchResultControl1.StartIndex        = 0;
                    this.CreateRssLink(strPureCaption, strRssNavigateUrl);
                    this.Page.Title = strPureCaption;
                    // this.SelectedNodeCaption = strPureCaption + "(" + lHitCount.ToString() + ")";
                    this.TreeView1.SelectedNodePath = strNodePath;
                    return;
                }
            }
            finally
            {
                app.ResultsetLocks.UnlockForRead(strResultsetFilename);
            }
        }
        catch (System.ApplicationException /*ex*/)
        {
            this.SetErrorInfo(strPureCaption + " 相关缓存文件暂时被占用,请稍后重新访问");
            goto END1;
        }

DO_REBUILD:

        if (bRedo == false)
        {
            /*
             * // 加入列表
             * lock (app.PendingCacheFiles)
             * {
             *  string strLine = strDataFile + ":" + strPrefix;
             *  if (app.PendingCacheFiles.IndexOf(strLine) == -1)
             *      app.PendingCacheFiles.Add(strLine);
             * }
             * app.ActivateCacheBuilder();
             * */
            CacheBuilder.AddToPendingList(app,
                                          strDataFile,
                                          strPrefix,
                                          "");


            bRedo = true;
            if (Wait() == true)
            {
                return;
            }
            goto REDO;
        }
        else
        {
            this.SetErrorInfo(strPureCaption + " 相关缓存正在建立,请稍后重新访问");
            // this.SelectedNodeCaption = strPureCaption;
        }

END1:
        this.CreateRssLink(strPureCaption, strRssNavigateUrl);
        this.Page.Title = strPureCaption;

        this.BrowseSearchResultControl1.ResultSetName     = "";
        this.BrowseSearchResultControl1.ResultsetFilename = "";

        this.BrowseSearchResultControl1.ResultCount = 0;
        this.BrowseSearchResultControl1.StartIndex  = 0;
        this.TreeView1.SelectedNodePath             = strNodePath;

        return;

ERROR1:
        Response.Write(HttpUtility.HtmlEncode(strError));
        Response.End();
    }