Beispiel #1
0
        /// <summary>
        /// Clones this instance.
        /// </summary>
        /// <returns>A clone of the code element.</returns>
        protected override CodeElement DoClone()
        {
            AttributeElement clone = new AttributeElement();

            clone._target = _target;

            return(clone);
        }
Beispiel #2
0
        /// <summary>
        /// Visits the custom attributes.
        /// </summary>
        /// <param name="customAttributes">The custom attributes.</param>
        /// <returns></returns>
        private static List <AttributeElement> ExtractCustomAttributes(CustomAttributeCollection customAttributes)
        {
            List <AttributeElement> ret = new List <AttributeElement>();

            if (customAttributes == null || customAttributes.Count == 0)
            {
                return(ret);
            }

            foreach (CustomAttribute ca in customAttributes)
            {
                AttributeElement ae = new AttributeElement();
                if (ca.Constructor.DeclaringType == null)
                {
                    continue;
                }

                ae.AttributeType = ca.Constructor.DeclaringType.ToString();

                for (int i = 0; i < ca.ConstructorParameters.Count; i++)
                {
                    AttributeValueElement ave = new AttributeValueElement();
                    ave.Name = ca.Constructor.Parameters[i].Name;
                    if (ca.ConstructorParameters[i] == null)
                    {
                        ave.Value = null;
                    }
                    else
                    {
                        ave.Value = ca.ConstructorParameters[i].ToString().Replace("\0", "");
                    }
                    ae.Values.Add(ave);
                }

                foreach (object propKey in ca.Properties.Keys)
                {
                    AttributeValueElement ave = new AttributeValueElement();
                    ave.Name = Convert.ToString(propKey, CultureInfo.InvariantCulture);
                    if (ca.Properties[propKey] == null)
                    {
                        ave.Value = null;
                    }
                    else
                    {
                        ave.Value = ca.Properties[propKey].ToString();
                    }
                    ae.Values.Add(ave);
                }

                ret.Add(ae);
            }

            return(ret);
        }
Beispiel #3
0
    public static string Attribute(AttributeElement att)
    {
        string defaultThemeClass = att.Instance.Settings.Theme.ReadonlyAttribute;
        if (att.Attribute.Type == eDBType.BINARY)
            defaultThemeClass = att.Instance.Settings.Theme.ReadonlyBlobAttribute;

        string themeClass = GetThemeClass(att, defaultThemeClass);
        Dictionary<string, object> properties = new Dictionary<string, object>();
        GetControlInfo(att, properties);

        return WebForm.Attribute(att.AttributeName, themeClass, null, properties);
    }
Beispiel #4
0
 private SAML2.Config.Attribute ToAttribute(AttributeElement value)
 {
     if (value == null)
     {
         return(null);
     }
     return(new SAML2.Config.Attribute
     {
         IsRequired = value.IsRequired,
         Name = value.Name
     });
 }
Beispiel #5
0
    public static string GridAttributePrompt(AttributeElement att)
    {
        string defaultThemeClass = att.Instance.Settings.Theme.ReadonlyGridAttribute;
        if (att.Attribute.Type == eDBType.BINARY)
            defaultThemeClass = att.Instance.Settings.Theme.ReadonlyGridBlobAttribute;

        string themeClass = GetThemeClass(att, defaultThemeClass);
        Dictionary<string, object> properties = new Dictionary<string, object>();
        GetControlInfo(att, properties);
        properties[Properties.HTMLSFLCOL.ReturnOnClick] = true;

        return WebForm.GridAttribute(att.AttributeName, themeClass, att.Description, att.Visible, null, properties);
    }
Beispiel #6
0
        /// <summary>
        /// Processes an attribute element.
        /// </summary>
        /// <param name="element">Attribute code element.</param>
        public override void VisitAttributeElement(AttributeElement element)
        {
            this.WriteComments(element.HeaderComments);

            bool nested = element.Parent is AttributeElement;

            if (!nested)
            {
                WriteIndented(CSharpSymbol.BeginAttribute.ToString());
                if (!string.IsNullOrEmpty(element.Target))
                {
                    Writer.Write(element.Target);
                    Writer.Write(CSharpSymbol.TypeImplements);
                    Writer.Write(' ');
                }
            }

            Writer.Write(element.Name);
            if (!string.IsNullOrEmpty(element.BodyText))
            {
                Writer.Write(CSharpSymbol.BeginParameterList);
                Writer.Write(element.BodyText);
                Writer.Write(CSharpSymbol.EndParameterList);
            }

            //
            // Nested list of attributes?
            //
            foreach (ICodeElement childElement in element.Children)
            {
                AttributeElement childAttribute = childElement as AttributeElement;
                if (childAttribute != null)
                {
                    Writer.Write(',');
                    Writer.WriteLine();
                    WriteIndented(string.Empty);
                    childAttribute.Accept(this);
                }
            }

            if (!nested)
            {
                Writer.Write(CSharpSymbol.EndAttribute);
            }

            if (!nested && element.Parent != null)
            {
                Writer.WriteLine();
            }
        }
