Пример #1
0
 private void CacheTaskDefinition(string taskKey, TaskDefinition taskDefinition)
 {
     if (_cachedTaskDefinitions.ContainsKey(taskKey))
     {
         _cachedTaskDefinitions[taskKey] = new CachedTaskDefinition()
         {
             TaskDefinition = taskDefinition,
             CachedAt = DateTime.UtcNow
         };
     }
     else
     {
         _cachedTaskDefinitions.Add(taskKey, new CachedTaskDefinition()
         {
             TaskDefinition = taskDefinition,
             CachedAt = DateTime.UtcNow
         });
     }
 }
Пример #2
0
        private TaskDefinition InsertNewTask(TaskId taskId)
        {
            using (var connection = CreateNewConnection(taskId))
            {
                using (var command = new SqlCommand(TaskQueryBuilder.InsertTaskQuery, connection))
                {
                    command.Parameters.Add(new SqlParameter("@ApplicationName", SqlDbType.VarChar, 200)).Value = taskId.ApplicationName;
                    command.Parameters.Add(new SqlParameter("@TaskName", SqlDbType.VarChar, 200)).Value = taskId.TaskName;

                    var task = new TaskDefinition();
                    task.TaskDefinitionId = (int)command.ExecuteScalar();

                    string key = taskId.ApplicationName + "::" + taskId.TaskName;

                    lock (_myCacheSyncObj)
                    {
                        CacheTaskDefinition(key, task);
                    }
                    return task;
                }
            }
        }
Пример #3
0
        private TaskDefinition LoadTask(TaskId taskId)
        {
            using (var connection = CreateNewConnection(taskId))
            {
                using (var command = new SqlCommand(TaskQueryBuilder.GetTaskQuery, connection))
                {
                    command.Parameters.Add(new SqlParameter("@ApplicationName", SqlDbType.VarChar, 200)).Value = taskId.ApplicationName;
                    command.Parameters.Add(new SqlParameter("@TaskName", SqlDbType.VarChar, 200)).Value = taskId.TaskName;
                    using (var reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            var task = new TaskDefinition();
                            task.TaskDefinitionId = int.Parse(reader["TaskDefinitionId"].ToString());

                            return task;
                        }
                    }
                }
            }

            return null;
        }