コード例 #1
0
        /// <summary>
        /// Creates the test step program.
        /// There are 2 step statuses: 1 complete and 1 in-progress
        /// There are 4 step types:
        ///     1) Allow multiple with an auto-complete dataview
        ///     2) Allow multiple without an autocomplete dataview
        ///     3) No multiple with an auto-complete dataview
        ///     4) No multiple with no auto-complete dataview
        /// </summary>
        private static void CreateTestStepProgram()
        {
            var rockContext        = new RockContext();
            var stepProgramService = new StepProgramService(rockContext);

            var dataViewService = new DataViewService(rockContext);
            var dataView        = dataViewService.Queryable().FirstOrDefault(dv => dv.ForeignKey == ForeignKey);

            var stepProgram = new StepProgram
            {
                Name         = "Test",
                ForeignKey   = ForeignKey,
                StepStatuses = new List <StepStatus> {
                    new StepStatus
                    {
                        ForeignKey       = ForeignKey,
                        Name             = "Complete",
                        IsCompleteStatus = true
                    },
                    new StepStatus
                    {
                        ForeignKey       = ForeignKey,
                        Name             = "In-progress",
                        IsCompleteStatus = false
                    }
                },
                StepTypes = new List <StepType>
                {
                    new StepType
                    {
                        Name                 = "Test: AllowMultiple with DataView",
                        ForeignKey           = ForeignKey,
                        AllowMultiple        = true,
                        AutoCompleteDataView = dataView
                    },
                    new StepType
                    {
                        Name          = "Test: AllowMultiple without DataView",
                        ForeignKey    = ForeignKey,
                        AllowMultiple = true
                    },
                    new StepType
                    {
                        Name                 = "Test: No multiple with DataView",
                        ForeignKey           = ForeignKey,
                        AllowMultiple        = false,
                        AutoCompleteDataView = dataView
                    },
                    new StepType
                    {
                        Name          = "Test: No multiple and no dataview",
                        ForeignKey    = ForeignKey,
                        AllowMultiple = false
                    }
                }
            };

            stepProgramService.Add(stepProgram);
            rockContext.SaveChanges();
        }
コード例 #2
0
 bool RunOneStepProgram(string name)
 {
     try
     {
         StepProgram stpProgram = easyRanger.GetStepProgram(Name);
         stpProgram.RunFromBeginning();
         foreach (Step stp in stpProgram.StepList)
         {
             if (stp.Enabled)
             {
                 if (!stp.Success)
                 {
                     mySyncContext.Post(delegate
                     {
                         updateLogMsg("Step #" + stp.Index + " in step program [" + stpProgram.Name + "] failed, error:" + easyRanger.GetLastErrorMessage());
                     }, null);
                     return(false);
                 }
             }
         }
         mySyncContext.Post(delegate
         {
             updateLogMsg("Step program [" + name + "] finished successfully!");
         }, null);
         return(true);
     }
     catch (Exception ex)
     {
         mySyncContext.Post(delegate
         {
             updateLogMsg("Step program [" + name + "] failed, error:" + ex.ToString());
         }, null);
         return(false);
     }
 }
コード例 #3
0
 /// <summary>
 /// Clears the block data.
 /// </summary>
 private void ClearBlockData()
 {
     _rockContext    = null;
     _personStepsMap = null;
     _person         = null;
     _stepProgram    = null;
     _stepTerm       = null;
     _stepTypes      = null;
 }
コード例 #4
0
ファイル: StepBulkEntry.ascx.cs プロジェクト: waldo2590/Rock
 /// <summary>
 /// Clears the block data.
 /// </summary>
 private void ClearBlockData()
 {
     _rockContext        = null;
     _stepProgramService = null;
     _stepProgram        = null;
     _stepType           = null;
     _person             = null;
     _personService      = null;
 }
コード例 #5
0
        //Get Step Name
        public List <string> StepNameList(StepProgram stepProgram)
        {
            List <string> stepNameList = new List <string>();

            foreach (Step stp in stepProgram.StepList)
            {
                stepNameList.Add(stp.Name);
            }
            return(stepNameList);
        }
