コード例 #1
0
ファイル: DBAccess.cs プロジェクト: sagius-li/Lydia
        public static RmAttribute GetAttribute(ref SqlConnection conn, string attributeName)
        {
            RmAttribute retVal = new RmAttribute();

            string query = @"
                select
                    Name,
                    DataType,
                    Multivalued
                from
                    fim.AttributeInternal with (nolock)
                where
                    Name='{0}'
            ";

            SqlCommand cmd = new SqlCommand(string.Format(query, attributeName), conn);

            SqlDataReader attributeReader = cmd.ExecuteReader();

            cmd.Dispose();

            while (attributeReader.Read())
            {
                retVal.Name     = attributeReader[0].ToString();
                retVal.DataType = attributeReader[1].ToString();
                if (attributeReader[2] != null)
                {
                    retVal.Multivalued = (bool)attributeReader[2];
                }
                else
                {
                    retVal.Multivalued = false;
                }

                break;
            }

            attributeReader.Close();
            attributeReader.Dispose();

            return(retVal);
        }
コード例 #2
0
ファイル: DBAccess.cs プロジェクト: sagius-li/Lydia
        public static List <RmAttribute> GetAttributes(ref SqlConnection conn, string objectType, int localeKey)
        {
            List <RmAttribute> retVal = new List <RmAttribute>();

            string query = @"
                with tblAttribute as
                (
	                select distinct
		                tblBinding.ObjectKey as [Key],
		                tblBinding.AttributeName as Name,
		                tblString.ValueString as DisplayName,
                        tblAttribute.DataType as DataType,
		                tblAttribute.Multivalued as IsMultivalue,
		                tblBinding.StringRegex as RegEx
	                from
		                fim.BindingInternal as tblBinding with (nolock)
                    inner join
						fim.AttributeInternal as tblAttribute with (nolock)
					on
						tblBinding.AttributeKey = tblAttribute.[Key]
	                inner join
		                fim.ObjectValueString as tblString with (nolock)
	                on
		                tblBinding.ObjectType='{0}' and 
		                tblString.AttributeKey=66 and 
		                tblString.LocaleKey={1} and 
		                tblBinding.ObjectKey=tblString.ObjectKey
                )
                select
	                tblAttribute.Name,
	                tblAttribute.DisplayName,
                    tblAttribute.DataType,
	                tblAttribute.IsMultivalue,
	                tblAttribute.RegEx,
	                tblString.ValueString as [Description]
                from
	                tblAttribute
                left join
	                fim.ObjectValueString as tblString with (nolock)
                on
	                tblString.ObjectKey=tblAttribute.[Key] and
	                tblString.AttributeKey=61 and
	                tblString.LocaleKey={1} and
	                tblString.ObjectTypeKey=5
            ";

            SqlCommand cmd = new SqlCommand(string.Format(query, objectType, localeKey), conn);

            SqlDataReader attributeReader = cmd.ExecuteReader();

            cmd.Dispose();

            while (attributeReader.Read())
            {
                RmAttribute attribute = new RmAttribute();
                if (attributeReader[0] != null && attributeReader[1] != null)
                {
                    attribute.Name        = attributeReader[0].ToString();
                    attribute.DisplayName = attributeReader[1].ToString();

                    if (attributeReader[2] != null)
                    {
                        attribute.DataType = attributeReader[2].ToString();
                    }
                    else
                    {
                        attribute.Description = string.Empty;
                    }

                    if (attributeReader[3] != null)
                    {
                        attribute.Multivalued = (bool)attributeReader[3];
                    }
                    else
                    {
                        attribute.Multivalued = false;
                    }

                    if (attributeReader[5] != null)
                    {
                        attribute.Description = attributeReader[5].ToString();
                    }
                    else
                    {
                        attribute.Description = string.Empty;
                    }

                    if (attributeReader[4] != null)
                    {
                        attribute.RegEx = attributeReader[4].ToString();
                    }

                    retVal.Add(attribute);
                }
            }

            attributeReader.Close();
            attributeReader.Dispose();

            return(retVal);
        }
