예제 #1
0
파일: MainForm.cs 프로젝트: renyh1013/dp2
        // 准备脚本环境
        int PrepareScript(string strProjectName,
            string strProjectLocate,
            out Assembly assemblyMain,
            out MyFilterDocument filter,
            out Batch batchObj,
            out string strError)
        {
            assemblyMain = null;
            Assembly assemblyFilter = null;
            filter = null;
            batchObj = null;

            string strWarning = "";
            string strMainCsDllName = strProjectLocate + "\\~main_" + Convert.ToString(m_nAssemblyVersion++) + ".dll";

            string strLibPaths = "\"" + this.DataDir + "\""
                + ","
                + "\"" + strProjectLocate + "\"";

            string[] saAddRef = {
									Environment.CurrentDirectory + "\\digitalplatform.marcdom.dll",
									Environment.CurrentDirectory + "\\digitalplatform.marckernel.dll",
									Environment.CurrentDirectory + "\\digitalplatform.rms.Client.dll",
									Environment.CurrentDirectory + "\\digitalplatform.library.dll",
									// Environment.CurrentDirectory + "\\digitalplatform.statis.dll",
									Environment.CurrentDirectory + "\\digitalplatform.dll",
									Environment.CurrentDirectory + "\\digitalplatform.Text.dll",
									Environment.CurrentDirectory + "\\digitalplatform.IO.dll",
									Environment.CurrentDirectory + "\\digitalplatform.Xml.dll",
									Environment.CurrentDirectory + "\\Interop.SHDocVw.dll",
									Environment.CurrentDirectory + "\\dp2batch.exe"};


            // 创建Project中Script main.cs的Assembly
            // return:
            //		-2	出错,但是已经提示过错误信息了。
            //		-1	出错
            int nRet = scriptManager.BuildAssembly(
                "MainForm",
                strProjectName,
                "main.cs",
                saAddRef,
                strLibPaths,
                strMainCsDllName,
                out strError,
                out strWarning);
            if (nRet == -2)
                goto ERROR1;
            if (nRet == -1)
            {
                if (strWarning == "")
                    goto ERROR1;
                MessageBox.Show(this, strWarning);
            }

            assemblyMain = Assembly.LoadFrom(strMainCsDllName);
            if (assemblyMain == null)
            {
                strError = "LoadFrom " + strMainCsDllName + " fail";
                goto ERROR1;
            }


            // 得到Assembly中Batch派生类Type
            Type entryClassType = ScriptManager.GetDerivedClassType(
                assemblyMain,
                "dp2Batch.Batch");

            // new一个Batch派生对象
            batchObj = (Batch)entryClassType.InvokeMember(null,
                BindingFlags.DeclaredOnly |
                BindingFlags.Public | BindingFlags.NonPublic |
                BindingFlags.Instance | BindingFlags.CreateInstance, null, null,
                null);

            // 为Batch派生类设置参数
            batchObj.MainForm = this;
            batchObj.ap = this.AppInfo;
            batchObj.ProjectDir = strProjectLocate;
            batchObj.DbPath = this.textBox_dbPath.Text;
            batchObj.SearchPanel = this.SearchPanel;
            /*
            batchObj.SearchPanel.InitialStopManager(this.toolBarButton_stop,
                this.statusBar_main);
            */

            // batchObj.Channel = channel;
            //batchObj.GisIniFilePath = applicationInfo.GetString(
            //	"preference",
            //	"gisinifilepath",
            //	"");

            ////////////////////////////
            // 装载marfilter.fltx
            string strFilterFileName = strProjectLocate + "\\marcfilter.fltx";

            if (FileUtil.FileExist(strFilterFileName) == true)
            {

                filter = new MyFilterDocument();

                filter.Batch = batchObj;
                filter.strOtherDef = entryClassType.FullName + " Batch = null;";


                filter.strPreInitial = " MyFilterDocument doc = (MyFilterDocument)this.Document;\r\n";
                filter.strPreInitial += " Batch = ("
                    + entryClassType.FullName + ")doc.Batch;\r\n";

                filter.Load(strFilterFileName);

                nRet = filter.BuildScriptFile(strProjectLocate + "\\marcfilter.fltx.cs",
                    out strError);
                if (nRet == -1)
                    goto ERROR1;

                string[] saAddRef1 = {
										 Environment.CurrentDirectory + "\\digitalplatform.marcdom.dll",
										 Environment.CurrentDirectory + "\\digitalplatform.marckernel.dll",
										 Environment.CurrentDirectory + "\\digitalplatform.rms.client.dll",
										 Environment.CurrentDirectory + "\\digitalplatform.library.dll",
										 // this.DataDir + "\\digitalplatform.statis.dll",
										 Environment.CurrentDirectory + "\\digitalplatform.dll",
										 Environment.CurrentDirectory + "\\digitalplatform.Text.dll",
										 Environment.CurrentDirectory + "\\digitalplatform.IO.dll",
										 Environment.CurrentDirectory + "\\digitalplatform.Xml.dll",
										 Environment.CurrentDirectory + "\\Interop.SHDocVw.dll",
										 Environment.CurrentDirectory + "\\dp2batch.exe",
										 strMainCsDllName};

                string strfilterCsDllName = strProjectLocate + "\\~marcfilter_" + Convert.ToString(m_nAssemblyVersion++) + ".dll";

                // 创建Project中Script的Assembly
                nRet = scriptManager.BuildAssembly(
                    "MainForm",
                    strProjectName,
                    "marcfilter.fltx.cs",
                    saAddRef1,
                    strLibPaths,
                    strfilterCsDllName,
                    out strError,
                    out strWarning);
                if (nRet == -2)
                    goto ERROR1;
                if (nRet == -1)
                {
                    if (strWarning == "")
                    {
                        goto ERROR1;
                    }
                    MessageBox.Show(this, strWarning);
                }


                assemblyFilter = Assembly.LoadFrom(strfilterCsDllName);
                if (assemblyFilter == null)
                {
                    strError = "LoadFrom " + strfilterCsDllName + "fail";
                    goto ERROR1;
                }


                filter.Assembly = assemblyFilter;

            }

            return 0;

        ERROR1:
            return -1;
        }
