Example #1
0
 public HardwareType Resolve(Hardware source, HardwareDto destination, HardwareType destMember, ResolutionContext context)
 {
     return(source switch
     {
         Cabinet e => HardwareType.Cabinet,
         ARM e => HardwareType.ARM,
         Flowmeter e => HardwareType.Flowmeter,
         Pressure e => HardwareType.Pressure,
         DiffPressure e => HardwareType.DiffPressure,
         Temperature e => HardwareType.Temperature,
         GasAnalyzer e => HardwareType.GasAnalyzer,
         FireSensor e => HardwareType.FireSensor,
         FlowComputer e => HardwareType.FlowComputer,
         PLC e => HardwareType.PLC,
         APC e => HardwareType.APC,
         NetworkHardware e => HardwareType.Network,
         Valve e => HardwareType.Valve,
         InformPanel e => HardwareType.InformPanel,
         FireModule e => HardwareType.FireModule,
         _ => HardwareType.Valve,
     });
Example #2
0
        static void Main(string[] args)
        {
            NetworkHardware[] net;

            Router router1 = new Router();
            Router router2 = new Router();

            NetworkSwitch networkSwitch1 = new NetworkSwitch();
            NetworkSwitch networkSwitch2 = new NetworkSwitch();

            net = new NetworkHardware[4] {
                (NetworkHardware)router1, (NetworkHardware)router2, (NetworkHardware)networkSwitch1, (NetworkHardware)networkSwitch2
            };

            Console.WriteLine("Display instance with default fields\n");
            Console.WriteLine(router1.DisplayFullInformation());
            Console.WriteLine(" ");
            Console.WriteLine(networkSwitch1.DisplayFullInformation());

            for (int i = 0; i < 2; i++)
            {
                Console.Write("setNameHardware: ");
                net[i].setNameHardware(Console.ReadLine());
                Console.Write("setModel: ");
                net[i].setModel(Console.ReadLine());
                Console.Write("setSize: ");
                net[i].setSize(Convert.ToInt32(Console.ReadLine()));
                Console.Write("setNumOfPorts: ");
                net[i].setNumOfPorts(Convert.ToInt32(Console.ReadLine()));
                Console.Write("setPower: ");
                net[i].setPower(Convert.ToInt32(Console.ReadLine()));


                Router router = (Router)net[i];

                Console.Write("setNumberOfChannels: ");
                router.setNumberOfChannels(Convert.ToInt32(Console.ReadLine()));
                Console.Write("setMaximumDataRate: ");
                router.setMaximumDataRate(Convert.ToInt32(Console.ReadLine()));
                Console.Write("setNumberOfLanPorts: ");
                router.setNumberOfLanPorts(Convert.ToInt32(Console.ReadLine()));
                Console.Write("setNumbersOfAntennas: ");
                router.setNumbersOfAntennas(Convert.ToInt32(Console.ReadLine()));
                Console.Write("setNumOfFrequency: ");
                router.setNumOfFrequency(Convert.ToInt32(Console.ReadLine()));

                net[i] = router;

                Console.WriteLine(net[i].DisplayFullInformation());
            }

            for (int i = 2; i < 4; i++)
            {
                Console.Write("setNameHardware: ");
                net[i].setNameHardware(Console.ReadLine());
                Console.Write("setModel: ");
                net[i].setModel(Console.ReadLine());
                Console.Write("setSize: ");
                net[i].setSize(Convert.ToInt32(Console.ReadLine()));
                Console.Write("setNumOfPorts: ");
                net[i].setNumOfPorts(Convert.ToInt32(Console.ReadLine()));
                Console.Write("setPower: ");
                net[i].setPower(Convert.ToInt32(Console.ReadLine()));


                NetworkSwitch router = (NetworkSwitch)net[i];

                Console.Write("setNumInOfPorts: ");
                router.setNumInOfPorts(Convert.ToInt32(Console.ReadLine()));
                Console.Write("setNumOutOfPorts: ");
                router.setNumOutOfPorts(Convert.ToInt32(Console.ReadLine()));
                Console.Write("isAutonomy(1/0): ");
                int  autonomy = Convert.ToInt32(Console.ReadLine());
                bool setAutomy;
                setAutomy = autonomy == 1 ? true : false;
                router.setAutonomy(setAutomy);
                Console.Write("setWeight: ");
                router.setWeight(Convert.ToInt32(Console.ReadLine()));
                Console.Write("setTypeDuplex: ");
                router.setTypeDuplex(Console.ReadLine());

                net[i] = router;

                Console.WriteLine(net[i].DisplayFullInformation());
            }
        }
        public async Task <int> Handle(CreateHardwareCommand request, CancellationToken cancellationToken)
        {
            var contract = await _context.Contracts.FirstOrDefaultAsync(c => c.Id == request.ContractId);

            if (contract == null)
            {
                throw new NullReferenceException("Договор с таким Id не найден.");
            }

            Hardware entity;

            switch (request.HardwareType)
            {
            case HardwareType.Cabinet:
                entity = new Cabinet
                {
                    Position      = request.Position,
                    SerialNumber  = request.SerialNumber,
                    Constructed   = (DateTime)request.Constructed,
                    ConstructedBy = request.ConstructedBy
                };
                break;

            case HardwareType.FlowComputer:
                entity = new FlowComputer
                {
                    Position        = request.Position,
                    SerialNumber    = request.SerialNumber,
                    DeviceModel     = request.DeviceModel,
                    IP              = request.IPAddress,
                    AssemblyVersion = request.AssemblyVersion,
                    CRC32           = request.CRC32,
                    LastConfigDate  = request.LastConfigDate
                };
                break;

            case HardwareType.Flowmeter:
                entity = new Flowmeter
                {
                    Position     = request.Position,
                    SerialNumber = request.SerialNumber,
                    DeviceModel  = request.DeviceModel,
                    DeviceType   = request.DeviceType,
                    MinValue     = request.MinValue,
                    MaxValue     = request.MaxValue,
                    EU           = request.EU,
                    Kfactor      = request.KFactor,
                    SignalType   = request.SignalType,
                    Settings     = new ModbusSettings
                    {
                        Address  = request.ModbusSettings.Address,
                        BoudRate = request.ModbusSettings.BoudRate,
                        DataBits = request.ModbusSettings.DataBits,
                        Parity   = Enum.GetName(typeof(Parity), request.ModbusSettings.Parity),
                        StopBit  = request.ModbusSettings.StopBit
                    }
                };
                break;

            case HardwareType.Network:
                entity = new NetworkHardware
                {
                    Position     = request.Position,
                    SerialNumber = request.SerialNumber,
                    DeviceType   = request.DeviceType,
                    DeviceModel  = request.DeviceModel,
                    Mask         = request.Mask
                };
                foreach (var item in request.NetworkDevices)
                {
                    ((NetworkHardware)entity).NetworkDevices.Add(new NetworkDevice
                    {
                        IP         = item.IP,
                        MacAddress = item.MacAddress,
                        Name       = item.Name
                    });
                }
                break;

            case HardwareType.PLC:
                entity = new PLC
                {
                    Position        = request.Position,
                    SerialNumber    = request.SerialNumber,
                    DeviceModel     = request.DeviceModel,
                    IP              = request.IPAddress,
                    AssemblyVersion = request.AssemblyVersion
                };
                break;

            case HardwareType.Pressure:
                entity = new Pressure
                {
                    Position     = request.Position,
                    SerialNumber = request.SerialNumber,
                    DeviceModel  = request.DeviceModel,
                    DeviceType   = request.DeviceType,
                    MinValue     = request.MinValue,
                    MaxValue     = request.MaxValue,
                    EU           = request.EU,
                    SignalType   = request.SignalType
                };
                break;

            case HardwareType.Temperature:
                entity = new Temperature
                {
                    Position     = request.Position,
                    SerialNumber = request.SerialNumber,
                    DeviceModel  = request.DeviceModel,
                    DeviceType   = request.DeviceType,
                    MinValue     = request.MinValue,
                    MaxValue     = request.MaxValue,
                    EU           = request.EU,
                    SignalType   = request.SignalType
                };
                break;

            case HardwareType.DiffPressure:
                entity = new DiffPressure
                {
                    Position     = request.Position,
                    SerialNumber = request.SerialNumber,
                    DeviceModel  = request.DeviceModel,
                    DeviceType   = request.DeviceType,
                    MinValue     = request.MinValue,
                    MaxValue     = request.MaxValue,
                    EU           = request.EU,
                    SignalType   = request.SignalType
                };
                break;

            case HardwareType.GasAnalyzer:
                entity = new GasAnalyzer
                {
                    Position     = request.Position,
                    SerialNumber = request.SerialNumber,
                    DeviceModel  = request.DeviceModel,
                    DeviceType   = request.DeviceType,
                    MinValue     = request.MinValue,
                    MaxValue     = request.MaxValue,
                    EU           = request.EU,
                    SignalType   = request.SignalType
                };
                break;

            case HardwareType.InformPanel:
                entity = new InformPanel
                {
                    Position     = request.Position,
                    SerialNumber = request.SerialNumber,
                    DeviceModel  = request.DeviceModel,
                    DeviceType   = request.DeviceType,
                    PanelType    = request.PanelType
                };
                break;

            case HardwareType.FireSensor:
                entity = new FireSensor
                {
                    Position     = request.Position,
                    SerialNumber = request.SerialNumber,
                    DeviceModel  = request.DeviceModel,
                    DeviceType   = request.DeviceType
                };
                break;

            case HardwareType.FireModule:
                entity = new FireModule
                {
                    Position     = request.Position,
                    SerialNumber = request.SerialNumber,
                    DeviceType   = request.DeviceType
                };
                break;

            case HardwareType.Valve:
                entity = new Valve
                {
                    Position     = request.Position,
                    SerialNumber = request.SerialNumber,
                    DeviceType   = request.DeviceType,
                    DeviceModel  = request.DeviceModel,
                    SignalType   = request.SignalType,
                    Settings     = new ModbusSettings
                    {
                        Address  = request.ModbusSettings.Address,
                        BoudRate = request.ModbusSettings.BoudRate,
                        DataBits = request.ModbusSettings.DataBits,
                        Parity   = Enum.GetName(typeof(Parity), request.ModbusSettings.Parity),
                        StopBit  = request.ModbusSettings.StopBit
                    }
                };
                break;

            case HardwareType.ARM:
                entity = new ARM
                {
                    Position     = request.Position,
                    Name         = request.ArmName,
                    SerialNumber = request.SerialNumber,
                    Monitor      = request.Monitor,
                    MonitorSN    = request.MonitorSN,
                    Keyboard     = request.Keyboard,
                    KeyboardSN   = request.KeyboardSN,
                    Mouse        = request.Mouse,
                    MouseSN      = request.MouseSN,
                    OS           = request.OS,
                    ProductKeyOS = request.ProductKeyOS,
                    HasRAID      = request.HasRAID
                };
                foreach (var item in request.NetworkAdapters)
                {
                    ((ARM)entity).NetworkAdapters.Add(new NetworkAdapter
                    {
                        IP         = item.IP,
                        MacAddress = item.MacAddress
                    });
                }
                break;

            case HardwareType.APC:
                entity = new APC
                {
                    Position     = request.Position,
                    SerialNumber = request.SerialNumber,
                    DeviceModel  = request.DeviceModel,
                    DeviceType   = request.DeviceType
                };
                break;

            default:
                entity = null;
                break;
            }

            contract.HardwareList.Add(entity);
            contract.HasProtocol = false;
            _context.Update(contract);

            try
            {
                await _context.SaveChangesAsync(cancellationToken);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(entity.Id);
        }