Exemplo n.º 1
0
        private void step1CodeActivity_ShowDocument_ExecuteCode(object sender, EventArgs e)
        {
            IFormMarkupProvider markupProvider = new FormDefinitionFileMarkupProvider(@"\Administrative\UserGroupElementProviderEditUserGroupStep1.xml");

            XDocument formDocument;

            using (var reader = markupProvider.GetReader())
            {
                formDocument = XDocument.Load(reader);
            }

            XElement bindingsElement    = formDocument.Root.Element(DataTypeDescriptorFormsHelper.CmsNamespace + FormKeyTagNames.Bindings);
            XElement layoutElement      = formDocument.Root.Element(DataTypeDescriptorFormsHelper.CmsNamespace + FormKeyTagNames.Layout);
            XElement placeHolderElement = layoutElement.Element(DataTypeDescriptorFormsHelper.MainNamespace + "PlaceHolder");


            IUserGroup userGroup = this.GetBinding <IUserGroup>("UserGroup");

            UpdateFormDefinitionWithActivePerspectives(userGroup, bindingsElement, placeHolderElement);
            UpdateFormDefinitionWithGlobalPermissions(userGroup, bindingsElement, placeHolderElement);

            var clientValidationRules = new Dictionary <string, List <ClientValidationRule> >();

            clientValidationRules.Add("Name", ClientValidationRuleFacade.GetClientValidationRules(userGroup, "Name"));

            string formDefinition = formDocument.GetDocumentAsString();

            this.DeliverFormData(
                userGroup.Name,
                StandardUiContainerTypes.Document,
                formDefinition,
                this.Bindings,
                clientValidationRules
                );
        }
Exemplo n.º 2
0
        /// <exclude />
        public Dictionary <string, List <ClientValidationRule> > GetBindingsValidationRules(IData data)
        {
            Verify.ArgumentNotNull(data, "data");

            var result = new Dictionary <string, List <ClientValidationRule> >();

            foreach (var fieldDescriptor in _dataTypeDescriptor.Fields)
            {
                var rules = ClientValidationRuleFacade.GetClientValidationRules(data, fieldDescriptor.Name);

                result.Add(GetBindingName(fieldDescriptor), rules);
            }

            return(result);
        }
        private static string FilterInvalidCharacters(string pageTitle)
        {
            var regexClientValidationRule =
                ClientValidationRuleFacade.GetClientValidationRules(typeof(IPage), "UrlTitle")
                .OfType <RegexClientValidationRule>().Single();

            var generated = new StringBuilder();
            var regex     = new Regex(regexClientValidationRule.Expression);

            foreach (char c in pageTitle)
            {
                var matchString = new string(c, 1);
                if (regex.IsMatch(matchString))
                {
                    generated.Append(c);
                }
            }

            return(generated.ToString());
        }
