Example #1
0
 /// <summary>
 /// Delegate or shared worklist to the specific user
 /// </summary>
 /// <param name="serialNumber">The serial number</param>
 /// <param name="destination">The specific user</param>
 public void DelegateWorklistItem(string serialNumber, string destination)
 {
     try {
         using (Connection workflowClient = this.GetWorkflowClient()) {
             K2.WorklistItem worklistItem = workflowClient.OpenWorklistItem(serialNumber, null, false);
             if (worklistItem == null)
             {
                 throw new InvalidOperationException(string.Format("Not Found", serialNumber));
             }
             K2.Destination destination2 = new K2.Destination();
             foreach (K2.Action action in worklistItem.Actions)
             {
                 if (action != null)
                 {
                     destination2.AllowedActions.Add(action.Name);
                 }
             }
             destination2.Name            = destination;
             destination2.DestinationType = DestinationType.User;
             worklistItem.Delegate(destination2);
         }
     } catch (UnauthorizedAccessException ex) {
         throw ex;
     } catch (SmartException ex) {
         throw ex;
     }
 }
Example #2
0
        /// <summary>
        /// Get The Out Of Office work type exception
        /// </summary>
        /// <param name="exceptionDtos">The Work type exceptions</param>
        /// <returns>The work type exception</returns>
        public WorkTypeExceptions GetWorkTypeExceptions(IList <WorkTypeExceptionDto> exceptionDtos)
        {
            WorkTypeExceptions worktypeExceptions = new WorkTypeExceptions();

            foreach (WorkTypeExceptionDto exceptionDto in exceptionDtos)
            {
                var          exception    = new WorkTypeException();
                Destinations destinations = new Destinations();
                foreach (DestinationDto dest in exceptionDto.Destinations)
                {
                    var destination = new K2.Destination(SecurityLabelUtils.GetNameWithLabel(dest.LoginName), DestinationType.User);
                    destinations.Add(destination);
                }
                exception.Name             = exceptionDto.Name;
                exception.Destinations     = destinations;
                exception.WorklistCriteria = this.configureWorklistCriteria(exceptionDto.ProcessPath, exceptionDto.Activity);
                worktypeExceptions.Add(exception);
            }

            return(worktypeExceptions);
        }
Example #3
0
        /// <summary>
        /// Delegate or shared worklist to other users
        /// </summary>
        /// <param name="serialNumber">The serial number</param>
        /// <param name="destinations">The other users</param>
        public void Share(string serialNumber, IList <string> destinations)
        {
            try
            {
                K2.WorklistItem worklistItem = GetWorklistItem(serialNumber);
                if (worklistItem == null)
                {
                    throw new InvalidOperationException(string.Format("Not Found", serialNumber));
                }

                if (destinations == null || destinations.Count == 0)
                {
                    throw new InvalidOperationException(string.Format("Destination users is null or empty"));
                }

                var destinationUsers = new K2.Destinations();
                foreach (string dest in destinations)
                {
                    K2.Destination destination = new K2.Destination();
                    foreach (K2.Action action in worklistItem.Actions)
                    {
                        if (action != null)
                        {
                            destination.AllowedActions.Add(action.Name);
                        }
                    }
                    destination.Name            = dest;
                    destination.DestinationType = DestinationType.User;
                    destinationUsers.Add(destination);
                }

                worklistItem.Delegate(destinationUsers);
            }
            catch (Exception ex)
            {
            }
        }
Example #4
0
        /// <summary>
        /// Create or set the Out Of Office of current user
        /// </summary>
        /// <param name="wrapper">The Out Of Office criteria</param>
        /// <returns>Success(true) or Fail(False)</returns>
        public bool SetOutOfOffice(OOFWrapper wrapper)
        {
            if (wrapper.WorkType == null)
            {
                using (Connection workflowClient = this.GetWorkflowClient()) {
                    workflowClient.SetUserStatus(Convert.ToBoolean(wrapper.Status) ? UserStatuses.Available : UserStatuses.OOF);
                }

                return(false);
            }

            using (Connection workflowClient = this.GetWorkflowClient()) {
                bool           isNew          = false;
                WorklistShares worklistShares = new WorklistShares();
                worklistShares = workflowClient.GetCurrentSharingSettings(ShareType.OOF);
                WorklistShare worklistShare = null;
                if (worklistShares.Count > 0)
                {
                    worklistShare           = worklistShares[0];
                    worklistShare.ShareType = ShareType.OOF;
                }
                else
                {
                    isNew = true;
                }

                if (worklistShare == null)
                {
                    worklistShare           = new WorklistShare();
                    worklistShare.ShareType = ShareType.OOF;
                    isNew = true;
                }


                worklistShare.StartDate = wrapper.StartDate;
                worklistShare.EndDate   = wrapper.EndDate;

                WorkTypes workTypes = worklistShare.WorkTypes;
                WorkType  workType  = new WorkType();

                if (workTypes.Count > 0)
                {
                    workType = workTypes[0];
                }
                else
                {
                    workType = new WorkType();
                    workTypes.Add(workType);
                }
                workType.Name = Guid.NewGuid().ToString();
                Destinations destinations = new Destinations();

                foreach (DestinationDto dest in wrapper.WorkType.Destinations)
                {
                    if (SecurityLabelUtils.IsCorrectUserName(dest.LoginName))
                    {
                        var destination = new K2.Destination(SecurityLabelUtils.GetNameWithLabel(dest.LoginName), DestinationType.User);
                        destinations.Add(destination);
                    }
                }

                workType.Destinations       = destinations;
                workType.WorkTypeExceptions = GetWorkTypeExceptions(wrapper.WorkType.WorkTypeExceptions);
                worklistShare.WorkTypes     = workTypes;

                if (isNew)
                {
                    workflowClient.ShareWorkList(worklistShare);
                }
                workflowClient.UpdateWorkType(worklistShare.WorkTypes[0]);
                workflowClient.SetUserStatus(Convert.ToBoolean(wrapper.Status) ? UserStatuses.Available : UserStatuses.OOF);
            }

            return(true);
        }