Beispiel #1
0
 public WorkerForm(MainForm mf)
 {
     MForm = mf;
     setProgressD = new SetProgress(OutputProgress);
     InitializeComponent();
 }
Beispiel #2
0
        // TODO: 如何中断长操作?
        // parameters:
        //      strFacetDefXml   分面特性定义XML片断
        //      nMaxRecords     处理的最多记录数。如果 == -1,表示不限制
        public static int DoFilter(
            OpacApplication app,
            LibraryChannel channel,
            string strResultsetName,
            string strFilterFileName,
            int nMaxRecords,
            SetProgress setprogress,
            ref Hashtable result_table,
            out long lOuputHitCount,
            // out string strFacetDefXml,
            out string strError)
        {
            strError       = "";
            lOuputHitCount = 0;
            long lRet = 0;
            int  nRet = 0;

            // strFacetDefXml = "";

            if (result_table == null)
            {
                result_table = new Hashtable();
            }

            FilterHost host = new FilterHost();

            LoanFilterDocument filter = null;

            nRet = app.PrepareMarcFilter(
                host,
                strFilterFileName,
                out filter,
                out strError);
            if (nRet == -1)
            {
                goto ERROR1;
            }

            try
            {
                /*
                 * XmlNode node = filter.Dom.DocumentElement.SelectSingleNode("facetDef");
                 * if (node != null)
                 * {
                 *  strFacetDefXml = node.OuterXml;
                 * }
                 * */

                long lStart = 0;

                // int nCount = 0;
                for (; ;)
                {
                    Record[] records = null;
                    // return:
                    //      -1  出错
                    //      >=0 结果集内记录的总数(注意,并不是本批返回的记录数)
                    lRet = channel.GetSearchResult(
                        null,
                        "#" + strResultsetName,
                        lStart,
                        100,
                        "id,xml",
                        "zh",
                        out records,
                        out strError);
                    if (lRet == -1)
                    {
                        return(-1);
                    }

                    lOuputHitCount = lRet;
                    long lCount = lRet;

                    if (nMaxRecords != -1)
                    {
                        lCount = Math.Min(lCount, nMaxRecords);
                    }

                    if (setprogress != null)
                    {
                        setprogress(lCount, lStart);
                    }

                    foreach (Record record in records)
                    {
                        // 2014/12/21
                        if (string.IsNullOrEmpty(record.RecordBody.Xml) == true)
                        {
                            continue;
                        }

                        // 如果必要,转换为MARC格式,调用filter
                        string strOutMarcSyntax = "";
                        string strMarc          = "";
                        // 将MARCXML格式的xml记录转换为marc机内格式字符串
                        // parameters:
                        //		bWarning	==true, 警告后继续转换,不严格对待错误; = false, 非常严格对待错误,遇到错误后不继续转换
                        //		strMarcSyntax	指示marc语法,如果=="",则自动识别
                        //		strOutMarcSyntax	out参数,返回marc,如果strMarcSyntax == "",返回找到marc语法,否则返回与输入参数strMarcSyntax相同的值
                        nRet = MarcUtil.Xml2Marc(record.RecordBody.Xml,
                                                 true,
                                                 "", // this.CurMarcSyntax,
                                                 out strOutMarcSyntax,
                                                 out strMarc,
                                                 out strError);
                        if (nRet == -1)
                        {
                            strError = "转换书目记录 " + record.Path + " 的 XML 格式到 MARC 时出错: " + strError;
                            goto ERROR1;
                        }

                        host.RecPath      = record.Path;
                        host.App          = app;
                        host.ResultParams = new KeyValueCollection();

                        nRet = filter.DoRecord(null,
                                               strMarc,
                                               strOutMarcSyntax,
                                               0,
                                               out strError);
                        if (nRet == -1)
                        {
                            goto ERROR1;
                        }

                        nRet = AddItems(ref result_table,
                                        host.ResultParams,
                                        record.Path,
                                        out strError);
                        if (nRet == -1)
                        {
                            return(-1);
                        }
                    }

                    if (records.Length <= 0  // < 100
                        )
                    {
                        break;
                    }

                    lStart += records.Length;
                    // nCount += records.Length;

                    if (lStart >= lCount)
                    {
                        if (setprogress != null)
                        {
                            setprogress(lCount, lCount);
                        }

                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                strError = "filter.DoRecord error: " + ExceptionUtil.GetDebugText(ex);
                return(-1);
            }
            finally
            {
                // 归还对象
                filter.FilterHost = null;   // 2016/1/23
                app.Filters.SetFilter(strFilterFileName, filter);
            }

            return(0);

ERROR1:
            return(-1);
        }
 private void ReportProgress(int progressPercentage)
 {
     SetProgress sp = new SetProgress(this._setProgress);
     this.Invoke(sp, progressPercentage);
 }
Beispiel #4
0
        public static async Task <String> GetFellowUrls(String psnPath, SetProgressStart setProgressStart, SetProgress setProgress, SetProgressFinish setProgressFinish)
        {
            if (Regex.IsMatch(psnPath, "_[0-1]?[0-9].pkg", RegexOptions.IgnoreCase))
            {
                setProgressStart();
                psnPath = await Task <String> .Factory.StartNew(() =>
                {
                    StringBuilder sb = new StringBuilder();
                    Int32 i          = 0;
                    while (true)
                    {
                        String newPath = Regex.Replace(psnPath, "_[0-1]?[0-9].pkg", $"_{i}.pkg");
                        Application.Current.Dispatcher.Invoke((Action) delegate
                        {
                            setProgress(new Uri(newPath).Segments.Last());
                        });

                        if (IsNetworkLastFilet(newPath))
                        {
                            break;
                        }
                        else
                        {
                            sb.AppendLine(newPath);
                            i++;
                        }
                    }

                    Application.Current.Dispatcher.Invoke((Action) delegate
                    {
                        setProgressFinish();
                    });
                    return(sb.ToString());
                });
            }
            return(psnPath);
        }