Esempio n. 1
0
        private static void CheckModelVersion(string version, IModuleConfigData envInfo)
        {
            I18N       i18N         = I18N.GetInstance(Constants.I18nName);
            const char versionDelim = '.';

            string[] versionElem = version.Split(versionDelim);
            string   envVersion  = envInfo.GetProperty <string>(Constants.VersionName);

            string[] envVersionElem  = envVersion.Split(versionDelim);
            int      versionElemSize = versionElem.Length <= envVersionElem.Length
                ? versionElem.Length
                : envVersionElem.Length;

            for (int i = 0; i < versionElemSize; i++)
            {
                int versionId    = int.Parse(versionElem[i]);
                int envVersionId = int.Parse(envVersionElem[i]);
                if (versionId > envVersionId)
                {
                    throw new TestflowDataException(ModuleErrorCode.InvalidModelVersion,
                                                    i18N.GetStr("InvalidModelVersion"));
                }
            }
            for (int i = envVersionElem.Length; i < versionElem.Length; i++)
            {
                if (int.Parse(versionElem[i]) > 0)
                {
                    throw new TestflowDataException(ModuleErrorCode.InvalidModelVersion,
                                                    i18N.GetStr("InvalidModelVersion"));
                }
            }
        }
Esempio n. 2
0
        // 使用TypeDescription信息更新VariableTypes和Class中的ClassType信息
        public static void ValidateComDescription(ISequenceManager sequenceManager, ComInterfaceDescription description,
                                                  DescriptionDataTable descriptionCollection)
        {
            int componentId = description.ComponentId;

            foreach (ITypeDescription typeDescription in description.TypeDescriptions)
            {
                ITypeData classType = GetTypeDataByDescription(sequenceManager, descriptionCollection, typeDescription);
                description.VariableTypes.Add(classType);
                if (null != typeDescription.Enumerations)
                {
                    description.Enumerations.Add(GetFullName(typeDescription), typeDescription.Enumerations);
                }
            }
            description.TypeDescriptions.Clear();
            description.TypeDescriptions = null;
            ((List <ITypeData>)description.VariableTypes).TrimExcess();

            foreach (ClassInterfaceDescription classDescription in description.Classes)
            {
                ITypeData classType = GetTypeDataByDescription(sequenceManager, descriptionCollection,
                                                               classDescription.ClassTypeDescription);
                classDescription.ClassType            = classType;
                classDescription.ClassTypeDescription = null;
            }
            ((List <IClassInterfaceDescription>)description.Classes).TrimExcess();

            I18N i18N = I18N.GetInstance(Constants.I18nName);

            foreach (IClassInterfaceDescription classDescription in description.Classes)
            {
                foreach (IFuncInterfaceDescription functionDescription in classDescription.Functions)
                {
                    // 配置实例属性配置方法和静态属性配置方法的描述信息
                    if (functionDescription.FuncType == FunctionType.InstancePropertySetter)
                    {
                        functionDescription.Description = i18N.GetStr("InstancePropertySetter");
                    }
                    else if (functionDescription.FuncType == FunctionType.StaticPropertySetter)
                    {
                        functionDescription.Description = i18N.GetStr("StaticPropertySetter");
                    }
                    foreach (IArgumentDescription argumentDescription in functionDescription.Arguments)
                    {
                        InitializeArgumentType(sequenceManager, descriptionCollection, argumentDescription);
                    }
                    ((List <IArgumentDescription>)functionDescription.Arguments).TrimExcess();
                    functionDescription.ClassType = classDescription.ClassType;
                    if (null != functionDescription.Return)
                    {
                        InitializeArgumentType(sequenceManager, descriptionCollection, functionDescription.Return);
                    }
                }
            }
        }
