Esempio n. 1
0
        // GET: Report/Edit/5
        public ActionResult Edit(int id)
        {
            string        connectionString = Configuration["ConnectionStrings:DefaultConnection"];
            ReportMapping _report          = new ReportMapping();

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                string sql = $"select rm.Id,bi.Id bankId,bi.Name Bank,br.Id branchId,br.BranchTitle,ui.FirstName,ui.ContactNo,rm.ReportTitle,rm.ReportUrl from tbl_ReportMappingInfo rm " +
                             $"left join tbl_BankInfo bi on rm.BankId=bi.Id " +
                             $"left join tbl_BranchInfo br on rm.BranchId = br.Id " +
                             $"left join tbl_UserInfo ui on rm.UserId= ui.Id Where rm.Id='{id}'";
                SqlCommand command = new SqlCommand(sql, connection);
                connection.Open();
                using (SqlDataReader dataReader = command.ExecuteReader())
                {
                    while (dataReader.Read())
                    {
                        _report.Id          = Convert.ToInt32(dataReader["Id"]);
                        _report.BankId      = Convert.ToInt32(dataReader["bankId"]);
                        _report.Bank_VW     = Convert.ToString(dataReader["Bank"]);
                        _report.BranchId    = Convert.ToInt32(dataReader["branchId"]);
                        _report.Branch_VW   = Convert.ToString(dataReader["BranchTitle"]);
                        _report.Username    = Convert.ToString(dataReader["FirstName"]);
                        _report.ContactNo   = Convert.ToString(dataReader["ContactNo"]);
                        _report.ReportTitle = Convert.ToString(dataReader["ReportTitle"]);
                        _report.ReportUrl   = Convert.ToString(dataReader["ReportUrl"]);
                    }
                }
                connection.Close();
            }
            return(View(_report));
        }
Esempio n. 2
0
        public ActionResult Save_Mapping(BigViewModel bigModel)
        {
            ReportHeader header = new ReportHeader();

            header.ElementSeparator    = (string)Session["ElementSeparator"];
            header.NewlineSeparator    = (string)Session["NewlineSeparator"];
            header.SubElementSeparator = (string)Session["SubElementSeparator"];

            header.Country     = bigModel.ReportHeader.Country;
            header.PartnerName = bigModel.ReportHeader.PartnerName;
            header.ReportType  = bigModel.ReportHeader.ReportType;

            //Insert through EDIFACTMapping
            header.EDI_FileType = "EDIFACT";


            //Load from Session
            if (Session["SegmentInitiator"] != null && Session["SegmentLocation"] != null && Session["FieldName"] != null)
            {
                SegmentInitiator    = (List <string>)Session["SegmentInitiator"];
                SegmentLocation     = (List <int>)Session["SegmentLocation"];
                FieldName           = (List <string>)Session["FieldName"];
                SegmentIdentifier_2 = (List <string>)Session["SegmentIdentifier_2"];
            }

            int id;

            using (EDI_ReportConverterEntities entity = new EDI_ReportConverterEntities())
            {
                entity.ReportHeaders.Add(header);
                entity.SaveChanges();
                id = header.Id;

                for (int i = 0; i < SegmentInitiator.Count; i++)
                {
                    ReportMapping mapping = new ReportMapping();
                    mapping.ReportHeader_Id     = id;
                    mapping.SegmentInitiator    = SegmentInitiator[i];
                    mapping.SegmentLocation     = SegmentLocation[i];
                    mapping.FieldName           = FieldName[i];
                    mapping.SegmentIdentifier_2 = SegmentIdentifier_2[i];

                    entity.ReportMappings.Add(mapping);
                    entity.SaveChanges();
                }
            }


            //validate if ReportHeader fields present (Make all ReportHeader fields mandatory)

            TempData["Message_Save_Mapping_Confirmation"] = "Mapping saved successfully!";

            Session["ReportheaderID"] = id; // Saving id in session. To be used in CriteriaController. Passing data as parameter to RedirecttoAction doesn't work

            //return View("Index");
            //return RedirectToAction("Index", "EDIFACT");  //redirects to upload and convert page
            return(RedirectToAction("Index", "Criteria")); // creating a new criteria that uses the given map header id
        }
        public ActionResult Save_Mapping(BigViewModel bigModel)
        {
            ReportHeader header = new ReportHeader();

            header.ElementSeparator    = (string)Session["ElementSeparator"];
            header.NewlineSeparator    = (string)Session["NewlineSeparator"];
            header.SubElementSeparator = (string)Session["SubElementSeparator"];

            header.Country     = bigModel.ReportHeader.Country;
            header.PartnerName = bigModel.ReportHeader.PartnerName;
            header.ReportType  = bigModel.ReportHeader.ReportType;


            //Load from Session
            if (Session["SegmentInitiator"] != null && Session["FieldName"] != null)
            {
                SegmentInitiator    = (List <string>)Session["SegmentInitiator"];
                SegmentLocation     = (List <int>)Session["SegmentLocation"];
                FieldName           = (List <string>)Session["FieldName"];
                SegmentIdentifier_2 = (List <string>)Session["SegmentIdentifier_2"];
            }

            using (EDI_ReportConverterEntities entity = new EDI_ReportConverterEntities())
            {
                entity.ReportHeaders.Add(header);
                entity.SaveChanges();
                int id = header.Id;

                for (int i = 0; i < SegmentInitiator.Count; i++)
                {
                    ReportMapping mapping = new ReportMapping();
                    mapping.ReportHeader_Id  = id;
                    mapping.SegmentInitiator = SegmentInitiator[i];
                    //mapping.SegmentLocation = SegmentLocation[i];
                    mapping.FieldName = FieldName[i];
                    //mapping.SegmentIdentifier_2 = SegmentIdentifier_2[i];

                    entity.ReportMappings.Add(mapping);
                    entity.SaveChanges();
                }
            }


            //validate if ReportHeader fields present (Make all ReportHeader fields mandatory)

            TempData["Message_Save_Mapping_Confirmation"] = "Mapping saved successfully!";


            //return View("Index");
            return(RedirectToAction("Index", "EDIFACT"));
        }
