コード例 #1
0
 /// <summary>
 /// 新建设备
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void CreateMouseLeft(object sender, EventArgs e)
 {
     try
     {
         NewDevice objNewDevice = new NewDevice();
         objNewDevice.ShowDialog();
         string title = objNewDevice.m_DeviceNameId;
         if (!string.IsNullOrEmpty(title))
         {
             TreeNode r = new TreeNode();
             r.Text             = title;
             r.ImageKey         = imageList.Images[2].ToString();
             r.SelectedImageKey = imageList.Images[5].ToString();
             OprationSelectRss("AddML", title, null);
             RssTreeView.SelectedNode.Nodes.Add(r);
             RssTreeView.SelectedNode = r;
             RssTreeView.Refresh();
         }
         db.dbMrg.CreatHDateTable(title);
         db.dbMrg.CreateAlertTable(title);
         db.dbMrg.CreateSystemArgsTable(title);
         string strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;  Data Source=..\\..\\mdb\\SystemParameter.mdb";
         string strDBInfo     = String.Format("insert into {0} ([name],[SampVmax],[SampTimer],[ChannlSum],[LTests],[LForsake],[LCleartime],[TOCAlarmup],[USAlarmup],[StorMode],[UvLamp],[PumpPipe])values ('{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}')",
                                              title, title, "5", "240", "1", "6", "3", "30", "500", "1000", "1", "0", "0");
         TOCTest.db.dbMrg.AlterDB(strConnection, strDBInfo);
     }
     catch (Exception ex)
     {
         utils.loghelp.log.Error(ex.Message, ex);
         MessageBox.Show("异常:" + ex.ToString(), "提示");
     }
 }
コード例 #2
0
 private void AddDevice()
 {
     try
     {
         UserInfo objUserInfo = UserInfo.Instance;
         db.dbMrg.AddAlertInfo("01", "01", objUserInfo.getUserName(), DateTime.Now.ToString(), "01", "增加节点!");
         NewDevice objNewDevice = new NewDevice();
         objNewDevice.ShowDialog();
         string title = objNewDevice.m_DeviceNameId;
         if (!string.IsNullOrEmpty(title))
         {
             TreeNode r = new TreeNode();
             r.Text             = title;
             r.ImageKey         = imageList.Images[2].ToString();
             r.SelectedImageKey = imageList.Images[2].ToString();
             OprationSelectRss("AddM", title, null);
             RssTreeView.SelectedNode.Parent.Nodes.Add(r);
             RssTreeView.SelectedNode = r;
             RssTreeView.Refresh();
         }
         db.dbMrg.CreatHDateTable(title);
     }
     catch (Exception ex)
     {
         utils.loghelp.log.Error(ex.Message, ex);
         MessageBox.Show("异常:" + ex.ToString(), "提示");
     }
 }
コード例 #3
0
        public ActionResult addDevice([FromBody] NewDevice newDevice)
        {
            DeviceInfo deviceInfo = new DeviceInfo();

            deviceInfo.UniqueCode = newDevice.UniqueCode;
            deviceInfo.DeviceName = newDevice.DeviceName;
            deviceInfo.CategoryId = newDevice.CategoryId;
            _context.DeviceInfo.Add(deviceInfo);
            _context.SaveChanges();
            return(Ok(deviceInfo));
        }
コード例 #4
0
        internal static async Task <Device> CreateDevice(IWimdioApiClient client)
        {
            var random = Guid.NewGuid().ToString().Split('-').First();

            var device = new NewDevice
            {
                Name        = $"Name {random}",
                Description = $"Description {random}",
                Mac         = Guid.NewGuid().ToString().Replace("-", "").Substring(0, 20)
            };

            return(await client.CreateDevice(device));
        }
