Exemple #1
0
        // 根据字符串构造ListViewItem。
        // 字符串的格式为\t间隔的
        // parameters:
        //      list    可以为null。如果为null,就没有自动扩展列标题数目的功能
        public static ListViewItem BuildListViewItem(
            ListView list,
            string strLine)
        {
            ListViewItem item = new ListViewItem();

            string[] parts = strLine.Split(new char[] { '\t' });
            for (int i = 0; i < parts.Length; i++)
            {
                ListViewUtil.ChangeItemText(item, i, parts[i]);

                // 确保列标题数目够
                if (list != null)
                {
                    ListViewUtil.EnsureColumns(list, parts.Length, 100);
                }
            }

            return(item);
        }
Exemple #2
0
        /// <summary>
        /// 在 ListView 最后追加一行
        /// </summary>
        /// <param name="list">ListView 对象</param>
        /// <param name="strID">左边第一列内容</param>
        /// <param name="others">其余列内容</param>
        /// <returns>新创建的 ListViewItem 对象</returns>
        public static ListViewItem AppendNewLine(
            ListView list,
            string strID,
            string[] others)
        {
            if (others != null)
            {
                ListViewUtil.EnsureColumns(list, others.Length + 1, 100);
            }

            ListViewItem item = new ListViewItem(strID, 0);

            list.Items.Add(item);

            if (others != null)
            {
                for (int i = 0; i < others.Length; i++)
                {
                    item.SubItems.Add(others[i]);
                }
            }

            return(item);
        }
Exemple #3
0
        int GetBrowseCols(List <string> pathlist,
                          List <ListViewItem> itemlist,
                          out string strError)
        {
            strError = "";

            EnableControls(false);

            LibraryChannel channel = this.GetChannel();

            stop.OnStop += new StopEventHandler(this.DoStop);
            stop.Initial("正在填充浏览列 ...");
            stop.BeginLoop();

            this.Update();
            Program.MainForm.Update();

            try
            {
                int nStart = 0;
                int nCount = 0;
                for (; ;)
                {
                    nCount = pathlist.Count - nStart;
                    if (nCount > 100)
                    {
                        nCount = 100;
                    }
                    if (nCount <= 0)
                    {
                        break;
                    }

                    Application.DoEvents();     // 出让界面控制权

                    if (stop != null && stop.State != 0)
                    {
                        strError = "用户中断";
                        return(-1);
                    }

                    stop.SetMessage("正在装入浏览信息 " + (nStart + 1).ToString() + " - " + (nStart + nCount).ToString());

                    string[] paths = new string[nCount];
                    pathlist.CopyTo(nStart, paths, 0, nCount);

                    Record[] searchresults = null;

                    long lRet = channel.GetBrowseRecords(
                        this.stop,
                        paths,
                        "id,cols",
                        out searchresults,
                        out strError);
                    if (lRet == -1)
                    {
                        return(-1);
                    }

                    if (searchresults == null || searchresults.Length == 0)
                    {
                        strError = "searchresults == null || searchresults.Length == 0";
                        return(-1);
                    }

                    for (int i = 0; i < searchresults.Length; i++)
                    {
                        Record record = searchresults[i];

                        ListViewUtil.EnsureColumns(this.listView_browse,
                                                   2 + (record.Cols == null ? 0 : record.Cols.Length),
                                                   200);

                        ListViewItem item = itemlist[nStart + i];
                        item.Text = record.Path;
                        if (record.Cols != null)
                        {
                            for (int j = 0; j < record.Cols.Length; j++)
                            {
                                item.SubItems.Add(record.Cols[j]);
                            }
                        }
                    }

                    nStart += searchresults.Length;
                }
            }
            finally
            {
                stop.EndLoop();
                stop.OnStop -= new StopEventHandler(this.DoStop);
                stop.Initial("");

                this.ReturnChannel(channel);

                EnableControls(true);
            }

            return(0);
        }
