public void AssignDevice(Device device)
        {
            this.Device = device;
            this.Progress = 0;
            this.Status = StationStatus.Idle;

            this.StationControl.Init();
        }
 public void UpdateDevice(Device device)
 {
     this.deviceRepo.Update(device);
 }
        /// <summary>
        /// Creats an order element in database.
        /// Create device elements and associate mac adresse to each device.
        /// </summary>
        /// <returns>The created order item</returns>
        public Order CreateOrder(string customerName, string orderNo, string deviceType, int deviceCount,
            string paramSetName)
        {
            // find paramset
            var paramSet = paramSetRepo.FirstOrDefault(ps => ps.Name == paramSetName);
            if (paramSet == null)
            {
                throw new NullReferenceException("Parameter set not found");
            }

            // create order and store to db
            var order = new Order()
            {
                CustomerName = customerName,
                OrderNo = orderNo,
                ForDeviceType = deviceType,
                OrderDate = DateTime.Now,
                NumberOfDevices = deviceCount,
                ParameterSet = paramSet
            };
            orderRepo.Add(order);

            // create devices and device parameters
            Device lastDevice = null;
            for (int i = 0; i < deviceCount; i++)
            {
                var device = new Device
                {
                    OrderNo = orderNo,
                    ParameterList = new List<Parameter>()
                };

                foreach (var param in paramSet.Parameters)
                {
                    // get first parameter from parameterset, all others by cloning from last device
                    var nextParam = lastDevice == null
                        ? param.GetNextAsClone(i == 0)
                        : lastDevice.GetParameter(param.TagId).GetNextAsClone(isFirstOfOrder: false);

                    device.ParameterList.Add(nextParam);
                }

                device.ServerId = device.GetParameterTargetValue(ParameterTagId.ServerId).ToUpperInvariant();
                if (string.IsNullOrWhiteSpace(device.ServerId))
                {
                    throw new NullReferenceException("ServerID must be available!");
                }

                // set serial no based on server Id
                var serialBytes = device.GetParameterTargetValue(ParameterTagId.ServerId).FromHexString().Reverse().Take(4).ToArray();
                var serialNoParam = device.GetParameter(ParameterTagId.ManufacturerSerialNumber);
                serialNoParam.TargetValue = BitConverter.ToUInt32(serialBytes, 0).ToString("D8");
                device.SerialNo = serialNoParam.TargetValue;

                // store device with parameters
                deviceRepo.Add(device);
                Log.Information("Device {@device} created", device);
                lastDevice = device;
            }

            return order;
        }