Esempio n. 3
0
        private void button_Save_Click(object sender, EventArgs e)
        {
            _fpsItem.Title        = textBox_Title.Text;
            _fpsItem.Description  = textBox_Description.Text;
            _fpsItem.Input        = textBox_Input.Text;
            _fpsItem.Output       = textBox_Output.Text;
            _fpsItem.SampleInput  = textBox_SampleInput.Text.Replace("\r\n", "\n").Replace("\r", "\n");
            _fpsItem.SampleOutput = textBox_SampleOutput.Text.Replace("\r\n", "\n").Replace("\r", "\n");
            _fpsItem.Hint         = textBox_Hint.Text;
            _fpsItem.Source       = textBox_Source.Text;

            if (!_fpsItem.SampleInput.EndsWith("\n"))
            {
                _fpsItem.SampleInput += "\n";
            }

            if (!_fpsItem.SampleOutput.EndsWith("\n"))
            {
                _fpsItem.SampleOutput += "\n";
            }

            MainForm.Singleton.FPSListBinder.Flush();

            MessageBox.Show(I18N.GetStr("Save successful!"));
            this.Close();
        }
Esempio n. 4
0
 /// <summary>
 /// 创建日志服务实例
 /// </summary>
 public LogService()
 {
     if (null != _inst)
     {
         I18N i18N = I18N.GetInstance(Constants.I18NName);
         throw new TestflowRuntimeException(CommonErrorCode.InternalError, i18N.GetStr("InstAlreadyExist"));
     }
     lock (_instLock)
     {
         Thread.MemoryBarrier();
         if (null != _inst)
         {
             I18N i18N = I18N.GetInstance(Constants.I18NName);
             throw new TestflowRuntimeException(CommonErrorCode.InternalError, i18N.GetStr("InstAlreadyExist"));
         }
         _runtimeLogSessions = new Dictionary <int, LocalLogSession>(Constants.DefaultLogStreamSize);
         I18NOption i18NOption = new I18NOption(this.GetType().Assembly, "i18n_logger_zh", "i18n_logger_en")
         {
             Name = Constants.I18NName
         };
         _i18N         = I18N.GetInstance(i18NOption);
         _testflowInst = TestflowRunner.GetInstance();
         _context      = _testflowInst.Context;
         _inst         = this;
     }
 }
Esempio n. 5
0
        public SequenceManager()
        {
            if (null != _instance)
            {
                I18N i18N = I18N.GetInstance(Constants.I18nName);
                throw new TestflowRuntimeException(CommonErrorCode.InternalError, i18N.GetStr("InstAlreadyExist"));
            }
            lock (_instLock)
            {
                Thread.MemoryBarrier();
                if (null != _instance)
                {
                    I18N i18N = I18N.GetInstance(Constants.I18nName);
                    throw new TestflowRuntimeException(CommonErrorCode.InternalError, i18N.GetStr("InstAlreadyExist"));
                }
                I18NOption i18NOption = new I18NOption(this.GetType().Assembly, "i18n_sequence_zh", "i18n_sequence_en")
                {
                    Name = Constants.I18nName
                };
                I18N.InitInstance(i18NOption);

                this.ConfigData = null;
                this.Version    = string.Empty;
                _instance       = this;
            }
        }
Esempio n. 6
0
        public EngineHandle()
        {
            I18NOption i18NOption = new I18NOption(typeof(EngineHandle).Assembly, "i18n_engineCore_zh.resx",
                                                   "i18n_engineCore_en.resx")
            {
                Name = Constants.I18nName
            };

            I18N.InitInstance(i18NOption);

            if (null != _instance)
            {
                I18N i18N = I18N.GetInstance(Constants.I18nName);
                throw new TestflowRuntimeException(CommonErrorCode.InternalError, i18N.GetStr("InstAlreadyExist"));
            }
            lock (_instLock)
            {
                Thread.MemoryBarrier();
                if (null != _instance)
                {
                    I18N i18N = I18N.GetInstance(Constants.I18nName);
                    throw new TestflowRuntimeException(CommonErrorCode.InternalError, i18N.GetStr("InstAlreadyExist"));
                }
                _instance = this;
            }
        }
Esempio n. 7
0
        private void SplitFPSFile()
        {
            int size;

            if (!Int32.TryParse(textBox_Size.Text, out size))
            {
                MessageBox.Show(I18N.GetStr("Size must be a number."));
                return;
            }

            int            outputNum      = 1;
            List <FPSItem> itemBufferList = new List <FPSItem>();
            int            nowSize        = 0;

            foreach (FPSItem item in _fpsItemList)
            {
                nowSize += item.TestDataSize / 1024 / 1024;
                itemBufferList.Add(item);

                if (nowSize >= size)
                {
                    WriteFPSFile(itemBufferList, textBox_OutputDir.Text, textBox_Prefix.Text, outputNum++);

                    itemBufferList.Clear();
                    nowSize = 0;
                }
            }

            if (itemBufferList.Count > 0)
            {
                WriteFPSFile(itemBufferList, textBox_OutputDir.Text, textBox_Prefix.Text, outputNum++);
            }
        }
