Esempio n. 1
0
        public Boolean IsEqual(WorkQueueGetWorkUserView compareMembership)
        {
            Boolean isEqual = true;

            isEqual = isEqual && (this.workQueueId == compareMembership.WorkQueueId);

            isEqual = isEqual && (this.securityAuthorityId != compareMembership.SecurityAuthorityId);

            isEqual = isEqual && (this.userAccountId != compareMembership.UserAccountId);

            isEqual = isEqual && (this.userDisplayName != compareMembership.UserDisplayName);

            isEqual = isEqual && (this.workQueueViewId != compareMembership.workQueueViewId);

            return(isEqual);
        }
Esempio n. 2
0
        public WorkQueueGetWorkUserView GetWorkUserView(Int64 securityAuthorityId, String userAccountId)
        {
            WorkQueueGetWorkUserView userView = null;

            foreach (WorkQueueGetWorkUserView currentUserView in getWorkUserViews)
            {
                if ((currentUserView.SecurityAuthorityId == securityAuthorityId)

                    && (currentUserView.UserAccountId == userAccountId))
                {
                    userView = currentUserView;

                    break;
                }
            }

            return(userView);
        }
Esempio n. 3
0
        public WorkQueueItem GetWork()
        {
            Int64 workQueueItemId = 0;

            WorkQueueItem workQueueItem = null;

            WorkQueueGetWorkUserView getWorkUserView = null;

            WorkQueueView workQueueView = null;

            List <Data.FilterDescriptor> filters = new List <Data.FilterDescriptor> ();

            String customFilters = String.Empty;


            // GET WORK IS DYNAMICALLY CREATED BY WORK QUEUE VIEWS, THIS CANNOT BE DONE IN A STORED PROCEDURE


            if (!HasWorkPermission)
            {
                application.SetLastException(new ApplicationException("Permission Denied. No Work Permissions to Work Queue (\"" + Name + "\").")); return(null);
            }

            try {
                // ATTEMPT TO GET USER SPECIFIC VIEW FIRST

                getWorkUserView = GetWorkUserView(application.Session.SecurityAuthorityId, application.Session.UserAccountId);

                if (getWorkUserView != null)
                {
                    workQueueView = getWorkUserView.WorkQueueView;
                }

                // ELSE FALLBACK TO DEFAULT VIEW FOR THE OVERALL WORK QUEUE

                else
                {
                    workQueueView = application.WorkQueueViewGet(getWorkViewId);
                }                                                                      // 0 VALUE IS HANDLED IN THE GET FUNCTION

                // FINALLY FALLBACK TO SYSTEM DEFAULT VIEW IF NO VIEW ASSIGNED TO WORK QUEUE

                if (workQueueView != null)
                {
                    // APPEND FILTERS THAT ARE FOR STANDARD FIELDS AND NOT CUSTOM FIELDS

                    foreach (Int32 currentFilterKey in workQueueView.FilterDefinitions.Keys)
                    {
                        if (workQueueView.WellKnownFields.ContainsKey(workQueueView.FilterDefinitions[currentFilterKey].PropertyPath))
                        {
                            filters.Add((Data.FilterDescriptor)workQueueView.FilterDefinitions[currentFilterKey]);
                        }
                    }
                }


                StringBuilder selectStatement = new StringBuilder();

                selectStatement.Append("SET TRANSACTION ISOLATION LEVEL SERIALIZABLE \r\n\r\n");

                selectStatement.Append("BEGIN TRANSACTION \r\n\r\n");

                selectStatement.Append("  DECLARE @workQueueItemId AS BIGINT \r\n\r\n");

                selectStatement.Append("  DECLARE @itemGroupKey AS VARCHAR (060) \r\n\r\n");


                selectStatement.Append("  SELECT @workQueueItemId = WorkQueueItemId, @itemGroupKey = ItemGroupKey \r\n\r\n FROM (\r\n\r\n");


                selectStatement.Append("  SELECT \r\n\r\n");

                selectStatement.Append("      " + application.WorkQueueItemsGetRowNumberSql(null, workQueueView) + " WorkQueueItemId, ItemGroupKey \r\n\r\n");

                selectStatement.Append("    FROM (" + application.WorkQueueItemsGetSqlStatement(filters) + ") AS WorkQueueItem ) AS WorkQueueItemTop1 WHERE RowNumber = 1 \r\n");


                if (workQueueView != null)
                {
                    String customFields = String.Empty;

                    foreach (Core.Work.WorkQueueViewFieldDefinition currentFieldDefinition in workQueueView.FieldDefinitions)
                    {
                        String extendedPropertyField = currentFieldDefinition.SqlSelectList;

                        if (!String.IsNullOrEmpty(extendedPropertyField))
                        {
                            customFields = customFields + ", " + extendedPropertyField;
                        }
                    }

                    selectStatement.Replace("/*_CUSTOM_FIELD_INSERT_*/", customFields);
                }

                String itemFilter = "      AND (WorkQueueItem.AssignedToSecurityAuthorityId = 0) AND (CompletionDate IS NULL) \r\n\r\n";

                itemFilter = itemFilter + "      AND (GETDATE () >= WorkQueueItem.ConstraintDate)\r\n\r\n";

                itemFilter = itemFilter + "      AND (WorkQueueId = " + Id.ToString() + ")\r\n\r\n";

                itemFilter = itemFilter + "      AND ((WorkTimeRestrictions IS NULL) \r\n\r\n";

                itemFilter = itemFilter + "        OR (CAST ((ISNULL (WorkTimeRestrictions.value ('(DayOfWeekTimes/";

                itemFilter = itemFilter + "Day[@DayOfWeek=\"" + ((Int32)DateTime.Today.DayOfWeek).ToString() + "\"]/";

                itemFilter = itemFilter + "Time[@StartTime <= \"" + DateTime.Now.ToString("hh:mm:ss") + "\"";

                itemFilter = itemFilter + "and @EndTime >= \"" + DateTime.Now.ToString("hh:mm:ss") + "\"])[1]', 'BIT'), 1) - 1) AS BIT) = 1)) \r\n\r\n";


                if (workQueueView != null)
                {
                    // APPEND FILTERS THAT ARE NOT STANDARD FIELDS

                    foreach (Int32 currentFilterKey in workQueueView.FilterDefinitions.Keys)
                    {
                        if (!workQueueView.WellKnownFields.ContainsKey(workQueueView.FilterDefinitions[currentFilterKey].PropertyPath))
                        {
                            foreach (Core.Work.WorkQueueViewFieldDefinition currentFieldDefinition in workQueueView.FieldDefinitions)
                            {
                                if (currentFieldDefinition.DisplayName == workQueueView.FilterDefinitions[currentFilterKey].PropertyPath)
                                {
                                    Data.FilterDescriptor filterDescriptor = new Data.FilterDescriptor(

                                        currentFieldDefinition.SqlDeclaration,

                                        workQueueView.FilterDefinitions[currentFilterKey].Operator,

                                        workQueueView.FilterDefinitions[currentFilterKey].Parameter.Value);

                                    itemFilter = itemFilter + " AND (" + filterDescriptor.SqlCriteriaString(String.Empty) + ")";
                                }
                            }
                        }
                    }
                }


                selectStatement.Replace("/*_CUSTOM_FILTER_INSERT_*/", itemFilter);



                selectStatement.Append("  IF (@workQueueItemId IS NOT NULL) \r\n\r\n");

                selectStatement.Append("      BEGIN \r\n\r\n");

                selectStatement.Append("        EXEC WorkQueueItem_AssignTo @workQueueItemId, ");

                selectStatement.Append(application.Session.SecurityAuthorityId.ToString() + ", ");

                selectStatement.Append("'" + application.Session.UserAccountId.Replace("'", "''") + "', ");

                selectStatement.Append("'" + application.Session.UserAccountName.Replace("'", "''") + "', ");

                selectStatement.Append("'" + application.Session.UserDisplayName.Replace("'", "''") + "', ");

                selectStatement.Append("'Get Work', \r\n\r\n");

                selectStatement.Append("'" + application.Session.SecurityAuthorityName.Replace("'", "''") + "', ");

                selectStatement.Append("'" + application.Session.UserAccountId.Replace("'", "''") + "', ");

                selectStatement.Append("'" + application.Session.UserAccountName.Replace("'", "''") + "' \r\n\r\n");

                if (getWorkUseGrouping)
                {
                    selectStatement.Append("        IF (LEN (RTRIM (@itemGroupKey)) > 0) \r\n\r\n");

                    selectStatement.Append("          BEGIN \r\n\r\n");

                    selectStatement.Append("            DECLARE @currentWorkQueueItemId AS BIGINT \r\n\r\n");

                    selectStatement.Append("            DECLARE GroupItemsCursor CURSOR FOR  \r\n\r\n");

                    selectStatement.Append("              SELECT WorkQueueItemId FROM WorkQueueItem WHERE (WorkQueueId = " + Id.ToString() + ") AND (ItemGroupKey = @itemGroupKey) AND (WorkQueueItemId <> @workQueueItemId) AND CompletionDate IS NULL AND AssignedToSecurityAuthorityId = 0 \r\n\r\n");

                    selectStatement.Append("            OPEN GroupItemsCursor \r\n\r\n");

                    selectStatement.Append("            FETCH NEXT FROM GroupItemsCursor INTO @currentWorkQueueItemId \r\n\r\n");

                    selectStatement.Append("            WHILE (@@FETCH_STATUS = 0)    \r\n\r\n");

                    selectStatement.Append("              BEGIN \r\n\r\n");

                    selectStatement.Append("                EXEC WorkQueueItem_AssignTo @currentWorkQueueItemId, ");

                    selectStatement.Append(application.Session.SecurityAuthorityId.ToString() + ", ");

                    selectStatement.Append("'" + application.Session.UserAccountId.Replace("'", "''") + "', ");

                    selectStatement.Append("'" + application.Session.UserAccountName.Replace("'", "''") + "', ");

                    selectStatement.Append("'" + application.Session.UserDisplayName.Replace("'", "''") + "', ");

                    selectStatement.Append("'Get Work - By Grouping', \r\n\r\n");

                    selectStatement.Append("'" + application.Session.SecurityAuthorityName.Replace("'", "''") + "', ");

                    selectStatement.Append("'" + application.Session.UserAccountId.Replace("'", "''") + "', ");

                    selectStatement.Append("'" + application.Session.UserAccountName.Replace("'", "''") + "' \r\n\r\n");


                    selectStatement.Append("                FETCH NEXT FROM GroupItemsCursor INTO @currentWorkQueueItemId \r\n\r\n");

                    selectStatement.Append("              END \r\n\r\n");

                    selectStatement.Append("            CLOSE GroupItemsCursor   \r\n\r\n");

                    selectStatement.Append("            DEALLOCATE GroupItemsCursor                      \r\n\r\n");

                    selectStatement.Append("          END \r\n\r\n");
                }

                selectStatement.Append("      END \r\n\r\n");

                selectStatement.Append("    ELSE  \r\n\r\n");

                selectStatement.Append("      BEGIN \r\n\r\n");

                selectStatement.Append("        SET @workQueueItemId = 0 \r\n\r\n");

                selectStatement.Append("      END \r\n\r\n");

                selectStatement.Append("      SELECT @workQueueItemId \r\n\r\n");

                selectStatement.Append("COMMIT TRANSACTION \r\n\r\n");


                workQueueItemId = (Int64)application.EnvironmentDatabase.ExecuteScalar(selectStatement.ToString());

                workQueueItem = application.WorkQueueItemGet(workQueueItemId);
            }

            catch (Exception applicationException) {
                application.EnvironmentDatabase.ExecuteSqlStatement("ROLLBACK TRANSACTION");

                throw applicationException;
            }

            finally {
            }

            return(workQueueItem);
        }