コード例 #6
0
        /// <summary>
        /// Populates the selection lists for Step Type and Step Status.
        /// </summary>
        /// <param name="filterField">The filter field.</param>
        private void PopulateStepProgramRelatedSelectionLists(FilterField filterField)
        {
            var dataContext = new RockContext();

            var programService = new StepProgramService(dataContext);

            SingleEntityPicker <StepProgram> stepProgramSingleEntityPicker = filterField.ControlsOfTypeRecursive <SingleEntityPicker <StepProgram> >().FirstOrDefault(c => c.HasCssClass("js-step-program-picker"));
            RockCheckBoxList cblStepType    = filterField.ControlsOfTypeRecursive <RockCheckBoxList>().FirstOrDefault(c => c.HasCssClass("js-step-type"));
            RockCheckBoxList _cblStepStatus = filterField.ControlsOfTypeRecursive <RockCheckBoxList>().FirstOrDefault(c => c.HasCssClass("js-step-status"));

            int?stepProgramId = stepProgramSingleEntityPicker.SelectedId;

            StepProgram stepProgram = null;

            if (stepProgramId != null)
            {
                stepProgram = programService.Get(stepProgramId.Value);
            }

            if (stepProgram != null)
            {
                // Step Type list
                cblStepType.Items.Clear();

                var stepTypeService = new StepTypeService(dataContext);

                var stepTypes = stepTypeService.Queryable().Where(x => x.StepProgramId == stepProgramId);

                foreach (var item in stepTypes)
                {
                    cblStepType.Items.Add(new ListItem(item.Name, item.Guid.ToString()));
                }

                cblStepType.Visible = cblStepType.Items.Count > 0;

                // Step Status list
                _cblStepStatus.Items.Clear();

                var stepStatusService = new StepStatusService(dataContext);

                var stepStatuses = stepStatusService.Queryable().Where(x => x.StepProgramId == stepProgramId);

                foreach (var item in stepStatuses)
                {
                    _cblStepStatus.Items.Add(new ListItem(item.Name, item.Guid.ToString()));
                }

                _cblStepStatus.Visible = _cblStepStatus.Items.Count > 0;
            }
            else
            {
                cblStepType.Visible    = false;
                _cblStepStatus.Visible = false;
            }
        }
コード例 #7
0
        /// <summary>
        /// Sets the selection.
        /// </summary>
        /// <param name="entityType">Type of the entity.</param>
        /// <param name="controls">The controls.</param>
        /// <param name="selection">The selection.</param>
        public override void SetSelection(Type entityType, Control[] controls, string selection)
        {
            var stepProgramPicker = (controls[0] as SingleEntityPicker <StepProgram>);
            var cblStepTypes      = (controls[1] as RockCheckBoxList);
            var cblStepStatuses   = (controls[2] as RockCheckBoxList);
            var sdpDateStarted    = (controls[3] as SlidingDateRangePicker);
            var sdpDateCompleted  = (controls[4] as SlidingDateRangePicker);
            var cblStepCampuses   = (controls[5] as RockCheckBoxList);

            var settings = new FilterSettings(selection);

            // Step Program
            var dataContext = new RockContext();

            StepProgram stepProgram = null;

            if (settings.StepProgramGuid.HasValue)
            {
                stepProgram = new StepProgramService(dataContext).Get(settings.StepProgramGuid.Value);
            }

            int?stepProgramId = null;

            if (stepProgram != null)
            {
                stepProgramId = stepProgram.Id;
            }

            stepProgramPicker.SetValue(stepProgramId);
            var filterField = stepProgramPicker.FirstParentControlOfType <FilterField>();

            PopulateStepProgramRelatedSelectionLists(filterField);

            foreach (var item in cblStepTypes.Items.OfType <ListItem>())
            {
                item.Selected = settings.StepTypeGuids.Contains(item.Value.AsGuid());
            }

            foreach (var item in cblStepStatuses.Items.OfType <ListItem>())
            {
                item.Selected = settings.StepStatusGuids.Contains(item.Value.AsGuid());
            }

            sdpDateStarted.DelimitedValues = settings.StartedInPeriod.ToDelimitedString();

            sdpDateCompleted.DelimitedValues = settings.CompletedInPeriod.ToDelimitedString();

            PopulateStepCampuses(cblStepCampuses);

            foreach (var item in cblStepCampuses.Items.OfType <ListItem>())
            {
                item.Selected = settings.StepCampusGuids.Contains(item.Value.AsGuid());
            }
        }