Esempio n. 8
0
        public static SequenceGroup LoadSequenceGroup(string seqFilePath, bool forceLoad, IModuleConfigData envInfo)
        {
            seqFilePath = ModuleUtils.GetAbsolutePath(seqFilePath, Directory.GetCurrentDirectory());

            if (!seqFilePath.EndsWith($".{CommonConst.SequenceFileExtension}"))
            {
                I18N i18N = I18N.GetInstance(Constants.I18nName);
                throw new TestflowDataException(ModuleErrorCode.InvalidFileType, i18N.GetStr("InvalidFileType"));
            }
            SequenceGroup sequenceGroup = XmlReaderHelper.ReadSequenceGroup(seqFilePath);


            // 需要单独配置Setup和TearDown的索引号
            sequenceGroup.SetUp.Index    = CommonConst.SetupIndex;
            sequenceGroup.TearDown.Index = CommonConst.TeardownIndex;

            string paramFilePath             = ModuleUtils.GetAbsolutePath(sequenceGroup.Info.SequenceParamFile, seqFilePath);
            SequenceGroupParameter parameter =
                XmlReaderHelper.ReadSequenceGroupParameter(paramFilePath);

            if (!forceLoad && !sequenceGroup.Info.Hash.Equals(parameter.Info.Hash))
            {
                I18N i18N = I18N.GetInstance(Constants.I18nName);
                throw new TestflowDataException(ModuleErrorCode.UnmatchedFileHash, i18N.GetStr("UnmatchedHash"));
            }
            sequenceGroup.Parameters = parameter;
            SetParameterToSequenceData(sequenceGroup, parameter);
            ValidateTypeDatas(sequenceGroup);

            sequenceGroup.Info.SequenceGroupFile = seqFilePath;
            sequenceGroup.Info.SequenceParamFile = paramFilePath;
            return(sequenceGroup);
        }
Esempio n. 9
0
        //todo I18n
        public void RemoveSequenceStep(ISequenceFlowContainer parent, ISequenceStep step)
        {
            bool removed = false;

            if (parent is ISequence)
            {
                removed = ((ISequence)parent).Steps.Remove(step);
            }
            else if (parent is ISequenceStep)
            {
                ISequenceStep parentStep = (ISequenceStep)parent;
                if (parentStep.StepType == SequenceStepType.TryFinallyBlock ||
                    parentStep.StepType == SequenceStepType.SequenceCall)
                {
                    I18N i18N = I18N.GetInstance(Constants.I18nName);
                    throw new TestflowDataException(ModuleErrorCode.InvalidEditOperation,
                                                    i18N.GetStr("InvalidOperation"));
                }
                removed = (parentStep).SubSteps.Remove(step);
            }
            else
            {
                throw new TestflowDataException(ModuleErrorCode.InvalidEditOperation, "Parent needs to be Sequence or SequenceStep");
            }

            //判断成功remove与否
            if (removed)
            {
                ContextSequenceGroupModify();
            }
            else
            {
                throw new TestflowDataException(ModuleErrorCode.TargetNotExist, $"Step {step.Name} could not be found in parent {parent.Name}");
            }
        }
Esempio n. 10
0
        private static ISequence GetSequence(ISequenceGroup sequenceGroup, int index)
        {
            ISequence sequence;

            switch (index)
            {
            case CommonConst.SetupIndex:
                sequence = sequenceGroup.SetUp;
                break;

            case CommonConst.TeardownIndex:
                sequence = sequenceGroup.TearDown;
                break;

            default:
                if (sequenceGroup.Sequences.Count <= index || index < 0)
                {
                    I18N i18N = I18N.GetInstance(UtilityConstants.UtilsName);
                    throw new TestflowDataException(ModuleErrorCode.SequenceDataError,
                                                    i18N.GetStr("CannotFindSequence"));
                }
                sequence = sequenceGroup.Sequences[index];
                break;
            }
            return(sequence);
        }