예제 #2
0
파일: MainForm.cs 프로젝트: renyh1013/dp2
        // 输出
        void DoExport(string strProjectName,
            string strProjectLocate)
        {
            string strError = "";
            int nRet = 0;

            Assembly assemblyMain = null;
            MyFilterDocument filter = null;
            batchObj = null;
            m_nRecordCount = -1;


            // 准备脚本
            if (strProjectName != "" && strProjectName != null)
            {
                nRet = PrepareScript(strProjectName,
                    strProjectLocate,
                    out assemblyMain,
                    out filter,
                    out batchObj,
                    out strError);
                if (nRet == -1)
                    goto ERROR1;

                this.AssemblyMain = assemblyMain;
                if (filter != null)
                    this.AssemblyFilter = filter.Assembly;
                else
                    this.AssemblyFilter = null;

            }


            // 执行脚本的OnInitial()

            // 触发Script中OnInitial()代码
            // OnInitial()和OnBegin的本质区别, 在于OnInitial()适合检查和设置面板参数
            if (batchObj != null)
            {
                BatchEventArgs args = new BatchEventArgs();
                batchObj.OnInitial(this, args);
                /*
                if (args.Continue == ContinueType.SkipBeginMiddle)
                    goto END1;
                if (args.Continue == ContinueType.SkipMiddle) 
                {
                    strError = "OnInitial()中args.Continue不能使用ContinueType.SkipMiddle.应使用ContinueType.SkipBeginMiddle";
                    goto ERROR1;
                }
                */
                if (args.Continue == ContinueType.SkipAll)
                    goto END1;
            }

            string strOutputFileName = "";

            if (textBox_dbPath.Text == "")
            {
                MessageBox.Show(this, "尚未选择源库...");
                return;
            }

            string[] dbpaths = this.textBox_dbPath.Text.Split(new char[] { ';' });

            Debug.Assert(dbpaths.Length != 0, "");

            // 如果为单库输出
            if (dbpaths.Length == 1)
            {
                // 否则移到DoExportFile()函数里面去校验
                ResPath respath = new ResPath(dbpaths[0]);

                channel = this.Channels.GetChannel(respath.Url);

                string strDbName = respath.Path;

                // 校验起止号
                if (checkBox_verifyNumber.Checked == true)
                {
                    nRet = VerifyRange(channel,
                        strDbName,
                        out strError);
                    if (nRet == -1)
                        MessageBox.Show(this, strError);
                }
                else
                {
                    if (this.textBox_startNo.Text == "")
                    {
                        strError = "尚未指定起始号";
                        goto ERROR1;
                    }
                    if (this.textBox_endNo.Text == "")
                    {
                        strError = "尚未指定结束号";
                        goto ERROR1;
                    }
                }
            }
            else
            {
                // 多库输出。修改界面要素,表示针对每个库都是全库处理
                this.radioButton_all.Checked = true;
                this.textBox_startNo.Text = "1";
                this.textBox_endNo.Text = "9999999999";
            }


            SaveFileDialog dlg = null;

            if (checkBox_export_delete.Checked == true)
            {
                DialogResult result = MessageBox.Show(this,
                        "确实要(在输出的同时)删除数据库记录?\r\n\r\n---------\r\n(确定)删除 (放弃)放弃批处理",
                        "dp2batch",
                        MessageBoxButtons.OKCancel,
                        MessageBoxIcon.Question,
                        MessageBoxDefaultButton.Button2);
                if (result != DialogResult.OK)
                {
                    strError = "放弃处理...";
                    goto ERROR1;
                }

                result = MessageBox.Show(this,
                    "在删除记录的同时, 是否将记录输出到文件?\r\n\r\n--------\r\n(是)一边删除一边输出 (否)只删除不输出",
                    "dp2batch",
                    MessageBoxButtons.YesNo,
                    MessageBoxIcon.Question,
                    MessageBoxDefaultButton.Button1);
                if (result != DialogResult.Yes)
                    goto SKIPASKFILENAME;
            }


            // 获得输出文件名
            dlg = new SaveFileDialog();

            dlg.Title = "请指定要保存的备份文件名";
            dlg.CreatePrompt = false;
            dlg.OverwritePrompt = false;
            dlg.FileName = strLastOutputFileName;
            dlg.FilterIndex = nLastOutputFilterIndex;

            dlg.Filter = "备份文件 (*.dp2bak)|*.dp2bak|XML文件 (*.xml)|*.xml|ISO2709文件 (*.iso;*.mrc)|*.iso;*.mrc|All files (*.*)|*.*";

            dlg.RestoreDirectory = true;

            if (dlg.ShowDialog(this) != DialogResult.OK)
            {
                strError = "放弃处理...";
                goto ERROR1;
            }

            strLastOutputFileName = dlg.FileName;
            nLastOutputFilterIndex = dlg.FilterIndex;
            strOutputFileName = dlg.FileName;

        SKIPASKFILENAME:

            // 触发Script中OnBegin()代码
            // OnBegin()中仍然有修改MainForm面板的自由
            if (batchObj != null)
            {
                BatchEventArgs args = new BatchEventArgs();
                batchObj.OnBegin(this, args);
                /*
                if (args.Continue == ContinueType.SkipMiddle)
                    goto END1;
                if (args.Continue == ContinueType.SkipBeginMiddle)
                    goto END1;
                */
                if (args.Continue == ContinueType.SkipAll)
                    goto END1;
            }



            if (dlg == null || dlg.FilterIndex == 1)
                nRet = DoExportFile(
                    dbpaths,
                    strOutputFileName,
                    ExportFileType.BackupFile,
                    null,
                    out strError);
            else if (dlg.FilterIndex == 2)
                nRet = DoExportFile(
                    dbpaths,
                    strOutputFileName,
                    ExportFileType.XmlFile,
                    null,
                    out strError);
            else if (dlg.FilterIndex == 3)
            {
                ResPath respath = new ResPath(dbpaths[0]);

                string strMarcSyntax = "";
                // 从marcdef配置文件中获得marc格式定义
                // return:
                //		-1	出错
                //		0	没有找到
                //		1	找到
                nRet = this.SearchPanel.GetMarcSyntax(respath.FullPath,
                    out strMarcSyntax,
                    out strError);
                if (nRet == 0 || nRet == -1)
                {
                    strError = "获取数据库 '" + dbpaths[0] + "' 的MARC格式时发生错误: " + strError;
                    goto ERROR1;
                }

                // 如果多于一个数据库输出到一个文件,需要关心每个数据库的MARC格式是否相同,给与适当的警告
                if (dbpaths.Length > 1)
                {
                    string strWarning = "";
                    for (int i = 1; i < dbpaths.Length; i++)
                    {
                        ResPath current_respath = new ResPath(dbpaths[i]);

                        string strPerMarcSyntax = "";
                        // 从marcdef配置文件中获得marc格式定义
                        // return:
                        //		-1	出错
                        //		0	没有找到
                        //		1	找到
                        nRet = this.SearchPanel.GetMarcSyntax(current_respath.FullPath,
                            out strPerMarcSyntax,
                            out strError);
                        if (nRet == 0 || nRet == -1)
                        {
                            strError = "获取数据库 '" + dbpaths[i] + "' 的MARC格式时发生错误: " + strError;
                            goto ERROR1;
                        }

                        if (strPerMarcSyntax != strMarcSyntax)
                        {
                            if (String.IsNullOrEmpty(strWarning) == false)
                                strWarning += "\r\n";
                            strWarning += "数据库 '" + dbpaths[i] + "' (" + strPerMarcSyntax + ")";

                        }
                    }

                    if (String.IsNullOrEmpty(strWarning) == false)
                    {
                        strWarning = "所选择的数据库中,下列数据库的MARC格式和第一个数据库( '" + dbpaths[0] + "' (" + strMarcSyntax + "))的不同: \r\n---\r\n" + strWarning + "\r\n---\r\n\r\n如果把这些不同MARC格式的记录混合输出到一个文件中,可能会造成许多软件以后读取它时发生困难。\r\n\r\n确实要这样混合着转出到一个文件中?";
                        DialogResult result = MessageBox.Show(this,
                            strWarning,
                            "dp2batch",
                            MessageBoxButtons.YesNo,
                            MessageBoxIcon.Question,
                            MessageBoxDefaultButton.Button2);
                        if (result == DialogResult.No)
                        {
                            strError = "放弃处理...";
                            goto ERROR1;
                        }
                    }
                }

                OpenMarcFileDlg marcdlg = new OpenMarcFileDlg();
                MainForm.SetControlFont(marcdlg, this.DefaultFont);
                marcdlg.IsOutput = true;
                marcdlg.Text = "请指定要输出的 ISO2709 文件属性";
                marcdlg.FileName = strOutputFileName;
                marcdlg.MarcSyntax = strMarcSyntax;
                marcdlg.EnableMarcSyntax = false;   // 不允许用户选择marc syntax,因为这是数据库配置好了的属性 2007/8/18

                marcdlg.CrLf = this.OutputCrLf;
                marcdlg.AddG01 = this.AddG01;
                marcdlg.RemoveField998 = this.Remove998;


                this.AppInfo.LinkFormState(marcdlg, "OpenMarcFileDlg_output_state");
                marcdlg.ShowDialog(this);
                this.AppInfo.UnlinkFormState(marcdlg);


                if (marcdlg.DialogResult != DialogResult.OK)
                {
                    strError = "放弃处理...";
                    goto ERROR1;
                }

                if (marcdlg.AddG01 == true)
                {
                    MessageBox.Show(this, "您选择了在导出的ISO2709记录中加入-01字段。请注意dp2Batch在将来导入这样的ISO2709文件的时候,记录中-01字段***起不到***覆盖定位的作用。“加入-01字段”功能是为了将导出的ISO2709文件应用到dt1000系统而设计的。\r\n\r\n如果您这样做的目的是为了对dp2系统书目库中的数据进行备份,请改用.xml格式或.dp2bak格式。");
                }


                strOutputFileName = marcdlg.FileName;
                this.CurMarcSyntax = strMarcSyntax;
                this.OutputCrLf = marcdlg.CrLf;
                this.AddG01 = marcdlg.AddG01;
                this.Remove998 = marcdlg.RemoveField998;

                nRet = DoExportFile(
                    dbpaths,
                    marcdlg.FileName,
                    ExportFileType.ISO2709File,
                    marcdlg.Encoding,
                    out strError);
            }
            else
            {
                strError = "不支持的文件类型...";
                goto ERROR1;
            }

            /*
            if (nRet == 1)
                goto END2;
            */
            if (nRet == -1)
                goto ERROR1;
        END1:
            // 触发Script的OnEnd()代码
            if (batchObj != null)
            {
                BatchEventArgs args = new BatchEventArgs();
                batchObj.OnEnd(this, args);
            }

            // END2:

            this.AssemblyMain = null;
            this.AssemblyFilter = null;
            if (filter != null)
                filter.Assembly = null;
            this.MarcFilter = null;

            if (String.IsNullOrEmpty(strError) == false)
                MessageBox.Show(this, strError);
            return;

        ERROR1:
            this.AssemblyMain = null;
            this.AssemblyFilter = null;
            if (filter != null)
                filter.Assembly = null;
            this.MarcFilter = null;


            MessageBox.Show(this, strError);

        }
