Esempio n. 1
0
        public static void Serialize(string seqFilePath, SequenceGroup sequenceGroup)
        {
            VerifySequenceData(sequenceGroup);

            string paramFilePath = ModuleUtils.GetParameterFilePath(seqFilePath);

            SequenceGroupParameter parameter = new SequenceGroupParameter();

            parameter.Initialize(sequenceGroup);
            // 将SequeneGroup配置的参数写入ParameterData中,用以序列化
            FillParameterDataToSequenceData(sequenceGroup, parameter);
            sequenceGroup.RefreshSignature();
            parameter.RefreshSignature(sequenceGroup);
            List <string> serializedFileList = new List <string>(20);

            try
            {
                // 暂时修改序列组文件路径为相对路径
                sequenceGroup.Info.SequenceGroupFile = ModuleUtils.GetFileName(seqFilePath);
                sequenceGroup.Info.SequenceParamFile = ModuleUtils.GetRelativePath(paramFilePath, seqFilePath);

                BackupExistFile(seqFilePath, paramFilePath);

                serializedFileList.Add(seqFilePath);
                XmlWriterHelper.Write(sequenceGroup, seqFilePath);

                serializedFileList.Add(paramFilePath);
                XmlWriterHelper.Write(parameter, paramFilePath);

                DeleteBackupFile(seqFilePath, paramFilePath);
            }
            catch (IOException ex)
            {
                RollBackFilesIfFailed(serializedFileList);
                throw new TestflowRuntimeException(ModuleErrorCode.SerializeFailed, ex.Message, ex);
            }
            catch (ApplicationException)
            {
                RollBackFilesIfFailed(serializedFileList);
                throw;
            }
            finally
            {
                // 恢复序列文件的绝对路径
                sequenceGroup.Info.SequenceGroupFile = seqFilePath;
                sequenceGroup.Info.SequenceParamFile = paramFilePath;
            }
        }