Esempio n. 11
0
        public ISequenceStep AddSequenceStep(ISequenceFlowContainer parent, IList <ISequenceStep> stepDatas, int index)
        {
            if (parent is ISequence)
            {
                for (int n = 0; n < stepDatas.Count; n++)
                {
                    ((ISequence)parent).Steps.Insert(n + index, stepDatas[n]);
                    stepDatas[n].Parent = parent;
                }
            }
            else if (parent is ISequenceStep)
            {
                for (int n = 0; n < stepDatas.Count; n++)
                {
                    ISequenceStep parentStep = (ISequenceStep)parent;
                    if (parentStep.StepType == SequenceStepType.TryFinallyBlock ||
                        parentStep.StepType == SequenceStepType.SequenceCall)
                    {
                        I18N i18N = I18N.GetInstance(Constants.I18nName);
                        throw new TestflowDataException(ModuleErrorCode.InvalidEditOperation,
                                                        i18N.GetStr("InvalidOperation"));
                    }
                    parentStep.SubSteps.Insert(n + index, stepDatas[n]);
                    stepDatas[n].Parent = parent;
                }
            }
            else
            {
                throw new TestflowDataException(ModuleErrorCode.InvalidEditOperation, "Parent needs to be Sequence or SequenceStep");
            }


            ContextSequenceGroupModify();
            return(stepDatas[0]);
        }
Esempio n. 12
0
        public void I18NEnglishTest()
        {
            I18N.RemoveInstance(I18nName);
            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
            _i18N = I18N.GetInstance(_i18NOption);
            string str = _i18N.GetStr(TestLabel);

            Assert.AreEqual(str, i18n_test_en.TestLabel);
        }
Esempio n. 13
0
        private void replaceNewLineToNToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string message =
                I18N.GetStr("This operation will replace all NewLine Chars of TestData to \\n(Linux). Are you sure ? ");

            if (MessageBox.Show(message, "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                ReplaceItemsNewLineToLinux();
                MessageBox.Show(I18N.GetStr("Replace successful!"));
            }
        }
Esempio n. 14
0
        private void searchToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SearchForm searchForm = new SearchForm();

            searchForm.ShowDialog();

            if (searchForm.Result.Item1)
            {
                int count = FPSListBinder.Search(searchForm.Result.Item2, searchForm.Result.Item3);
                MessageBox.Show(count.ToString(), I18N.GetStr("Result Count"));
            }
        }
Esempio n. 15
0
 private void button_Split_Click(object sender, EventArgs e)
 {
     try
     {
         SplitFPSFile();
         MessageBox.Show(I18N.GetStr("Split successful!"));
     }
     catch
     {
         MessageBox.Show(I18N.GetStr("Split failed!"));
     }
 }
Esempio n. 16
0
 private void button_Search_Click(object sender, EventArgs e)
 {
     if (string.IsNullOrEmpty(textBox_Description.Text) &&
         string.IsNullOrEmpty(textBox_Title.Text))
     {
         MessageBox.Show(I18N.GetStr("Keywords can not be empty."));
         return;
     }
     Result = new Tuple <bool, string, string>(true, textBox_Title.Text, textBox_Description.Text);
     this.Hide();
     this.Close();
 }
Esempio n. 17
0
        /// <summary>
        /// 创建库类型属性实例
        /// </summary>
        public TestflowCategoryAttribute(LibraryCategory category)
        {
            I18NOption i18NOption = new I18NOption(Assembly.GetAssembly(this.GetType()), "i18n_userlib_zh",
                                                   "i18n_userlib_en")
            {
                Name = Constants.I18nName
            };

            I18N.InitInstance(i18NOption);
            I18N i18N = I18N.GetInstance(Constants.I18nName);

            this.Category       = category;
            this.CategoryString = i18N.GetStr(category.ToString());
        }
Esempio n. 18
0
        /// <summary>
        /// 创建库类型属性实例
        /// </summary>
        /// <param name="categoryString"></param>
        public TestflowCategoryAttribute(string categoryString)
        {
            I18NOption i18NOption = new I18NOption(Assembly.GetAssembly(this.GetType()), "i18n_userlib_zh",
                                                   "i18n_userlib_en")
            {
                Name = Constants.I18nName
            };

            I18N.InitInstance(i18NOption);
            I18N i18N = I18N.GetInstance(Constants.I18nName);

            this.CategoryString = i18N.GetStr(categoryString) ?? categoryString;
            Category            = LibraryCategory.Miscellaneous;
        }
