Example #1
0
        public static void Serialize(string filePath, SequenceGroup sequenceGroup)
        {
            filePath = ModuleUtils.GetAbsolutePath(filePath, Directory.GetCurrentDirectory());

            VerifySequenceData(sequenceGroup);
            sequenceGroup.Info.SequenceGroupFile = filePath;
            sequenceGroup.Info.SequenceParamFile = ModuleUtils.GetParameterFilePath(filePath);

            SequenceGroupParameter parameter = new SequenceGroupParameter();

            parameter.Initialize(sequenceGroup);
            // 将SequeneGroup配置的参数写入ParameterData中,用以序列化
            FillParameterDataToSequenceData(sequenceGroup, parameter);

            List <string> serialziedFileList = new List <string>(20);

            try
            {
                serialziedFileList.Add(filePath);
                XmlWriterHelper.Write(sequenceGroup, sequenceGroup.Info.SequenceGroupFile);

                serialziedFileList.Add(sequenceGroup.Info.SequenceParamFile);
                XmlWriterHelper.Write(parameter, sequenceGroup.Info.SequenceParamFile);
            }
            catch (IOException ex)
            {
                RollBackFilesIfFailed(serialziedFileList);
                throw new TestflowRuntimeException(ModuleErrorCode.SerializeFailed, ex.Message, ex);
            }
            catch (ApplicationException)
            {
                RollBackFilesIfFailed(serialziedFileList);
                throw;
            }
        }
Example #2
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;
            }
        }
Example #3
0
        public static void Serialize(string filePath, TestProject testProject)
        {
            filePath = ModuleUtils.GetAbsolutePath(filePath, Directory.GetCurrentDirectory());

            VerifySequenceData(testProject);
            List <string> serialziedFileList = new List <string>(10);

            try
            {
                // 初始化各个SequenceGroup的文件位置信息
                InitSequenceGroupLocations(testProject, filePath);
                serialziedFileList.Add(filePath);
                XmlWriterHelper.Write(testProject, filePath);
                // 将testProject当前配置的数据信息写入ParameterData中
                FillParameterDataToSequenceData(testProject);
                for (int i = 0; i < testProject.SequenceGroups.Count; i++)
                {
                    SequenceGroup sequenceGroup     = testProject.SequenceGroups[i] as SequenceGroup;
                    string        sequenceGroupPath = ModuleUtils.GetAbsolutePath(sequenceGroup.Info.SequenceGroupFile, filePath);
                    string        parameterFilePath = ModuleUtils.GetAbsolutePath(sequenceGroup.Info.SequenceParamFile, sequenceGroupPath);;
                    if (!ModuleUtils.IsValidFilePath(sequenceGroupPath))
                    {
                        sequenceGroupPath = ModuleUtils.GetSequenceGroupPath(filePath, i);
                        sequenceGroup.Info.SequenceGroupFile = ModuleUtils.GetRelativePath(sequenceGroupPath, filePath);
                        parameterFilePath = ModuleUtils.GetParameterFilePath(sequenceGroupPath);
                        sequenceGroup.Info.SequenceParamFile = ModuleUtils.GetRelativePath(parameterFilePath, sequenceGroupPath);
                    }
                    else if (!ModuleUtils.IsValidFilePath(parameterFilePath))
                    {
                        parameterFilePath = ModuleUtils.GetParameterFilePath(sequenceGroupPath);
                        sequenceGroup.Info.SequenceParamFile = ModuleUtils.GetRelativePath(parameterFilePath, sequenceGroupPath);
                    }
                    SequenceGroupParameter parameter = new SequenceGroupParameter();
                    parameter.Initialize(sequenceGroup);
                    // 将SequeneGroup配置的参数写入ParameterData中,用以序列化
                    FillParameterDataToSequenceData(sequenceGroup, parameter);
                    sequenceGroup.RefreshSignature();
                    parameter.RefreshSignature(sequenceGroup);
                    // 创建sequenceGroupd的文件夹
                    string directory = ModuleUtils.GetSequenceGroupDirectory(sequenceGroupPath);
                    if (!Directory.Exists(directory))
                    {
                        Directory.CreateDirectory(directory);
                    }

                    serialziedFileList.Add(sequenceGroupPath);
                    XmlWriterHelper.Write(sequenceGroup, sequenceGroupPath);

                    serialziedFileList.Add(parameterFilePath);
                    XmlWriterHelper.Write(parameter, parameterFilePath);
                }
            }
            catch (IOException ex)
            {
                RollBackFilesIfFailed(serialziedFileList);
                throw new TestflowRuntimeException(ModuleErrorCode.SerializeFailed, ex.Message, ex);
            }
            catch (ApplicationException)
            {
                RollBackFilesIfFailed(serialziedFileList);
                throw;
            }
        }