Esempio n. 4
0
        public IActionResult Index()
        {
            var _userObj = HttpContext.Session.GetObjectFromJson <User>("_userObj");

            if (_userObj != null)
            {
                List <ReportMapping> _reportList = new List <ReportMapping>();
                string connectionString          = Configuration["ConnectionStrings:DefaultConnection"];
                using (SqlConnection connection = new SqlConnection(connectionString))
                {
                    //SqlDataReader
                    connection.Open();

                    string sql = "select rm.Id,ui.Id,bi.Id bankId,bi.Name BankName,br.Id branchId,br.BranchTitle,ui.FirstName,ui.ContactNo,rm.ReportTitle,rm.ReportUrl from tbl_ReportMappingInfo rm " +
                                 "left join tbl_BankInfo bi on rm.BankId=bi.Id " +
                                 "left join tbl_BranchInfo br on rm.BranchId = br.Id " +
                                 "left join tbl_UserInfo ui on rm.UserId= ui.Id where ui.id='" + _userObj.Id + "' and br.Id='" + _userObj.BranchId + "' "; SqlCommand command = new SqlCommand(sql, connection);
                    using (SqlDataReader dataReader = command.ExecuteReader())
                    {
                        while (dataReader.Read())
                        {
                            ReportMapping _report = new ReportMapping();
                            _report.Id          = Convert.ToInt32(dataReader["Id"]);
                            _report.BankId      = Convert.ToInt32(dataReader["bankId"]);
                            _report.Bank_VW     = Convert.ToString(dataReader["BankName"]);
                            _report.BranchId    = Convert.ToInt32(dataReader["branchId"]);
                            _report.Branch_VW   = Convert.ToString(dataReader["BranchTitle"]);
                            _report.Username    = Convert.ToString(dataReader["FirstName"]);
                            _report.ContactNo   = Convert.ToString(dataReader["ContactNo"]);
                            _report.ReportTitle = Convert.ToString(dataReader["ReportTitle"]);
                            _report.ReportUrl   = Convert.ToString(dataReader["ReportUrl"]);
                            _reportList.Add(_report);
                        }
                    }
                    connection.Close();
                }

                return(View(_reportList));
            }
            else
            {
                return(RedirectToAction("Login", "Home"));
            }
        }
