private void ShiftScopedPublishShiftCrew(object sender, ShiftCrewDto shiftCrew) { logger.LogInformation("PublishShiftCrew {@shiftCrew}", shiftCrew); var profile = GetShiftProfile(shiftCrew.NameShiftProfile); if (profile != null && connector != null && !string.IsNullOrWhiteSpace(profile.TagPublish)) { connector.SetJson(profile.TagPublish, shiftCrew); } PublishShiftCrew?.Invoke(this, shiftCrew); notification?.OnUpdateShiftCrew(shiftCrew); }
public void UpdateShift(DateTime now) { foreach (var profile in configuration.ShiftProfiles.Where(p => p.Start <= now && p.End > now)) { var lastShift = repository.GetLastShiftHistory(profile.Name); if (lastShift == null) { logger.LogError("Not has last shift for profile:{profileName}", profile.Name);; continue; } // Add next shift if (lastShift.Start < now) { var end = lastShift.End < now?now.AddDays(1) : lastShift.End.DateTime.AddDays(1); end = end > profile.End ? profile.End.DateTime : end; GenerateHistory(profile, lastShift.End.DateTime, end); } var shiftCrew = repository.GetShiftCrew(profile.Name, now); var lastShiftEnd = shiftCrew?.End ?? profile.Start; if (lastShiftEnd < now) { GenerateHistory(profile, lastShiftEnd.DateTime); shiftCrew = repository.GetShiftCrew(profile.Name, now); } // Publish current shift if (shiftCrew.Start <= DateTime.Now && shiftCrew.End > DateTime.Now) { if (cacheShiftCrew.GetValueOrDefault(profile.Name)?.Start != shiftCrew.Start) { cacheShiftCrew[profile.Name] = shiftCrew; PublishShiftCrew?.Invoke(this, shiftCrew); } } } }