// Puts a serialized fixit onto the queue. public async Task SendMessageAsync(FixItTask fixIt) { CloudQueue queue = _queueClient.GetQueueReference(fixitQueueName); await queue.CreateIfNotExistsAsync(); var fixitJson = JsonConvert.SerializeObject(fixIt); CloudQueueMessage message = new CloudQueueMessage(fixitJson); await queue.AddMessageAsync(message); }
// Puts a serialized fixit onto the queue. public async Task SendMessageAsync(FixItTask fixIt) { CloudQueue queue = queueClient.GetQueueReference(FixitQueueName); await queue.CreateIfNotExistsAsync(); var fixitJson = JsonConvert.SerializeObject(new FixItTaskMessage { Task = fixIt, OperationId = CorrelationManager.GetOperationId() }); CloudQueueMessage message = new CloudQueueMessage(fixitJson); await queue.AddMessageAsync(message); }
public async Task<ActionResult> Create(FixItTask fixittask, HttpPostedFileBase photo) { if (ModelState.IsValid) { fixittask.CreatedBy = User.Identity.Name; fixittask.PhotoUrl = this.photoService.UploadPhoto(photo); await this.fixItRepository.CreateAsync(fixittask); return this.RedirectToAction("Success"); } return this.View(fixittask); }
public async Task UpdateAsync(FixItTask taskToSave) { var timespan = Stopwatch.StartNew(); try { await repository.UpdateAsync(taskToSave); timespan.Stop(); logger.TraceApi("SQL Database", "FixItTaskRepository.UpdateAsync", timespan.Elapsed, "taskToSave={0}", taskToSave); } catch (Exception e) { logger.Error(e, "Error in FixItTaskRepository.UpdateAsync(taskToSave={0})", taskToSave); throw; } }
public async Task CreateAsync(FixItTask taskToAdd) { Stopwatch timespan = Stopwatch.StartNew(); try { db.FixItTasks.Add(taskToAdd); await db.SaveChangesAsync(); timespan.Stop(); log.TraceApi("SQL Database", "FixItTaskRepository.CreateAsync", timespan.Elapsed, "taskToAdd={0}", taskToAdd); } catch (Exception e) { log.Error(e, "Error in FixItTaskRepository.CreateAsync(taskToAdd={0})", taskToAdd); throw; } }
public async Task UpdateAsync(FixItTask taskToSave) { Stopwatch timespan = Stopwatch.StartNew(); try { db.Entry(taskToSave).State = EntityState.Modified; await db.SaveChangesAsync(); timespan.Stop(); log.TraceApi("SQL Database", "FixItTaskRepository.UpdateAsync", timespan.Elapsed, "taskToSave={0}", taskToSave); } catch (Exception e) { log.Error(e, "Error in FixItTaskRepository.UpdateAsync(taskToSave={0})", taskToSave); throw; } }
public async Task <FixItTask> FindTaskByIdAsync(int id) { FixItTask fixItTask = null; Stopwatch timespan = Stopwatch.StartNew(); try { fixItTask = await this.db.FixItTasks.FindAsync(id); timespan.Stop(); this.log.TraceApi("SQL Database", "FixItTaskRepository.FindTaskByIdAsync", timespan.Elapsed, "id={0}", id); } catch (Exception e) { this.log.Error(e, "Error in FixItTaskRepository.FindTaskByIdAsynx(id={0})", id); } return(fixItTask); }
public async Task DeleteAsync(int id) { Stopwatch timespan = Stopwatch.StartNew(); try { FixItTask fixittask = await this.db.FixItTasks.FindAsync(id); this.db.FixItTasks.Remove(fixittask); await this.db.SaveChangesAsync(); timespan.Stop(); this.log.TraceApi("SQL Database", "FixItTaskRepository.DeleteAsync", timespan.Elapsed, "id={0}", id); } catch (Exception e) { this.log.Error(e, "Error in FixItTaskRepository.DeleteAsync(id={0})", id); } }
// Processes any messages on the queue. public async Task ProcessMessagesAsync(CancellationToken token) { CloudQueue queue = _queueClient.GetQueueReference(fixitQueueName); await queue.CreateIfNotExistsAsync(); while (!token.IsCancellationRequested) { // The default timeout is 90 seconds, so we won’t continuously poll the queue if there are no messages. // Pass in a cancellation token, because the operation can be long-running. CloudQueueMessage message = await queue.GetMessageAsync(token); if (message != null) { FixItTask fixit = JsonConvert.DeserializeObject <FixItTask>(message.AsString); await _repository.CreateAsync(fixit); await queue.DeleteMessageAsync(message); } } }
public async Task CreateAsync(FixItTask taskToAdd) { Stopwatch timespan = Stopwatch.StartNew(); db = new MyFixItContext(); try { db.FixItTasks.Add(taskToAdd); await db.SaveChangesAsync(); timespan.Stop(); log.TraceApi("SQL Database", "FixItTaskRepository.CreateAsync", timespan.Elapsed, "taskToAdd={0}", taskToAdd); } catch (Exception e) { log.Error(e, "Error in FixItTaskRepository.CreateAsync(taskToAdd={0})", taskToAdd); throw; } }
public Task UpdateAsync(FixItTask taskToSave) { context.Entry(taskToSave).State = EntityState.Modified; return(context.SaveChangesAsync()); }
public Task CreateAsync(FixItTask taskToAdd) { context.FixItTasks.Add(taskToAdd); return(context.SaveChangesAsync()); }