/// <summary> /// Starts new scope that will measure execution time of the operation /// with specified <paramref name="specification"/>.<br /> /// Uppon disposing will store the results of measurement in the current session.<br /> /// If there is no session started - returns dummy operation that will do nothing. /// </summary> public ProfileOperation Profile(ProfileOperationSpecification specification) { try { if (!this.Configuration.Enabled) { return(null); } var session = this.currentSession.Get(); ProfileOperation operation; if (session != null) { operation = session.StartMeasure(specification); } else { operation = new ProfileOperation(id: 0, profiler: this, session: null, specification: specification, parent: null); } return(operation); } catch (Exception ex) { this.logger.LogError(ex); return(null); } }
/// <summary> /// Profiled operation has been ended. /// </summary> public void OnOperationEnded(ProfileOperation operation) { if (operation == null) { throw new ArgumentNullException(nameof(operation)); } try { this.eventsHandler.OnOperationEnded(operation); } catch (Exception ex) { this.logger.LogError(ex); } }
public void Always_ReturnsCorrectDateTimeInUtc() { // arrange var session = this.fixture.Create <ProfileSession>(); var expected_date_time = DateTime.UtcNow; // act var sut = new ProfileOperation(1, session.Profiler, session, this.fixture.Create <ProfileOperationSpecification>(), null); // assert sut.StartDate.Should().BeAfter(expected_date_time).And.BeCloseTo(expected_date_time, 1000); }
public async Task <ProfileOperation> UpdateProfileOperation(ProfileOperation po) { var pop = await GetProfileOperationById(po.ApplicationUserId, po.OperationId); if (pop == null) { return(null); } pop.Price = po.Price; pop.Duration = po.Duration; pop.Comments = po.Comments; _context.ProfileOperations.Update(pop); await _context.SaveChangesAsync(); return(pop); }
public async Task <ProfileOperation> AddOperationToProfile(string pId, string oId, ProfileOperation po) { var pop = new ProfileOperation(); var p = await _context.Users.FindAsync(pId); var o = await _context.Operations.FindAsync(oId); pop.Id = Guid.NewGuid().ToString(); pop.ApplicationUser = p; pop.ApplicationUserId = p.Id; pop.Operation = o; pop.OperationId = o.Id; pop.Price = po.Price; pop.Duration = po.Duration; pop.Comments = po.Comments; _context.ProfileOperations.Add(pop); await _context.SaveChangesAsync(); return(pop); }
public void Always_ReturnsCorrectFullName(string category, string name, string resource, string expected) { // arrange var session = this.fixture.Create <ProfileSession>(); var sut = new ProfileOperation(1, session.Profiler, session, new ProfileOperationSpecification(name) { Category = category }, null); sut.Resource = resource; // act var result = sut.FullName; // assert result.Should().Be(expected); }
public void OnOperationEnded(ProfileOperation operation) { }
public void OnOperationEnded(ProfileOperation operation) { Console.WriteLine("IProfilerEventsHandler.OnOperationEnded: {0} (duration {1})", operation, operation.Duration); }