Пример #1
0
        private void ChangePasswordDlg_Load(object sender, System.EventArgs e)
        {
            textBox_url.Text      = Url;
            textBox_userName.Text = UserName;
            stopManager.Initial(button_Cancel,
                                label_message,
                                null);
            stopManager.LinkReverseButton(button_OK);

            stop = new DigitalPlatform.Stop();
            stop.Register(this.stopManager, true);      // 和容器关联
        }
Пример #2
0
        private void DupForm_Load(object sender, EventArgs e)
        {
            Debug.Assert(this.dom != null, "尚未Initial()");

            stop = new DigitalPlatform.Stop();
            if (this.stopManager != null)
            {
                stop.Register(this.stopManager, true);  // 和容器关联
            }
            // 自动启动查重
            if (this.AutoBeginSearch == true)
            {
                API.PostMessage(this.Handle, WM_INITIAL, 0, 0);
            }
        }
Пример #3
0
        private void button_OK_Click(object sender, System.EventArgs e)
        {
            string strMetaData = "";

            // TODO: 一旦遇到问题,可以放开注释试验
            // this.textBox_content.Text = RemoveSingle0a(this.textBox_content.Text);


            if (this.Obj != null)
            {
                if (this.IsText == true)
                {
                    byte[] baContent = StringUtil.GetUtf8Bytes(this.textBox_content.Text, true);
                    this.Obj.Content = baContent;
                }
                else
                {
                    if (this.Stream != null)
                    {
                        this.Obj.Content = new byte[this.Stream.Length];
                        this.Stream.Seek(0, SeekOrigin.Begin);
                        this.Stream.Read(this.Obj.Content,
                                         0, (int)this.Stream.Length);
                    }
                    else
                    {
                        this.Obj.Content = null;
                    }
                }

                StringUtil.ChangeMetaData(ref strMetaData,
                                          null,           // string strID,
                                          this.LocalPath, // string strLocalPath,
                                          this.Mime,      // string strMimeType,
                                          null,           // string strLastModified,
                                          null,           // string strPath,
                                          null);          // string strTimestamp)
                this.Obj.Metadata = strMetaData;

                this.Obj.Changed = true;

                this.DialogResult = DialogResult.OK;
                this.Close();

                return;
            }

            this.channel = Channels.GetChannel(this.ServerUrl);

            Debug.Assert(channel != null, "Channels.GetChannel() 异常");

            DigitalPlatform.Stop stop = null;

            if (stopManager != null)
            {
                stop = new DigitalPlatform.Stop();

                stop.Register(this.stopManager, true);  // 和容器关联

                stop.OnStop += new StopEventHandler(this.DoStop);
                stop.Initial("正在保存配置文件: " + this.Path);

                stop.BeginLoop();
            }

            if (this.IsText == true)
            {
                // 更新stream对象内容
                byte[] baContent = StringUtil.GetUtf8Bytes(this.textBox_content.Text, true);
                this.Stream = new MemoryStream(baContent);  // !!! 什么时候释放?

                /*
                 * this.Stream.SetLength(0);
                 * StreamWriter sw = new StreamWriter(this.Stream, Encoding.UTF8);
                 * sw.Write(this.textBox_content.Text);
                 */
            }

            if (this.Stream != null)
            {
                this.Stream.Seek(0, SeekOrigin.Begin);
            }

            // 保存配置文件
            string strError = "";

            byte[] baOutputTimestamp = null;
            string strOutputPath     = "";
            string strStyle          = "";

            if (this.checkBox_autoCreate.Checked == true)
            {
                if (strStyle != "")
                {
                    strStyle += ",";
                }
                strStyle += "autocreatedir";
            }


            StringUtil.ChangeMetaData(ref strMetaData,
                                      null,           // string strID,
                                      this.LocalPath, // string strLocalPath,
                                      this.Mime,      // string strMimeType,
                                      null,           // string strLastModified,
                                      null,           // string strPath,
                                      null);          // string strTimestamp)

            string strRange = "";

            if (this.Stream != null && this.Stream.Length != 0)
            {
                Debug.Assert(this.Stream.Length != 0, "test");
                strRange = "0-" + Convert.ToString(this.Stream.Length - 1);
            }
            long lRet = channel.DoSaveResObject(this.Path,
                                                this.Stream,
                                                (this.Stream != null && this.Stream.Length != 0) ? this.Stream.Length : 0,
                                                strStyle,
                                                strMetaData, // strMetadata,
                                                strRange,
                                                true,
                                                this.TimeStamp, // timestamp,
                                                out baOutputTimestamp,
                                                out strOutputPath,
                                                out strError);

            /*
             * // 保存配置文件
             * byte[] baOutputTimeStamp = null;
             * string strOutputPath = "";
             * string strError = "";
             *
             *
             * long lRet = channel.DoSaveTextRes(this.Path,
             *  this.textBox_content.Text,
             *  true,	// bInlucdePreamble
             *  "",	// style
             *  this.TimeStamp,
             *  out baOutputTimeStamp,
             *  out strOutputPath,
             *  out strError);
             */

            if (stopManager != null)
            {
                stop.EndLoop();
                stop.OnStop -= new StopEventHandler(this.DoStop);
                stop.Initial("");
            }

            if (lRet == -1)
            {
                MessageBox.Show(this, strError);
                goto FINISH;
            }

            this.TimeStamp = baOutputTimestamp;

            MessageBox.Show(this, "配置文件 '" + this.Path + "' 保存成功");


            /////////////
FINISH:

            if (stopManager != null && stop != null)
            {
                stop.Unregister();      // 和容器关联
                stop = null;
            }

            this.channel = null;

            this.DialogResult = DialogResult.OK;
            this.Close();
        }
Пример #4
0
        private void CfgFileEditDlg_Load(object sender, System.EventArgs e)
        {
            button_export.Enabled = false;

            MemoryStream stream = null;
            string       strMetaData;
            string       strError = "";
            string       strMime  = "";

            Hashtable values = null;

            if (Obj != null)
            {
                if (this.Obj.Content != null)
                {
                    stream      = new MemoryStream(this.Obj.Content);
                    this.Stream = stream;
                    this.Stream.Seek(0, SeekOrigin.Begin);

                    button_export.Enabled = true;
                }

                this.TimeStamp = this.Obj.TimeStamp;

                strMetaData = this.Obj.Metadata;

                // 观察mime
                // 取metadata
                values = StringUtil.ParseMetaDataXml(strMetaData,
                                                     out strError);
                if (values == null)
                {
                    MessageBox.Show(this, strError);
                    return;
                }
                strMime = (string)values["mimetype"];
                if (strMime == null || strMime == "")
                {
                    strMime = "text";
                }
                this.Mime = strMime;

                this.LocalPath = (string)values["localpath"];
                if (this.LocalPath == null)
                {
                    this.LocalPath = "";
                }

                this.textBox_content.Text = "";

                // string strFirstPart = StringUtil.GetFirstPartPath(ref strMime);
                if (this.IsText == true)
                {
                    if (this.Stream != null)
                    {
                        this.Stream.Seek(0, SeekOrigin.Begin);
                        using (StreamReader sr = new StreamReader(this.Stream, Encoding.UTF8))
                        {
                            this.textBox_content.Text = ConvertCrLf(sr.ReadToEnd());
                        }
                    }
                }
                else
                {
                }

                //////

                button_OK.Enabled = false;

                this.textBox_content.SelectionStart  = 0;
                this.textBox_content.SelectionLength = 0;
                return;
            }

            this.channel = Channels.GetChannel(this.ServerUrl);
            Debug.Assert(channel != null, "Channels.GetChannel() 异常");

            DigitalPlatform.Stop stop = null;

            if (stopManager != null)
            {
                stop = new DigitalPlatform.Stop();

                stop.Register(this.stopManager, true);  // 和容器关联

                stop.OnStop += new StopEventHandler(this.DoStop);
                stop.Initial("正在下载配置文件: " + this.Path);

                stop.BeginLoop();
            }

            // string strContent = "";
            byte[] baTimeStamp = null;
            string strOutputPath;

            string strStyle = "content,data,metadata,timestamp,outputpath";

            //			string strStyle = "attachment,data,metadata,timestamp,outputpath";

            stream = new MemoryStream();

            long lRet = channel.GetRes(
                this.Path,
                stream,
                stop,   // stop,
                strStyle,
                null,   // byte [] input_timestamp,
                out strMetaData,
                out baTimeStamp,
                out strOutputPath,
                out strError);

            /*
             * long lRet = channel.GetRes((
             *  this.Path,
             *  out strContent,
             *  out strMetaData,
             *  out baTimeStamp,
             *  out strOutputPath,
             *  out strError);
             */

            if (stopManager != null)
            {
                stop.EndLoop();
                stop.OnStop -= new StopEventHandler(this.DoStop);
                stop.Initial("");
            }

            if (lRet == -1)
            {
                MessageBox.Show(this, strError);
                goto FINISH;
            }

            this.Stream = stream;
            this.Stream.Seek(0, SeekOrigin.Begin);

            button_export.Enabled = true;


            this.TimeStamp = baTimeStamp;

            // 观察mime
            // 取metadata
            values = StringUtil.ParseMetaDataXml(strMetaData,
                                                 out strError);
            if (values == null)
            {
                MessageBox.Show(this, strError);
                goto FINISH;
            }
            strMime = (string)values["mimetype"];
            if (strMime == null || strMime == "")
            {
                strMime = "text";
            }
            this.Mime = strMime;

            this.LocalPath = (string)values["localpath"];
            if (this.LocalPath == null)
            {
                this.LocalPath = "";
            }

            // string strFirstPart = StringUtil.GetFirstPartPath(ref strMime);
            if (this.IsText == true)
            {
                this.Stream.Seek(0, SeekOrigin.Begin);
                using (StreamReader sr = new StreamReader(this.Stream, Encoding.UTF8))
                {
                    this.textBox_content.Text = ConvertCrLf(sr.ReadToEnd());
                }
                // 注意,此后 this.Stream 被关闭
            }
            else
            {
                //this.textBox_content.Text = "<二进制内容无法直接编辑>";
                //this.textBox_content.ReadOnly = true;
                //this.button_format.Enabled = false;
            }

            //////

            button_OK.Enabled = false;
FINISH:
            if (stopManager != null && stop != null)
            {
                stop.Unregister();      // 和容器关联
                stop = null;
            }

            this.channel = null;

            this.textBox_content.SelectionStart  = 0;
            this.textBox_content.SelectionLength = 0;
        }
