Exemplo n.º 1
0
        /// <summary>
        /// Gets document with type from queue.
        /// </summary>
        /// <param name="docType">Document type, e.g.: docx, pptx, xlsx.</param>
        /// <returns>Document information.</returns>
        /// <exception cref="ArgumentException">When document type is wrong.</exception>
        public WebDocumentInfo GetDocument(string docType, int sizeFile)
        {
            if (docType == null || !availableDocs.TryGetValue(docType, out var docsQueue))
            {
                throw new ArgumentException($"Could not get documents collection for type {docType}.");
            }

            if (docsQueue?.Count == 0)
            {
                return(GetNewDocument(docType, sizeFile));
            }

            WebDocumentInfo doc = null;

            Wait.ForResult(() => docsQueue.TryDequeue(out doc));

            Volatile.Read(ref DocumentTaken)?.Invoke(docType, (string)doc?.Id?.Clone());
            return(doc);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Converts document info into a string in a MS Office app title format.
        /// </summary>
        /// <param name="document">Document info.</param>
        /// <param name="versionLabel">Document version label.</param>
        /// <param name="formatString">Format string.</param>
        /// <returns>A string representation of MS Office app title.</returns>
        public static string ConvertToMsOfficeTitle(this WebDocumentInfo document, string versionLabel, string formatString)
        {
            var versionInfo = document.Versions.Find(v => v.VersionLabel.Equals(versionLabel));

            return(string.Format(formatString, document.Name, versionInfo.VersionType, document.Id, versionInfo.Number));
        }