예제 #3
0
파일: MainForm.cs 프로젝트: renyh1013/dp2
        void DoImport(string strProjectName,
            string strProjectLocate)
        {
            string strError = "";
            int nRet = 0;

            Assembly assemblyMain = null;
            MyFilterDocument filter = null;
            this.MarcFilter = null;
            batchObj = null;
            m_nRecordCount = -1;

            // 准备脚本
            if (strProjectName != "" && strProjectName != null)
            {
                nRet = PrepareScript(strProjectName,
                    strProjectLocate,
                    out assemblyMain,
                    out filter,
                    out batchObj,
                    out strError);
                if (nRet == -1)
                    goto ERROR1;

                this.AssemblyMain = assemblyMain;
                if (filter != null)
                    this.AssemblyFilter = filter.Assembly;
                else
                    this.AssemblyFilter = null;

                this.MarcFilter = filter;
            }

            // 执行脚本的OnInitial()

            // 触发Script中OnInitial()代码
            // OnInitial()和OnBegin的本质区别, 在于OnInitial()适合检查和设置面板参数
            if (batchObj != null)
            {
                BatchEventArgs args = new BatchEventArgs();
                batchObj.OnInitial(this, args);
                /*
                if (args.Continue == ContinueType.SkipBeginMiddle)
                    goto END1;
                if (args.Continue == ContinueType.SkipMiddle) 
                {
                    strError = "OnInitial()中args.Continue不能使用ContinueType.SkipMiddle.应使用ContinueType.SkipBeginMiddle";
                    goto ERROR1;
                }
                */
                if (args.Continue == ContinueType.SkipAll)
                    goto END1;
            }


            if (this.textBox_import_fileName.Text == "")
            {
                strError = "尚未指定输入文件名...";
                goto ERROR1;
            }
            FileInfo fi = new FileInfo(this.textBox_import_fileName.Text);
            if (fi.Exists == false)
            {
                strError = "文件" + this.textBox_import_fileName.Text + "不存在...";
                goto ERROR1;
            }

            OpenMarcFileDlg dlg = null;

            // ISO2709文件需要预先准备条件
            if (String.Compare(fi.Extension, ".iso", true) == 0
                || String.Compare(fi.Extension, ".mrc", true) == 0)
            {
                // 询问encoding和marcsyntax
                dlg = new OpenMarcFileDlg();
                MainForm.SetControlFont(dlg, this.DefaultFont);

                dlg.Text = "请指定要导入的 ISO2709 文件属性";
                dlg.FileName = this.textBox_import_fileName.Text;

                this.AppInfo.LinkFormState(dlg, "OpenMarcFileDlg_input_state");
                dlg.ShowDialog(this);
                this.AppInfo.UnlinkFormState(dlg);

                if (dlg.DialogResult != DialogResult.OK)
                    return;

                this.textBox_import_fileName.Text = dlg.FileName;
                this.CurMarcSyntax = dlg.MarcSyntax;
            }

            // 触发Script中OnBegin()代码
            // OnBegin()中仍然有修改MainForm面板的自由
            if (batchObj != null)
            {
                BatchEventArgs args = new BatchEventArgs();
                batchObj.OnBegin(this, args);
                /*
                if (args.Continue == ContinueType.SkipMiddle)
                    goto END1;
                if (args.Continue == ContinueType.SkipBeginMiddle)
                    goto END1;
                */
                if (args.Continue == ContinueType.SkipAll)
                    goto END1;
            }

            if (String.Compare(fi.Extension, ".dp2bak", true) == 0)
                nRet = this.DoImportBackup(this.textBox_import_fileName.Text,
                    out strError);

            else if (String.Compare(fi.Extension, ".xml", true) == 0)
                nRet = this.DoImportXml(this.textBox_import_fileName.Text,
                    out strError);

            else if (String.Compare(fi.Extension, ".iso", true) == 0
                || String.Compare(fi.Extension, ".mrc", true) == 0)
            {
                this.m_tableMarcSyntax.Clear(); // 2015/5/29
                this.CheckTargetDb += new CheckTargetDbEventHandler(CheckTargetDbCallBack);

                try
                {
                    nRet = this.DoImportIso2709(dlg.FileName,
                        dlg.MarcSyntax,
                        dlg.Encoding,
                        out strError);
                }
                finally
                {
                    this.CheckTargetDb -= new CheckTargetDbEventHandler(CheckTargetDbCallBack);
                }

            }
            else
            {
                strError = "未知的文件类型...";
                goto ERROR1;
            }


        END1:
            // 触发Script的OnEnd()代码
            if (batchObj != null)
            {
                BatchEventArgs args = new BatchEventArgs();
                batchObj.OnEnd(this, args);
            }

            // END2:

            this.AssemblyMain = null;
            this.AssemblyFilter = null;
            if (filter != null)
                filter.Assembly = null;


            if (strError != "")
                MessageBox.Show(this, strError);

            this.MarcFilter = null;
            return;

        ERROR1:
            this.AssemblyMain = null;
            this.AssemblyFilter = null;
            if (filter != null)
                filter.Assembly = null;

            this.MarcFilter = null;

            MessageBox.Show(this, strError);
        }