Пример #1
0
        public void UpdateTaskAttributes(IEnumerable <string> taskTypes, IDictionary <string, string> searchAttributes, IDictionary <string, string> replaceAttributes)
        {
            const string MethodName = "UpdateTaskAttributes";

            CheckObjectAlreadyDisposed();

            if (s_Logger.IsDebugEnabled)
            {
                s_Logger.Debug(
                    string.Format(
                        "{0}({1},{2},{3})",
                        MethodName,
                        string.Join(@",", taskTypes.ToArray()),
                        searchAttributes,
                        replaceAttributes));
            }

            // coalesce if nescessary
            searchAttributes = searchAttributes ?? new Dictionary <string, string>();
            taskTypes        = taskTypes ?? Enumerable.Empty <string>();
            try
            {
                IQuery       query = BuildFindTasksQuery(taskTypes, searchAttributes, null, null);
                IList <Task> tasks = query.List <Task>();
                foreach (Task task in tasks)
                {
                    //check that all keys exist, skip task if not so
                    if (replaceAttributes.Keys.All(k => task.Attributes.ContainsKey(k)))
                    {
                        //replace the values
                        foreach (string key in replaceAttributes.Keys)
                        {
                            task.AddAttribute(key, replaceAttributes[key]);
                        }
                    }
                    else
                    {
                        // log info
                        s_Logger.InfoFormat(
                            "Skipped task because at least one replacement attribute key could not be found Task=({0},{1},{2},{3})",
                            task,
                            string.Join(@",", taskTypes.ToArray()),
                            searchAttributes,
                            replaceAttributes);
                    }
                }
            }
            catch (HibernateException he)
            {
                // Any hibernate exception is an error
                string message = string.Format(
                    "{0}({1},{2},{3})",
                    MethodName,
                    string.Join(@",", taskTypes.ToArray()),
                    searchAttributes,
                    replaceAttributes);
                s_Logger.Fatal(message, he);
                StatelessCrudDao.TriageException(he, message);
                // Line needed to keep resharper happy :)
                // triageException should give an exception back instead of throwing it already
                throw new Exception();
            }

            if (s_Logger.IsDebugEnabled)
            {
                s_Logger.Debug(
                    string.Format(
                        "{0}({1},{2},{3}) ended succussfully",
                        MethodName,
                        string.Join(@",", taskTypes.ToArray()),
                        searchAttributes,
                        replaceAttributes));
            }
        }
Пример #2
0
        public FindTasksResult FindTasks(IEnumerable <string> taskTypes, IDictionary <string, string> searchAttributes, TaskStateEnum?taskState)
        {
            const int    MaximumResults = 50;
            const string MethodName     = "FindTasks";

            CheckObjectAlreadyDisposed();

            int numberOfMatchingTasks;

            if (s_Logger.IsDebugEnabled)
            {
                s_Logger.DebugFormat(
                    "{0}({1},{2},{3})",
                    MethodName,
                    string.Join(@",", taskTypes.ToArray()),
                    searchAttributes,
                    taskState != null
                        ? taskState.ToString()
                        : string.Empty);
            }

            // coalesce if nescessary
            searchAttributes = searchAttributes ?? new Dictionary <string, string>();
            taskTypes        = taskTypes ?? Enumerable.Empty <string>();
            IList <Task> result;

            try
            {
                IQuery query = BuildFindTasksQuery(taskTypes, searchAttributes, taskState, MaximumResults);
                result = query.List <Task>();
                if (result.Count < MaximumResults)
                {
                    numberOfMatchingTasks = result.Count;
                }
                else
                {
                    query = BuildCountTasksQuery(taskTypes, searchAttributes, taskState);
                    numberOfMatchingTasks = (int)query.UniqueResult <long>();
                }
            }
            catch (HibernateException he)
            {
                // Any hibernate exception is an error
                string message = string.Format(
                    "{0}({1},{2},{3})",
                    MethodName,
                    string.Join(@",", taskTypes.ToArray()),
                    searchAttributes,
                    taskState != null
                        ? taskState.ToString()
                        : string.Empty);
                s_Logger.Fatal(message, he);
                StatelessCrudDao.TriageException(he, message);
                // Line needed to keep resharper happy :)
                // triageException should give an exception back instead of throwing it already
                throw new Exception();
            }

            if (s_Logger.IsDebugEnabled)
            {
                s_Logger.DebugFormat(
                    "{0}({1},{2},{3}) result {4}",
                    MethodName,
                    string.Join(@",", taskTypes.ToArray()),
                    searchAttributes,
                    taskState.HasValue
                        ? taskState.ToString()
                        : string.Empty, result);
            }

            ICollection <Task> allowedResult = result
                                               .Where(r => HasSufficientSecurity(r.GetType(), SecurityActionFlag.RETRIEVE))
                                               .ToArray();

            return(new FindTasksResult(allowedResult, numberOfMatchingTasks));
        }
Пример #3
0
        public FindTasksResult FindTasks(string tasktype, string reference, TaskStateEnum?taskState)
        {
            const int    MaximumResults = 50;
            const string MethodName     = "FindTasks";

            CheckObjectAlreadyDisposed();

            ICollection <Task> result = new HashedSet <Task>();
            int numberOfMatchingTasks = -1;

            if (s_Logger.IsDebugEnabled)
            {
                s_Logger.Debug(
                    string.Format(
                        "{0}({1},{2},{3})",
                        MethodName,
                        tasktype ?? string.Empty,
                        reference,
                        taskState.HasValue
                            ? taskState.ToString()
                            : string.Empty));
            }

            try
            {
                ICriteria criteria = BuildFindTasksQuery(tasktype, reference, taskState, MaximumResults);
                result = criteria.List <Task>();
                if (result.Count < MaximumResults)
                {
                    numberOfMatchingTasks = result.Count;
                }
                else
                {
                    criteria = BuildCountTasksQuery(tasktype, reference, taskState);
                    numberOfMatchingTasks = criteria.UniqueResult <int>();
                }
            }
            catch (HibernateException he)
            {
                // Any hibernate exception is an error
                string message = string.Format(
                    "{0}({1},{2},{3})",
                    MethodName,
                    tasktype ?? string.Empty,
                    reference,
                    taskState.HasValue ?
                    taskState.ToString()
                        : string.Empty);
                s_Logger.Fatal(message, he);
                StatelessCrudDao.TriageException(he, message);
            }

            if (s_Logger.IsDebugEnabled)
            {
                s_Logger.Debug(
                    string.Format(
                        "{0}({1},{2},{3}) result {4}",
                        MethodName,
                        tasktype ?? string.Empty,
                        reference,
                        taskState.HasValue
                            ? taskState.ToString()
                            : string.Empty, result));
            }

            ICollection <Task> allowedResult = result
                                               .Where(r => HasSufficientSecurity(r.GetType(), SecurityActionFlag.RETRIEVE))
                                               .ToList();

            return(new FindTasksResult(allowedResult, numberOfMatchingTasks));
        }