Exemplo n.º 1
0
 public void AddTest()
 {
     Assert.AreEqual(false, _service.AddDevice(new ExampleDeviceDTO()
     {
         Id = 0, Name = "A", Enabled = false
     }).Result);
     Assert.AreEqual(false, _service.AddDevice(new ExampleDeviceDTO()
     {
         Id = -1, Name = "B", Enabled = true
     }).Result);
 }
Exemplo n.º 2
0
 public void AddDeviceTest()
 {
     Assert.AreEqual(true, dService.AddDevice(new DeviceDTO()
     {
         Enabled = true, Id = 0, Name = "A"
     }));
 }
        public async Task <ActionResult> AddDevice(DeviceModel device)
        {
            if (ModelState.IsValid)
            {
                await deviceService.AddDevice(device);

                return(RedirectToAction(nameof(AddDevice)));
            }
            return(View(device));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> AddDevice(DTODevice device)
        {
            bool success = await _service.AddDevice(device);

            if (success)
            {
                return(Ok());
            }
            else
            {
                return(BadRequest());
            }
        }
Exemplo n.º 5
0
 protected void Add_Click(object sender, EventArgs e)
 {
     if (DeviceService.AddDevice(device_num.Text, device_name.Text, manufacturer.Text, Convert.ToDecimal(single_price.Text), depart_num.Text) != -1)
     {
         Response.Write("<script language=javascript>window.alert('添加设备成功!');</script>");
         device_num.Text   = "";
         device_name.Text  = "";
         manufacturer.Text = "";
         single_price.Text = "";
     }
     else
     {
         Response.Write("<script language=javascript>window.alert('该设备编号已存在,请输入其他编号!');</script>");
     }
 }
Exemplo n.º 6
0
        private async void AddDeviceActionAsync(object data)
        {
            var name = await RestService.PingAsync(PartnerAddress);

            if (!string.IsNullOrEmpty(name))
            {
                DeviceService.AddDevice(PartnerAddress, name);
                PartnerAddress = "http://";
            }
            else
            {
                if (!(PartnerAddress.Contains(Port) && PartnerAddress.Contains("localhost")))
                {
                    await Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() => MessageBox.Show("Connection to address " + PartnerAddress + " failed.", "Connection failed", MessageBoxButton.OK, MessageBoxImage.Stop)));
                }
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// 编辑或创建设备
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonX2_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this._device.DeviceName))
            {
                MessageBox.Show("测点名称不能为空");
                return;
            }

            if (string.IsNullOrEmpty(this._device.DeviceNum))
            {
                MessageBox.Show("测点编号不能为空");
                return;
            }

            if (string.IsNullOrEmpty(this._device.IPAddress) || string.IsNullOrEmpty(this._device.Port))
            {
                MessageBox.Show("IP或端口号不能为空");
                return;
            }

            try
            {
                if (_device.Id == 0)
                {
                    DeviceService.AddDevice(this._device);
                }
                else
                {
                    DeviceService.UpdateDevice(this._device);
                }
                if (EditComplete != null)
                {
                    EditComplete(this._device);
                }

                this.Hide();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 8
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");
            string requestBody   = await new StreamReader(req.Body).ReadToEndAsync();
            var    deviceInfo    = JsonConvert.DeserializeObject <DeviceInfo>(requestBody);
            var    a             = Environment.GetEnvironmentVariable("databaseconnectionstring");
            var    context       = new PublicContext(Environment.GetEnvironmentVariable("databaseconnectionstring"));
            var    deviceService = new DeviceService(context);
            var    device        = await deviceService.GetDevice(deviceInfo.compname, deviceInfo.osname);

            if (device != null)
            {
                await deviceService.UpdateDevice(device.Id, deviceInfo);
            }
            else
            {
                await deviceService.AddDevice(deviceInfo);
            }
            return(new OkObjectResult("{\"status\": \"Ok\"}"));
        }
Exemplo n.º 9
0
        public void RegisterDevice(int id)
        {
            var remoteIpAddress = HttpContext.Connection.RemoteIpAddress;

            deviceService.AddDevice(new Device(id, remoteIpAddress.ToString()));
        }
Exemplo n.º 10
0
        public async void Add_Device_Inserts_Element()
        {
            var deviceResult = await service.AddDevice(deviceDto);

            Assert.Null(deviceResult.Messages);
        }