Пример #1
0
        /// <summary>
        /// Generates a service from the specified discovery uri.
        /// </summary>
        /// <param name="url">The URL or file where the discovery document can be found.</param>
        public void GenerateService(Uri url)
        {
            Console.WriteLine(" Generating: " + url);

            // Create the output directory if it does not exist yet.
            if (!Directory.Exists(OutputDir))
            {
                Directory.CreateDirectory(OutputDir);
            }

            // Discover the service.
            Console.WriteLine("  Fetching " + url);
            IDiscoveryDevice src = url.IsFile
                ? (IDiscoveryDevice)
                                   new StreamDiscoveryDevice
            {
                DiscoveryStream = File.Open(url.LocalPath, FileMode.Open, FileAccess.Read)
            }
                : new StringDiscoveryDevice {
                Document = Utils.FetchDocument(url)
            };
            var      discovery = new DiscoveryService(src);
            IService service   = discovery.GetService(DiscoveryVersion.Version_1_0);

            // Generate the formal names based upon the discovery data.
            string name    = service.Name;
            string version = service.Version;

            string formalServiceName = GeneratorUtils.UpperFirstLetter(name);
            string serviceNamespace  = GeneratorUtils.GetNamespaceName(formalServiceName);

            if ((Flags & GeneratorFlags.GoogleService) > 0) // If this is a google service, add the google prefix.
            {
                formalServiceName = GooglePrefix + formalServiceName;
                serviceNamespace  = GooglePrefix + serviceNamespace;
            }

            string baseFileName = Path.Combine(OutputDir, formalServiceName + "." + version);
            string fileName     = baseFileName + CodeFileExtension;
            string libfileName  = baseFileName + LibraryExtension;

            serviceNamespace = String.Format("{0}.{1}", serviceNamespace, GeneratorUtils.GetNamespaceName(version));

            // Produce the code.
            var             generator     = new GoogleServiceGenerator(service, serviceNamespace);
            CodeCompileUnit generatedCode = generator.GenerateCode();

            WriteCodeToFile(generatedCode, fileName);

            if ((Flags & GeneratorFlags.CompileLibrary) > 0)
            {
                CompileIntoLibrary(service, generatedCode, libfileName);
            }
        }
Пример #2
0
 /// <summary>
 /// Insantiates the discovery class
 /// </summary>
 public DiscoveryService(IDiscoveryDevice discovery)
 {
     DiscoveryDevice = discovery;
 }
Пример #3
0
 /// <summary>
 /// Insantiates the discovery class
 /// </summary>
 public DiscoveryService(IDiscoveryDevice discovery)
 {
     DiscoveryDevice = discovery;
 }