public WorkflowFileInfo(string title, bool isDirty, WorkflowType workflowType, string filePath) { Title = title; IsDirty = isDirty; WorkflowType = workflowType; FilePath = filePath; }
/// <summary> /// Initializes a new instance of the <see cref="WorkflowInfo" /> class. /// </summary> /// <param name="Mapping">The mapping.</param> /// <param name="Function">The function.</param> /// <param name="Version">The version.</param> /// <param name="ReturnValues">The return values.</param> public WorkflowInfo(string Mapping, WorkflowType Function, int Version, dynamic ReturnValues) { this.Mapping = Mapping; this.Function = Function; this.Version = Version; this.ReturnValues = ReturnValues; this.Continue = true; }
public WorkItem(int jobId, int? parentId, int order, WorkflowType type, string path) { JobId = jobId; ParentId = parentId; Order = order; Type = type; WorkflowPath = path; Status = WorkItemStatus.Created; }
/// <summary> /// Activates a new <see cref="Rock.Model.Workflow"/> instance. /// </summary> /// <param name="workflowType">The <see cref="Rock.Model.WorkflowType"/> to be activated.</param> /// <param name="name">A <see cref="System.String"/> representing the name of the <see cref="Rock.Model.Workflow"/> instance.</param> /// <param name="currentPersonId">A <see cref="System.Int32"/> representing the PersonId of the <see cref="Rock.Model.Person"/> who is activating the /// <see cref="Rock.Model.Workflow"/> instance; this will be null if it was completed by the anonymous user.</param> /// <returns>The activated <see cref="Rock.Model.Workflow"/> instance</returns> public Workflow Activate( WorkflowType workflowType, string name, int? currentPersonId ) { var workflow = Workflow.Activate( workflowType, name ); this.Add( workflow, currentPersonId ); this.Save( workflow, currentPersonId ); return workflow; }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); try { var htmlContentItemID = -1; var htmlContent = _htmlTextController.GetTopHtmlText(ModuleId, false, WorkflowID); if ((htmlContent != null)) { htmlContentItemID = htmlContent.ItemID; } if (!Page.IsPostBack) { var workflowStates = _workflowStateController.GetWorkflowStates(WorkflowID); var maxVersions = _htmlTextController.GetMaximumVersionHistory(PortalId); var userCanEdit = UserInfo.IsSuperUser || PortalSecurity.IsInRole(PortalSettings.AdministratorRoleName) || UserInfo.UserID == LockedByUserID; lblMaxVersions.Text = maxVersions.ToString(); dgVersions.PageSize = Math.Min(Math.Max(maxVersions, 5), 10); //min 5, max 10 switch (workflowStates.Count) { case 1: CurrentWorkflowType = WorkflowType.DirectPublish; break; case 2: CurrentWorkflowType = WorkflowType.ContentStaging; break; } if (htmlContentItemID != -1) { DisplayContent(htmlContent); DisplayPreview(htmlContent); } else { DisplayInitialContent(workflowStates[0] as WorkflowStateInfo); } divPublish.Visible = CurrentWorkflowType != WorkflowType.DirectPublish; DisplayVersions(); } } catch (Exception exc) { Exceptions.ProcessModuleLoadException(this, exc); } }
/// <summary> /// Creates a new workflow state instance. /// </summary> /// <param name="stateId">The (unique) id of the new state.</param> /// <param name="name">A human-readable name for the new state.</param> /// <param name="displayLabel">A human-readable label to be used in the GUI for the new state.</param> /// <param name="isTemporary">If set to <c>true</c>, this workflow state will only be temporary located on the /// workflow navigation stack, until another workflow state of type <see cref="Workflow.WorkflowType.Workflow"/> /// is pushed onto it.</param> /// <param name="mainScreen">For states of type <see cref="Workflow.WorkflowType.Workflow"/>, this is the name of the /// automatically loaded starting screen of this workflow state. For states of type <see cref="Workflow.WorkflowType.Dialog"/>, /// this is the name of the dialog to be shown.</param> /// <param name="inheritMenu">Whether the menu items should be inherited from the last workflow state.</param> /// <param name="isTransient">Whether the new state is a transient state. See the docs of the /// <see cref="IsTransient"/> property.</param> /// <param name="workflowModelId">The id of the workflow model which attends the workflow state.</param> /// <param name="type">The type of the new workflow state.</param> public WorkflowState(Guid stateId, string name, string displayLabel, bool isTemporary, string mainScreen, bool inheritMenu, bool isTransient, Guid? workflowModelId, WorkflowType type) { _stateId = stateId; _name = name; _displayLabel = displayLabel; _isTemporary = isTemporary; _mainScreen = mainScreen; _inheritMenu = inheritMenu; _isTransient = isTransient; _workflowModelId = workflowModelId; _type = type; }
public void Can_Get_Past_Tense_Type_Description(WorkflowType type, int?days, string expected) { DateTime?date = null; if (days.HasValue) { date = DateTime.Now.AddDays(days.Value); } string description = type.DescriptionPastTense(date); Assert.StartsWith(expected, description); }
/// <summary> /// Returns breadcrumbs specific to the block that should be added to navigation /// based on the current page reference. This function is called during the page's /// oninit to load any initial breadcrumbs. /// </summary> /// <param name="pageReference">The <see cref="Rock.Web.PageReference" />.</param> /// <returns> /// A <see cref="System.Collections.Generic.List{BreadCrumb}" /> of block related <see cref="Rock.Web.UI.BreadCrumb">BreadCrumbs</see>. /// </returns> public override List<BreadCrumb> GetBreadCrumbs( Rock.Web.PageReference pageReference ) { var breadCrumbs = new List<BreadCrumb>(); var workflowTypeId = PageParameter( "WorkflowTypeId" ).AsInteger(); _workflowType = new WorkflowTypeService( new RockContext() ).Get( workflowTypeId ); if ( _workflowType != null ) { breadCrumbs.Add( new BreadCrumb( _workflowType.Name, pageReference ) ); } return breadCrumbs; }
/// <summary> /// Creates a new workflow state instance. /// </summary> /// <param name="stateId">The (unique) id of the new state.</param> /// <param name="name">A human-readable name for the new state.</param> /// <param name="displayLabel">A human-readable label to be used in the GUI for the new state.</param> /// <param name="isTemporary">If set to <c>true</c>, this workflow state will only be temporary located on the /// workflow navigation stack, until another workflow state of type <see cref="Workflow.WorkflowType.Workflow"/> /// is pushed onto it.</param> /// <param name="mainScreen">For states of type <see cref="Workflow.WorkflowType.Workflow"/>, this is the name of the /// automatically loaded starting screen of this workflow state. For states of type <see cref="Workflow.WorkflowType.Dialog"/>, /// this is the name of the dialog to be shown.</param> /// <param name="inheritMenu">Whether the menu items should be inherited from the last workflow state.</param> /// <param name="isTransient">Whether the new state is a transient state. See the docs of the /// <see cref="IsTransient"/> property.</param> /// <param name="workflowModelId">The id of the workflow model which attends the workflow state.</param> /// <param name="type">The type of the new workflow state.</param> public WorkflowState(Guid stateId, string name, string displayLabel, bool isTemporary, string mainScreen, bool inheritMenu, bool isTransient, Guid?workflowModelId, WorkflowType type) { _stateId = stateId; _name = name; _displayLabel = displayLabel; _isTemporary = isTemporary; _mainScreen = mainScreen; _inheritMenu = inheritMenu; _isTransient = isTransient; _workflowModelId = workflowModelId; _type = type; }
public ActionResult CreateWorkflowType(WorkflowType workflowtype) { if (ModelState.IsValid) { ViewData["WorkflowTypeID"] = workflowtype.WorkflowTypeID; ViewData["Name"] = workflowtype.Name; ViewData["requirements"] = workflowtype.Requirements; db.Types.Add(workflowtype); db.SaveChanges(); return(RedirectToAction("Index")); } return(View()); }
/// <summary> /// Raises the <see cref="E:System.Web.UI.Control.Init" /> event. /// </summary> /// <param name="e">An <see cref="T:System.EventArgs" /> object that contains the event data.</param> protected override void OnInit(EventArgs e) { base.OnInit(e); int workflowTypeId = 0; workflowTypeId = PageParameter("WorkflowTypeId").AsInteger(); _workflowType = new WorkflowTypeService(new RockContext()).Get(workflowTypeId); if (_workflowType != null) { pnlWorkflowTypeSelect.Visible = false; gfWorkflows.ApplyFilterClick += gfWorkflows_ApplyFilterClick; gfWorkflows.DisplayFilterValue += gfWorkflows_DisplayFilterValue; // this event gets fired after block settings are updated. it's nice to repaint the screen if these settings would alter it this.BlockUpdated += Block_BlockUpdated; this.AddConfigurationUpdateTrigger(upnlSettings); gWorkflows.DataKeyNames = new string[] { "Id" }; gWorkflows.GridRebind += gWorkflows_GridRebind; gWorkflows.Actions.ShowExcelExport = false; gWorkflows.Actions.ShowMergeTemplate = false; LinkButton btnBulk = new LinkButton { Text = "<i class='fa fa-truck fa-fw'></i>", CssClass = "btn-bulk-update btn btn-default btn-sm" }; btnBulk.Click += Actions_BulkUpdateClick; gWorkflows.Actions.Controls.Add(btnBulk); if (!string.IsNullOrWhiteSpace(_workflowType.WorkTerm)) { gWorkflows.RowItemText = _workflowType.WorkTerm; lGridTitle.Text = _workflowType.WorkTerm.Pluralize(); } RockPage.PageTitle = _workflowType.Name; if (!string.IsNullOrWhiteSpace(_workflowType.IconCssClass)) { lHeadingIcon.Text = string.Format("<i class='{0}'></i>", _workflowType.IconCssClass); } } else { pnlWorkflowList.Visible = false; } }
public ActionResult DeleteWorkflowType(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } WorkflowType type = db.Types.Find(id); if (type == null) { return(HttpNotFound()); } return(View(type)); }
public EditWorkflow(MainWindow pMainWindow) { InitializeComponent(); this._MainWindow = pMainWindow; this._MainWindow.ErrorOnPage = false; this._MainWindow.RedoFlowRequired = false; this._MainWindow.Policy._PolicyType = WDAC_Policy.PolicyType.Edit; this.Policy = this._MainWindow.Policy; this.Log = this._MainWindow.Log; this.Log.AddInfoMsg("==== Edit Workflow Page Initialized ===="); this.Workflow = WorkflowType.Edit; // Edit xml is default in the UI this.SelectedLevel = RuleLevel.None; }
/// <summary> /// Returns breadcrumbs specific to the block that should be added to navigation /// based on the current page reference. This function is called during the page's /// oninit to load any initial breadcrumbs. /// </summary> /// <param name="pageReference">The <see cref="Rock.Web.PageReference" />.</param> /// <returns> /// A <see cref="System.Collections.Generic.List{BreadCrumb}" /> of block related <see cref="Rock.Web.UI.BreadCrumb">BreadCrumbs</see>. /// </returns> public override List <BreadCrumb> GetBreadCrumbs(Rock.Web.PageReference pageReference) { var breadCrumbs = new List <BreadCrumb>(); var workflowTypeId = PageParameter("WorkflowTypeId").AsInteger(); _workflowType = new WorkflowTypeService(new RockContext()).Get(workflowTypeId); if (_workflowType != null) { breadCrumbs.Add(new BreadCrumb(_workflowType.Name, pageReference)); } return(breadCrumbs); }
/// <summary> /// Initializes a new instance of the <see cref="WorkflowNavigationWorkflowType" /> class. /// </summary> /// <param name="workflowType">Type of the workflow.</param> /// <param name="canManage">if set to <c>true</c> [can manage].</param> /// <param name="canViewList">if set to <c>true</c> [can view list].</param> public WorkflowNavigationWorkflowType(WorkflowType workflowType, bool canManage, bool canViewList) { Id = workflowType.Id; Name = workflowType.Name; Description = workflowType.Description; IconCssClass = workflowType.IconCssClass; WorkTerm = workflowType.WorkTerm; HasForms = workflowType.HasActiveForms; HighlightColor = string.Empty; CanManage = canManage; CanViewList = canViewList; IsActive = workflowType.IsActive == true; }
public List <object> GetItems(string folder, string name) { List <object> retVal = new List <object>(); if (String.IsNullOrEmpty(name)) { retVal = new List <object>(Configuration.GetInstance().WorkflowTypes.Cast <object>()); } else { retVal.Add(WorkflowType.GetByName(name)); } return(retVal); }
public async Task DeleteAsync(WorkflowType workflowType) { // Delete workflows first. var workflows = await _session.Query <Workflow, WorkflowIndex>(x => x.WorkflowTypeId == workflowType.WorkflowTypeId).ListAsync(); foreach (var workflow in workflows) { _session.Delete(workflow); } // Then delete the workflow type. _session.Delete(workflowType); var context = new WorkflowTypeDeletedContext(workflowType); await _handlers.InvokeAsync((handler, context) => handler.DeletedAsync(context), context, _logger); }
/// <summary> /// Tries to acquire a lock before starting an instance of this workflow type, if it is /// a singleton or if the event is exclusive, otherwise returns true with a null locker. /// </summary> public static Task <(ILocker locker, bool locked)> TryAcquireWorkflowTypeLockAsync( this IDistributedLock distributedLock, WorkflowType workflowType, bool isExclusiveEvent = false) { if (workflowType.IsSingleton || isExclusiveEvent) { return(distributedLock.TryAcquireLockAsync( "WFT_" + workflowType.WorkflowTypeId + "_LOCK", TimeSpan.FromMilliseconds(20_000), TimeSpan.FromMilliseconds(20_000))); } return(Task.FromResult <(ILocker, bool)>((null, true))); }
public async Task <WorkflowType> Get(long Id) { WorkflowType WorkflowType = await DataContext.WorkflowType.Where(x => x.Id == Id).Select(x => new WorkflowType() { Id = x.Id, Code = x.Code, Name = x.Name, }).AsNoTracking().FirstOrDefaultAsync(); if (WorkflowType == null) { return(null); } return(WorkflowType); }
public static IEnumerable <WorkflowRoutesEntry> GetWorkflowTypeRoutesEntries(WorkflowType workflowType, IActivityLibrary activityLibrary) { return(workflowType.Activities.Where(x => x.IsStart && x.Name == HttpRequestFilterEvent.EventName).Select(x => { var activity = activityLibrary.InstantiateActivity <HttpRequestFilterEvent>(x); var entry = new WorkflowRoutesEntry { WorkflowId = workflowType.Id.ToString(), ActivityId = x.ActivityId, HttpMethod = activity.HttpMethod, RouteValues = activity.RouteValues }; return entry; })); }
public IRequest Marshall(DescribeWorkflowTypeRequest describeWorkflowTypeRequest) { IRequest request = new DefaultRequest(describeWorkflowTypeRequest, "AmazonSimpleWorkflow"); string target = "SimpleWorkflowService.DescribeWorkflowType"; request.Headers["X-Amz-Target"] = target; request.Headers["Content-Type"] = "application/x-amz-json-1.0"; using (StringWriter stringWriter = new StringWriter()) { JsonWriter writer = new JsonWriter(stringWriter); writer.WriteObjectStart(); if (describeWorkflowTypeRequest != null && describeWorkflowTypeRequest.IsSetDomain()) { writer.WritePropertyName("domain"); writer.Write(describeWorkflowTypeRequest.Domain); } if (describeWorkflowTypeRequest != null) { WorkflowType workflowType = describeWorkflowTypeRequest.WorkflowType; if (workflowType != null) { writer.WritePropertyName("workflowType"); writer.WriteObjectStart(); if (workflowType != null && workflowType.IsSetName()) { writer.WritePropertyName("name"); writer.Write(workflowType.Name); } if (workflowType != null && workflowType.IsSetVersion()) { writer.WritePropertyName("version"); writer.Write(workflowType.Version); } writer.WriteObjectEnd(); } } writer.WriteObjectEnd(); string snippet = stringWriter.ToString(); request.Content = System.Text.Encoding.UTF8.GetBytes(snippet); return(request); } }
private void LoadWorkflowType() { if (_rockContext == null) { _rockContext = new RockContext(); } if (_workflowService == null) { _workflowService = new WorkflowService(_rockContext); } if (_workflowTypeService == null) { _workflowTypeService = new WorkflowTypeService(_rockContext); } // Get the workflow type id (initial page request) if (!WorkflowTypeId.HasValue) { // Get workflow type set by attribute value Guid workflowTypeguid = GetAttributeValue("WorkflowType").AsGuid(); if (!workflowTypeguid.IsEmpty()) { _workflowType = _workflowTypeService.Get(workflowTypeguid); } // If an attribute value was not provided, check for query/route value if (_workflowType != null) { WorkflowTypeId = _workflowType.Id; ConfiguredType = true; } else { WorkflowTypeId = PageParameter("WorkflowTypeId").AsIntegerOrNull(); ConfiguredType = false; } } // Get the workflow type if (_workflowType == null && WorkflowTypeId.HasValue) { _workflowType = _workflowTypeService.Get(WorkflowTypeId.Value); } }
public Task SaveAsync(WorkflowType workflowType) { var isNew = workflowType.Id == 0; _session.Save(workflowType); if (isNew) { var context = new WorkflowTypeCreatedContext(workflowType); return(_handlers.InvokeAsync((handler, context) => handler.CreatedAsync(context), context, _logger)); } else { var context = new WorkflowTypeUpdatedContext(workflowType); return(_handlers.InvokeAsync((handler, context) => handler.UpdatedAsync(context), context, _logger)); } }
public Workflow NewWorkflow(WorkflowType workflowType, string correlationId = null) { var workflow = new Workflow { WorkflowTypeId = workflowType.WorkflowTypeId, Status = WorkflowStatus.Idle, State = JObject.FromObject(new WorkflowState { ActivityStates = workflowType.Activities.Select(x => x).ToDictionary(x => x.ActivityId, x => x.Properties) }), CorrelationId = correlationId, CreatedUtc = _clock.UtcNow }; workflow.WorkflowId = _workflowIdGenerator.GenerateUniqueId(workflow); return(workflow); }
public async Task SaveAsync(WorkflowType workflowType) { var isNew = workflowType.Id == 0; _session.Save(workflowType); if (isNew) { var context = new WorkflowTypeCreatedContext(workflowType); await _handlers.InvokeAsync(async x => await x.CreatedAsync(context), _logger); } else { var context = new WorkflowTypeUpdatedContext(workflowType); await _handlers.InvokeAsync(async x => await x.UpdatedAsync(context), _logger); } }
public async Task DeleteAsync(WorkflowType workflowType) { // TODO: Remove this when versioning is implemented. // Delete workflows first. var workflows = await _session.Query <Workflow, WorkflowIndex>(x => x.WorkflowTypeId == workflowType.WorkflowTypeId).ListAsync(); foreach (var workflow in workflows) { _session.Delete(workflow); } // Then delete the workflow type. _session.Delete(workflowType); var context = new WorkflowTypeDeletedContext(workflowType); await _handlers.InvokeAsync(async x => await x.DeletedAsync(context), _logger); }
public Response MakeRequest(WorkflowType selection) { string section = "Remove Order(s)"; Console.Clear(); Console.Title = $"{Utilities.ProgramTitle} - {section}"; Utilities.GenerateSeparator('=', Console.WindowWidth, ConsoleColor.Red); Console.SetCursorPosition((Console.WindowWidth - section.Length) / 2, Console.CursorTop); Console.WriteLine(section.Color("White")); Utilities.GenerateSeparator('=', Console.WindowWidth, ConsoleColor.Red); var request = new Request { Type = WorkflowType.Remove, Date = Utilities.GetDate("Order Date", false), OrderNumber = Utilities.GetNumber <int>("Order Number", new Regex(@"^\d{1,5}$")) }; IWorkflow flow = WorkflowFactory.Create(WorkflowType.Find); Response response = flow.Execute(request); if (response.Success) { Order removalTarget = response.Order; Utilities.PrintOrderDetails(removalTarget, WorkflowType.Remove); Console.WriteLine("Please confirm that you want to remove this order."); string polarOption = Utilities.GetString("(Y)es or (N)o", new Regex(@"^Y(es)?$|^N(o)?$", RegexOptions.IgnoreCase), false).ToUpper(); if (polarOption == "Y" || polarOption == "YES") { flow = WorkflowFactory.Create(selection); response = flow.Execute(request); } else { response.Success = false; response.Message = $"Order #{removalTarget.OrderNumber} removal cancelled. Ending workflow..."; return(response); } } return(response); }
public async Task <IActionResult> EditProperties(WorkflowTypePropertiesViewModel viewModel, int?id) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageWorkflows)) { return(Forbid()); } if (!ModelState.IsValid) { return(View(viewModel)); } var isNew = id == null; var workflowType = default(WorkflowType); if (isNew) { workflowType = new WorkflowType(); workflowType.WorkflowTypeId = _workflowTypeIdGenerator.GenerateUniqueId(workflowType); } else { workflowType = await _session.GetAsync <WorkflowType>(id.Value); if (workflowType == null) { return(NotFound()); } } workflowType.Name = viewModel.Name?.Trim(); workflowType.IsEnabled = viewModel.IsEnabled; workflowType.IsSingleton = viewModel.IsSingleton; workflowType.LockTimeout = viewModel.LockTimeout; workflowType.LockExpiration = viewModel.LockExpiration; workflowType.DeleteFinishedWorkflows = viewModel.DeleteFinishedWorkflows; await _workflowTypeStore.SaveAsync(workflowType); return(isNew ? RedirectToAction(nameof(Edit), new { workflowType.Id }) : Url.IsLocalUrl(viewModel.ReturnUrl) ? (IActionResult)this.Redirect(viewModel.ReturnUrl, true) : RedirectToAction(nameof(Index))); }
/// <summary> /// Populate the ddlSettingsSubmissionAttribute drop down with the Attributes available in /// the specified WorkflowType. /// </summary> /// <param name="workflowType">The WorkflowType whose Attributes should be populated.</param> protected void LoadSubmissionWorkflowAttributes(WorkflowType workflowType) { ddlSettingsSubmissionAttribute.Items.Clear(); ddlSettingsSubmissionAttribute.Items.Add(string.Empty); if (workflowType != null) { new AttributeService(new RockContext()) .GetByEntityTypeId(new Workflow().TypeId).AsQueryable() .Where(a => a.EntityTypeQualifierColumn.Equals("WorkflowTypeId", StringComparison.OrdinalIgnoreCase) && a.EntityTypeQualifierValue.Equals(workflowType.Id.ToString())) .OrderBy(a => a.Order) .ThenBy(a => a.Name) .ToList() .ForEach(a => ddlSettingsSubmissionAttribute.Items.Add(a.Name)); } }
internal static IEnumerable <WorkflowRoutesEntry> GetWorkflowRoutesEntries(WorkflowType workflowType, Workflow workflow, IActivityLibrary activityLibrary) { var awaitingActivityIds = workflow.BlockingActivities.Select(x => x.ActivityId).ToDictionary(x => x); return(workflowType.Activities.Where(x => x.Name == HttpRequestFilterEvent.EventName && awaitingActivityIds.ContainsKey(x.ActivityId)).Select(x => { var activity = activityLibrary.InstantiateActivity <HttpRequestFilterEvent>(x); var entry = new WorkflowRoutesEntry { WorkflowId = workflow.WorkflowId, ActivityId = x.ActivityId, HttpMethod = activity.HttpMethod, RouteValues = activity.RouteValues, }; return entry; })); }
/// <summary> /// Creates the control(s) necessary for prompting user for a new value /// </summary> /// <param name="configurationValues">The configuration values.</param> /// <param name="id"></param> /// <returns> /// The control /// </returns> public override Control EditControl(Dictionary <string, ConfigurationValue> configurationValues, string id) { ListControl editControl; editControl = new Rock.Web.UI.Controls.RockDropDownList { ID = id }; editControl.Items.Add(new ListItem()); IEnumerable <WorkflowActivityType> activityTypes = null; Guid?workflowTypeGuid = configurationValues != null && configurationValues.ContainsKey(WORKFLOW_TYPE_KEY) ? configurationValues[WORKFLOW_TYPE_KEY].Value.AsGuidOrNull() : null; WorkflowType workflowType = null; if (workflowTypeGuid.HasValue) { var workflowTypeService = new WorkflowTypeService(new RockContext()); workflowType = workflowTypeService.Get(workflowTypeGuid.Value); } if (workflowType == null) { workflowType = GetContextWorkflowType(); } if (workflowType != null) { activityTypes = workflowType.ActivityTypes; if (activityTypes != null && activityTypes.Any()) { foreach (var activityType in activityTypes.OrderBy(a => a.Order)) { editControl.Items.Add(new ListItem(activityType.Name ?? "[New Activity]", activityType.Guid.ToString().ToUpper())); } } return(editControl); } return(null); }
/// <summary> /// Sets the value. ( as Guid ) /// </summary> /// <param name="control">The control.</param> /// <param name="configurationValues"></param> /// <param name="value">The value.</param> public override void SetEditValue(Control control, Dictionary <string, ConfigurationValue> configurationValues, string value) { var picker = control as WorkflowTypePicker; if (picker != null) { WorkflowType item = null; Guid? guid = value.AsGuidOrNull(); // get the item (or null) and set it if (guid.HasValue) { var rockContext = new RockContext(); item = new WorkflowTypeService(rockContext).GetNoTracking(guid.Value); } picker.SetValue(item); } }
public Workflow NewWorkflow(WorkflowType workflowType, string correlationId = null) { var workflow = new Workflow { Id = Guid.NewGuid(), WorkflowTypeId = workflowType.WorkflowTypeId, Status = WorkflowStatus.Idle, State = JObject.FromObject(new WorkflowState { ActivityStates = workflowType.Activities.Select(x => x) .ToDictionary(x => x.ActivityId, x => x.Properties) }), CorrelationId = correlationId, CreatedUtc = _dateTimeProvider.Now, WorkflowId = RandomHelper.Generate26UniqueId() }; return(workflow); }
protected void AddAttributeColumns(WorkflowType workflowType) { // Remove attribute columns foreach (var column in gWorkflows.Columns.OfType <AttributeField>().ToList()) { gWorkflows.Columns.Remove(column); } if (workflowType != null) { // Add attribute columns int entityTypeId = new Workflow().TypeId; string qualifier = workflowType.Id.ToString(); foreach (var attribute in new AttributeService(new RockContext()).Queryable() .Where(a => a.EntityTypeId == entityTypeId && a.IsGridColumn && a.EntityTypeQualifierColumn.Equals("WorkflowTypeId", StringComparison.OrdinalIgnoreCase) && a.EntityTypeQualifierValue.Equals(qualifier)) .OrderBy(a => a.Order) .ThenBy(a => a.Name)) { string dataFieldExpression = attribute.Key; bool columnExists = gWorkflows.Columns.OfType <AttributeField>().FirstOrDefault(a => a.DataField.Equals(dataFieldExpression)) != null; if (!columnExists) { AttributeField boundField = new AttributeField(); boundField.DataField = dataFieldExpression; boundField.HeaderText = attribute.Name; boundField.SortExpression = string.Empty; var attributeCache = Rock.Web.Cache.AttributeCache.Read(attribute.Id); if (attributeCache != null) { boundField.ItemStyle.HorizontalAlign = attributeCache.FieldType.Field.AlignValue; } gWorkflows.Columns.Add(boundField); } } } }
protected void AddAttributeColumns( WorkflowType workflowType ) { // Remove attribute columns foreach ( var column in gWorkflows.Columns.OfType<AttributeField>().ToList() ) { gWorkflows.Columns.Remove( column ); } if ( workflowType != null ) { // Add attribute columns int entityTypeId = new Workflow().TypeId; string qualifier = workflowType.Id.ToString(); foreach ( var attribute in new AttributeService( new RockContext() ).Queryable() .Where( a => a.EntityTypeId == entityTypeId && a.IsGridColumn && a.EntityTypeQualifierColumn.Equals( "WorkflowTypeId", StringComparison.OrdinalIgnoreCase ) && a.EntityTypeQualifierValue.Equals( qualifier ) ) .OrderBy( a => a.Order ) .ThenBy( a => a.Name ) ) { string dataFieldExpression = attribute.Key; bool columnExists = gWorkflows.Columns.OfType<AttributeField>().FirstOrDefault( a => a.DataField.Equals( dataFieldExpression ) ) != null; if ( !columnExists ) { AttributeField boundField = new AttributeField(); boundField.DataField = dataFieldExpression; boundField.AttributeId = attribute.Id; boundField.HeaderText = attribute.Name; var attributeCache = Rock.Web.Cache.AttributeCache.Read( attribute.Id ); if ( attributeCache != null ) { boundField.ItemStyle.HorizontalAlign = attributeCache.FieldType.Field.AlignValue; } gWorkflows.Columns.Add( boundField ); } } } }
/// <summary> /// Initializes a new instance of the <see cref="WorkflowNavigationWorkflowType"/> class. /// </summary> /// <param name="workflowType">Type of the workflow.</param> public WorkflowNavigationWorkflowType(WorkflowType workflowType, bool canManage) { Id = workflowType.Id; Name = workflowType.Name; Description = workflowType.Description; IconCssClass = workflowType.IconCssClass; WorkTerm = workflowType.WorkTerm; HasForms = workflowType.HasActiveForms; HighlightColor = string.Empty; CanManage = canManage; if (workflowType.IsActive.HasValue) { IsActive = workflowType.IsActive.Value; } else { IsActive = true; } }
private void button_Parse_LogFile_Click(object sender, EventArgs e) { if (this.SelectedLevel == RuleLevel.None) { this.Log.AddWarningMsg("Selected Level is null. Level must be selected before Parse_LogEvent_Click"); this.label_Error.Text = "Rule level must be selected before event log file parsing can begin"; this.label_Error.Visible = true; this.label_Error.BringToFront(); return; } if (this.runspace == null) { this.runspace = RunspaceFactory.CreateRunspace(); this.runspace.Open(); } string dspTitle = "Choose event logs to convert to policy"; List <string> eventLogPaths = Helper.BrowseForMultiFiles(dspTitle, Helper.BrowseFileType.EventLog); // Prep UI this.textBox_EventLogFilePath.Text = eventLogPaths[0]; this.panel_Progress.Visible = true; this.label_Error.Visible = false; this.eventLogParsing_Result_Panel.Visible = false; this.Workflow = WorkflowType.ArbitraryEventLog; this.DriverFiles = Helper.ReadArbitraryEventLogs(eventLogPaths); // TODO: handle 0 case this.NumberRules = this.DriverFiles.Count; this.label_Progress.Text = String.Format("0 / {0} Rules from Event Log Created", this.NumberRules); // Create background worker to display updates to UI if (!this.backgroundWorker.IsBusy) { this.backgroundWorker.RunWorkerAsync(); } }
/// <summary> /// Sets the value. /// </summary> /// <param name="workflowType">The Workflow Type.</param> public void SetValue( WorkflowType workflowType ) { if ( workflowType != null ) { ItemId = workflowType.Id.ToString(); string parentCategoryIds = string.Empty; var parentCategory = workflowType.Category; while ( parentCategory != null ) { parentCategoryIds = parentCategory.Id + "," + parentCategoryIds; parentCategory = parentCategory.ParentCategory; } InitialItemParentIds = parentCategoryIds.TrimEnd( new[] { ',' } ); ItemName = workflowType.Name; } else { ItemId = Constants.None.IdValue; ItemName = Constants.None.TextHtml; } }
public WorkflowFileViewModel(WorkflowType workflowType, uint dirtyCounter) : base(string.Concat(workflowType, dirtyCounter)) { InitializeWorkflowFileViewModel(); WorkflowType = workflowType; IsDirty = true; IsSaved = true; Title = string.Format( "{0} {1}", workflowType == WorkflowType.Activity ? "Activity" : "WorkflowService", dirtyCounter); FilePath = string.Concat( Title, workflowType == WorkflowType.Activity ? ".xaml" : ".xamlx"); var resourcePath = workflowType == WorkflowType.Activity ? "FlowStudio.DefaultActivity.xaml" : "FlowStudio.DefaultWorkflowService.xamlx"; using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourcePath)) { if (stream != null) { using (var reader = new StreamReader(stream)) { WorkflowDesigner.Text = reader.ReadToEnd(); } } } WorkflowDesigner.Load(); FinalizeWorkflowFileViewModel(); }
private void LoadWorkflowType() { if ( _rockContext == null ) { _rockContext = new RockContext(); } if ( _workflowService == null ) { _workflowService = new WorkflowService( _rockContext ); } if ( _workflowTypeService == null ) { _workflowTypeService = new WorkflowTypeService( _rockContext ); } // Get the workflow type id (initial page request) if ( !WorkflowTypeId.HasValue ) { // Get workflow type set by attribute value Guid workflowTypeguid = GetAttributeValue( "WorkflowType" ).AsGuid(); if ( !workflowTypeguid.IsEmpty() ) { _workflowType = _workflowTypeService.Get( workflowTypeguid ); } // If an attribute value was not provided, check for query/route value if ( _workflowType != null ) { WorkflowTypeId = _workflowType.Id; ConfiguredType = true; } else { WorkflowTypeId = PageParameter( "WorkflowTypeId" ).AsIntegerOrNull(); ConfiguredType = false; } } // Get the workflow type if ( _workflowType == null && WorkflowTypeId.HasValue ) { _workflowType = _workflowTypeService.Get( WorkflowTypeId.Value ); } }
/// <summary> /// Shows the edit details. /// </summary> /// <param name="workflowType">Type of the workflow.</param> /// <param name="rockContext">The rock context.</param> private void ShowEditDetails( WorkflowType workflowType, RockContext rockContext ) { ExpandedActivities = new List<Guid>(); ExpandedActivityAttributes = new List<Guid>(); ExpandedActions = new List<Guid>(); if ( workflowType.Id == 0 ) { lReadOnlyTitle.Text = ActionTitle.Add( WorkflowType.FriendlyTypeName ).FormatAsHtmlTitle(); foreach( var activity in workflowType.ActivityTypes) { ExpandedActivities.Add( activity.Guid ); } hlInactive.Visible = false; } else { pwDetails.Expanded = false; } SetEditMode( true ); LoadDropDowns(); cbIsActive.Checked = workflowType.IsActive ?? false; tbName.Text = workflowType.Name; tbDescription.Text = workflowType.Description; cpCategory.SetValue( workflowType.CategoryId ); tbWorkTerm.Text = workflowType.WorkTerm; tbProcessingInterval.Text = workflowType.ProcessingIntervalSeconds != null ? workflowType.ProcessingIntervalSeconds.ToString() : string.Empty; cbIsPersisted.Checked = workflowType.IsPersisted; ddlLoggingLevel.SetValue( (int)workflowType.LoggingLevel ); tbIconCssClass.Text = workflowType.IconCssClass; BindAttributesGrid(); BuildControls( true ); }
/// <summary> /// Shows the edit details. /// </summary> /// <param name="workflowType">Type of the workflow.</param> /// <param name="rockContext">The rock context.</param> private void ShowEditDetails( WorkflowType workflowType, RockContext rockContext ) { ExpandedActivities = new List<Guid>(); ExpandedActivityAttributes = new List<Guid>(); ExpandedActions = new List<Guid>(); if ( workflowType.Id == 0 ) { lReadOnlyTitle.Text = ActionTitle.Add( WorkflowType.FriendlyTypeName ).FormatAsHtmlTitle(); foreach( var activity in workflowType.ActivityTypes) { ExpandedActivities.Add( activity.Guid ); } hlInactive.Visible = false; } else { pwDetails.Expanded = false; } SetEditMode( true ); cbIsActive.Checked = workflowType.IsActive ?? false; tbName.Text = workflowType.Name; tbDescription.Text = workflowType.Description; cpCategory.SetValue( workflowType.CategoryId ); tbWorkTerm.Text = workflowType.WorkTerm; tbNumberPrefix.Text = workflowType.WorkflowIdPrefix; if ( workflowType.ProcessingIntervalSeconds.HasValue ) { int mins = workflowType.ProcessingIntervalSeconds.Value / 60; tbProcessingInterval.Text = mins.ToString( "N0" ); } else { tbProcessingInterval.Text = string.Empty; } cbIsPersisted.Checked = workflowType.IsPersisted; ddlLoggingLevel.SetValue( (int)workflowType.LoggingLevel ); tbIconCssClass.Text = workflowType.IconCssClass; ceSummaryViewText.Text = workflowType.SummaryViewText; ceNoActionMessage.Text = workflowType.NoActionMessage; BindAttributesGrid(); BuildControls( true ); }
/// <summary> /// Handles the Click event of the btnSave control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> protected void btnSave_Click( object sender, EventArgs e ) { ParseControls( true ); var rockContext = new RockContext(); var service = new WorkflowTypeService( rockContext ); WorkflowType workflowType = null; int? workflowTypeId = hfWorkflowTypeId.Value.AsIntegerOrNull(); if ( workflowTypeId.HasValue ) { workflowType = service.Get( workflowTypeId.Value ); } if ( workflowType == null ) { workflowType = new WorkflowType(); } var validationErrors = new List<string>(); // check for unique prefix string prefix = tbNumberPrefix.UntrimmedText; if ( !string.IsNullOrWhiteSpace( prefix ) && prefix.ToUpper() != ( workflowType.WorkflowIdPrefix ?? string.Empty ).ToUpper() ) { if ( service.Queryable().AsNoTracking() .Any( w => w.Id != workflowType.Id && w.WorkflowIdPrefix == prefix ) ) { validationErrors.Add( "Workflow Number Prefix is already being used by another workflow type. Please use a unique prefix." ); } else { workflowType.WorkflowIdPrefix = prefix; } } else { workflowType.WorkflowIdPrefix = prefix; } workflowType.IsActive = cbIsActive.Checked; workflowType.Name = tbName.Text; workflowType.Description = tbDescription.Text; workflowType.CategoryId = cpCategory.SelectedValueAsInt(); workflowType.WorkTerm = tbWorkTerm.Text; workflowType.ModifiedByPersonAliasId = CurrentPersonAliasId; workflowType.ModifiedDateTime = RockDateTime.Now; int? mins = tbProcessingInterval.Text.AsIntegerOrNull(); if ( mins.HasValue ) { workflowType.ProcessingIntervalSeconds = mins.Value * 60; } else { workflowType.ProcessingIntervalSeconds = null; } workflowType.IsPersisted = cbIsPersisted.Checked; workflowType.LoggingLevel = ddlLoggingLevel.SelectedValueAsEnum<WorkflowLoggingLevel>(); workflowType.IconCssClass = tbIconCssClass.Text; workflowType.SummaryViewText = ceSummaryViewText.Text; workflowType.NoActionMessage = ceNoActionMessage.Text; if ( validationErrors.Any() ) { nbValidationError.Text = string.Format( "Please Correct the Following<ul><li>{0}</li></ul>", validationErrors.AsDelimited( "</li><li>" ) ); nbValidationError.Visible = true; return; } if ( !Page.IsValid || !workflowType.IsValid ) { return; } foreach(var activityType in ActivityTypesState) { if (!activityType.IsValid) { return; } foreach(var actionType in activityType.ActionTypes) { if ( !actionType.IsValid ) { return; } } } rockContext.WrapTransaction( () => { // Save the entity field changes to workflow type if ( workflowType.Id.Equals( 0 ) ) { service.Add( workflowType ); } rockContext.SaveChanges(); // Save the workflow type attributes SaveAttributes( new Workflow().TypeId, "WorkflowTypeId", workflowType.Id.ToString(), AttributesState, rockContext ); WorkflowActivityTypeService workflowActivityTypeService = new WorkflowActivityTypeService( rockContext ); WorkflowActivityService workflowActivityService = new WorkflowActivityService( rockContext ); WorkflowActionService workflowActionService = new WorkflowActionService( rockContext ); WorkflowActionTypeService workflowActionTypeService = new WorkflowActionTypeService( rockContext ); WorkflowActionFormService workflowFormService = new WorkflowActionFormService( rockContext ); WorkflowActionFormAttributeService workflowFormAttributeService = new WorkflowActionFormAttributeService( rockContext ); // delete WorkflowActionTypes that aren't assigned in the UI anymore List<WorkflowActionType> actionTypesInDB = workflowActionTypeService.Queryable().Where( a => a.ActivityType.WorkflowTypeId.Equals( workflowType.Id ) ).ToList(); List<WorkflowActionType> actionTypesInUI = new List<WorkflowActionType>(); foreach ( var workflowActivity in ActivityTypesState ) { foreach ( var workflowAction in workflowActivity.ActionTypes ) { actionTypesInUI.Add( workflowAction ); } } var deletedActionTypes = from actionType in actionTypesInDB where !actionTypesInUI.Select( u => u.Guid ).Contains( actionType.Guid ) select actionType; foreach ( var actionType in deletedActionTypes.ToList() ) { if ( actionType.WorkflowForm != null ) { workflowFormService.Delete( actionType.WorkflowForm ); } // Delete any workflow actions of this type int loopCounter = 0; foreach ( var action in workflowActionService.Queryable().Where( a => a.ActionTypeId == actionType.Id ) ) { workflowActionService.Delete( action ); loopCounter++; if ( loopCounter > 100 ) { rockContext.SaveChanges(); loopCounter = 0; } } rockContext.SaveChanges(); workflowActionTypeService.Delete( actionType ); } rockContext.SaveChanges(); // delete WorkflowActivityTypes that aren't assigned in the UI anymore List<WorkflowActivityType> activityTypesInDB = workflowActivityTypeService.Queryable().Where( a => a.WorkflowTypeId.Equals( workflowType.Id ) ).ToList(); var deletedActivityTypes = from activityType in activityTypesInDB where !ActivityTypesState.Select( u => u.Guid ).Contains( activityType.Guid ) select activityType; foreach ( var activityType in deletedActivityTypes.ToList() ) { // Delete any workflow activities of this type int loopCounter = 0; foreach ( var activity in workflowActivityService.Queryable().Where( a => a.ActivityTypeId == activityType.Id ) ) { workflowActivityService.Delete( activity ); loopCounter++; if ( loopCounter > 100 ) { rockContext.SaveChanges(); loopCounter = 0; } } rockContext.SaveChanges(); workflowActivityTypeService.Delete( activityType ); } rockContext.SaveChanges(); // add or update WorkflowActivityTypes(and Actions) that are assigned in the UI int workflowActivityTypeOrder = 0; foreach ( var editorWorkflowActivityType in ActivityTypesState ) { // Add or Update the activity type WorkflowActivityType workflowActivityType = workflowType.ActivityTypes.FirstOrDefault( a => a.Guid.Equals( editorWorkflowActivityType.Guid ) ); if ( workflowActivityType == null ) { workflowActivityType = new WorkflowActivityType(); workflowActivityType.Guid = editorWorkflowActivityType.Guid; workflowType.ActivityTypes.Add( workflowActivityType ); } workflowActivityType.IsActive = editorWorkflowActivityType.IsActive; workflowActivityType.Name = editorWorkflowActivityType.Name; workflowActivityType.Description = editorWorkflowActivityType.Description; workflowActivityType.IsActivatedWithWorkflow = editorWorkflowActivityType.IsActivatedWithWorkflow; workflowActivityType.Order = workflowActivityTypeOrder++; // Save Activity Type rockContext.SaveChanges(); // Save ActivityType Attributes if ( ActivityAttributesState.ContainsKey( workflowActivityType.Guid ) ) { SaveAttributes( new WorkflowActivity().TypeId, "ActivityTypeId", workflowActivityType.Id.ToString(), ActivityAttributesState[workflowActivityType.Guid], rockContext ); } // Because the SaveAttributes above may have flushed the cached entity attribute cache, and it would get loaded again with // a different context, manually reload the cache now with our context to prevent a database lock conflict (when database is // configured without snapshot isolation turned on) AttributeCache.LoadEntityAttributes( rockContext ); int workflowActionTypeOrder = 0; foreach ( var editorWorkflowActionType in editorWorkflowActivityType.ActionTypes ) { WorkflowActionType workflowActionType = workflowActivityType.ActionTypes.FirstOrDefault( a => a.Guid.Equals( editorWorkflowActionType.Guid ) ); if ( workflowActionType == null ) { // New action workflowActionType = new WorkflowActionType(); workflowActionType.Guid = editorWorkflowActionType.Guid; workflowActivityType.ActionTypes.Add( workflowActionType ); } workflowActionType.CriteriaAttributeGuid = editorWorkflowActionType.CriteriaAttributeGuid; workflowActionType.CriteriaComparisonType = editorWorkflowActionType.CriteriaComparisonType; workflowActionType.CriteriaValue = editorWorkflowActionType.CriteriaValue; workflowActionType.Name = editorWorkflowActionType.Name; workflowActionType.EntityTypeId = editorWorkflowActionType.EntityTypeId; workflowActionType.IsActionCompletedOnSuccess = editorWorkflowActionType.IsActionCompletedOnSuccess; workflowActionType.IsActivityCompletedOnSuccess = editorWorkflowActionType.IsActivityCompletedOnSuccess; workflowActionType.Attributes = editorWorkflowActionType.Attributes; workflowActionType.AttributeValues = editorWorkflowActionType.AttributeValues; workflowActionType.Order = workflowActionTypeOrder++; if ( workflowActionType.WorkflowForm != null && editorWorkflowActionType.WorkflowForm == null ) { // Form removed workflowFormService.Delete( workflowActionType.WorkflowForm ); workflowActionType.WorkflowForm = null; } if ( editorWorkflowActionType.WorkflowForm != null ) { if ( workflowActionType.WorkflowForm == null ) { workflowActionType.WorkflowForm = new WorkflowActionForm(); } workflowActionType.WorkflowForm.NotificationSystemEmailId = editorWorkflowActionType.WorkflowForm.NotificationSystemEmailId; workflowActionType.WorkflowForm.IncludeActionsInNotification = editorWorkflowActionType.WorkflowForm.IncludeActionsInNotification; workflowActionType.WorkflowForm.AllowNotes = editorWorkflowActionType.WorkflowForm.AllowNotes; workflowActionType.WorkflowForm.Header = editorWorkflowActionType.WorkflowForm.Header; workflowActionType.WorkflowForm.Footer = editorWorkflowActionType.WorkflowForm.Footer; workflowActionType.WorkflowForm.Actions = editorWorkflowActionType.WorkflowForm.Actions; workflowActionType.WorkflowForm.ActionAttributeGuid = editorWorkflowActionType.WorkflowForm.ActionAttributeGuid; var editorGuids = editorWorkflowActionType.WorkflowForm.FormAttributes .Select( a => a.Attribute.Guid ) .ToList(); foreach ( var formAttribute in workflowActionType.WorkflowForm.FormAttributes .Where( a => !editorGuids.Contains( a.Attribute.Guid ) ).ToList() ) { workflowFormAttributeService.Delete( formAttribute ); } int attributeOrder = 0; foreach ( var editorAttribute in editorWorkflowActionType.WorkflowForm.FormAttributes.OrderBy( a => a.Order ) ) { int attributeId = AttributeCache.Read( editorAttribute.Attribute.Guid, rockContext ).Id; var formAttribute = workflowActionType.WorkflowForm.FormAttributes .Where( a => a.AttributeId == attributeId ) .FirstOrDefault(); if ( formAttribute == null ) { formAttribute = new WorkflowActionFormAttribute(); formAttribute.Guid = editorAttribute.Guid; formAttribute.AttributeId = attributeId; workflowActionType.WorkflowForm.FormAttributes.Add( formAttribute ); } formAttribute.Order = attributeOrder++; formAttribute.IsVisible = editorAttribute.IsVisible; formAttribute.IsReadOnly = editorAttribute.IsReadOnly; formAttribute.IsRequired = editorAttribute.IsRequired; formAttribute.HideLabel = editorAttribute.HideLabel; formAttribute.PreHtml = editorAttribute.PreHtml; formAttribute.PostHtml = editorAttribute.PostHtml; } } } } rockContext.SaveChanges(); foreach ( var activityType in workflowType.ActivityTypes ) { foreach ( var workflowActionType in activityType.ActionTypes ) { workflowActionType.SaveAttributeValues( rockContext ); } } } ); var qryParams = new Dictionary<string, string>(); qryParams["workflowTypeId"] = workflowType.Id.ToString(); NavigateToPage( RockPage.Guid, qryParams ); }
/// <summary> /// Returns breadcrumbs specific to the block that should be added to navigation /// based on the current page reference. This function is called during the page's /// oninit to load any initial breadcrumbs. /// </summary> /// <param name="pageReference">The <see cref="Rock.Web.PageReference" />.</param> /// <returns> /// A <see cref="System.Collections.Generic.List{BreadCrumb}" /> of block related <see cref="Rock.Web.UI.BreadCrumb">BreadCrumbs</see>. /// </returns> public override List<BreadCrumb> GetBreadCrumbs( Rock.Web.PageReference pageReference ) { var breadCrumbs = new List<BreadCrumb>(); if (!string.IsNullOrWhiteSpace(GetAttributeValue("DefaultWorkflowType"))) { Guid workflowTypeGuid = Guid.Empty; Guid.TryParse( GetAttributeValue( "DefaultWorkflowType" ), out workflowTypeGuid ); _workflowType = new WorkflowTypeService( new RockContext() ).Get( workflowTypeGuid ); } else { int workflowTypeId = 0; workflowTypeId = PageParameter( "WorkflowTypeId" ).AsInteger(); _workflowType = new WorkflowTypeService( new RockContext() ).Get( workflowTypeId ); } if ( _workflowType != null ) { breadCrumbs.Add( new BreadCrumb( _workflowType.Name, pageReference ) ); } return breadCrumbs; }
/// <summary> /// Handles the Click event of the btnSave control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> protected void btnSave_Click( object sender, EventArgs e ) { ParseControls( true ); var rockContext = new RockContext(); var service = new WorkflowTypeService( rockContext ); WorkflowType workflowType = null; int? workflowTypeId = hfWorkflowTypeId.Value.AsIntegerOrNull(); if ( workflowTypeId.HasValue ) { workflowType = service.Get( workflowTypeId.Value ); } if ( workflowType == null ) { workflowType = new WorkflowType(); } workflowType.IsActive = cbIsActive.Checked; workflowType.Name = tbName.Text; workflowType.Description = tbDescription.Text; workflowType.CategoryId = cpCategory.SelectedValueAsInt(); workflowType.Order = 0; workflowType.WorkTerm = tbWorkTerm.Text; workflowType.ProcessingIntervalSeconds = tbProcessingInterval.Text.AsIntegerOrNull(); workflowType.IsPersisted = cbIsPersisted.Checked; workflowType.LoggingLevel = ddlLoggingLevel.SelectedValueAsEnum<WorkflowLoggingLevel>(); workflowType.IconCssClass = tbIconCssClass.Text; if ( !Page.IsValid || !workflowType.IsValid ) { return; } foreach(var activityType in ActivityTypesState) { if (!activityType.IsValid) { return; } foreach(var actionType in activityType.ActionTypes) { if ( !actionType.IsValid ) { return; } } } rockContext.WrapTransaction( () => { // Save the entity field changes to workflow type if ( workflowType.Id.Equals( 0 ) ) { service.Add( workflowType ); } rockContext.SaveChanges(); // Save the workflow type attributes SaveAttributes( new Workflow().TypeId, "WorkflowTypeId", workflowType.Id.ToString(), AttributesState, rockContext ); WorkflowActivityTypeService workflowActivityTypeService = new WorkflowActivityTypeService( rockContext ); WorkflowActionTypeService workflowActionTypeService = new WorkflowActionTypeService( rockContext ); WorkflowActionFormService workflowFormService = new WorkflowActionFormService( rockContext ); WorkflowActionFormAttributeService workflowFormAttributeService = new WorkflowActionFormAttributeService( rockContext ); // delete WorkflowActionTypes that aren't assigned in the UI anymore List<WorkflowActionType> actionTypesInDB = workflowActionTypeService.Queryable().Where( a => a.ActivityType.WorkflowTypeId.Equals( workflowType.Id ) ).ToList(); List<WorkflowActionType> actionTypesInUI = new List<WorkflowActionType>(); foreach ( var workflowActivity in ActivityTypesState ) { foreach ( var workflowAction in workflowActivity.ActionTypes ) { actionTypesInUI.Add( workflowAction ); } } var deletedActionTypes = from actionType in actionTypesInDB where !actionTypesInUI.Select( u => u.Guid ).Contains( actionType.Guid ) select actionType; deletedActionTypes.ToList().ForEach( actionType => { if ( actionType.WorkflowForm != null ) { workflowFormService.Delete( actionType.WorkflowForm ); } workflowActionTypeService.Delete( actionType ); } ); rockContext.SaveChanges(); // delete WorkflowActivityTypes that aren't assigned in the UI anymore List<WorkflowActivityType> activityTypesInDB = workflowActivityTypeService.Queryable().Where( a => a.WorkflowTypeId.Equals( workflowType.Id ) ).ToList(); var deletedActivityTypes = from activityType in activityTypesInDB where !ActivityTypesState.Select( u => u.Guid ).Contains( activityType.Guid ) select activityType; deletedActivityTypes.ToList().ForEach( activityType => { workflowActivityTypeService.Delete( activityType ); } ); rockContext.SaveChanges(); // add or update WorkflowActivityTypes(and Actions) that are assigned in the UI int workflowActivityTypeOrder = 0; foreach ( var editorWorkflowActivityType in ActivityTypesState ) { // Add or Update the activity type WorkflowActivityType workflowActivityType = workflowType.ActivityTypes.FirstOrDefault( a => a.Guid.Equals( editorWorkflowActivityType.Guid ) ); if ( workflowActivityType == null ) { workflowActivityType = new WorkflowActivityType(); workflowActivityType.Guid = editorWorkflowActivityType.Guid; workflowType.ActivityTypes.Add( workflowActivityType ); } workflowActivityType.IsActive = editorWorkflowActivityType.IsActive; workflowActivityType.Name = editorWorkflowActivityType.Name; workflowActivityType.Description = editorWorkflowActivityType.Description; workflowActivityType.IsActivatedWithWorkflow = editorWorkflowActivityType.IsActivatedWithWorkflow; workflowActivityType.Order = workflowActivityTypeOrder++; // Save Activity Type rockContext.SaveChanges(); // Save ActivityType Attributes if ( ActivityAttributesState.ContainsKey( workflowActivityType.Guid ) ) { SaveAttributes( new WorkflowActivity().TypeId, "ActivityTypeId", workflowActivityType.Id.ToString(), ActivityAttributesState[workflowActivityType.Guid], rockContext ); } int workflowActionTypeOrder = 0; foreach ( var editorWorkflowActionType in editorWorkflowActivityType.ActionTypes ) { WorkflowActionType workflowActionType = workflowActivityType.ActionTypes.FirstOrDefault( a => a.Guid.Equals( editorWorkflowActionType.Guid ) ); if ( workflowActionType == null ) { // New action workflowActionType = new WorkflowActionType(); workflowActionType.Guid = editorWorkflowActionType.Guid; workflowActivityType.ActionTypes.Add( workflowActionType ); } workflowActionType.CriteriaAttributeGuid = editorWorkflowActionType.CriteriaAttributeGuid; workflowActionType.CriteriaComparisonType = editorWorkflowActionType.CriteriaComparisonType; workflowActionType.CriteriaValue = editorWorkflowActionType.CriteriaValue; workflowActionType.Name = editorWorkflowActionType.Name; workflowActionType.EntityTypeId = editorWorkflowActionType.EntityTypeId; workflowActionType.IsActionCompletedOnSuccess = editorWorkflowActionType.IsActionCompletedOnSuccess; workflowActionType.IsActivityCompletedOnSuccess = editorWorkflowActionType.IsActivityCompletedOnSuccess; workflowActionType.Attributes = editorWorkflowActionType.Attributes; workflowActionType.AttributeValues = editorWorkflowActionType.AttributeValues; workflowActionType.Order = workflowActionTypeOrder++; if ( workflowActionType.WorkflowForm != null && editorWorkflowActionType.WorkflowForm == null ) { // Form removed workflowFormService.Delete( workflowActionType.WorkflowForm ); workflowActionType.WorkflowForm = null; } if ( editorWorkflowActionType.WorkflowForm != null ) { if ( workflowActionType.WorkflowForm == null ) { workflowActionType.WorkflowForm = new WorkflowActionForm(); } workflowActionType.WorkflowForm.NotificationSystemEmailId = editorWorkflowActionType.WorkflowForm.NotificationSystemEmailId; workflowActionType.WorkflowForm.IncludeActionsInNotification = editorWorkflowActionType.WorkflowForm.IncludeActionsInNotification; workflowActionType.WorkflowForm.AllowNotes = editorWorkflowActionType.WorkflowForm.AllowNotes; workflowActionType.WorkflowForm.Header = editorWorkflowActionType.WorkflowForm.Header; workflowActionType.WorkflowForm.Footer = editorWorkflowActionType.WorkflowForm.Footer; workflowActionType.WorkflowForm.Actions = editorWorkflowActionType.WorkflowForm.Actions; workflowActionType.WorkflowForm.ActionAttributeGuid = editorWorkflowActionType.WorkflowForm.ActionAttributeGuid; var editorGuids = editorWorkflowActionType.WorkflowForm.FormAttributes .Select( a => a.Attribute.Guid ) .ToList(); foreach ( var formAttribute in workflowActionType.WorkflowForm.FormAttributes .Where( a => !editorGuids.Contains( a.Attribute.Guid ) ).ToList() ) { workflowFormAttributeService.Delete( formAttribute ); } int attributeOrder = 0; foreach ( var editorAttribute in editorWorkflowActionType.WorkflowForm.FormAttributes.OrderBy( a => a.Order ) ) { int attributeId = AttributeCache.Read( editorAttribute.Attribute.Guid, rockContext ).Id; var formAttribute = workflowActionType.WorkflowForm.FormAttributes .Where( a => a.AttributeId == attributeId ) .FirstOrDefault(); if ( formAttribute == null ) { formAttribute = new WorkflowActionFormAttribute(); formAttribute.Guid = editorAttribute.Guid; formAttribute.AttributeId = attributeId; workflowActionType.WorkflowForm.FormAttributes.Add( formAttribute ); } formAttribute.Order = attributeOrder++; formAttribute.IsVisible = editorAttribute.IsVisible; formAttribute.IsReadOnly = editorAttribute.IsReadOnly; formAttribute.IsRequired = editorAttribute.IsRequired; formAttribute.HideLabel = editorAttribute.HideLabel; formAttribute.PreHtml = editorAttribute.PreHtml; formAttribute.PostHtml = editorAttribute.PostHtml; } } } } rockContext.SaveChanges(); foreach ( var activityType in workflowType.ActivityTypes ) { foreach ( var workflowActionType in activityType.ActionTypes ) { workflowActionType.SaveAttributeValues( rockContext ); } } } ); var qryParams = new Dictionary<string, string>(); qryParams["workflowTypeId"] = workflowType.Id.ToString(); NavigateToPage( RockPage.Guid, qryParams ); }
/// <summary> /// Shows the readonly details. /// </summary> /// <param name="workflowType">Type of the workflow.</param> private void ShowReadonlyDetails( WorkflowType workflowType ) { SetEditMode( false ); hfWorkflowTypeId.SetValue( workflowType.Id ); lReadOnlyTitle.Text = workflowType.Name.FormatAsHtmlTitle(); hlInactive.Visible = workflowType.IsActive == false; lblActivitiesReadonlyHeaderLabel.Text = string.Format( "<strong>Activities</strong> ({0})", workflowType.ActivityTypes.Count() ); if ( workflowType.Category != null ) { hlType.Visible = true; hlType.Text = workflowType.Category.Name; } else { hlType.Visible = false; } lWorkflowTypeDescription.Text = workflowType.Description; if ( workflowType.ActivityTypes.Count > 0 ) { // Activities lblWorkflowActivitiesReadonly.Text = @" <div> <ol>"; foreach ( var activityType in workflowType.ActivityTypes.OrderBy( a => a.Order ) ) { string activityTypeTextFormat = @" <li> <strong>{0}</strong> {1} <br /> {2} <ol> {3} </ol> </li> "; string actionTypeText = string.Empty; foreach ( var actionType in activityType.ActionTypes.OrderBy( a => a.Order ) ) { actionTypeText += string.Format( "<li>{0}</li>" + Environment.NewLine, actionType.Name ); } string actionsTitle = activityType.ActionTypes.Count > 0 ? "Actions:" : "No Actions"; lblWorkflowActivitiesReadonly.Text += string.Format( activityTypeTextFormat, activityType.Name, activityType.Description, actionsTitle, actionTypeText ); } lblWorkflowActivitiesReadonly.Text += @" </ol> </div> "; } else { lblWorkflowActivitiesReadonly.Text = "<div>" + None.TextHtml + "</div>"; } }
/// <summary> /// Handles the Click event of the btnSave control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> protected void btnSave_Click( object sender, EventArgs e ) { var rockContext = new RockContext(); WorkflowType workflowType; WorkflowTypeService service = new WorkflowTypeService( rockContext ); int workflowTypeId = int.Parse( hfWorkflowTypeId.Value ); if ( workflowTypeId == 0 ) { workflowType = new WorkflowType(); workflowType.IsSystem = false; workflowType.Name = string.Empty; } else { workflowType = service.Get( workflowTypeId ); } workflowType.Name = tbName.Text; workflowType.Description = tbDescription.Text; workflowType.CategoryId = cpCategory.SelectedValueAsInt(); workflowType.Order = 0; workflowType.WorkTerm = tbWorkTerm.Text; if ( !string.IsNullOrWhiteSpace( tbProcessingInterval.Text ) ) { workflowType.ProcessingIntervalSeconds = int.Parse( tbProcessingInterval.Text ); } workflowType.IsPersisted = cbIsPersisted.Checked; workflowType.LoggingLevel = ddlLoggingLevel.SelectedValueAsEnum<WorkflowLoggingLevel>(); workflowType.IsActive = cbIsActive.Checked; if ( !Page.IsValid ) { return; } if ( !workflowType.IsValid ) { // Controls will render the error messages return; } RockTransactionScope.WrapTransaction( () => { // Save the entity field changes to workflow type if ( workflowType.Id.Equals( 0 ) ) { service.Add( workflowType ); } rockContext.SaveChanges(); // Save the attributes SaveAttributes( new Workflow().TypeId, "WorkflowTypeId", workflowType.Id.ToString(), AttributesState, rockContext ); WorkflowActivityTypeService workflowActivityTypeService = new WorkflowActivityTypeService( rockContext ); WorkflowActionTypeService workflowActionTypeService = new WorkflowActionTypeService( rockContext ); WorkflowActionFormService workflowFormService = new WorkflowActionFormService( rockContext ); WorkflowActionFormAttributeService workflowFormAttributeService = new WorkflowActionFormAttributeService( rockContext ); // delete WorkflowActionTypes that aren't assigned in the UI anymore List<WorkflowActivityEditor> workflowActivityTypeEditorList = phActivities.Controls.OfType<WorkflowActivityEditor>().ToList(); List<WorkflowActionType> actionTypesInDB = workflowActionTypeService.Queryable().Where( a => a.ActivityType.WorkflowTypeId.Equals( workflowType.Id ) ).ToList(); List<WorkflowActionType> actionTypesInUI = new List<WorkflowActionType>(); foreach ( WorkflowActivityEditor workflowActivityTypeEditor in workflowActivityTypeEditorList ) { foreach ( WorkflowActionEditor editor in workflowActivityTypeEditor.Controls.OfType<WorkflowActionEditor>() ) { actionTypesInUI.Add( editor.WorkflowActionType ); } } var deletedActionTypes = from actionType in actionTypesInDB where !actionTypesInUI.Select( u => u.Guid ).Contains( actionType.Guid ) select actionType; deletedActionTypes.ToList().ForEach( actionType => { if (actionType.WorkflowForm != null) { workflowFormService.Delete( actionType.WorkflowForm ); } workflowActionTypeService.Delete( actionType ); } ); rockContext.SaveChanges(); // delete WorkflowActivityTypes that aren't assigned in the UI anymore List<WorkflowActivityType> activityTypesInDB = workflowActivityTypeService.Queryable().Where( a => a.WorkflowTypeId.Equals( workflowType.Id ) ).ToList(); List<WorkflowActivityType> activityTypesInUI = workflowActivityTypeEditorList.Select( a => a.GetWorkflowActivityType() ).ToList(); var deletedActivityTypes = from activityType in activityTypesInDB where !activityTypesInUI.Select( u => u.Guid ).Contains( activityType.Guid ) select activityType; deletedActivityTypes.ToList().ForEach( activityType => { workflowActivityTypeService.Delete( activityType ); } ); rockContext.SaveChanges(); // add or update WorkflowActivityTypes(and Actions) that are assigned in the UI int workflowActivityTypeOrder = 0; foreach ( WorkflowActivityEditor workflowActivityTypeEditor in workflowActivityTypeEditorList ) { // Add or Update the activity type WorkflowActivityType editorWorkflowActivityType = workflowActivityTypeEditor.GetWorkflowActivityType(); WorkflowActivityType workflowActivityType = workflowType.ActivityTypes.FirstOrDefault( a => a.Guid.Equals( editorWorkflowActivityType.Guid ) ); if ( workflowActivityType == null ) { workflowActivityType = new WorkflowActivityType(); workflowType.ActivityTypes.Add( workflowActivityType ); } workflowActivityType.IsActive = editorWorkflowActivityType.IsActive; workflowActivityType.Name = editorWorkflowActivityType.Name; workflowActivityType.Description = editorWorkflowActivityType.Description; workflowActivityType.IsActivatedWithWorkflow = editorWorkflowActivityType.IsActivatedWithWorkflow; workflowActivityType.Order = workflowActivityTypeOrder++; int workflowActionTypeOrder = 0; foreach ( WorkflowActionEditor workflowActionTypeEditor in workflowActivityTypeEditor.Controls.OfType<WorkflowActionEditor>() ) { WorkflowActionType editorWorkflowActionType = workflowActionTypeEditor.WorkflowActionType; WorkflowActionType workflowActionType = workflowActivityType.ActionTypes.FirstOrDefault( a => a.Guid.Equals( editorWorkflowActionType.Guid ) ); if ( workflowActionType == null ) { // New action workflowActionType = new WorkflowActionType(); workflowActivityType.ActionTypes.Add( workflowActionType ); } workflowActionType.Name = editorWorkflowActionType.Name; workflowActionType.EntityTypeId = editorWorkflowActionType.EntityTypeId; workflowActionType.IsActionCompletedOnSuccess = editorWorkflowActionType.IsActionCompletedOnSuccess; workflowActionType.IsActivityCompletedOnSuccess = editorWorkflowActionType.IsActivityCompletedOnSuccess; workflowActionType.Attributes = editorWorkflowActionType.Attributes; workflowActionType.AttributeValues = editorWorkflowActionType.AttributeValues; workflowActionType.Order = workflowActionTypeOrder++; if ( workflowActionType.WorkflowForm != null && editorWorkflowActionType.WorkflowForm == null ) { // Form removed workflowFormService.Delete( workflowActionType.WorkflowForm ); workflowActionType.WorkflowForm = null; } if (editorWorkflowActionType.WorkflowForm != null) { if (workflowActionType.WorkflowForm == null) { workflowActionType.WorkflowForm = new WorkflowActionForm(); } workflowActionType.WorkflowForm.Header = editorWorkflowActionType.WorkflowForm.Header; workflowActionType.WorkflowForm.Footer = editorWorkflowActionType.WorkflowForm.Footer; workflowActionType.WorkflowForm.InactiveMessage = editorWorkflowActionType.WorkflowForm.InactiveMessage; workflowActionType.WorkflowForm.Actions = editorWorkflowActionType.WorkflowForm.Actions; var editorGuids = editorWorkflowActionType.WorkflowForm.FormAttributes .Select( a => a.Attribute.Guid) .ToList(); foreach( var formAttribute in workflowActionType.WorkflowForm.FormAttributes .Where( a => !editorGuids.Contains(a.Attribute.Guid) ) ) { workflowFormAttributeService.Delete(formAttribute); } int attributeOrder = 0; foreach ( var editorAttribute in editorWorkflowActionType.WorkflowForm.FormAttributes.OrderBy( a => a.Order ) ) { int attributeId = AttributeCache.Read( editorAttribute.Attribute.Guid ).Id; var formAttribute = workflowActionType.WorkflowForm.FormAttributes .Where( a => a.AttributeId == attributeId ) .FirstOrDefault(); if (formAttribute == null) { formAttribute = new WorkflowActionFormAttribute(); formAttribute.Guid = editorAttribute.Guid; formAttribute.AttributeId = attributeId; workflowActionType.WorkflowForm.FormAttributes.Add( formAttribute ); } formAttribute.Order = attributeOrder++; formAttribute.IsVisible = editorAttribute.IsVisible; formAttribute.IsReadOnly = editorAttribute.IsReadOnly; formAttribute.IsRequired = editorAttribute.IsRequired; } } } } rockContext.SaveChanges(); foreach ( var activityType in workflowType.ActivityTypes ) { foreach ( var workflowActionType in activityType.ActionTypes ) { workflowActionType.SaveAttributeValues( rockContext ); } } } ); var qryParams = new Dictionary<string, string>(); qryParams["workflowTypeId"] = workflowType.Id.ToString(); NavigateToPage( RockPage.Guid, qryParams ); }
/// <summary> /// Initializes a new instance of the <see cref="WorkflowNavigationWorkflowType" /> class. /// </summary> /// <param name="workflowType">Type of the workflow.</param> /// <param name="canManage">if set to <c>true</c> [can manage].</param> /// <param name="canViewList">if set to <c>true</c> [can view list].</param> public WorkflowNavigationWorkflowType( WorkflowType workflowType, bool canManage, bool canViewList ) { Id = workflowType.Id; Name = workflowType.Name; Description = workflowType.Description; IconCssClass = workflowType.IconCssClass; WorkTerm = workflowType.WorkTerm; HasForms = workflowType.HasActiveForms; HighlightColor = string.Empty; CanManage = canManage; CanViewList = canViewList; if ( workflowType.IsActive.HasValue ) { IsActive = workflowType.IsActive.Value; } else { IsActive = true; } }
/// <summary> /// Shows the detail. /// </summary> private void ShowDetail() { int? workflowTypeId = PageParameter( "workflowTypeId" ).AsIntegerOrNull(); int? parentCategoryId = PageParameter( "ParentCategoryId" ).AsIntegerOrNull(); if ( !workflowTypeId.HasValue ) { pnlDetails.Visible = false; return; } var rockContext = new RockContext(); WorkflowType workflowType = null; if ( workflowTypeId.Value.Equals( 0 ) ) { workflowType = new WorkflowType(); workflowType.Id = 0; workflowType.IsActive = true; workflowType.IsPersisted = true; workflowType.IsSystem = false; workflowType.CategoryId = parentCategoryId; workflowType.IconCssClass = "fa fa-list-ol"; workflowType.ActivityTypes.Add( new WorkflowActivityType { Guid = Guid.NewGuid(), IsActive = true } ); workflowType.WorkTerm = "Work"; } else { workflowType = new WorkflowTypeService( rockContext ).Get( workflowTypeId.Value ); } if ( workflowType == null ) { return; } pnlDetails.Visible = true; hfWorkflowTypeId.Value = workflowType.Id.ToString(); // render UI based on Authorized and IsSystem bool readOnly = false; nbEditModeMessage.Text = string.Empty; // User must have 'Edit' rights to block, or 'Administrate' rights to workflow type if ( !IsUserAuthorized( Authorization.EDIT ) ) { readOnly = true; nbEditModeMessage.Heading = "Information"; nbEditModeMessage.Text = EditModeMessage.ReadOnlyEditActionNotAllowed( WorkflowType.FriendlyTypeName ); } if ( workflowType.IsSystem ) { readOnly = true; nbEditModeMessage.Heading = "Information"; nbEditModeMessage.Text = EditModeMessage.ReadOnlySystem( WorkflowType.FriendlyTypeName ); } if ( readOnly ) { btnEdit.Visible = false; btnSecurity.Visible = false; ShowReadonlyDetails( workflowType ); } else { btnEdit.Visible = true; btnSecurity.Title = "Secure " + workflowType.Name; btnSecurity.EntityId = workflowType.Id; if ( workflowType.Id > 0 ) { ShowReadonlyDetails( workflowType ); } else { LoadStateDetails(workflowType, rockContext); ShowEditDetails( workflowType, rockContext ); } } }
private void CreateNewWorkfow(WorkflowType workflowType) { var file = new WorkflowFileViewModel(workflowType, ++dirtyCounter); files.Add(file); ActiveWorkflowFile = file; SubscribeToFileEvents(file); }
/// <summary> /// Adds the person to group. /// </summary> /// <param name="rockContext">The rock context.</param> /// <param name="person">The person.</param> /// <param name="workflowType">Type of the workflow.</param> /// <param name="groupMembers">The group members.</param> private void AddPersonToGroup( RockContext rockContext, Person person, WorkflowType workflowType, List<GroupMember> groupMembers ) { if (person != null ) { if ( !_group.Members .Any( m => m.PersonId == person.Id && m.GroupRoleId == _defaultGroupRole.Id)) { var groupMemberService = new GroupMemberService(rockContext); var groupMember = new GroupMember(); groupMember.PersonId = person.Id; groupMember.GroupRoleId = _defaultGroupRole.Id; groupMember.GroupMemberStatus = (GroupMemberStatus)GetAttributeValue("GroupMemberStatus").AsInteger(); groupMember.GroupId = _group.Id; groupMemberService.Add( groupMember ); rockContext.SaveChanges(); if ( workflowType != null ) { try { List<string> workflowErrors; var workflow = Workflow.Activate( workflowType, person.FullName ); new WorkflowService( rockContext ).Process( workflow, groupMember, out workflowErrors ); } catch (Exception ex) { ExceptionLogService.LogException( ex, this.Context ); } } } } }
/// <summary> /// Launches the workflow. /// </summary> /// <param name="rockContext">The rock context.</param> /// <param name="connectionWorkflow">The connection workflow.</param> /// <param name="name">The name.</param> private void LaunchWorkflow( RockContext rockContext, Attendance attendance, PersonAlias pagePersonAlias, WorkflowType pageWorkflowType ) { if ( pageWorkflowType != null ) { var workflow = Rock.Model.Workflow.Activate( pageWorkflowType, pageWorkflowType.WorkTerm, rockContext ); if ( workflow != null ) { workflow.SetAttributeValue( "Person", attendance.PersonAlias.Guid ); workflow.SetAttributeValue( "PagePerson", pagePersonAlias.Guid ); var workflowService = new Rock.Model.WorkflowService( rockContext ); List<string> workflowErrors; if ( workflowService.Process( workflow, attendance, out workflowErrors ) ) { if ( workflow.Id != 0 ) { if ( workflow.HasActiveEntryForm( CurrentPerson ) ) { var qryParam = new Dictionary<string, string>(); qryParam.Add( "WorkflowTypeId", pageWorkflowType.Id.ToString() ); qryParam.Add( "WorkflowId", workflow.Id.ToString() ); NavigateToLinkedPage( "WorkflowEntryPage", qryParam ); } else { mdWorkflowLaunched.Show( string.Format( "A '{0}' workflow has been started.", pageWorkflowType.Name ), ModalAlertType.Information ); } } else { mdWorkflowLaunched.Show( string.Format( "A '{0}' workflow was processed (but not persisted).", pageWorkflowType.Name ), ModalAlertType.Information ); } } else { mdWorkflowLaunched.Show( "Workflow Processing Error(s):<ul><li>" + workflowErrors.AsDelimited( "</li><li>" ) + "</li></ul>", ModalAlertType.Information ); } return; } } Dictionary<string, string> qParams = new Dictionary<string, string>(); qParams.Add( "AttendanceId", attendance.Id.ToString() ); qParams.Add( "PagePersonId", pagePersonAlias.Person.Id.ToString() ); NavigateToLinkedPage( "WorkflowEntryPage", qParams ); }
/// <summary> /// Creates a new transient state. In transient states, some variables like the models are automatically /// inherited from the parent state. /// </summary> /// <param name="name">The human-readable name of the new state.</param> /// <param name="displayLabel">A human-readable label for the new state, to be used in the GUI.</param> /// <param name="mainScreen">The main screen to be shown in the new state.</param> /// <param name="inheritMenu">If set to <c>true</c>, the menu items of the parent state will be /// inherited.</param> /// <param name="workflowType">The workflow type of the new transient state.</param> /// <returns>New transient workflow state.</returns> public static WorkflowState CreateTransientState(string name, string displayLabel, bool isTemporary, string mainScreen, bool inheritMenu, WorkflowType workflowType) { return new WorkflowState(Guid.NewGuid(), name, displayLabel, isTemporary, mainScreen, inheritMenu, true, null, workflowType); }
/// <summary> /// Builds the controls. /// </summary> /// <param name="setValues">if set to <c>true</c> [set values].</param> /// <param name="activeActivityTypeGuid">The active activity type unique identifier.</param> /// <param name="activeActionTypeGuid">The active action type unique identifier.</param> private void BuildControls( bool setValues = false, Guid? activeActivityTypeGuid = null, Guid? activeActionTypeGuid = null ) { phActivities.Controls.Clear(); if ( ActivityTypesState != null ) { // Add a workflowtype object to the Items collection that is used by attribute field types that may get qualifier from // the current workflow type (i.e. WorkflowActivityTypeAttribute var workflowType = new WorkflowType(); workflowType.ActivityTypes = ActivityTypesState; System.Web.HttpContext.Current.Items["WorkflowType"] = workflowType; // Save the current workflow type attributes to state for any action settings that may need them var workflowAttributes = new Dictionary<Guid, Attribute>(); AttributesState.OrderBy( a => a.Order ).ToList().ForEach( a => workflowAttributes.Add( a.Guid, a ) ); System.Web.HttpContext.Current.Items["WorkflowTypeAttributes"] = workflowAttributes; if ( workflowAttributes.Any() ) { wpAttributes.Title = string.Format( "Attributes <small>Count: {0}</small>", workflowAttributes.Count.ToString( "N0" ) ); } else { wpAttributes.Title = "Attributes"; } foreach ( var workflowActivityType in ActivityTypesState.OrderBy( a => a.Order ) ) { BuildActivityControl( phActivities, setValues, workflowActivityType, workflowAttributes, activeActivityTypeGuid, activeActionTypeGuid ); } } }
/// <summary> /// Shows the detail. /// </summary> /// <param name="itemKey">The item key.</param> /// <param name="itemKeyValue">The item key value.</param> /// <param name="parentCategoryId">The parent category id.</param> public void ShowDetail( string itemKey, int itemKeyValue, int? parentCategoryId ) { if ( !itemKey.Equals( "workflowTypeId" ) ) { pnlDetails.Visible = false; return; } var rockContext = new RockContext(); WorkflowType workflowType = null; if ( !itemKeyValue.Equals( 0 ) ) { workflowType = new WorkflowTypeService( rockContext ).Get( itemKeyValue ); } else { workflowType = new WorkflowType { Id = 0, IsActive = true, IsPersisted = true, IsSystem = false, CategoryId = parentCategoryId }; workflowType.ActivityTypes.Add( new WorkflowActivityType { Guid = Guid.NewGuid(), IsActive = true } ); } if ( workflowType == null ) { return; } pnlDetails.Visible = true; hfWorkflowTypeId.Value = workflowType.Id.ToString(); // render UI based on Authorized and IsSystem bool readOnly = false; nbEditModeMessage.Text = string.Empty; if ( !IsUserAuthorized( Authorization.EDIT ) ) { readOnly = true; nbEditModeMessage.Heading = "Information"; nbEditModeMessage.Text = EditModeMessage.ReadOnlyEditActionNotAllowed( WorkflowType.FriendlyTypeName ); } if ( workflowType.IsSystem ) { readOnly = true; nbEditModeMessage.Heading = "Information"; nbEditModeMessage.Text = EditModeMessage.ReadOnlySystem( WorkflowType.FriendlyTypeName ); } if ( readOnly ) { btnEdit.Visible = false; ShowReadonlyDetails( workflowType ); } else { btnEdit.Visible = true; if ( workflowType.Id > 0 ) { ShowReadonlyDetails( workflowType ); } else { ShowEditDetails( workflowType, rockContext ); } } }
private void LoadStateDetails( WorkflowType workflowType, RockContext rockContext ) { if ( workflowType != null ) { var attributeService = new AttributeService( rockContext ); AttributesState = attributeService .GetByEntityTypeId( new Workflow().TypeId ).AsQueryable() .Where( a => a.EntityTypeQualifierColumn.Equals( "WorkflowTypeId", StringComparison.OrdinalIgnoreCase ) && a.EntityTypeQualifierValue.Equals( workflowType.Id.ToString() ) ) .OrderBy( a => a.Order ) .ThenBy( a => a.Name ) .ToList(); ActivityTypesState = workflowType.ActivityTypes.OrderBy( a => a.Order ).ToList(); ActivityAttributesState = new Dictionary<Guid, List<Attribute>>(); foreach ( var activityType in ActivityTypesState ) { var activityTypeAttributes = attributeService .GetByEntityTypeId( new WorkflowActivity().TypeId ).AsQueryable() .Where( a => a.EntityTypeQualifierColumn.Equals( "ActivityTypeId", StringComparison.OrdinalIgnoreCase ) && a.EntityTypeQualifierValue.Equals( activityType.Id.ToString() ) ) .OrderBy( a => a.Order ) .ThenBy( a => a.Name ) .ToList(); ActivityAttributesState.Add( activityType.Guid, activityTypeAttributes ); foreach ( var actionType in activityType.ActionTypes ) { var action = EntityTypeCache.Read( actionType.EntityTypeId ); if ( action != null ) { Rock.Attribute.Helper.UpdateAttributes( action.GetEntityType(), actionType.TypeId, "EntityTypeId", actionType.EntityTypeId.ToString(), rockContext ); actionType.LoadAttributes( rockContext ); } } } } else { AttributesState = new List<Attribute>(); ActivityTypesState = new List<WorkflowActivityType>(); ActivityAttributesState = new Dictionary<Guid, List<Attribute>>(); } }
/// <summary> /// Shows the edit details. /// </summary> /// <param name="workflowType">Type of the workflow.</param> private void ShowEditDetails( WorkflowType workflowType, RockContext rockContext ) { if ( workflowType.Id == 0 ) { lReadOnlyTitle.Text = ActionTitle.Add( WorkflowType.FriendlyTypeName ).FormatAsHtmlTitle(); hlInactive.Visible = false; } SetEditMode( true ); LoadDropDowns(); tbName.Text = workflowType.Name; tbDescription.Text = workflowType.Description; cbIsActive.Checked = workflowType.IsActive ?? false; cpCategory.SetValue( workflowType.CategoryId ); tbWorkTerm.Text = workflowType.WorkTerm; tbProcessingInterval.Text = workflowType.ProcessingIntervalSeconds != null ? workflowType.ProcessingIntervalSeconds.ToString() : string.Empty; cbIsPersisted.Checked = workflowType.IsPersisted; ddlLoggingLevel.SetValue( (int)workflowType.LoggingLevel ); var attributeService = new AttributeService( rockContext ); AttributesState = new ViewStateList<Attribute>(); AttributesState.AddAll( attributeService.GetByEntityTypeId( new Workflow().TypeId ).AsQueryable() .Where( a => a.EntityTypeQualifierColumn.Equals( "WorkflowTypeId", StringComparison.OrdinalIgnoreCase ) && a.EntityTypeQualifierValue.Equals( workflowType.Id.ToString() ) ) .OrderBy( a => a.Order ) .ThenBy( a => a.Name ) .ToList() ); BindAttributesGrid(); phActivities.Controls.Clear(); foreach ( WorkflowActivityType workflowActivityType in workflowType.ActivityTypes.OrderBy( a => a.Order ) ) { CreateWorkflowActivityTypeEditorControls( workflowActivityType ); } RefreshActivityLists(); }
/// <summary> /// Shows the detail. /// </summary> private void ShowDetail() { int? workflowTypeId = PageParameter( "workflowTypeId" ).AsIntegerOrNull(); int? parentCategoryId = PageParameter( "ParentCategoryId" ).AsIntegerOrNull(); if ( !workflowTypeId.HasValue ) { pnlDetails.Visible = false; return; } var rockContext = new RockContext(); WorkflowType workflowType = null; if ( workflowTypeId.Value.Equals( 0 ) ) { workflowType = new WorkflowType(); workflowType.Id = 0; workflowType.IsActive = true; workflowType.IsPersisted = true; workflowType.IsSystem = false; workflowType.CategoryId = parentCategoryId; workflowType.IconCssClass = "fa fa-list-ol"; workflowType.ActivityTypes.Add( new WorkflowActivityType { Name = "Start", Guid = Guid.NewGuid(), IsActive = true, IsActivatedWithWorkflow = true } ); workflowType.WorkTerm = "Work"; workflowType.ProcessingIntervalSeconds = 28800; // Default to every 8 hours workflowType.SummaryViewText = GetAttributeValue( "DefaultSummaryViewText" ); workflowType.NoActionMessage = GetAttributeValue( "DefaultNoActionMessage" ); // hide the panel drawer that show created and last modified dates pdAuditDetails.Visible = false; } else { workflowType = new WorkflowTypeService( rockContext ).Get( workflowTypeId.Value ); pdAuditDetails.SetEntity( workflowType, ResolveRockUrl( "~" ) ); } if ( workflowType == null ) { return; } pnlDetails.Visible = true; hfWorkflowTypeId.Value = workflowType.Id.ToString(); // render UI based on Authorized and IsSystem bool readOnly = false; nbEditModeMessage.Text = string.Empty; // User must have 'Edit' rights to block, or 'Administrate' rights to workflow type if ( !IsUserAuthorized( Authorization.EDIT ) ) { readOnly = true; nbEditModeMessage.Heading = "Information"; nbEditModeMessage.Text = EditModeMessage.ReadOnlyEditActionNotAllowed( WorkflowType.FriendlyTypeName ); } if ( workflowType.IsSystem ) { readOnly = true; nbEditModeMessage.Heading = "Information"; nbEditModeMessage.Text = EditModeMessage.ReadOnlySystem( WorkflowType.FriendlyTypeName ); } if ( readOnly ) { btnEdit.Visible = false; btnSecurity.Visible = false; ShowReadonlyDetails( workflowType ); } else { btnEdit.Visible = true; btnSecurity.Title = "Secure " + workflowType.Name; btnSecurity.EntityId = workflowType.Id; if ( workflowType.Id > 0 ) { ShowReadonlyDetails( workflowType ); } else { LoadStateDetails(workflowType, rockContext); ShowEditDetails( workflowType, rockContext ); } } }
private void LaunchWorkflow( WorkflowType workflowType, FinancialTransaction transaction ) { if ( workflowType != null ) { using ( var rockContext = new RockContext() ) { string workflowName = transaction.TransactionCode; if ( transaction.AuthorizedPersonAliasId != null ) { var person = new PersonAliasService( rockContext ).GetPerson( transaction.AuthorizedPersonAliasId.Value ); if ( person != null ) { workflowName = person.FullName; } } var workflowService = new WorkflowService( rockContext ); var workflow = Rock.Model.Workflow.Activate( workflowType, workflowName, rockContext ); if ( workflow != null ) { List<string> workflowErrors; workflowService.Process( workflow, transaction, out workflowErrors ); } } } }
/// <summary> /// Adds the person to group. /// </summary> /// <param name="rockContext">The rock context.</param> /// <param name="person">The person.</param> /// <param name="workflowType">Type of the workflow.</param> /// <param name="groupMembers">The group members.</param> private void AddPersonToGroup( RockContext rockContext, Person person, WorkflowType workflowType, List<GroupMember> groupMembers ) { if (person != null ) { if ( !_group.Members .Any( m => m.PersonId == person.Id && m.GroupRoleId == _defaultGroupRole.Id)) { var groupMemberService = new GroupMemberService(rockContext); var groupMember = new GroupMember(); groupMember.PersonId = person.Id; groupMember.GroupRoleId = _defaultGroupRole.Id; groupMember.GroupMemberStatus = (GroupMemberStatus)GetAttributeValue("GroupMemberStatus").AsInteger(); groupMember.GroupId = _group.Id; groupMemberService.Add( groupMember ); rockContext.SaveChanges(); if ( workflowType != null ) { try { var workflowService = new WorkflowService( rockContext ); var workflow = Workflow.Activate( workflowType, person.FullName ); List<string> workflowErrors; if ( workflow.Process( rockContext, groupMember, out workflowErrors ) ) { if ( workflow.IsPersisted || workflow.IsPersisted ) { if ( workflow.Id == 0 ) { workflowService.Add( workflow ); } rockContext.WrapTransaction( () => { rockContext.SaveChanges(); workflow.SaveAttributeValues( _rockContext ); foreach ( var activity in workflow.Activities ) { activity.SaveAttributeValues( rockContext ); } } ); } } } catch (Exception ex) { ExceptionLogService.LogException( ex, this.Context ); } } } } }