Beispiel #1
0
        /// <summary>
        ///     Retrieves the first picture of the document.
        /// </summary>
        /// <param name="number">The publication number.</param>
        /// <param name="cancellationToken">The cancellation notification.</param>
        /// <returns>The first picture of the document.</returns>
        public async Task <byte[]> RetrieveFirstPicture(PatentNumber number, CancellationToken cancellationToken)
        {
            var target = $"published-data/images/{number.C}/{number.N}/PA/firstpage";
            var result = await _requestManager.Execute(target, OPSConstants.Format.Picture, OPSConverter.ToByteArray, null, cancellationToken);

            return(result.Success && result.Content?.Length > 0 ? result.Content : null);
        }
        private async Task <Patent[]> Retrieve(int offset = 0)
        {
            var lines = _numbersTextBox.Text.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);

            if (lines.Length == 0)
            {
                return(new Patent[0]);
            }

            _previewListBox.Items.Clear();

            _progressBar.Maximum = lines.Length + offset;
            _progressLabel.Text  = "parsing numbers";

            var output  = new List <string>();
            var results = new List <Patent>();

            foreach (var line in lines)
            {
                try
                {
                    var number = PatentNumber.Parse(line);

                    await UpdateProgression(number.ToString());

                    var patent = await ToolsContext.Current.Provider.Retrieve(number);

                    var patentTitle = string.Concat(number, '\t', patent.Title?.ToUpper() ?? "N/A");

                    _previewListBox.Items.Add(patentTitle);

                    output.Add(number.ToString());
                    results.Add(patent);
                }
                catch
                {
                    if (!line.StartsWith("*"))
                    {
                        output.Add(string.Concat("*", line));
                    }
                }
                finally
                {
                    await UpdateProgression();
                }
            }

            _numbersTextBox.Text = string.Join(Environment.NewLine, output);
            return(results.ToArray());
        }
Beispiel #3
0
        /// <summary>
        ///     Retrieves all the family members of the document.
        /// </summary>
        /// <param name="number">The publication number.</param>
        /// <param name="cancellationToken">The cancellation notification.</param>
        /// <returns>The family members of the document.</returns>
        public async Task <PatentFamilyMember[]> RetrieveFamily(PatentNumber number, CancellationToken cancellationToken)
        {
            var content = number.Format('.');
            var result  = await _requestManager.Execute("family/publication/docdb", OPSConstants.Format.Exchange, OPSConverter.ToWPD, content, cancellationToken);

            if (!result.Success || result.Content.PatentFamily == null)
            {
                throw new InvalidOperationException($"cannot retrieve family members for {number}: ${result.Error.Code}");
            }

            var patentFamilyMemberAssembler = new PatentFamilyMemberAssembler();

            return(patentFamilyMemberAssembler.Convert(result.Content.PatentFamily.FamilyMembers));
        }
Beispiel #4
0
        /// <summary>
        ///     Retrieves the patent document corresponding to the publication number.
        /// </summary>
        /// <param name="number">The publication number.</param>
        /// <param name="cancellationToken">The cancellation notification.</param>
        /// <returns>The patent document corresponding to the publication number.</returns>
        public async Task <Patent> Retrieve(PatentNumber number, CancellationToken cancellationToken = default)
        {
            var patent = await _opsClient.RetrievePatent(number, cancellationToken);

            patent.Family = await _opsClient.RetrieveFamily(number, cancellationToken);

            patent.Picture = await _opsClient.RetrieveFirstPicture(number, cancellationToken);

            if (number.C == "EP" && number.K.StartsWith("B"))
            {
                patent.Claims = await _epsClient.RetrieveClaims(number, cancellationToken);
            }

            return(patent);
        }
Beispiel #5
0
        /// <summary>
        ///     Write the error to a text file.
        /// </summary>
        /// <param name="number">The publication number.</param>
        /// <param name="exception">The exception.</param>
        private void WriteError(PatentNumber number, Exception exception)
        {
            try
            {
                var content  = new StringBuilder();
                var filename = Path.Combine(_temporaryDirectory, $"{number.Format()}.txt");

                content.AppendFormat("[{0}] {1}{2}", DateTime.Now, exception.Message, Environment.NewLine);
                content.Append(exception.StackTrace).Append(Environment.NewLine).Append(Environment.NewLine);

                File.AppendAllText(filename, content.ToString());
            }
            catch
            {
                // ignored
            }
        }
