コード例 #1
0
        public void CreateInspectionTest()
        {
            List <DamageDTO> damages = this.CreateDamages();
            UserDTO          user    = this.CreateUser();
            VehicleDTO       vehicle = this.CreateVehicle();

            InspectionDTO inspection = new InspectionDTO();

            inspection.Damages         = damages;
            inspection.CreatorUserName = user.UserName;
            inspection.Date            = DateTime.Now;
            inspection.Location        = "Puerto 1";
            inspection.IdVehicle       = vehicle.Vin;

            UserDTO userDTO = this.CreateUser();
            Guid    token   = Guid.NewGuid();

            var mockInspectionService = new Mock <InspectionService>();

            mockInspectionService.Setup(b => b.CreateInspection(inspection)).Verifiable();
            var mockUserService = new Mock <UserService>();

            mockUserService.Setup(us => us.GetUserLoggedIn(token)).Returns(userDTO);

            InspectionController inspectionController = new InspectionController(mockInspectionService.Object, mockUserService.Object);

            inspectionController.Request = createInspectionControllerRequest();
            this.addTokenHeaderToRequest(inspectionController.Request, token);

            ResponseMessageResult response = (ResponseMessageResult)inspectionController.Post(inspection);

            Assert.AreEqual(HttpStatusCode.OK, response.Response.StatusCode);
        }
コード例 #2
0
        private async void InitCameraAndInspector()
        {
            if (MachineConfig.MV_SimulationAcquisitionEnabled)
            {
                _camera = new SimCamera(MachineConfigProvider.MachineConfig.MV_SimulationImageFileNames);
            }
            else
            {
                _camera = new JaiCamera();
            }

            if (!MachineConfig.MV_SimulationInspectorEnabled)
            {
                _inspectionSchema     = InspectionController.GetInspectionSchema();
                _inspectionController = new InspectionController();
            }

            bool isSuccessful;

            isSuccessful = await Task.Run(() => _camera.Init());

            if (!isSuccessful)
            {
                throw new Exception("Camera cannot init");
            }
        }
コード例 #3
0
ファイル: OracleQuery.cs プロジェクト: deeze307/IA
        // Obtiene lista de defectos de inspeccion detallados por referencia
        public static string ListFaultInfo(InspectionController ictrl)
        {
            //                    CI.VC_LAST_RESULT_CODE IS NULL OR

            string query = @"           
                SELECT
                CI.SEG_ID,

                REF.CIR_NAME as referencia,

                CI.INSP_RESULT_CODE as faultcode,
                CI.VC_LAST_RESULT_CODE,

                CASE WHEN 
                    CI.VC_LAST_RESULT_CODE = 0
                       THEN 'FALSO' ELSE 'REAL' END AS resultado

                FROM
                COMP_RESULT_INFO CI,
                CIR_INFO REF

                WHERE

                REF.CIR_ID = CI.COMP_ID AND
                CI.INSP_RESULT_CODE != 0 AND

                REF.PG_ITEM_ID = " + ictrl.vtsOraclePgItemId + @" AND
                CI.INSP_ID = " + ictrl.vtsOracleInspId;

            //  CASE WHEN CI.VC_LAST_RESULT_CODE = 0 THEN 'FALSO' ELSE 'REAL' END AS resultado
            //  CI.USR_CONFIRM_FLAG  = 1 AND

            return(query);
        }
コード例 #4
0
        private void StartButton_OnClick(object sender, RoutedEventArgs e)
        {
            Save();

            var ret = MessageBox.Show("Are you sure to start? ", "Warning", MessageBoxButton.YesNo);

            if (ret != MessageBoxResult.Yes)
            {
                return;
            }



            List <string> workedDir = new List <string>();

            foreach (var directory in Directories)
            {
                if (string.IsNullOrEmpty(directory.DirectoryPath))
                {
                    //MessageBox.Show("ImageDir is null: " + directory.DirectoryPath);
                    continue;
                }

                workedDir.Add(directory.DirectoryPath);

                // Init
                InspectionSchema schema = null;

                try
                {
                    if (!File.Exists(InspectionSchemaTextBox.Text))
                    {
                        MessageBox.Show("InspectionSchema file is not exist!");
                        return;
                    }

                    //                schema = InspectionSchemaTextBox.Text.LoadFromFile();
                    //schema = InspectionSchemaExtensions.LoadFromFile(InspectionSchemaTextBox.Text);
                    schema = InspectionController.GetInspectionSchema();
                }
                catch (Exception exception)
                {
                    MessageBox.Show("InspectionSchema loading error!");
                    return;
                }

                Run(directory.DirectoryPath, schema.DeepClone());
            }

            string dirs = string.Empty;

            foreach (var dir in workedDir)
            {
                dirs += dir + "\n";
            }

            MessageBox.Show("Directories exported:\n\n" + dirs);
        }
