public static AttributeDeclaration GetAttributeDeclaration(Attribute attribute, ClientCodeGenerator textTemplateClientCodeGenerator, bool forcePropagation)
        {
            Type attributeType = attribute.GetType();

            // Check if this attribute should be blocked
            if (IsAttributeBlocked(attributeType))
            {
                return null;
            }

            ICustomAttributeBuilder cab = GetCustomAttributeBuilder(attributeType);
            AttributeDeclaration attributeDeclaration = null;
            if (cab != null)
            {
                try
                {
                    attributeDeclaration = cab.GetAttributeDeclaration(attribute);
                }
                catch (AttributeBuilderException)
                {
                    return null;
                }
                if (attributeDeclaration != null)
                {
                    if (!forcePropagation)
                    {
                        // Verify attribute's shared type|property|method requirements are met
                        ValidateAttributeDeclarationRequirements(attributeDeclaration, textTemplateClientCodeGenerator);
                    }
                }
            }

            return attributeDeclaration;
        }
        /// <summary>
        /// Generates the WebContext class. It calls the GenerateWebContextClass method to generate the actual code in a specific language.
        /// </summary>
        /// <param name="domainServiceDescriptions">The list of all the DomainServiceDesctiption objects.</param>
        /// <param name="clientCodeGenerator">The ClientCodeGenerator object for this instance.</param>
        /// <returns>The generated code.</returns>
        public string Generate(IEnumerable<DomainServiceDescription> domainServiceDescriptions, ClientCodeGenerator clientCodeGenerator)
        {
            this.ClientCodeGenerator = clientCodeGenerator;
            this.DomainServiceDescriptions = domainServiceDescriptions;

            return this.GenerateWebContextClass();
        }
        /// <summary>
        /// Generates the entity class on the client.
        /// </summary>
        /// <param name="entityType">The type of the entity to be generated</param>
        /// <param name="domainServiceDescriptions">The list of all the DomainServiceDescription objects.</param>
        /// <param name="clientCodeGenerator">The ClientCodeGenerator object for this instance.</param>
        /// <returns>Generated entity class code.</returns>
        public string Generate(Type entityType, IEnumerable<DomainServiceDescription> domainServiceDescriptions, ClientCodeGenerator clientCodeGenerator)
        {
            this.Type = entityType;
            this.ClientCodeGenerator = clientCodeGenerator;
            this.DomainServiceDescriptions = domainServiceDescriptions;

            return this.GenerateDataContractProxy();
        }
        /// <summary>
        /// Generates complex object code.
        /// </summary>
        /// <param name="complexObjectType">Type of the complex object for which the proxy is to be generates.</param>
        /// <param name="domainServiceDescription">The DomainServiceDescription for the domain service associated with this complex type.</param>
        /// <param name="clientCodeGenerator">ClientCodeGenerator object for this instance.</param>
        /// <returns>The generated complex object code.</returns>
        public string Generate(Type complexObjectType, DomainServiceDescription domainServiceDescription, ClientCodeGenerator clientCodeGenerator)
        {
            this.Type = complexObjectType;
            this.ClientCodeGenerator = clientCodeGenerator;
            this.DomainServiceDescription = domainServiceDescription;

            return this.GenerateDataContractProxy();
        }
