Пример #1
0
        private Task <string> CheckAndAddReferenceFolder(ConnectedServiceHandlerContext context, Project project)
        {
            ODataConnectedServiceInstance codeGenInstance = (ODataConnectedServiceInstance)context.ServiceInstance;
            var serviceReferenceFolderName = context.HandlerHelper.GetServiceArtifactsRootFolder();

            ProjectItem serviceReferenceFolder;
            ProjectItem namespaceFolder;

            project.ProjectItems.TryGetFolder(serviceReferenceFolderName, out serviceReferenceFolder);

            if (codeGenInstance.NamespacePrefix != null)
            {
                if (!serviceReferenceFolder.ProjectItems.TryGetFolder(codeGenInstance.NamespacePrefix, out namespaceFolder))
                {
                    serviceReferenceFolder.ProjectItems.AddFolder(codeGenInstance.NamespacePrefix);
                }
            }

            var referenceFolderPath = Path.Combine(
                ProjectHelper.GetProjectFullPath(project),
                serviceReferenceFolderName,
                codeGenInstance.NamespacePrefix ?? "");

            return(Task.FromResult <string>(referenceFolderPath));
        }
Пример #2
0
        /// <summary>
        /// Cleanup object references
        /// </summary>
        /// <param name="disposing"></param>
        protected override void Dispose(bool disposing)
        {
            try
            {
                if (disposing)
                {
                    if (this.AdvancedSettingsViewModel != null)
                    {
                        this.AdvancedSettingsViewModel.Dispose();
                        this.AdvancedSettingsViewModel = null;
                    }

                    if (this.ConfigODataEndpointViewModel != null)
                    {
                        this.ConfigODataEndpointViewModel.Dispose();
                        this.ConfigODataEndpointViewModel = null;
                    }

                    if (this.serviceInstance != null)
                    {
                        this.serviceInstance.Dispose();
                        this.serviceInstance = null;
                    }
                }
            }
            finally
            {
                base.Dispose(disposing);
            }
        }
Пример #3
0
        public override async Task <UpdateServiceInstanceResult> UpdateServiceInstanceAsync(ConnectedServiceHandlerContext context, CancellationToken ct)
        {
            Project project = ProjectHelper.GetProjectFromHierarchy(context.ProjectHierarchy);
            ODataConnectedServiceInstance codeGenInstance = (ODataConnectedServiceInstance)context.ServiceInstance;

            var codeGenDescriptor = await GenerateCode(codeGenInstance.ServiceConfig.Endpoint, codeGenInstance.ServiceConfig.EdmxVersion, context, project);

            context.SetExtendedDesignerData <ServiceConfiguration>(codeGenInstance.ServiceConfig);
            return(new UpdateServiceInstanceResult());
        }
        private async Task <BaseCodeGenDescriptor> SaveServiceInstanceAsync(ConnectedServiceHandlerContext context)
        {
            Project project = ProjectHelper.GetProjectFromHierarchy(context.ProjectHierarchy);
            ODataConnectedServiceInstance serviceInstance = (ODataConnectedServiceInstance)context.ServiceInstance;

            var codeGenDescriptor = await GenerateCodeAsync(serviceInstance.ServiceConfig.Endpoint, serviceInstance.ServiceConfig.EdmxVersion, context, project);

            context.SetExtendedDesignerData <ServiceConfiguration>(serviceInstance.ServiceConfig);
            return(codeGenDescriptor);
        }
Пример #5
0
        private string GetReferenceFolderName(ConnectedServiceHandlerContext context, Project project)
        {
            ODataConnectedServiceInstance codeGenInstance = (ODataConnectedServiceInstance)context.ServiceInstance;
            var serviceReferenceFolderName = context.HandlerHelper.GetServiceArtifactsRootFolder();

            var referenceFolderPath = Path.Combine(
                ProjectHelper.GetProjectFullPath(project),
                serviceReferenceFolderName,
                context.ServiceInstance.Name,
                codeGenInstance.NamespacePrefix ?? "");

            return(referenceFolderPath);
        }
Пример #6
0
        public override Task <ConnectedServiceInstance> GetFinishedServiceInstanceAsync()
        {
            this.userSettings.Save();

            ODataConnectedServiceInstance instance = new ODataConnectedServiceInstance();

            instance.InstanceId           = AdvancedSettingsViewModel.GeneratedFileName;
            instance.Name                 = ConfigODataEndpointViewModel.ServiceName;
            instance.MetadataTempFilePath = ConfigODataEndpointViewModel.MetadataTempPath;

            instance.ServiceConfig = this.CreateServiceConfiguration();

            return(Task.FromResult <ConnectedServiceInstance>(instance));
        }