Пример #5
0
        // 在服务器端创建对象
        // return:
        //		-1	错误
        //		1	以及存在同名对象
        //		0	正常返回
        int NewServerSideObject(string strPath,
            int nType,
            Stream stream,
            byte[] baTimeStamp,
            out byte[] baOutputTimestamp,
            out string strError)
        {
            strError = "";
            baOutputTimestamp = null;

            Debug.Assert(this.Channels != null, "");

            this.channel = Channels.GetChannel(this.ServerUrl);

            Debug.Assert(channel != null, "Channels.GetChannel() 异常");

            DigitalPlatform.Stop stop = null;

            if (stopManager != null)
            {
                stop = new DigitalPlatform.Stop();

                stop.Register(this.stopManager, true);	// 和容器关联

                stop.OnStop += new StopEventHandler(this.DoStop);
                stop.Initial("正在创建新对象: " + this.ServerUrl + "?" + strPath);

                stop.BeginLoop();

            }

            string strOutputPath = "";
            string strStyle = "";

            if (nType == ResTree.RESTYPE_FOLDER)
                strStyle = "createdir";
            /*
            long lRet = channel.DoSaveTextRes(strPath,
                "",	// content 暂时为空
                true,	// bInlucdePreamble
                strStyle,	// style
                null,	// baTimeStamp,
                out baOutputTimestamp,
                out strOutputPath,
                out strError);
            */

            string strRange = "";
            if (stream != null && stream.Length != 0)
            {
                Debug.Assert(stream.Length != 0, "test");
                strRange = "0-" + Convert.ToString(stream.Length - 1);
            }
            long lRet = channel.DoSaveResObject(strPath,
                stream,
                (stream != null && stream.Length != 0) ? stream.Length : 0,
                strStyle,
                "",	// strMetadata,
                strRange,
                true,
                baTimeStamp,	// timestamp,
                out baOutputTimestamp,
                out strOutputPath,
                out strError);

            if (stopManager != null)
            {
                stop.EndLoop();
                stop.OnStop -= new StopEventHandler(this.DoStop);
                stop.Initial("");

                stop.Unregister();	// 和容器关联
            }

            if (lRet == -1)
            {
                if (this.channel.ErrorCode == ChannelErrorCode.AlreadyExist)
                {
                    this.channel = null;
                    return 1;	// 已经存在同名同类型对象
                }
                this.channel = null;
                strError = "写入 '" + strPath + "' 发生错误: " + strError;
                return -1;
            }

            this.channel = null;
            return 0;
        }
Пример #6
0
        int GetDbStyle(string strDbName,
            out string strError)
        {
            strError = "";

            this.channel = Channels.GetChannel(this.ServerUrl);

            Debug.Assert(channel != null, "Channels.GetChannel() 异常");

            ResInfoItem[] items = null;

            DigitalPlatform.Stop stop = null;

            if (stopManager != null)
            {
                stop = new DigitalPlatform.Stop();
                stop.Register(this.stopManager, true);	// 和容器关联

                stop.OnStop += new StopEventHandler(this.DoStop);
                stop.Initial("正在获得数据库 " + strDbName + "的风格参数");

                stop.BeginLoop();
            }

            long lRet = channel.DoDir("",   // 列出全部数据库
                this.Lang,
                null,   // 不需要列出全部语言的名字
                out items,
                out strError);

            if (stopManager != null)
            {
                stop.EndLoop();
                stop.OnStop -= new StopEventHandler(this.DoStop);
                stop.Initial("");

                stop.Unregister();	// 和容器关联
            }

            this.channel = null;

            if (lRet == -1)
                return -1;

            if (items == null)
                return 0;   // 数据库不存在

            for (int i = 0; i < items.Length; i++)
            {
                // 忽略非数据库类型节点
                if (items[i].Type != ResTree.RESTYPE_DB)
                    continue;

                if (items[i].Name == strDbName)
                    return items[i].Style;
            }

            return 0;   // 数据库不存在
        }
