public virtual JobRequestResult Process(JobRequest request) { #region Unaffected logic if (request.RequestedByDate.CompareTo(DateTime.Now) < 0) return new JobRequestResult {Accepted = false, Errors = new List<IJobRequestError> {new JobInThePastError()}}; #endregion Unaffected logic #region Altered Logic to support 3 days in the future limit for non-emergency requests if (request.RequestedByDate.CompareTo(DateTime.Now.AddDays(2)) <= 0) return new JobRequestResult {Accepted = false, Errors = new List<IJobRequestError> {new RequestedDateTooSoonError()}}; #endregion Altered Logic to support 2 days in the future limit for non-emergency requests #region Unaffected logic using (var ctx = new SharedDbContext()) { var matchingTasks = ctx.Job.Find(request.RequestedTask); if (matchingTasks == null) return new JobRequestResult {Accepted = false, Errors = new List<IJobRequestError> {new UnknownJobIdError()}}; var maximumNumberOfJobsAlreadyScheduled = (from job in ctx.ScheduledJob where job.ScheduledOn.Equals(request.RequestedByDate) select job).Count() > 3; if (maximumNumberOfJobsAlreadyScheduled) return new JobRequestResult {Accepted = false, Errors = new List<IJobRequestError> {new RequestedDateFullError()}}; var scheduledJob = ctx.ScheduledJob.Create(); scheduledJob.ScheduledOn = request.RequestedByDate; ctx.ScheduledJob.Add(scheduledJob); ctx.SaveChanges(); } return new JobRequestResult {Accepted = true, ScheduledToBeginOn = request.RequestedByDate}; #endregion Unaffected logic }
//TODO /// <Summary>Does this page need to show the location selector?</Summary> //public bool ShowLocationSelector(MenuHelper currentMenu) //{ // return currentMenu.ShowLocationSelection && HasLocations; //} public JsonResult UpdateStatus(int locationId, string status) { var locationCacher = new LocationCacher(SharedDbContext); var location = AllLocations.SingleOrDefault(l => l.Id == locationId); if (location == null) { return(new { Saved = false }.AsJsonResult()); } if (location.TallyStatus != status) { SharedDbContext.Location.Attach(location); location.TallyStatus = status; SharedDbContext.SaveChanges(); locationCacher.UpdateItemAndSaveCache(location); } return(new { Saved = true, Location = LocationInfoForJson(location) }.AsJsonResult()); }
static void StartServerInfoTask() { var t = new System.Timers.Timer(); t.AutoReset = true; t.Elapsed += new System.Timers.ElapsedEventHandler((s, e) => { using (SharedDbContext shared = new SharedDbContext()) { ServerDb serverDb = shared.Servers.Where(s => s.Name == Name).FirstOrDefault(); if (serverDb != null) { serverDb.IpAddress = IpAddress; serverDb.Port = Port; serverDb.BusyScore = SessionManager.Instance.GetBusyScore(); shared.SaveChangesEx(); } else { serverDb = new ServerDb() { Name = Program.Name, IpAddress = Program.IpAddress, Port = Program.Port, BusyScore = SessionManager.Instance.GetBusyScore() }; shared.Servers.Add(serverDb); shared.SaveChangesEx(); } } }); t.Interval = 10 * 1000; t.Start(); }
public JsonResult SortLocations(List <int> idList) { //var ids = idList.Split(new[] { ',' }).AsInts().ToList(); var locationCacher = new LocationCacher(SharedDbContext); var locations = locationCacher.AllForThisElection.Where(l => idList.Contains(l.Id)).ToList(); var sortOrder = 1; foreach (var id in idList) { var newOrder = sortOrder++; var location = locations.SingleOrDefault(l => l.Id == id); if (location != null && location.SortOrder != newOrder) { SharedDbContext.Location.Attach(location); location.SortOrder = newOrder; locationCacher.UpdateItemAndSaveCache(location); } } SharedDbContext.SaveChanges(); return(new { Saved = true }.AsJsonResult()); }
public JobRequestResult Process(JobRequest request) { #region Unaffected By Change if (request.RequestedByDate.CompareTo(DateTime.Now) < 0) return new JobRequestResult {Accepted = false, Errors = new List<IJobRequestError> {new JobInThePastError()}}; using (var ctx = new SharedDbContext()) { var matchingTasks = ctx.Job.Find(request.RequestedTask); if(matchingTasks == null) return new JobRequestResult {Accepted = false, Errors = new List<IJobRequestError> {new UnknownJobIdError()}}; #endregion Unaffected By Change #region New Code to Support limiting number of jobs per day to 4 var maximumNumberOfJobsAlreadyScheduled = (from job in ctx.ScheduledJob where job.ScheduledOn.Equals(request.RequestedByDate) select job).Count() > 3; if (maximumNumberOfJobsAlreadyScheduled) return new JobRequestResult {Accepted = false, Errors = new List<IJobRequestError> {new RequestedDateFullError()}}; #endregion New Code to Support limiting number of jobs per day to 4 #region Unaffected By Change var scheduledJob = ctx.ScheduledJob.Create(); scheduledJob.ScheduledOn = request.RequestedByDate; ctx.ScheduledJob.Add(scheduledJob); ctx.SaveChanges(); } return new JobRequestResult {Accepted = true, ScheduledToBeginOn = request.RequestedByDate}; #endregion Unaffected By Change }
public ScheduledJobResult Schedule(JobRequest request) { using (var context = new SharedDbContext()) { var scheduledJob = context.ScheduledJob.Create(); var maximumNumberOfJobsAlreadyScheduled = (from job in context.ScheduledJob where job.ScheduledOn.Equals(request.RequestedByDate) select job).Count() > 3; if(maximumNumberOfJobsAlreadyScheduled) { var date = GetNextAvailableDate(context, request.RequestedByDate); scheduledJob.ScheduledOn = date; context.ScheduledJob.Add(scheduledJob); context.SaveChanges(); return new ScheduledJobResult { ScheduledToStart = date, Errors = new List<IJobSchedulingError>{new RequestedDateFullError()} }; } scheduledJob.ScheduledOn = request.RequestedByDate; context.ScheduledJob.Add(scheduledJob); context.SaveChanges(); } return new ScheduledJobResult{ScheduledToStart = request.RequestedByDate}; }
/// <summary> /// /// </summary> /// <param name="context"></param> public UnitOfWork(SharedDbContext context, IDataAuditingService dataAuditingService, IStatusesAuditingService statusesAuditingService) { _dataAuditingService = dataAuditingService; _statusesAuditingService = statusesAuditingService; DbContext = context; }
public AdminPortalResources(SharedDbContext sharedDbContext, ApplicationDbContext appDbContext, ICityStateApiService cityStateApiService, IUserManagement userManagement, IAzureStorageService imageStorageService) { _sharedDbContext = sharedDbContext; _appDbContext = appDbContext; _cityStateApiService = cityStateApiService; _userManagement = userManagement; _imageStorageService = imageStorageService; }
private DateTime GetNextAvailableDate(SharedDbContext context, DateTime startfrom) { var date = startfrom; do { date = date.AddDays(1); } while ((from job in context.ScheduledJob where job.ScheduledOn.Equals(date) select job).Count() > 3); return date; }
public static void SeedHostDb(SharedDbContext context) { context.SuppressAutoSetTenantId = true; // Host seed new InitialHostDbBuilder(context).Create(); // Default tenant seed (in host database). new DefaultTenantBuilder(context).Create(); new TenantRoleAndUserBuilder(context, 1).Create(); }
public static bool SaveChangesEx(this SharedDbContext db) { try { db.SaveChanges(); return(true); } catch { return(false); } }
public AccountApiController(IConfiguration configuration, ILogger <AccountController> logger, PgSqlContext pgContext, SqlServerContext sqlContext) { Configuration = configuration; Logger = logger; DbContext = (configuration.GetValue <string>("EntityFramework:Driver")) switch { "PostgreSql" => pgContext, "SqlServer" => sqlContext, _ => throw new InvalidOperationException("The EntityFramework:Driver configuration value must be set to \"PostgreSql\" or \"SqlServer\"."), }; }
public ScheduledJobResult Schedule(JobRequest request) { using (var ctx = new SharedDbContext()) { var scheduledJob = ctx.ScheduledJob.Create(); scheduledJob.ScheduledOn = request.RequestedByDate; ctx.ScheduledJob.Add(scheduledJob); ctx.SaveChanges(); } _messenger.Send(new EmergencyJobScheduled{ScheduledOn = request.RequestedByDate}); return new ScheduledJobResult{ScheduledToStart = request.RequestedByDate, Errors = new List<IJobSchedulingError>()}; }
internal static bool SaveChangesEx(this SharedDbContext db) { try { db.SaveChanges(); return(true); } catch { // SaveChanges 실패했을때 예외 return(false); } }
public static bool SaveChangesEx(this SharedDbContext db) { try { db.SaveChanges(); return(true); } catch (Exception ex) { Debug.WriteLine(ex.Message); return(false); } }
public JobRequestValidationResult Validate(JobRequest request) { if (DateTime.Now.CompareTo(request.RequestedByDate) > 0) return new JobRequestValidationResult {Errors = new List<IValidationError> {new DateInThePastValidationError()}}; using (var context = new SharedDbContext()) { var matchingKnownJob = context.Job.Find(request.RequestedTask); if (matchingKnownJob == null) return new JobRequestValidationResult {Errors = new List<IValidationError> {new UnknownJobValidationError()}}; } return new JobRequestValidationResult{IsValid = true}; }
public JsonResult UpdateLocationInfo(string info) { var location = UserSession.CurrentLocation; SharedDbContext.Location.Attach(location); location.ContactInfo = info; SharedDbContext.SaveChanges(); new LocationCacher(SharedDbContext).UpdateItemAndSaveCache(location); return(new { Saved = true }.AsJsonResult()); }
public AccountController(IConfiguration configuration, ILogger <AccountController> logger, IDistributedCache cache, CryptoService crypto, SmtpClientService smtpClient, PgSqlContext pgContext, SqlServerContext sqlContext) { Configuration = configuration; Logger = logger; Cache = cache; Crypto = crypto; SmtpClient = smtpClient; DbContext = (configuration.GetValue <string>("EntityFramework:Driver")) switch { "PostgreSql" => pgContext, "SqlServer" => sqlContext, _ => throw new InvalidOperationException("The EntityFramework:Driver configuration value must be set to \"PostgreSql\" or \"SqlServer\"."), }; }
public JobRequestResult Process(JobRequest request) { if (request.RequestedByDate.CompareTo(DateTime.Now) < 0) return new JobRequestResult {Accepted = false, Errors = new List<IJobRequestError> {new JobInThePastError()}}; using (var ctx = new SharedDbContext()) { var matchingTasks = ctx.Job.Find(request.RequestedTask); if(matchingTasks == null) return new JobRequestResult {Accepted = false, Errors = new List<IJobRequestError> {new UnknownJobIdError()}}; var scheduledJob = ctx.ScheduledJob.Create(); scheduledJob.ScheduledOn = request.RequestedByDate; ctx.ScheduledJob.Add(scheduledJob); ctx.SaveChanges(); } return new JobRequestResult {Accepted = true, ScheduledToBeginOn = request.RequestedByDate}; }
static void Main(string[] args) { using (SharedDbContext shared = new SharedDbContext()) { } ConfigManager.LoadConfig(); DataManager.LoadData(); GameLogic.Instance.Push(() => { GameLogic.Instance.Add(1); }); // DNS (Domain Name System) string host = Dns.GetHostName(); IPHostEntry ipHost = Dns.GetHostEntry(host); IPAddress ipAddr = ipHost.AddressList[1]; IPEndPoint endPoint = new IPEndPoint(ipAddr, Port); IpAddress = ipAddr.ToString(); _listener.Init(endPoint, () => { return(SessionManager.Instance.Generate()); }); Console.WriteLine("Listening..."); StartServerInfoTask(); // DB Task { Thread t = new Thread(DbTask); t.Name = "DB"; t.Start(); } // Network Task { Thread t = new Thread(NetworkTask); t.Name = "Network send"; t.Start(); } // GameLogic Task Thread.CurrentThread.Name = "GameLogic"; GameLogicTask(); }
public JobRequestValidationResult Validate(JobRequest request) { //Date cannot be in the past if (request.RequestedByDate.CompareTo(DateTime.Now) < 0) return new JobRequestValidationResult {Errors = new List<IValidationError> {new DateInThePastValidationError()}}; //Date cannot be earlier than 4 days from now if (request.RequestedByDate.CompareTo(DateTime.Now.AddDays(3)) <= 0) return new JobRequestValidationResult {Errors = new List<IValidationError> {new DateTooSoonForNonEmergencyError()}}; using (var context = new SharedDbContext()) { var matchingKnownJob = context.Job.Find(request.RequestedTask); //must be known task if (matchingKnownJob == null) return new JobRequestValidationResult {Errors = new List<IValidationError> {new UnknownJobValidationError()}}; } return new JobRequestValidationResult{IsValid = true, Errors = new List<IValidationError>()}; }
public JsonResult UpdateNumCollected(int numCollected) { var location = UserSession.CurrentLocation; if (location == null) { return(new { Message = "Must select your location first!" }.AsJsonResult()); } SharedDbContext.Location.Attach(location); location.BallotsCollected = numCollected; SharedDbContext.SaveChanges(); new LocationCacher(SharedDbContext).UpdateItemAndSaveCache(location); return(new { Saved = true, Location = LocationInfoForJson(location) }.AsJsonResult()); }
public DefaultEditionCreator(SharedDbContext context) { _context = context; }
public DefaultTenantBuilder(SharedDbContext context) { _context = context; }
public InitialHostDbBuilder(SharedDbContext context) { _context = context; }
public DbDataTransformer(IConfiguration configuration, IWebHostEnvironment env, SharedDbContext dbContext) { Configuration = configuration; Env = env; DbContext = dbContext; }
public TenantRoleAndUserBuilder(SharedDbContext context, int tenantId) { _context = context; _tenantId = tenantId; }
public ServiceOrderTable(SharedDbContext db) { _db = db; }
public RepositoryBase(ISharedDbContext dbContext) { _DbContext = (SharedDbContext)dbContext; }
public NewTenantProcedure(Func <bool, SharedDbContext> dbContextFunction) { _db = dbContextFunction(true); }
public DefaultSettingsCreator(SharedDbContext context) { _context = context; }
/// <summary> /// Constructor /// </summary> /// <param name="context"></param> public EFRepository(SharedDbContext dbContext) { _context = dbContext; Dispose(false); }
public AccountController(AppDbContext context, SharedDbContext shared) { _context = context; _shared = shared; }
public PaymentTable(SharedDbContext db) { _db = db; }
public HostRoleAndUserCreator(SharedDbContext context) { _context = context; }
public CompanyProvider(SharedDbContext context, IHttpContextAccessor accesor, UserManager <ApplicationUser> userManager) { _context = context; _accesor = accesor; _userManager = userManager; }
public DefaultLanguagesCreator(SharedDbContext context) { _context = context; }
public TenantTable(SharedDbContext db, ServiceOrderTable serviceOrderTable) { this.db = db; _serviceOrderTable = serviceOrderTable; }