コード例 #8
0
        /// <summary>
        /// Populates the selection lists for Step Type and Step Status.
        /// </summary>
        /// <param name="stepProgramId">The Step Program identifier.</param>
        private void PopulateStepProgramRelatedSelectionLists(int?stepProgramId)
        {
            var dataContext = new RockContext();

            var programService = new StepProgramService(dataContext);

            StepProgram stepProgram = null;

            if (stepProgramId != null)
            {
                stepProgram = programService.Get(stepProgramId.Value);
            }

            if (stepProgram != null)
            {
                // Step Type list
                _cblStepType.Items.Clear();

                var stepTypeService = new StepTypeService(dataContext);

                var stepTypes = stepTypeService.Queryable().Where(x => x.StepProgramId == stepProgramId);

                foreach (var item in stepTypes)
                {
                    _cblStepType.Items.Add(new ListItem(item.Name, item.Guid.ToString()));
                }

                _cblStepType.Visible = _cblStepType.Items.Count > 0;

                // Step Status list
                _cblStepStatus.Items.Clear();

                var stepStatusService = new StepStatusService(dataContext);

                var stepStatuses = stepStatusService.Queryable().Where(x => x.StepProgramId == stepProgramId);

                foreach (var item in stepStatuses)
                {
                    _cblStepStatus.Items.Add(new ListItem(item.Name, item.Guid.ToString()));
                }

                _cblStepStatus.Visible = _cblStepStatus.Items.Count > 0;
            }
            else
            {
                _cblStepType.Visible   = false;
                _cblStepStatus.Visible = false;
            }
        }
コード例 #9
0
        private StepStatus AddStepStatusToStepProgram(StepProgram program, Guid guid, string name, bool isCompleteStatus, string colorCode, int order)
        {
            var newStatus = new StepStatus();

            newStatus.Guid             = guid;
            newStatus.Name             = name;
            newStatus.IsActive         = true;
            newStatus.Order            = order;
            newStatus.IsCompleteStatus = isCompleteStatus;
            newStatus.StatusColor      = colorCode;
            newStatus.ForeignKey       = _SampleDataForeignKey;

            program.StepStatuses.Add(newStatus);

            return(newStatus);
        }
コード例 #10
0
        private StepType AddStepTypeToStepProgram(StepProgram program, Guid guid, string name, string iconCssClass, int order, bool hasEndDate = false, string description = null)
        {
            var newType = new StepType();

            newType.Guid         = guid;
            newType.Name         = name;
            newType.Description  = description;
            newType.IconCssClass = iconCssClass;
            newType.HasEndDate   = hasEndDate;
            newType.IsActive     = true;
            newType.Order        = order;
            newType.ForeignKey   = _SampleDataForeignKey;

            program.StepTypes.Add(newType);

            return(newType);
        }
コード例 #11
0
        private StepProgram CreateStepProgram(Guid guid, Guid categoryGuid, string name, string description, string iconCssClass, int order)
        {
            var newProgram = new StepProgram();

            var categoryId = CategoryCache.Get(categoryGuid).Id;

            newProgram.Guid         = guid;
            newProgram.Name         = name;
            newProgram.Description  = description;
            newProgram.CategoryId   = categoryId;
            newProgram.Order        = order;
            newProgram.IconCssClass = iconCssClass;

            newProgram.ForeignKey = _SampleDataForeignKey;

            return(newProgram);
        }
コード例 #12
0
        /// <summary>
        /// Create step program data
        /// </summary>
        private static void CreateStepProgramData()
        {
            var tedDeckerGuid = TestGuids.TestPeople.TedDecker.AsGuid();
            var personAlias   = new PersonAliasService(_rockContext).Queryable().First(pa => pa.Person.Guid == tedDeckerGuid);

            _personAliasId = personAlias.Id;

            var stepProgram = new StepProgram
            {
                Guid       = new Guid(StepProgramGuidString),
                Name       = "Testing Program",
                ForeignKey = KEY
            };

            for (var i = 0; i < STEP_TYPE_COUNT; i++)
            {
                var stepType = new StepType
                {
                    Name       = $"Step Type {i}",
                    ForeignKey = KEY
                };

                if (i < COMPLETE_COUNT)
                {
                    stepType.Steps.Add(new Step
                    {
                        StartDateTime     = RockDateTime.Today.AddDays(-1),
                        CompletedDateTime = RockDateTime.Today,
                        PersonAliasId     = _personAliasId,
                        ForeignKey        = KEY
                    });
                }

                stepProgram.StepTypes.Add(stepType);
            }

            _stepProgramService.Add(stepProgram);
            _rockContext.SaveChanges(true);
        }