コード例 #5
0
        public async Task GetAll_Should_Call_Get_All()
        {
            // Given
            var controller = new InspectionController(_inspectionService, _tenantIdProvider);

            var allResponse = controller.GetAll(null, null);

            await _inspectionService.Received().GetAllAsync(null, null);
        }
コード例 #6
0
ファイル: Pendiente.cs プロジェクト: deeze307/IA
        public int vtwinTestMachineId = 0;    // id de maquina en oracle

        public static void Delete(InspectionController ictrl)
        {
            ictrl.machine.LogBroadcast("debug",
                                       string.Format("+ Pendiente.Delete({0}) ", ictrl.barcode)
                                       );

            string         query = string.Format("CALL sp_removeProcesarPendient('{0}')", ictrl.barcode);
            MySqlConnector sql   = new MySqlConnector();

            sql.LoadConfig("IASERVER");
            bool rs = sql.NonQuery(query);
        }
コード例 #7
0
        public void Overview_StateUnderTest_ExpectedBehavior()
        {
            // Arrange
            var inspectionController      = new InspectionController();
            InspectionFormViewModel model = null;

            // Act
            var result = inspectionController.Overview(
                model);

            // Assert
            Assert.Fail();
        }
コード例 #8
0
        public void Get_ShouldFail_GivenInspectionDoesntExist()
        {
            // Given
            var inspectionService = Substitute.For <IInspectionService>();

            inspectionService.When(s => s.GetAsync(Arg.Any <Guid>()))
            .Do(v => throw new ItemNotFoundException(v[0].ToString(), "inspection"));
            var controller = new InspectionController(inspectionService, _tenantIdProvider);

            // When
            AsyncTestDelegate action = async() => await controller.GetInspection(Guid.NewGuid());

            // Then
            Assert.ThrowsAsync <ItemNotFoundException>(action);
        }
コード例 #9
0
        public void Index_StateUnderTest_ExpectedBehavior1()
        {
            // Arrange
            var                     inspectionController = new InspectionController();
            FormCollection          form  = null;
            InspectionFormViewModel model = null;

            // Act
            var result = inspectionController.Index(
                form,
                model);

            // Assert
            Assert.Fail();
        }
コード例 #10
0
        public void ErrorCreateInspectionWithoutTokenTest()
        {
            InspectionDTO inspection = new InspectionDTO();

            var mockInspectionService = new Mock <InspectionService>();

            mockInspectionService.Setup(b => b.CreateInspection(inspection)).Verifiable();

            InspectionController inspectionController = new InspectionController(mockInspectionService.Object, null);

            inspectionController.Request = createInspectionControllerRequest();

            ResponseMessageResult response = (ResponseMessageResult)inspectionController.Post(inspection);

            Assert.AreEqual(HttpStatusCode.BadRequest, response.Response.StatusCode);
        }
コード例 #11
0
        public MainWindow()
        {
            InitializeComponent();

            RegionIndicators = new ObservableCollection <RegionIndicatorViewModel>();
            DefectIndicators = new BindableCollection <RectangleIndicatorViewModel>();
            ObjectIndicators = new ObservableCollection <RectangleIndicatorViewModel>();
            LineIndicators   = new ObservableCollection <LineIndicatorViewModel>();
            CircleIndicators = new ObservableCollection <CircleIndicatorViewModel>();

            this.DataContext = this;
            this.Closing    += MainWindow_Closing;

            InspectionController = new InspectionController();

            Refresh();
        }