Пример #7
0
        // 导入数据
        int ImportData(bool bFastMode = false)
        {
            string strError = "";
            string strTimeMessage = "";
            int CHUNK_SIZE = 150 * 1024;    // 70

            if (this.SelectedNode == null)
            {
                strError = "尚未选择要要导入数据的数据库节点";
                goto ERROR0;
            }

            if (this.SelectedNode.ImageIndex != RESTYPE_DB)
            {
                strError = "所选择的节点不是数据库类型。请选择要导入数据的数据库节点。";
                goto ERROR0;
            }

            if (bFastMode == true)
            {
                DialogResult result = MessageBox.Show(this,
        "警告:\r\n在快速导入期间,相关数据库会进入一种锁定状态,对数据库的其他检索和修改操作暂时会被禁止,直到处理完成。\r\n\r\n请问确实要进行快速导入么?",
        "导入数据",
        MessageBoxButtons.YesNo,
        MessageBoxIcon.Question,
        MessageBoxDefaultButton.Button2);
                if (result == DialogResult.No)
                    return 0;
            }

            OpenFileDialog dlg = new OpenFileDialog();

            dlg.Title = "请指定要导入的数据文件";
            dlg.FileName = "";
            dlg.Filter = "备份文件 (*.dp2bak)|*.dp2bak|XML文件 (*.xml)|*.xml|ISO2709文件 (*.iso;*.mrc)|*.iso;*.mrc|All files (*.*)|*.*";
            dlg.RestoreDirectory = true;

            if (dlg.ShowDialog() != DialogResult.OK)
            {
                return 0;
            }

            long lTotalCount = 0;

            ImportUtil import_util = new ImportUtil();
            int nRet = import_util.Begin(this,
                this.AppInfo,
                dlg.FileName,
                out strError);
            if (nRet == -1 || nRet == 1)
                goto ERROR0;

#if NO
            ResPath respath = new ResPath(this.SelectedNode);
            this.channel = Channels.GetChannel(respath.Url);
            Debug.Assert(channel != null, "Channels.GetChannel() 异常");
#endif
            // 缺省的目标数据库路径
            ResPath default_target_respath = new ResPath(this.SelectedNode);
            RmsChannel cur_channel = Channels.CreateTempChannel(default_target_respath.Url);
            Debug.Assert(cur_channel != null, "Channels.GetChannel() 异常");

            List<string> target_dburls = new List<string>();
#if NO
            DigitalPlatform.Stop stop = null;

            if (stopManager != null)
            {
                stop = new DigitalPlatform.Stop();

                stop.Register(this.stopManager, true);	// 和容器关联

                stop.OnStop += new StopEventHandler(this.DoStop);
                stop.Initial("正在导入数据 " + respath.FullPath);
                stop.BeginLoop();
            }
#endif
            DigitalPlatform.Stop stop = PrepareStop("正在导入数据 ...");  // + default_target_respath.FullPath);
            stop.OnStop -= new StopEventHandler(this.DoStop);   // 去掉缺省的回调函数
            stop.OnStop += (sender1, e1) =>
            {
                if (cur_channel != null)
                    cur_channel.Abort();
            };
            stop.Style = StopStyle.EnableHalfStop;  // API的间隙才让中断。避免获取结果集的中途,因为中断而导致 Session 失效,结果集丢失,进而无法 Retry 获取
            ProgressEstimate estimate = new ProgressEstimate();
            try // open import util
            {
                    bool bDontPromptTimestampMismatchWhenOverwrite = false;
                    DbNameMap map = new DbNameMap();
                    long lSaveOffs = -1;

                    estimate.SetRange(0, import_util.Stream.Length);
                    estimate.StartEstimate();

                    stop.SetProgressRange(0, import_util.Stream.Length);

                    List<UploadRecord> records = new List<UploadRecord>();
                    int nBatchSize = 0;
                    for (int index = 0; ; index++)
                    {
                        Application.DoEvents();	// 出让界面控制权

                        if (stop.State != 0)
                        {
                            DialogResult result = MessageBox.Show(this,
                                "确实要中断当前批处理操作?",
                                "导入数据",
                                MessageBoxButtons.YesNo,
                                MessageBoxIcon.Question,
                                MessageBoxDefaultButton.Button2);
                            if (result == DialogResult.Yes)
                            {
                                strError = "用户中断";
                                goto ERROR1;
                            }
                            else
                            {
                                stop.Continue();
                            }
                        }

                        //string strXml = "";
                        //string strResPath = "";
                        //string strTimeStamp = "";
                        UploadRecord record = null;

                        if (import_util.FileType == ExportFileType.BackupFile)
                        {
                            if (lSaveOffs != -1)
                                import_util.Stream.Seek(lSaveOffs, SeekOrigin.Begin);
                        }

                        nRet = import_util.ReadOneRecord(out record,
                            out strError);
                        if (nRet == -1)
                            goto ERROR1;
                        if (nRet == 1)
                            break;

                        if (import_util.FileType == ExportFileType.BackupFile)
                        {
                            // 保存每次读取后的文件指针位置
                            lSaveOffs = import_util.Stream.Position;
                        }

                        Debug.Assert(record != null, "");
#if NO
                    XmlDocument dom = new XmlDocument();
                    try
                    {
                        dom.LoadXml(strXml);
                    }
                    catch (Exception ex)
                    {
                        strError = "XML装入DOM时出错: " + ex.Message;
                        goto ERROR1;
                    }
                    string strResPath = DomUtil.GetAttr(DpNs.dprms, dom.DocumentElement, "path");
                    string strTimeStamp = DomUtil.GetAttr(DpNs.dprms, dom.DocumentElement, "timestamp");
#endif

                        // 准备目标路径
                        {
                            string strLongPath = record.Url + "?" + record.RecordBody.Path;
#if NO
                        // 根据原始路径准备即将写入的路径
                        // return:
                        //      -1  出错
                        //      0   用户放弃
                        //      1   成功
                        nRet = ImportUtil.PrepareOverwritePath(
                this.Servers,
                this.Channels,
                this,
                ref map,
                ref strLongPath,
                out strError);
                        if (nRet == 0 || nRet == -1)
                            goto ERROR1;
#endif
                            // 根据原始路径准备即将写入的路径
                            // return:
                            //      -1  出错
                            //      0   用户放弃
                            //      1   成功
                            //      2   要跳过本条
                            nRet = ImportUtil.PrepareOverwritePath(
                                this,
                                this.Servers,
                                this.Channels,
                                this.AppInfo,
                                index,
                                default_target_respath.FullPath,
                                ref map,
                                ref strLongPath,
                                out strError);
                            if (nRet == 0 || nRet == -1)
                                goto ERROR1;
                            if (nRet == 2)
                                continue;

                            ResPath respath = new ResPath(strLongPath);
                            record.Url = respath.Url;
                            record.RecordBody.Path = respath.Path;

                            // 记载每个数据库的 URL
                            string strDbUrl = GetDbUrl(strLongPath);
                            if (target_dburls.IndexOf(strDbUrl) == -1)
                            {
                                // 每个数据库要进行一次快速模式的准备操作
                                if (bFastMode == true)
                                {
                                    nRet = ManageKeysIndex(strDbUrl,
                                        "beginfastappend",
                                        "正在对数据库 "+strDbUrl+" 进行快速导入模式的准备工作 ...",
                                        out strError);
                                    if (nRet == -1)
                                        goto ERROR1;
                                }
                                target_dburls.Add(strDbUrl);
                            }
                        }

                        bool bNeedPush = false;
                        // 是否要把积累的记录推送出去进行写入?
                        // 要进行以下检查:
                        // 1) 当前记录和前一条记录之间,更换了服务器
                        // 2) 累积的记录尺寸超过要求
                        // 3) 当前记录是一条超大的记录 (这是因为要保持从文件中读出的顺序来写入(例如追加时候的号码增量顺序),就必须在单条写入本条前,先写入积累的那些记录)
                        if (records.Count > 0)
                        {
                            if (record.TooLarge() == true)
                                bNeedPush = true;
                            else if (nBatchSize + record.RecordBody.Xml.Length > CHUNK_SIZE)
                                bNeedPush = true;
                            else
                            {
                                if (LastUrl(records) != record.Url)
                                    bNeedPush = true;
                            }
                        }


                        if (bNeedPush == true)
                        {
                            // 准备 Channel
                            Debug.Assert(records.Count > 0, "");
                            cur_channel = ImportUtil.GetChannel(this.Channels,
                                stop,
                                LastUrl(records),
                                cur_channel);

                            List<UploadRecord> save_records = new List<UploadRecord>();
                            save_records.AddRange(records);

                            while (records.Count > 0)
                            {
                                // 将 XML 记录成批写入数据库
                                // return:
                                //      -1  出错
                                //      >=0 本次已经写入的记录个数。本函数返回时 records 集合的元素数没有变化(但元素的Path和Timestamp会有变化),如果必要调主可截取records集合中后面未处理的部分再次调用本函数
                                nRet = ImportUtil.WriteRecords(
                                    this,
                                    stop,
                                    cur_channel,
                                    bFastMode,
                                    records,
                                    ref bDontPromptTimestampMismatchWhenOverwrite,
                                    out strError);
                                if (nRet == -1)
                                    goto ERROR1;
                                if (nRet == 0)
                                {
                                    // TODO: 或可以改为单条写入
                                    strError = "WriteRecords() error :" + strError;
                                    goto ERROR1;
                                }
                                Debug.Assert(nRet <= records.Count, "");
                                records.RemoveRange(0, nRet);
                                lTotalCount += nRet;
                            }

                            // 上载对象
                            // return:
                            //      -1  出错
                            //      0   成功
                            nRet = import_util.UploadObjects(
                                stop,
                                cur_channel,
                                save_records,
                                ref bDontPromptTimestampMismatchWhenOverwrite,
                                out strError);
                            if (nRet == -1)
                                goto ERROR1;

                            nBatchSize = 0;
                            stop.SetProgressValue(import_util.Stream.Position);

                            stop.SetMessage("已经写入记录 " + lTotalCount.ToString() + " 条。"
    + "剩余时间 " + ProgressEstimate.Format(estimate.Estimate(import_util.Stream.Position)) + " 已经过时间 " + ProgressEstimate.Format(estimate.delta_passed));

                        }

                        // 如果 记录的 XML 尺寸太大不便于成批上载,需要在单独直接上载
                        if (record.TooLarge() == true)
                        {
                            // 准备 Channel
                            // ResPath respath = new ResPath(record.RecordBody.Path);
                            cur_channel = ImportUtil.GetChannel(this.Channels,
                                stop,
                                record.Url,
                                cur_channel);

                            // 写入一条 XML 记录
                            // return:
                            //      -1  出错
                            //      0   邀请中断整个处理
                            //      1   成功
                            //      2   跳过本条,继续处理后面的
                            nRet = ImportUtil.WriteOneXmlRecord(
                                this,
                                stop,
                                cur_channel,
                                record,
                                ref bDontPromptTimestampMismatchWhenOverwrite,
                                out strError);
                            if (nRet == -1)
                                goto ERROR1;
                            if (nRet == 0)
                                goto ERROR1;

                            List<UploadRecord> temp = new List<UploadRecord>();
                            temp.Add(record);
                            // 上载对象
                            // return:
                            //      -1  出错
                            //      0   成功
                            nRet = import_util.UploadObjects(
                                stop,
                                cur_channel,
                                temp,
                                ref bDontPromptTimestampMismatchWhenOverwrite,
                                out strError);
                            if (nRet == -1)
                                goto ERROR1;

                            lTotalCount += 1;
                            continue;
                        }

                        records.Add(record);
                        if (record.RecordBody != null && record.RecordBody.Xml != null)
                            nBatchSize += record.RecordBody.Xml.Length;
                    }

                    // 最后提交一次
                    if (records.Count > 0)
                    {
                        // 准备 Channel
                        Debug.Assert(records.Count > 0, "");
                        cur_channel = ImportUtil.GetChannel(this.Channels,
                            stop,
                            LastUrl(records),
                            cur_channel);

                        List<UploadRecord> save_records = new List<UploadRecord>();
                        save_records.AddRange(records);

                        while (records.Count > 0)
                        {
                            // 将 XML 记录成批写入数据库
                            // return:
                            //      -1  出错
                            //      >=0 本次已经写入的记录个数。本函数返回时 records 集合的元素数没有变化(但元素的Path和Timestamp会有变化),如果必要调主可截取records集合中后面未处理的部分再次调用本函数
                            nRet = ImportUtil.WriteRecords(
                                this,
                                stop,
                                cur_channel,
                                bFastMode,
                                records,
                                ref bDontPromptTimestampMismatchWhenOverwrite,
                                out strError);
                            if (nRet == -1)
                                goto ERROR1;
                            if (nRet == 0)
                            {
                                strError = "WriteRecords() error :" + strError;
                                goto ERROR1;
                            }
                            Debug.Assert(nRet <= records.Count, "");
                            records.RemoveRange(0, nRet);
                            lTotalCount += nRet;
                        }

                        // 上载对象
                        // return:
                        //      -1  出错
                        //      0   成功
                        nRet = import_util.UploadObjects(
                            stop,
                            cur_channel,
                            save_records,
                            ref bDontPromptTimestampMismatchWhenOverwrite,
                            out strError);
                        if (nRet == -1)
                            goto ERROR1;

                        nBatchSize = 0;
                        stop.SetProgressValue(import_util.Stream.Position);

                        stop.SetMessage("已经写入记录 " + lTotalCount.ToString() + " 条。"
    + "剩余时间 " + ProgressEstimate.Format(estimate.Estimate(import_util.Stream.Position)) + " 已经过时间 " + ProgressEstimate.Format(estimate.delta_passed));

                        records.Clear();
                        nBatchSize = 0;
                    }
            }// close import util
            finally
            {
                if (bFastMode == true)
                {
                    foreach (string url in target_dburls)
                    {
                        string strQuickModeError = "";
                        nRet = ManageKeysIndex(url,
                            "endfastappend",
                            "正在对数据库 " + url + " 进行快速导入模式的收尾工作,请耐心等待 ...",
                            out strQuickModeError);
                        if (nRet == -1)
                            MessageBox.Show(this, strQuickModeError);
                    }
                }

                EndStop(stop);
#if NO
                if (stopManager != null)
                {
                    stop.EndLoop();
                    stop.OnStop -= new StopEventHandler(this.DoStop);
                    stop.Initial("");

                    stop.Unregister();	// 和容器脱离关联
                }
#endif
                cur_channel.Close();
                cur_channel = null;

                import_util.End();
            }

            strTimeMessage = "总共耗费时间: " + estimate.GetTotalTime().ToString();
            MessageBox.Show(this, "文件 " + dlg.FileName + " 内的数据已经成功导入下列数据库:\r\n\r\n" + StringUtil.MakePathList(target_dburls, "\r\n") + "\r\n\r\n共导入记录 " + lTotalCount.ToString() + " 条。\r\n\r\n" + strTimeMessage);
            return 0;
        ERROR0:
            MessageBox.Show(this, strError);
            return -1;
        ERROR1:
            MessageBox.Show(this, strError);
            // 使用了 lTotalCount 和 estimate 以后的报错
            if (lTotalCount > 0)
            {
                strTimeMessage = "总共耗费时间: " + estimate.GetTotalTime().ToString();
                MessageBox.Show(this, "文件 " + dlg.FileName + " 内的部分数据已经成功导入下列数据库:\r\n\r\n" + StringUtil.MakePathList(target_dburls, "\r\n") + "\r\n\r\n共导入记录 " + lTotalCount.ToString() + " 条。\r\n\r\n" + strTimeMessage);
            }
            return -1;
        }
