Beispiel #1
0
        public void WithTreeAndRecursive_ShouldAssembleChilds()
        {
            IController controller = Controller(
                activeAlarm: Alarm("Root Alarm", AlarmType.Info),
                actualValues: new [] { VelocityTag() },
                children: new[] { ChildController(
                                      parameters: new[] { Tag(
                                                              dataType: "INT",
                                                              name: "AnyTag",
                                                              value: 13,
                                                              unit: "...",
                                                              comment: "Whatever") }).Object },
                commands: new [] { Command("Start", "Starts the system") },
                configurations: new Tag[0],
                controllerMode: ControllerMode.Auto,
                currentState: "Running",
                currentSubState: "Sub-Running",
                enableForcing: true,
                id: 1,
                isEnabled: true,
                isSimulation: true,
                name: "Root",
                fullname: "Root",
                parameters: new Tag[0],
                type: "RootController").Object;
            PlcInformationDtoAssembler assembler = CreateAssembler();
            ControllerDTO dto = assembler.AssembleControllerDto(controller, recursive: true);

            ApprovalTests.Approvals.Verify(dto.ToJson());
        }
Beispiel #2
0
        public void WithNull_ShouldReturnNull()
        {
            PlcInformationDtoAssembler assembler = CreateAssembler();
            ControllerDTO dto = assembler.AssembleControllerDto(null);

            dto.Should().BeNull();
        }
Beispiel #3
0
 public static void ShouldHaveValues(this ControllerDTO dto,
                                     string activeAlarm,
                                     PlcEssentials.PlcInformation.DTOs.AlarmType alarmType,
                                     string currentState,
                                     string currentSubState,
                                     bool enableForcing,
                                     int id,
                                     bool isEnabled,
                                     bool isSimulated,
                                     PlcEssentials.PlcInformation.DTOs.ControllerMode mode,
                                     string name,
                                     string fullname,
                                     string type)
 {
     dto.ActiveAlarm.Should().Be(activeAlarm);
     dto.ActualValues.Should().NotBeNull();
     dto.Children.Should().NotBeNull();
     dto.ControllerState.Should().Be(alarmType);
     dto.Commands.Should().NotBeNull();
     dto.Configurations.Should().NotBeNull();
     dto.CurrentState.Should().Be(currentState);
     dto.CurrentSubState.Should().Be(currentSubState);
     dto.EnableForcing.Should().Be(enableForcing);
     dto.Id.Should().Be(id);
     dto.Inputs.Should().NotBeNull();
     dto.IsEnabled.Should().Be(isEnabled);
     dto.IsSimulation.Should().Be(isSimulated);
     dto.Mode.Should().Be(mode);
     dto.Name.Should().Be(name);
     dto.FullName.Should().Be(fullname);
     dto.Outputs.Should().NotBeNull();
     dto.Parameters.Should().NotBeNull();
     dto.Type.Should().Be(type);
 }
Beispiel #4
0
        public void WithControllerHavingChildAndNonRecursive_ShouldReturnNoChild()
        {
            IController controller = ChildController(children: new[] { ChildController(name: "Subchild").Object }).Object;
            PlcInformationDtoAssembler assembler = CreateAssembler();
            ControllerDTO dto = assembler.AssembleControllerDto(controller, recursive: false);

            dto.Children.Should().BeEmpty();
        }
Beispiel #5
0
        public void WithControllerHavingNoAlarm_ShouldReturnDtoWithEmptyAlarm()
        {
            IController controller = ChildController().Object;
            PlcInformationDtoAssembler assembler = CreateAssembler();
            ControllerDTO dto = assembler.AssembleControllerDto(controller);

            dto.ActiveAlarm.Should().BeEmpty();
        }
Beispiel #6
0
        public void WithControllerHavingChildAndRecurcive_ShouldReturnBothDtos()
        {
            IController controller = ChildController(children: new[] { ChildController(name: "Subchild").Object }).Object;
            PlcInformationDtoAssembler assembler = CreateAssembler();
            ControllerDTO dto = assembler.AssembleControllerDto(controller, recursive: true);

            dto.Children.Should().HaveCount(1);
            dto.Children.First().Name.Should().Be("Subchild");
        }
Beispiel #7
0
        public void WithControllerChild_ShouldReturnDtoChild()
        {
            IController controller = ChildController(
                activeAlarm: Alarm("Special Child Alarm", AlarmType.Warning)).Object;
            PlcInformationDtoAssembler assembler = CreateAssembler();
            ControllerDTO dto = assembler.AssembleControllerDto(controller);

            dto.ShouldHaveValues(
                activeAlarm: "Special Child Alarm",
                alarmType: PlcEssentials.PlcInformation.DTOs.AlarmType.Warning,
                currentState: "Ready",
                currentSubState: "Sub-Ready",
                enableForcing: false,
                id: 2,
                isEnabled: false,
                isSimulated: false,
                mode: PlcEssentials.PlcInformation.DTOs.ControllerMode.Manual,
                name: "Child",
                fullname: "Child",
                type: "ChildType");
        }