Пример #7
0
        public override async Task <AddServiceInstanceResult> AddServiceInstanceAsync(ConnectedServiceHandlerContext context, CancellationToken ct)
        {
            Project project = ProjectHelper.GetProjectFromHierarchy(context.ProjectHierarchy);
            ODataConnectedServiceInstance codeGenInstance = (ODataConnectedServiceInstance)context.ServiceInstance;

            var codeGenDescriptor = await GenerateCode(codeGenInstance.MetadataTempFilePath, codeGenInstance.ServiceConfig.EdmxVersion, context, project);

            context.SetExtendedDesignerData <ServiceConfiguration>(codeGenInstance.ServiceConfig);

            var result = new AddServiceInstanceResult(
                context.ServiceInstance.Name,
                new Uri(codeGenDescriptor.ClientDocUri));

            return(result);
        }
        public override Task<ConnectedServiceInstance> GetFinishedServiceInstanceAsync()
        {
            ODataConnectedServiceInstance instance = new ODataConnectedServiceInstance();
            instance.Name = "OData Connected Service";
            instance.Endpoint = ConfigODataEndpointViewModel.Endpoint;
            instance.GenByDataSvcUtil = ConfigODataEndpointViewModel.UseDataSvcUtil;
            if (AdvancedSettingsViewModel.UseNamespacePrefix)
            {
                instance.NamespacePrefix = AdvancedSettingsViewModel.NamespacePrefix;
            }

            instance.IgnoreUnexpectedElementsAndAttributes = AdvancedSettingsViewModel.IgnoreUnexpectedElementsAndAttributes;
            instance.UseDataServiceCollection = AdvancedSettingsViewModel.UseDataServiceCollection;
            instance.EnableNamingAlias = AdvancedSettingsViewModel.EnableNamingAlias;

            return Task.FromResult<ConnectedServiceInstance>(instance);
        }
Пример #9
0
        private async Task GenerateClientCodeWithoutDataSvcUtil(ConnectedServiceHandlerContext context, Project project)
        {
            await context.Logger.WriteMessageAsync(LoggerMessageCategory.Information, "Generating Client Proxy ...");

            ODataConnectedServiceInstance codeGenInstance = (ODataConnectedServiceInstance)context.ServiceInstance;
            var address = codeGenInstance.Endpoint;

            if (address.StartsWith("https:") || address.StartsWith("http"))
            {
                if (!address.EndsWith("$metadata"))
                {
                    address = address.TrimEnd('/') + "/$metadata";
                }
            }

            EntityClassGenerator generator = new EntityClassGenerator(LanguageOption.GenerateCSharpCode);

            generator.UseDataServiceCollection = codeGenInstance.UseDataServiceCollection;
            generator.Version = DataServiceCodeVersion.V3;

            var referenceFolderPath = await CheckAndAddReferenceFolder(context, project);

            string outputFile = Path.Combine(referenceFolderPath, "Reference.cs");

            XmlReaderSettings settings = new XmlReaderSettings();

            if (!String.IsNullOrEmpty(address))
            {
                XmlResolver resolver = new XmlUrlResolver();
                {
                    resolver.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
                }

                settings.XmlResolver = resolver;
            }

            using (XmlReader reader = XmlReader.Create(address, settings))
            {
                using (StreamWriter writer = File.CreateText(outputFile))
                {
                    var error = generator.GenerateCode(reader, writer, codeGenInstance.NamespacePrefix);
                }
            }
            await context.HandlerHelper.AddFileAsync(outputFile, outputFile);
        }
Пример #10
0
        public override Task <ConnectedServiceInstance> GetFinishedServiceInstanceAsync()
        {
            ODataConnectedServiceInstance instance = new ODataConnectedServiceInstance();

            instance.Name             = "OData Connected Service";
            instance.Endpoint         = ConfigODataEndpointViewModel.Endpoint;
            instance.GenByDataSvcUtil = ConfigODataEndpointViewModel.UseDataSvcUtil;
            if (AdvancedSettingsViewModel.UseNamespacePrefix)
            {
                instance.NamespacePrefix = AdvancedSettingsViewModel.NamespacePrefix;
            }

            instance.IgnoreUnexpectedElementsAndAttributes = AdvancedSettingsViewModel.IgnoreUnexpectedElementsAndAttributes;
            instance.UseDataServiceCollection = AdvancedSettingsViewModel.UseDataServiceCollection;
            instance.EnableNamingAlias        = AdvancedSettingsViewModel.EnableNamingAlias;

            return(Task.FromResult <ConnectedServiceInstance>(instance));
        }
Пример #11
0
        /// <summary>
        /// Cleanup object references
        /// </summary>
        /// <param name="disposing"></param>
        protected override void Dispose(bool disposing)
        {
            try
            {
                if (disposing)
                {
                    if (AdvancedSettingsViewModel != null)
                    {
                        AdvancedSettingsViewModel.Dispose();
                        AdvancedSettingsViewModel = null;
                    }

                    if (OperationImportsViewModel != null)
                    {
                        OperationImportsViewModel.Dispose();
                        OperationImportsViewModel = null;
                    }

                    if (SchemaTypesViewModel != null)
                    {
                        SchemaTypesViewModel.Dispose();
                        SchemaTypesViewModel = null;
                    }

                    if (ConfigODataEndpointViewModel != null)
                    {
                        ConfigODataEndpointViewModel.Dispose();
                        ConfigODataEndpointViewModel = null;
                    }

                    if (serviceInstance != null)
                    {
                        serviceInstance.Dispose();
                        serviceInstance = null;
                    }
                }
            }
            finally
            {
                base.Dispose(disposing);
            }
        }