Пример #8
0
		// 递归
		public int Fill(TreeNode node)
		{
			TreeNodeCollection children = null;

			if (node == null) 
			{
				children = this.Nodes;
			}
			else 
			{
				children = node.Nodes;
			}

			int i;


			// 填充根
			if (node == null) 
			{
				children.Clear();

				TreeNode nodeNew = new TreeNode(this.ServerUrl, ResTree.RESTYPE_SERVER, ResTree.RESTYPE_SERVER);
				ResTree.SetLoading(nodeNew);

				NodeInfo nodeinfo = new NodeInfo();
				nodeinfo.TreeNode = nodeNew;
				nodeinfo.Expandable = true;
				nodeinfo.DefElement = GetDefElementString(nodeNew.ImageIndex);
				nodeinfo.NodeState |= NodeState.Object;

				nodeNew.Tag = nodeinfo;


				if (EnabledIndices != null
					&& StringUtil.IsInList(nodeNew.ImageIndex, EnabledIndices) == false)
					nodeNew.ForeColor = ControlPaint.LightLight(nodeNew.ForeColor);

				children.Add(nodeNew);
				return 0;
			}


			// 根以下的节点类型
			ResPath respath = new ResPath(node);

			string strPath = respath.Path;

			//if (node != null)
			//	strPath = TreeViewUtil.GetPath(node);

			this.channel = Channels.GetChannel(this.ServerUrl);

			Debug.Assert(channel != null, "Channels.GetChannel() 异常");

			ResInfoItem [] items = null;

			string strError = "";

			DigitalPlatform.Stop stop = null;

			if (stopManager != null) 
			{
				stop = new DigitalPlatform.Stop();

                stop.Register(this.stopManager, true);	// 和容器关联

                stop.OnStop += new StopEventHandler(this.DoStop);
				stop.Initial("正在列目录: " + this.ServerUrl + "?" + strPath);
				stop.BeginLoop();

			}

			long lRet = channel.DoDir(strPath,
				this.Lang,
                null,   // 不需要列出全部语言的名字
				out items,
				out strError);

			if (stopManager != null) 
			{
				stop.EndLoop();
                stop.OnStop -= new StopEventHandler(this.DoStop);
				stop.Initial("");

				stop.Unregister();	// 和容器关联
			}

			this.channel = null;

			if (lRet == -1) 
			{
				try 
				{
					MessageBox.Show(this, "Channel::DoDir() Error: " + strError);
				}
				catch
				{
					// this可能已经不存在
					return -1;
				}

				if (node != null) 
				{
					ResTree.SetLoading(node);	// 出错的善后处理,重新出现+号
					node.Collapse();
				}
				return -1;
			}


			if (items != null) 
			{
				children.Clear();

				for(i=0;i<items.Length;i++) 
				{
					// 忽略from类型节点
					if (items[i].Type == ResTree.RESTYPE_FROM)
						continue;

					TreeNode nodeNew = new TreeNode(items[i].Name, items[i].Type, items[i].Type);


					NodeInfo nodeinfo = new NodeInfo();
					nodeinfo.TreeNode = nodeNew;
					nodeinfo.Expandable = items[i].HasChildren;
					nodeinfo.DefElement = GetDefElementString(nodeNew.ImageIndex);
					nodeinfo.NodeState |= NodeState.Object;
                    nodeinfo.Style = items[i].Style;
					nodeNew.Tag = nodeinfo;

					if (items[i].HasChildren)
						ResTree.SetLoading(nodeNew);

					if (EnabledIndices != null
						&& StringUtil.IsInList(nodeNew.ImageIndex, EnabledIndices) == false)
						nodeNew.ForeColor = ControlPaint.LightLight(nodeNew.ForeColor);

					children.Add(nodeNew);
				}
			}

			return 0;
		}
Пример #9
0
        private void CfgFileEditDlg_Load(object sender, System.EventArgs e)
        {
            button_export.Enabled = false;

            MemoryStream stream = null;
            string strMetaData;
            string strError = "";
            string strMime = "";

            Hashtable values = null;

            if (Obj != null)
            {
                if (this.Obj.Content != null)
                {
                    stream = new MemoryStream(this.Obj.Content);
                    this.Stream = stream;
                    this.Stream.Seek(0, SeekOrigin.Begin);

                    button_export.Enabled = true;
                }

                this.TimeStamp = this.Obj.TimeStamp;

                strMetaData = this.Obj.Metadata;

                // 观察mime
                // 取metadata
                values = StringUtil.ParseMetaDataXml(strMetaData,
                    out strError);
                if (values == null)
                {
                    MessageBox.Show(this, strError);
                    return;
                }
                strMime = (string)values["mimetype"];
                if (strMime == null || strMime == "")
                    strMime = "text";
                this.Mime = strMime;

                this.LocalPath = (string)values["localpath"];
                if (this.LocalPath == null)
                    this.LocalPath = "";

                this.textBox_content.Text = "";

                // string strFirstPart = StringUtil.GetFirstPartPath(ref strMime);
                if (this.IsText == true)
                {
                    if (this.Stream != null)
                    {
                        this.Stream.Seek(0, SeekOrigin.Begin);
                        using (StreamReader sr = new StreamReader(this.Stream, Encoding.UTF8))
                        {
                            this.textBox_content.Text = ConvertCrLf(sr.ReadToEnd());
                        }
                    }
                }
                else
                {
                }

                //////

                button_OK.Enabled = false;

                this.textBox_content.SelectionStart = 0;
                this.textBox_content.SelectionLength = 0;
                return;
            }

            this.channel = Channels.GetChannel(this.ServerUrl);
            Debug.Assert(channel != null, "Channels.GetChannel() 异常");

            DigitalPlatform.Stop stop = null;

            if (stopManager != null)
            {
                stop = new DigitalPlatform.Stop();

                stop.Register(this.stopManager, true);	// 和容器关联

                stop.OnStop += new StopEventHandler(this.DoStop);
                stop.Initial("正在下载配置文件: " + this.Path);

                stop.BeginLoop();

            }

            // string strContent = "";
            byte[] baTimeStamp = null;
            string strOutputPath;

            string strStyle = "content,data,metadata,timestamp,outputpath";
            //			string strStyle = "attachment,data,metadata,timestamp,outputpath";

            stream = new MemoryStream();

            long lRet = channel.GetRes(
                this.Path,
                stream,
                stop,	// stop,
                strStyle,
                null,	// byte [] input_timestamp,
                out strMetaData,
                out baTimeStamp,
                out strOutputPath,
                out strError);

            /*
            long lRet = channel.GetRes((
                this.Path,
                out strContent,
                out strMetaData,
                out baTimeStamp,
                out strOutputPath,
                out strError);
            */

            if (stopManager != null)
            {
                stop.EndLoop();
                stop.OnStop -= new StopEventHandler(this.DoStop);
                stop.Initial("");

            }

            if (lRet == -1)
            {
                MessageBox.Show(this, strError);
                goto FINISH;
            }

            this.Stream = stream;
            this.Stream.Seek(0, SeekOrigin.Begin);

            button_export.Enabled = true;


            this.TimeStamp = baTimeStamp;

            // 观察mime
            // 取metadata
            values = StringUtil.ParseMetaDataXml(strMetaData,
                out strError);
            if (values == null)
            {
                MessageBox.Show(this, strError);
                goto FINISH;
            }
            strMime = (string)values["mimetype"];
            if (strMime == null || strMime == "")
                strMime = "text";
            this.Mime = strMime;

            this.LocalPath = (string)values["localpath"];
            if (this.LocalPath == null)
                this.LocalPath = "";

            // string strFirstPart = StringUtil.GetFirstPartPath(ref strMime);
            if (this.IsText == true)
            {
                this.Stream.Seek(0, SeekOrigin.Begin);
                using (StreamReader sr = new StreamReader(this.Stream, Encoding.UTF8))
                {
                    this.textBox_content.Text = ConvertCrLf(sr.ReadToEnd());
                }
                // 注意,此后 this.Stream 被关闭
            }
            else
            {
                //this.textBox_content.Text = "<二进制内容无法直接编辑>";
                //this.textBox_content.ReadOnly = true;
                //this.button_format.Enabled = false;
            }

            //////

            button_OK.Enabled = false;
        FINISH:
            if (stopManager != null && stop != null)
            {
                stop.Unregister();	// 和容器关联
                stop = null;
            }

            this.channel = null;

            this.textBox_content.SelectionStart = 0;
            this.textBox_content.SelectionLength = 0;
        }
