Esempio n. 1
0
        private ICriteria BuildCountTasksQuery(string tasktype, string reference, TaskStateEnum?taskState)
        {
            ICriteria criteria = BuildBaseTasksQuery(tasktype, reference, taskState);

            criteria.SetProjection(Projections.RowCount());
            return(criteria);
        }
Esempio n. 2
0
        private ICriteria BuildBaseTasksQuery(string tasktype, string reference, TaskStateEnum?taskState)
        {
            if (!reference.EndsWith("%"))
            {
                reference = string.Concat(reference, "%");
            }
            if (!(string.IsNullOrEmpty(tasktype) || tasktype.EndsWith("/")))
            {
                tasktype = string.Concat(tasktype, "/");
            }
            ICriteria criteria = Session
                                 .CreateCriteria <Task>()
                                 .Add(Restrictions.Like("Reference", reference));

            if (!string.IsNullOrEmpty(tasktype))
            {
                criteria.Add(Restrictions.Eq("TaskType", tasktype));
            }
            if (taskState.HasValue)
            {
                int      value       = (int)taskState.Value;
                Junction disjunction = Restrictions.Disjunction();
                int      state       = 1;
                while (state <= value)
                {
                    if ((state & value) != 0)
                    {
                        disjunction.Add(Restrictions.Eq("State", (TaskStateEnum)state));
                    }
                    state <<= 1;
                }
                criteria.Add(disjunction);
            }
            return(criteria);
        }
Esempio n. 3
0
        public FindTasksResult FindTasks(string tasktype, string reference, TaskStateEnum?taskState)
        {
            Contract.Requires(Transaction.Current != null);
            Contract.Requires(!string.IsNullOrEmpty(reference));
            Contract.Ensures(Contract.Result <FindTasksResult>() != null);

            return(default(FindTasksResult));
        }
Esempio n. 4
0
        private ICriteria BuildFindTasksQuery(string tasktype, string reference, TaskStateEnum?taskState, int maximumResults)
        {
            ICriteria criteria = BuildBaseTasksQuery(tasktype, reference, taskState);

            criteria.AddOrder(Order.Asc("CreatedAt"));
            criteria.SetMaxResults(maximumResults);
            return(criteria);
        }
Esempio n. 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="VirtualDiskRecoverTaskState" /> class.
 /// </summary>
 /// <param name="error">error.</param>
 /// <param name="isInstantRecoveryFinished">Specifies if instant recovery of the virtual disk is complete..</param>
 /// <param name="taskState">Specifies the current state of the restore virtual disks task. Specifies the current state of the restore virtual disks task. &#39;kDetachDisksDone&#39; indicates the detached state of disks. &#39;kSetupDisksDone&#39; indicates that disks setup is completed. &#39;kMigrateDisksStarted&#39; indicates that disks are being migrated. &#39;kMigrateDisksDone&#39; indicates that disk migration is completed. &#39;kUnMountDatastoreDone&#39; indicates that disk has unmounted the datastore..</param>
 /// <param name="virtualDiskRestoreResponse">virtualDiskRestoreResponse.</param>
 public VirtualDiskRecoverTaskState(RequestError error = default(RequestError), bool?isInstantRecoveryFinished = default(bool?), TaskStateEnum?taskState = default(TaskStateEnum?), VirtualDiskRestoreResponse virtualDiskRestoreResponse = default(VirtualDiskRestoreResponse))
 {
     this.IsInstantRecoveryFinished = isInstantRecoveryFinished;
     this.TaskState = taskState;
     this.Error     = error;
     this.IsInstantRecoveryFinished = isInstantRecoveryFinished;
     this.TaskState = taskState;
     this.VirtualDiskRestoreResponse = virtualDiskRestoreResponse;
 }
