Exemple #1
0
        /// <summary>
        /// 刷新浏览行
        /// </summary>
        /// <param name="items_param">要刷新的 ListViewItem 集合</param>
        /// <param name="strFormat">浏览格式。供调用 GetSearchResult() 时 strStyle 参数之用 </param>
        /// <param name="bBeginLoop">是否要调用 stop.BeginLoop() </param>
        /// <param name="bClearRestColumns">是否清除右侧多余的列内容</param>
        /// <param name="strError">返回出错信息</param>
        /// <returns>-1: 出错; 0: 成功</returns>
        public int RefreshListViewLines(List<ListViewItem> items_param,
            string strFormat,
            bool bBeginLoop,
            bool bClearRestColumns,
            out string strError)
        {
            strError = "";

            if (items_param.Count == 0)
                return 0;

            if (stop != null && bBeginLoop == true)
            {
                stop.Style = StopStyle.EnableHalfStop;
                stop.OnStop += new StopEventHandler(this.DoStop);
                stop.Initial("正在刷新浏览行 ...");
                stop.BeginLoop();

                this.EnableControls(false);
            }

            try
            {
                List<ListViewItem> items = new List<ListViewItem>();
                List<string> recpaths = new List<string>();
                foreach (ListViewItem item in items_param)
                {
                    if (string.IsNullOrEmpty(item.Text) == true)
                        continue;
                    items.Add(item);
                    recpaths.Add(item.Text);

                    ClearOneChange(item, true);
                }

                if (stop != null)
                    stop.SetProgressRange(0, items.Count);

                BrowseLoader loader = new BrowseLoader();
                loader.Channel = Channel;
                loader.Stop = stop;
                loader.RecPaths = recpaths;
                if (string.IsNullOrEmpty(strFormat) == true)
                    loader.Format = "id,cols";
                else
                    loader.Format = strFormat;

                int i = 0;
                foreach (DigitalPlatform.CirculationClient.localhost.Record record in loader)
                {
                    Application.DoEvents();	// 出让界面控制权

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

                    Debug.Assert(record.Path == recpaths[i], "");

                    if (stop != null)
                    {
                        stop.SetMessage("正在刷新浏览行 " + record.Path + " ...");
                        stop.SetProgressValue(i);
                    }

                    ListViewItem item = items[i];

#if NO
                    if (record.Cols == null)
                    {
                        int c = 0;
                        foreach (ListViewItem.ListViewSubItem subitem in item.SubItems)
                        {
                            if (c != 0)
                                subitem.Text = "";
                            c++;
                        }
                    }
                    else
                    {
                        for (int c = 0; c < record.Cols.Length; c++)
                        {
                            ListViewUtil.ChangeItemText(item,
                            c + 1,
                            record.Cols[c]);
                        }

                        // TODO: 是否清除余下的列内容?
                    }
#endif
                    RefreshOneLine(item, record.Cols, bClearRestColumns);

                    i++;
                }

                return 0;
            }
            catch (Exception ex)
            {
                strError = ex.Message;
                return -1;
            }
            finally
            {
                if (stop != null && bBeginLoop == true)
                {
                    stop.EndLoop();
                    stop.OnStop -= new StopEventHandler(this.DoStop);
                    stop.Initial("");
                    stop.HideProgress();
                    stop.Style = StopStyle.None;

                    this.EnableControls(true);
                }
            }
        }
