Exemplo n.º 1
0
        private static List<TaskActivityDC> SaveStoreLibraryAndTaskActivity(StoreLibraryAndTaskActivityRequestDC request)
        {
            List<TaskActivityDC> reply = new List<TaskActivityDC>();
            reply.Add(new TaskActivityDC());
            StatusReplyDC status = new StatusReplyDC();
            var publishingState = String.Empty;
            Tuple<bool, string> dependencyCheckResult;  // true/false for if the dependencies pass, and a string error message if there are problems
            TaskActivityDC activityDC = new TaskActivityDC()
            {
                Incaller = request.Incaller,
                IncallerVersion = request.IncallerVersion,
                Activity = new StoreActivitiesDC()
                {
                    Incaller = request.Incaller,
                    IncallerVersion = request.IncallerVersion,
                    Locked = false,
                    LockedBy = null,
                }
            };
            Version nextVersion = null;

            request.ActivityLibrary.Incaller = request.Incaller;
            request.ActivityLibrary.IncallerVersion = request.IncallerVersion;

            //// Check if the library is in production first. If so bail.
            if (IsLibraryInProduction(request.ActivityLibrary))
            {
                status = SetUpReplyStatus(SprocValues.ACTIVITYLIBRARY_MARKED_FOR_PRODUCTION_ID, SprocValues.ACTIVITYLIBRARY_MARKED_FOR_PRODUCTION_MSG, Convert.ToString(Guid.Empty));
                return SetupErrorReply(reply, status);
            }

            if (request.EnforceVersionRules)
            {
                var checkReply = ActivityBusinessService.CheckActivityExists(request.TaskActivitiesList[0].Activity);

                if (checkReply.Errorcode == 0)
                {
                    bool exists = false;

                    if (bool.TryParse(checkReply.Output, out exists) && exists)
                    {
                        nextVersion = GetNextVersion(request.TaskActivitiesList[0].Activity, Environment.UserName);
                    }
                }

                var saRequest = ConvertStoreLibraryAndTaskActivityRequestDCToStoreLibraryAndActivitiesRequestDC(request);
                dependencyCheckResult = VersionHelper.CheckDependencyRules(saRequest);
                if (!dependencyCheckResult.Item1)
                    throw new VersionException(dependencyCheckResult.Item2, null);

                reply.Clear();
            }
            if (string.IsNullOrEmpty(request.ActivityLibrary.StatusName))
                throw new ValidationException(-1, "'Status Name' for Activity Library records cannot be null.");

            if (request.EnforceVersionRules)
            {
                foreach (var activity in request.TaskActivitiesList)
                {
                    activityDC.Activity.Name = activity.Activity.Name;
                    activityDC.Activity.Version = activity.Activity.OldVersion;

                    List<StoreActivitiesDC> existingRecords = Activities.StoreActivitiesGetByName(activityDC.Activity.Name, string.Empty);
                    if (existingRecords.Any())
                    {
                        //Clear the Store Activities lock
                        var lockReply = Activities.StoreActivitiesUpdateLock(activityDC.Activity, DateTime.Now);
                        if (lockReply.StatusReply.Errorcode != 0)
                        {
                            status = SetUpReplyStatus(lockReply.StatusReply.Errorcode, lockReply.StatusReply.ErrorMessage, Convert.ToString(Guid.Empty));
                            return SetupErrorReply(reply, status);
                        }
                    }
                }

                if (nextVersion != null)
                {
                    request.ActivityLibrary.VersionNumber = nextVersion.ToString();
                    request.TaskActivitiesList[0].Activity.Version = nextVersion.ToString();
                    request.StoreActivityLibraryDependenciesGroupsRequestDC.Version = nextVersion.ToString();
                }
            }

            // add the entires
            // Create the ActivityLibrary
            var activityLibraryDCCreate = request.ActivityLibrary;
            activityLibraryDCCreate.Incaller = request.Incaller;
            activityLibraryDCCreate.IncallerVersion = request.IncallerVersion;
            ActivityLibraryDC createALreply = ActivityLibrary.ActivityLibraryCreateOrUpdate(activityLibraryDCCreate);
            if (createALreply.StatusReply.Errorcode != 0)
            {
                status = SetUpReplyStatus(createALreply.StatusReply.Errorcode, createALreply.StatusReply.ErrorMessage, Convert.ToString(Guid.Empty));
                return SetupErrorReply(reply, status);
            }
            // Store the store activities
            foreach (var activity in request.TaskActivitiesList)
            {
                activity.Incaller = request.Incaller;
                activity.IncallerVersion = request.IncallerVersion;
                activity.Activity.Incaller = request.Incaller;
                activity.Activity.IncallerVersion = request.IncallerVersion;
                activity.Activity.ActivityLibraryName = request.ActivityLibrary.Name;
                activity.Activity.ActivityLibraryVersion = request.ActivityLibrary.VersionNumber;
                activity.Activity.AuthGroupName = request.ActivityLibrary.AuthGroupName;
                activity.Activity.Locked = true;
                activity.Activity.LockedBy = request.InUpdatedByUserAlias;
                StoreActivitiesDC createSAreply = null;
                createSAreply = Activities.StoreActivitiesCreateOrUpdate(activity.Activity);
                if (createSAreply.StatusReply.Errorcode != 0)
                {
                    status = SetUpReplyStatus(createSAreply.StatusReply.Errorcode, createSAreply.StatusReply.ErrorMessage, Convert.ToString(Guid.Empty));
                    return SetupErrorReply(reply, status);
                }
                activity.ActivityId = createSAreply.Id;

                TaskActivityDC createTAreply = TaskActivityBusinessService.TaskActivityCreateOrUpdate(activity);
                if (createTAreply.StatusReply.Errorcode != 0)
                {
                    status = SetUpReplyStatus(createTAreply.StatusReply.Errorcode, createTAreply.StatusReply.ErrorMessage, Convert.ToString(Guid.Empty));
                    return SetupErrorReply(reply, status);
                }
                createTAreply.Activity = createSAreply;
                reply.Add(createTAreply);
            }
            // Create the ActivityLibrary dependency list

            // store the 1st entry
            // create the head list
            try
            {
                if (request.StoreActivityLibraryDependenciesGroupsRequestDC != null)
                {
                    if (request.StoreActivityLibraryDependenciesGroupsRequestDC.List != null &&
                        request.StoreActivityLibraryDependenciesGroupsRequestDC.List.Count > 0)
                    {
                        var headList = new ActivityLibraryDependenciesListHeadCreateOrUpdateRequestDC();

                        headList.Name = request.ActivityLibrary.Name;
                        headList.Version = request.ActivityLibrary.VersionNumber;
                        headList.Incaller = request.Incaller;
                        headList.IncallerVersion = request.IncallerVersion;
                        headList.InInsertedByUserAlias = request.InInsertedByUserAlias;
                        headList.InUpdatedByUserAlias = request.InUpdatedByUserAlias;
                        StatusReplyDC replyHeadCreate = ActivityLibraryDependency.ActivityLibraryDependenciesListHeadCreateOrUpdate(headList);

                        if (replyHeadCreate.Errorcode != 0)
                            return SetupErrorReply(reply, status);

                        StatusReplyDC ActivityLibraryDependenciesCreateOrUpdateStatusReply = null;
                        ActivityLibraryDependenciesCreateOrUpdateStatusReply =
                            ActivityLibraryDependenciesCreateOrUpdate(
                                                                        request.StoreActivityLibraryDependenciesGroupsRequestDC.Name,
                                                                        request.StoreActivityLibraryDependenciesGroupsRequestDC.Version,
                                                                        request.StoreActivityLibraryDependenciesGroupsRequestDC.List,
                                                                        request.Incaller,
                                                                        request.IncallerVersion,
                                                                        request.InInsertedByUserAlias,
                                                                        request.InUpdatedByUserAlias
                                                                      );
                        if (ActivityLibraryDependenciesCreateOrUpdateStatusReply.Errorcode != 0)
                            return SetupErrorReply(reply, ActivityLibraryDependenciesCreateOrUpdateStatusReply);
                    }
                }
            }
            catch (TransactionAbortedException tex)
            {
                status = SetUpReplyStatus(SprocValues.GENERIC_CATCH_ID,
                                         "[UploadLibraryAndTaskActivities]" + tex.Message,
                                         Convert.ToString(Guid.Empty));
                return SetupErrorReply(reply, status);
            }
            catch (Exception ex)
            {
                status = SetUpReplyStatus(SprocValues.GENERIC_CATCH_ID,
                                         "[UploadLibraryAndTaskActivities]" + ex.Message,
                                         Convert.ToString(Guid.Empty));
                return SetupErrorReply(reply, status);
            }
            return reply;
        }
Exemplo n.º 2
0
 public TaskActivityDC TaskActivityUpdateStatus(TaskActivityDC request)
 {
     //// Eliminate with validation pipeline implementation
     if (request == null)
     {
         var reply = new TaskActivityDC();
         reply.StatusReply = SetupStatusreplyNullRequestError();
         return reply;
     }
     return TaskActivityBusinessService.TaskActivityUpdateStatus(request);
 }