コード例 #12
0
ファイル: OracleQuery.cs プロジェクト: deeze307/IA
        // Obtiene lista de maquinas
        public static string ListBlockBarcode(InspectionController ictrl)
        {
            string query = @"
                SELECT
                SEG_ID,
                SEG_BARCODE,
                COMP_NG_COUNT,
                VC_COMPLETE_FLAG
                FROM 

                SEG_RESULT_INFO

                WHERE

                INSP_ID = " + ictrl.vtsOracleInspId;

            return(query);
        }
コード例 #13
0
ファイル: OracleQuery.cs プロジェクト: deeze307/IA
        public static string ListBlocks(InspectionController ictrl)
        {
            string query = @"
            SELECT 
                SEG_ID, SEG_NO

            FROM 
            seg_info 

            WHERE 
              pos_x <> 0 and 
              pos_y <> 0 and
              size_x <> 0 and
              size_y <> 0 and
              PG_ITEM_ID = " + ictrl.vtsOraclePgItemId;

            return(query);
        }
コード例 #14
0
        public void ErrorCreateInspectionBadTokenTest()
        {
            InspectionDTO inspection = new InspectionDTO();
            Guid          token      = Guid.NewGuid();

            var mockInspectionService = new Mock <InspectionService>();

            mockInspectionService.Setup(b => b.CreateInspection(inspection)).Verifiable();
            var mockUserService = new Mock <UserService>();

            mockUserService.Setup(us => us.GetUserLoggedIn(token)).Throws(new UserNotExistException());

            InspectionController inspectionController = new InspectionController(mockInspectionService.Object, mockUserService.Object);

            inspectionController.Request = createInspectionControllerRequest();

            ResponseMessageResult response = (ResponseMessageResult)inspectionController.Post(inspection);

            Assert.AreEqual(HttpStatusCode.BadRequest, response.Response.StatusCode);
        }
コード例 #15
0
        /// <summary>
        /// Setup the test
        /// </summary>
        public InspectionApiUnitTest()
        {
            DbContextOptions <DbAppContext> options      = new DbContextOptions <DbAppContext>();
            Mock <DbAppContext>             dbAppContext = new Mock <DbAppContext>(null, options);

            /*
             *
             * Here you will need to mock up the context.
             *
             * ItemType fakeItem = new ItemType(...);
             *
             * Mock<DbSet<ItemType>> mockList = MockDbSet.Create(fakeItem);
             *
             * dbAppContext.Setup(x => x.ModelEndpoint).Returns(mockItem.Object);
             *
             */

            InspectionService _service = new InspectionService(null, dbAppContext.Object);

            _InspectionApi = new InspectionController(_service);
        }
コード例 #16
0
ファイル: Pendiente.cs プロジェクト: deeze307/IA
        public static void Save(InspectionController ictrl)
        {
            DateTime customDate = DateTime.Parse(ictrl.fecha + " " + ictrl.hora);

            ictrl.machine.LogBroadcast("debug",
                                       string.Format("+ Pendiente.Save({0}) ", ictrl.barcode)
                                       );

            string query = string.Format("CALL sp_addProcesarPendient('{0}', '{1}', '{2}', '{3}', '{4}', '{5}');",
                                         ictrl.barcode,
                                         customDate.ToString("yyyy-MM-dd HH:mm:ss"),
                                         ictrl.machine.mysql_id,
                                         ictrl.programa,
                                         ictrl.vtwinProgramNameId,
                                         ictrl.vtwinTestMachineId
                                         );

            MySqlConnector sql = new MySqlConnector();

            sql.LoadConfig("IASERVER");
            bool rs = sql.NonQuery(query);
        }
コード例 #17
0
        public async Task CompleteInspection_Should_Call_CompleteInspectionAsync_And_Return_NoContent()
        {
            // Given
            var controller = new InspectionController(_inspectionService, _tenantIdProvider);

            var completionDto = new InspectionCompleteDto
            {
                Id         = _incompleteInspection.Id,
                FinishTime = DateTimeOffset.Now
            };

            // When
            // user tries to mark inspection as completed
            var response = (OkObjectResult)await controller.PutInspectionComplete(completionDto.Id, completionDto, default(CancellationToken));

            // Then
            // The controller calls service with proper arguments
            await _inspectionService.Received().CompleteInspectionAsync(
                Arg.Is <Guid>(g => g == completionDto.Id),
                Arg.Is <DateTimeOffset>(t => t == completionDto.FinishTime),
                Arg.Any <CancellationToken>());

            response.StatusCode.ShouldBe((int)HttpStatusCode.OK);
        }
