/// <summary>
        /// List all existing shares for a current user
        /// </summary>
        private void ListSharedUsers()
        {
            ServiceObject serviceObject = base.ServiceBroker.Service.ServiceObjects[0];

            serviceObject.Properties.InitResultTable();
            DataTable results = base.ServiceBroker.ServicePackage.ResultTable;

            using (Connection k2Con = this.ServiceBroker.K2Connection.GetWorkflowClientConnection())
            {
                // None for userstatus means the users is not configured, throw an exception
                if (UserStatuses.None == k2Con.GetUserStatus())
                {
                    throw new ApplicationException(Resources.OutOfOfficeNotConfiguredForUser);
                }

                WorklistShares wsColl = k2Con.GetCurrentSharingSettings(ShareType.OOF);

                foreach (WorklistShare ws in wsColl)
                {
                    //throw new ApplicationException("collection count is: "+ wsColl.Count.ToString());
                    foreach (WorkType wt in ws.WorkTypes)
                    {
                        foreach (Destination dest in wt.Destinations)
                        {
                            DataRow dr = results.NewRow();
                            dr[Constants.SOProperties.OutOfOffice.DestinationUser] = dest.Name.ToString();
                            results.Rows.Add(dr);
                        }
                    }
                }

                k2Con.Close();
            }
        }
        /// <summary>
        /// Remove all existing shares for a current user
        /// </summary>
        private void RemoveAllShares()
        {
            ServiceObject serviceObject = base.ServiceBroker.Service.ServiceObjects[0];

            serviceObject.Properties.InitResultTable();
            DataTable results = base.ServiceBroker.ServicePackage.ResultTable;

            using (Connection k2Con = this.ServiceBroker.K2Connection.GetWorkflowClientConnection())
            {
                // None for userstatus means the users is not configured, throw an exception
                if (UserStatuses.None == k2Con.GetUserStatus())
                {
                    throw new ApplicationException(Resources.OutOfOfficeNotConfiguredForUser);
                }

                WorklistShares wsColl = k2Con.GetCurrentSharingSettings(ShareType.OOF);
                if (wsColl != null && wsColl.Count > 0)
                {
                    k2Con.UnShareAll();
                }

                k2Con.Close();
            }

            // Necessary to prevent unwanted errors when configuring status
            SetStatus(UserStatuses.Available);
        }
Exemplo n.º 3
0
        private void ListSharedUsers()
        {
            string userFQN = base.GetStringProperty(Constants.SOProperties.OutOfOffice.UserFQN);

            ServiceObject serviceObject = base.ServiceBroker.Service.ServiceObjects[0];

            serviceObject.Properties.InitResultTable();
            DataTable results = base.ServiceBroker.ServicePackage.ResultTable;

            WorkflowManagementServer mngServer = this.ServiceBroker.K2Connection.GetConnection <WorkflowManagementServer>();

            using (mngServer.Connection)
            {
                // None for userstatus means the users is not configured, throw an exception
                if (mngServer.GetUserStatus(userFQN) == UserStatuses.None)
                {
                    throw new ApplicationException(Resources.OutOfOfficeNotConfiguredForUser);
                }
                WorklistShares wsColl = mngServer.GetCurrentSharingSettings(userFQN, ShareType.OOF);

                foreach (WorklistShare ws in wsColl)
                {
                    foreach (WorkType wt in ws.WorkTypes)
                    {
                        foreach (Destination dest in wt.Destinations)
                        {
                            DataRow dr = results.NewRow();
                            dr[Constants.SOProperties.OutOfOffice.UserFQN]         = userFQN;
                            dr[Constants.SOProperties.OutOfOffice.DestinationUser] = dest.Name.ToString();
                            results.Rows.Add(dr);
                        }
                    }
                }
            }
        }