Пример #12
0
        public override async Task <UpdateServiceInstanceResult> UpdateServiceInstanceAsync(ConnectedServiceHandlerContext context, CancellationToken ct)
        {
            Project project = ProjectHelper.GetProjectFromHierarchy(context.ProjectHierarchy);
            ODataConnectedServiceInstance codeGenInstance = (ODataConnectedServiceInstance)context.ServiceInstance;

            if (codeGenInstance.GenByDataSvcUtil)
            {
                await this.AddNuGetPackagesAsync(context, project, new Version(3, 0));

                await this.GenerateClientCode(context, project);
            }
            else
            {
                await this.AddNuGetPackagesAsync(context, project, new Version(3, 0));

                await this.GenerateClientCodeWithoutDataSvcUtil(context, project);
            }

            UpdateServiceInstanceResult result = new UpdateServiceInstanceResult();

            return(result);
        }
Пример #13
0
        private async Task GenerateClientCode(ConnectedServiceHandlerContext context, Project project)
        {
            await context.Logger.WriteMessageAsync(LoggerMessageCategory.Information, "Generating Client Proxy ...");

            ODataConnectedServiceInstance codeGenInstance = (ODataConnectedServiceInstance)context.ServiceInstance;

            string command = Path.Combine(CodeGeneratorUtils.GetWCFDSInstallLocation(), @"bin\tools\DataSvcUtil.exe");

            string referenceFolderPath = GetReferenceFolderName(context, project);
            string outputFile          = Path.Combine(referenceFolderPath, "Reference.cs");

            StringBuilder arguments = new StringBuilder(string.Format("/c \"\"{0}\" /version:3.0 /language:{1} /out:\"{2}\" /uri:{3}", command, "CSharp", outputFile, codeGenInstance.Endpoint));

            if (codeGenInstance.UseDataServiceCollection)
            {
                arguments.Append("/dataServiceCollection");
            }

            arguments.Append("\"");

            ProcessHelper.ExecuteCommand(command, arguments.ToString());
            await context.HandlerHelper.AddFileAsync(outputFile, outputFile);
        }
Пример #14
0
        private async Task GenerateClientCodeWithoutDataSvcUtil(ConnectedServiceHandlerContext context, Project project)
        {
            await context.Logger.WriteMessageAsync(LoggerMessageCategory.Information, "Generating Client Proxy ...");

            ODataConnectedServiceInstance codeGenInstance = (ODataConnectedServiceInstance)context.ServiceInstance;
            string address = codeGenInstance.Endpoint;

            if (address == null)
            {
                throw new Exception("Please input the service endpoint");
            }

            if (address.StartsWith("https:") || address.StartsWith("http"))
            {
                if (!address.EndsWith("$metadata"))
                {
                    address = address.TrimEnd('/') + "/$metadata";
                }
            }

            EntityClassGenerator generator = new EntityClassGenerator(LanguageOption.GenerateCSharpCode);

            generator.UseDataServiceCollection = codeGenInstance.UseDataServiceCollection;
            generator.Version = DataServiceCodeVersion.V3;

            string referenceFolderPath = GetReferenceFolderName(context, project);
            string outputFile          = Path.Combine(referenceFolderPath, "Reference.cs");

            XmlReaderSettings settings = new XmlReaderSettings();

            if (!String.IsNullOrEmpty(address))
            {
                XmlResolver resolver = new XmlUrlResolver();
                {
                    resolver.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
                }

                settings.XmlResolver = resolver;
            }
            XmlReader reader = null;

            try
            {
                reader = XmlReader.Create(address, settings);

                string tempFile = Path.GetTempFileName();

                using (StreamWriter writer = File.CreateText(tempFile))
                {
                    var errors = generator.GenerateCode(reader, writer, codeGenInstance.NamespacePrefix);
                    if (errors != null && errors.Count() > 0)
                    {
                        foreach (var err in errors)
                        {
                            await context.Logger.WriteMessageAsync(LoggerMessageCategory.Warning, err.Message);
                        }
                    }
                }

                reader.Close();
                await context.HandlerHelper.AddFileAsync(tempFile, outputFile);
            }
            catch (WebException e)
            {
                throw new Exception(string.Format("Cannot access {0}", address), e);
            }
            finally
            {
                if (reader != null)
                {
                    reader.Dispose();
                    reader = null;
                }
            }
        }
Пример #15
0
        public override Task<ConnectedServiceInstance> GetFinishedServiceInstanceAsync()
        {
            this.userSettings.Save();

            ODataConnectedServiceInstance instance = new ODataConnectedServiceInstance();
            instance.InstanceId = AdvancedSettingsViewModel.GeneratedFileName;
            instance.Name = ConfigODataEndpointViewModel.ServiceName;
            instance.MetadataTempFilePath = ConfigODataEndpointViewModel.MetadataTempPath;

            instance.ServiceConfig = this.CreateServiceConfiguration();

            return Task.FromResult<ConnectedServiceInstance>(instance);
        }