Beispiel #8
0
        public void WithControllerRoot_ShouldReturnDtoRoot()
        {
            IController controller = Controller(
                activeAlarm: Alarm("Root Alarm", AlarmType.Info),
                actualValues: new Tag[0],
                children: new IController[0],
                commands: new ICommand[0],
                configurations: new Tag[0],
                controllerMode: ControllerMode.Auto,
                currentState: "Running",
                currentSubState: "Sub-Running",
                enableForcing: true,
                id: 1,
                isEnabled: true,
                isSimulation: true,
                name: "Root",
                fullname: "Root",
                parameters: new Tag[0],
                type: "RootController").Object;
            PlcInformationDtoAssembler assembler = CreateAssembler();
            ControllerDTO dto = assembler.AssembleControllerDto(controller);

            dto.ShouldHaveValues(
                activeAlarm: "Root Alarm",
                alarmType: PlcEssentials.PlcInformation.DTOs.AlarmType.Normal,
                currentState: "Running",
                currentSubState: "Sub-Running",
                enableForcing: true,
                id: 1,
                isEnabled: true,
                isSimulated: true,
                mode: PlcEssentials.PlcInformation.DTOs.ControllerMode.Auto,
                name: "Root",
                fullname: "Root",
                type: "RootController");
        }
        public virtual ControllerDTO AssembleControllerDto(IController controller, bool recursive = false)
        {
            if (controller == null)
            {
                return(null);
            }
            var dto = new ControllerDTO
            {
                ActiveAlarm     = GetActiveAlarmText(controller),
                ActualValues    = AssembleTagDtos(controller.ActualValues).ToList(),
                Children        = new List <ControllerDTO>(0),
                Commands        = AssembleCommandDtos(controller.Commands).ToList(),
                ControllerState = GetActiveAlarmType(controller),
                Configurations  = AssembleTagDtos(controller.Configurations).ToList(),
                CurrentState    = controller.CurrentState,
                CurrentSubState = controller.CurrentSubState,
                EnableForcing   = controller.EnableForcing,
                Id                = controller.Id,
                Inputs            = AssembleTagDtos(controller.Inputs).ToList(),
                IsEnabled         = controller.IsEnabled,
                IsSimulation      = controller.IsSimulation,
                Mode              = (DTOs.ControllerMode)controller.ControllerMode,
                Name              = controller.Name,
                Outputs           = AssembleTagDtos(controller.Outputs).ToList(),
                Parameters        = AssembleTagDtos(controller.Parameters).ToList(),
                Type              = controller.Type,
                PlcControllerPath = controller.PlcInternalTreePath,
                FullName          = controller.FullName
            };

            if (recursive)
            {
                dto.Children = AssembleControllerDtos(controller.Childs).ToList();
            }
            return(dto);
        }