Пример #10
0
		// 登出
		void menu_logout(object sender, System.EventArgs e)
		{
			if (this.SelectedNode == null) 
			{
				MessageBox.Show(this, "尚未选择节点");
				return;
			}

			ResPath respath = new ResPath(this.SelectedNode);

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

			Debug.Assert(channel != null, "Channels.GetChannel() 异常");

#if NO
			DigitalPlatform.Stop stop = null;

			if (stopManager != null) 
			{
				stop = new DigitalPlatform.Stop();

                stop.Register(this.stopManager, true);	// 和容器关联

                stop.OnStop += new StopEventHandler(this.DoStop);
				stop.Initial("正在登出: " + respath.FullPath);
				stop.BeginLoop();

			}
#endif
            DigitalPlatform.Stop stop = PrepareStop("正在登出: " + respath.FullPath);

			string strError;
			// return:
			//		-1	error
			//		0	login failed
			//		1	login succeed
			long nRet = channel.DoLogout(
				out strError);

            EndStop(stop);
#if NO
			if (stopManager != null) 
			{
				stop.EndLoop();
                stop.OnStop -= new StopEventHandler(this.DoStop);
				stop.Initial("");

				stop.Unregister();	// 和容器关联
			}
#endif

			this.channel = null;

			if (nRet == -1) 
			{
				MessageBox.Show(this, strError);
				return;
			}

			// 刷新
			//ResPath OldPath = new ResPath(this.SelectedNode);

			respath.Path = "";
			ExpandPath(respath);	// 选中服务器,以下节点清除
			SetLoading(this.SelectedNode);
			if (this.SelectedNode != null)
				this.SelectedNode.Collapse();

			//ExpandPath(OldPath);

		}
Пример #11
0
        void RefreshDB(bool bClearAllKeyTables)
        {
            if (this.SelectedNode == null)
            {
                MessageBox.Show(this, "尚未选择要刷新定义的数据库节点");
                return;
            }

            if (this.SelectedNode.ImageIndex != RESTYPE_DB)
            {
                MessageBox.Show(this, "所选择的节点不是数据库类型。请选择要刷新定义的数据库节点。");
                return;
            }

            ResPath respath = new ResPath(this.SelectedNode);

            string strText = "确实要刷新位于服务器 '" + respath.Url + "' 上的数据库 '" + respath.Path + "' 的定义吗?\r\n\r\n注:刷新数据库定义,会为数据库增补在keys配置文件中新增的SQL表,不会损坏数据库中已有的数据。";

            DialogResult msgResult = MessageBox.Show(this,
                strText,
                "刷新数据库定义",
                MessageBoxButtons.OKCancel,
                MessageBoxIcon.Question,
                MessageBoxDefaultButton.Button2);

            if (msgResult != DialogResult.OK)
            {
                MessageBox.Show(this, "刷新数据库定义的操作被放弃...");
                return;
            }


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

            Debug.Assert(channel != null, "Channels.GetChannel() 异常");


            string strError = "";

#if NO
            DigitalPlatform.Stop stop = null;

            if (stopManager != null)
            {
                stop = new DigitalPlatform.Stop();

                stop.Register(this.stopManager, true);	// 和容器关联

                stop.OnStop += new StopEventHandler(this.DoStop);
                stop.Initial("正在刷新数据库定义: " + respath.FullPath );
                stop.BeginLoop();

            }
#endif
            DigitalPlatform.Stop stop = PrepareStop("正在刷新数据库定义: " + respath.FullPath);


            long lRet = channel.DoRefreshDB(
                "begin",
                respath.Path,
                bClearAllKeyTables,
                out strError);

            EndStop(stop);
#if NO
            if (stopManager != null)
            {
                stop.EndLoop();
                stop.OnStop -= new StopEventHandler(this.DoStop);
                stop.Initial("");

                stop.Unregister();	// 和容器脱离关联
            }
#endif

            this.channel = null;

            if (lRet == -1)
            {
                MessageBox.Show(this, strError);
            }
            else
            {
                MessageBox.Show(this, "位于服务器'" + respath.Url + "'上的数据库 '" + respath.Path + "' 被成功刷新了定义。");
            }
        }
Пример #12
0
		// 初始化数据库
		void menu_initialDB(object sender, System.EventArgs e)
		{
			if (this.SelectedNode == null)
			{
				MessageBox.Show(this, "尚未选择要初始化的数据库节点");
				return;
			}
			
			if (this.SelectedNode.ImageIndex != RESTYPE_DB)
			{
				MessageBox.Show(this, "所选择的节点不是数据库类型。请选择要初始化的数据库节点。");
				return;
			}

			ResPath respath = new ResPath(this.SelectedNode);

			string strText = "你确实要初始化位于服务器 '"+respath.Url+"' 上的数据库 '"+respath.Path + "' 吗?\r\n\r\n警告:数据库一旦被初始化,其中包含的原有数据将全部被摧毁,并且无法恢复!";

			DialogResult msgResult = MessageBox.Show(this,
				strText,
				"初始化数据库",
				MessageBoxButtons.OKCancel,
				MessageBoxIcon.Question,
				MessageBoxDefaultButton.Button2);
				
			if (msgResult != DialogResult.OK) 
			{
				MessageBox.Show(this, "初始化数据库操作被放弃...");
				return;
			}


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

			Debug.Assert(channel != null, "Channels.GetChannel() 异常");


			string strError = "";

#if NO
			DigitalPlatform.Stop stop = null;

			if (stopManager != null) 
			{
				stop = new DigitalPlatform.Stop();

                stop.Register(this.stopManager, true);	// 和容器关联

                stop.OnStop += new StopEventHandler(this.DoStop);
				stop.Initial("正在初始化数据库: " + respath.FullPath);
				stop.BeginLoop();

			}
#endif
            DigitalPlatform.Stop stop = PrepareStop("正在初始化数据库: " + respath.FullPath);

			long lRet = channel.DoInitialDB(respath.Path, out strError);

            EndStop(stop);
#if NO
			if (stopManager != null) 
			{
				stop.EndLoop();
                stop.OnStop -= new StopEventHandler(this.DoStop);
				stop.Initial("");

				stop.Unregister();	// 和容器脱离关联
			}
#endif

			this.channel = null;

			if (lRet == -1) 
			{
				MessageBox.Show(this, strError);
			}
			else 
			{
				MessageBox.Show(this, "位于服务器'"+respath.Url+"'上的数据库 '"+respath.Path+"' 被成功初始化。");
			}
		}
Пример #13
0
        DigitalPlatform.Stop PrepareStop(string strText)
        {
            if (stopManager == null)
                return null;

            DigitalPlatform.Stop stop = new DigitalPlatform.Stop();

            stop.Register(this.stopManager, true);	// 和容器关联

            stop.OnStop += new StopEventHandler(this.DoStop);
            stop.Initial(strText);
            stop.BeginLoop();

            return stop;
        }