Esempio n. 5
0
        public ActionResult Edit(ReportMapping _report)
        {
            string connectionString = Configuration["ConnectionStrings:DefaultConnection"];

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                _report.UpdatedBy   = "Admin";
                _report.UpdatedDate = DateTime.Now;

                string sql = $"Update tbl_ReportMappingInfo SET ReportTitle='{_report.ReportTitle}', ReportUrl='{_report.ReportUrl}',UpdateBy='{_report.UpdatedBy}',UpdateDate='{_report.UpdatedDate}' Where Id='{_report.Id}'";
                using (SqlCommand command = new SqlCommand(sql, connection))
                {
                    connection.Open();
                    command.ExecuteNonQuery();
                    connection.Close();
                }
            }
            //return RedirectToAction("Index");
            return(RedirectToAction("Index", "Report"));
        }
Esempio n. 6
0
        public ActionResult Create(ReportMapping _report)
        {
            try
            {
                // TODO: Add insert logic here
                if (ModelState.IsValid)
                {
                    string connectionString = Configuration["ConnectionStrings:DefaultConnection"];
                    using (SqlConnection connection = new SqlConnection(connectionString))
                    {
                        int _selectedValueBank     = _report.BankId;
                        int _selectedValueBrnach   = _report.BranchId;
                        int _selectedValueUserType = _report.UserId;

                        _report.CreatedBy   = "Admin";
                        _report.CreatedDate = DateTime.Now;

                        string sql = $"Insert Into tbl_ReportMappingInfo (BankId, BranchId, UserId,ReportTitle,ReportUrl,CreatedBy,CreatedDate) Values ('{_report.BankId}', '{_report.BranchId}','{_report.UserId}','{_report.ReportTitle}','{_report.ReportUrl}','{_report.CreatedBy}','{_report.CreatedDate}')";
                        using (SqlCommand command = new SqlCommand(sql, connection))
                        {
                            command.CommandType = CommandType.Text;
                            connection.Open();
                            command.ExecuteNonQuery();
                            connection.Close();
                        }
                        return(RedirectToAction("Index"));
                    }
                }
                else
                {
                    return(View());
                }

                //return RedirectToAction(nameof(Index));
            }
            catch (Exception ex)
            {
                throw ex;
                //return View();
            }
        }
Esempio n. 7
0
        private Dictionary <string, string> GetParameters(ReportMapping mapping)
        {
            var parametes = new Dictionary <string, string>();

            if (StartDate.HasValue)
            {
                parametes.Add("@inicio", StartDate.Value.ToShortDateString());
            }
            if (LastDate.HasValue)
            {
                parametes.Add("@fin", LastDate.Value.ToShortDateString());
            }

            parametes.Add("@whscode", Config.WhsCode);


            if (mapping.ParameterType == 1)
            {
                parametes.Add("@ItmsGrpCod", GetItmsGrpCode());
            }

            return(parametes);
        }
