Example #1
0
        void DoItems(List<string> item_xmls, ProcessInfo info)
        {
            string strError = "";

            List<EntityInfo> entityArray = new List<EntityInfo>();
            string strRootElementName = "";

            foreach (string xml in item_xmls)
            {
                if (string.IsNullOrEmpty(xml))
                    continue;
                XmlDocument item_dom = new XmlDocument();
                item_dom.LoadXml(xml);

                strRootElementName = item_dom.DocumentElement.LocalName;

                string strPath = item_dom.DocumentElement.GetAttribute("path");
                string strTimestamp = item_dom.DocumentElement.GetAttribute("timestamp");

                EntityInfo item = new EntityInfo();

                string strRefID = DomUtil.GetElementText(item_dom.DocumentElement, "refID");

                if (strRootElementName == "item")
                {
                    RefreshRefID(info.ItemRefIDTable, ref strRefID);
                }
                else if (strRootElementName == "order")
                {
                    RefreshRefID(info.OrderRefIDTable, ref strRefID);

                    // 记录中 distribute 元素中的 refid 要被替换
                    string strDistribute = DomUtil.GetElementText(item_dom.DocumentElement, "distribute");
                    if (string.IsNullOrEmpty(strDistribute) == false)
                    {
                        LocationCollection collection = new LocationCollection();
                        int nRet = collection.Build(strDistribute, out strError);
                        if (nRet != -1)
                        {
                            collection.RefreshRefIDs(ref info.ItemRefIDTable);
                        }
                        string strNewDistribute = collection.ToString();
                        if (strNewDistribute != strDistribute)
                        {
                            DomUtil.SetElementText(item_dom.DocumentElement, "distribute", strNewDistribute);
                        }
                    }
                }
                else
                {
                    RefreshRefID(null, ref strRefID);
                }

                item.RefID = strRefID;
                DomUtil.SetElementText(item_dom.DocumentElement, "refID", strRefID);

                DomUtil.SetElementText(item_dom.DocumentElement,
                    "parent", Global.GetRecordID(info.BiblioRecPath));

                string strXml = item_dom.DocumentElement.OuterXml;

                item.Action = "new";

                item.NewRecord = strXml;
                item.NewTimestamp = ByteArray.GetTimeStampByteArray(strTimestamp);

                item.OldRecord = "";
                item.OldTimestamp = null;

                entityArray.Add(item);
            }

            info.stop.SetMessage("正在为书目记录 '" + info.BiblioRecPath + "' 上传 "+info.UploadedSubItems+"+" + entityArray.Count + " 个下属 " + strRootElementName + " 记录 ...");

            info.UploadedSubItems += entityArray.Count;

            EntityInfo[] errorinfos = null;

            long lRet = 0;

            if (strRootElementName == "item")
                lRet = info.Channel.SetEntities(
                     info.stop,
                     info.BiblioRecPath,
                     entityArray.ToArray(),
                     out errorinfos,
                     out strError);
            else if (strRootElementName == "order")
                lRet = info.Channel.SetOrders(
                     info.stop,
                     info.BiblioRecPath,
                     entityArray.ToArray(),
                     out errorinfos,
                     out strError);
            else if (strRootElementName == "issue")
                lRet = info.Channel.SetIssues(
                     info.stop,
                     info.BiblioRecPath,
                     entityArray.ToArray(),
                     out errorinfos,
                     out strError);
            else if (strRootElementName == "comment")
                lRet = info.Channel.SetComments(
                     info.stop,
                     info.BiblioRecPath,
                     entityArray.ToArray(),
                     out errorinfos,
                     out strError);
            else
            {
                strError = "未知的 strRootElementName '" + strRootElementName + "'";
                throw new Exception(strError);
            }
            if (lRet == -1)
                throw new Exception(strError);

            if (errorinfos == null || errorinfos.Length == 0)
                return;

            StringBuilder text = new StringBuilder();
            foreach (EntityInfo error in errorinfos)
            {
                if (String.IsNullOrEmpty(error.RefID) == true)
                    throw new Exception("服务器返回的EntityInfo结构中RefID为空");

                // 正常信息处理
                if (error.ErrorCode == ErrorCodeValue.NoError)
                    continue;

                text.Append(error.RefID + "在提交保存过程中发生错误 -- " + error.ErrorInfo + "\r\n");
                info.ItemErrorCount++;
            }

            if (text.Length > 0)
            {
                strError = "在为书目记录 '" + info.BiblioRecPath + "' 导入下属 '" + strRootElementName + "' 记录的阶段出现错误:\r\n" + text.ToString();

                this.OutputText(strError, 2);

                // 询问是否忽略错误继续向后处理? 此后全部忽略?
                if (AskContinue(info, strError) == false)
                    throw new Exception(strError);
            }
        }