Exemple #4
0
        // 检索
        // return:
        //      -1  error
        //      0   succeed
        /// <summary>
        /// 启动查重
        /// </summary>
        /// <param name="strProjectName">查重方案名</param>
        /// <param name="strRecPath">发起记录路径</param>
        /// <param name="strXml">发起记录的 XML</param>
        /// <param name="strUsedProjectName">返回实际使用的方案名</param>
        /// <param name="strError">返回出错信息</param>
        /// <returns>-1: 出错; >=0: 命中的记录数</returns>
        public int DoSearch(string strProjectName,
                            string strRecPath,
                            string strXml,
                            out string strUsedProjectName,
                            out string strError)
        {
            strError           = "";
            strUsedProjectName = "";

            if (strProjectName == "<默认>" ||
                strProjectName == "<default>")
            {
                strProjectName = "";
            }

            EventFinish.Reset();

            EnableControls(false);

            LibraryChannel channel     = this.GetChannel();
            TimeSpan       old_timeout = channel.Timeout;

            channel.Timeout = TimeSpan.FromMinutes(2);

            stop.OnStop += new StopEventHandler(this.DoStop);
            stop.Initial("正在进行查重 ...");
            stop.BeginLoop();

            //this.Update();
            //Program.MainForm.Update();

            try
            {
                this.ClearDupState();

                this.listView_browse.Items.Clear();
                // 2008/11/22
                this.SortColumns.Clear();
                SortColumns.ClearColumnSortDisplay(this.listView_browse.Columns);

                string strBrowseStyle = "cols";
                if (this.checkBox_includeLowCols.Checked == false)
                {
                    strBrowseStyle += ",excludecolsoflowthreshold";
                }

                long lRet = channel.SearchDup(
                    stop,
                    strRecPath,
                    strXml,
                    strProjectName,
                    "includeoriginrecord", // includeoriginrecord
                    out strUsedProjectName,
                    out strError);
                if (lRet == -1)
                {
                    goto ERROR1;
                }

                long lHitCount = lRet;

                if (lHitCount == 0)
                {
                    goto END1;   // 查重发现没有命中
                }
                if (stop != null)
                {
                    stop.SetProgressRange(0, lHitCount);
                }

                long lStart    = 0;
                long lPerCount = Math.Min(50, lHitCount);
                // 装入浏览格式
                for (; ;)
                {
                    Application.DoEvents();     // 出让界面控制权

                    if (stop != null && stop.State != 0)
                    {
                        strError = "用户中断";
                        goto ERROR1;
                    }

                    stop.SetMessage("正在装入浏览信息 " + (lStart + 1).ToString() + " - " + (lStart + lPerCount).ToString() + " (命中 " + lHitCount.ToString() + " 条记录) ...");

                    DupSearchResult[] searchresults = null;

                    lRet = channel.GetDupSearchResult(
                        stop,
                        lStart,
                        lPerCount,
                        strBrowseStyle, // "cols,excludecolsoflowthreshold",
                        out searchresults,
                        out strError);
                    if (lRet == -1)
                    {
                        goto ERROR1;
                    }

                    if (lRet == 0)
                    {
                        break;
                    }

                    Debug.Assert(searchresults != null, "");

                    // 处理浏览结果
                    for (int i = 0; i < searchresults.Length; i++)
                    {
                        DupSearchResult result = searchresults[i];

                        ListViewUtil.EnsureColumns(this.listView_browse,
                                                   2 + (result.Cols == null ? 0 : result.Cols.Length),
                                                   200);

                        if (this.checkBox_returnAllRecords.Checked == false)
                        {
                            // 遇到第一个权值较低的,就中断全部获取浏览过程
                            if (result.Weight < result.Threshold)
                            {
                                goto END1;
                            }
                        }

                        ListViewItem item = new ListViewItem();
                        item.Text = result.Path;
                        item.SubItems.Add(result.Weight.ToString());
                        if (result.Cols != null)
                        {
                            for (int j = 0; j < result.Cols.Length; j++)
                            {
                                item.SubItems.Add(result.Cols[j]);
                            }
                        }
                        this.listView_browse.Items.Add(item);

                        if (item.Text == this.RecordPath)
                        {
                            // 如果就是发起记录自己  2008/2/29
                            item.ImageIndex = ITEMTYPE_OVERTHRESHOLD;
                            item.BackColor  = Color.LightGoldenrodYellow;
                            item.ForeColor  = SystemColors.GrayText; // 表示就是发起记录自己
                        }
                        else if (result.Weight >= result.Threshold)
                        {
                            item.ImageIndex = ITEMTYPE_OVERTHRESHOLD;
                            item.BackColor  = Color.LightGoldenrodYellow;
                        }
                        else
                        {
                            item.ImageIndex = ITEMTYPE_NORMAL;
                        }

                        if (stop != null)
                        {
                            stop.SetProgressValue(lStart + i + 1);
                        }
                    }

                    lStart += searchresults.Length;
                    if (lStart >= lHitCount || lPerCount <= 0)
                    {
                        break;
                    }
                }

END1:
                this.SetDupState();

                return((int)lHitCount);
            }
            finally
            {
                stop.EndLoop();
                stop.OnStop -= new StopEventHandler(this.DoStop);
                stop.Initial("");
                stop.HideProgress();

                EventFinish.Set();

                channel.Timeout = old_timeout;
                this.ReturnChannel(channel);

                EnableControls(true);
            }


ERROR1:
            return(-1);
        }
