Exemplo n.º 1
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();
    }