示例#1
0
        //
        /// <summary>
        /// insert Incident and the attached Notes, then update the logs with
        /// the new incident id.  Delete any logs in the deleted.  Ignore any
        /// deleted notes, then shouldn't exist yet.
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public NetworkIncidentData Insert(NetworkIncidentSave data)
        {
            System.Diagnostics.Debug.WriteLine(data.user.UserName + ' ' + data.incident.IPAddress);
            long _id     = 0;
            int  _server = data.incident.ServerId;

            //
            try
            {
                Log.Logger.Log(LoggingLevel.Debug, data.user.UserName, MethodBase.GetCurrentMethod(), data.incident.ToString());
                IncidentAccess   _ia       = new IncidentAccess(_niEntities);
                NetworkLogAccess _nla      = new NetworkLogAccess(_niEntities);
                Incident         _incident = _ia.Insert(data.incident);
                _incident.IncidentNotes = data.incidentNotes
                                          .AsEnumerable().Select(itd => itd.ToIncidentNote()).ToList();
                _niEntities.SaveChanges();
                _id = _incident.IncidentId;
                // List<NetworkLogData> networkLogs;
                foreach (NetworkLogData _nl in data.networkLogs.Where(_l => _l.Selected == true))
                {
                    _nl.IncidentId = _id;
                    _nla.UpdateIncidentId(_nl);
                }
                // List<NetworkLogData> deletedLogs;
                foreach (NetworkLogData _nl in data.deletedLogs)
                {
                    _nla.Delete(_nl.NetworkLogId);
                }
                _niEntities.SaveChanges();
            }
            catch (DbEntityValidationException _entityEx)
            {
                // extension method
                string _errors = _entityEx.EntityValidationErrors.GetDbValidationErrors();
                Log.Logger.Log(LoggingLevel.Error, data.user.UserName, MethodBase.GetCurrentMethod(), data.incident.ToString() + ' ' + _errors, _entityEx);
                System.Diagnostics.Debug.WriteLine(_errors);
            }
            catch (Exception _ex)
            {
                //Logger _logger = new Logger(_niEntities, "NetworkIncident");
                Log.Logger.Log(LoggingLevel.Error, data.user.UserName, MethodBase.GetCurrentMethod(), data.incident.ToString() + _ex.Message, _ex);
                System.Diagnostics.Debug.WriteLine(_ex.ToString());
            }
            return(GetByPrimaryKey(_id, _server));
        }
示例#2
0
        //
        /// <summary>
        /// EMail the last ISP Report
        /// </summary>
        /// <param name="data"></param>
        private void EMailIspReport(NetworkIncidentSave data)
        {
            Log.Logger.Log(LoggingLevel.Debug, data.user.UserName, MethodBase.GetCurrentMethod(), string.Format("Entering, Mailing: {0}, incident: {1}", data.incident.AbuseEmailAddress, data.incident.IncidentId));
            var _notes = _niEntities.Incidents.Where(i => i.IncidentId == data.incident.IncidentId).FirstOrDefault()
                         .IncidentNotes.Where(n => n.NoteTypeId == Constants.incidentTypeIdOfIspReport).ToList( );

            if (_notes.Count > 0)
            {
                try
                {
                    IncidentNote _note = _notes[_notes.Count - 1];   // last ISP Rpt
                    // translate the message from json string of sendgrid type
                    JavaScriptSerializer j    = new JavaScriptSerializer();
                    SendGridMessage      _sgm = (SendGridMessage)j.Deserialize(_note.Note, typeof(SendGridMessage));
                    IEMail _email             = new EMail(Log.Logger).NewMailMessage(_sgm).Send( );
                }
                catch (Exception _ex)
                {
                    Log.Logger.Log(LoggingLevel.Error, data.user.UserName, MethodBase.GetCurrentMethod(), _ex.Message + ", " + data.incident.ToString(), _ex);
                }
            }
            Log.Logger.Log(LoggingLevel.Debug, data.user.UserName, MethodBase.GetCurrentMethod(), string.Format("Exiting, Mailing: {0}, incident: {1}", data.incident.AbuseEmailAddress, data.incident.IncidentId));
        }
示例#3
0
        //
        public NetworkIncidentData Update(NetworkIncidentSave data)
        {
            string _params = string.Format("Entering with: incidentId: {0}, UserName: {1}", data.incident.IncidentId, data.user.UserName);

            System.Diagnostics.Debug.WriteLine(_params);
            //
            long     _id       = data.incident.IncidentId;
            Incident _incident = null;

            try
            {
                Log.Logger.Log(LoggingLevel.Debug, data.user.UserName, MethodBase.GetCurrentMethod(), "Entering ... " + data.incident.ToString());
                IncidentAccess     _ia             = new IncidentAccess(_niEntities);
                NetworkLogAccess   _nla            = new NetworkLogAccess(_niEntities);
                IncidentNoteAccess _ina            = new IncidentNoteAccess(_niEntities);
                IncidentData       _incidentBefore = _ia.GetByPrimaryKey(data.incident.IncidentId);
                _incident = _ia.Update(data.incident);
                // Update notes
                foreach (IncidentNoteData _in in data.incidentNotes.Where(_r => _r.IsChanged == true && _r.IncidentNoteId > 0))
                {
                    _ina.Update(_in);
                }
                // Add notes
                foreach (IncidentNoteData _in in data.incidentNotes.Where(_r => _r.IncidentNoteId < 0))
                {
                    _incident.IncidentNotes.Add(_in.ToIncidentNote());
                }
                // Delete notes
                foreach (IncidentNoteData _in in data.deletedNotes)
                {
                    _ina.Delete(_in.IncidentNoteId);
                }
                // Update logs
                foreach (NetworkLogData _nl in data.networkLogs.Where(_l => _l.IsChanged == true))
                {
                    _nla.UpdateIncidentId(_nl);
                }
                // Delete Logs;
                foreach (NetworkLogData _nl in data.deletedLogs)
                {
                    if (_nl.Selected == false)
                    {
                        _nla.Delete(_nl.NetworkLogId);
                    }
                }
                //
                _niEntities.SaveChanges();
                Log.Logger.Log(LoggingLevel.Info, data.user.UserName, MethodBase.GetCurrentMethod(), "Inside, after save ... id: " + data.incident.IncidentId.ToString());
                //
                if (_incidentBefore.Mailed == false && data.incident.Mailed == true)
                {
                    Task.Run(() =>
                    {
                        EMailIspReport(data);
                    });
                }
            }
            catch (DbEntityValidationException _entityEx)
            {
                // extension method
                string _errors = _entityEx.EntityValidationErrors.GetDbValidationErrors();
                Log.Logger.Log(LoggingLevel.Error, data.user.UserName, MethodBase.GetCurrentMethod(), data.incident.ToString() + ' ' + _errors, _entityEx);
                System.Diagnostics.Debug.WriteLine(_errors);
            }
            catch (Exception _ex)
            {
                Log.Logger.Log(LoggingLevel.Error, data.user.UserName, MethodBase.GetCurrentMethod(), data.incident.ToString() + _ex.Message, _ex);
                System.Diagnostics.Debug.WriteLine(_ex.ToString());
            }
            NetworkIncidentData _networkIncident =
                GetByPrimaryKey(data.incident.IncidentId, data.incident.ServerId);

            Log.Logger.Log(LoggingLevel.Debug, data.user.UserName, MethodBase.GetCurrentMethod(), "Exiting ... " + _networkIncident.incident.ToString());
            return(_networkIncident);
        }