public async Task DeleteAsync(FixItTask taskToRemove)
        {
            var watch = Stopwatch.StartNew();

            try
            {
                _context.FixItTasks.Remove(taskToRemove);
                await _context.SaveChangesAsync();
                watch.Stop();
                _logger.TraceApi("MyFixIt3", "FixItTaskRepository.RemoveAsync", watch.Elapsed, "Removed task {0}",
                    taskToRemove);
            }
            catch (Exception ex)
            {
                _logger.Error(ex, "Failed to remove a FixIt task");
                throw;
            }
        }
        public async Task CreateAsync(FixItTask taskToAdd)
        {
            var watch = Stopwatch.StartNew();

            try
            {
                _context.FixItTasks.Add(taskToAdd);
                await _context.SaveChangesAsync();
                watch.Stop();
                _logger.Information("Add a task takes {0}, Task to add: {1}", watch.Elapsed, taskToAdd);
            }

            catch (Exception ex)
            {
                _logger.Error(ex, "Failed to add a FixIt task");
                throw;
            }

        }
Exemplo n.º 3
0
        public async Task SendMessageAsync(FixItTask newTask)
        {
            var watch = Stopwatch.StartNew();

            try
            {
                var storageAccount = CloudStorageAccount.Parse(_storageConnectionstring);
                var queueClient = storageAccount.CreateCloudQueueClient();
                var queue = queueClient.GetQueueReference(_queueName);
                await queue.CreateIfNotExistsAsync();
                var taskInJson = JsonConvert.SerializeObject(newTask);
                var taskMessage = new CloudQueueMessage(taskInJson);
                await queue.AddMessageAsync(taskMessage);
                watch.Stop();
                _logger.TraceApi("Queue Manager", "SendMessageAsync", watch.Elapsed, "Message added to queue: {0}", newTask);
            }
            catch (Exception ex)
            {
                _logger.Error(ex, "Error in SendMessgeAsync, task:{0}", newTask);   
                throw;
            }
        }
        public async Task UpdateAsync(FixItTask taskToSave)
        {
            var watch = Stopwatch.StartNew();

            try
            {
                _context.Entry(taskToSave).State = EntityState.Modified;
                await _context.SaveChangesAsync();
                watch.Stop();
                _logger.TraceApi("SQL database", "UpdateAsync", watch.Elapsed, "taskToSave={0}", taskToSave);
            }
            catch (Exception ex)
            {
                _logger.Error(ex, "Error in UpdateAsync(tasktosave={0}", taskToSave);
                throw;
            }
        }