Esempio n. 19
0
        public static void LoadParameter(SequenceGroup sequenceGroup, string filePath, bool forceLoad)
        {
            filePath = ModuleUtils.GetAbsolutePath(filePath, Directory.GetCurrentDirectory());
            SequenceGroupParameter parameter = XmlReaderHelper.ReadSequenceGroupParameter(filePath);

            if (!forceLoad && !sequenceGroup.Info.Hash.Equals(parameter.Info.Hash))
            {
                I18N i18N = I18N.GetInstance(Constants.I18nName);
                throw new TestflowDataException(ModuleErrorCode.UnmatchedFileHash, i18N.GetStr("UnmatchedHash"));
            }
            sequenceGroup.Parameters = parameter;
            SetParameterToSequenceData(sequenceGroup, parameter);
            ValidateTypeDatas(sequenceGroup);
        }
Esempio n. 20
0
        public static TestProject LoadTestProject(string filePath, bool forceLoad, IModuleConfigData envInfo)
        {
            filePath = ModuleUtils.GetAbsolutePath(filePath, Directory.GetCurrentDirectory());

            if (!filePath.EndsWith($".{CommonConst.TestGroupFileExtension}"))
            {
                I18N i18N = I18N.GetInstance(Constants.I18nName);
                throw new TestflowRuntimeException(ModuleErrorCode.InvalidFileType, i18N.GetStr("InvalidFileType"));
            }
            TestProject testProject = null;

            testProject = XmlReaderHelper.ReadTestProject(filePath);

            // 需要单独配置Setup和TearDown的索引号
            testProject.SetUp.Index    = CommonConst.SetupIndex;
            testProject.TearDown.Index = CommonConst.TeardownIndex;

            CheckModelVersion(testProject.ModelVersion, envInfo);
            foreach (ISequenceGroup sequenceGroup in testProject.SequenceGroups)
            {
                CheckModelVersion(sequenceGroup.Info.Version, envInfo);
            }
            foreach (SequenceGroupLocationInfo sequenceGroupLocation in testProject.SequenceGroupLocations)
            {
                SequenceGroup sequenceGroup = null;

                string sequenceGroupFile = ModuleUtils.GetAbsolutePath(sequenceGroupLocation.SequenceFilePath, filePath);
                if (File.Exists(sequenceGroupFile))
                {
                    sequenceGroup        = LoadSequenceGroup(sequenceGroupFile, forceLoad, envInfo);
                    sequenceGroup.Parent = testProject;
                }
                else
                {
                    ILogService logService = TestflowRunner.GetInstance().LogService;
                    logService.Print(LogLevel.Warn, CommonConst.PlatformLogSession, 0, "Sequence group file not exist.");
                    sequenceGroup = new SequenceGroup();
                    sequenceGroup.Initialize(testProject);
                    sequenceGroup.Info.SequenceGroupFile = sequenceGroupFile;
                    sequenceGroup.Available = false;
                }
                testProject.SequenceGroups.Add(sequenceGroup);
            }
            ValidateTypeDatas(testProject);

            return(testProject);
        }
Esempio n. 21
0
        public static SequenceGroup ReadSequenceGroup(string filePath)
        {
            if (!filePath.EndsWith($".{CommonConst.SequenceFileExtension}"))
            {
                I18N i18N = I18N.GetInstance(Constants.I18nName);
                throw new TestflowDataException(ModuleErrorCode.InvalidFileType, i18N.GetStr("InvalidFileType"));
            }
            XmlReader reader = null;

            try
            {
                reader = CreateXmlReader(filePath);
                Dictionary <string, Type> typeMapping = GetTypeMapping();
                // 找到TestProject节点后跳出
                while (reader.Read())
                {
                    if (XmlNodeType.Element != reader.NodeType)
                    {
                        continue;
                    }
                    if (typeof(SequenceGroup).Name.Equals(reader.Name))
                    {
                        break;
                    }
                }
                SequenceGroup sequenceGroup = new SequenceGroup();
                FillDataToObject(reader, sequenceGroup, typeMapping);
                return(sequenceGroup);
            }
            catch (ArgumentException ex)
            {
                ILogService logService = TestflowRunner.GetInstance().LogService;
                logService.Print(LogLevel.Error, CommonConst.PlatformLogSession, 0, ex);
                throw new TestflowDataException(ModuleErrorCode.DeSerializeFailed, ex.Message, ex);
            }
            catch (IOException ex)
            {
                ILogService logService = TestflowRunner.GetInstance().LogService;
                logService.Print(LogLevel.Error, CommonConst.PlatformLogSession, 0, ex);
                throw new TestflowRuntimeException(ModuleErrorCode.DeSerializeFailed, ex.Message, ex);
            }
            finally
            {
                reader?.Close();
            }
        }