Exemple #5
0
        // 检索
        // return:
        //      -1  error
        //      0   succeed
        public int DoSearch(string strProjectName,
                            string strRecPath,
                            string strXml,
                            out string strUsedProjectName,
                            out string strError)
        {
            strError           = "";
            strUsedProjectName = "";

            if (strProjectName == "<默认>" ||
                strProjectName == "<default>")
            {
                strProjectName = "";
            }

            EventFinish.Reset();

            EnableControls(false);

            stop.OnStop += new StopEventHandler(this.DoStop);
            stop.Initial("正在进行查重 ...");
            stop.BeginLoop();

            this.Update();
            this.MainForm.Update();

            try
            {
                this.ClearDupState(true);
                this.listView_browse.Items.Clear();

                // 获得server url
                if (String.IsNullOrEmpty(this.LibraryServerName) == true)
                {
                    strError = "尚未指定服务器名";
                    goto ERROR1;
                }
                dp2Server server = this.MainForm.Servers.GetServerByName(this.LibraryServerName);
                if (server == null)
                {
                    strError = "服务器名为 '" + this.LibraryServerName + "' 的服务器不存在...";
                    goto ERROR1;
                }

                this.SortColumns.Clear();
                SortColumns.ClearColumnSortDisplay(this.listView_browse.Columns);

                string strBrowseStyle = "cols";
                if (this.checkBox_includeLowCols.Checked == false)
                {
                    strBrowseStyle += ",excludecolsoflowthreshold";
                }

                string strServerUrl = server.Url;

                this.Channel = this.Channels.GetChannel(strServerUrl);

                long lRet = Channel.SearchDup(
                    stop,
                    strRecPath,
                    strXml,
                    strProjectName,
                    "includeoriginrecord", // includeoriginrecord
                    out strUsedProjectName,
                    out strError);
                if (lRet == -1)
                {
                    goto ERROR1;
                }

                long lHitCount = lRet;

                if (lHitCount == 0)
                {
                    goto END1;   // 查重发现没有命中
                }
                long lStart    = 0;
                long lPerCount = Math.Min(50, lHitCount);
                // 装入浏览格式
                for (; ;)
                {
                    Application.DoEvents();     // 出让界面控制权

                    if (stop != null)
                    {
                        if (stop.State != 0)
                        {
                            strError = "用户中断";
                            goto ERROR1;
                        }
                    }

                    stop.SetMessage("正在装入浏览信息 " + (lStart + 1).ToString() + " - " + (lStart + lPerCount).ToString() + " (命中 " + lHitCount.ToString() + " 条记录) ...");

                    lRet = Channel.GetDupSearchResult(
                        stop,
                        lStart,
                        lPerCount,
                        strBrowseStyle, // "cols,excludecolsoflowthreshold",
                        out DupSearchResult[] searchresults,
                        out strError);
                    if (lRet == -1)
                    {
                        goto ERROR1;
                    }

                    if (lRet == 0)
                    {
                        break;
                    }

                    Debug.Assert(searchresults != null, "");

                    // 处理浏览结果
                    for (int i = 0; i < searchresults.Length; i++)
                    {
                        DupSearchResult result = searchresults[i];

                        ListViewUtil.EnsureColumns(this.listView_browse,
                                                   2 + (result.Cols == null ? 0 : result.Cols.Length),
                                                   200);

                        if (this.checkBox_returnAllRecords.Checked == false)
                        {
                            // 遇到第一个权值较低的,就中断全部获取浏览过程
                            if (result.Weight < result.Threshold)
                            {
                                goto END1;
                            }
                        }

                        /*
                         * if (result.Cols == null)
                         * {
                         *  strError = "返回的结果行错误 result.Cols == null";
                         *  goto ERROR1;
                         * }
                         *
                         * ListViewUtil.EnsureColumns(this.listView_browse,
                         *  2 + result.Cols.Length,
                         *  200);
                         * */

                        ListViewItem item = new ListViewItem();
                        item.Text = result.Path;
                        item.Tag  = result;
                        item.SubItems.Add(result.Weight.ToString());
                        if (result.Cols != null)
                        {
                            for (int j = 0; j < result.Cols.Length; j++)
                            {
                                item.SubItems.Add(result.Cols[j]);
                            }
                        }
                        this.listView_browse.Items.Add(item);

                        if (item.Text == this.RecordPath)
                        {
                            // 如果就是发起记录自己  2008/2/29
                            item.ImageIndex = ITEMTYPE_OVERTHRESHOLD;
                            item.BackColor  = Color.LightGoldenrodYellow;
                            item.ForeColor  = SystemColors.GrayText; // 表示就是发起记录自己
                        }
                        else if (result.Weight >= result.Threshold)
                        {
                            item.ImageIndex = ITEMTYPE_OVERTHRESHOLD;
                            item.BackColor  = Color.LightYellow;
                            item.Font       = new Font(item.Font, FontStyle.Bold);
                        }
                        else
                        {
                            item.ImageIndex = ITEMTYPE_NORMAL;
                        }
                    }

                    lStart += searchresults.Length;
                    if (lStart >= lHitCount || lPerCount <= 0)
                    {
                        break;
                    }
                }

END1:
                this.SetDupState();

                return((int)lHitCount);
            }
            finally
            {
                stop.EndLoop();
                stop.OnStop -= new StopEventHandler(this.DoStop);
                stop.Initial("");

                EventFinish.Set();

                EnableControls(true);
            }


ERROR1:
            return(-1);
        }