コード例 #5
0
        /// <summary>
        /// The ButtonOk_Click method.
        /// </summary>
        /// <param name="sender">The <paramref name="sender"/> parameter.</param>
        /// <param name="args">The <paramref name="args"/> parameter.</param>
        private void ButtonOk_Click(object sender, EventArgs args)
        {
            if (string.IsNullOrEmpty(cbxDeviceType.Text))
            {
                return;
            }

            try
            {
                var newDevice = new NewDevice
                {
                    Ip                   = tbxIp.Text,
                    Name                 = tbxName.Text,
                    Username             = tbxUsername.Text,
                    Password             = tbxPassword.Text,
                    ShouldAutoCommission = ckbxAutoCommission.Checked,
                    Type                 = (Device.Types)cbxDeviceType.SelectedIndex
                };

                if (cbxRecorder.Enabled)
                {
                    var dataStorageItem = cbxRecorder.SelectedItem as ComboboxItem;
                    if (dataStorageItem != null)
                    {
                        var dataStorage = dataStorageItem.Value as DataStorage;
                        if (dataStorage != null)
                        {
                            newDevice.DataStorageId = dataStorage.Id;
                        }
                    }

                    var driverTypeItem = cbxDriverType.SelectedItem as ComboboxItem;
                    if (driverTypeItem != null)
                    {
                        var driverType = driverTypeItem.Value.ToString();
                        if (!string.IsNullOrEmpty(driverType))
                        {
                            newDevice.DriverType = driverType;
                        }
                    }
                }

                MainForm.CurrentSystem.AddDevice(newDevice);
            }
            catch (Exception ex)
            {
                MainForm.Instance.WriteToLog(string.Format("Error adding device: {0}", ex.Message));
                throw;
            }
        }
コード例 #6
0
        /// <summary>
        /// The ButtonOk_Click method.
        /// </summary>
        /// <param name="sender">The <paramref name="sender"/> parameter.</param>
        /// <param name="args">The <paramref name="args"/> parameter.</param>
        private void ButtonOk_Click(object sender, EventArgs args)
        {
            if (string.IsNullOrEmpty(cbxDeviceType.Text))
            {
                return;
            }

            try
            {
                var newDevice = new NewDevice
                {
                    Ip                   = tbxIp.Text,
                    Host                 = tbxHostname.Text,
                    Name                 = tbxName.Text,
                    Username             = tbxUsername.Text,
                    Password             = tbxPassword.Text,
                    ShouldAutoCommission = ckbxAutoCommission.Checked
                };

                if (cbxDeviceType.SelectedIndex > 11)
                {
                    newDevice.Type = (Device.Types)cbxDeviceType.SelectedIndex + 1;
                }
                else
                {
                    newDevice.Type = (Device.Types)cbxDeviceType.SelectedIndex;
                }

                if (cbxDriverType.Enabled)
                {
                    var driverTypeItem = cbxDriverType.SelectedItem as ComboboxItem;
                    if (driverTypeItem != null)
                    {
                        var driverType = driverTypeItem.Value.ToString();
                        if (!string.IsNullOrEmpty(driverType))
                        {
                            newDevice.DriverType = driverType;
                        }
                    }
                }

                MainForm.CurrentSystem.AddDevice(newDevice);
            }
            catch (Exception ex)
            {
                MainForm.Instance.WriteToLog($"Error adding device: {ex.Message}");
                throw;
            }
        }
コード例 #7
0
        public async Task <IActionResult> Post([FromBody] NewDevice request)
        {
            try
            {
                var id = await this._deviceService.Insert(User.Identity.Name, request);

                return(this.Ok(id));
            }
            catch (Exception ex)
            {
                this._logger.LogError(ex, ex.Message);

                throw ex;
            }
        }