Esempio n. 6
0
        /// <inheritdoc cref="ITasksDao.FindTasks"/>
        public FindTasksResult FindTasks(string taskType, string reference, TaskStateEnum?taskState)
        {
            Contract.Requires(!string.IsNullOrEmpty(reference));
            Contract.Ensures(Contract.Result <FindTasksResult>() != null);

            CheckObjectAlreadyDisposed();
            if (WindowsIdentity != null)
            {
                using (WindowsIdentity.Impersonate())
                {
                    return(TasksDao.FindTasks(taskType, reference, taskState));
                }
            }
            return(TasksDao.FindTasks(taskType, reference, taskState));
        }
Esempio n. 7
0
        private IQuery BuildCountTasksQuery(
            IEnumerable <string> taskTypes,
            IEnumerable <KeyValuePair <string, string> > searchAttributes,
            TaskStateEnum?taskState)
        {
            Contract.Requires(searchAttributes != null);
            Contract.Ensures(Contract.Result <IQuery>() != null);

            TaskQuery taskQuery = BuildBaseTasksQuery(taskTypes, searchAttributes, taskState, null);
            IQuery    query     = Session.CreateQuery(@"select count(*) " + taskQuery.QueryString);

            foreach (KeyValuePair <string, object> parameter in taskQuery.Parameters)
            {
                query.SetParameter(parameter.Key, parameter.Value);
            }
            return(query);
        }
Esempio n. 8
0
        private IQuery BuildFindTasksQuery(
            IEnumerable <string> taskTypes,
            IEnumerable <KeyValuePair <string, string> > searchAttributes,
            TaskStateEnum?taskState,
            int?maximumResults)
        {
            Contract.Requires(searchAttributes != null);
            Contract.Ensures(Contract.Result <IQuery>() != null);

            TaskQuery taskQuery = BuildBaseTasksQuery(taskTypes, searchAttributes, taskState, @"t.CreatedAt asc");
            IQuery    query     = Session.CreateQuery(taskQuery.QueryString);

            foreach (KeyValuePair <string, object> parameter in taskQuery.Parameters)
            {
                query.SetParameter(parameter.Key, parameter.Value);
            }
            if (maximumResults != null)
            {
                query.SetMaxResults(maximumResults.Value);
            }
            return(query);
        }
Esempio n. 9
0
        private static TaskQuery BuildBaseTasksQuery(
            IEnumerable <string> taskTypes,
            IEnumerable <KeyValuePair <string, string> > searchAttributes,
            TaskStateEnum?taskState,
            string optionalOrderbyClause)
        {
            Contract.Requires(searchAttributes != null);
            Contract.Ensures(Contract.Result <TaskQuery>() != null);

            // Start with base query
            StringBuilder queryString               = new StringBuilder(@"from Task t", 2048);
            List <string> wherePredicates           = new List <string>();
            IDictionary <string, object> parameters = new Dictionary <string, object>();

            // Handle searchAttributes
            {
                int i = 0;
                foreach (KeyValuePair <string, string> pair in searchAttributes)
                {
                    queryString.AppendFormat(@" join t.Attributes a{0}", i);
                    wherePredicates.Add(string.Format(@"index(a{0}) = :AttributeName{0} and a{0} = :AttributeValue{0}", i));
                    parameters.Add(@"AttributeName" + i, pair.Key);
                    parameters.Add(@"AttributeValue" + i, pair.Value);
                    i++;
                }
            }

            // Handle taskTypes
            {
                StringBuilder orTasks = new StringBuilder(512);
                int           i       = 0;
                foreach (string taskType in taskTypes.Where(taskType => !string.IsNullOrEmpty(taskType)))
                {
                    orTasks.Append(i == 0 ? "(" : " or ");
                    orTasks.Append(@"t.TaskType = :TaskType" + i);
                    parameters.Add(@"TaskType" + i, taskType.EndsWith("/") ? taskType : string.Concat(taskType, "/"));
                    i++;
                }
                if (i > 0)
                {
                    orTasks.Append(')');
                    wherePredicates.Add(orTasks.ToString());
                }
            }

            // Handle taskState
            if (taskState != null)
            {
                int           value = (int)taskState.Value;
                StringBuilder taskStatePredicate  = new StringBuilder(64);
                bool          firstStatePredicate = true;
                int           state = 1;
                int           i     = 0;
                while (state <= value)
                {
                    if ((state & value) != 0)
                    {
                        if (firstStatePredicate)
                        {
                            taskStatePredicate.AppendFormat(@"(t.State = :State{0}", i);
                            firstStatePredicate = false;
                        }
                        else
                        {
                            taskStatePredicate.AppendFormat(@" or t.State = :State{0}", i);
                        }
                        parameters.Add(@"State" + i, (TaskStateEnum)state);
                    }
                    state <<= 1;
                    i++;
                }
                if (!firstStatePredicate)
                {
                    taskStatePredicate.Append(')');
                    wherePredicates.Add(taskStatePredicate.ToString());
                }
            }

            // join query with where predicates
            bool firstPredicate = true;

            foreach (string predicate in wherePredicates)
            {
                if (firstPredicate)
                {
                    queryString.AppendFormat(@" where {0}", predicate);
                    firstPredicate = false;
                }
                else
                {
                    queryString.AppendFormat(@" and {0}", predicate);
                }
            }

            // Append 'order by' clause if specified
            if (!string.IsNullOrEmpty(optionalOrderbyClause))
            {
                queryString.AppendFormat(@" order by {0}", optionalOrderbyClause);
            }

            return(new TaskQuery(queryString.ToString(), parameters));
        }