Esempio n. 22
0
 /// <summary>
 /// 获取或创建当前AppDomain下的FlowRunner实例
 /// </summary>
 /// <returns></returns>
 public static TestflowRunner GetInstance()
 {
     if (null != _runnerInst)
     {
         return(_runnerInst);
     }
     lock (_instLock)
     {
         if (null != _runnerInst)
         {
             I18N i18N = I18N.GetInstance(CommonConst.I18nName);
             throw new TestflowInternalException(CommonErrorCode.InternalError,
                                                 i18N.GetStr("PlatformNotInitialized"));
         }
     }
     return(_runnerInst);
 }
Esempio n. 23
0
        private void PrintRuntimeStatus(StreamWriter sw, string runtimeHash, int sessionId, int sequenceIndex)
        {
            const int    stepNameLength   = 3;
            const int    recordTimeLength = 4;
            const int    resultLength     = 2;
            const int    failInfoLength   = 5;
            const string preOffset        = "\t\t";

            IList <RuntimeStatusData> runtimeStatus = _dataMaintainer.GetRuntimeStatus(runtimeHash, sessionId, sequenceIndex);

            if (runtimeStatus.Count > 1)
            {
                sw.WriteLine(preOffset + _i18n.GetStr("RuntimeStatusName"));
                StringBuilder tableContent    = new StringBuilder(300);
                string        stepNameTitle   = _i18n.GetStr("StepNameTitle");
                string        recordTimeTitle = _i18n.GetStr("RecordTimeTitle");
                string        resultTitle     = _i18n.GetStr("StepResultTitle");
                string        failInfoTitle   = _i18n.GetStr("FailedInfoTitle");

                tableContent.Append(preOffset).Append(stepNameTitle).Append(GetDelimTab(stepNameTitle, stepNameLength));
                tableContent.Append(recordTimeTitle).Append(GetDelimTab(recordTimeTitle, recordTimeLength));
                tableContent.Append(resultTitle).Append(GetDelimTab(resultTitle, resultLength));
                tableContent.Append(failInfoTitle).Append(GetDelimTab(failInfoTitle, failInfoLength));

                sw.WriteLine(tableContent.ToString());
                int titleLength = Encoding.GetEncoding("GBK").GetByteCount(tableContent.ToString());
                titleLength += 30;
                tableContent.Clear();
                tableContent.Append(preOffset);
                for (int i = 0; i < titleLength - 2; i++)
                {
                    tableContent.Append("-");
                }
                sw.WriteLine(tableContent.ToString());
                for (int i = 0; i < runtimeStatus.Count - 1; i++)
                {
                    tableContent.Clear();
                    tableContent.Append(preOffset);
                    string stepName = runtimeStatus[i].Stack;
                    string time     = runtimeStatus[i].Time.ToString(DateFormat);
                    string result   = runtimeStatus[i].Result.ToString();
                    string failInfo = runtimeStatus[i].FailedInfo?.Message ?? string.Empty;
                    tableContent.Append(stepName).Append(GetDelimTab(stepName, stepNameLength));
                    tableContent.Append(time).Append(GetDelimTab(time, recordTimeLength));
                    tableContent.Append(result).Append(GetDelimTab(result, resultLength));
                    tableContent.Append(failInfo).Append(GetDelimTab(stepName, failInfoLength));
                    sw.WriteLine(tableContent.ToString());
                }
                sw.WriteLine("");
            }
        }