Exemplo n.º 4
0
        private void ListUsers()
        {
            ServiceObject serviceObject = base.ServiceBroker.Service.ServiceObjects[0];

            serviceObject.Properties.InitResultTable();
            DataTable results = base.ServiceBroker.ServicePackage.ResultTable;
            WorkflowManagementServer mngServer = this.ServiceBroker.K2Connection.GetConnection <WorkflowManagementServer>();

            using (mngServer.Connection)
            {
                SourceCode.Workflow.Management.OOF.Users users = mngServer.GetUsers(ShareType.OOF);


                foreach (SourceCode.Workflow.Management.OOF.User user in users)
                {
                    if (user.Status != UserStatuses.None)
                    {
                        WorklistShares wsColl = mngServer.GetCurrentSharingSettings(user.FQN, ShareType.OOF);
                        foreach (WorklistShare ws in wsColl)
                        {
                            foreach (WorkType wt in ws.WorkTypes)
                            {
                                foreach (Destination dest in wt.Destinations)
                                {
                                    DataRow dr = results.NewRow();
                                    dr[Constants.SOProperties.OutOfOffice.UserFQN]         = user.FQN;
                                    dr[Constants.SOProperties.OutOfOffice.DestinationUser] = dest.Name;
                                    results.Rows.Add(dr);
                                }
                            }
                        }
                    }
                }
            }
        }
        private void RemoveOutOfOffice()
        {
            string destinationUser = base.GetStringProperty(Constants.SOProperties.OutOfOffice.DestinationUser);

            ServiceObject serviceObject = base.ServiceBroker.Service.ServiceObjects[0];

            serviceObject.Properties.InitResultTable();
            DataTable results = base.ServiceBroker.ServicePackage.ResultTable;


            using (Connection k2Con = new Connection())
            {
                k2Con.Open(base.K2ClientConnectionSetup);

                WorklistShares wsColl = k2Con.GetCurrentSharingSettings(ShareType.OOF);

                //  Throw error if multiple configurations (WorklistShare objects) detected, as this method cannot support that
                if (wsColl.Count != 1)
                {
                    throw new ApplicationException(Constants.ErrorMessages.MultipleOOFConfigurations);
                }


                //  If configuration exist already, remove user and re-share
                else if (wsColl.Count == 1)
                {
                    WorklistShare worklistshare = wsColl[0];

                    int capacity = worklistshare.WorkTypes[0].Destinations.Count;

                    string[] existingDestinations = new string[capacity];

                    for (int i = 0; i < capacity; i++)
                    {
                        existingDestinations[i] = worklistshare.WorkTypes[0].Destinations[i].Name.ToUpper().Trim();
                    }

                    int destinationIndex = Array.IndexOf(existingDestinations, destinationUser.ToUpper().Trim());

                    if (destinationIndex != -1)
                    {
                        worklistshare.WorkTypes[0].Destinations.Remove(destinationIndex);
                    }

                    bool result = k2Con.ShareWorkList(worklistshare);

                    DataRow dr = results.NewRow();

                    dr[Constants.SOProperties.OutOfOffice.DestinationUser] = destinationUser;

                    results.Rows.Add(dr);;
                }

                k2Con.Close();
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Load worklist shared from K2 HostServer
        /// </summary>
        /// <returns>The worklist shares</returns>
        public WorklistShares LoadOOF()
        {
            WorklistShares result;

            using (Connection workflowClient = this.GetWorkflowClient()) {
                WorklistShares currentSharingSettings = workflowClient.GetCurrentSharingSettings(ShareType.OOF);
                result = currentSharingSettings;
            }
            return(result);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Get User Out of Office status from K2 HostServer
        /// </summary>
        /// <param name="originalDestinationUser">The Originator Destination User</param>
        /// <returns>The Worklist user status</returns>
        public WorklistUserStatus GetOOFStatus(string originalDestinationUser)
        {
            bool status = false;
            WorklistUserStatus worklistUserStatus = new WorklistUserStatus();

            using (Connection workflowClient = this.GetWorkflowClient()) {
                switch (string.IsNullOrEmpty(originalDestinationUser) ? workflowClient.GetUserStatus() : workflowClient.GetUserStatus(originalDestinationUser))
                {
                case UserStatuses.None:
                case UserStatuses.Available:
                    status = true;
                    break;

                case UserStatuses.OOF:
                    status = false;
                    break;
                }
                worklistUserStatus.Status = status;
                if (!worklistUserStatus.Status)
                {
                    WorklistShares worklistShares = new WorklistShares();
                    worklistShares = workflowClient.GetCurrentSharingSettings(ShareType.OOF);
                    if (worklistShares.Count > 0)
                    {
                        WorklistShare worklistShare = worklistShares[0];
                        worklistShare.ShareType = ShareType.OOF;
                        List <OOFUser> list = new List <OOFUser>();
                        foreach (K2.Destination destination in worklistShare.WorkTypes[0].Destinations)
                        {
                            list.Add(new OOFUser {
                                UserName = destination.Name,
                                Type     = destination.DestinationType.ToString()
                            });
                        }
                        worklistUserStatus.users = list;
                    }
                }
            }
            return(worklistUserStatus);
        }
        //sample that shows how to use Out-of-Office in the workflow management API
        //in this example, we just want to output all users that are currently out-of-office
        public void ListOutOfOfficeUsers()
        {
            //establish the connection
            WorkflowManagementServer K2Mgmt = new WorkflowManagementServer();

            K2Mgmt.CreateConnection();
            K2Mgmt.Connection.Open("connectionstring");
            SourceCode.Workflow.Management.OOF.Users OOFUsers = K2Mgmt.GetUsers(ShareType.OOF);
            foreach (SourceCode.Workflow.Management.OOF.User OOFUser in OOFUsers)
            {
                WorklistShares wlss = K2Mgmt.GetCurrentSharingSettings(OOFUser.FQN, ShareType.OOF);
                foreach (WorklistShare wls in wlss)
                {
                    //do something with each "share" record
                    Console.WriteLine("User Name: " + OOFUser.FQN);
                    Console.WriteLine("Start Date: " + wls.StartDate.ToString());
                    Console.WriteLine("End Date: " + wls.EndDate.ToString());
                }
            }

            //close the connection
            K2Mgmt.Connection.Close();
        }
Exemplo n.º 9
0
        private void RemoveAllShares()
        {
            string userFQN = base.GetStringProperty(Constants.SOProperties.OutOfOffice.UserFQN);

            WorkflowManagementServer mngServer = this.ServiceBroker.K2Connection.GetConnection <WorkflowManagementServer>();

            using (mngServer.Connection)
            {
                if (mngServer.GetUserStatus(userFQN) == UserStatuses.None)
                {
                    throw new ApplicationException(Resources.OutOfOfficeNotConfiguredForUser);
                }

                WorklistShares shares = mngServer.GetCurrentSharingSettings(userFQN, ShareType.OOF);

                if (shares == null || shares.Count > 0)
                {
                    mngServer.UnShareAll(userFQN);
                }

                mngServer.Connection.Close();
            }
            SetStatus(UserStatuses.Available, false);
        }
Exemplo n.º 10
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)
            {
                _connection.SetUserStatus(Convert.ToBoolean(wrapper.Status) ? UserStatuses.Available : UserStatuses.OOF);
                return(false);
            }


            bool           isNew          = false;
            WorklistShares worklistShares = new WorklistShares();

            worklistShares = _connection.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)
            {
                var destination = new Destination(dest.LoginName.FQNWithK2Label(), DestinationType.User);
                destinations.Add(destination);
            }

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

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


            return(true);
        }