Beispiel #5
0
        /// <summary>
        /// Generates complex object code.
        /// </summary>
        /// <param name="complexObjectType">Type of the complex object for which the proxy is to be generates.</param>
        /// <param name="domainServiceDescription">The DomainServiceDescription for the domain service associated with this complex type.</param>
        /// <param name="clientCodeGenerator">ClientCodeGenerator object for this instance.</param>
        /// <returns>The generated complex object code.</returns>
        public string Generate(Type complexObjectType, DomainServiceDescription domainServiceDescription, ClientCodeGenerator clientCodeGenerator)
        {
            this.Type = complexObjectType;
            this.ClientCodeGenerator      = clientCodeGenerator;
            this.DomainServiceDescription = domainServiceDescription;

            return(this.GenerateDataContractProxy());
        }
        public static AttributeDeclaration GetAttributeDeclaration(Attribute attribute, ClientCodeGenerator textTemplateClientCodeGenerator, bool forcePropagation)
        {
            Type attributeType = attribute.GetType();

            // Check if this attribute should be blocked
            if (IsAttributeBlocked(attributeType))
            {
                return(null);
            }

            ICustomAttributeBuilder cab = GetCustomAttributeBuilder(attributeType);
            AttributeDeclaration    attributeDeclaration = null;

            if (cab != null)
            {
                try
                {
                    attributeDeclaration = cab.GetAttributeDeclaration(attribute);
                }
                catch (AttributeBuilderException)
                {
                    return(null);
                }
                if (attributeDeclaration != null)
                {
                    if (!forcePropagation)
                    {
                        // Verify attribute's shared type|property|method requirements are met
                        ValidateAttributeDeclarationRequirements(attributeDeclaration, textTemplateClientCodeGenerator);
                    }
                }
            }

            return(attributeDeclaration);
        }
        private static void ValidateAttributeDeclarationRequirements(AttributeDeclaration attributeDeclaration, ClientCodeGenerator textTemplateClientCodeGenerator)
        {
            // Verify the attribute itself is shared.
            CodeMemberShareKind shareKind = textTemplateClientCodeGenerator.GetTypeShareKind(attributeDeclaration.AttributeType);

            // If there is no PDB or this type has no human-authored code, we cannot determine
            // whether it is shared and get a null value.  This requires a special message to
            // explain why we treat the type as not shared.
            if (shareKind == CodeMemberShareKind.Unknown)
            {
                attributeDeclaration.Errors.Add(
                    string.Format(
                        CultureInfo.CurrentCulture,
                        Resource.ClientCodeGen_Attribute_RequiresShared_NoPDB,
                        attributeDeclaration.AttributeType,
                        attributeDeclaration.AttributeType.Assembly.GetName().Name,
                        textTemplateClientCodeGenerator.ClientProjectName));
            }
            else if (shareKind == CodeMemberShareKind.NotShared)
            {
                attributeDeclaration.Errors.Add(
                    string.Format(
                        CultureInfo.CurrentCulture,
                        Resource.ClientCodeGen_Attribute_RequiresShared,
                        attributeDeclaration.AttributeType,
                        textTemplateClientCodeGenerator.ClientProjectName));
            }

            // Verify shared types.  Here, we order by type name so that any generated errors
            // are presented in a consistent order.
            foreach (var type in attributeDeclaration.RequiredTypes.OrderBy(t => t.FullName))
            {
                shareKind = textTemplateClientCodeGenerator.GetTypeShareKind(type);

                // Missing PDB or lack of user code means we cannot know -- issue special warning
                if (shareKind == CodeMemberShareKind.Unknown)
                {
                    attributeDeclaration.Errors.Add(
                        string.Format(
                            CultureInfo.CurrentCulture,
                            Resource.ClientCodeGen_Attribute_RequiresShared_Type_NoPDB,
                            attributeDeclaration.AttributeType,
                            type,
                            type.Assembly.GetName().Name,
                            textTemplateClientCodeGenerator.ClientProjectName));
                }
                else if (shareKind == CodeMemberShareKind.NotShared)
                {
                    attributeDeclaration.Errors.Add(
                        string.Format(
                            CultureInfo.CurrentCulture,
                            Resource.ClientCodeGen_Attribute_RequiresShared_Type,
                            attributeDeclaration.AttributeType,
                            type,
                            textTemplateClientCodeGenerator.ClientProjectName));
                }
            }

            // Verify shared methods.  Here, we order by method name so that any generated errors
            // are presented in a consistent order.
            foreach (var method in attributeDeclaration.RequiredMethods.OrderBy(p => p.Name))
            {
                shareKind = textTemplateClientCodeGenerator.GetMethodShareKind(method);
                if (shareKind == CodeMemberShareKind.NotShared)
                {
                    attributeDeclaration.Errors.Add(
                        string.Format(
                            CultureInfo.CurrentCulture,
                            Resource.ClientCodeGen_Attribute_RequiresShared_Method,
                            attributeDeclaration.AttributeType,
                            method.Name,
                            method.DeclaringType,
                            textTemplateClientCodeGenerator.ClientProjectName));
                }
            }

            // Verify shared properties.  Here, we order by property name so that any generated errors
            // are presented in a consistent order.
            foreach (var property in attributeDeclaration.RequiredProperties.OrderBy(p => p.Name))
            {
                shareKind = textTemplateClientCodeGenerator.GetPropertyShareKind(property.DeclaringType, property.Name);
                if (shareKind == CodeMemberShareKind.NotShared)
                {
                    attributeDeclaration.Errors.Add(
                        string.Format(
                            CultureInfo.CurrentCulture,
                            Resource.ClientCodeGen_Attribute_RequiresShared_Property,
                            attributeDeclaration.AttributeType,
                            property.Name,
                            property.DeclaringType,
                            textTemplateClientCodeGenerator.ClientProjectName));
                }
            }
        }
 /// <summary>
 /// Geterates the DomainContext class.
 /// </summary>
 /// <param name="domainServiceDescription">DomainServcieDescription for the domain service for which the proxy is to be generated.</param>
 /// <param name="clientCodeGenerator">ClientCodeGenerator object for this instance.</param>
 /// <returns>The generated DomainContext class code.</returns>
 public string Generate(DomainServiceDescription domainServiceDescription, ClientCodeGenerator clientCodeGenerator)
 {
     this.DomainServiceDescription = domainServiceDescription;
     this.ClientCodeGenerator = clientCodeGenerator;
     return this.GenerateDomainContextClass();
 }
 /// <summary>
 /// Generates enums on the client. It calls the GenerateEnums method to generate the actual code in a specific language.
 /// </summary>
 /// <param name="enumsToGenerate">The list of all the enums to generate.</param>
 /// <param name="clientCodeGenerator">The ClientCodeGenerator object for this instance.</param>
 /// <returns>The generated enum code.</returns>
 public string GenerateEnums(HashSet<Type> enumsToGenerate, ClientCodeGenerator clientCodeGenerator)
 {
     this.EnumsToGenerate = enumsToGenerate;
     this.ClientCodeGenerator = clientCodeGenerator;
     return this.GenerateEnums();
 }
        private static void ValidateAttributeDeclarationRequirements(AttributeDeclaration attributeDeclaration, ClientCodeGenerator textTemplateClientCodeGenerator)
        {
            // Verify the attribute itself is shared.
            CodeMemberShareKind shareKind = textTemplateClientCodeGenerator.GetTypeShareKind(attributeDeclaration.AttributeType);

            // If there is no PDB or this type has no human-authored code, we cannot determine
            // whether it is shared and get a null value.  This requires a special message to
            // explain why we treat the type as not shared.
            if (shareKind == CodeMemberShareKind.Unknown)
            {
                attributeDeclaration.Errors.Add(
                string.Format(
                    CultureInfo.CurrentCulture,
                    Resource.ClientCodeGen_Attribute_RequiresShared_NoPDB,
                    attributeDeclaration.AttributeType,
                    attributeDeclaration.AttributeType.Assembly.GetName().Name,
                    textTemplateClientCodeGenerator.ClientProjectName));
            }
            else if (shareKind == CodeMemberShareKind.NotShared)
            {
                attributeDeclaration.Errors.Add(
                    string.Format(
                        CultureInfo.CurrentCulture,
                        Resource.ClientCodeGen_Attribute_RequiresShared,
                        attributeDeclaration.AttributeType,
                        textTemplateClientCodeGenerator.ClientProjectName));
            }

            // Verify shared types.  Here, we order by type name so that any generated errors
            // are presented in a consistent order.
            foreach (var type in attributeDeclaration.RequiredTypes.OrderBy(t => t.FullName))
            {
                shareKind = textTemplateClientCodeGenerator.GetTypeShareKind(type);

                // Missing PDB or lack of user code means we cannot know -- issue special warning
                if (shareKind == CodeMemberShareKind.Unknown)
                {
                    attributeDeclaration.Errors.Add(
                    string.Format(
                        CultureInfo.CurrentCulture,
                        Resource.ClientCodeGen_Attribute_RequiresShared_Type_NoPDB,
                        attributeDeclaration.AttributeType,
                        type,
                        type.Assembly.GetName().Name,
                        textTemplateClientCodeGenerator.ClientProjectName));
                }
                else if (shareKind == CodeMemberShareKind.NotShared)
                {
                    attributeDeclaration.Errors.Add(
                        string.Format(
                            CultureInfo.CurrentCulture,
                            Resource.ClientCodeGen_Attribute_RequiresShared_Type,
                            attributeDeclaration.AttributeType,
                            type,
                            textTemplateClientCodeGenerator.ClientProjectName));
                }
            }

            // Verify shared methods.  Here, we order by method name so that any generated errors
            // are presented in a consistent order.
            foreach (var method in attributeDeclaration.RequiredMethods.OrderBy(p => p.Name))
            {
                shareKind = textTemplateClientCodeGenerator.GetMethodShareKind(method);
                if (shareKind == CodeMemberShareKind.NotShared)
                {
                    attributeDeclaration.Errors.Add(
                        string.Format(
                            CultureInfo.CurrentCulture,
                            Resource.ClientCodeGen_Attribute_RequiresShared_Method,
                            attributeDeclaration.AttributeType,
                            method.Name,
                            method.DeclaringType,
                            textTemplateClientCodeGenerator.ClientProjectName));
                }
            }

            // Verify shared properties.  Here, we order by property name so that any generated errors
            // are presented in a consistent order.
            foreach (var property in attributeDeclaration.RequiredProperties.OrderBy(p => p.Name))
            {
                shareKind = textTemplateClientCodeGenerator.GetPropertyShareKind(property.DeclaringType, property.Name);
                if (shareKind == CodeMemberShareKind.NotShared)
                {
                    attributeDeclaration.Errors.Add(
                        string.Format(
                            CultureInfo.CurrentCulture,
                            Resource.ClientCodeGen_Attribute_RequiresShared_Property,
                            attributeDeclaration.AttributeType,
                            property.Name,
                            property.DeclaringType,
                            textTemplateClientCodeGenerator.ClientProjectName));
                }
            }
        }
 /// <summary>
 /// Generates enums on the client. It calls the GenerateEnums method to generate the actual code in a specific language.
 /// </summary>
 /// <param name="enumsToGenerate">The list of all the enums to generate.</param>
 /// <param name="clientCodeGenerator">The ClientCodeGenerator object for this instance.</param>
 /// <returns>The generated enum code.</returns>
 public string GenerateEnums(HashSet <Type> enumsToGenerate, ClientCodeGenerator clientCodeGenerator)
 {
     this.EnumsToGenerate     = enumsToGenerate;
     this.ClientCodeGenerator = clientCodeGenerator;
     return(this.GenerateEnums());
 }
