This class represents the generated code tree.
This is a customized data structure that is optimized for WSCF code generation purposes. It provides faster access to service contracts, service types, client types, message contracts and data contracts. Furthermore this class provides the common operations for adding new types and substituting one type with another. An instance of this class is handed over to each ICodeDecorator.
Пример #1
0
 /// <summary>
 /// Invokes all ICodeDecorator(s) in the decorators collection.
 /// </summary>
 public void ApplyDecorations(ExtendedCodeDomTree code, CustomCodeGenerationOptions options)
 {
     foreach (ICodeDecorator decorator in decorators)
     {
         decorator.Decorate(code, options);
     }
 }
        /// <summary>
        /// Invokes all ICodeDecorator(s) in the decorators collection.
        /// </summary>
        public void ApplyDecorations(ExtendedCodeDomTree code, CustomCodeGenerationOptions options)
        {
            //string fileName = "C:\\Users\\rs239\\Documents\\NIEM\\temp\\Decorators.txt";
            //StringWriter stringWriter = new StringWriter();

            //stringWriter.WriteLine("Namespace = " + codeNamespace.Name);

            //stringWriter.WriteLine("___________________________________________");
            //stringWriter.WriteLine(ctd.Name);

            //FileStream fs = File.Open(fileName, FileMode.Create, FileAccess.Write, FileShare.None);
            //StreamWriter writer = new StreamWriter(fs);
            //writer.Write(stringWriter);
            //writer.Flush();
            
            foreach (ICodeDecorator decorator in decorators)
            {
                IMetadata metadataDecorator = decorator as IMetadata;
                if (metadataDecorator != null)
                {
                    metadataDecorator.MetadataSet = this.metadataSet;
                }

                decorator.Decorate(code, options);
            }
        }
 /// <summary>
 /// Invokes all ICodeDecorator(s) in the decorators collection.
 /// </summary>
 public void ApplyDecorations(ExtendedCodeDomTree code, CustomCodeGenerationOptions options)
 {
     foreach (ICodeDecorator decorator in decorators)
     {
         decorator.Decorate(code, options);
     }
 }
Пример #4
0
 public void Decorate(ExtendedCodeDomTree code, CustomCodeGenerationOptions options)
 {
     if (options.GenerateTypedLists)
     {
         CollectionTypeGenerator generator = new CollectionTypeGenerator(new ListTypeProvider(), code);
         generator.Execute();
     }
 }
 public void Decorate(ExtendedCodeDomTree code, CustomCodeGenerationOptions options)
 {
     if (options.GenerateCollections)
     {
         CollectionTypeGenerator generator = new CollectionTypeGenerator(new CollectionTypeProvider(), code);
         generator.Execute();
     }
 }
        public CodeTypeReference CreateCollectionType(CodeTypeReference entityType, ExtendedCodeDomTree code)
        {
            Debug.Assert(entityType != null, "Argument entityType could not be null.");

			// Do not create a ByteCollection as this is not compatiable with base64Binary!
			if (entityType.BaseType == typeof(byte).FullName) return entityType;

            CodeTypeDeclaration collectionType = GenerateCollectionType(entityType);
            code.DataContracts.Add(new CodeTypeExtension(collectionType));

            CodeTypeReference collectionRef = new CodeTypeReference(collectionType.Name);
            return collectionRef;
        }
        public void Decorate(ExtendedCodeDomTree code, CustomCodeGenerationOptions options)
        {
            // Notify if we get any null references.
            Debug.Assert(code != null, "code parameter could not be null.");
            Debug.Assert(options != null, "options parameter could not be null.");

            // We apply this decorator only if this option is turned on.
            if (options.AdjustCasing)
            {
                // Initialize the state.
                this.code = code;
                this.options = options;
                DecorateInternal();
            }
        }
Пример #8
0
        public void Decorate(ExtendedCodeDomTree code, CustomCodeGenerationOptions options)
        {
            // Notify if we get any null references.
            Debug.Assert(code != null, "code parameter could not be null.");
            Debug.Assert(options != null, "options parameter could not be null.");

            // We apply this decorator only if this option is turned on.
            if (options.AdjustCasing)
            {
                // Initialize the state.
                this.code    = code;
                this.options = options;
                DecorateInternal();
            }
        }