Exemple #6
0
        int GetBrowseCols(List <string> pathlist,
                          List <ListViewItem> itemlist,
                          out string strError)
        {
            strError = "";

            // 获得server url
            if (String.IsNullOrEmpty(this.LibraryServerName) == true)
            {
                strError = "尚未指定服务器名";
                return(-1);
            }
            dp2Server server = this.MainForm.Servers.GetServerByName(this.LibraryServerName);

            if (server == null)
            {
                strError = "服务器名为 '" + this.LibraryServerName + "' 的服务器不存在...";
                return(-1);
            }

            string strServerUrl = server.Url;

            this.Channel = this.Channels.GetChannel(strServerUrl);

            EnableControls(false);

            stop.OnStop += new StopEventHandler(this.DoStop);
            stop.Initial("正在填充浏览列 ...");
            stop.BeginLoop();

            this.Update();
            this.MainForm.Update();

            try
            {
                int nStart = 0;
                int nCount = 0;
                for (; ;)
                {
                    nCount = pathlist.Count - nStart;
                    if (nCount > 100)
                    {
                        nCount = 100;
                    }
                    if (nCount <= 0)
                    {
                        break;
                    }

                    Application.DoEvents();     // 出让界面控制权

                    if (stop != null)
                    {
                        if (stop.State != 0)
                        {
                            strError = "用户中断";
                            return(-1);
                        }
                    }

                    stop.SetMessage("正在装入浏览信息 " + (nStart + 1).ToString() + " - " + (nStart + nCount).ToString());

                    string[] paths = new string[nCount];
                    pathlist.CopyTo(nStart, paths, 0, nCount);

                    DigitalPlatform.LibraryClient.localhost.Record[] searchresults = null;

                    long lRet = this.Channel.GetBrowseRecords(
                        this.stop,
                        paths,
                        "id,cols",
                        out searchresults,
                        out strError);
                    if (lRet == -1)
                    {
                        return(-1);
                    }

                    if (searchresults == null || searchresults.Length == 0)
                    {
                        strError = "searchresults == null || searchresults.Length == 0";
                        return(-1);
                    }

                    for (int i = 0; i < searchresults.Length; i++)
                    {
                        DigitalPlatform.LibraryClient.localhost.Record record = searchresults[i];

                        ListViewUtil.EnsureColumns(this.listView_browse,
                                                   2 + (record.Cols == null ? 0 : record.Cols.Length),
                                                   200);

                        ListViewItem item = itemlist[nStart + i];
                        item.Text = record.Path;
                        if (record.Cols != null)
                        {
                            for (int j = 0; j < record.Cols.Length; j++)
                            {
                                item.SubItems.Add(record.Cols[j]);
                            }
                        }
                    }


                    nStart += searchresults.Length;
                }
            }
            finally
            {
                stop.EndLoop();
                stop.OnStop -= new StopEventHandler(this.DoStop);
                stop.Initial("");

                EnableControls(true);
            }

            return(0);
        }