Beispiel #7
0
        public void GetAttributeAttributesTest()
        {
            FieldElement fieldElement = new FieldElement();

            fieldElement.Name = "TestField";

            string attribute = ElementUtilities.GetAttribute(ElementAttributeType.Attributes, fieldElement);

            Assert.AreEqual(string.Empty, attribute, "Unexpected attribute.");

            //
            // Add some attributes to the element.
            //
            AttributeElement attribute1 = new AttributeElement();

            attribute1.Name     = "Attribute1";
            attribute1.BodyText = "false";

            AttributeElement attribute2 = new AttributeElement();

            attribute2.Name     = "Attribute2";
            attribute2.BodyText = "false";

            fieldElement.AddAttribute(attribute1);
            fieldElement.AddAttribute(attribute2);

            attribute = ElementUtilities.GetAttribute(ElementAttributeType.Attributes, fieldElement);
            Assert.AreEqual("Attribute1, Attribute2", attribute, "Unexpected attribute.");

            //
            // Add nested attributes to the element.
            //
            fieldElement.ClearAttributes();
            attribute1          = new AttributeElement();
            attribute1.Name     = "Attribute1";
            attribute1.BodyText = "false";

            attribute2          = new AttributeElement();
            attribute2.Name     = "Attribute2";
            attribute2.BodyText = "false";
            attribute1.AddChild(attribute2);

            fieldElement.AddAttribute(attribute1);

            attribute = ElementUtilities.GetAttribute(ElementAttributeType.Attributes, fieldElement);
            Assert.AreEqual("Attribute1, Attribute2", attribute, "Unexpected attribute.");
        }
Beispiel #8
0
        public void GenerateLink(AttributeElement att, AttributesElement gridAtts)
        {
            // Process attributes that use links but don't have one already.
            if (att.Autolink && att.Link == null)
            {
                LevelElement levelToLink = FindLevelToLink(att,gridAtts);
                if (levelToLink != null)
                {
                    LinkElement link = new LinkElement();
                    att.Links.Add(link);
                    //link = new LinkElement();
                    link.Webpanel = levelToLink.View.ObjectName;
                    bool isTemCallBack = false;
                    if (gridAtts.Instance.Settings.Template.TabFunction == SettingsTemplateElement.TabFunctionValue.TreeViewAnchor)
                    {
                        link.Parameters.Add(new ParameterElement("TrnMode.Update"));
                    }
                    foreach (ParameterElement parameter in levelToLink.View.Parameters)
                    {
                        if (parameter.Name == "&" + HPatternInstance.PARMCALLBACK)
                        {
                            isTemCallBack = true;
                        }
                        link.Parameters.Add(parameter.Clone());
                    }
                    if (isTemCallBack == false && gridAtts.Instance.Settings.Template.GenerateCallBackLink)
                    {
                        ParameterElement parm = new ParameterElement("&" + HPatternInstance.PARMCALLBACK);
                        parm.Domain = Domain.Get(gridAtts.Instance.Model,HPatternInstance.PARMCALLBACK);
                        link.Parameters.Add(parm);
                    }
                    /*
                    bool isSuperTypeLink = (General.NodeName(attriNode) != levelToLink.Level.DescriptionAttribute);

                    // Avoid self-links.
                    if (IsAcceptableLink(filename, attriNode, levelToLink, isSuperTypeLink))
                    {
                        attriNode.Attributes["link"].Value = ExtractLinkName(levelToLink.Filename);
                        attriNode.Attributes["level"].Value = levelToLink.Level.Name;

                        if (isSuperTypeLink)
                            AddSupertypeLinkParams(attriNode, levelToLink);
                    }
                    */
                }
            }
        }