Esempio n. 10
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));
        }
 public FindTasksResult FindTasks(string tasktype, IDictionary <string, string> searchAttributes, TaskStateEnum?taskState)
 {
     // NOP
     return(null);
 }
 public FindTasksResult FindTasks(IEnumerable <string> taskTypes, IDictionary <string, string> searchAttributes, TaskStateEnum?taskState)
 {
     // NOP
     return(null);
 }
        /// <inheritdoc cref="ITasksDao.FindTasks"/>
        public FindTasksResult FindTasks(string taskType, IDictionary <string, string> searchAttributes, TaskStateEnum?taskState)
        {
            Contract.Ensures(Contract.Result <FindTasksResult>() != null);

            IEnumerable <string> taskTypes = string.IsNullOrEmpty(taskType)
                ? Enumerable.Empty <string>()
                : new[] { taskType };

            return(FindTasks(taskTypes, searchAttributes, taskState));
        }
Esempio n. 14
0
        public FindTasksResult FindTasks(IEnumerable <string> taskTypes, IDictionary <string, string> searchAttributes, TaskStateEnum?taskState)
        {
            Contract.Requires(Transaction.Current != null);
            Contract.Requires(taskTypes != null);
            Contract.Ensures(Contract.Result <FindTasksResult>() != null);

            return(default(FindTasksResult));
        }
        public FindTasksResult FindTasks(IEnumerable <string> taskTypes, IDictionary <string, string> searchAttributes, TaskStateEnum?taskState)
        {
            Contract.Ensures(Contract.Result <FindTasksResult>() != null);

            CheckObjectAlreadyDisposed();
            if (WindowsIdentity != null)
            {
                using (WindowsIdentity.Impersonate())
                {
                    return(TasksDao.FindTasks(taskTypes, searchAttributes, taskState));
                }
            }
            return(TasksDao.FindTasks(taskTypes, searchAttributes, taskState));
        }
Esempio n. 16
0
 public FindTasksResult FindTasks(string tasktype, IDictionary <string, string> searchAttributes, TaskStateEnum?taskState)
 {
     return(new FindTasksResult(m_Tasks, 0));
 }
Esempio n. 17
0
 public FindTasksResult FindTasks(IEnumerable <string> taskTypes, IDictionary <string, string> searchAttributes, TaskStateEnum?taskState)
 {
     return(new FindTasksResult(m_Tasks, 0));
 }
Esempio n. 18
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));
        }
 public FindTasksResult FindTasks(string tasktype, string reference, TaskStateEnum?taskState)
 {
     // NOP
     return(null);
 }