コード例 #18
0
        public void BeginInspection_Should_Call_BeginInspectionAsync_And_Return_Created_()
        {
            // Given
            var controller = new InspectionController(_inspectionService, _tenantIdProvider);

            var newInspectionModel = new InspectionDto
            {
                MethodSetId      = "Method_Set_Id",
                StartTime        = DateTime.Now - TimeSpan.FromMinutes(7),
                FinishTime       = DateTime.Now,
                InspectionPlace  = InspectionPlace.OnWorkplace,
                InspectionType   = InspectionType.PreShift,
                EmployeeId       = Guid.NewGuid().ToString(),
                BranchOfficeId   = Guid.NewGuid().ToString(),
                DepartmentId     = Guid.NewGuid().ToString(),
                MachineName      = "HOST002",
                MethodSetVersion = "Version 16"
            };

            // When
            var response = controller.PostInspection(newInspectionModel);

            // Then
            _inspectionService.Received().BeginInspectionAsync(Arg.Any <Inspection>());
            _inspectionService.Received().BeginInspectionAsync(
                Arg.Is <Inspection>(v => v.StartTime == newInspectionModel.StartTime &&
                                    v.TenantId == _tenantId));

            var createdResponse = (CreatedResult)response.Result;

            Assert.That(createdResponse.Location, Is.EqualTo(nameof(InspectionController.GetInspection)));

            var createdAttribs = (CreatedWithGuidDto)createdResponse.Value;

            Assert.That(createdAttribs.Id, Is.EqualTo(_newId));
        }
コード例 #19
0
 public void Setup()
 {
     _inspectionService = new Mock <IInspectionService>().Object;
     _sut = new InspectionController(_inspectionService);
 }
