示例#1
0
		public Report GetOrCreateReport(FCCLReportType type, int objectId, string objectName, DateTime testDate, DateTime printDate, long? reportNumber = null)
		{
			bool notCommited = true;
			int attemptCount = 0;
			Report report = null;

			while (notCommited && attemptCount < 5)
			{
				using (var tran = context.Database.BeginTransaction())
				{
					try
					{
						attemptCount++;
						logger.Info("GetOrCreateReport|objectName: {0}, reportNumber: {1}", objectName, reportNumber);
						if (reportNumber.HasValue)
						{
							report = GetByNumber(reportNumber.Value);
						}
						if (report == null)
						{
							report = repo.Create();
							if (reportNumber.HasValue)
							{
								report.ReportNumber = reportNumber.Value;
							}
							else
							{
								report.ReportNumber = repo.Get().OrderByDescending(r => r.Created).First().ReportNumber + 1;
								logger.Info("GetOrCreateReport|retrieved number: {0}", report.ReportNumber);
							}
						}
						else
						{
							logger.Info("GetOrCreateReport|retrieved report Id: {0}", report.Id);
						}
						report.ReportType = (short)type;
						report.ObjectId = objectId;
						report.ObjectName = objectName;
						report.TestDate = testDate.Year > 1753 ? testDate.Date : DateTime.Now.Date;
						report.PrintDate = printDate.Year > 1753 ? printDate.Date : DateTime.Now.Date;
						Save(report);
						context.SaveChanges();
						tran.Commit();
						notCommited = false;
					}
					catch (Exception ex)
					{
						logger.Fatal(string.Format("GetOrCreateReport|objectName: {0}, reportNumber: {1} at cnt {2}|msg:{3}|stack:{4}", objectName, reportNumber, attemptCount, ex.Message, ex.StackTrace));
					}
				}
			}
			if(notCommited)
			{
				throw new Exception("Nu am putut salva raportul");
			}
			logger.Info("GetOrCreateReport|objectName: {0}, reportNumber: {1}", objectName, reportNumber);
			return report;
		}
示例#2
0
        public Report GetOrCreateReport(FCCLReportType type, int objectId, string objectName, DateTime testDate, DateTime printDate, long?reportNumber = null)
        {
            bool   notCommited  = true;
            int    attemptCount = 0;
            Report report       = null;

            while (notCommited && attemptCount < 5)
            {
                using (var tran = context.Database.BeginTransaction())
                {
                    try
                    {
                        attemptCount++;
                        logger.Info("GetOrCreateReport|objectName: {0}, reportNumber: {1}", objectName, reportNumber);
                        if (reportNumber.HasValue)
                        {
                            report = GetByNumber(reportNumber.Value);
                        }
                        if (report == null)
                        {
                            report = repo.Create();
                            if (reportNumber.HasValue)
                            {
                                report.ReportNumber = reportNumber.Value;
                            }
                            else
                            {
                                report.ReportNumber = repo.Get().OrderByDescending(r => r.Created).First().ReportNumber + 1;
                                logger.Info("GetOrCreateReport|retrieved number: {0}", report.ReportNumber);
                            }
                        }
                        else
                        {
                            logger.Info("GetOrCreateReport|retrieved report Id: {0}", report.Id);
                        }
                        report.ReportType = (short)type;
                        report.ObjectId   = objectId;
                        report.ObjectName = objectName;
                        report.TestDate   = testDate.Year > 1753 ? testDate.Date : DateTime.Now.Date;
                        report.PrintDate  = printDate.Year > 1753 ? printDate.Date : DateTime.Now.Date;
                        Save(report);
                        context.SaveChanges();
                        tran.Commit();
                        notCommited = false;
                    }
                    catch (Exception ex)
                    {
                        logger.Fatal(string.Format("GetOrCreateReport|objectName: {0}, reportNumber: {1} at cnt {2}|msg:{3}|stack:{4}", objectName, reportNumber, attemptCount, ex.Message, ex.StackTrace));
                    }
                }
            }
            if (notCommited)
            {
                throw new Exception("Nu am putut salva raportul");
            }
            logger.Info("GetOrCreateReport|objectName: {0}, reportNumber: {1}", objectName, reportNumber);
            return(report);
        }