Beispiel #6
0
        /// <summary>
        ///     Retrieves the patent document corresponding to the publication number.
        /// </summary>
        /// <param name="number">The publication number.</param>
        /// <param name="cancellationToken">The cancellation notification.</param>
        /// <returns>The patent document corresponding to the publication number.</returns>
        public async Task <Patent> RetrievePatent(PatentNumber number, CancellationToken cancellationToken = default)
        {
            if (number == null)
            {
                throw new ArgumentNullException(nameof(number));
            }

            var patentAssembler = new PatentAssembler();

            var content = number.Format('.');
            var result  = await _requestManager.Execute("published-data/publication/docdb/biblio", OPSConstants.Format.Exchange, OPSConverter.ToWPD, content, cancellationToken);

            if (!result.Success && result.Content.ExchangeDocuments.Length != 0)
            {
                throw new InvalidOperationException($"cannot retrieve root document for {number}: ${result.Error.Code}");
            }

            return(patentAssembler.Convert(result.Content.ExchangeDocuments[0]));
        }
Beispiel #7
0
        /// <summary>
        ///     Retrieves the patent document corresponding to the publication number.
        /// </summary>
        /// <param name="number">The publication number.</param>
        /// <param name="cancellationToken">The cancellation notification.</param>
        /// <returns>The patent document corresponding to the publication number.</returns>
        public async Task <Patent> Retrieve(PatentNumber number, CancellationToken cancellationToken = default)
        {
            try
            {
                var patent = await _opsClient.RetrievePatent(number, cancellationToken);

                patent.Family = await _opsClient.RetrieveFamily(number, cancellationToken);

                patent.Picture = await _opsClient.RetrieveFirstPicture(number, cancellationToken);

                if (string.IsNullOrEmpty(patent.Abstract) && patent.Family.Any(x => x.PublicationNumber.C == "WO"))
                {
                    try
                    {
                        var pctFamilyMember = patent.Family.First(x => x.PublicationNumber.C == "WO");
                        var pctPatent       = await _opsClient.RetrievePatent(pctFamilyMember.PublicationNumber, cancellationToken);

                        patent.Abstract = string.Concat("[FROM ", pctFamilyMember.PublicationNumber, "] ", pctPatent.Abstract);
                    }
                    catch
                    {
                        // ignored
                    }
                }

                if (number.C == "EP" && number.K.StartsWith("B"))
                {
                    patent.Claims = await _epsClient.RetrieveClaims(number, cancellationToken);
                }

                return(patent);
            }
            catch (Exception exception)
            {
                WriteError(number, exception);
                throw;
            }
        }
Beispiel #8
0
 /// <summary>
 ///     Insert a link to the document.
 /// </summary>
 /// <param name="target">The target in the document.</param>
 /// <param name="address">The URL address.</param>
 /// <param name="number">The patent number.</param>
 private void InsertLink(Range target, string address, PatentNumber number)
 {
     InsertLink(target, address, number.ToString());
 }
Beispiel #9
0
 /// <summary>
 ///     Formats the input value.
 /// </summary>
 /// <param name="input">The input value.</param>
 /// <returns>The output string.</returns>
 private string Format(PatentNumber input)
 {
     return(input != null?input.Format(' ') : _empty);
 }
        /// <summary>
        ///     Gets the temporary target path.
        /// </summary>
        /// <param name="number">The publication number.</param>
        /// <returns>The temporary target path.</returns>
        private string GetTemporaryTarget(PatentNumber number)
        {
            var filename = string.Concat(number.Format(), _pictureFormat).ToLower();

            return(Path.Combine(ToolsContext.Current.TemporaryDirectory, filename));
        }
 /// <summary>
 ///     Inserts the value into the document target range.
 /// </summary>
 /// <param name="target">The document target range.</param>
 /// <param name="value">The value.</param>
 private void Insert(Range target, PatentNumber value)
 {
     Insert(target, value?.ToString());
 }
 /// <summary>
 ///     Inserts the value into the document target range.
 /// </summary>
 /// <param name="target">The document target range.</param>
 /// <param name="value">The value.</param>
 /// <param name="address">The URL address.</param>
 private void Insert(Range target, PatentNumber value, string address)
 {
     Insert(target, value.ToString(), address);
 }