示例#1
0
        public async Task Experiment_ShouldBeFinishedWithoutAnyExceptions(string path, ExperimentInfo experimentInfo)
        {
            // Arrange
            _outputHelper.WriteLine($"Running test with data from '{path}'");

            var experiment = new Experiment
            {
                Id          = Guid.NewGuid(),
                TestsAmount = 1
            };

            var generatorMock = new Mock <IExperimentGenerator>();

            generatorMock.Setup(g =>
                                g.GenerateDataForTest(It.Is <Experiment>(ex => ex.Id == experiment.Id), It.IsAny <int>()))
            .Returns(() => experimentInfo);
            ExperimentInfo resultInfo = null;
            var            experimentTestResultService = new Mock <IExperimentTestResultService>();

            experimentTestResultService
            .Setup(e => e.SaveExperimentTestResult(It.Is <Guid>(id => id == experiment.Id),
                                                   It.IsAny <ExperimentInfo>()))
            .Callback <Guid, ExperimentInfo>((id, info) => resultInfo = info);

            ExperimentReport experimentReport = null;
            var reportServiceMock             = new Mock <IReportsService>();

            reportServiceMock.Setup(x => x.Save(It.Is <ExperimentReport>(r => r.ExperimentId == experiment.Id)))
            .Callback <ExperimentReport>((report) => experimentReport = report);

            var experimentPipeline = new ExperimentPipeline(
                generatorMock.Object,
                Mock.Of <IWorkerExperimentService>(),
                experimentTestResultService.Object,
                reportServiceMock.Object,
                Mock.Of <ILogger <ExperimentPipeline> >(),
                Mock.Of <IOptions <DbSettings> >(),
                new OnlineExecutor());

            // Act
            await experimentPipeline.Run(new[]
            {
                experiment
            }, false, true);

            // Assert
            resultInfo.Should().NotBeNull();
            experimentReport.Should().NotBeNull();
        }
示例#2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.HttpMethod == "POST")
            {
                #region 检查提交信息是否为空。

                //实验名称。
                if (Request.Form["Name"]=="")
                {
                    Response.Write("<script type=\"text/javascript\"> alert('实验大类名称不能为空!');</script>");
                    return;
                }

                //实验照片。
                if (Request.Files["Photo"] == null || Request.Files["Photo"].ContentLength == 0)
                {
                    Response.Write("<script type=\"text/javascript\"> alert('照片不能为空!');</script>");
                    return;
                }
                #endregion
                HttpPostedFile photo = Request.Files["Photo"];
                string photoName = Request.Form["Name"] + DateTime.Now.ToString("yyyy-mm-dd-hh-mm-ss") + "." + photo.ContentType.Split('/')[1];

                ExperimentInfo newExperiment = new ExperimentInfo
                {
                    Name = Request.Form["Name"].Trim(),
                    Semester = presentTerm,
                    //Order=
                    PhotoUrl = "../Datas/Photos/Experiment/" + photoName,
                };

                photo.SaveAs(Request.PhysicalApplicationPath + "Datas\\Photos\\Experiment\\" + photoName);
                LabDB.ExperimentInfo.InsertOnSubmit(newExperiment);
                try
                {
                    LabDB.SubmitChanges();
                    Response.Write("<script type=\"text/javascript\"> alert('添加成功!');</script>");
                    return;
                }
                catch
                {
                    Response.Write("<script type=\"text/javascript\"> alert('发生错误!请重试或联系管理员!');</script>");
                    return;
                }
            }
        }
示例#3
0
        /// <summary>
        /// Get a folder (subfolder) based upon a folder format and experiment information
        /// </summary>
        /// <param name="folderFormat"></param>
        /// <param name="experiment"></param>
        /// <returns>folder string, or String.Empty if there is a formatting problem</returns>
        private string GetSubPath(string folderFormat, ExperimentInfo experiment)
        {
            if (String.IsNullOrEmpty(folderFormat))
            {
                return(string.Empty); // no folder format specified
            }
            if (folderFormat == ConfigurationSettings.NotUsed)
            {
                return(string.Empty); // folder format is "no folder"
            }
            if (folderFormat == ConfigurationSettings.ExperFileName)
            {
                return(string.Empty); // folder format is the experiment file name
            }
            string result = folderFormat;

            List <string>   standardNONTimeConfigs = new List <string>(new[] { ConfigurationSettings.UserID, ConfigurationSettings.ProjectID, ConfigurationSettings.ExperID, ConfigurationSettings.ExperimentSource, ConfigurationSettings.Instrument });
            Regex           regex           = new Regex(@"\{[^}]*\}", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.Multiline | RegexOptions.Singleline);
            MatchCollection matchCollection = regex.Matches(result);

            foreach (Match match in matchCollection)
            {
                if (standardNONTimeConfigs.Contains(match.Value))
                {
                    string toReplaceWith = experiment.ExperimentReference.User;
                    switch (match.Value)
                    {
                    case ConfigurationSettings.ExperID:
                        toReplaceWith = experiment.ExperimentReference.Name;
                        break;

                    case ConfigurationSettings.ProjectID:
                        toReplaceWith = experiment.UserDefinedField ?? String.Empty;
                        break;

                    case ConfigurationSettings.ExperimentSource:
                        toReplaceWith = String.Empty;
                        if (experiment.ExperimentReference != null && experiment.ExperimentReference.Source != null)
                        {
                            if (experiment.ExperimentReference.Source is InstrumentReference)
                            {
                                toReplaceWith = ((InstrumentReference)(experiment.ExperimentReference.Source)).HostAddress;
                            }
                            else if (experiment.ExperimentReference.Source is ApplicationReference)
                            {
                                toReplaceWith = ((ApplicationReference)(experiment.ExperimentReference.Source)).HostAddress;
                            }
                        }
                        break;

                    case ConfigurationSettings.Instrument:
                        toReplaceWith = String.Empty;
                        if (!String.IsNullOrEmpty(experiment.InstrumentType))
                        {
                            toReplaceWith = experiment.InstrumentType;
                        }
                        else if (experiment.ExperimentReference != null && experiment.ExperimentReference.Source != null)
                        {
                            if (experiment.ExperimentReference.Source is InstrumentReference)
                            {
                                toReplaceWith = ((InstrumentReference)(experiment.ExperimentReference.Source)).InstrumentType;
                            }
                            else if (experiment.ExperimentReference.Source is ApplicationReference)
                            {
                                toReplaceWith = ((ApplicationReference)(experiment.ExperimentReference.Source)).Name;
                            }
                        }
                        break;
                    }
                    if (string.IsNullOrWhiteSpace(toReplaceWith))
                    {
                        toReplaceWith = "Unknown";
                    }
                    result = result.Replace(match.Value, toReplaceWith);
                }
                else
                {
                    try
                    {
                        string formatedTime = experiment.StartTime.ToLocalTime().ToString(match.Value.Trim(new[] { '{', '}' }));
                        result = result.Replace(match.Value, formatedTime);
                    }
                    catch (Exception ex)
                    {
                        GC.KeepAlive(ex);
                    }
                }
            }
            char[] invalidFileNameChars = Path.GetInvalidPathChars().Concat(new[] { '\\', ':', '/', '*', '\'', '?' }).Distinct().ToArray();
            if (result.IndexOfAny(invalidFileNameChars) != -1)
            {
                result = invalidFileNameChars.Aggregate(new StringBuilder(result), (currentName, c) => currentName.Replace(c, '_')).ToString();
            }

            return(result);
        }