Beispiel #9
0
        public void TestUacFilterNullValue()
        {
            var filter = new UacAttributeFilter();

            var job = new JobElement();

            var attrib = new AttributeElement();

            var searchResult = SearchResultFactory.Construct(new
            {
                userAccountControl = 0
            });

            var result = (bool)filter.Execute(null, searchResult, job, attrib);

            Assert.IsTrue(result);
        }
Beispiel #10
0
        public void TestUacFilterIsInactive()
        {
            var filter = new UacAttributeFilter();

            var job = new JobElement();

            var attrib = new AttributeElement();

            var searchResult = SearchResultFactory.Construct(new
            {
                userAccountControl = 0
            });

            const int currentValue = 0x0002;
            var       result       = (bool)filter.Execute(currentValue, searchResult, job, attrib);

            Assert.IsFalse(result);
        }
        public void TestReadLdapMissingAttribute()
        {
            var filter = new ReadLdapFilter();
            var attrib = new AttributeElement
            {
                Name = "NotFound"
            };

            // mock the ldap search result
            var result = SearchResultFactory.Construct(new
            {
                givenName = "Thomas"
            });

            var value = filter.Execute(null, result, null, attrib);

            Assert.IsNull(value);
        }
Beispiel #12
0
        public void ClearAttributesTest()
        {
            TCodeElement codeElement = new TCodeElement();

            AttributeElement attribute1 = new AttributeElement("Test");
            AttributeElement attribute2 = new AttributeElement("Ignore");

            codeElement.AddAttribute(attribute1);
            codeElement.AddAttribute(attribute2);

            Assert.AreEqual(2, codeElement.Attributes.Count, "Attributes were not added correctly.");

            codeElement.ClearAttributes();

            Assert.AreEqual(0, codeElement.Attributes.Count, "Attributes were not cleared correctly.");

            Assert.IsNull(attribute1.Parent, "Attribute parent should have been cleared.");
            Assert.IsNull(attribute2.Parent, "Attribute parent should have been cleared.");
        }
        public void TestReadLdapValue()
        {
            var filter = new ReadLdapFilter();
            var attrib = new AttributeElement
            {
                Name = "givenName"
            };

            // mock the ldap search result
            var result = SearchResultFactory.Construct(new
            {
                givenName = "Thomas"
            });


            var value = filter.Execute(null, result, null, attrib);

            Assert.AreEqual(value, "Thomas");
        }
Beispiel #14
0
        public void RemoveAttributeTest()
        {
            TCodeElement codeElement1 = new TCodeElement();

            AttributeElement attribute1 = new AttributeElement("Test");
            AttributeElement attribute2 = new AttributeElement("Ignore");

            codeElement1.AddAttribute(attribute1);
            codeElement1.AddAttribute(attribute2);

            Assert.AreEqual(2, codeElement1.Attributes.Count, "Attributes were not added correctly.");

            //
            // Remove the attribute using the method
            //
            codeElement1.RemoveAttribute(attribute2);

            Assert.AreEqual(1, codeElement1.Attributes.Count, "Attribute should have been removed.");

            Assert.IsTrue(codeElement1.Attributes.Contains(attribute1));
            Assert.IsFalse(codeElement1.Attributes.Contains(attribute2));

            //
            // Remove the attribute by assigning a different parent
            //
            TCodeElement codeElement2 = new TCodeElement();

            attribute1.Parent = codeElement2;

            Assert.AreEqual(
                0,
                codeElement1.Attributes.Count,
                "Attribute should have been removed from the original element.");
            Assert.AreEqual(
                1,
                codeElement2.Attributes.Count,
                "Attribute should have been added to the new element.");

            Assert.IsFalse(codeElement1.Attributes.Contains(attribute1));
            Assert.IsTrue(codeElement2.Attributes.Contains(attribute1));
        }