Exemplo n.º 11
0
        public void EndK2OOF()
        {
            string conStringIIF = this.AppConfig.IIFConnectionString;

            using (SqlConnection con = new SqlConnection(conStringIIF))
            {
                con.Open();
                string querySelect = "SELECT";
                querySelect = querySelect + " [Src].[Id], [Src].[FromDate], [Src].[ToDate]";
                querySelect = querySelect + " , [Src].[FromFQN], [Src].[ToFQN]";
                querySelect = querySelect + " , [Src].[IsActive], [Src].[IsCanceled], [Src].[IsExpired]";
                querySelect = querySelect + " , [Src].[IsStartedInK2], [Src].[IsEndedInK2]";
                querySelect = querySelect + " FROM [dbo].[Vw_TaskDelegation_NeedK2Ended] AS [Src]";

                List <TaskDelegation> listTaskDelegation = new List <TaskDelegation>();

                using (SqlCommand cmd = con.CreateCommand())
                {
                    cmd.CommandType = CommandType.Text;
                    cmd.CommandText = querySelect;

                    using (SqlDataReader dr = cmd.ExecuteReader())
                    {
                        int indexOf_Id            = dr.GetOrdinal("Id");
                        int indexOf_FromDate      = dr.GetOrdinal("FromDate");
                        int indexOf_ToDate        = dr.GetOrdinal("ToDate");
                        int indexOf_FromFQN       = dr.GetOrdinal("FromFQN");
                        int indexOf_ToFQN         = dr.GetOrdinal("ToFQN");
                        int indexOf_IsActive      = dr.GetOrdinal("IsActive");
                        int indexOf_IsCanceled    = dr.GetOrdinal("IsCanceled");
                        int indexOf_IsExpired     = dr.GetOrdinal("IsExpired");
                        int indexOf_IsStartedInK2 = dr.GetOrdinal("IsStartedInK2");
                        int indexOf_IsEndedInK2   = dr.GetOrdinal("IsEndedInK2");

                        while (dr.Read())
                        {
                            TaskDelegation data = new TaskDelegation();
                            data.Id            = dr.GetInt64(indexOf_Id);
                            data.FromDate      = dr.GetDateTime(indexOf_FromDate);
                            data.ToDate        = dr.GetDateTime(indexOf_ToDate);
                            data.FromFQN       = dr.GetString(indexOf_FromFQN);
                            data.ToFQN         = dr.GetString(indexOf_ToFQN);
                            data.IsActive      = dr.GetBoolean(indexOf_IsActive);
                            data.IsCanceled    = dr.GetBoolean(indexOf_IsCanceled);
                            data.IsExpired     = dr.GetBoolean(indexOf_IsExpired);
                            data.IsStartedInK2 = dr.GetBoolean(indexOf_IsStartedInK2);
                            data.IsEndedInK2   = dr.GetBoolean(indexOf_IsEndedInK2);

                            listTaskDelegation.Add(data);
                        }
                    }
                }

                Exception innerEx = null;

                foreach (TaskDelegation taskDelegation in listTaskDelegation)
                {
                    try
                    {
                        using (Connection k2Con = new Connection())
                        {
                            k2Con.Open(this.AppConfig.K2Server);
                            k2Con.ImpersonateUser(taskDelegation.FromFQN);

                            WorklistShares worklistShares = k2Con.GetCurrentSharingSettings(ShareType.OOF);
                            foreach (WorklistShare worklistShare in worklistShares)
                            {
                                WorkTypes workTypes   = worklistShare.WorkTypes;
                                bool      needUnShare = false;
                                foreach (WorkType workType in workTypes)
                                {
                                    if (workType.Name == "TaskDelegationWork_" + taskDelegation.Id.ToString())
                                    {
                                        needUnShare = true;
                                        break;
                                    }
                                }

                                if (needUnShare)
                                {
                                    k2Con.UnShare(worklistShare);
                                }
                            }

                            k2Con.SetUserStatus(UserStatuses.Available);

                            string queryUpdate = "UPDATE [dbo].[TaskDelegation] SET";
                            queryUpdate = queryUpdate + " [IsActive] = 0";
                            if (!taskDelegation.IsCanceled)
                            {
                                queryUpdate = queryUpdate + ", [IsExpired] = 1";
                            }
                            queryUpdate = queryUpdate + ", [IsEndedInK2] = 1";
                            queryUpdate = queryUpdate + " WHERE [Id] = @Id";

                            using (SqlCommand cmd = con.CreateCommand())
                            {
                                cmd.CommandType = CommandType.Text;
                                cmd.CommandText = queryUpdate;
                                cmd.Parameters.Add(this.NewSqlParameter("Id", SqlDbType.BigInt, taskDelegation.Id));

                                cmd.ExecuteNonQuery();
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        innerEx = ex;
                    }
                }

                string queryUpdateSkipped = "[dbo].[TaskDelegation_UpdateSkipped_SP]";

                try
                {
                    using (SqlCommand cmd = con.CreateCommand())
                    {
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.CommandText = queryUpdateSkipped;
                        cmd.ExecuteNonQuery();
                    }
                }
                catch (Exception ex)
                {
                    innerEx = ex;
                }

                if (innerEx != null)
                {
                    throw new Exception("An error occured. " + innerEx.Message, innerEx);
                }

                con.Close();
            }
        }
        // Example from page - http://help.k2.com/onlinehelp/k2blackpearl/DevRef/4.6.9/default.htm#How_to_set_a_users_Out_of_Office_Status.html%3FTocPath%3DRuntime%2520APIs%2520and%2520Services%7CWorkflow%7CWorkflow%2520Client%2520API%7CWorkflow%2520Client%2520API%2520Samples%7C_____10
        /// <summary>
        /// Add OOF share for current user
        /// </summary>
        private void AddOutOfOffice()
        {
            string destinationUser = base.GetStringProperty(Constants.SOProperties.OutOfOffice.DestinationUser);

            ServiceObject serviceObject = base.ServiceBroker.Service.ServiceObjects[0];

            serviceObject.Properties.InitResultTable();
            DataTable results = base.ServiceBroker.ServicePackage.ResultTable;


            using (Connection k2Con = this.ServiceBroker.K2Connection.GetWorkflowClientConnection())
            {
                WorklistShares wsColl = k2Con.GetCurrentSharingSettings(ShareType.OOF);

                //  Throw error if multiple configurations (WorklistShare objects) detected, as this method cannot support that
                if (wsColl.Count > 1)
                {
                    throw new ApplicationException(Resources.MultipleOOFConfigurations);
                }
                else if (wsColl.Count == 1) //  If configuration exist already, add to it
                {
                    WorklistShare worklistshare = wsColl[0];
                    int           capacity      = worklistshare.WorkTypes[0].Destinations.Count;

                    string[] existingDestinations = new string[capacity];

                    for (int i = 0; i < capacity; i++)
                    {
                        existingDestinations[i] = worklistshare.WorkTypes[0].Destinations[i].Name.ToUpper().Trim();
                    }

                    if (Array.IndexOf(existingDestinations, destinationUser.ToUpper().Trim()) == -1)
                    {
                        worklistshare.WorkTypes[0].Destinations.Add(new Destination(destinationUser, DestinationType.User));
                    }

                    bool result = k2Con.ShareWorkList(worklistshare);

                    DataRow dr = results.NewRow();
                    dr[Constants.SOProperties.OutOfOffice.DestinationUser] = destinationUser;
                    results.Rows.Add(dr);;
                }
                else   // New user, create configuration for OOF
                {
                    // ALL Work that remains which does not form part of any "WorkTypeException" Filter
                    WorklistCriteria worklistcriteria = new WorklistCriteria();
                    worklistcriteria.Platform = "ASP";

                    // Send ALL Work based on the above Filter to the following User
                    Destinations worktypedestinations = new Destinations();
                    worktypedestinations.Add(new Destination(destinationUser, DestinationType.User));

                    // Link the filters and destinations to the Work
                    WorkType worktype = new WorkType("MyWork_" + k2Con.User.FQN, worklistcriteria, worktypedestinations);

                    WorklistShare worklistshare = new WorklistShare();
                    worklistshare.ShareType = ShareType.OOF;
                    worklistshare.WorkTypes.Add(worktype);

                    bool result = k2Con.ShareWorkList(worklistshare);
                    k2Con.SetUserStatus(UserStatuses.Available);

                    DataRow dr = results.NewRow();
                    dr[Constants.SOProperties.OutOfOffice.DestinationUser] = destinationUser;
                    results.Rows.Add(dr);
                }

                k2Con.Close();
            }
        }
Exemplo n.º 13
0
        private void AddOutOfOffice()
        {
            string userFQN         = base.GetStringProperty(Constants.SOProperties.OutOfOffice.UserFQN, true);
            string destinationUser = base.GetStringProperty(Constants.SOProperties.OutOfOffice.DestinationUser, true);

            ServiceObject serviceObject = base.ServiceBroker.Service.ServiceObjects[0];

            serviceObject.Properties.InitResultTable();
            DataTable results = base.ServiceBroker.ServicePackage.ResultTable;

            WorkflowManagementServer mngServer = new WorkflowManagementServer();

            using (mngServer.CreateConnection())
            {
                mngServer.Open(BaseAPIConnectionString);

                WorklistShares wsColl = mngServer.GetCurrentSharingSettings(userFQN, ShareType.OOF);

                //  Throw error if multiple configurations (WorklistShare objects) detected, as this method cannot support that
                if (wsColl.Count > 1)
                {
                    throw new ApplicationException(Constants.ErrorMessages.MultipleOOFConfigurations);
                }

                //  If configuration exist already, add to it
                if (wsColl.Count == 1)
                {
                    WorklistShare worklistshare = wsColl[0];
                    worklistshare.WorkTypes[0].Destinations.Add(new Destination(destinationUser, DestinationType.User));
                    bool result = mngServer.ShareWorkList(userFQN, worklistshare);
                    if (!result)
                    {
                        throw new ApplicationException(Constants.ErrorMessages.FailedToSetOOF);
                    }
                    DataRow dr = results.NewRow();
                    dr[Constants.SOProperties.OutOfOffice.UserFQN]         = userFQN;
                    dr[Constants.SOProperties.OutOfOffice.DestinationUser] = destinationUser;

                    results.Rows.Add(dr);;
                }
                // New user, create configuration for OOF
                else
                {
                    // ALL Work that remains which does not form part of any "WorkTypeException" Filter
                    WorklistCriteria worklistcriteria = new WorklistCriteria();
                    worklistcriteria.Platform = "ASP";

                    // Send ALL Work based on the above Filter to the following User
                    Destinations worktypedestinations = new Destinations();
                    worktypedestinations.Add(new Destination(destinationUser, DestinationType.User));

                    // Link the filters and destinations to the Work
                    WorkType worktype = new WorkType("MyWork", worklistcriteria, worktypedestinations);

                    WorklistShare worklistshare = new WorklistShare();
                    worklistshare.ShareType = ShareType.OOF;
                    worklistshare.WorkTypes.Add(worktype);

                    bool result = mngServer.ShareWorkList(userFQN, worklistshare);
                    if (!result)
                    {
                        throw new ApplicationException(Constants.ErrorMessages.FailedToSetOOF);
                    }
                    result = mngServer.SetUserStatus(userFQN, UserStatuses.Available);
                    if (!result)
                    {
                        throw new ApplicationException(Constants.ErrorMessages.FailedToSetOOF);
                    }

                    DataRow dr = results.NewRow();
                    dr[Constants.SOProperties.OutOfOffice.UserFQN]         = userFQN;
                    dr[Constants.SOProperties.OutOfOffice.DestinationUser] = destinationUser;
                    results.Rows.Add(dr);
                }
            }
        }
Exemplo n.º 14
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);
        }