Exemple #2
0
        // 将书目记录中的对象资源写入外部文件
        public static int WriteObjectFiles(Stop stop,
            LibraryChannel channel,
            string strBiblioRecPath,
            ref XmlDocument biblio_dom,
            string strOutputDir,
            out string strError)
        {
            strError = "";

            List<string> recpaths = new List<string>();
            List<string> errors = new List<string>();

            XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable());
            nsmgr.AddNamespace("dprms", DpNs.dprms);

            XmlNodeList nodes = biblio_dom.DocumentElement.SelectNodes("//dprms:file", nsmgr);

            foreach (XmlElement node in nodes)
            {
                string strID = DomUtil.GetAttr(node, "id");
                string strUsage = DomUtil.GetAttr(node, "usage");
                string strRights = DomUtil.GetAttr(node, "rights");

                string strResPath = strBiblioRecPath + "/object/" + strID;
                strResPath = strResPath.Replace(":", "/");
                recpaths.Add(strResPath);
            }

            try
            {
                BrowseLoader loader = new BrowseLoader();
                loader.Channel = channel;
                loader.Stop = stop;
                loader.RecPaths = recpaths;
                loader.Format = "id,metadata,timestamp";

                int i = 0;
                foreach (DigitalPlatform.LibraryClient.localhost.Record record in loader)
                {
                    Application.DoEvents();

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

                    Debug.Assert(record.Path == recpaths[i], "");
                    XmlElement file = nodes[i] as XmlElement;

                    if (record.RecordBody.Result != null
                        && record.RecordBody.Result.ErrorCode != ErrorCodeValue.NoError)
                    {
                        if (record.RecordBody.Result.ErrorCode == ErrorCodeValue.NotFound)
                            goto CONTINUE;
                        strError = record.RecordBody.Result.ErrorString;
                        file.SetAttribute("_error", strError);
                        errors.Add(strError);
                        goto CONTINUE;
                    }

                    string strMetadataXml = record.RecordBody.Metadata;
                    byte[] baMetadataTimestamp = record.RecordBody.Timestamp;

                    file.SetAttribute("_timestamp", ByteArray.GetHexTimeStampString(baMetadataTimestamp));

                    // TODO: 另一种方法是用 URL 数据库名 ObjectID 等共同构造一个文件名
                    string strGUID = Guid.NewGuid().ToString();
                    string strMetadataFileName = Path.Combine(strOutputDir, strGUID + ".met");
                    string strObjectFileName = Path.Combine(strOutputDir, strGUID + ".bin");

                    // metadata 写入外部文件
                    if (string.IsNullOrEmpty(strMetadataXml) == false)
                    {
                        PathUtil.CreateDirIfNeed(Path.GetDirectoryName(strMetadataFileName));
                        using (StreamWriter sw = new StreamWriter(strMetadataFileName))
                        {
                            sw.Write(strMetadataXml);
                        }
                    }

                    file.SetAttribute("_metadataFile", Path.GetFileName(strMetadataFileName));

                    // 对象内容写入外部文件
                    int nRet = DownloadObject(stop,
            channel,
            record.Path,
            strObjectFileName,
            out strError);
                    if (nRet == -1)
                    {
                        // TODO: 是否要重试几次?
                        file.SetAttribute("error", strError);
                        errors.Add(strError);
                        goto CONTINUE;
                    }

                    file.SetAttribute("_objectFile", Path.GetFileName(strObjectFileName));

#if NO
                    // 取metadata值
                    Hashtable values = StringUtil.ParseMedaDataXml(strMetadataXml,
                        out strError);
                    if (values == null)
                    {
                        file.SetAttribute("error", strError);
                        errors.Add(strError);
                        continue;
                    }

                    // metadata 中的一些属性,写入 file 元素属性? _ 打头
                    // localpath
                    ListViewUtil.ChangeItemText(item, COLUMN_LOCALPATH, (string)values["localpath"]);

                    // size
                    ListViewUtil.ChangeItemText(item, COLUMN_SIZE, (string)values["size"]);

                    // mime
                    ListViewUtil.ChangeItemText(item, COLUMN_MIME, (string)values["mimetype"]);

                    // tiemstamp
                    string strTimestamp = ByteArray.GetHexTimeStampString(baMetadataTimestamp);
                    ListViewUtil.ChangeItemText(item, COLUMN_TIMESTAMP, strTimestamp);
#endif

                CONTINUE:
                    i++;
                }

                if (errors.Count > 0)
                {
                    strError = StringUtil.MakePathList(errors, "; ");
                    return -1;
                }

                return 0;
            }
            catch (Exception ex)
            {
                // TODO: 出现异常后,是否改为用原来的方法一个一个对象地获取 metadata?
                strError = ex.Message;
                return -1;
            }
        }
Exemple #3
0
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="channel">通讯通道</param>
        /// <param name="stop">停止对象</param>
        /// <param name="items">ListViewItem 数组</param>
        /// <param name="cacheTable">用于缓存的 Hashtable</param>
        public ListViewPatronLoader(LibraryChannel channel,
            Stop stop,
            List<ListViewItem> items,
            Hashtable cacheTable)
        {
            m_loader = new BrowseLoader();
            m_loader.Channel = channel;
            m_loader.Stop = stop;
            m_loader.Format = "id,xml,timestamp";
            // m_loader.GetBiblioInfoStyle = GetBiblioInfoStyle.Timestamp; // 附加信息只取得 timestamp

            this.Items = items;
            this.CacheTable = cacheTable;
        }
