Пример #1
0
 // 写入数据库的时候, 可以锁定一个范围,后面可以继续并发追加记录,这样效率就很高了。
 // 只有在删除已经写入数据库的部分记录的瞬间,才需要锁定整个集合
 public void AddLogItem(SearchLogItem item)
 {
     if (this.m_lock.TryEnterReadLock(m_nLockTimeout) == false)
         throw new ApplicationException("锁定尝试中超时");
     try
     {
         this._searchLogCache.Add(item);
     }
     finally
     {
         this.m_lock.ExitReadLock();
     }
 }
Пример #2
0
 // 写入数据库的时候, 可以锁定一个范围,后面可以继续并发追加记录,这样效率就很高了。
 // 只有在删除已经写入数据库的部分记录的瞬间,才需要锁定整个集合
 public void AddLogItem(SearchLogItem item)
 {
     if (this.m_lock.TryEnterReadLock(m_nLockTimeout) == false)
     {
         throw new ApplicationException("锁定尝试中超时");
     }
     try
     {
         this._searchLogCache.Add(item);
     }
     finally
     {
         this.m_lock.ExitReadLock();
     }
 }
Пример #3
0
        int PrepareBiblioRecord(
            out string strError)
        {
            strError = "";
            int nRet = 0;
            long lRet = 0;
            // string strOutputPath = "";

            if (string.IsNullOrEmpty(this.RecPath) == true)
                return 0;   // 此时无法进行初始化

            OpacApplication app = (OpacApplication)this.Page.Application["app"];
            SessionInfo sessioninfo = (SessionInfo)this.Page.Session["sessioninfo"];

            string strBiblioXml = "";
            string strBiblioState = "";

            byte[] timestamp = null;
            string[] formats = new string[1];
            formats[0] = "xml";

            string[] results = null;
            lRet = sessioninfo.Channel.GetBiblioInfos(
                null,
                this.RecPath,
                "",
                formats,
                out results,
                out timestamp,
                out strError);
            if (lRet == -1)
            {
                strError = "获得种记录 '" + this.RecPath + "' 时出错: " + strError;
                goto ERROR1;
            }
            if (results == null || results.Length < 1)
            {
                strError = "results error ";
                goto ERROR1;
            }

            if (app.SearchLog != null)
            {
                SearchLogItem log = new SearchLogItem();
                log.IP = this.Page.Request.UserHostAddress.ToString();
                log.Query = "";
                log.Time = DateTime.UtcNow;
                log.HitCount = 1;
                log.Format = "biblio";
                log.RecPath = this.RecPath;
                app.SearchLog.AddLogItem(log);
            }

            strBiblioXml = results[0];
            this.m_strXml = strBiblioXml;

            this.Timestamp = ByteArray.GetHexTimeStampString(timestamp);
            this.BiblioRecPath = this.RecPath;

            string strMarc = "";

            // 转换为MARC
            {
                string strOutMarcSyntax = "";

                // 将MARCXML格式的xml记录转换为marc机内格式字符串
                // parameters:
                //		bWarning	==true, 警告后继续转换,不严格对待错误; = false, 非常严格对待错误,遇到错误后不继续转换
                //		strMarcSyntax	指示marc语法,如果=="",则自动识别
                //		strOutMarcSyntax	out参数,返回marc,如果strMarcSyntax == "",返回找到marc语法,否则返回与输入参数strMarcSyntax相同的值
                nRet = MarcUtil.Xml2Marc(strBiblioXml,
                    true,
                    "", // this.CurMarcSyntax,
                    out strOutMarcSyntax,
                    out strMarc,
                    out strError);
                if (nRet == -1)
                    goto ERROR1;

                this.m_strMARC = strMarc;
            }

            bool bAjax = true;
            if (this.DisableAjax == true)
                bAjax = false;
            else
            {
                if (app != null
                    && app.WebUiDom != null
                    && app.WebUiDom.DocumentElement != null)
                {
                    XmlNode nodeBiblioControl = app.WebUiDom.DocumentElement.SelectSingleNode(
            "biblioControl");
                    if (nodeBiblioControl != null)
                    {
                        DomUtil.GetBooleanParam(nodeBiblioControl,
                            "ajax",
                            true,
                            out bAjax,
                            out strError);
                    }
                }
            }

            if (bAjax == false)
            {
                string strBiblio = "";
                string strBiblioDbName = ResPath.GetDbName(this.RecPath);

                // 需要从内核映射过来文件
                string strLocalPath = "";
                nRet = app.MapKernelScriptFile(
                    null,   // sessioninfo,
                    strBiblioDbName,
                    "./cfgs/opac_biblio.fltx",  // OPAC查询固定认这个角色的配置文件,作为公共查询书目格式创建的脚本。而流通前端,创建书目格式的时候,找的是loan_biblio.fltx配置文件
                    out strLocalPath,
                    out strError);
                if (nRet == -1)
                    goto ERROR1;


                // 将种记录数据从XML格式转换为HTML格式
                KeyValueCollection result_params = null;

                // 2006/11/28 changed
                string strFilterFileName = strLocalPath;    // app.CfgDir + "\\biblio.fltx";
                nRet = app.ConvertBiblioXmlToHtml(
                        strFilterFileName,
                        strBiblioXml,
                        this.RecPath,
                        out strBiblio,
                        out result_params,
                        out strError);
                if (nRet == -1)
                    goto ERROR1;

                // TODO: Render的时候设置,已经晚了半拍
                // 要想办法在全部Render前得到题名和进行设置
                if (this.AutoSetPageTitle == true
                    && result_params != null && result_params.Count > 0)
                {
                    string strTitle = result_params["title"].Value;
                    if (string.IsNullOrEmpty(strTitle) == false)
                        this.Page.Title = strTitle;

                    bool bHasDC = false;
                    // 探测一下,是否有至少一个DC.开头的 key ?
                    foreach (KeyValue item in result_params)
                    {
                        if (StringUtil.HasHead(item.Key, "DC.") == true)
                        {
                            bHasDC = true;
                            break;
                        }
                    }

                    if (bHasDC == true)
                    {
                        // <header profile="http://dublincore.org/documents/2008/08/04/dc-html/">
                        this.Page.Header.Attributes.Add("profile", "http://dublincore.org/documents/2008/08/04/dc-html/");

                        // DC rel
                        // 
                        HtmlLink link = new HtmlLink();
                        link.Href = "http://purl.org/dc/elements/1.1/";
                        link.Attributes.Add("rel", "schema.DC");
                        this.Page.Header.Controls.Add(link);

                        // <link rel="schema.DCTERMS" href="http://purl.org/dc/terms/" >
                        link = new HtmlLink();
                        link.Href = "http://purl.org/dc/terms/";
                        link.Attributes.Add("rel", "schema.DCTERMS");
                        this.Page.Header.Controls.Add(link);

                        foreach (KeyValue item in result_params)
                        {
                            if (StringUtil.HasHead(item.Key, "DC.") == false
                                && StringUtil.HasHead(item.Key, "DCTERMS.") == false)
                                continue;
                            HtmlMeta meta = new HtmlMeta();
                            meta.Name = item.Key;
                            meta.Content = item.Value;
                            if (StringUtil.HasHead(item.Value, "urn:") == true
                                || StringUtil.HasHead(item.Value, "http:") == true
                                || StringUtil.HasHead(item.Value, "info:") == true
                                )
                                meta.Attributes.Add("scheme", "DCTERMS.URI");

                            this.Page.Header.Controls.Add(meta);
                        }
                    }
                }

                /*
                string strPrefix = "";
                if (this.Wrapper == true)
                    strPrefix = this.GetPrefixString("书目信息", "content_wrapper")
                        + "<div class='biblio_wrapper'>";

                string strPostfix = "";
                if (this.Wrapper == true)
                    strPostfix = "</div>" + this.GetPostfixString();
                 * */


                /*
                LiteralControl literal = (LiteralControl)FindControl("biblio");
                literal.Text = strPrefix + strBiblio + strPostfix;
                 * */

                // strBiblio = strPrefix + strBiblio + strPostfix;

                this.m_strOpacBiblio = strBiblio;
            }


            return 0;
        ERROR1:
            return -1;
        }