Esempio n. 8
0
        // GET: Report
        public ActionResult Index()
        {
            List <ReportMapping> _reportList = new List <ReportMapping>();
            string connectionString          = Configuration["ConnectionStrings:DefaultConnection"];

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                //SqlDataReader
                connection.Open();

                string sql = "select rm.Id,bi.Id bankId,bi.Name BankName,br.Id branchId,br.BranchTitle,ui.FirstName,ui.ContactNo,rm.ReportTitle,rm.ReportUrl from tbl_ReportMappingInfo rm " +
                             "left join tbl_BankInfo bi on rm.BankId=bi.Id " +
                             "left join tbl_BranchInfo br on rm.BranchId = br.Id " +
                             "left join tbl_UserInfo ui on rm.UserId= ui.Id"; SqlCommand command = new SqlCommand(sql, connection);
                using (SqlDataReader dataReader = command.ExecuteReader())
                {
                    while (dataReader.Read())
                    {
                        ReportMapping _report = new ReportMapping();
                        _report.Id          = Convert.ToInt32(dataReader["Id"]);
                        _report.BankId      = Convert.ToInt32(dataReader["bankId"]);
                        _report.Bank_VW     = Convert.ToString(dataReader["BankName"]);
                        _report.BranchId    = Convert.ToInt32(dataReader["branchId"]);
                        _report.Branch_VW   = Convert.ToString(dataReader["BranchTitle"]);
                        _report.Username    = Convert.ToString(dataReader["FirstName"]);
                        _report.ContactNo   = Convert.ToString(dataReader["ContactNo"]);
                        _report.ReportTitle = Convert.ToString(dataReader["ReportTitle"]);
                        _report.ReportUrl   = Convert.ToString(dataReader["ReportUrl"]);
                        _reportList.Add(_report);
                    }
                }
                connection.Close();
            }
            return(View(_reportList));
            //return View();
        }