コード例 #13
0
        /// <summary>
        /// Gets the models from the delimited values.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="stepProgram">The step program</param>
        /// <param name="stepType">The step type</param>
        private void GetModelsFromAttributeValue(string value, out StepProgram stepProgram, out StepType stepType)
        {
            stepProgram = null;
            stepType    = null;

            ParseDelimitedGuids(value, out var stepProgramGuid, out var stepTypeGuid);

            if (stepProgramGuid.HasValue || stepTypeGuid.HasValue)
            {
                var rockContext = new RockContext();

                if (stepProgramGuid.HasValue)
                {
                    var stepProgramService = new StepProgramService(rockContext);
                    stepProgram = stepProgramService.Queryable().AsNoTracking().FirstOrDefault(sp => sp.Guid == stepProgramGuid.Value);
                }

                if (stepTypeGuid.HasValue)
                {
                    var stepTypeService = new StepTypeService(rockContext);
                    stepType = stepTypeService.Queryable().AsNoTracking().FirstOrDefault(sp => sp.Guid == stepTypeGuid.Value);
                }
            }
        }
コード例 #14
0
        /// <summary>
        /// Initialize the essential context in which this block is operating.
        /// </summary>
        /// <returns>True, if the block context is valid.</returns>
        private bool InitializeBlockContext()
        {
            _program = null;

            // Try to load the Step Program from the cache.
            var programGuid = GetAttributeValue(AttributeKey.StepProgram).AsGuid();

            int    programId = 0;
            string sharedItemKey;

            // If a Step Program is specified in the block settings use it, otherwise use the PageParameters.
            if (programGuid != Guid.Empty)
            {
                sharedItemKey = string.Format("{0}:{1}", PageParameterKey.StepProgramId, programGuid);
            }
            else
            {
                programId = PageParameter(PageParameterKey.StepProgramId).AsInteger();

                sharedItemKey = string.Format("{0}:{1}", PageParameterKey.StepProgramId, programId);
            }

            if (!string.IsNullOrEmpty(sharedItemKey))
            {
                _program = RockPage.GetSharedItem(sharedItemKey) as StepProgram;
            }

            // Retrieve the program from the data store and cache for subsequent use.
            if (_program == null)
            {
                var dataContext = this.GetDataContext();

                var stepProgramService = new StepProgramService(dataContext);

                if (programGuid != Guid.Empty)
                {
                    _program = stepProgramService.Queryable().Where(g => g.Guid == programGuid).FirstOrDefault();
                }
                else if (programId != 0)
                {
                    _program = stepProgramService.Queryable().Where(g => g.Id == programId).FirstOrDefault();
                }

                if (_program != null)
                {
                    RockPage.SaveSharedItem(sharedItemKey, _program);
                }
            }

            // Verify the Step Program is valid.
            if (_program == null)
            {
                this.ShowNotification("There are no Step Types available in this context.", NotificationBoxType.Info, true);
                return(false);
            }

            // Check for View permissions.
            if (!_program.IsAuthorized(Authorization.VIEW, CurrentPerson))
            {
                this.ShowNotification("Sorry, you are not authorized to view this content.", NotificationBoxType.Danger, true);
                return(false);
            }

            return(true);
        }