Esempio n. 4
0
        public override void MapDataFields(System.Data.DataRow currentRow)
        {
            String selectStatement = String.Empty;


            base.MapDataFields(currentRow);


            workflowId = (currentRow["WorkflowId"] is DBNull) ? 0 : (Int64)currentRow["WorkflowId"];


            scheduleValue = (Int32)currentRow["ScheduleValue"];

            scheduleQualifier = (Mercury.Server.Core.Enumerations.DateQualifier)(Int32) currentRow["ScheduleQualifier"];

            thresholdValue = (Int32)currentRow["ThresholdValue"];

            thresholdQualifier = (Mercury.Server.Core.Enumerations.DateQualifier)(Int32) currentRow["ThresholdQualifier"];

            initialConstraintValue = (Int32)currentRow["InitialConstraintValue"];

            initialConstraintQualifier = (Mercury.Server.Core.Enumerations.DateQualifier)(Int32) currentRow["InitialConstraintQualifier"];

            initialMilestoneValue = (Int32)currentRow["InitialMilestoneValue"];

            initialMilestoneQualifier = (Mercury.Server.Core.Enumerations.DateQualifier)(Int32) currentRow["InitialMilestoneQualifier"];


            GetWorkViewId = (Int64)currentRow["GetWorkViewId"];

            GetWorkUseGrouping = (Boolean)currentRow["GetWorkUseGrouping"];


            // LOAD WORK QUEUE USER VIEWS

            selectStatement = "SELECT * FROM dbo.WorkQueueGetWorkUserView WHERE WorkQueueId = " + Id.ToString() + " ORDER BY SecurityAuthorityId, UserAccountName";

            System.Data.DataTable userViewsTable = application.EnvironmentDatabase.SelectDataTable(selectStatement);

            getWorkUserViews = new List <WorkQueueGetWorkUserView> ();


            foreach (System.Data.DataRow currentUserViewRow in userViewsTable.Rows)
            {
                WorkQueueGetWorkUserView userView = new WorkQueueGetWorkUserView(application);

                userView.MapDataFields(currentUserViewRow);

                getWorkUserViews.Add(userView);
            }



            // ALWAYS LOAD WORK TEAMS

            selectStatement = "SELECT WorkQueueTeam.*, WorkTeam.WorkTeamName FROM WorkQueueTeam JOIN WorkTeam ON WorkQueueTeam.WorkTeamId = WorkTeam.WorkTeamId WHERE WorkQueueId = " + id.ToString() + " ORDER BY WorkTeamName";

            System.Data.DataTable workTeamsTable = application.EnvironmentDatabase.SelectDataTable(selectStatement.ToString(), 0);

            foreach (System.Data.DataRow currentWorkTeamRow in workTeamsTable.Rows)
            {
                WorkQueueTeam team = new WorkQueueTeam(application);

                team.MapDataFields(currentWorkTeamRow);

                workTeams.Add(team);
            }

            return;
        }