Esempio n. 9
0
        /// <summary>
        ///     Analyze report
        /// </summary>
        /// <param name="report">report</param>
        /// <exception cref="ArgumentNullException">report</exception>
        public async Task Analyze(IMessageContext context, ErrorReportEntity report)
        {
            if (report == null)
            {
                throw new ArgumentNullException(nameof(report));
            }

            var countThisMonth = _repository.GetMonthReportCount();

            if (countThisMonth >= 500)
            {
                _repository.AddMissedReport(DateTime.Today);
                return;
            }

            _logger.Debug("Running as " + context.Principal.ToFriendlyString());
            var exists = _repository.ExistsByClientId(report.ClientReportId);

            if (exists)
            {
                _logger.Warn($"Report have already been uploaded: {report.ClientReportId} for {report.RemoteAddress}.");
                return;
            }

            ErrorHashCode hashcodeResult;

            try
            {
                hashcodeResult = _hashCodeGenerator.GenerateHashCode(report);
                report.Init(hashcodeResult.HashCode);
            }
            catch (Exception ex)
            {
                var reportJson = JsonConvert.SerializeObject(report);
                if (reportJson.Length > 1000000)
                {
                    reportJson = reportJson.Substring(0, 100000) + "[....]";
                }
                _logger.Fatal($"Failed to init report {reportJson}", ex);
                return;
            }

            var storeReport        = true;
            var applicationVersion = GetVersionFromReport(report);
            var isReOpened         = false;

            IncidentBeingAnalyzed incident = null;

            if (hashcodeResult.CompabilityHashSource != null)
            {
                incident = _repository.FindIncidentForReport(report.ApplicationId, hashcodeResult.CompabilityHashSource, hashcodeResult.CollisionIdentifier);
                if (incident != null)
                {
                    report.Init(hashcodeResult.CompabilityHashSource);
                }
            }
            if (incident == null)
            {
                incident = _repository.FindIncidentForReport(report.ApplicationId, report.ReportHashCode, hashcodeResult.CollisionIdentifier);
            }

            var isNewIncident = false;

            if (incident == null)
            {
                if (report.Exception == null)
                {
                    _logger.Debug("Got no exception");
                }

                isNewIncident = true;
                incident      = BuildIncident(report);
                _repository.CreateIncident(incident);
                await _repository.StoreReportStats(new ReportMapping()
                {
                    IncidentId    = incident.Id,
                    ErrorId       = report.ClientReportId,
                    ReceivedAtUtc = report.CreatedAtUtc
                });

                var evt = new IncidentCreated(incident.ApplicationId,
                                              incident.Id, incident.Description, incident.FullName)
                {
                    CreatedAtUtc       = incident.CreatedAtUtc,
                    ApplicationVersion = applicationVersion,
                };
                _logger.Info($"Storing IncidentCreated with {context.Principal.ToFriendlyString()}: {JsonConvert.SerializeObject(evt)}");
                await _domainQueue.PublishAsync(context.Principal, evt);

                await context.SendAsync(evt);
            }
            else
            {
                if (incident.IsIgnored)
                {
                    _logger.Info("Incident is ignored: " + JsonConvert.SerializeObject(report));
                    incident.WasJustIgnored();
                    _repository.UpdateIncident(incident);
                    return;
                }

                // Do this before checking closed
                // as we want to see if it still gets reports.
                var stat = new ReportMapping()
                {
                    IncidentId    = incident.Id,
                    ErrorId       = report.ClientReportId,
                    ReceivedAtUtc = report.CreatedAtUtc
                };
                await _repository.StoreReportStats(stat);

                _logger.Debug("Storing stats " + JsonConvert.SerializeObject(stat));

                if (incident.IsClosed)
                {
                    if (applicationVersion != null && incident.IsReportIgnored(applicationVersion))
                    {
                        _logger.Info("Ignored report since it's for a version less that the solution version: " + JsonConvert.SerializeObject(report));
                        incident.WasJustIgnored();
                        _repository.UpdateIncident(incident);
                        return;
                    }

                    isReOpened = true;
                    incident.ReOpen();
                    var evt = new IncidentReOpened(incident.ApplicationId, incident.Id,
                                                   incident.CreatedAtUtc)
                    {
                        ApplicationVersion = applicationVersion
                    };
                    await context.SendAsync(evt);

                    await _domainQueue.PublishAsync(context.Principal, evt);
                }

                incident.AddReport(report);

                // Let's continue to receive reports once a day when
                // limit is reached (to get more fresh data, and still not load the system unnecessary).
                var timesSinceLastReport = DateTime.UtcNow.Subtract(incident.LastStoredReportUtc);
                if (incident.ReportCount > _reportConfig.Value.MaxReportsPerIncident &&
                    timesSinceLastReport < TimeSpan.FromMinutes(10))
                {
                    _repository.UpdateIncident(incident);
                    _logger.Debug($"Report count is more than {_reportConfig.Value.MaxReportsPerIncident}. Ignoring reports for incident {incident.Id}. Minutes since last report: " + timesSinceLastReport.TotalMinutes);
                    storeReport = false;
                    //don't exit here, since we want to be able to process reports
                }
            }

            if (!string.IsNullOrWhiteSpace(report.EnvironmentName))
            {
                _repository.SaveEnvironmentName(incident.Id, report.EnvironmentName);
            }

            report.IncidentId = incident.Id;

            if (storeReport)
            {
                incident.LastStoredReportUtc = DateTime.UtcNow;
                _repository.UpdateIncident(incident);
                _repository.CreateReport(report);
                _logger.Debug($"saving report {report.Id} for incident {incident.Id}");
            }

            var appName = _repository.GetAppName(incident.ApplicationId);
            var summary = new IncidentSummaryDTO(incident.Id, incident.Description)
            {
                ApplicationId   = incident.ApplicationId,
                ApplicationName = appName,
                CreatedAtUtc    = incident.CreatedAtUtc,
                LastUpdateAtUtc = incident.UpdatedAtUtc,
                IsReOpened      = incident.IsReOpened,
                Name            = incident.Description,
                ReportCount     = incident.ReportCount
            };
            var sw = new Stopwatch();

            sw.Start();
            var e = new ReportAddedToIncident(summary, ConvertToCoreReport(report, applicationVersion), isReOpened)
            {
                IsNewIncident   = isNewIncident,
                IsStored        = storeReport,
                EnvironmentName = report.EnvironmentName
            };
            await context.SendAsync(e);

            if (storeReport)
            {
                await context.SendAsync(new ProcessInboundContextCollections());
            }

            if (sw.ElapsedMilliseconds > 200)
            {
                _logger.Debug($"PublishAsync took {sw.ElapsedMilliseconds}");
            }
            sw.Stop();
        }