Esempio n. 24
0
        private void CheckPropertyDescription(ITypeData typeData, string property)
        {
            if (null != _loader.Exception)
            {
                return;
            }
            I18N        i18N       = I18N.GetInstance(Constants.I18nName);
            ILogService logService = TestflowRunner.GetInstance().LogService;

            switch (_loader.ErrorCode)
            {
            case ModuleErrorCode.LibraryLoadError:
                logService.Print(LogLevel.Error, CommonConst.PlatformLogSession, _loader.Exception,
                                 $"Assembly '{typeData.AssemblyName}' load error.");
                throw new TestflowRuntimeException(ModuleErrorCode.LibraryLoadError,
                                                   i18N.GetStr("RuntimeError"));
                break;

            case ModuleErrorCode.PropertyNotFound:
                logService.Print(LogLevel.Error, CommonConst.PlatformLogSession, _loader.Exception,
                                 $"Property '{property}' of type '{typeData.Name}' does not exist.");
                throw new TestflowRuntimeException(ModuleErrorCode.PropertyNotFound,
                                                   i18N.GetFStr("PropertyNotFound", typeData.Name, property));
                break;

            case ModuleErrorCode.TypeCannotLoad:
                logService.Print(LogLevel.Error, CommonConst.PlatformLogSession, _loader.Exception,
                                 $"Type '{typeData.Name}' does not exist.");
                throw new TestflowRuntimeException(ModuleErrorCode.TypeCannotLoad,
                                                   i18N.GetFStr("TypeNotFound", typeData.Name));
                break;

            case ModuleErrorCode.AssemblyNotLoad:
                logService.Print(LogLevel.Error, CommonConst.PlatformLogSession, _loader.Exception,
                                 $"Assemly '{typeData.AssemblyName}' does not exist.");
                throw new TestflowRuntimeException(ModuleErrorCode.AssemblyNotLoad,
                                                   i18N.GetFStr("AssemblyNotLoad", typeData.AssemblyName));
                break;

            default:
                break;
            }
        }
Esempio n. 25
0
        public static void LogAndRaiseRuntimeException(LogLevel level, string logInfo, int errorCode,
                                                       Exception innerException, string message, params string[] param)
        {
            I18N        i18N       = I18N.GetInstance(Constants.I18nName);
            ILogService logService = TestflowRunner.GetInstance().LogService;

            string exMessage = (null == param || 0 == param.Length)
                ? i18N.GetStr(message)
                : i18N.GetFStr(message, param);

            if (null == innerException)
            {
                logService.Print(level, CommonConst.PlatformLogSession, logInfo);
                throw new TestflowRuntimeException(errorCode, exMessage);
            }
            else
            {
                logService.Print(level, CommonConst.PlatformLogSession, innerException, logInfo);
                throw new TestflowRuntimeException(errorCode, exMessage, innerException);
            }
        }
Esempio n. 26
0
        private static string GetDotNetRootDir()
        {
            string windDir = Environment.GetEnvironmentVariable(Constants.WindirVar);

            if (string.IsNullOrWhiteSpace(windDir))
            {
                I18N i18N = I18N.GetInstance(Constants.I18nName);
                throw new TestflowRuntimeException(ModuleErrorCode.InvalidEnvDir, i18N.GetStr("InvalidDotNetDir"));
            }
            if (!windDir.EndsWith(Path.DirectorySeparatorChar.ToString()))
            {
                windDir += Path.DirectorySeparatorChar;
            }
            string dotNetRootDir = string.Format(Constants.DotNetRootDirFormat, windDir);

            if (!Directory.Exists(dotNetRootDir))
            {
                I18N i18N = I18N.GetInstance(Constants.I18nName);
                throw new TestflowRuntimeException(ModuleErrorCode.InvalidEnvDir, i18N.GetStr("InvalidDotNetDir"));
            }
            return(dotNetRootDir);
        }
Esempio n. 27
0
        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();

            saveFileDialog.FileName = "freeproblemset.xml";
            saveFileDialog.Filter   = "*.xml|XML File";

            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    using (FileStream fs = new FileStream(saveFileDialog.FileName, FileMode.Create))
                    {
                        new FPSParser().ConvertToStream(FPSListBinder.FPSItemList.ToArray(), fs);
                    }
                    MessageBox.Show(I18N.GetStr("Save successful!"));
                }
                catch
                {
                    MessageBox.Show(I18N.GetStr("Save failed!"));
                }
            }
        }