コード例 #20
0
        public void Run(string imageDir, InspectionSchema schema)
        {
            IList <string> fileNames;

            try
            {
                var strings = Directory.GetFiles(imageDir).ToList();

                fileNames = strings.Where(x =>
                {
                    if (x.EndsWith(".bmp"))
                    {
                        return(true);
                    }

                    if (x.EndsWith(".tif"))
                    {
                        return(true);
                    }

                    if (x.EndsWith(".jpg"))
                    {
                        return(true);
                    }

                    return(false);
                }).ToList();
            }
            catch (Exception)
            {
                MessageBox.Show("Image directory cannot load files! " + imageDir);
                return;
            }


            // Inspect
            IList <InspectionResult> inspectionResults = new List <InspectionResult>();

//            IList<ImageInfo> imageInfos = new List<ImageInfo>();
            IList <HImage> images = new List <HImage>();

            foreach (var fileName in fileNames)
            {
                string name = fileName;

                var fn = (string)name;
                Debug.WriteLine("Task.Started: " + fn);

//                BitmapImage bi = null;
//                try
//                {
//                    Debug.WriteLine("BitmapImage() begin");
//                    bi = new BitmapImage(new Uri(fn, UriKind.RelativeOrAbsolute));
//                    Debug.WriteLine("BitmapImage() end");
//                }
//                catch (Exception e2)
//                {
//                    MessageBox.Show("BitmapImage loading error: " + fn);
//                }
//
//                Debug.WriteLine("ToImageInfoWith8Bpp() begin");
//                var imageInfo = bi.ToImageInfoWith8Bpp();
//                Debug.WriteLine("ToImageInfoWith8Bpp() end");
//
//                imageInfos.Add(imageInfo);

                images.Add(new HImage(name));
            }

            IList <Task> tasks = new List <Task>();

            foreach (var imageInfo in images)
            {
//                string name = fileName;
                var imageInfo2 = imageInfo;
                var task       = new Task(
                    (x) =>
                {
                    HImage imageInfo3 = (HImage)imageInfo2;
//                        Debug.WriteLine("Task.Started: " + fn);
//
//                        BitmapImage bi = null;
//                        try
//                        {
//                            Debug.WriteLine("BitmapImage() begin");
//                            bi = new BitmapImage(new Uri(fn, UriKind.RelativeOrAbsolute));
//                            Debug.WriteLine("BitmapImage() end");
//                        }
//                        catch (Exception e2)
//                        {
//                            MessageBox.Show("BitmapImage loading error: " + fn);
//                        }
//
//                        Debug.WriteLine("ToImageInfoWith8Bpp() begin");
//                        var imageInfo = bi.ToImageInfoWith8Bpp();
//                        Debug.WriteLine("ToImageInfoWith8Bpp() end");

                    using (var inspectionController = new InspectionController())
                    {
                        inspectionController
                        .SetInspectionSchema(schema.DeepClone())
                        .SetImage(imageInfo3)
                        .CreateCoordinate()
                        .Inspect()
                        ;

                        inspectionController.InspectionResult.Comment = "";

                        inspectionResults.Add(inspectionController.InspectionResult);
                    }

                    //                var targetTask = new SearchingTask();
                    //                foreach (var csd in schema.CircleSearchingDefinitions)
                    //                {
                    //                    var relativeVector = new Vector(csd.BaselineX*1000.0/16.0, csd.BaselineY*1000.0/16.0);
                    //                    var originalVector = coord.GetOriginalVector(relativeVector);
                    //                    csd.CenterX = originalVector.X;
                    //                    csd.CenterY = originalVector.Y;
                    //                }
                    //                targetTask.CircleDefinitions.AddRange(schema.CircleSearchingDefinitions);
                    //
                    //
                    //                var targetResult = inspector.Search(imageInfo, targetTask);
                    //
                    //                targetResult.CircleSearchingResults.UpdateRelativeCoordinate(coord);
                }, imageInfo);
                tasks.Add(task);
                task.Start();
            }

            Task.WaitAll(tasks.ToArray());

            var coordinateResultGroups = inspectionResults.Select(x => x.CoordinateCircles).ToList();
            List <CircleSearchingResultCollection> objectsResultGroups = inspectionResults.Select(x => x.Circles).ToList();

            foreach (var task in objectsResultGroups)
            {
                foreach (var t in task)
                {
                    Debug.WriteLine("objectsResultGroups Circle " + t.Index + " X: " + t.Definition.CenterX);
                    Debug.WriteLine("objectsResultGroups Circle " + t.Index + " Y: " + t.Definition.CenterY);
                }
            }

            DateTime dateTime  = DateTime.Now;
            string   reportDir = "_reports" + dateTime.ToString("_yyyy-MM-dd_HH.mm.ss");
            var      exportDir = Path.Combine(imageDir, reportDir);

            Directory.CreateDirectory(exportDir);

            // SaveToCSV
            ReportManager.SaveToCSV(coordinateResultGroups, exportDir, "Coordinate");
            ReportManager.SaveToCSV(objectsResultGroups, exportDir, "Objects");
            Debug.WriteLine("SaveToCSV() end");


            var distGroups = inspectionResults.Select(x => x.DistanceBetweenPointsResults).ToList();

            ReportManager.SaveCsvGroupByEdge(distGroups, exportDir, "Edges");
            Debug.WriteLine("SaveCsvGroupByEdge() end");


            List <RegionDefectResult> defectsGroups = inspectionResults.SelectMany(x => x.RegionDefectResults).ToList();
            var dgs = defectsGroups.Select(x => x.DefectResults).ToList();

            ReportManager.SaveDefectResultsToCsvGroupByWorkpiece(dgs, exportDir, "Defects");
            Debug.WriteLine("SaveDefectResultsToCsvGroupByWorkpiece() end");

            // SaveToXaml
            ReportManager.SaveToXaml(coordinateResultGroups, exportDir, "Coordinate");
            ReportManager.SaveToXaml(objectsResultGroups, exportDir, "Objects");
            ReportManager.SaveToXaml(inspectionResults, exportDir, "All");
            Debug.WriteLine("SaveToXaml() end");


            var cs = CoordinateCircleCalculator.Calculate(inspectionResults);


            //            var allResultGroup = new List<CircleSearchingResultCollection>();
            //            allResultGroup.AddRange(coordinateResultGroups);
            //            allResultGroup.AddRange(objectsResultGroups);
            //            ReportManager.SaveToCSV(allResultGroup, exportDir, "All");
            //            ReportManager.SaveToXaml(allResultGroup, exportDir, "All");
        }