Exemplo n.º 4
0
        private static void EvalutePropertyBinding(ElementCompileTreeNode element, PropertyCompileTreeNode property, CompileContext compileContext, MethodInfo sourceGetMethodInfo, string bindSourceName, string[] propertyPath, bool makeBinding)
        {
            if (makeBinding)
            {
                bool?optional = ((BindingsProducer)compileContext.BindingsProducer).GetOptionalValueByName(bindSourceName);
                if (!optional.HasValue)
                {
                    throw new FormCompileException(string.Format("{1} binds to an undeclared binding name '{0}'. All binding names must be declared in /cms:formdefinition/cms:bindings", bindSourceName, element.XmlSourceNodeInformation.XPath), element, property);
                }
                if (optional.Value)
                {
                    throw new FormCompileException(string.Format("Property binding to the optional object named '{0}' is not allowed", bindSourceName), element, property);
                }

                if (compileContext.IsUniqueSourceObjectBinding(bindSourceName))
                {
                    throw new FormCompileException(string.Format("{0} binds to {1} which is already object bound. Property bindings to a source object which is object bound is not allowed.", element.XmlSourceNodeInformation.XPath, bindSourceName), element, property);
                }

                var uniquePropertyName = new StringBuilder();
                for (int i = 0; i < propertyPath.Length; ++i)
                {
                    uniquePropertyName.Append(propertyPath[i]);
                }
                if (!compileContext.RegisterUniqueSourcePropertyBinding(bindSourceName, uniquePropertyName.ToString()))
                {
                    throw new FormCompileException(string.Format("{0} binds to {1} which is already bound. Multiple bindings to the same source object property is not allowed.", element.XmlSourceNodeInformation.XPath, uniquePropertyName), element, property);
                }
            }


            object     value, propertyOwner;
            MethodInfo getMethodInfo, setMethodInfo;
            string     propertyName;
            Type       type;

            ResolvePropertyBinding(element, property, compileContext, bindSourceName, propertyPath,
                                   out value, out type, out propertyOwner, out propertyName, out getMethodInfo, out setMethodInfo);

            if (makeBinding)
            {
                if (setMethodInfo == null)
                {
                    throw new FormCompileException(string.Format("The type {0} does not have a set property named {1}", type, propertyName), element, property);
                }

                compileContext.Rebindings.Add(new CompileContext.PropertyRebinding(
                                                  element.Producer,
                                                  sourceGetMethodInfo,
                                                  propertyOwner,
                                                  setMethodInfo,
                                                  getMethodInfo.ReturnType,
                                                  bindSourceName,
                                                  propertyName));
            }

            property.Value = value;

            IUiControl uiControl = element.Producer as IUiControl;

            if (uiControl != null)
            {
                uiControl.ClientValidationRules = ClientValidationRuleFacade.GetClientValidationRules(propertyOwner, propertyName);
            }
        }
        private void initializeCodeActivity_ExecuteCode(object sender, EventArgs e)
        {
            var dataEntityToken = (DataEntityToken)this.EntityToken;

            var user          = (IUser)dataEntityToken.Data;
            var userFormLogin = user.GetUserFormLogin();

            this.Bindings.Add(BindingNames.User, user);
            this.Bindings.Add(BindingNames.UserFormLogin, userFormLogin);
            this.Bindings.Add(BindingNames.NewPassword, NotPassword);

            CultureInfo userCulture         = UserSettings.GetUserCultureInfo(user.Username);
            CultureInfo c1ConsoleUiLanguage = UserSettings.GetUserC1ConsoleUiLanguage(user.Username);

            List <KeyValuePair>         regionLanguageList = StringResourceSystemFacade.GetSupportedCulturesList();
            Dictionary <string, string> culturesDictionary = StringResourceSystemFacade.GetAllCultures();

            this.Bindings.Add("AllCultures", culturesDictionary);
            this.Bindings.Add("CultureName", userCulture.Name);

            this.Bindings.Add("C1ConsoleUiCultures", regionLanguageList);
            this.Bindings.Add("C1ConsoleUiLanguageName", c1ConsoleUiLanguage.Name);

            if (UserSettings.GetActiveLocaleCultureInfos(user.Username).Any() && (user.Username != UserSettings.Username))
            {
                this.Bindings.Add("ActiveLocaleName", UserSettings.GetCurrentActiveLocaleCultureInfo(user.Username).Name);
                this.Bindings.Add("ActiveLocaleList", DataLocalizationFacade.ActiveLocalizationCultures.ToDictionary(f => f.Name, DataLocalizationFacade.GetCultureTitle));
            }

            var clientValidationRules = new Dictionary <string, List <ClientValidationRule> >
            {
                { "Username", ClientValidationRuleFacade.GetClientValidationRules(user, "Username") },
                { "Group", ClientValidationRuleFacade.GetClientValidationRules(user, "Group") }
            };


            IFormMarkupProvider markupProvider = new FormDefinitionFileMarkupProvider(@"\Administrative\EditUserStep1.xml");

            XDocument formDocument;

            using (var reader = markupProvider.GetReader())
            {
                formDocument = XDocument.Load(reader);
            }

            XElement        bindingsElement     = formDocument.Root.Element(DataTypeDescriptorFormsHelper.CmsNamespace + FormKeyTagNames.Bindings);
            XElement        layoutElement       = formDocument.Root.Element(DataTypeDescriptorFormsHelper.CmsNamespace + FormKeyTagNames.Layout);
            XElement        tabPanelsElement    = layoutElement.Element(DataTypeDescriptorFormsHelper.MainNamespace + "TabPanels");
            List <XElement> placeHolderElements = tabPanelsElement.Elements(DataTypeDescriptorFormsHelper.MainNamespace + "PlaceHolder").ToList();

            UpdateFormDefinitionWithUserGroups(user, bindingsElement, placeHolderElements[1]);
            UpdateFormDefinitionWithActivePerspectives(user, bindingsElement, placeHolderElements[2]);
            //UpdateFormDefinitionWithGlobalPermissions(user, bindingsElement, placeHolderElements[1]);

            if (DataLocalizationFacade.ActiveLocalizationCultures.Any())
            {
                UpdateFormDefinitionWithActiveLocales(user, bindingsElement, placeHolderElements[1]);
            }

            string formDefinition = formDocument.GetDocumentAsString();

            this.DeliverFormData(
                user.Username,
                StandardUiContainerTypes.Document,
                formDefinition,
                this.Bindings,
                clientValidationRules
                );
        }