Пример #14
0
        // 导出数据
        void menu_export(object sender, System.EventArgs e)
        {
            string strError = "";

            string strTimeMessage = "";
            long lTotalCount = 0;	// 总命中数
            long lExportCount = 0;	// 已经传出的数量

            if (this.SelectedNode == null)
            {
                strError = "尚未选择要要导出数据的数据库节点";
                goto ERROR1;
            }

            if (this.SelectedNode.ImageIndex != RESTYPE_DB)
            {
                strError = "所选择的节点不是数据库类型。请选择要导出数据的数据库节点。";
                goto ERROR1;
            }

            ResPath respath = new ResPath(this.SelectedNode);

            // 询问导出数据的范围
            ExportDataDialog data_range_dlg = new ExportDataDialog();
            data_range_dlg.DbPath = respath.Path;
            data_range_dlg.AllRecords = true;
            data_range_dlg.StartPosition = FormStartPosition.CenterScreen;
            data_range_dlg.ShowDialog(this);

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

            string strRange = "0-9999999999";
            if (data_range_dlg.AllRecords == false)
                strRange = data_range_dlg.StartID + "-" + data_range_dlg.EndID;

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

            dlg.Title = "请指定要保存的数据文件名";
            dlg.CreatePrompt = false;
            dlg.OverwritePrompt = false;
            dlg.FileName = "";
            dlg.FilterIndex = 1;

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

            dlg.RestoreDirectory = true;

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

            ExportUtil export_util = new ExportUtil();


            string strQueryXml = "<target list='" + respath.Path
    + ":" + "__id'><item><word>"+strRange+"</word><match>exact</match><relation>range</relation><dataType>number</dataType><maxCount>-1</maxCount></item><lang>chi</lang></target>";


            RmsChannel cur_channel = Channels.CreateTempChannel(respath.Url);
            Debug.Assert(cur_channel != null, "Channels.GetChannel() 异常");

#if NO
            DigitalPlatform.Stop stop = null;

            if (stopManager != null)
            {
                stop = new DigitalPlatform.Stop();

                stop.Register(this.stopManager, true);	// 和容器关联

                stop.OnStop += new StopEventHandler(this.DoStop);
                stop.Initial("正在导出数据 " + respath.FullPath);
                stop.BeginLoop();
            }
#endif
            DigitalPlatform.Stop stop = PrepareStop("正在导出数据 " + respath.FullPath);

            stop.OnStop -= new StopEventHandler(this.DoStop);   // 去掉缺省的回调函数
            stop.OnStop += (sender1, e1) =>
            {
                    if (cur_channel != null)
                        cur_channel.Abort();
                };

            try
            {
                long lRet = cur_channel.DoSearch(strQueryXml,
    "default",
    out strError);
                if (lRet == -1)
                {
                    strError = "检索数据库 '"+respath.Path+"' 时出错: " + strError;
                    goto ERROR1;
                }

                if (lRet == 0)
                {
                    strError = "数据库 '" + respath.Path + "' 中没有任何数据记录";
                    goto ERROR1;	// not found
                }

                stop.Style = StopStyle.EnableHalfStop;  // API的间隙才让中断。避免获取结果集的中途,因为中断而导致 Session 失效,结果集丢失,进而无法 Retry 获取

                lTotalCount = lRet;	// 总命中数
                long lThisCount = lTotalCount;
                long lStart = 0;

                ProgressEstimate estimate = new ProgressEstimate();

                estimate.SetRange(0, lTotalCount);
                estimate.StartEstimate();

                stop.SetProgressRange(0, lTotalCount);

                int nRet = export_util.Begin(this,
    dlg.FileName,
    out strError);
                if (nRet == -1)
                    goto ERROR1;

                DialogResult last_one_result = DialogResult.Yes;    // 前一次对话框选择的方式
                bool bDontAskOne = false;
                int nRedoOneCount = 0;
                DialogResult last_get_result = DialogResult.Retry;    // 前一次对话框选择的方式
                bool bDontAskGet = false;
                int nRedoGetCount = 0;

                for (; ; )
                {
                    Application.DoEvents();	// 出让界面控制权

                    if (stop.State != 0)
                    {
                        DialogResult result = MessageBox.Show(this,
                            "确实要中断当前批处理操作?",
                            "导出数据",
                            MessageBoxButtons.YesNo,
                            MessageBoxIcon.Question,
                            MessageBoxDefaultButton.Button2);
                        if (result == DialogResult.Yes)
                        {
                            strError = "用户中断";
                            goto ERROR1;
                        }
                        else
                        {
                            stop.Continue();
                        }
                    }

                    string strStyle = "id,xml,timestamp";
                    if (export_util.FileType == ExportFileType.BackupFile)
                        strStyle = "id,xml,timestamp,metadata";

                    nRedoGetCount = 0;
                REDO_GET:
                    Record[] searchresults = null;
                    lRet = cur_channel.DoGetSearchResult(
                        "default",
                        lStart,
                        lThisCount,
                        strStyle,
                        this.Lang,
                        stop,
                        out searchresults,
                        out strError);
                    if (lRet == -1)
                    {
                        if (stop.State != 0)    // 已经中断
                            goto ERROR1;

                        // 自动重试有次数限制,避免进入死循环
                        if (bDontAskGet == true && last_get_result == DialogResult.Retry
                            && nRedoGetCount < 3)
                        {
                            nRedoGetCount++;
                            goto REDO_GET;
                        }

                        DialogResult result = MessageDlg.Show(this,
    "获取检索结果时 (偏移量 " + lStart + ") 出错:\r\n---\r\n"
    + strError + "\r\n---\r\n\r\n是否重试获取操作?\r\n\r\n注:\r\n[重试] 重新获取\r\n[中断] 中断整个批处理",
    "导出数据",
    MessageBoxButtons.RetryCancel,
    MessageBoxDefaultButton.Button1,
    ref bDontAskOne,
    new string[] { "重试", "中断" });
                        last_get_result = result;

                        if (result == DialogResult.Retry)
                        {
                            nRedoGetCount = 0;
                            goto REDO_GET;
                        }

                        Debug.Assert(result == DialogResult.Cancel, ""); 

                        strError = "获取检索结果时出错: " + strError;
                        goto ERROR1;
                    }

                    for (int i = 0; i < searchresults.Length; i++)
                    {
                        Record record = searchresults[i];

                        if (i == 0)
                        {
                            stop.SetMessage("正在输出记录 " + record.Path + ",已输出 " + lExportCount.ToString() + " 条。"
        + "剩余时间 " + ProgressEstimate.Format(estimate.Estimate(lExportCount)) + " 已经过时间 " + ProgressEstimate.Format(estimate.delta_passed));
                        }
                        nRedoOneCount = 0;

                    REDO_ONE:
                        nRet = export_util.ExportOneRecord(
                            cur_channel,
                            stop,
                            respath.Url,
                            record.Path,
                            record.RecordBody.Xml,
                            record.RecordBody.Metadata,
                            record.RecordBody.Timestamp,
                            out strError);
                        if (nRet == -1)
                        {
                            if (stop.State != 0)    // 已经中断
                                goto ERROR1;

                            // 重试、跳过、中断?
                            // 重试的时候,注意保持文件最后位置,不要留下残余的尾部
                            // MessageBoxButtons.AbortRetryIgnore  YesNoCancel
                            if (bDontAskOne == true && last_one_result == DialogResult.No)
                                continue;   // TODO: 最好在日志文件中记载跳过的记录。或者批处理结束后显示出来

                            // 自动重试有次数限制,避免进入死循环
                            if (bDontAskOne == true && last_one_result == DialogResult.Yes
                                && nRedoOneCount < 3)
                            {
                                nRedoOneCount++;
                                goto REDO_ONE;
                            }

                            DialogResult result = MessageDlg.Show(this,
                                "导出记录 '" + record.Path + "' 时出错:\r\n---\r\n"
                                + strError + "\r\n---\r\n\r\n是否重试导出操作?\r\n\r\n注:\r\n[重试] 重新导出这条记录\r\n[跳过] 忽略导出这条记录,但继续后面的处理\r\n[中断] 中断整个批处理",
                                "导出数据",
                                MessageBoxButtons.YesNoCancel,
                                MessageBoxDefaultButton.Button1,
                                ref bDontAskOne,
                                new string [] {"重试","跳过","中断"});
                            last_one_result = result;

                            if (result == DialogResult.Yes)
                            {
                                nRedoOneCount = 0;
                                goto REDO_ONE;
                            }

                            if (result == DialogResult.No)
                                continue;

                            Debug.Assert(result == DialogResult.Cancel, ""); 

                            goto ERROR1;
                        }

                        stop.SetProgressValue(lExportCount + 1);
                        lExportCount++;
                    }

                    if (lStart + searchresults.Length >= lTotalCount)
                        break;

                    lStart += searchresults.Length;
                    lThisCount -= searchresults.Length;
                }

                strTimeMessage = "总共耗费时间: " + estimate.GetTotalTime().ToString();
            }
            finally
            {
                EndStop(stop);
#if NO
                if (stopManager != null)
                {
                    stop.EndLoop();
                    stop.OnStop -= new StopEventHandler(this.DoStop);
                    stop.Initial("");

                    stop.Unregister();	// 和容器脱离关联
                }
#endif
                cur_channel.Close();
                cur_channel = null;

                export_util.End();
            }

            MessageBox.Show(this, "位于服务器 '" + respath.Url + "' 上的数据库 '" + respath.Path + "' 内共有记录 " + lTotalCount.ToString() + " 条,本次导出 " + lExportCount.ToString() + " 条。" + strTimeMessage);
            return;
        ERROR1:
            MessageBox.Show(this, strError);
            if (lExportCount > 0)
                MessageBox.Show(this, "数据库内共有记录 " + lTotalCount.ToString() + " 条,本次导出 " + lExportCount.ToString() + " 条");
        }