Beispiel #15
0
        public void AddAttributeTest()
        {
            TCodeElement codeElement = new TCodeElement();

            AttributeElement attribute1 = new AttributeElement("Test");
            AttributeElement attribute2 = new AttributeElement("Ignore");

            codeElement.AddAttribute(attribute1);
            codeElement.AddAttribute(attribute2);

            Assert.AreEqual(2, codeElement.Attributes.Count, "Attributes were not added correctly.");

            Assert.AreSame(codeElement, attribute1.Parent, "Attribute parent was not set correctly.");
            Assert.AreSame(codeElement, attribute2.Parent, "Attribute parent was not set correctly.");

            codeElement.AddAttribute(attribute2);

            Assert.AreEqual(2, codeElement.Attributes.Count, "Attribute should not have been added again.");

            Assert.IsTrue(codeElement.Attributes.Contains(attribute1));
            Assert.IsTrue(codeElement.Attributes.Contains(attribute2));
        }
        /// <summary>
        ///     Processes and attribute and returns its value
        ///     to be stored in the ActiveDirectory user object
        /// </summary>
        /// <param name="result">The current result to process.</param>
        /// <param name="jobConfig">The current job configuration.</param>
        /// <param name="attrib">The attribute to process.</param>
        /// <param name="attribFilters">The dictionary of filters</param>
        /// <returns></returns>
        public object ProcessAttribute(SearchResult result,
                                       JobElement jobConfig,
                                       AttributeElement attrib,
                                       Dictionary <string, IAttributeFilter> attribFilters)
        {
            var filters = new List <IAttributeFilter>();

            if (attrib.IncludeInQuery)
            {
                filters.Add(GetAttributeFilter(ContainerRegistry.PluginNameReadLdapFilter, attribFilters));
            }

            attrib.Filter.Split(',').ToList().ForEach(f =>
            {
                if (!string.IsNullOrWhiteSpace(f))
                {
                    filters.Add(GetAttributeFilter(f.Trim(), attribFilters));
                }
            });

            object currentValue = null;

            foreach (var filter in filters)
            {
                try
                {
                    currentValue = filter.Execute(currentValue, result, jobConfig, attrib);
                }
                catch (Exception ex)
                {
                    Logger.Error(ex, "Error executing filter {0} for attribute {1}", filter.GetType().FullName,
                                 attrib.Name);
                    throw;
                }
            }

            return(currentValue);
        }
Beispiel #17
0
    public static string GridVariableBC(AttributeElement var)
    {
        string themeClass = GetThemeClass(var, var.Instance.Settings.Theme.ReadonlyGridAttribute);
        Dictionary<string, object> properties = new Dictionary<string, object>();
        properties[Properties.HTMLSFLCOL.ReadOnly] = true;
        GetControlInfo(var, properties);

        return WebForm.GridVariable(var.AttributeName, themeClass, var.Description, var.Visible, null, properties);
    }
Beispiel #18
0
 virtual public void VisitAttribute(AttributeElement x)
 {
     VisitElement(x.ClassRef);
     VisitList(x.CallSignature.Parameters);
 }
Beispiel #19
0
        /// <summary>
        /// Processes an attribute element.
        /// </summary>
        /// <param name="element">Attribute code element.</param>
        public override void VisitAttributeElement(AttributeElement element)
        {
            this.WriteComments(element.HeaderComments);

            // HACK: Create an explicit element type for Option (or compiler directive)
            if (element[VBExtendedProperties.Option] is bool &&
                (bool)element[VBExtendedProperties.Option])
            {
                WriteIndented(element.BodyText);
            }
            else
            {
                bool nested = element.Parent is AttributeElement;
                if (!nested)
                {
                    WriteIndented(VBSymbol.BeginAttribute.ToString());
                }

                if (!string.IsNullOrEmpty(element.Target))
                {
                    Writer.Write(element.Target);
                    Writer.Write(VBSymbol.LineDelimiter);
                    Writer.Write(' ');
                }

                Writer.Write(element.Name);
                if (!string.IsNullOrEmpty(element.BodyText))
                {
                    Writer.Write(VBSymbol.BeginParameterList);
                    Writer.Write(element.BodyText);
                    Writer.Write(VBSymbol.EndParameterList);
                }

                //
                // Nested list of attributes?
                //
                foreach (ICodeElement childElement in element.Children)
                {
                    AttributeElement childAttribute = childElement as AttributeElement;
                    if (childAttribute != null)
                    {
                        Writer.Write(", _");
                        Writer.WriteLine();
                        WriteIndented(string.Empty);
                        childAttribute.Accept(this);
                    }
                }

                if (!nested)
                {
                    Writer.Write(VBSymbol.EndAttribute);

                    if (element.Parent is TextCodeElement)
                    {
                        Writer.Write(" _");
                    }
                }

                if (!nested && element.Parent != null)
                {
                    Writer.WriteLine();
                }
            }
        }
Beispiel #20
0
        /// <summary>
        ///     This filter reads a value from the search result
        /// </summary>
        /// <param name="currentValue">The current result value</param>
        /// <param name="result">The ldap result</param>
        /// <param name="jobElement">The configuration job element</param>
        /// <param name="attrib">The current attribute element</param>
        /// <returns></returns>
        public object Execute(object currentValue, SearchResult result, JobElement jobElement, AttributeElement attrib)
        {
            if (currentValue == null)
            {
                return(true);
            }

            var uacFlags = (int)currentValue;

            return(!Convert.ToBoolean(uacFlags & 0x0002));
        }
