Example #1
0
        /// <summary>
        /// 测试一个类型是由拓展形成的图层的单层投影
        /// </summary>
        /// <param name="filename">文件名</param>
        /// <param name="newName">输出新的文件名</param>
        /// <returns>返回测试结果</returns>
        public TestingResult TestLayer(string filename, out string newName)
        {
            newName = filename;
            LayerSource layer = new LayerSource(filename, this as MapWinGIS.ICallback); //打开指定文件的图层

            if (layer.Type == LayerSourceType.Undefined)                                //图层类型是没有定义的
            {
                string message = layer.GetErrorMessage();
                if (message == "")
                {
                    message = "Unspecified error";
                }

                MessageBox.Show("Invalid datasource: " + message.ToLower() + Environment.NewLine + filename, m_mapWin.ApplicationInfo.ApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(TestingResult.Error);
            }
            else
            {
                LayerSource   newLayer = null;
                TestingResult result   = this.TestLayer(layer, out newLayer);
                if (result == TestingResult.Substituted)
                {
                    newName = newLayer.Filename;
                    newLayer.Close();
                }

                layer.Close();
                return(result);
            }
        }
        private static bool CheckForTimeLimit(TestingResult result)
        {
            var test          = result.TestingUrl.Test;
            var testTimeLimit = test.TestTimeLimit;

            if (testTimeLimit == null)
            {
                var questionTimeLimit = test.QuestionTimeLimit;
                if (questionTimeLimit == null)
                {
                    return(true);
                }
                testTimeLimit = TimeSpan.FromTicks(questionTimeLimit.Value.Ticks * test.TestQuestions.Count);
            }

            DateTime startTime;

            if (!_startedQuizzes.TryRemove(result.AttemptGuid, out startTime))
            {
                return(false);
            }
            var actualTime = DateTime.Now - startTime;

            return(actualTime < (testTimeLimit + TimeSpan.FromSeconds(10)));
        }
Example #3
0
        public TestingResultViewModel(TestingResult tr, TaskTest t)
        {
            Score      = tr.Score;
            Commentary = tr.Commentary;
            Result     = tr.ResultCode.ToString();
            TestType   = t.TestType;
            TestName   = TestsNamesConverter.ConvertTypeToName(TestType);

            if (TestsNamesConverter.IsValidType(TestType))
            {
                object obj = null;
                if (tr.TestData != null)
                {
                    switch (TestType)
                    {
                    case "reflectionTest":
                        obj = JsonConvert.DeserializeObject <ReflectionTestResult>(tr.TestData);
                        break;

                    case "functionalTest":
                        obj = JsonConvert.DeserializeObject <FunctionalTestResult>(tr.TestData);
                        break;

                    case "codeStyleTest":
                        obj = JsonConvert.DeserializeObject <CodeStyleTestResult>(tr.TestData);
                        break;
                    }
                }

                Data = obj;
            }
        }
Example #4
0
        /// <summary>
        /// Sell your car (ICar) through dealership
        /// </summary>
        /// <param name="car"> The car to be sold. </param>
        /// <returns> true - car passed the CarTester testing ,
        ///			  false -  car was rejected by CarTester testing
        /// </returns>
        ///
        public TestingResult SellSecondHandCar(ICar car, double sellingCost)
        {
            IServiceState service = Service.GetInstance();

            service.InsertCar(car);
            service.TestCar();

            bool isEligible = service.GetResultsEligible();

            if (isEligible)
            {
                car.Price = sellingCost;
                _secondHandCars.Add(car);
            }

            var result = new TestingResult()
            {
                Passed = service.GetResultsEligible(),
                ResultOfInvestigation = service.GetResultMessage(),
            };


            service.EjectCar();

            return(result);
        }
Example #5
0
 public bool AddUserAnswer(int testingId, TestingResult testResult)
 {
     using (SqlConnection connection = new SqlConnection(_connectionString))
     {
         var command = connection.CreateCommand();
         command.CommandType = CommandType.StoredProcedure;
         command.CommandText = "dbo.AddTestingResult";
         command.Parameters.AddWithValue("@idAnswer", testResult.IdAnswer);
         command.Parameters.AddWithValue("@idTesting", testingId);
         var idParameter = new SqlParameter()
         {
             DbType        = DbType.Int32,
             ParameterName = "@id",
             Value         = testResult.ID,
             Direction     = ParameterDirection.Output,
         };
         command.Parameters.Add(idParameter);
         connection.Open();
         try
         {
             command.ExecuteNonQuery();
             testResult.ID = (int)idParameter.Value;
             return(true);
         }
         catch (SqlException e)
         {
             _log.Error(e.Message);
             throw e;
         }
     }
 }
Example #6
0
        public static TestResponse WriteToDb(HSEContestDbContext _db, TestingResult res, bool recheck)
        {
            bool ok = false;

            if (recheck)
            {
                var existing = _db.TestingResults.FirstOrDefault(r => r.SolutionId == res.SolutionId && r.TestId == res.TestId);

                if (existing != null)
                {
                    existing.Commentary = res.Commentary;
                    existing.ResultCode = res.ResultCode;
                    existing.Score      = res.Score;
                    existing.TestData   = res.TestData;

                    _db.SaveChanges();

                    ok = true;
                }
            }
            else
            {
                var x           = _db.TestingResults.Add(res);
                var beforeState = x.State;
                int r           = _db.SaveChanges();
                var afterState  = x.State;

                ok = beforeState == EntityState.Added && afterState == EntityState.Unchanged && r == 1;
            }

            TestResponse response;

            if (ok)
            {
                response = new TestResponse
                {
                    OK           = true,
                    Message      = "success",
                    Result       = res.ResultCode,
                    Score        = res.Score,
                    TestResultId = res.Id,
                    TestId       = res.TestId,
                };
            }
            else
            {
                response = new TestResponse
                {
                    OK      = false,
                    Message = "can't write result to db",
                    Result  = ResultCode.IE,
                    Score   = res.Score,
                    TestId  = res.TestId,
                };
            }

            return(response);
        }
Example #7
0
    private void StartTest(int testnr)
    {
        string _currentTestName = _testSettings.tests[testnr];

        UpdateButton();

        _currentTest = _testSettings.GetSettings(_currentTestName);
        ApplySettings();
    }
Example #8
0
 public TestingResultCsv Map(TestingResult testingResult)
 {
     return(new TestingResultCsv
     {
         TestName = testingResult.Test.Name,
         Interviewee = testingResult.Interviewee,
         Date = testingResult.TestingStartDateTime
     });
 }
        TestResponse WriteTestResponseToDb(TestResponse resp, int solutionId, int testId)
        {
            var testResult = _db.TestingResults.FirstOrDefault(t => t.SolutionId == solutionId && t.TestId == testId);

            if (testResult is null)
            {
                var res = new TestingResult
                {
                    Score = resp.Score,
                    Commentary = resp.Message,
                    SolutionId = solutionId,
                    TestId = testId,
                    ResultCode = resp.Result,
                };
                var x = _db.TestingResults.Add(res);
                var beforeState = x.State;
                int r = _db.SaveChanges();
                var afterState = x.State;

                bool ok = beforeState == EntityState.Added && afterState == EntityState.Unchanged && r == 1;

                TestResponse response;

                if (ok)
                {
                    response = new TestResponse
                    {
                        OK = true,
                        Message = "success",
                        Result = ResultCode.OK,
                        Score = res.Score,
                        TestResultId = res.Id,
                        TestId = testId,
                    };
                }
                else
                {
                    response = new TestResponse
                    {
                        OK = false,
                        Message = "can't write result to db",
                        Result = ResultCode.IE,
                        Score = res.Score,
                        TestId = testId,
                    };
                }

                return response;
            }
            else
            {
                return resp;
            }
        }
        public void FinishQuiz(TestingResult result)
        {
            var questionList         = result.TestingUrl.Test.TestQuestions;
            var answeredQuestionList = result.TestingResultAnswers;

            var correctlyAnswered = answeredQuestionList.Where(IsTestingResultAnswerCorrect).Count();

            result.QuestionTried = answeredQuestionList.Count;
            result.Score         = (double)correctlyAnswered / questionList.Count;
            result.IsValid       = CheckForTimeLimit(result);

            _testingResultRepository.Add(result);
        }
Example #11
0
        public ActionResult HandelForm(Test ApplicatioNames, Test TestTypes, Test ProjectNames)
        {
            string    ProjectName    = ProjectNames.ProjectName.ToString();
            string    TestType       = TestTypes.TestType.ToString();
            string    ApplicatioName = ApplicatioNames.ApplicatioName.ToString();
            TestCase1 Testobj        = new TestCase1();

            switch (ProjectName)
            {
            case "lifeAlborzInsurance":
            {
                switch (ApplicatioName)
                {
                case "AlborzContactManagingDirector":
                {
                    switch (TestType)
                    {
                    case "AcceptanceTest":
                        string[] testrepo = Testobj.TestAction1();
                        IList <TestingResult> testindexlist = new List <TestingResult>();
                        testindexlist.Add(new TestingResult()
                                {
                                    TestCheck1 = ApplicatioName, TestCheck2 = ProjectName, TestCheck3 = TestType
                                });

                        TestingResult aaa = new TestingResult();
                        aaa.TestCheck1 = ApplicatioName;
                        aaa.TestCheck2 = ProjectName;
                        aaa.TestCheck3 = TestType;

                        _context.Add(aaa);
                        _context.SaveChangesAsync();
                        ViewData["testindexlist"] = testindexlist;
                        return(View("TestResult"));
                    }
                }
                break;
                }
                break;
            }
            }

            return(View("Index"));
        }
        /// <summary>
        /// Reprojects layer of undefined type
        /// </summary>
        /// <param name="filename">Filename of layer to reproject. A changed name will be returned when new file was created</param>
        /// <param name="projection">New projection</param>
        /// <param name="inPlace">Whether new files should be written</param>
        /// <param name="report">A reference to report form</param>
        /// <returns>True on success and false otherwise</returns>
        public static TestingResult ReprojectLayer(string filename, out string newFilename, MapWinGIS.GeoProjection projection, frmTesterReport callback)
        {
            newFilename = "";
            LayerSource source = new LayerSource(filename, callback);

            if (source.Type != LayerSourceType.Undefined)
            {
                LayerSource   sourceNew = null;
                TestingResult result    = CoordinateTransformation.ReprojectLayer(source, out sourceNew, projection, callback);
                if (sourceNew != null)
                {
                    newFilename = sourceNew.Filename;
                }

                return(result);
            }
            else
            {
                return(TestingResult.Error);
            }
        }
        /// <summary>
        /// Reprojects layer of undefined type
        /// </summary>
        /// <param name="filename">Filename of layer to reproject. A changed name will be returned when new file was created</param>
        /// <param name="projection">New projection</param>
        /// <param name="inPlace">Whether new files should be written</param>
        /// <param name="report">A reference to report form</param>
        /// <returns>True on success and false otherwise</returns>
        public static TestingResult ReprojectLayer(LayerSource layer, out LayerSource newLayer, MapWinGIS.GeoProjection projection, frmTesterReport report)
        {
            newLayer = null;
            TestingResult result = TestingResult.Error;

            switch (layer.Type)
            {
            case LayerSourceType.Shapefile:
                MapWinGIS.Shapefile sfNew = null;
                result = CoordinateTransformation.Reproject(layer.Shapefile, out sfNew, projection, report);
                if (sfNew != null)
                {
                    newLayer = new LayerSource(sfNew);
                }
                break;

            case LayerSourceType.Grid:
                MapWinGIS.Grid gridNew = null;
                result = CoordinateTransformation.Reproject(layer.Grid, out gridNew, projection, report);
                if (gridNew != null)
                {
                    newLayer = new LayerSource(gridNew);
                }
                break;

            case LayerSourceType.Image:
                MapWinGIS.Image imageNew = null;
                result = CoordinateTransformation.Reproject(layer.Image, out imageNew, projection, report);
                if (imageNew != null)
                {
                    newLayer = new LayerSource(imageNew);
                }
                break;

            default:
                System.Diagnostics.Debug.Print("Coordinate transformation: unsupported interface");
                break;
            }
            return(result);
        }
Example #14
0
        /// <summary>
        /// 测试单层投影
        /// </summary>
        /// <param name="layer">图层源(Shapefile或grid对象)</param>
        /// <param name="newLayer">输出新图层</param>
        /// <returns>返回测试结果</returns>
        public TestingResult TestLayer(LayerSource layer, out LayerSource newLayer)
        {
            if (layer == null)
            {
                throw new ArgumentException("空图层引用被通过");
            }

            newLayer = null;

            MapWinGIS.GeoProjection projectProj = m_mapWin.Project.GeoProjection;
            MapWinGIS.GeoProjection layerProj   = layer.Projection;
            bool isSame = projectProj.get_IsSameExt(layerProj, layer.Extents, 10);

            // 让我们看看我们是否有项目的投影的一种方言
            if (!isSame && !projectProj.IsEmpty)
            {
                ProjectionDatabase db = (ProjectionDatabase)m_mapWin.ProjectionDatabase;//投影数据源
                if (db != null)
                {
                    CoordinateSystem cs = db.GetCoordinateSystem(projectProj, ProjectionSearchType.Enhanced);//坐标系统
                    if (cs != null)
                    {
                        db.ReadDialects(cs);
                        foreach (string dialect in cs.Dialects)
                        {
                            MapWinGIS.GeoProjection projTemp = new MapWinGIS.GeoProjection();
                            if (!projTemp.ImportFromAutoDetect(dialect))
                            {
                                continue;
                            }

                            if (layerProj.get_IsSame(projTemp))
                            {
                                isSame = true;
                                break;
                            }
                        }
                    }
                }
            }

            // 投影中可以包含的文件的后缀名,让我们试着用正确的后缀搜索文件
            if (!isSame)
            {
                if (CoordinateTransformation.SeekSubstituteFile(layer, projectProj, out newLayer))
                {
                    m_report.AddFile(layer.Filename, layer.Projection.Name, ProjectionOperaion.Substituted, newLayer.Filename);
                    return(TestingResult.Substituted);
                }
            }

            if (!layer.Projection.IsEmpty)
            {
                if (projectProj.IsEmpty)
                {
                    // 层具有投影,项目没有;分配到投影,不提示用户

                    // 让我们找个众所周知的投影与EPSG编码
                    ProjectionDatabase db = m_mapWin.ProjectionDatabase as ProjectionDatabase;
                    if (db != null)
                    {
                        CoordinateSystem cs = db.GetCoordinateSystem(layerProj, ProjectionSearchType.UseDialects);
                        if (cs != null)
                        {
                            MapWinGIS.GeoProjection proj = new MapWinGIS.GeoProjection();
                            if (proj.ImportFromEPSG(cs.Code))
                            {
                                layerProj = proj;
                            }
                        }
                    }

                    m_mapWin.Project.GeoProjection = layerProj;
                    return(TestingResult.Ok);
                }
                else if (isSame)
                {
                    // 相同投影
                    return(TestingResult.Ok);
                }
                else
                {
                    // 用户必须被提示
                    if (!m_usePreviousAnswerMismatch && !m_mapWin.ApplicationInfo.NeverShowProjectionDialog)
                    {
                        bool dontShow     = false;
                        bool useForOthers = false;

                        ArrayList list = new ArrayList();
                        list.Add("Ignore mismatch");
                        list.Add("Reproject file");
                        //list.Add("Skip file");
                        // PM 2013-05-03:
                        list.Add("Don't load the layer");

                        frmProjectionMismatch form = new frmProjectionMismatch((ProjectionDatabase)m_mapWin.ProjectionDatabase);

                        int choice = form.ShowProjectionMismatch(list, (int)m_mapWin.ApplicationInfo.ProjectionMismatchBehavior,
                                                                 projectProj, layer.Projection, out useForOthers, out dontShow);

                        form.Dispose();
                        if (choice == -1)
                        {
                            return(TestingResult.CancelOperation);
                        }

                        m_usePreviousAnswerMismatch = useForOthers;
                        m_mapWin.ApplicationInfo.ProjectionMismatchBehavior = (ProjectionMismatchBehavior)choice;
                        m_mapWin.ApplicationInfo.NeverShowProjectionDialog  = dontShow;
                    }

                    MapWinGIS.Interfaces.ProjectionMismatchBehavior behavior = m_mapWin.ApplicationInfo.ProjectionMismatchBehavior;

                    switch (behavior)
                    {
                    case ProjectionMismatchBehavior.Reproject:
                        TestingResult result = CoordinateTransformation.ReprojectLayer(layer, out newLayer, projectProj, m_report);
                        if (result == TestingResult.Ok || result == TestingResult.Substituted)
                        {
                            ProjectionOperaion oper    = result == TestingResult.Ok ? ProjectionOperaion.Reprojected : ProjectionOperaion.Substituted;
                            string             newName = newLayer == null ? "" : newLayer.Filename;
                            m_report.AddFile(layer.Filename, layer.Projection.Name, oper, newName);
                            return(newName == layer.Filename ? TestingResult.Ok : TestingResult.Substituted);
                        }
                        else
                        {
                            m_report.AddFile(layer.Filename, layer.Projection.Name, ProjectionOperaion.FailedToReproject, "");
                            return(TestingResult.Error);
                        }

                    case ProjectionMismatchBehavior.IgnoreMismatch:
                        m_report.AddFile(layer.Filename, layer.Projection.Name, ProjectionOperaion.MismatchIgnored, "");
                        return(TestingResult.Ok);

                    case ProjectionMismatchBehavior.SkipFile:
                        m_report.AddFile(layer.Filename, layer.Projection.Name, ProjectionOperaion.Skipped, "");
                        return(TestingResult.SkipFile);
                    }
                }
            }
            else if (!projectProj.IsEmpty)          // 图层投影是空的
            {
                bool projectProjectionExists = !projectProj.IsEmpty;

                // 用户必须被提示
                if (!m_usePreviousAnswerAbsence && !m_mapWin.ApplicationInfo.NeverShowProjectionDialog)
                {
                    bool dontShow     = false;
                    bool useForOthers = false;

                    ArrayList list = new ArrayList();

                    // 当在投影第一变体应排除
                    int val = projectProjectionExists ? 0 : 1;

                    if (projectProjectionExists)
                    {
                        // PM 2013-05-03:
                        //list.Add("Assign projection from project");
                        list.Add("Use the project's projection");
                    }
                    // list.Add("Ignore the absence");
                    // list.Add("Skip the file");
                    list.Add("Ignore the missing of projection file");
                    list.Add("Don't load the layer");

                    frmProjectionMismatch form = new frmProjectionMismatch((ProjectionDatabase)m_mapWin.ProjectionDatabase);
                    int choice = form.ShowProjectionAbsence(list, (int)m_mapWin.ApplicationInfo.ProjectionAbsenceBehavior - val, projectProj, out useForOthers, out dontShow);
                    form.Dispose();

                    if (choice == -1)
                    {
                        return(TestingResult.CancelOperation);
                    }

                    choice += val;

                    m_usePreviousAnswerAbsence = useForOthers;
                    m_mapWin.ApplicationInfo.ProjectionAbsenceBehavior = (ProjectionAbsenceBehavior)choice;
                    m_mapWin.ApplicationInfo.NeverShowProjectionDialog = dontShow;
                }

                // 当在项目没有投影,它不能分配层
                ProjectionAbsenceBehavior behavior = m_mapWin.ApplicationInfo.ProjectionAbsenceBehavior;
                if (!projectProjectionExists && m_mapWin.ApplicationInfo.ProjectionAbsenceBehavior == ProjectionAbsenceBehavior.AssignFromProject)
                {
                    behavior = ProjectionAbsenceBehavior.IgnoreAbsence;
                }

                switch (behavior)
                {
                case ProjectionAbsenceBehavior.AssignFromProject:
                    m_report.AddFile(layer.Filename, layer.Projection.Name, ProjectionOperaion.Assigned, "");
                    layer.Projection = projectProj;
                    return(TestingResult.Ok);

                case ProjectionAbsenceBehavior.IgnoreAbsence:
                    m_report.AddFile(layer.Filename, layer.Projection.Name, ProjectionOperaion.AbsenceIgnored, "");
                    return(TestingResult.Ok);

                case ProjectionAbsenceBehavior.SkipFile:
                    m_report.AddFile(layer.Filename, layer.Projection.Name, ProjectionOperaion.Skipped, "");
                    return(TestingResult.SkipFile);
                }
            }
            else
            {
                // 层没有投影,项目也没有,不在这里
            }

            System.Diagnostics.Debug.Print("Invalid result in projection tester");
            return(TestingResult.Ok);
        }
        //TODO:
        private List <TestingResultAnswer> MapTestingResultAnswers(IEnumerable <ChoicePassingViewModel> questions, TestingResult result)
        {
            return(questions.Select(questionFromTestAnswer =>
            {
                //?????????????????????????????????????????????????????????????????????????????????????????
                var parsedQuestion = _getInfoService.GetQuestionByGuid(questionFromTestAnswer.QuestionGuid);
                var answersSelected = string.Join(",", questionFromTestAnswer.AnswersSelected);

                return new TestingResultAnswer
                {
                    TestQuestion = parsedQuestion,
                    TestingResult = result,
                    TestAnswersSelected = answersSelected
                };
            }).ToList());
        }
    public TestingResult GetSettings(string testname)
    {
        TestingResult settings = new TestingResult();

        switch (testname)
        {
        case "test1":
            settings.XWallDistance = 1000;
            settings.YWallDistance = 1000;
            settings.MaxAngle      = 0f;
            break;

        case "test2":
            settings.XWallDistance = 1000;
            settings.YWallDistance = 1000;
            settings.MaxAngle      = 1f;
            break;

        case "test3":
            settings.XWallDistance = 1000;
            settings.YWallDistance = 1000;
            settings.MaxAngle      = 2f;
            break;

        case "test4":
            settings.XWallDistance = 1000;
            settings.YWallDistance = 1000;
            settings.MaxAngle      = 3f;

            break;

        case "test5":
            settings.XWallDistance = 1000;
            settings.YWallDistance = 1000;
            settings.MaxAngle      = 4f;
            break;

        case "test6":
            settings.XWallDistance = 1000;
            settings.YWallDistance = 1000;
            settings.MaxAngle      = 5f;
            break;

        case "test7":
            settings.XWallDistance = 1000;
            settings.YWallDistance = 1000;
            settings.MaxAngle      = 6f;
            break;

        case "test8":
            settings.XWallDistance = 1000;
            settings.YWallDistance = 1000;
            settings.MaxAngle      = 7f;
            break;

        case "test9":
            settings.XWallDistance = 1000;
            settings.YWallDistance = 1000;
            settings.MaxAngle      = 8f;
            break;

        case "test10":
            settings.XWallDistance = 1000;
            settings.YWallDistance = 1000;
            settings.MaxAngle      = 9f;
            settings.factor        = 450;
            break;

        case "test11":
            settings.XWallDistance = 1000;
            settings.YWallDistance = 1000;
            settings.MaxAngle      = 9.5f;
            break;

        //Test day 2
        case "test12":
            settings.XWallDistance = 1000;
            settings.YWallDistance = 1000;
            settings.MaxAngle      = 10f;
            break;

        case "test13":
            settings.XWallDistance = 1000;
            settings.YWallDistance = 1000;
            settings.MaxAngle      = 12f;
            break;

        case "test14":
            settings.XWallDistance = 1000;
            settings.YWallDistance = 1000;
            settings.MaxAngle      = 14f;
            break;

        case "test15":
            settings.XWallDistance = 1000;
            settings.YWallDistance = 1000;
            settings.MaxAngle      = 15f;

            break;

        case "test16":
            settings.XWallDistance = 1000;
            settings.YWallDistance = 1000;
            settings.MaxAngle      = 16f;
            break;

        case "test17":
            settings.XWallDistance = 1000;
            settings.YWallDistance = 1000;
            settings.MaxAngle      = 17f;
            break;

        case "test18":
            settings.XWallDistance = 1000;
            settings.YWallDistance = 1000;
            settings.MaxAngle      = 18f;
            break;

        case "test19":
            settings.XWallDistance = 1000;
            settings.YWallDistance = 1000;
            settings.MaxAngle      = 19f;
            break;

        case "test20":
            settings.XWallDistance = 1000;
            settings.YWallDistance = 1000;
            settings.MaxAngle      = 20f;
            break;

        case "test21":
            settings.XWallDistance = 1000;
            settings.YWallDistance = 1000;
            settings.MaxAngle      = 21f;
            break;

        case "test22":
            settings.XWallDistance = 1000;
            settings.YWallDistance = 1000;
            settings.MaxAngle      = 22f;
            break;

        //Test 3
        case "test23":

            break;

        case "test24":
            settings.factor = 450;
            break;

        case "test25":
            settings.factor = 400;
            break;

        case "test26":
            settings.factor = 350;
            break;

        case "test27":
            settings.factor = 300;
            break;

        case "test28":
            settings.factor = 250;
            break;

        case "test29":
            settings.factor = 200;
            break;

        case "test30":
            settings.factor = 100;
            break;

        case "test31":
            settings.factor    = 500;
            settings.threshold = 3.5f;
            break;

        case "test32":
            settings.factor    = 500;
            settings.threshold = 3f;
            break;

        //Test 4
        case "test33":
            settings.XWallDistance = 1000;
            settings.YWallDistance = 1000;
            settings.MaxAngle      = 10f;
            settings.factor        = 450;
            settings.threshold     = 4f;
            break;

        case "test34":
            settings.XWallDistance = 1000;
            settings.YWallDistance = 1000;
            settings.MaxAngle      = 12f;
            settings.factor        = 400;
            settings.threshold     = 3.8f;
            break;

        case "test35":
            settings.XWallDistance = 1000;
            settings.YWallDistance = 1000;
            settings.MaxAngle      = 14f;
            settings.factor        = 350;
            settings.threshold     = 3.5f;
            break;

        case "test36":
            settings.XWallDistance = 1000;
            settings.YWallDistance = 1000;
            settings.MaxAngle      = 15f;
            settings.factor        = 300;
            settings.threshold     = 3.4f;

            break;

        case "test37":
            settings.XWallDistance = 1000;
            settings.YWallDistance = 1000;
            settings.MaxAngle      = 16f;
            settings.factor        = 250;
            settings.threshold     = 3.3f;
            break;

        case "test38":
            settings.XWallDistance = 1000;
            settings.YWallDistance = 1000;
            settings.MaxAngle      = 17f;
            settings.factor        = 200;
            settings.threshold     = 3.2f;
            break;

        case "test39":
            settings.XWallDistance = 1000;
            settings.YWallDistance = 1000;
            settings.MaxAngle      = 18f;
            settings.factor        = 150;
            settings.threshold     = 3.1f;
            break;

        case "test40":
            settings.XWallDistance = 1000;
            settings.YWallDistance = 1000;
            settings.MaxAngle      = 19f;
            settings.factor        = 100;
            settings.threshold     = 3.0f;
            break;

        case "test41":
            settings.XWallDistance = 1000;
            settings.YWallDistance = 1000;
            settings.MaxAngle      = 20f;
            settings.factor        = 50;
            settings.threshold     = 2.9f;
            break;

        case "test42":
            settings.XWallDistance = 1000;
            settings.YWallDistance = 1000;
            settings.MaxAngle      = 21f;
            settings.factor        = 25;
            settings.threshold     = 2.8f;
            break;
        }
        return(settings);
    }
Example #17
0
        /// <summary>
        /// Does the reprojection work
        /// </summary>
        private void DoReprojection(IEnumerable <string> filenames, ISpatialReference projection, bool inPlace)
        {
            var report = new TesterReportForm();

            report.InitProgress(projection);
            var files = new List <string>();

            int count = 0; // number of successfully reprojected shapefiles

            foreach (string filename in filenames)
            {
                var layer = GeoSource.Open(filename) as ILayerSource;
                if (layer == null)
                {
                    continue;
                }

                ILayerSource layerNew = null;

                if (projection.IsSame(layer.Projection))
                {
                    report.AddFile(layer.Filename, projection.Name, ProjectionOperaion.SameProjection, "");
                    files.Add(layer.Filename);
                }
                else
                {
                    TestingResult result = _reprojectingService.Reproject(layer, out layerNew, projection, report);
                    if (result == TestingResult.Ok || result == TestingResult.Substituted)
                    {
                        var oper = result == TestingResult.Ok
                                       ? ProjectionOperaion.Reprojected
                                       : ProjectionOperaion.Substituted;
                        string newName = layerNew == null ? "" : layerNew.Filename;
                        report.AddFile(layer.Filename, layer.Projection.Name, oper, newName);
                        files.Add(newName == "" ? layer.Filename : newName);
                        count++;
                    }
                    else
                    {
                        var operation = result == TestingResult.Error
                                            ? ProjectionOperaion.FailedToReproject
                                            : ProjectionOperaion.Skipped;
                        report.AddFile(layer.Filename, layer.Projection.Name, ProjectionOperaion.Skipped, "");
                    }
                }

                layer.Close();
                if (layerNew != null)
                {
                    layerNew.Close();
                }
            }
            report.ShowReport(projection, "Reprojection results:", ReportType.Loading);

            IEnumerable <string> names = _context.Layers.Select(l => l.Filename).ToList();

            names = files.Except(names);

            if (count == 0)
            {
                MessageService.Current.Info("No files to add to the map.");
                return;
            }

            if (!projection.IsSame(_context.Map.Projection))
            {
                MessageService.Current.Info(
                    "Chosen projection is different from the project one. The layers can't be added to map.");
                return;
            }

            if (!names.Any())
            {
                MessageService.Current.Info("No files to add to the map.");
                return;
            }

            if (MessageService.Current.Ask("Do you want to add layers to the project?"))
            {
                //_context.Layers.StartAddingSession();

                foreach (string filename in names)
                {
                    var ds    = GeoSource.Open(filename);
                    var layer = LayerSourceHelper.ConvertToLayer(ds);
                    _context.Layers.Add(layer);
                }

                //_context.Layers.StopAddingSession();
            }
        }
Example #18
0
        /// <summary>
        /// Does the reprojection work
        /// </summary>
        private void DoReprojection(IEnumerable <string> filenames, MapWinGIS.GeoProjection projection, bool inPlace)
        {
            frmTesterReport report = new frmTesterReport();

            report.InitProgress(projection);
            List <string> files = new List <string>();

            int count = 0;  // number of successfully reprojected shapefiles

            foreach (string filename in filenames)
            {
                LayerSource layer    = new LayerSource(filename);
                LayerSource layerNew = null;

                if (projection.get_IsSame(layer.Projection))
                {
                    report.AddFile(layer.Filename, projection.Name, ProjectionOperaion.SameProjection, "");
                    files.Add(layer.Filename);
                }
                else
                {
                    TestingResult result = CoordinateTransformation.ReprojectLayer(layer, out layerNew, projection, report);
                    if (result == TestingResult.Ok || result == TestingResult.Substituted)
                    {
                        ProjectionOperaion oper    = result == TestingResult.Ok ? ProjectionOperaion.Reprojected : ProjectionOperaion.Substituted;
                        string             newName = layerNew == null ? "" : layerNew.Filename;
                        report.AddFile(layer.Filename, layer.Projection.Name, oper, newName);
                        files.Add(newName == "" ? layer.Filename : newName);
                        count++;
                    }
                    else
                    {
                        ProjectionOperaion operation = result == TestingResult.Error ? ProjectionOperaion.FailedToReproject : ProjectionOperaion.Skipped;
                        report.AddFile(layer.Filename, layer.Projection.Name, ProjectionOperaion.Skipped, "");
                    }
                }

                layer.Close();
                if (layerNew != null)
                {
                    layerNew.Close();
                }
            }
            report.ShowReport(projection, "Reprojection results:", ReportType.Loading);

            IEnumerable <string> names = m_mapWin.Layers.Select(l => l.FileName);

            names = files.Except(names);

            if (count > 0)
            {
                if (projection.get_IsSame(m_mapWin.Project.GeoProjection))
                {
                    if (names.Count() > 0)
                    {
                        if (MessageBox.Show("Do you want to add layers to the project?", m_mapWin.ApplicationInfo.ApplicationName,
                                            MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                        {
                            m_mapWin.Layers.StartAddingSession();

                            foreach (string filename in names)
                            {
                                m_mapWin.Layers.Add(filename);
                            }
                            m_mapWin.Layers.StopAddingSession();
                        }
                    }
                    else
                    {
                        MessageBox.Show("No files to add to the map.",
                                        m_mapWin.ApplicationInfo.ApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                else
                {
                    MessageBox.Show("Chosen projection is different from the project one. The layers can't be added to map.",
                                    m_mapWin.ApplicationInfo.ApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            else
            {
                MessageBox.Show("No files to add to the map.",
                                m_mapWin.ApplicationInfo.ApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        public TestResponse TestProject([FromBody] TestRequest request)
        {
            try
            {
                var solution = _db.Solutions.Find(request.SolutionId);

                if (solution is null)
                {
                    return(new TestResponse
                    {
                        OK = false,
                        Message = "no solution found",
                        Result = ResultCode.IE,
                        TestId = request.TestId,
                    });
                }

                var compilation = _db.CompilationResults.Find(request.SolutionId);

                if (compilation is null)
                {
                    return(new TestResponse
                    {
                        OK = false,
                        Message = "no compilation found",
                        Result = ResultCode.IE,
                        TestId = request.TestId,
                    });
                }

                if (compilation.ResultCode != ResultCode.OK || compilation.File is null)
                {
                    return(new TestResponse
                    {
                        OK = false,
                        Message = "no compilation file found",
                        Result = ResultCode.IE,
                        TestId = request.TestId,
                    });
                }
                else
                {
                    TestingResult result;

                    var resp = CheckCodeStyle(compilation.StOutput);
                    resp.OK = true;

                    result = new TestingResult
                    {
                        SolutionId = solution.Id,
                        TestId     = request.TestId,
                        Commentary = resp.Commentary,
                        ResultCode = resp.Result,
                        Score      = resp.Score,
                        TestData   = JsonConvert.SerializeObject(resp)
                    };

                    return(DbWriter.WriteToDb(_db, result, request.ReCheck));
                }
            }
            catch (Exception e)
            {
                return(new TestResponse
                {
                    OK = false,
                    Message = "Error occured: " + e.Message + (e.InnerException is null ? "" : " Inner: " + e.InnerException.Message),
                    Result = ResultCode.IE,
                    TestId = request.TestId,
                });
        public async Task <TestResponse> TestProject([FromBody] TestRequest request)
        {
            try
            {
                var solution = _db.Solutions.Find(request.SolutionId);

                if (solution is null)
                {
                    return(new TestResponse
                    {
                        OK = false,
                        Message = "no solution found",
                        Result = ResultCode.IE,
                        TestId = request.TestId,
                    });
                }

                var compilation = _db.CompilationResults.Find(request.SolutionId);

                if (compilation is null)
                {
                    return(new TestResponse
                    {
                        OK = false,
                        Message = "no compilation found",
                        Result = ResultCode.IE,
                        TestId = request.TestId,
                    });
                }

                if (compilation.ResultCode != ResultCode.OK || compilation.File is null)
                {
                    return(new TestResponse
                    {
                        OK = false,
                        Message = "no compilation file found",
                        Result = ResultCode.IE,
                        TestId = request.TestId,
                    });
                }
                else
                {
                    string dirPath = "/home/solution";

                    if (Directory.Exists(dirPath))
                    {
                        Directory.Delete(dirPath, true);
                    }

                    var    dir      = Directory.CreateDirectory(dirPath);
                    string fullPath = dirPath + "/" + compilation.File.Name;

                    System.IO.File.WriteAllBytes(fullPath, compilation.File.Content);
                    ZipFile.ExtractToDirectory(fullPath, dirPath, true);

                    var pathToDll = FindExeFile(dir);

                    TestingResult result;
                    if (pathToDll == null)
                    {
                        dir.Delete(true);

                        result = new TestingResult
                        {
                            SolutionId = solution.Id,
                            TestId     = request.TestId,
                            Commentary = "No dll file found!",
                            ResultCode = ResultCode.RE,
                        };

                        return(DbWriter.WriteToDb(_db, result, request.ReCheck));
                    }

                    var resp = await TestProject(pathToDll, request.TestId);

                    resp.OK = true;

                    dir.Delete(true);

                    result = new TestingResult
                    {
                        SolutionId = solution.Id,
                        TestId     = request.TestId,
                        Commentary = resp.Commentary,
                        ResultCode = resp.Result,
                        Score      = resp.Score,
                        TestData   = JsonConvert.SerializeObject(resp)
                    };

                    return(DbWriter.WriteToDb(_db, result, request.ReCheck));
                }
            }
            catch (Exception e)
            {
                return(new TestResponse
                {
                    OK = false,
                    Message = "Error occured: " + e.Message + (e.InnerException is null ? "" : " Inner: " + e.InnerException.Message),
                    Result = ResultCode.IE,
                    TestId = request.TestId,
                });
 public void setSettings(TestingResult testingResult)
 {
     Debug.Log("adding testresults" + testingResult);
     _currentTest = testingResult;
 }