コード例 #3
0
        public DSResource convertToDSResource(ResourceManagementClient client, ResourceObject resource,
                                              string[] loadedAttributes, bool includePermission, ResourceOption option, bool deepResolve = true)
        {
            DSResource dsResource = new DSResource
            {
                DisplayName        = resource.DisplayName,
                ObjectID           = resource.ObjectID.Value,
                ObjectType         = resource.ObjectTypeName,
                HasPermissionHints = resource.HasPermissionHints
            };

            List <RmAttribute> attributeDef = getAttributeDefinition(resource.ObjectTypeName, option.CultureKey, option.ConnectionInfo.EncryptionKey);

            Dictionary <string, DSAttribute> attributes = new Dictionary <string, DSAttribute>();

            foreach (string attributeName in loadedAttributes)
            {
                if (resource.Attributes.ContainsAttribute(attributeName))
                {
                    AttributeValue attValue = resource.Attributes[attributeName];

                    if (attValue.Attribute.SystemName.Equals("ObjectID") || attValue.Attribute.SystemName.Equals("ObjectType"))
                    {
                        continue;
                    }

                    DSAttribute dsAttribute = new DSAttribute
                    {
                        Description    = attValue.Attribute.Description,
                        DisplayName    = attValue.Attribute.DisplayName,
                        IsMultivalued  = attValue.Attribute.IsMultivalued,
                        IsReadOnly     = attValue.Attribute.IsReadOnly,
                        IsRequired     = attValue.Attribute.IsRequired,
                        Regex          = attValue.Attribute.Regex,
                        SystemName     = attValue.Attribute.SystemName,
                        Type           = attValue.Attribute.Type.ToString(),
                        IsNull         = attValue.IsNull,
                        PermissionHint = attValue.PermissionHint.ToString(),
                        Value          = attValue.Value,
                        Values         = attValue.Values.ToList()
                    };

                    if (attributeDef != null)
                    {
                        RmAttribute attr = attributeDef.FirstOrDefault(a => a.Name.Equals(attValue.AttributeName));
                        if (attr != null)
                        {
                            dsAttribute.DisplayName = attr.DisplayName;
                            dsAttribute.Description = attr.Description;
                        }
                    }

                    if (!dsAttribute.IsNull && dsAttribute.Type.Equals("Reference"))
                    {
                        dsAttribute.Value = attValue.Attribute.IsMultivalued ?
                                            attValue.StringValues.FirstOrDefault() : attValue.StringValue;
                        dsAttribute.Values = attValue.Attribute.IsMultivalued ?
                                             attValue.StringValues.ToList <object>() : new List <object>()
                        {
                            attValue.StringValue
                        };

                        if (!string.IsNullOrEmpty(dsAttribute.Value.ToString()) && deepResolve && option.ResolveID)
                        {
                            if (dsAttribute.IsMultivalued)
                            {
                                foreach (string value in attValue.StringValues)
                                {
                                    ResourceObject resolvedObject = client.GetResource(
                                        value, option.AttributesToResolve, includePermission);
                                    dsAttribute.ResolvedValues.Add(convertToDSResource(client,
                                                                                       resolvedObject, option.AttributesToResolve, includePermission, option, option.DeepResolve));
                                }
                            }
                            else
                            {
                                ResourceObject resolvedObject = client.GetResource(
                                    attValue.StringValue, option.AttributesToResolve, includePermission);
                                dsAttribute.ResolvedValue = convertToDSResource(client,
                                                                                resolvedObject, option.AttributesToResolve, includePermission, option, option.DeepResolve);
                            }
                        }
                    }

                    attributes.Add(attValue.AttributeName, dsAttribute);
                }
            }

            dsResource.Attributes = attributes;

            return(dsResource);
        }