Ejemplo n.º 1
0
        private async Task GenerateCodeForV3Clients(GenerateOptions generateOptions, IConsole console)
        {
            var serviceConfiguration = new ServiceConfiguration();

            serviceConfiguration.Endpoint                           = generateOptions.MetadataUri;
            serviceConfiguration.ServiceName                        = Constants.DefaultServiceName;
            serviceConfiguration.GeneratedFileNamePrefix            = generateOptions.FileName;
            serviceConfiguration.CustomHttpHeaders                  = generateOptions.CustomHeaders;
            serviceConfiguration.WebProxyHost                       = generateOptions.WebProxyHost;
            serviceConfiguration.IncludeWebProxy                    = generateOptions.IncludeWebProxy;
            serviceConfiguration.IncludeWebProxyNetworkCredentials  = generateOptions.IncludeWebProxyNetworkCredentials;
            serviceConfiguration.WebProxyNetworkCredentialsUsername = generateOptions.WebProxyNetworkCredentialsUsername;
            serviceConfiguration.WebProxyNetworkCredentialsPassword = generateOptions.WebProxyNetworkCredentialsPassword;
            serviceConfiguration.WebProxyNetworkCredentialsDomain   = generateOptions.WebProxyNetworkCredentialsDomain;
            serviceConfiguration.NamespacePrefix                    = generateOptions.NamespacePrefix;

            Project project = ProjectHelper.CreateProjectInstance(generateOptions.OutputDir);
            BaseCodeGenDescriptor codeGenDescriptor = new CodeGenDescriptorFactory().Create(
                Constants.EdmxVersion3,
                new ODataCliFileHandler(new ODataCliMessageLogger(console), project),
                new ODataCliMessageLogger(console),
                new ODataCliPackageInstaller(project,
                                             new ODataCliMessageLogger(console)));
            await codeGenDescriptor.AddNugetPackagesAsync().ConfigureAwait(false);

            await codeGenDescriptor.AddGeneratedClientCodeAsync(generateOptions.MetadataUri, generateOptions.OutputDir, LanguageOption.GenerateCSharpCode, serviceConfiguration).ConfigureAwait(false);
        }
Ejemplo n.º 2
0
        private async Task GenerateCodeForV4Clients(GenerateOptions generateOptions, IConsole console)
        {
            var serviceConfigurationV4 = new ServiceConfigurationV4();

            serviceConfigurationV4.Endpoint                              = generateOptions.MetadataUri;
            serviceConfigurationV4.ServiceName                           = Constants.DefaultServiceName;
            serviceConfigurationV4.GeneratedFileNamePrefix               = generateOptions.FileName;
            serviceConfigurationV4.CustomHttpHeaders                     = generateOptions.CustomHeaders;
            serviceConfigurationV4.WebProxyHost                          = generateOptions.WebProxyHost;
            serviceConfigurationV4.IncludeWebProxy                       = generateOptions.IncludeWebProxy;
            serviceConfigurationV4.IncludeWebProxyNetworkCredentials     = generateOptions.IncludeWebProxyNetworkCredentials;
            serviceConfigurationV4.WebProxyNetworkCredentialsUsername    = generateOptions.WebProxyNetworkCredentialsUsername;
            serviceConfigurationV4.WebProxyNetworkCredentialsPassword    = generateOptions.WebProxyNetworkCredentialsPassword;
            serviceConfigurationV4.WebProxyNetworkCredentialsDomain      = generateOptions.WebProxyNetworkCredentialsDomain;
            serviceConfigurationV4.NamespacePrefix                       = generateOptions.NamespacePrefix;
            serviceConfigurationV4.MakeTypesInternal                     = generateOptions.EnableInternal;
            serviceConfigurationV4.GenerateMultipleFiles                 = generateOptions.MultipleFiles;
            serviceConfigurationV4.ExcludedSchemaTypes                   = generateOptions.ExcludedSchemaTypes;
            serviceConfigurationV4.ExcludedBoundOperations               = generateOptions.ExcludedBoundOperations;
            serviceConfigurationV4.ExcludedOperationImports              = generateOptions.ExcludedOperationImports;
            serviceConfigurationV4.IgnoreUnexpectedElementsAndAttributes = generateOptions.IgnoreUnexpectedElements;
            serviceConfigurationV4.EnableNamingAlias                     = generateOptions.UpperCamelCase;

            Project project = ProjectHelper.CreateProjectInstance(generateOptions.OutputDir);
            BaseCodeGenDescriptor codeGenDescriptor = new CodeGenDescriptorFactory().Create(
                Constants.EdmxVersion4,
                new ODataCliFileHandler(new ODataCliMessageLogger(console), project),
                new ODataCliMessageLogger(console),
                new ODataCliPackageInstaller(project, new ODataCliMessageLogger(console)));
            await codeGenDescriptor.AddNugetPackagesAsync().ConfigureAwait(false);

            await codeGenDescriptor.AddGeneratedClientCodeAsync(generateOptions.MetadataUri, generateOptions.OutputDir, LanguageOption.GenerateCSharpCode, serviceConfigurationV4).ConfigureAwait(false);
        }