Exemple #7
0
        int FillBrowseList(List <string> path_list,
                           string strWeight,
                           int nThreshold,
                           out string strError)
        {
            strError = "";

            int nWeight = 0;

            try
            {
                nWeight = Convert.ToInt32(strWeight);
            }
            catch
            {
                strError = "weight字符串 '" + strWeight + "' 格式不正确,应该为纯数字";
                return(-1);
            }


            string strShorterStartRecordPath = Global.ModifyDtlpRecPath(this.RecordPath, "");

            // int nDupCount = 0;

            // 处理每条记录
            for (int i = 0; i < path_list.Count; i++)
            {
                Application.DoEvents(); // 出让界面控制权

                if (stop != null)
                {
                    if (stop.State != 0)
                    {
                        strError = "用户中断";
                        return(-1);
                    }
                }

                string strPath = path_list[i];


                // 查重
                ListViewItem item = DetectDup(strPath);

                int nCurrentWeight = 0;

                if (item == null)
                {
                    string strCompletePath = Global.ModifyDtlpRecPath(strPath,
                                                                      "ctlno");

                    item      = new ListViewItem();
                    item.Text = strPath;
                    item.SubItems.Add(strWeight);
                    this.listView_browse.Items.Add(item);

                    nCurrentWeight = nWeight;

                    string[] cols = null;

                    int nRet = GetOneBrowseRecord(
                        strCompletePath,
                        out cols,
                        out strError);
                    if (nRet == -1)
                    {
                        item.SubItems.Add(strError);
                        continue;
                    }
                    if (cols != null)
                    {
                        // 确保列标题数量足够
                        ListViewUtil.EnsureColumns(this.listView_browse,
                                                   cols.Length,
                                                   200);
                        for (int j = 0; j < cols.Length; j++)
                        {
                            item.SubItems.Add(cols[j]);
                        }
                    }
                }
                else
                {
                    // 先获得已经有的分数
                    string strExistWeight = item.SubItems[1].Text;

                    int nExistWeight = 0;
                    try
                    {
                        nExistWeight = Convert.ToInt32(strExistWeight);
                    }
                    catch
                    {
                        strError = "原有的weight字符串 '" + strExistWeight + "' 格式不正确,应该为纯数字";
                        return(-1);
                    }

                    nCurrentWeight = nExistWeight + nWeight;

                    item.SubItems[1].Text = nCurrentWeight.ToString();
                }

                if (strPath == strShorterStartRecordPath)
                {
                    // 如果就是发起记录自己  2008/2/29
                    item.ImageIndex = ITEMTYPE_OVERTHRESHOLD;
                    item.BackColor  = Color.LightGoldenrodYellow;
                    item.ForeColor  = SystemColors.GrayText; // 表示就是发起记录自己
                }
                else if (nCurrentWeight >= nThreshold)
                {
                    item.ImageIndex = ITEMTYPE_OVERTHRESHOLD;
                    item.BackColor  = Color.LightYellow;
                    item.Font       = new Font(item.Font, FontStyle.Bold);
                }
                else
                {
                    item.ImageIndex = ITEMTYPE_NORMAL;
                }

                // this.listView_browse.UpdateItem(this.listView_browse.Items.Count - 1);
            }

            return(0);
        }