예제 #1
0
        async Task <Profile> ITextkernelParser.Parse(byte[] file, string filename)
        {
            this.logger.LogInformation("Parsing {FileLength} Bytes", file.Length);

            var sw = new Stopwatch();

            sw.Start();

            // Create the auto-generated Extract service client, pointing to the configured address
            var extractService = new ExtractInterfaceClient(ExtractInterfaceClient.EndpointConfiguration.ExtractImplPort, this.address);

            // Call the WCF generated from the SOAP WSDL
            var result = await extractService.extractAdvancedAsync(this.account, this.username, this.password, this.entries, filename, file, null, null, null);

            sw.Stop();

            // Get the raw content result
            string rawResult = result.@return;

            this.logger.LogInformation("Textkernel Extract Response {Chars}chars in {ServiceDuration}ms", rawResult.Length, sw.ElapsedMilliseconds);

            sw.Restart();

            Profile p;

            // Load the string into a stream we can pass to the deseraliser
            using (var stream = new MemoryStream())
                using (var writer = new StreamWriter(stream))
                {
                    writer.Write(rawResult);
                    writer.Flush();
                    stream.Position = 0;

                    // Textkernel includes all empty nodes, which results in lots of serialised empty strings,
                    // strip empty nodes out first
                    var cleaner = await XDocument.LoadAsync(stream, LoadOptions.None, CancellationToken.None);

                    cleaner.Descendants().Where(e => string.IsNullOrEmpty(e.Value)).Remove();

                    // Create a reader for the cleaned XML and deserialise
                    using (var reader = cleaner.CreateReader())
                        p = this.serializer.Deserialize(reader) as Profile;
                }

            sw.Stop();
            this.logger.LogInformation("Textkernel Parsed: {CurrentJob} in {ParseDuration}ms", p?.Summary?.CurrentJob, sw.ElapsedMilliseconds);

            return(p);
        }
예제 #2
0
 private static System.ServiceModel.EndpointAddress GetDefaultEndpointAddress()
 {
     return(ExtractInterfaceClient.GetEndpointAddress(EndpointConfiguration.ExtractImplPort));
 }
예제 #3
0
 private static System.ServiceModel.Channels.Binding GetDefaultBinding()
 {
     return(ExtractInterfaceClient.GetBindingForEndpoint(EndpointConfiguration.ExtractImplPort));
 }
예제 #4
0
 public ExtractInterfaceClient(EndpointConfiguration endpointConfiguration, System.ServiceModel.EndpointAddress remoteAddress) :
     base(ExtractInterfaceClient.GetBindingForEndpoint(endpointConfiguration), remoteAddress)
 {
     this.Endpoint.Name = endpointConfiguration.ToString();
     ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
 }
예제 #5
0
 public ExtractInterfaceClient(EndpointConfiguration endpointConfiguration) :
     base(ExtractInterfaceClient.GetBindingForEndpoint(endpointConfiguration), ExtractInterfaceClient.GetEndpointAddress(endpointConfiguration))
 {
     this.Endpoint.Name = endpointConfiguration.ToString();
     ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
 }
예제 #6
0
 public ExtractInterfaceClient() :
     base(ExtractInterfaceClient.GetDefaultBinding(), ExtractInterfaceClient.GetDefaultEndpointAddress())
 {
     this.Endpoint.Name = EndpointConfiguration.ExtractImplPort.ToString();
     ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
 }