Beispiel #1
0
        /// <summary>
        /// Generates the given service saving to the outputFile in the language passed in.
        /// </summary>
        public static void GenerateService(string serviceName,
                                           string version,
                                           string clientNamespace,
                                           string language,
                                           string outputFile)
        {
            // Generate the discovery URL for that service
            string url = string.Format(GoogleDiscoveryURL, serviceName, version);

            var discovery = CreateDefaultCachingDiscovery(url);
            // Build the service based on discovery information.
            var service = discovery.GetService(DiscoveryVersion.Version_1_0, new FactoryParameters());

            var generator     = new GoogleServiceGenerator(service, clientNamespace);
            var generatedCode = generator.GenerateCode();

            var provider = CodeDomProvider.CreateProvider(language);

            using (StreamWriter sw = new StreamWriter(outputFile, false))
            {
                IndentedTextWriter tw = new IndentedTextWriter(sw, "  ");

                // Generate source code using the code provider.
                provider.GenerateCodeFromCompileUnit(generatedCode, tw, new CodeGeneratorOptions());

                // Close the output file.
                tw.Close();
            }
        }
        /// <summary>
        /// Generates the given service saving to the outputFile in the language passed in.
        /// </summary>
        public static void GenerateService(string serviceName,
            string version,
            string clientNamespace,
            string language,
            string outputFile)
        {
            // Generate the discovery URL for that service
            string url = string.Format(GoogleDiscoveryURL, serviceName, version);

            var discovery = CreateDefaultCachingDiscovery(url);
            // Build the service based on discovery information.
            var service = discovery.GetService(DiscoveryVersion.Version_1_0);

            var generator = new GoogleServiceGenerator(service, clientNamespace);
            var generatedCode = generator.GenerateCode();

            var provider = CodeDomProvider.CreateProvider(language);

            using (StreamWriter sw = new StreamWriter(outputFile, false))
            {
                IndentedTextWriter tw = new IndentedTextWriter(sw, "  ");

                // Generate source code using the code provider.
                provider.GenerateCodeFromCompileUnit(generatedCode, tw, new CodeGeneratorOptions());

                // Close the output file.
                tw.Close();
            }
        }
        /// <summary>
        ///     Checks all the parameters and calls the GoogleServiceGenerator.
        /// </summary>
        protected override void ExecuteTask()
        {
            DiscoveryUrl.ThrowIfNullOrEmpty("DiscoveryUrl");
            OutputFile.ThrowIfNull("OutputFile");
            ClientNamespace.ThrowIfNullOrEmpty("ClientNamespace");
            ApiVersion.ThrowIfNullOrEmpty("ApiVersion");
            BaseUrl.ThrowIfNullOrEmpty("BaseUrl");

            Project.Log(Level.Info, "Fetching Discovery " + DiscoveryUrl);
            var fetcher = new WebDiscoveryDevice(new Uri(DiscoveryUrl));
            var discovery = new DiscoveryService(fetcher);
            var param = new FactoryParameterV1_0(BaseUrl, null);
            var service = discovery.GetService(DiscoveryVersion.Version_1_0, param);
            var generator = new GoogleServiceGenerator(service, ClientNamespace);
            var provider = CodeDomProvider.CreateProvider("CSharp");
            Project.Log(Level.Info, "Generating To File " + OutputFile.FullName);
            using (StreamWriter sw = new StreamWriter(OutputFile.FullName, false))
            {
                IndentedTextWriter tw = new IndentedTextWriter(sw, "  ");
                provider.GenerateCodeFromCompileUnit(generator.GenerateCode(), tw, new CodeGeneratorOptions());
                tw.Close();
            }
        }