Exemple #4
0
        /// <summary>
        /// 刷新浏览行
        /// </summary>
        /// <param name="items_param">要刷新的 ListViewItem 集合</param>
        /// <param name="strError">返回出错信息</param>
        /// <returns>-1: 出错; 0: 成功</returns>
        public int RefreshListViewLines(List<ListViewItem> items_param,
            out string strError)
        {
            strError = "";

            if (items_param.Count == 0)
                return 0;

            LibraryChannel channel = this.GetChannel();

            stop.Style = StopStyle.EnableHalfStop;
            stop.OnStop += new StopEventHandler(this.DoStop);
            stop.Initial("正在刷新浏览行 ...");
            stop.BeginLoop();

            this.EnableControls(false);
            try
            {
                List<ListViewItem> items = new List<ListViewItem>();
                List<string> recpaths = new List<string>();
                foreach (ListViewItem item in items_param)
                {
                    if (string.IsNullOrEmpty(item.Text) == true)
                        continue;
                    items.Add(item);
                    recpaths.Add(item.Text);

                    ClearOneChange(item, true);
                }

                if (stop != null)
                    stop.SetProgressRange(0, items.Count);

                BrowseLoader loader = new BrowseLoader();
                loader.Channel = channel;
                loader.Stop = stop;
                loader.RecPaths = recpaths;
                loader.Format = "id,cols";

                int i = 0;
                foreach (DigitalPlatform.LibraryClient.localhost.Record record in loader)
                {
                    Application.DoEvents();	// 出让界面控制权

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

                    Debug.Assert(record.Path == recpaths[i], "");

                    if (stop != null)
                    {
                        stop.SetMessage("正在刷新浏览行 " + record.Path + " ...");
                        stop.SetProgressValue(i);
                    }

                    // TODO: 注意处理好 record.RecordBody.Result 带有出错信息的情形

                    ListViewItem item = items[i];
                    if (record.Cols == null)
                    {
                        int c = 0;
                        foreach (ListViewItem.ListViewSubItem subitem in item.SubItems)
                        {
                            if (c != 0)
                                subitem.Text = "";
                            c++;
                        }
                    }
                    else
                    {
                        for (int c = 0; c < record.Cols.Length; c++)
                        {
                            ListViewUtil.ChangeItemText(item,
                            c + 1,
                            record.Cols[c]);
                        }

                        // TODO: 是否清除余下的列内容?
                    }


                    i++;
                }

                return 0;
            }
            catch (Exception ex)
            {
                strError = "BiblioSearchForm RefreshListViewLines() exception: " + ExceptionUtil.GetAutoText(ex);
                return -1;
            }
            finally
            {
                stop.EndLoop();
                stop.OnStop -= new StopEventHandler(this.DoStop);
                stop.Initial("");
                stop.HideProgress();
                stop.Style = StopStyle.None;

                this.ReturnChannel(channel);

                this.EnableControls(true);
            }
        }
Exemple #5
0
        /// <summary>
        /// 刷新浏览行
        /// </summary>
        /// <param name="items_param">要刷新的 ListViewItem 集合</param>
        /// <param name="strFormat">浏览格式。供调用 GetSearchResult() 时 strStyle 参数之用 </param>
        /// <param name="bBeginLoop">是否要调用 stop.BeginLoop() </param>
        /// <param name="bClearRestColumns">是否清除右侧多余的列内容</param>
        /// <param name="strError">返回出错信息</param>
        /// <returns>-1: 出错; 0: 成功</returns>
        public int RefreshListViewLines(List<ListViewItem> items_param,
            string strFormat,
            bool bBeginLoop,
            bool bClearRestColumns,
            out string strError)
        {
            strError = "";

            if (items_param.Count == 0)
                return 0;

            if (stop != null && bBeginLoop == true)
            {
                stop.Style = StopStyle.EnableHalfStop;
                stop.OnStop += new StopEventHandler(this.DoStop);
                stop.Initial("正在刷新浏览行 ...");
                stop.BeginLoop();

                this.EnableControls(false);
            }

            try
            {
                List<ListViewItem> items = new List<ListViewItem>();
                List<string> recpaths = new List<string>();
                foreach (ListViewItem item in items_param)
                {
                    if (string.IsNullOrEmpty(item.Text) == true)
                        continue;
                    items.Add(item);
                    recpaths.Add(item.Text);

                    // TODO: 对出错状态的行不要清除修改状态
                    ClearOneChange(item, true);
                }

                if (stop != null)
                    stop.SetProgressRange(0, items.Count);

                BrowseLoader loader = new BrowseLoader();
                loader.Channel = Channel;
                loader.Stop = stop;
                loader.RecPaths = recpaths;
                if (string.IsNullOrEmpty(strFormat) == true)
                    loader.Format = "id,cols";
                else
                    loader.Format = strFormat;

                int i = 0;
                foreach (DigitalPlatform.LibraryClient.localhost.Record record in loader)
                {
                    Application.DoEvents();	// 出让界面控制权

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

                    Debug.Assert(record.Path == recpaths[i], "");

                    if (stop != null)
                    {
                        stop.SetMessage("正在刷新浏览行 " + record.Path + " ...");
                        stop.SetProgressValue(i);
                    }

                    ListViewItem item = items[i];

                    // TODO: 注意保护好事项的背景色?
                    // TODO: 注意处理好 record.RecordBody.Result 带有出错信息的情形
                    RefreshOneLine(item, record.Cols, bClearRestColumns);

                    i++;
                }

                return 0;
            }
            catch (Exception ex)
            {
                strError = "SearchFormBase RefreshListViewLines() {6BB2AEC9-B53F-4745-A655-AA9B286554B8} exception: " + ExceptionUtil.GetAutoText(ex);
                return -1;
            }
            finally
            {
                if (stop != null && bBeginLoop == true)
                {
                    stop.EndLoop();
                    stop.OnStop -= new StopEventHandler(this.DoStop);
                    stop.Initial("");
                    stop.HideProgress();
                    stop.Style = StopStyle.None;

                    this.EnableControls(true);
                }
            }
        }