コード例 #15
0
        /// <summary>
        /// Creates the test step program.
        /// There are 2 step statuses: 1 complete and 1 in-progress
        /// There are 4 step types.
        ///
        /// Jerry completed the program with two aliases
        /// Simon started the program
        /// Kathy completed the program 2x
        /// Barry started the program
        /// </summary>
        private static void CreateTestStepProgram()
        {
            var rockContext        = new RockContext();
            var stepProgramService = new StepProgramService(rockContext);
            var personService      = new PersonService(rockContext);

            var barryAliasId = personService.Get(BarryBopPersonGuidString.AsGuid()).PrimaryAliasId.Value;
            var kathyAliasId = personService.Get(KathyKolePersonGuidString.AsGuid()).PrimaryAliasId.Value;
            var simonAliasId = personService.Get(SimonSandsPersonGuidString.AsGuid()).PrimaryAliasId.Value;

            var jerryAliases  = personService.Get(JerryJenkinsPersonGuidString.AsGuid()).Aliases.ToList();
            var jerryAliasId1 = jerryAliases[0].Id;
            var jerryAliasId2 = jerryAliases[1].Id;

            var stepProgram = new StepProgram
            {
                Name         = "Test",
                ForeignKey   = ForeignKey,
                StepStatuses = new List <StepStatus> {
                    new StepStatus
                    {
                        ForeignKey       = ForeignKey,
                        Name             = "Complete",
                        IsCompleteStatus = true
                    },
                    new StepStatus
                    {
                        ForeignKey       = ForeignKey,
                        Name             = "In-progress",
                        IsCompleteStatus = false
                    }
                },
                StepTypes = new List <StepType>
                {
                    new StepType
                    {
                        Name          = "Test: Step Type 1",
                        ForeignKey    = ForeignKey,
                        AllowMultiple = true,
                        Steps         = new [] {
                            new Step {
                                PersonAliasId     = jerryAliasId2,
                                CompletedDateTime = new DateTime(2019, 2, 1),
                                StartDateTime     = new DateTime(2019, 1, 1),
                                ForeignKey        = ForeignKey
                            },
                            new Step {
                                PersonAliasId     = simonAliasId,
                                CompletedDateTime = new DateTime(2019, 2, 1),
                                StartDateTime     = new DateTime(2019, 1, 1),
                                ForeignKey        = ForeignKey
                            },
                            new Step {
                                PersonAliasId     = barryAliasId,
                                CompletedDateTime = new DateTime(2019, 2, 1),
                                StartDateTime     = new DateTime(2019, 1, 1),
                                ForeignKey        = ForeignKey
                            },
                            new Step {
                                PersonAliasId     = barryAliasId,
                                CompletedDateTime = new DateTime(2019, 2, 1),
                                StartDateTime     = new DateTime(2019, 1, 1),
                                ForeignKey        = ForeignKey
                            },
                            new Step {
                                PersonAliasId     = kathyAliasId,
                                CompletedDateTime = new DateTime(2020, 2, 1),
                                StartDateTime     = new DateTime(2020, 1, 1),
                                ForeignKey        = ForeignKey
                            },
                            new Step {
                                PersonAliasId     = kathyAliasId,
                                CompletedDateTime = new DateTime(2019, 2, 1),
                                StartDateTime     = new DateTime(2019, 1, 1),
                                ForeignKey        = ForeignKey
                            },
                        }
                    },
                    new StepType
                    {
                        Name          = "Test: Step Type 2",
                        ForeignKey    = ForeignKey,
                        AllowMultiple = true,
                        Steps         = new [] {
                            new Step {
                                PersonAliasId     = jerryAliasId1,
                                CompletedDateTime = new DateTime(2020, 3, 1),
                                StartDateTime     = new DateTime(2020, 1, 1),
                                ForeignKey        = ForeignKey
                            },
                            new Step {
                                PersonAliasId     = kathyAliasId,
                                CompletedDateTime = new DateTime(2020, 2, 1),
                                StartDateTime     = new DateTime(2020, 1, 1),
                                ForeignKey        = ForeignKey
                            },
                            new Step {
                                PersonAliasId     = kathyAliasId,
                                CompletedDateTime = new DateTime(2019, 2, 1),
                                StartDateTime     = new DateTime(2019, 1, 1),
                                ForeignKey        = ForeignKey
                            },
                        }
                    },
                    new StepType
                    {
                        Name          = "Test: Step Type 3",
                        ForeignKey    = ForeignKey,
                        AllowMultiple = false,
                        Steps         = new [] {
                            new Step {
                                PersonAliasId     = jerryAliasId1,
                                CompletedDateTime = new DateTime(2020, 2, 1),
                                StartDateTime     = new DateTime(2020, 1, 1),
                                ForeignKey        = ForeignKey
                            },
                            new Step {
                                PersonAliasId     = kathyAliasId,
                                CompletedDateTime = new DateTime(2020, 2, 1),
                                StartDateTime     = new DateTime(2020, 1, 1),
                                ForeignKey        = ForeignKey
                            },
                            new Step {
                                PersonAliasId     = kathyAliasId,
                                CompletedDateTime = new DateTime(2019, 2, 1),
                                StartDateTime     = new DateTime(2019, 1, 1),
                                ForeignKey        = ForeignKey
                            },
                        }
                    },
                    new StepType
                    {
                        Name          = "Test: Step Type 4",
                        ForeignKey    = ForeignKey,
                        AllowMultiple = false,
                        Steps         = new [] {
                            new Step {
                                PersonAliasId     = jerryAliasId1,
                                CompletedDateTime = new DateTime(2020, 2, 1),
                                StartDateTime     = new DateTime(2020, 1, 1),
                                ForeignKey        = ForeignKey
                            },
                            new Step {
                                PersonAliasId     = kathyAliasId,
                                CompletedDateTime = new DateTime(2020, 2, 1),
                                StartDateTime     = new DateTime(2020, 1, 1),
                                ForeignKey        = ForeignKey
                            },
                            new Step {
                                PersonAliasId     = kathyAliasId,
                                CompletedDateTime = new DateTime(2019, 4, 1),
                                StartDateTime     = new DateTime(2019, 1, 1),
                                ForeignKey        = ForeignKey
                            },
                        }
                    }
                }
            };

            stepProgramService.Add(stepProgram);
            rockContext.SaveChanges();
        }