Esempio n. 28
0
 /// <summary>
 /// 通过索引号获取Sequence
 /// </summary>
 public static ISequence GetSequence(ISequenceFlowContainer sequenceData, int sessionId, int sequence)
 {
     if (sequenceData is ITestProject)
     {
         ITestProject testProject = (ITestProject)sequenceData;
         if (sessionId == CommonConst.TestGroupSession)
         {
             return(sequence == CommonConst.SetupIndex
                 ? testProject.SetUp
                 : testProject.TearDown);
         }
         else
         {
             if (testProject.SequenceGroups.Count <= sessionId || sessionId < 0)
             {
                 I18N i18N = I18N.GetInstance(UtilityConstants.UtilsName);
                 throw new TestflowDataException(ModuleErrorCode.SequenceDataError,
                                                 i18N.GetStr("CannotFindSequence"));
             }
             return(GetSequence(testProject.SequenceGroups[sessionId], sequence));
         }
     }
     else if (sequenceData is ISequenceGroup)
     {
         return(GetSequence((ISequenceGroup)sequenceData, sequence));
     }
     else if (sequenceData is ISequence)
     {
         return((ISequence)sequenceData);
     }
     else
     {
         I18N i18N = I18N.GetInstance(UtilityConstants.UtilsName);
         throw new TestflowDataException(ModuleErrorCode.SequenceDataError, i18N.GetStr("CannotFindSequence"));
     }
 }
Esempio n. 29
0
        protected DatabaseProxy(IModuleConfigData configData, bool isRuntimeModuleModule)
        {
            this.ConfigData = configData;
            IsRuntimeModule = isRuntimeModuleModule;

            I18NOption i18NOption = new I18NOption(this.GetType().Assembly, "i18n_datamaintain_zh", "i18n_datamaintain_en")
            {
                Name = Constants.I18nName
            };

            I18N.InitInstance(i18NOption);
            I18N   = I18N.GetInstance(Constants.I18nName);
            Logger = TestflowRunner.GetInstance().LogService;
            try
            {
                // 使用DbProviderFactory方式连接需要在App.Config文件中定义DbProviderFactories节点
                // 但是App.Config文件只在入口Assembly中时才会被默认加载,所以目前写死为SqlConnection
//                DbProviderFactory factory = DbProviderFactories.GetFactory("System.Data.SQLite");
//                Connection = factory.CreateConnection();
//                if (null == Connection)
//                {
//                    Logger.Print(LogLevel.Fatal, CommonConst.PlatformLogSession, "Connect db failed.");
//                    throw new TestflowRuntimeException(ModuleErrorCode.ConnectDbFailed, I18N.GetStr("ConnectDbFailed"));
//                }
                InitializeDatabaseAndConnection();
            }
            catch (DbException ex)
            {
                Logger.Print(LogLevel.Fatal, CommonConst.PlatformLogSession, ex, "Connect db failed.");
                throw new TestflowRuntimeException(ModuleErrorCode.ConnectDbFailed, I18N.GetStr("ConnectDbFailed"), ex);
            }

            this._databaseLock = new ReaderWriterLockSlim();

            DataModelMapper = new DataModelMapper();
        }
Esempio n. 30
0
 //todo I18n
 public void RemoveSequenceStep(ISequenceFlowContainer parent, int index)
 {
     if (parent is ISequence)
     {
         ((ISequence)parent).Steps.RemoveAt(index);
     }
     else if (parent is ISequenceStep)
     {
         ISequenceStep parentStep = (ISequenceStep)parent;
         if (parentStep.StepType == SequenceStepType.TryFinallyBlock ||
             parentStep.StepType == SequenceStepType.SequenceCall)
         {
             I18N i18N = I18N.GetInstance(Constants.I18nName);
             throw new TestflowDataException(ModuleErrorCode.InvalidEditOperation,
                                             i18N.GetStr("InvalidOperation"));
         }
         (parentStep).SubSteps.RemoveAt(index);
     }
     else
     {
         throw new TestflowDataException(ModuleErrorCode.InvalidEditOperation, "Parent needs to be Sequence or SequenceStep");
     }
     ContextSequenceGroupModify();
 }