Beispiel #10
0
        private async Task <List <UserRightDTO> > GetUserRights(string userId)
        {
            UnitOfWork   unitOfWork = new UnitOfWork(factory);
            SqlParameter parUser1   = new SqlParameter
            {
                ParameterName = "@UserId",
                IsNullable    = false,
                Direction     = ParameterDirection.Input,
                DbType        = DbType.String,
                Value         = userId
            };
            IEnumerable <UserRightOfficeDTO> rightsString = unitOfWork.SQLQuery <UserRightOfficeDTO>("exec UserRights @UserId", parUser1);
            List <UserRightDTO> dtos = new List <UserRightDTO>();

            try
            {
                if (rightsString != null)
                {
                    if (rightsString.Count() != 0)
                    {
                        var result = rightsString.Select(r => new OfficeSecurity {
                            Id = r.OfficeId.GetValueOrDefault(), ShortName = r.OfficeShortName
                        }).Distinct().ToList();
                        if (result != null)
                        {
                            foreach (var item in result)
                            {
                                UserRightDTO dto = new UserRightDTO();
                                dto.OfficeId   = item.Id;
                                dto.OfficeName = item.ShortName;

                                List <ControllerBoxDTO> boxesList = new List <ControllerBoxDTO>();
                                var bList = rightsString
                                            .Where(d => d.OfficeId == item.Id)
                                            .Select(d => new ControllerBoxDTO {
                                    Id = d.BoxId.GetValueOrDefault(), Name = d.BoxName
                                })
                                            .Distinct()
                                            .ToList();

                                if (bList != null)
                                {
                                    foreach (var box in bList)
                                    {
                                        ControllerBoxDTO boxDTO = new ControllerBoxDTO();
                                        boxDTO.Name = box.Name;
                                        boxDTO.Id   = box.Id;

                                        List <ControllerDTO> controllerList = new List <ControllerDTO>();
                                        var cList = rightsString.Where(r => r.OfficeId == item.Id && r.BoxId == box.Id)
                                                    .Select(r => new ControllerDTO {
                                            Id = r.ControllerId.GetValueOrDefault(), ControllerName = r.ControllerName
                                        })
                                                    .Distinct().ToList();

                                        if (cList != null)
                                        {
                                            foreach (var c in cList)
                                            {
                                                ControllerDTO cDto = new ControllerDTO();
                                                cDto.ControllerName = c.ControllerName;
                                                cDto.Id             = c.Id;

                                                List <ActionDTO> actionList = new List <ActionDTO>();
                                                var aList = rightsString.Where(r => r.OfficeId == item.Id && r.ControllerId == c.Id)
                                                            .Select(r => new ActionDTO {
                                                    Id = r.ActionId.GetValueOrDefault(), ActionName = r.ActionName, ActionLongName = r.ActionLongName
                                                })
                                                            .Distinct().ToList();
                                                if (aList != null)
                                                {
                                                    foreach (var a in aList)
                                                    {
                                                        ActionDTO aDto = new ActionDTO();
                                                        aDto.Id             = a.Id;
                                                        aDto.ActionLongName = a.ActionLongName == null ? "" : a.ActionLongName;
                                                        aDto.ActionName     = a.ActionName == null ? "" : a.ActionName;
                                                        actionList.Add(aDto);
                                                    }
                                                }
                                                cDto.Actions = actionList;
                                                controllerList.Add(cDto);
                                            }
                                        }

                                        boxDTO.Controllers = controllerList;
                                        boxesList.Add(boxDTO);
                                    }
                                }
                                dto.Boxes = boxesList;
                                dtos.Add(dto);
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                string m = e.Message;
            }
            return(dtos);
        }
Beispiel #11
0
        public UserInfoViewModel GetUserInfo()
        {
            string UserId = identityHelper.GetUserId(User);

            UnitOfWork unitOfWork = new UnitOfWork(factory);

            SqlParameter parUser = new SqlParameter
            {
                ParameterName = "@UserId",
                IsNullable    = false,
                Direction     = ParameterDirection.Input,
                DbType        = DbType.String,
                Value         = UserId
            };


            UserInfoViewModel userInfoViewModel = unitOfWork.SQLQuery <UserInfoViewModel>("exec UserInfo @UserId", parUser).FirstOrDefault();

            //Task<List<UserRightDTO>> tRights = GetUserRights(UserId);
            //Task<UserInfoViewModel> tModel = GetUserInfoViewModel(UserId);


            //await Task.WhenAll(tModel, tRights);

            //UserInfoViewModel userInfoViewModel = tModel.Result;
            //userInfoViewModel.UserRights = tRights.Result;
            //return userInfoViewModel;


            //i don't know why but they need another parameter

            SqlParameter parUser1 = new SqlParameter
            {
                ParameterName = "@UserId",
                IsNullable    = false,
                Direction     = ParameterDirection.Input,
                DbType        = DbType.String,
                Value         = UserId
            };

            IEnumerable <UserRightOfficeDTO> rightsString = unitOfWork.SQLQuery <UserRightOfficeDTO>("exec UserRights @UserId", parUser1);
            List <UserRightDTO> dtos = new List <UserRightDTO>();

            try
            {
                if (rightsString != null)
                {
                    if (rightsString.Count() != 0)
                    {
                        var result = rightsString.Select(r => new OfficeSecurity {
                            Id = r.OfficeId.GetValueOrDefault(), ShortName = r.OfficeShortName
                        }).Distinct().ToList();
                        if (result != null)
                        {
                            foreach (var item in result)
                            {
                                UserRightDTO dto = new UserRightDTO();
                                dto.OfficeId   = item.Id;
                                dto.OfficeName = item.ShortName;

                                List <ControllerBoxDTO> boxesList = new List <ControllerBoxDTO>();
                                var bList = rightsString
                                            .Where(d => d.OfficeId == item.Id)
                                            .Select(d => new ControllerBoxDTO {
                                    Id = d.BoxId.GetValueOrDefault(), Name = d.BoxName
                                })
                                            .Distinct()
                                            .ToList();

                                if (bList != null)
                                {
                                    foreach (var box in bList)
                                    {
                                        ControllerBoxDTO boxDTO = new ControllerBoxDTO();
                                        boxDTO.Name = box.Name;
                                        boxDTO.Id   = box.Id;

                                        List <ControllerDTO> controllerList = new List <ControllerDTO>();
                                        var cList = rightsString.Where(r => r.OfficeId == item.Id && r.BoxId == box.Id)
                                                    .Select(r => new ControllerDTO {
                                            Id = r.ControllerId.GetValueOrDefault(), ControllerName = r.ControllerName
                                        })
                                                    .Distinct().ToList();

                                        if (cList != null)
                                        {
                                            foreach (var c in cList)
                                            {
                                                ControllerDTO cDto = new ControllerDTO();
                                                cDto.ControllerName = c.ControllerName;
                                                cDto.Id             = c.Id;

                                                List <ActionDTO> actionList = new List <ActionDTO>();
                                                var aList = rightsString.Where(r => r.OfficeId == item.Id && r.ControllerId == c.Id)
                                                            .Select(r => new ActionDTO {
                                                    Id = r.ActionId.GetValueOrDefault(), ActionName = r.ActionName, ActionLongName = r.ActionLongName
                                                })
                                                            .Distinct().ToList();
                                                if (aList != null)
                                                {
                                                    foreach (var a in aList)
                                                    {
                                                        ActionDTO aDto = new ActionDTO();
                                                        aDto.Id             = a.Id;
                                                        aDto.ActionLongName = a.ActionLongName == null ? "" : a.ActionLongName;
                                                        aDto.ActionName     = a.ActionName == null ? "" : a.ActionName;
                                                        actionList.Add(aDto);
                                                    }
                                                }
                                                cDto.Actions = actionList;
                                                controllerList.Add(cDto);
                                            }
                                        }

                                        boxDTO.Controllers = controllerList;
                                        boxesList.Add(boxDTO);
                                    }
                                }
                                dto.Boxes = boxesList;
                                dtos.Add(dto);
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                string m = e.Message;
            }

            userInfoViewModel.UserRights = dtos.OrderBy(d => d.OfficeName);

            return(userInfoViewModel);
        }
Beispiel #12
0
        public List <UserRightDTO> GetUserRightsDTO()
        {
            List <UserRightDTO> dtos = new List <UserRightDTO>();

            try
            {
                if (UserRights != null)
                {
                    if (UserRights.Count != 0)
                    {
                        var result = UserRights.Select(r => r.OfficeSecurity).Distinct().ToList();
                        if (result != null)
                        {
                            foreach (var item in result)
                            {
                                UserRightDTO dto = new UserRightDTO();
                                dto.OfficeId   = item.Id;
                                dto.OfficeName = item.ShortName;

                                List <ControllerBoxDTO> boxesList = new List <ControllerBoxDTO>();
                                var bList = UserRights
                                            .Where(d => d.OfficeId == item.Id)
                                            .Select(d => d.Action.Controller.ControllerBox)
                                            .Distinct()
                                            .ToList();

                                if (bList != null)
                                {
                                    foreach (var box in bList)
                                    {
                                        ControllerBoxDTO boxDTO = new ControllerBoxDTO();
                                        boxDTO.Name = box.Name;
                                        boxDTO.Id   = box.Id;

                                        List <ControllerDTO> controllerList = new List <ControllerDTO>();
                                        var cList = UserRights.Where(r => r.OfficeId == item.Id && r.Action.Controller.BoxId == box.Id).Select(r => r.Action.Controller).Distinct().ToList();

                                        if (cList != null)
                                        {
                                            foreach (var c in cList)
                                            {
                                                ControllerDTO cDto = new ControllerDTO();
                                                cDto.ControllerName = c.Name;
                                                cDto.Id             = c.Id;

                                                List <ActionDTO> actionList = new List <ActionDTO>();
                                                var aList = UserRights.Where(r => r.OfficeId == item.Id && r.Action.ControllerId == c.Id).Select(r => r.Action).Distinct().ToList();
                                                if (aList != null)
                                                {
                                                    foreach (var a in aList)
                                                    {
                                                        ActionDTO aDto = new ActionDTO();
                                                        aDto.Id             = a.Id;
                                                        aDto.ActionLongName = a.LongName == null ? "" : a.LongName;
                                                        aDto.ActionName     = a.Name == null ? "" : a.Name;
                                                        actionList.Add(aDto);
                                                    }
                                                }
                                                cDto.Actions = actionList;
                                                controllerList.Add(cDto);
                                            }
                                        }

                                        boxDTO.Controllers = controllerList;
                                        boxesList.Add(boxDTO);
                                    }
                                }
                                dto.Boxes = boxesList;
                                dtos.Add(dto);
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                string m = e.Message;
            }
            return(dtos);
        }