예제 #1
0
        /// <summary>
        /// This method checks if Upload method should be executed.
        /// </summary>
        /// <param name="workflow">WorkflowItem to save</param>
        /// <returns>true if pre-condition check passed</returns>
        public static Tuple<bool, StoreActivitiesDC> CheckCanUpload(IWorkflowsQueryService proxy, WorkflowItem workflow)
        {
            StoreActivitiesDC workflowDC = DataContractTranslator.ActivityItemToStoreActivitiyDC(workflow);
            var workflowList = proxy.StoreActivitiesGetByName(workflowDC);

            //a new created workflow with duplicated name to be saved.
            if ((!workflow.IsOpenFromServer || workflow.Name != workflow.OriginalName) && workflowList.Count > 0)
            {
                MessageBoxService.CannotSaveDuplicatedNameWorkflow(workflow.Name);
                return new Tuple<bool, StoreActivitiesDC>(false, null);
            }

            StoreActivitiesDC latestWorkflow = workflowList.FirstOrDefault();
            bool shouldContinue = false;
            StoreActivitiesDC workflowToOpen = null;

            if (latestWorkflow == null || latestWorkflow.InsertedDateTime <= workflowDC.UpdatedDateTime)
            {
                if (AuthorizationService.IsAdministrator(AuthorizationService.CurrentPrincipalFunc())
                    || (latestWorkflow == null)
                    || (workflowDC.LockedBy == Environment.UserName))
                {
                    shouldContinue = true;
                }
                else
                {
                    MessageBoxService.CannotSaveLockedActivity();
                    shouldContinue = false;
                }
            }
            else // there is a new version saved on server after user checked current one out
            {
                if (AuthorizationService.IsAdministrator(AuthorizationService.CurrentPrincipalFunc()))
                {
                    if (MessageBoxService.CreateNewActivityOnSaving() == MessageBoxResult.Yes)
                    {
                        shouldContinue = true;
                    }
                }
                else
                {
                    if (MessageBoxService.DownloadNewActivityOnSaving() == MessageBoxResult.Yes)
                    {
                        workflowToOpen = latestWorkflow;
                    }
                }
            }
            return new Tuple<bool, StoreActivitiesDC>(shouldContinue, workflowToOpen);
        }