Example #1
0
        /// <summary>
        ///
        /// </summary>
        public void addRecord(SystemRecord pRecord)
        {
            if (pRecord != null)
            {
                // Check if record already exists
                foreach (SystemRecord lTmp in cRecordList)
                {
                    if (lTmp.ID == pRecord.ID)
                    {
                        throw new RecordExistsException("System alrady exists.");
                    }
                }

                if (!Regex.Match(pRecord.SrcMAC.Trim(), @"^[\da-f]{1,2}[\-:][\da-f]{1,2}[\-:][\da-f]{1,2}[\-:][\da-f]{1,2}[\-:][\da-f]{1,2}[\-:][\da-f]{1,2}$", RegexOptions.IgnoreCase).Success)
                {
                    throw new RecordException("Something is wrong with the MAC address");
                }

                if (!Regex.Match(pRecord.SrcIP.Trim(), @"^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$", RegexOptions.IgnoreCase).Success)
                {
                    throw new RecordException("Something is wrong with the IP address");
                }

                cRecordList.Add(pRecord);

                // Resize the DGV to the defined maximum size. \
                while (cRecordList.Count > cMaxTableRows)
                {
                    cRecordList.RemoveAt(0);
                }

                notifyRecords();
            }
        }
        private void SaveHistory(DataTable dt, string filename)
        {
            if (dt != null && dt.Rows.Count > 0)
            {
                var obj = new SystemRecord();
                obj.Id           = Common.GenerateId();
                obj.Filename     = filename;
                obj.Description  = dt.Rows[0]["Description"].ToString();
                obj.DateCreated  = DateTime.Now;
                obj.ComputerName = Common.GetComputerName(Request.UserHostAddress);

                _SystemRecordService.Create(obj);
            }
        }
Example #3
0
 /// <summary>
 ///
 /// </summary>
 private void TryAddRecord(SystemRecord newRecord)
 {
     try
     {
         this.AddRecord(newRecord);
     }
     catch (RecordException rex)
     {
         this.pluginProperties.HostApplication.LogMessage($"{this.Config.PluginName}: {rex.Message}");
     }
     catch (RecordExistsException)
     {
     }
     catch (Exception ex)
     {
         this.pluginProperties.HostApplication.LogMessage($"{this.Config.PluginName} 2: {ex.Message}");
     }
 }
Example #4
0
        public void AddRecord(SystemRecord record)
        {
            if (this.InvokeRequired)
            {
                this.BeginInvoke(new AddRecordDelegate(this.AddRecord), new object[] { record });
                return;
            }

            if (record == null)
            {
                throw new RecordException("The record is invalid");
            }

            if (!Regex.Match(record.SrcMac.Trim(), @"^[\da-f]{1,2}[\-:][\da-f]{1,2}[\-:][\da-f]{1,2}[\-:][\da-f]{1,2}[\-:][\da-f]{1,2}[\-:][\da-f]{1,2}$", RegexOptions.IgnoreCase).Success)
            {
                throw new RecordException("Something is wrong with the MAC address");
            }

            if (!Regex.Match(record.SrcIp.Trim(), @"^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$", RegexOptions.IgnoreCase).Success)
            {
                throw new RecordException("Something is wrong with the IP address");
            }

            if (this.systemRecords.ToList().FindAll(elem => record.Id == elem.Id).Count() > 0)
            {
                throw new RecordExistsException($"System ({record.Id}) already exists.");
            }

            // Add new record to the data grid view
            lock (this)
            {
                this.dgv_Systems.SuspendLayout();
                this.systemRecords.Add(record);

                // Resize the DGV to the defined maximum size. \
                while (this.systemRecords.Count > MAX_TABLE_ROWS)
                {
                    this.systemRecords.RemoveAt(0);
                }

                this.dgv_Systems.ResumeLayout();
            }
        }
        public MessageReport Create(SystemRecord obj)
        {
            var re = new MessageReport();

            re.Message   = "Error";
            re.isSuccess = false;

            try
            {
                _SystemRecordRepository.Add(obj);

                Save();

                re.Message   = "Thêm mới thành công";
                re.isSuccess = true;
            }
            catch (Exception ex)
            {
                re.Message   = ex.Message;
                re.isSuccess = false;
            }

            return(re);
        }
Example #6
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="pRecord"></param>
 public void addRecord(SystemRecord pRecord)
 {
     cDomain.addRecord(pRecord);
 }