Beispiel #21
0
        public object Execute(object currentValue, SearchResult result, JobElement jobConfig, AttributeElement attrib)
        {
            // build the list of allowed groups...if populated
            // then the group will only be included if it matches
            // one of the allowed group names
            var groups   = new SortedList <string, string>();
            var groupSet = new HashSet <string>();

            foreach (GroupElement group in jobConfig.Groups)
            {
                groupSet.Add(group.Name);
            }

            // get the current member values
            var props = result.Properties[attrib.Name];

            if (props == null)
            {
                return(null);
            }

            foreach (string dn in props)
            {
                var group = new DistinguishedName(dn);

                // check to see if the group is in the allowed list
                // or if the list is empty then allow the group
                var groupName = string.IsNullOrWhiteSpace(jobConfig.RemoveGroupPrefix) ?
                                group.CommonName :
                                group.CommonName.Replace(jobConfig.RemoveGroupPrefix, string.Empty);

                if (groupSet.Count == 0 || groupSet.Contains(groupName))
                {
                    groups[dn] = groupName;
                }
            }

            return(groups);
        }
        /// <summary>
        ///     This filter reads a value from the search result
        /// </summary>
        /// <param name="currentValue">The current result value</param>
        /// <param name="result">The ldap result</param>
        /// <param name="jobElement">The configuration job element</param>
        /// <param name="attrib">The current attribute element</param>
        /// <returns></returns>
        public object Execute(object currentValue, SearchResult result, JobElement jobElement, AttributeElement attrib)
        {
            var propValues = result.Properties[attrib.Name];

            if (propValues != null && propValues.Count > 0)
            {
                return(propValues[0]);
            }

            return(null);
        }
Beispiel #23
0
        private LevelElement FindLevelToLink(AttributeElement att, AttributesElement gridAtts)
        {
            foreach (HPatternInstance instance in m_Instances)
            {
                if (instance.Settings.Grid.BuildAutoLink)
                {
                    foreach (LevelElement level in instance.Levels)
                    {
                        // Don't include a link to the same view in tabs.
                        if (level.View != null && level.View.Parameters != null && level.DescriptionAttribute != null && level.DescriptionAttribute.Attribute == att.Attribute)
                        {
                            bool isTemTodos = true;
                            foreach (ParameterElement par in level.View.Parameters)
                            {
                                if (par.IsAttribute && gridAtts.FindAttribute(par.Name) == null)
                                {
                                    isTemTodos = false;
                                    break;
                                }

                            }
                            if (isTemTodos)
                            {
                                return level;
                            }
                        }
                    }
                }
            }

            // Nothing found.
            return null;
        }
 private SAML2.Config.Attribute ToAttribute(AttributeElement value)
 {
     if (value == null) return null;
     return new SAML2.Config.Attribute
     {
         IsRequired = value.IsRequired,
         Name = value.Name
     };
 }
Beispiel #25
0
        /// <summary>
        /// Clones this instance.
        /// </summary>
        /// <returns>A clone of the code element.</returns>
        protected override CodeElement DoClone()
        {
            AttributeElement clone = new AttributeElement();
            clone._target = _target;

            return clone;
        }
 /// <summary>
 /// Processes an attribute element.
 /// </summary>
 /// <param name="element">Attribute code element.</param>
 public abstract void VisitAttributeElement(AttributeElement element);
        /// <summary>
        ///     This filter reads a value from the search result
        /// </summary>
        /// <param name="currentValue">The current result value</param>
        /// <param name="result">The ldap result</param>
        /// <param name="jobElement">The configuration job element</param>
        /// <param name="attrib">The current attribute element</param>
        /// <returns></returns>
        public object Execute(object currentValue, SearchResult result, JobElement jobElement, AttributeElement attrib)
        {
            const string propName = "distinguishedName";

            if (!result.Properties.Contains(propName))
            {
                return(null);
            }

            var propValues = result.Properties[propName];

            if (propValues != null && propValues.Count > 0)
            {
                var dn = new DistinguishedName(propValues[0].ToString());
                return(dn.DomainComponents.Count > 0 ? dn.DomainComponents[0] : null);
            }

            return(null);
        }