Пример #9
0
        public void Decorate(ExtendedCodeDomTree code, CustomCodeGenerationOptions options)
        {
            // Some validations to make debugging easier.
            Debug.Assert(code != null, "code parameter could not be null.");
            Debug.Assert(options != null, "options parameter could not be null.");

            // We execute this decorator only if we are generating the service side code.
            if (options.GenerateService)
            {
                // Initialize the state.
                this.code    = code;
                this.options = options;
                CreateServiceType();
            }
        }
        public void Decorate(ExtendedCodeDomTree code, CustomCodeGenerationOptions options)
        {
            // Some validations to make debugging easier.
            Debug.Assert(code != null, "code parameter could not be null.");
            Debug.Assert(options != null, "options parameter could not be null.");

            // We execute this decorator only if we are generating the service side code.
            if (options.GenerateService)
            {
                // Initialize the state.
                this.code = code;
                this.options = options;
                CreateServiceType();                
            }
        }
Пример #11
0
 public static PascalCaseConverterBase GetPascalCaseConverter(CodeTypeExtension typeExtension, ExtendedCodeDomTree code)
 {
     switch (typeExtension.Kind)
     {
         case CodeTypeKind.DataContract:
             return new DataContractConverter(typeExtension, code);
         case CodeTypeKind.MessageContract:
             return new MessageContractConverter(typeExtension, code);
         case CodeTypeKind.ServiceContract:
             return new ServiceContractConverter(typeExtension, code);
         case CodeTypeKind.ClientType:
             return new ClientTypeConverter(typeExtension, code);
         default:
             return null;
     }
 }
        /// <summary>
        /// Executes the code generation workflow.
        /// </summary>        
        public CodeWriterOutput GenerateCode(CodeGenerationOptions options)
        {
            // Step 1 - Parse the code generation options and create the code provider.
            codeGenerationOptions = CodeGenerationOptionsParser.ParseCodeGenerationOptions(options);

			CreateCodeProvider();

        	ExtendedCodeDomTree extendedCodeDomTree;

            MetadataSet metadataSet = null;

			if (options.GenerateDataContracts)
			{
				// Step 2 - Build the set of XML schemas.
				XmlSchemas schemas = MetadataFactory.GetXmlSchemas(codeGenerationOptions.MetadataResolverOptions);
                
				// Step 3 - Generate the data contract code and get the CodeNamespace.
				DataContractGenerator dataContractGenerator = new DataContractGenerator(schemas, codeGenerationOptions.PrimaryOptions, codeProvider);
				CodeNamespace codeNamespace = dataContractGenerator.GenerateCode();

				// Step 4 - Wrap the CodeDOM in the custom object model.
				extendedCodeDomTree = new ExtendedCodeDomTree(codeNamespace, codeGenerationOptions.WriterOptions.Language, null);
			}
			else
			{
				// Step 2 - Build the service metadata.
				metadataSet = MetadataFactory.GetMetadataSet(codeGenerationOptions.MetadataResolverOptions);

                // Step 3 - Generate the client/service code and get the CodeNamespace.
				ClientServiceGenerator clientServiceGenerator = new ClientServiceGenerator(metadataSet, codeGenerationOptions.PrimaryOptions, codeProvider);
				CodeNamespace codeNamespace = clientServiceGenerator.GenerateCode();

				// Step 4 - Wrap the CodeDOM in the custom object model.
				extendedCodeDomTree = new ExtendedCodeDomTree(codeNamespace, codeGenerationOptions.WriterOptions.Language, clientServiceGenerator.Configuration);
			}
                       
            
            // Step 5 - Apply the code decorations.
            CodeDecorators decorators = new CodeDecorators(metadataSet);
            decorators.ApplyDecorations(extendedCodeDomTree, codeGenerationOptions.CustomOptions);

            // Step 6 - Restore the original CodeDOM.
        	CodeNamespace cns = extendedCodeDomTree.UnwrapCodeDomTree();
				
            // Step 6 - Finally, write out the code to physical files.
            return CodeWriter.Write(cns, extendedCodeDomTree.Configuration, codeGenerationOptions.WriterOptions, extendedCodeDomTree.TextFiles, codeProvider);            
        }