Пример #15
0
		// 递归
		public int Fill(TreeNode node,
            out string strError)
		{
            strError = "";
			TreeNodeCollection children = null;

			if (node == null) 
			{
				children = this.Nodes;
			}
			else 
			{
				children = node.Nodes;
			}

			int i;


			// 填充根
			if (node == null) 
			{
				children.Clear();

				for(i=0;i<Servers.Count;i++) 
				{
					Server server = (Server)Servers[i];
					TreeNode nodeNew = new TreeNode(server.Url, RESTYPE_SERVER, RESTYPE_SERVER);
					SetLoading(nodeNew);

					if (EnabledIndices != null
						&& StringUtil.IsInList(nodeNew.ImageIndex, EnabledIndices) == false)
						nodeNew.ForeColor = ControlPaint.LightLight(nodeNew.ForeColor);

					children.Add(nodeNew);
				}

				return 0;
			}


			// 根以下的节点类型
			ResPath respath = new ResPath(node);

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

			Debug.Assert(channel != null, "Channels.GetChannel() 异常");

			/*
			int nStart = 0;
			int nPerCount = -1;
			int nCount = 0;
			*/

			ResInfoItem [] items = null;

#if NO
			DigitalPlatform.Stop stop = null;

			if (stopManager != null) 
			{
				stop = new DigitalPlatform.Stop();

                stop.Register(this.stopManager, true);	// 和容器关联

                stop.OnStop += new StopEventHandler(this.DoStop);
				stop.Initial("正在列目录: " + respath.FullPath);
				stop.BeginLoop();
			}
#endif
            DigitalPlatform.Stop stop = PrepareStop("正在列目录: " + respath.FullPath);

            long lRet = 0;
            try
            {
                lRet = channel.DoDir(respath.Path,
                    this.Lang,
                    null,   // 不需要列出全部语言的名字
                    out items,
                    out strError);
            }
            finally
            {
                EndStop(stop);
            }

#if NO
			if (stopManager != null) 
			{
				stop.EndLoop();
                stop.OnStop -= new StopEventHandler(this.DoStop);
				stop.Initial("");

				stop.Unregister();	// 和容器关联
			}
#endif

			this.channel = null;

			if (lRet == -1) 
			{
#if NO
				try 
				{
					MessageBox.Show(this, "Channel::DoDir() Error: " + strError);
				}
				catch
				{
					// this可能已经不存在
					return -1;
				}
#endif
				if (node != null) 
				{
					SetLoading(node);	// 出错的善后处理,重新出现+号
					node.Collapse();
				}
				return -1;
			}


			if (items != null) 
			{
				children.Clear();

				//for(i=0;i<items.Length;i++) 
                foreach(ResInfoItem res_item in items)
				{
                    // ResInfoItem res_item = items[i];

                    TreeNode nodeNew = new TreeNode(res_item.Name, res_item.Type, res_item.Type);

                    if (res_item.Type == RESTYPE_DB)
                    {
                        DbProperty prop = new DbProperty();
                        prop.TypeString = res_item.TypeString;  // 类型字符串
                        nodeNew.Tag = prop;
                        List<string> column_names = null;
                        int nRet = GetBrowseColumns(
                            node.Text,
                            res_item.Name,
                            out column_names,
                            out strError);
                        if (nRet == -1)
                            return -1;
                        prop.ColumnNames = column_names;
                    }
                    else
                    {
                        ItemProperty prop = new ItemProperty();
                        prop.TypeString = res_item.TypeString;  // 类型字符串
                        nodeNew.Tag = prop;
                    }

                    if (res_item.HasChildren)
						SetLoading(nodeNew);

					if (EnabledIndices != null
						&& StringUtil.IsInList(nodeNew.ImageIndex, EnabledIndices) == false)
						nodeNew.ForeColor = ControlPaint.LightLight(nodeNew.ForeColor);

					children.Add(nodeNew);
				}
			}

			return 0;
		}
Пример #16
0
        private void DupForm_Load(object sender, EventArgs e)
        {
            Debug.Assert(this.dom != null, "尚未Initial()");

            stop = new DigitalPlatform.Stop();
            if (this.stopManager != null)
                stop.Register(this.stopManager, true);	// 和容器关联

                        // 自动启动查重
            if (this.AutoBeginSearch == true)
            {
                API.PostMessage(this.Handle, WM_INITIAL, 0, 0);
            }
        }
Пример #17
0
        // 递归
        public int Fill(TreeNode node)
        {
            TreeNodeCollection children = null;

            if (node == null)
            {
                children = this.Nodes;
            }
            else
            {
                children = node.Nodes;
            }

            int i;


            // 填充根
            if (node == null)
            {
                children.Clear();

                TreeNode nodeNew = new TreeNode(this.ServerUrl, ResTree.RESTYPE_SERVER, ResTree.RESTYPE_SERVER);
                ResTree.SetLoading(nodeNew);

                NodeInfo nodeinfo = new NodeInfo();
                nodeinfo.TreeNode   = nodeNew;
                nodeinfo.Expandable = true;
                nodeinfo.DefElement = GetDefElementString(nodeNew.ImageIndex);
                nodeinfo.NodeState |= NodeState.Object;

                nodeNew.Tag = nodeinfo;


                if (EnabledIndices != null &&
                    StringUtil.IsInList(nodeNew.ImageIndex, EnabledIndices) == false)
                {
                    nodeNew.ForeColor = ControlPaint.LightLight(nodeNew.ForeColor);
                }

                children.Add(nodeNew);
                return(0);
            }


            // 根以下的节点类型
            ResPath respath = new ResPath(node);

            string strPath = respath.Path;

            //if (node != null)
            //	strPath = TreeViewUtil.GetPath(node);

            this.channel = Channels.GetChannel(this.ServerUrl);

            Debug.Assert(channel != null, "Channels.GetChannel() 异常");

            ResInfoItem[] items = null;

            string strError = "";

            DigitalPlatform.Stop stop = null;

            if (stopManager != null)
            {
                stop = new DigitalPlatform.Stop();

                stop.Register(this.stopManager, true);  // 和容器关联

                stop.OnStop += new StopEventHandler(this.DoStop);
                stop.Initial("正在列目录: " + this.ServerUrl + "?" + strPath);
                stop.BeginLoop();
            }

            long lRet = channel.DoDir(strPath,
                                      this.Lang,
                                      null, // 不需要列出全部语言的名字
                                      out items,
                                      out strError);

            if (stopManager != null)
            {
                stop.EndLoop();
                stop.OnStop -= new StopEventHandler(this.DoStop);
                stop.Initial("");

                stop.Unregister();      // 和容器关联
            }

            this.channel = null;

            if (lRet == -1)
            {
                try
                {
                    MessageBox.Show(this, "Channel::DoDir() Error: " + strError);
                }
                catch
                {
                    // this可能已经不存在
                    return(-1);
                }

                if (node != null)
                {
                    ResTree.SetLoading(node);   // 出错的善后处理,重新出现+号
                    node.Collapse();
                }
                return(-1);
            }


            if (items != null)
            {
                children.Clear();

                for (i = 0; i < items.Length; i++)
                {
                    // 忽略from类型节点
                    if (items[i].Type == ResTree.RESTYPE_FROM)
                    {
                        continue;
                    }

                    TreeNode nodeNew = new TreeNode(items[i].Name, items[i].Type, items[i].Type);


                    NodeInfo nodeinfo = new NodeInfo();
                    nodeinfo.TreeNode   = nodeNew;
                    nodeinfo.Expandable = items[i].HasChildren;
                    nodeinfo.DefElement = GetDefElementString(nodeNew.ImageIndex);
                    nodeinfo.NodeState |= NodeState.Object;
                    nodeinfo.Style      = items[i].Style;
                    nodeNew.Tag         = nodeinfo;

                    if (items[i].HasChildren)
                    {
                        ResTree.SetLoading(nodeNew);
                    }

                    if (EnabledIndices != null &&
                        StringUtil.IsInList(nodeNew.ImageIndex, EnabledIndices) == false)
                    {
                        nodeNew.ForeColor = ControlPaint.LightLight(nodeNew.ForeColor);
                    }

                    children.Add(nodeNew);
                }
            }

            return(0);
        }
