private const string ProductionStatusName = "Production"; // This is the string that the StatusCode table will have for items that have been moved to production. #endregion Fields #region Methods /// <summary> /// Gets the ActivityLibrary and associated StoreActivity entries as a unit. A transaction is used here /// to eliminate getting caught in the middle of a multi row update. /// </summary> /// <param name="request">GetLibraryAndActivitiesDC object</param> /// <returns>List<GetLibraryAndActivitiesDC> object</returns> public static List<GetLibraryAndActivitiesDC> GetLibraryAndActivities(GetLibraryAndActivitiesDC request) { var reply = new List<GetLibraryAndActivitiesDC>(); var statusReply = new StatusReplyDC(); //// ActivityLibraryDC alDC = request.ActivityLibrary; List<ActivityLibraryDC> activityLibraryDClist = null; using (var transaction = new TransactionScope()) { try { //// Get StoreActivities reply = ActivityRepositoryService.GetActivitiesByActivityLibrary(request, true); if (reply[0].StatusReply.Errorcode != 0) throw new Exception(reply[0].StatusReply.ErrorMessage); //// Get ActivityLibrary activityLibraryDClist = ActivityLibraryRepositoryService.GetActivityLibraries(request.ActivityLibrary, true); if (activityLibraryDClist.Count == 1 && activityLibraryDClist[0].StatusReply.Errorcode == 0) reply[0].ActivityLibrary = activityLibraryDClist[0]; else throw new FaultException(); transaction.Complete(); reply[0].StatusReply = statusReply; } catch (TransactionAbortedException) { statusReply.ErrorMessage = reply[0].StatusReply.ErrorMessage; statusReply.Errorcode = reply[0].StatusReply.Errorcode; } catch (Exception) { statusReply.ErrorMessage = reply[0].StatusReply.ErrorMessage; statusReply.Errorcode = reply[0].StatusReply.Errorcode; } } return reply; }
private static List<TaskActivityDC> SetupErrorReply(List<TaskActivityDC> reply, StatusReplyDC status) { reply.Clear(); reply.Add(new TaskActivityDC()); reply[0].StatusReply = status; return reply; }
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; }
public static StoreActivityLibrariesDependenciesDC StoreActivityLibraryDependencyList(StoreActivityLibrariesDependenciesDC request) { var statusReply = new StatusReplyDC(); //// StoreDependenciesDependentActiveLibrary dal = null; var storeActivityLibrariesDependenciesDC = new StoreActivityLibrariesDependenciesDC(); storeActivityLibrariesDependenciesDC.StoreDependenciesDependentActiveLibraryList = new List<StoreDependenciesDependentActiveLibrary>(); storeActivityLibrariesDependenciesDC.StoreDependenciesRootActiveLibrary = request.StoreDependenciesRootActiveLibrary; StoreActivityLibrariesDependenciesDC reply = null; using (var transaction = new TransactionScope()) { try { if (request == null) { statusReply.Errorcode = SprocValues.REQUEST_OBJECT_IS_NULL_ID; statusReply.ErrorMessage = SprocValues.REQUEST_OBJECT_IS_NULL_MSG; throw new Exception(statusReply.ErrorMessage); } if (request.StoreDependenciesRootActiveLibrary == null) { statusReply.Errorcode = SprocValues.REQUEST_ACTION_STORE_DEPENDENCIES_ROOTACTIVITY_LIBRARY_IS_NULL_ID; statusReply.ErrorMessage = SprocValues.REQUEST_ACTION_STORE_DEPENDENCIES_ROOTACTIVITY_LIBRARY_IS_NULL_MSG; throw new Exception(statusReply.ErrorMessage); } if (request.StoreDependenciesDependentActiveLibraryList == null) { statusReply.Errorcode = SprocValues.REQUEST_ACTION_STORE_DEPENDENCIES_DEPENDENT_ACTIVITY_LIBRARY_IS_NULL_ID; statusReply.ErrorMessage = SprocValues.REQUEST_ACTION_STORE_DEPENDENCIES_DEPENDENT_ACTIVITY_LIBRARY_IS_NULL_MSG; throw new Exception(statusReply.ErrorMessage); } storeActivityLibrariesDependenciesDC.StoreDependenciesRootActiveLibrary = request.StoreDependenciesRootActiveLibrary; //// CreateOrUpdate ActivityLibraryDependencies foreach (var dependentLibrary in request.StoreDependenciesDependentActiveLibraryList) { storeActivityLibrariesDependenciesDC.StoreDependenciesDependentActiveLibraryList.Add( dependentLibrary); storeActivityLibrariesDependenciesDC.Incaller = request.Incaller; storeActivityLibrariesDependenciesDC.IncallerVersion = request.IncallerVersion; storeActivityLibrariesDependenciesDC.InsertedByUserAlias = request.InsertedByUserAlias; storeActivityLibrariesDependenciesDC.UpdatedByUserAlias = request.UpdatedByUserAlias; reply = ActivityLibraryDependency.StoreActivityLibraryDependenciesCreateOrUpdate(storeActivityLibrariesDependenciesDC); if (reply.StatusReply.Errorcode != 0) throw new Exception(reply.StatusReply.ErrorMessage); storeActivityLibrariesDependenciesDC.StoreDependenciesDependentActiveLibraryList.Remove(dependentLibrary); } } catch (TransactionAbortedException) { //// TODO temp removal of faults tex case //// throw new FaultException(new FaultReason(Convert.ToString(reply.StatusReply.Errorcode) + "|" + reply.StatusReply.ErrorMessage)); statusReply.ErrorMessage = reply.StatusReply.ErrorMessage; statusReply.Errorcode = reply.StatusReply.Errorcode; } catch (Exception) { //// TODO temp removal of faults ex case //// throw new FaultException(new FaultReason(Convert.ToString(reply.StatusReply.Errorcode) + "|" + reply.StatusReply.ErrorMessage)); statusReply.ErrorMessage = reply.StatusReply.ErrorMessage; statusReply.Errorcode = reply.StatusReply.Errorcode; } transaction.Complete(); } return reply; }
/// <summary> /// Sets up the StatusReply object /// </summary> /// <param name="errorCode">errorCode value</param> /// <param name="errorMessager">errorMessager string</param> /// <param name="errorGuid">errorGuid object</param> /// <returns>StatusReplyDC object</returns> public static StatusReplyDC SetUpReplyStatus(int errorCode, string errorMessager, string errorGuid) { var reply = new StatusReplyDC(); reply.Errorcode = errorCode; reply.ErrorGuid = errorGuid; reply.ErrorMessage = errorMessager; return reply; }
/// <summary> /// Populates the statusResult object with the request is null ErrorCode and ErrorMessage /// </summary> /// <returns>StatusReplyDC object</returns> private static CWF.DataContracts.StatusReplyDC SetupStatusreplyNullRequestError() { var reply = new StatusReplyDC(); reply.Errorcode = SprocValues.REQUEST_OBJECT_IS_NULL_ID; reply.ErrorMessage = SprocValues.REQUEST_OBJECT_IS_NULL_MSG; return reply; }
/// <summary> /// Write an event to the log. /// </summary> /// <param name="eventSourceName">Event source name</param> /// <param name="eventId">Event id</param> /// <param name="eventLevel">Severity level of the event</param> /// <param name="eventCategory">Event category. Possible values are in EventCategory enumeration - Administrative, Operational, Analytic, Debug, APIUsage</param> /// <param name="description">The list of messages to be logged.</param> /// <returns>a Status Reply object suitable for being returned from the WCF service, giving info about the event written</returns> private static StatusReplyDC WriteEvent(string eventSourceName, int eventId, EventLogEntryType eventLevel, EventCategory eventCategory, object[] insertionStrings) { StatusReplyDC result = new StatusReplyDC { Errorcode = eventId, ErrorGuid = string.Format("{0}\r\n\r\n{1}", SprocValues.LOG_LOCATION + ":" + eventSourceName, insertionStrings.ToList() .Aggregate((first, last) => string.Format("{0}\r\n{1}", first, last)) .ToString()), }; LogClient.Source = SprocValues.DAL_CALLER_INFO; LogClient.Log = SprocValues.LOG_LOCATION; LogClient.WriteEvent(new EventInstance(eventId, (int)eventCategory, eventLevel), insertionStrings); return result; }