Пример #13
0
        /// <summary>
        /// Executes the code generation workflow.
        /// </summary>
        public CodeWriterOutput GenerateCode(CodeGenerationOptions options)
        {
            // Step 1 - Parse the code generation options and create the code provider.
            codeGenerationOptions = CodeGenerationOptionsParser.ParseCodeGenerationOptions(options);

            CreateCodeProvider();

            ExtendedCodeDomTree extendedCodeDomTree;

            if (options.GenerateDataContracts)
            {
                // Step 2 - Build the set of XML schemas.
                XmlSchemas schemas = MetadataFactory.GetXmlSchemas(codeGenerationOptions.MetadataResolverOptions);

                // Step 3 - Generate the data contract code and get the CodeNamespace.
                DataContractGenerator dataContractGenerator = new DataContractGenerator(schemas, codeGenerationOptions.PrimaryOptions, codeProvider);
                CodeNamespace         codeNamespace         = dataContractGenerator.GenerateCode();

                // Step 4 - Wrap the CodeDOM in the custom object model.
                extendedCodeDomTree = new ExtendedCodeDomTree(codeNamespace, codeGenerationOptions.WriterOptions.Language, null);
            }
            else
            {
                // Step 2 - Build the service metadata.
                MetadataSet metadataSet = MetadataFactory.GetMetadataSet(codeGenerationOptions.MetadataResolverOptions);

                // Step 3 - Generate the client/service code and get the CodeNamespace.
                ClientServiceGenerator clientServiceGenerator = new ClientServiceGenerator(metadataSet, codeGenerationOptions.PrimaryOptions, codeProvider);
                CodeNamespace          codeNamespace          = clientServiceGenerator.GenerateCode();

                // Step 4 - Wrap the CodeDOM in the custom object model.
                extendedCodeDomTree = new ExtendedCodeDomTree(codeNamespace, codeGenerationOptions.WriterOptions.Language, clientServiceGenerator.Configuration);
            }

            // Step 5 - Apply the code decorations.
            CodeDecorators decorators = new CodeDecorators();

            decorators.ApplyDecorations(extendedCodeDomTree, codeGenerationOptions.CustomOptions);

            // Step 6 - Restore the original CodeDOM.
            CodeNamespace cns = extendedCodeDomTree.UnwrapCodeDomTree();

            // Step 6 - Finally, write out the code to physical files.
            return(CodeWriter.Write(cns, extendedCodeDomTree.Configuration, codeGenerationOptions.WriterOptions, extendedCodeDomTree.TextFiles, codeProvider));
        }
Пример #14
0
        public CodeTypeReference CreateCollectionType(CodeTypeReference entityType, ExtendedCodeDomTree code)
        {
            Debug.Assert(entityType != null, "Argument entityType could not be null.");

            // Do not create a ByteCollection as this is not compatiable with base64Binary!
            if (entityType.BaseType == typeof(byte).FullName)
            {
                return(entityType);
            }

            CodeTypeDeclaration collectionType = GenerateCollectionType(entityType);

            code.DataContracts.Add(new CodeTypeExtension(collectionType));

            CodeTypeReference collectionRef = new CodeTypeReference(collectionType.Name);

            return(collectionRef);
        }
        public CodeTypeReference CreateCollectionType(CodeTypeReference entityType, ExtendedCodeDomTree code)
        {
            Debug.Assert(entityType != null, "Argument entity type could not be null.");

			// Do not create a ByteCollection as this is not compatiable with base64Binary!
			if (entityType.BaseType == typeof(byte).FullName) return entityType;

            CodeTypeReference ctr = new CodeTypeReference(typeof(List<>));

			if (entityType.IsNullableType())
			{
				ctr.TypeArguments.Add(entityType.CloseNullableType());
			}
			else
			{
				ctr.TypeArguments.Add(entityType.BaseType);
			}
            return ctr;
        }