Esempio n. 10
0
 public async Task StoreReportStats(ReportMapping mapping)
 {
     await _unitOfWork.InsertAsync(mapping);
 }
        public async Task HandleAsync(IMessageContext context, SubmitFeedback command)
        {
            if (string.IsNullOrEmpty(command.Email))
            {
                if (string.IsNullOrEmpty(command.Feedback))
                {
                    return;
                }
                if (command.Feedback.Length < 3)
                {
                    return;
                }
            }

            ReportMapping report2;
            int?          reportId = null;

            if (command.ReportId > 0)
            {
                var report = await _reportsRepository.GetAsync(command.ReportId);

                report2 = new ReportMapping
                {
                    ApplicationId = report.ApplicationId,
                    ErrorId       = report.ClientReportId,
                    IncidentId    = report.IncidentId,
                    ReceivedAtUtc = report.CreatedAtUtc
                };
                reportId = report.Id;
            }
            else
            {
                report2 = await _reportsRepository.FindByErrorIdAsync(command.ErrorId);

                if (report2 == null)
                {
                    _logger.Warn("Failed to find report by error id: " + command.ErrorId);
                }
            }

            // storing it without connections as the report might not have been uploaded yet.
            if (report2 == null)
            {
                _logger.InfoFormat(
                    "Failed to find report. Let's enqueue it instead for report {0}/{1}. Email: {2}, Feedback: {3}",
                    command.ReportId, command.ErrorId, command.Email, command.Feedback);
                try
                {
                    using (var cmd = _unitOfWork.CreateCommand())
                    {
                        cmd.CommandText =
                            "INSERT INTO IncidentFeedback (ErrorReportId, RemoteAddress, Description, EmailAddress, CreatedAtUtc, Conversation, ConversationLength) "
                            +
                            "VALUES (@ErrorReportId, @RemoteAddress, @Description, @EmailAddress, @CreatedAtUtc, '', 0)";
                        cmd.AddParameter("ErrorReportId", command.ErrorId);
                        cmd.AddParameter("RemoteAddress", command.RemoteAddress);
                        cmd.AddParameter("Description", command.Feedback);
                        cmd.AddParameter("EmailAddress", command.Email);
                        cmd.AddParameter("CreatedAtUtc", DateTime.UtcNow);
                        cmd.ExecuteNonQuery();
                    }

                    _logger.Info("** STORING FEEDBACK");
                }
                catch (Exception exception)
                {
                    _logger.Error(
                        $"{command.ErrorId}: Failed to store '{command.Email}' '{command.Feedback}'", exception);
                    //hide errors.
                }

                return;
            }

            using (var cmd = (DbCommand)_unitOfWork.CreateCommand())
            {
                cmd.CommandText =
                    "INSERT INTO IncidentFeedback (ErrorReportId, ApplicationId, ReportId, IncidentId, RemoteAddress, Description, EmailAddress, CreatedAtUtc, Conversation, ConversationLength) "
                    +
                    "VALUES (@ErrorReportId, @ApplicationId, @ReportId, @IncidentId, @RemoteAddress, @Description, @EmailAddress, @CreatedAtUtc, @Conversation, 0)";
                cmd.AddParameter("ErrorReportId", command.ErrorId);
                cmd.AddParameter("ApplicationId", report2.ApplicationId);
                cmd.AddParameter("ReportId", reportId);
                cmd.AddParameter("IncidentId", report2.IncidentId);
                cmd.AddParameter("RemoteAddress", command.RemoteAddress);
                cmd.AddParameter("Description", command.Feedback);
                cmd.AddParameter("EmailAddress", command.Email);
                cmd.AddParameter("Conversation", "");
                cmd.AddParameter("CreatedAtUtc", DateTime.UtcNow);

                var app = await _applicationRepository.GetByIdAsync(report2.ApplicationId);

                var evt = new FeedbackAttachedToIncident
                {
                    ApplicationId    = report2.ApplicationId,
                    ApplicationName  = app.Name,
                    Message          = command.Feedback,
                    UserEmailAddress = command.Email,
                    IncidentId       = report2.IncidentId
                };
                await context.SendAsync(evt);

                await cmd.ExecuteNonQueryAsync();
            }
        }