예제 #1
0
        public int UpdateFrom6()
        {
            SchemaBuilder.AlterTable("DynamicButtonToWorkflowsRecord", table => table
                                     .AddColumn <string>("GlobalIdentifier")
                                     );

            var buttonsWithoutGuid = _dynamicButtonToWorkflowsService.GetButtons().Where(w => String.IsNullOrWhiteSpace(w.GlobalIdentifier));

            if (buttonsWithoutGuid.Count() > 0)
            {
                List <DynamicButtonToWorkflowsEdit> buttonList = new List <DynamicButtonToWorkflowsEdit>();
                var activities       = _activityRepository.Table.Where(w => w.Name.Equals("DynamicButtonEvent"));
                var typesWithButtons = _contentDefinitionManager.ListTypeDefinitions().Where(w => w.Parts.Any(p => p.PartDefinition.Name == "DynamicButtonToWorkflowsPart")).ToList();

                foreach (var button in buttonsWithoutGuid)
                {
                    // Associo un Guid a tutti i bottoni già esistenti che non ne hanno uno
                    DynamicButtonToWorkflowsEdit buttonData = new DynamicButtonToWorkflowsEdit();
                    buttonData.Id                = button.Id;
                    buttonData.ButtonText        = button.ButtonText;
                    buttonData.ButtonAsync       = button.ButtonAsync;
                    buttonData.ButtonDescription = button.ButtonDescription;
                    buttonData.ButtonMessage     = button.ButtonMessage;
                    buttonData.ButtonName        = button.ButtonName;
                    buttonData.GlobalIdentifier  = Guid.NewGuid().ToString();
                    buttonData.Delete            = false;

                    buttonList.Add(buttonData);

                    // Correggo i riferimenti ai bottoni nelle parti
                    string partSettingToEdit = string.Format("{{{0}}}", button.Id);

                    foreach (var type in typesWithButtons)
                    {
                        var part = type.Parts.Where(w => w.PartDefinition.Name == "DynamicButtonToWorkflowsPart").FirstOrDefault();
                        if (part != null)
                        {
                            part.Settings["DynamicButtonsSetting.Buttons"] = part.Settings["DynamicButtonsSetting.Buttons"].Replace(partSettingToEdit, string.Format("{{{0}}}", buttonData.GlobalIdentifier));
                            _contentDefinitionManager.StoreTypeDefinition(type);
                        }
                    }

                    // Correggo i riferimenti ai bottoni nelle activities dei workflows
                    string activitySettingToEdit = string.Format("\"DynamicButton\":\"{0}\"", button.Id);
                    var    activitiesWithButton  = activities.Where(w => w.State.Contains(activitySettingToEdit));

                    foreach (var activity in activitiesWithButton)
                    {
                        activity.State = activity.State.Replace(activitySettingToEdit, string.Format("\"DynamicButton\":\"{0}\"", buttonData.GlobalIdentifier));
                        _activityRepository.Update(activity);
                    }
                }

                _dynamicButtonToWorkflowsService.UpdateButtons(buttonList);
                _activityRepository.Flush();
            }

            return(7);
        }
예제 #2
0
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            DynamicButtonToWorkflowsEdit dynButtonEditVM = (DynamicButtonToWorkflowsEdit)value;

            if (dynButtonEditVM.Delete)
            {
                return(ValidationResult.Success);
            }
            else
            {
                if (String.IsNullOrWhiteSpace(dynButtonEditVM.ButtonName))
                {
                    return(new ValidationResult(T("The Button Name field is required.").Text));
                }
                else
                {
                    return(ValidationResult.Success);
                }
            }
        }