Пример #4
0
    protected void BiblioSearchControl1_Search(object sender, DigitalPlatform.OPAC.Web.SearchEventArgs e)
    {
        if (WebUtil.PrepareEnvironment(this,
ref app,
ref sessioninfo) == false)
            return;

        string strError = "";

        string strResultSetNamePrefix = Session.SessionID + "_opac_base";  //  "opac_base";

        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,
                e.QueryXml,
                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 = e.QueryXml;
                log.Time = DateTime.UtcNow;
                log.HitCount = (int)lRet;
                log.Format = "searchcount";
                app.SearchLog.AddLogItem(log);
            }

            // not found
            if (lRet == 0)
            {
                this.BrowseSearchResultControl1.Visible = false;
#if FITLER
                this.filter.Visible = false;
#endif

                strError = "没有找到";
                goto ERROR1;
            }

            e.ErrorInfo = string.Format(
                this.BiblioSearchControl1.GetString("hit_records_number"),
                lRet.ToString());
            // e.ErrorInfo = "命中记录 " +lRet.ToString()+ " 条";
            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
        }
        finally
        {
            //sessioninfo.Channel.
            channel.Idle -= new IdleEventHandler(channel_Idle);
            sessioninfo.ReturnChannel(channel);
        }
        return;
    ERROR1:
        e.ErrorInfo = strError;
        this.BrowseSearchResultControl1.ResultSetName = "";
        this.BrowseSearchResultControl1.ResultCount = 0;

#if FILTER
        this.filter.ResultSetName = "";
#endif
    }
Пример #5
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();
    }