Beispiel #12
0
        /// <summary>
        /// Generates the WebContext class. It calls the GenerateWebContextClass method to generate the actual code in a specific language.
        /// </summary>
        /// <param name="domainServiceDescriptions">The list of all the DomainServiceDesctiption objects.</param>
        /// <param name="clientCodeGenerator">The ClientCodeGenerator object for this instance.</param>
        /// <returns>The generated code.</returns>
        public string Generate(IEnumerable <DomainServiceDescription> domainServiceDescriptions, ClientCodeGenerator clientCodeGenerator)
        {
            this.ClientCodeGenerator       = clientCodeGenerator;
            this.DomainServiceDescriptions = domainServiceDescriptions;

            return(this.GenerateWebContextClass());
        }
Beispiel #13
0
 /// <summary>
 /// Geterates the DomainContext class.
 /// </summary>
 /// <param name="domainServiceDescription">DomainServcieDescription for the domain service for which the proxy is to be generated.</param>
 /// <param name="clientCodeGenerator">ClientCodeGenerator object for this instance.</param>
 /// <returns>The generated DomainContext class code.</returns>
 public string Generate(DomainServiceDescription domainServiceDescription, ClientCodeGenerator clientCodeGenerator)
 {
     this.DomainServiceDescription = domainServiceDescription;
     this.ClientCodeGenerator      = clientCodeGenerator;
     return(this.GenerateDomainContextClass());
 }
Beispiel #14
0
        /// <summary>
        /// Generates the entity class on the client.
        /// </summary>
        /// <param name="entityType">The type of the entity to be generated</param>
        /// <param name="domainServiceDescriptions">The list of all the DomainServiceDescription objects.</param>
        /// <param name="clientCodeGenerator">The ClientCodeGenerator object for this instance.</param>
        /// <returns>Generated entity class code.</returns>
        public string Generate(Type entityType, IEnumerable <DomainServiceDescription> domainServiceDescriptions, ClientCodeGenerator clientCodeGenerator)
        {
            this.Type = entityType;
            this.ClientCodeGenerator       = clientCodeGenerator;
            this.DomainServiceDescriptions = domainServiceDescriptions;

            return(this.GenerateDataContractProxy());
        }