/// <summary> /// Adds elements from queue with filtration. /// </summary> /// <param name="entitySchemaName">Entity schema name of queue element.</param> /// <param name="entitySelect">Query to queue object with filtration.</param> /// <param name="queueId">Identifier of queue.</param> /// <param name="queueName">Queue name.</param> /// <returns></returns> private int AddEntityQueueItemsByFilter(string entitySchemaName, Select entitySelect, Guid queueId, string queueName) { try { entitySelect.Top(_insertQueueItemTopValue) .Column(new QueryParameter("QueueId", queueId)).As("QueueId") .Column(new QueryParameter("StatusId", _newQueueItemStatusId)).As("StatusId"); var selectCondition = new QueryCondition(); selectCondition.IsNot = true; selectCondition.Exists( new Select(_userConnection) .Column("QueueItem", "Id") .From("QueueItem") .InnerJoin("QueueItemStatus") .On("QueueItemStatus", "Id").IsEqual("QueueItem", "StatusId") .Where(entitySchemaName, "Id").IsEqual("QueueItem", "EntityRecordId") .And("QueueItem", "QueueId").IsEqual(Column.Parameter(queueId)) .And("QueueItemStatus", "IsFinal").IsNotEqual(Column.Parameter(true))); if (!entitySelect.HasCondition) { entitySelect.Where(selectCondition); } else { entitySelect.And(selectCondition); } var insertSelect = new InsertSelect(_userConnection) .Into("QueueItem") .Set("EntityRecordId", "QueueId", "StatusId") .FromSelect(entitySelect); DateTime addedRecordsStartTime = DateTime.Now; int addedRecords = insertSelect.Execute(); if (addedRecordsStartTime.AddSeconds(60) < DateTime.Now) { insertSelect.BuildParametersAsValue = true; QueuesUtilities.LogDebug(string.Format(GetResourceValue("LongInsertQueueItemsMessage"), queueName, _autoUpdateQueuesProcessId.ToString(), insertSelect.GetSqlText())); } return(addedRecords); } catch (Exception e) { QueuesUtilities.LogError(string.Format(GetResourceValue("InvokeMethodErrorMessage"), string.Concat("AddEntityQueueItemsByFilter ", queueName), e.Message), e); throw; } }