Ejemplo n.º 3
0
        private async Task <int> HandleGenerateCommand(GenerateOptions options, IConsole console)
        {
            try
            {
                if (!Directory.Exists(options.OutputDir))
                {
                    Directory.CreateDirectory(options.OutputDir);
                }

                if (options.Proxy != null)
                {
                    string[] proxyParts = options.Proxy.Split('@');
                    string   server     = proxyParts.Length > 0 ? proxyParts[0] : string.Empty;
                    string   username   = proxyParts.Length > 1 ? proxyParts[1] : string.Empty;

                    if (!string.IsNullOrWhiteSpace(server))
                    {
                        options.WebProxyHost = server;
                        if (!string.IsNullOrWhiteSpace(username))
                        {
                            string[] usernameParts = username.Split(':');
                            options.WebProxyNetworkCredentialsPassword = usernameParts.Length > 1 ? usernameParts[1] : string.Empty;

                            string[] userParts = usernameParts[0].Split('\\', '/');
                            options.WebProxyNetworkCredentialsDomain   = userParts.Length > 0 ? userParts[0] : string.Empty;
                            options.WebProxyNetworkCredentialsUsername = userParts.Length > 1 ? userParts[1] : string.Empty;
                            options.IncludeWebProxyNetworkCredentials  = true;
                        }
                        options.IncludeWebProxy = true;
                    }
                }

                Version version = GetMetadataVersion(options);
                if (version == Constants.EdmxVersion4)
                {
                    await GenerateCodeForV4Clients(options, console).ConfigureAwait(false);
                }
                else if (version == Constants.EdmxVersion3)
                {
                    await GenerateCodeForV3Clients(options, console).ConfigureAwait(false);
                }
            }
            catch (Exception ex)
            {
                console.Error.Write(ex.Message);
                return(0);
            }

            return(1);
        }
Ejemplo n.º 4
0
        private Version GetMetadataVersion(GenerateOptions generateOptions)
        {
            Version version = null;
            var     serviceConfiguration = new ServiceConfiguration();

            serviceConfiguration.Endpoint          = generateOptions.MetadataUri;
            serviceConfiguration.CustomHttpHeaders = generateOptions.CustomHeaders;
            serviceConfiguration.WebProxyHost      = generateOptions.WebProxyHost;
            serviceConfiguration.IncludeWebProxy   = generateOptions.IncludeWebProxy;
            serviceConfiguration.IncludeWebProxyNetworkCredentials  = generateOptions.IncludeWebProxyNetworkCredentials;
            serviceConfiguration.WebProxyNetworkCredentialsUsername = generateOptions.WebProxyNetworkCredentialsUsername;
            serviceConfiguration.WebProxyNetworkCredentialsPassword = generateOptions.WebProxyNetworkCredentialsPassword;
            serviceConfiguration.WebProxyNetworkCredentialsDomain   = generateOptions.WebProxyNetworkCredentialsDomain;

            version = MetadataReader.GetMetadataVersion(serviceConfiguration);
            return(version);
        }