Пример #16
0
        public void Decorate(ExtendedCodeDomTree code, CustomCodeGenerationOptions options)
        {
            this.code = code;
            this.options = options;
            this.configuration = code.Configuration;

            // Are we on the service side code gen?
            if (options.GenerateService)
            {
                // Then generate the service side configuration.
                GenerateServiceConfiguration();

                // Do we have to enable metadata endpoint?
                if (options.EnableWsdlEndpoint)
                {
                    AddMetadataServiceBehavior();
                }
            }
        }
Пример #17
0
        public void Decorate(ExtendedCodeDomTree code, CustomCodeGenerationOptions options)
        {
            this.code          = code;
            this.options       = options;
            this.configuration = code.Configuration;

            // Are we on the service side code gen?
            if (options.GenerateService)
            {
                // Then generate the service side configuration.
                GenerateServiceConfiguration();

                // Do we have to enable metadata endpoint?
                if (options.EnableWsdlEndpoint)
                {
                    AddMetadataServiceBehavior();
                }
            }
        }
Пример #18
0
        public CodeTypeReference CreateCollectionType(CodeTypeReference entityType, ExtendedCodeDomTree code)
        {
            Debug.Assert(entityType != null, "Argument entity type could not be null.");

            // Do not create a ByteCollection as this is not compatiable with base64Binary!
            if (entityType.BaseType == typeof(byte).FullName)
            {
                return(entityType);
            }

            CodeTypeReference ctr = new CodeTypeReference(typeof(List <>));

            if (entityType.IsNullableType())
            {
                ctr.TypeArguments.Add(entityType.CloseNullableType());
            }
            else
            {
                ctr.TypeArguments.Add(entityType.BaseType);
            }
            return(ctr);
        }
Пример #19
0
 public ClientTypeConverter(CodeTypeExtension typeExtension, ExtendedCodeDomTree code)
     : base(typeExtension, code)
 {
 }
Пример #20
0
 public CollectionTypeGenerator(ICollectionTypeProvider collectionTypeProvider, ExtendedCodeDomTree code)
 {
     this.collectionTypeProvider = collectionTypeProvider;
     this.generatedTypes         = new Dictionary <string, CodeTypeReference>();
     this.code = code;
 }
Пример #21
0
 public ClientTypeConverter(CodeTypeExtension typeExtension, ExtendedCodeDomTree code)
     : base(typeExtension, code)
 {
 }
Пример #22
0
 public DataContractConverter(CodeTypeExtension typeExtension, ExtendedCodeDomTree code)
     : base(typeExtension, code)
 {
 }
 public CollectionTypeGenerator(ICollectionTypeProvider collectionTypeProvider, ExtendedCodeDomTree code)
 {
     this.collectionTypeProvider = collectionTypeProvider;
     this.generatedTypes = new Dictionary<string, CodeTypeReference>();
     this.code = code;
 }
Пример #24
0
 protected PascalCaseConverterBase(CodeTypeExtension codeTypeExtension, ExtendedCodeDomTree code)
 {
     this.typeExtension = codeTypeExtension;
     this.Code          = code;
     this.type          = (CodeTypeDeclaration)codeTypeExtension.ExtendedObject;
 }
Пример #25
0
 protected PascalCaseConverterBase(CodeTypeExtension codeTypeExtension, ExtendedCodeDomTree code)
 {
     this.typeExtension = codeTypeExtension;
     this.Code = code;
     this.type = (CodeTypeDeclaration)codeTypeExtension.ExtendedObject;
 }
Пример #26
0
 public ServiceContractConverter(CodeTypeExtension typeExtension, ExtendedCodeDomTree code)
     : base(typeExtension, code)
 {
 }
Пример #27
0
        public static PascalCaseConverterBase GetPascalCaseConverter(CodeTypeExtension typeExtension, ExtendedCodeDomTree code)
        {
            switch (typeExtension.Kind)
            {
            case CodeTypeKind.DataContract:
                return(new DataContractConverter(typeExtension, code));

            case CodeTypeKind.MessageContract:
                return(new MessageContractConverter(typeExtension, code));

            case CodeTypeKind.ServiceContract:
                return(new ServiceContractConverter(typeExtension, code));

            case CodeTypeKind.ClientType:
                return(new ClientTypeConverter(typeExtension, code));

            default:
                return(null);
            }
        }