예제 #1
0
        public static int OutputEntities(
            Stop stop,
            LibraryChannel channel,
            string strBiblioRecPath,
            string strDbType,
            XmlTextWriter writer,
            out string strError)
        {
            strError = "";

            bool bBegin = false;

            long lPerCount = 100; // 每批获得多少个
            long lStart = 0;
            long lResultCount = 0;
            long lCount = -1;
            for (; ; )
            {
                if (stop != null && stop.State != 0)
                {
                    strError = "用户中断";
                    return -1;
                }

                EntityInfo[] entities = null;

                long lRet = 0;

                channel.Timeout = new TimeSpan(0, 5, 0);
                if (strDbType == "item")
                {
                    lRet = channel.GetEntities(
                         stop,
                         strBiblioRecPath,
                         lStart,
                         lCount,
                         "", // "onlygetpath",
                         "zh",
                         out entities,
                         out strError);
                }
                if (strDbType == "order")
                {
                    lRet = channel.GetOrders(
                         stop,
                         strBiblioRecPath,
                         lStart,
                         lCount,
                         "", // "onlygetpath",
                         "zh",
                         out entities,
                         out strError);
                }
                if (strDbType == "issue")
                {
                    lRet = channel.GetIssues(
                         stop,
                         strBiblioRecPath,
                         lStart,
                         lCount,
                         "", // "onlygetpath",
                         "zh",
                         out entities,
                         out strError);
                }
                if (strDbType == "comment")
                {
                    lRet = channel.GetComments(
                         stop,
                         strBiblioRecPath,
                         lStart,
                         lCount,
                         "", // "onlygetpath",
                         "zh",
                         out entities,
                         out strError);
                }
                if (lRet == -1)
                    return -1;

                lResultCount = lRet;

                if (lRet == 0)
                    return 0;

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

                foreach (EntityInfo info in entities)
                {
                    if (info.ErrorCode != ErrorCodeValue.NoError)
                    {
                        strError = "路径为 '" + info.OldRecPath + "' 的册记录装载中发生错误: " + info.ErrorInfo;  // NewRecPath
                        return -1;
                    }

                    if (bBegin == false)
                    {
                        writer.WriteStartElement("dprms", strDbType + "Collection", DpNs.dprms);
                        bBegin = true;
                    }

                    XmlDocument item_dom = new XmlDocument();
                    item_dom.LoadXml(info.OldRecord);

                    writer.WriteStartElement("dprms", strDbType, DpNs.dprms);
                    writer.WriteAttributeString("path", info.OldRecPath);
                    writer.WriteAttributeString("timestamp", ByteArray.GetHexTimeStampString(info.OldTimestamp));
                    DomUtil.RemoveEmptyElements(item_dom.DocumentElement);
                    item_dom.DocumentElement.WriteContentTo(writer);
                    writer.WriteEndElement();
                }

                lStart += entities.Length;
                if (lStart >= lResultCount)
                    break;

                if (lCount == -1)
                    lCount = lPerCount;

                if (lStart + lCount > lResultCount)
                    lCount = lResultCount - lStart;
            }

            if (bBegin == true)
                writer.WriteEndElement();

            return 1;
        }