Пример #18
0
        private void button_OK_Click(object sender, System.EventArgs e)
        {
            string strMetaData = "";

            // TODO: 一旦遇到问题,可以放开注释试验
            // this.textBox_content.Text = RemoveSingle0a(this.textBox_content.Text);


            if (this.Obj != null)
            {
                if (this.IsText == true)
                {
                    byte[] baContent = StringUtil.GetUtf8Bytes(this.textBox_content.Text, true);
                    this.Obj.Content = baContent;
                }
                else
                {
                    if (this.Stream != null)
                    {
                        this.Obj.Content = new byte[this.Stream.Length];
                        this.Stream.Seek(0, SeekOrigin.Begin);
                        this.Stream.Read(this.Obj.Content,
                            0, (int)this.Stream.Length);
                    }
                    else
                    {
                        this.Obj.Content = null;
                    }
                }

                StringUtil.ChangeMetaData(ref strMetaData,
                    null,	// string strID,
                    this.LocalPath,	// string strLocalPath,
                    this.Mime,	// string strMimeType,
                    null,	// string strLastModified,
                    null,	// string strPath,
                    null);	// string strTimestamp)
                this.Obj.Metadata = strMetaData;

                this.Obj.Changed = true;

                this.DialogResult = DialogResult.OK;
                this.Close();

                return;
            }

            this.channel = Channels.GetChannel(this.ServerUrl);

            Debug.Assert(channel != null, "Channels.GetChannel() 异常");

            DigitalPlatform.Stop stop = null;

            if (stopManager != null)
            {
                stop = new DigitalPlatform.Stop();

                stop.Register(this.stopManager, true);	// 和容器关联

                stop.OnStop += new StopEventHandler(this.DoStop);
                stop.Initial("正在保存配置文件: " + this.Path);

                stop.BeginLoop();

            }

            if (this.IsText == true)
            {
                // 更新stream对象内容
                byte[] baContent = StringUtil.GetUtf8Bytes(this.textBox_content.Text, true);
                this.Stream = new MemoryStream(baContent);  // !!! 什么时候释放?
                /*
                this.Stream.SetLength(0);
                StreamWriter sw = new StreamWriter(this.Stream, Encoding.UTF8);
                sw.Write(this.textBox_content.Text);
                */
            }

            if (this.Stream != null)
                this.Stream.Seek(0, SeekOrigin.Begin);

            // 保存配置文件
            string strError = "";
            byte[] baOutputTimestamp = null;
            string strOutputPath = "";
            string strStyle = "";

            if (this.checkBox_autoCreate.Checked == true)
            {
                if (strStyle != "")
                    strStyle += ",";
                strStyle += "autocreatedir";
            }


            StringUtil.ChangeMetaData(ref strMetaData,
                null,	// string strID,
                this.LocalPath,	// string strLocalPath,
                this.Mime,	// string strMimeType,
                null,	// string strLastModified,
                null,	// string strPath,
                null);	// string strTimestamp)

            string strRange = "";
            if (this.Stream != null && this.Stream.Length != 0)
            {
                Debug.Assert(this.Stream.Length != 0, "test");
                strRange = "0-" + Convert.ToString(this.Stream.Length - 1);
            }
            long lRet = channel.DoSaveResObject(this.Path,
                this.Stream,
                (this.Stream != null && this.Stream.Length != 0) ? this.Stream.Length : 0,
                strStyle,
                strMetaData,	// strMetadata,
                strRange,
                true,
                this.TimeStamp,	// timestamp,
                out baOutputTimestamp,
                out strOutputPath,
                out strError);

            /*
            // 保存配置文件
            byte[] baOutputTimeStamp = null;
            string strOutputPath = "";
            string strError = "";


            long lRet = channel.DoSaveTextRes(this.Path,
                this.textBox_content.Text,
                true,	// bInlucdePreamble
                "",	// style
                this.TimeStamp,
                out baOutputTimeStamp,
                out strOutputPath,
                out strError);
            */

            if (stopManager != null)
            {
                stop.EndLoop();
                stop.OnStop -= new StopEventHandler(this.DoStop);
                stop.Initial("");
            }

            if (lRet == -1)
            {
                MessageBox.Show(this, strError);
                goto FINISH;
            }

            this.TimeStamp = baOutputTimestamp;

            MessageBox.Show(this, "配置文件 '" + this.Path + "' 保存成功");


            /////////////
        FINISH:

            if (stopManager != null && stop != null)
            {

                stop.Unregister();	// 和容器关联
                stop = null;
            }

            this.channel = null;

            this.DialogResult = DialogResult.OK;
            this.Close();
        }
Пример #19
0
        /*
        // 将内存对象创建为真正的服务器端对象
        public int BuildRealObjects(
            string strDbName,
            DatabaseObject root,
            out string strError)
        {
            strError = "";

            int nRet = 0;

            // 创建根
            if (root.Type != -1)
            {
                if (root.Type == ResTree.RESTYPE_DB)
                    goto DOCHILD;	// 忽略本节点,但是继续作下级节点


                // 缺省配置文件,忽略保存
                if (root.IsDefaultFile() == true)
                    return 0;

                MemoryStream stream = null;
					
                if (root.Type == ResTree.RESTYPE_FILE)
                    stream = new MemoryStream(root.Content);

                string strPath = root.MakePath(strDbName);
// 在服务器端创建对象
                nRet = NewServerSideObject(strPath,
                    root.Type,
                    stream,
                    root.TimeStamp,
                    out strError);
                if (nRet == -1)
                    return -1;
            }

            DOCHILD:
            // 递归
            for(int i=0;i<root.Children.Count;i++)
            {
                DatabaseObject obj = (DatabaseObject)root.Children[i];

                nRet = BuildRealObjects(
                    strDbName,
                    obj,
                    out strError);
                if (nRet == -1)
                    return -1;
            }


            return 0;
        }
        */


        // 根据路径创建内存对象
        public int CreateObject(DatabaseObject obj,
            string strPath,
            out string strError)
        {
            strError = "";
            obj.Children.Clear();


            if (obj.Type == ResTree.RESTYPE_FILE)
            {
                byte[] baTimeStamp = null;
                string strMetaData;
                string strOutputPath;


                this.channel = Channels.GetChannel(this.ServerUrl);

                Debug.Assert(channel != null, "Channels.GetChannel() 异常");


                // string strStyle = "attachment,data,timestamp,outputpath";
                string strStyle = "content,data,timestamp,outputpath";
                using (MemoryStream stream = new MemoryStream())
                {

                    long lRet = channel.GetRes(strPath,
                        stream,
                        null,	// stop,
                        strStyle,
                        null,	// byte [] input_timestamp,
                        out strMetaData,
                        out baTimeStamp,
                        out strOutputPath,
                        out strError);
                    if (lRet == -1)
                    {
                        // obj.SetData(null);
                        obj.TimeStamp = null;
                        return 0;	// 继续处理
                    }

                    obj.SetData(stream);
                    obj.TimeStamp = baTimeStamp;
                }
            }

            if (obj.Type == ResTree.RESTYPE_DB
                || obj.Type == ResTree.RESTYPE_FOLDER)
            {

                this.channel = Channels.GetChannel(this.ServerUrl);

                Debug.Assert(channel != null, "Channels.GetChannel() 异常");

                ResInfoItem[] items = null;

                DigitalPlatform.Stop stop = null;

                if (stopManager != null)
                {
                    stop = new DigitalPlatform.Stop();
                    stop.Register(this.stopManager, true);	// 和容器关联

                    stop.OnStop += new StopEventHandler(this.DoStop);
                    stop.Initial("正在列目录: " + this.ServerUrl + "?" + strPath);

                    stop.BeginLoop();
                }

                long lRet = channel.DoDir(strPath,
                    this.Lang,
                    null,   // 不需要返回全部语言的名字
                    out items,
                    out strError);

                if (stopManager != null)
                {
                    stop.EndLoop();
                    stop.OnStop -= new StopEventHandler(this.DoStop);
                    stop.Initial("");

                    stop.Unregister();	// 和容器关联
                }

                this.channel = null;

                if (lRet == -1)
                    return -1;

                if (items == null)
                    return 0;

                for (int i = 0; i < items.Length; i++)
                {
                    // 忽略from类型节点
                    if (items[i].Type == ResTree.RESTYPE_FROM)
                        continue;

                    DatabaseObject child = new DatabaseObject();
                    child.Name = items[i].Name;
                    child.Type = items[i].Type;
                    child.Style = items[i].Style;

                    child.Parent = obj;
                    obj.Children.Add(child);

                    int nRet = CreateObject(child,
                        strPath + "/" + items[i].Name,
                        out strError);
                    if (nRet == -1)
                        return -1;

                }
            }




            return 0;
        }
Пример #20
0
        private void ChangePasswordDlg_Load(object sender, System.EventArgs e)
        {
            textBox_url.Text = Url;
            textBox_userName.Text = UserName;
            stopManager.Initial(button_Cancel,
                label_message,
                null);
            stopManager.LinkReverseButton(button_OK);

            stop = new DigitalPlatform.Stop();
            stop.Register(this.stopManager, true);	// 和容器关联
        }
Пример #21
0
        int ManageKeysIndex(
            string strDbUrl,
            string strAction,
            string strMessage,
            out string strError)
        {
            strError = "";

            ResPath respath = null;
            if (strDbUrl == null)
            {
                if (this.SelectedNode == null)
                {
                    strError = "尚未选择要要操作的数据库节点";
                    goto ERROR1;
                }

                if (this.SelectedNode.ImageIndex != RESTYPE_DB)
                {
                    strError = "所选择的节点不是数据库类型。请选择要操作的数据库节点。";
                    goto ERROR1;
                }
                respath = new ResPath(this.SelectedNode);
            }
            else
                respath = new ResPath(strDbUrl);

            this.channel = Channels.GetChannel(respath.Url);
            Debug.Assert(channel != null, "Channels.GetChannel() 异常");

#if NO
            DigitalPlatform.Stop stop = null;

            if (stopManager != null)
            {
                stop = new DigitalPlatform.Stop();

                stop.Register(this.stopManager, true);	// 和容器关联

                stop.OnStop += new StopEventHandler(this.DoStop);
                stop.Initial("正在导出数据 " + respath.FullPath);
                stop.BeginLoop();
            }
#endif
            DigitalPlatform.Stop stop = PrepareStop(
                strMessage == null ?
                "正在对 " + respath.FullPath + " 进行管理操作 " + strAction + " ..."
                : strMessage);

            TimeSpan old_timeout = channel.Timeout;
            if (strAction == "endfastappend")
            {
                // 收尾阶段可能要耗费很长的时间
                channel.Timeout = new TimeSpan(3, 0, 0);
            }

            try
            {
                long lRet = channel.DoRefreshDB(
                    strAction,
                    respath.Path,
                    false,
                    out strError);
                if (lRet == -1)
                {
                    strError = "管理数据库 '" + respath.Path + "' 时出错: " + strError;
                    goto ERROR1;
                }

            }
            finally
            {
                EndStop(stop);
#if NO
                if (stopManager != null)
                {
                    stop.EndLoop();
                    stop.OnStop -= new StopEventHandler(this.DoStop);
                    stop.Initial("");

                    stop.Unregister();	// 和容器脱离关联
                }
#endif
                if (strAction == "endfastappend")
                {
                    channel.Timeout = old_timeout;
                }

                this.channel = null;
            }
            return 0;
        ERROR1:
            return -1;
        }