コード例 #8
0
        public ActionResult Remove(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            NewDevice device = db.NewDevices.Find(id);

            if (device == null)
            {
                return(HttpNotFound());
            }
            db.NewDevices.Remove(device);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #9
0
ファイル: MainForm.cs プロジェクト: Yeami/cryotech-catalog
 private void DisplayDevices(List <Device> Devices)
 {
     foreach (var NewDevice in Devices)
     {
         if (NewDevice.GetType() == typeof(Fridge))
         {
             Fridge NewFridge = (Fridge)Convert.ChangeType(NewDevice, typeof(Fridge));
             DisplayFridgeDevice(NewFridge);
         }
         else if (NewDevice.GetType() == typeof(Freezer))
         {
             Freezer NewFreezer = (Freezer)Convert.ChangeType(NewDevice, typeof(Freezer));
             DisplayFreezerDevice(NewFreezer);
         }
     }
 }
コード例 #10
0
ファイル: RedirectModule.cs プロジェクト: chj853/51degrees
 /// <summary>
 /// Record the new device if we're as certain as we can be that it is
 /// not one we've processed already.
 /// </summary>
 /// <param name="context">Context of the request.</param>
 private void RecordNewDevice(HttpContext context)
 {
     try
     {
         if (NewDevice.Enabled &&
             context.Request.HttpMethod == "GET" &&
             context.Handler != null &&
             IsPageType(context.Handler.GetType()) &&
             IsFirstTime(context, false))
         {
             NewDevice.RecordNewDevice(context.Request);
         }
     }
     catch (Exception ex)
     {
         EventLog.Debug(ex);
     }
 }
コード例 #11
0
        /// <summary>
        /// Insert new device
        /// </summary>
        /// <param name="username">Username of device</param>
        /// <param name="model">Device info</param>
        /// <returns>Id Device</returns>
        public async Task <int> Insert(string username, NewDevice model)
        {
            try
            {
                var newDevice = model.Adapt <Device>();

                newDevice.Username  = model.Username;
                newDevice.CreatedBy = username ?? model.Username;
                newDevice.CreatedAt = DateTime.Now;

                var result = await this._deviceRepository.InsertAsync(newDevice);

                return(result);
            }
            catch
            {
                throw;
            }
        }
コード例 #12
0
        /// <summary>
        /// API call to add new device to database.
        /// </summary>
        /// <param name="id">Identifier of the device</param>
        /// <param name="loc">Location ID</param>
        /// <param name="hw">Hardware ID</param>
        /// <param name="sw">Software ID</param>
        /// <returns>Device that was created.</returns>
        public object Get(string id, int loc, int hw, int sw)
        {
            var err = new { Error = "An error occured." };

            // Check Device ID against a whitelist of values to prevent XSS
            if (!IsmIoTSettings.RegexHelper.Text.IsMatch(id))
            {
                return(err);
            }

            // If device with same ID already exists, return error
            if (db.IsmDevices.Any(d => d.DeviceId == id) || db.NewDevices.Any(d => d.DeviceId == id))
            {
                return new { Error = "This device ID is already taken." }
            }
            ;
            // Generate random password of length 32 with at least 1 non-alphanumerical character
            string password = System.Web.Security.Membership.GeneratePassword(32, 1);
            // We create a hash of the password to store it in Database
            // No need for salt since this scrypt implementation adds salt automatically (scrypt requires salt)
            string hash = new ScryptEncoder().Encode(password);
            var    dev  = new NewDevice
            {
                DeviceId   = id,
                HardwareId = hw,
                LocationId = loc,
                ReleaseId  = sw,
                Code       = generator.Next(0, 999999).ToString("D6"),
                Approved   = false,
                Password   = hash
            };

            db.NewDevices.Add(dev);
            db.SaveChanges();
            return(new
            {
                Id = dev.DeviceId,
                Code = dev.Code,
                Password = password
            });
        }
コード例 #13
0
ファイル: Mesh.cs プロジェクト: yoav79/AquilaSharp
        //recepcion de paketes 00:00:00:00:00:00:00
        private void _bridge_Receive(object sender, PackagesReceivedEventArgs e)
        {
            LogProviderManager.Logger.Log(LogType.debug, "Message Receive");

            if (e.Packet.Frame.Length <= 0)
            {
                return;
            }

            if (e.Packet.Frame[0] == CmdGetEui)
            {
                Announce(e.Packet.SrcAddr);
            }
            else if (e.Packet.Frame[0] == CmdResetEui && e.Packet.Frame.Length >= 9)
            {
                var euiAddr = e.Packet.Frame.Skip(1).Take(8).ToArray();
                NewDevice?.Invoke(this, new NewDeviceReceivedEventArgs(e.Packet.SrcAddr, euiAddr));
            }
            else
            {
                Receive?.Invoke(this, new PackagesReceivedEventArgs(e.Packet));
            }
        }
コード例 #14
0
ファイル: RedirectModule.cs プロジェクト: chj853/51degrees
 /// <summary>
 /// Sends any queued data and records the module being
 /// disposed if debug enabled.
 /// </summary>
 public virtual void Dispose()
 {
     EventLog.Debug("Disposing Redirection Module");
     NewDevice.Send();
 }
コード例 #15
0
        public override async Task HandleReceivedMessage(OicReceivedMessage received)
        {
            var isDiscoverResponse = false;

            lock (_discoverRequests)
                isDiscoverResponse = _discoverRequests.Contains(received.Message.RequestId);

            if (!isDiscoverResponse)
            {
                _logger?.LogTrace($"Request ({received.Message.RequestId}) was not intended for {nameof(OicResourceDiscoverClient)}");

                if (Handler != null)
                {
                    await Handler.HandleReceivedMessage(received);
                }
                return;
            }

            var response = received.Message as OicResponse;

            if (response.ResposeCode != OicResponseCode.Content)
            {
                _logger?.LogInformation($"Response to discover request resulted in {response.ResposeCode:G}");
                _logger?.LogInformation(_configuration.Serialiser.Prettify(response.Content, response.ContentType));
                return;
            }

            var resources = _configuration.Serialiser.Deserialise(response.Content, response.ContentType) as OicResourceList
                            ?? throw new OicException($"Incorrect response for /oic/res request");

            //Todo: Review Resource Directory (OIC Core v1.1.1: Section 11.3.6.1.2 Resource directory)
            foreach (var resource in resources)
            {
                var newDevice = false;

                if (!(resource is OicResourceDirectory directory))
                {
                    _logger?.LogError($"{nameof(resource)} ({resource.GetType()}) is not of type {typeof(OicResourceList)}. Skipping");
                    continue;
                }

                OicRemoteDevice device = null;
                lock (Devices)
                    device = Devices.FirstOrDefault(d => d.DeviceId == directory.DeviceId);

                if (device == null)
                {
                    _logger?.LogDebug($"Discovered new device ({directory.DeviceId})");
                    device = new OicRemoteDevice(received.Endpoint)
                    {
                        DeviceId = directory.DeviceId
                    };
                    lock (Devices)
                        Devices.Add(device);
                    newDevice = true;
                }
                else
                {
                    _logger?.LogDebug($"Updating existing device ({directory.DeviceId})");
                }

                // Update device name
                device.Name = device.Name ?? directory.Name;

                // Add or update device resources
                // TODO: Do we want to clear out old resources?
                var newResources = directory.Links.Select(l => l.CreateResource(_configuration.Resolver));
                foreach (var newResource in newResources)
                {
                    var oldResource = device.Resources.SingleOrDefault(r => r.RelativeUri == newResource.RelativeUri);
                    if (oldResource == null)
                    {
                        device.Resources.Add(newResource);
                    }
                    else
                    {
                        oldResource.UpdateFields(newResource);
                    }
                }

                if (newDevice)
                {
                    NewDevice?.Invoke(this, new OicNewDeviceEventArgs {
                        Device = device, Endpoint = received.Endpoint
                    });
                }
            }
        }