コード例 #1
0
        /// <summary>
        /// This interface is used to generate a quote from file URLs that will be loaded. A quote can contain multiple projects.
        /// </summary>
        /// <param name="service"></param>
        /// <param name="fileURLs"></param>
        /// <param name="fileNames"></param>
        /// <param name="options"></param>
        /// <param name="referenceFiles">If null, will not use reference files</param>
        /// <returns></returns>
        public Quote GenerateQuote(Service service, Uri[] fileURLs, String[] fileNames, QuoteOptions options, IEnumerable<File> referenceFiles = null)
        {
            // Check the service
            if (service == null)
            {
                throw new ArgumentNullException("service", "Must specify a Service to generate a quote");
            }

            if (fileURLs == null || fileNames == null)
            {
                throw new ArgumentNullException("files", "Must specify the fileURLs and fileNames");
            }

            if (!service.AcceptsFiles)
            {
                throw new ArgumentException("This service does not accept files.  Please use GenerateQuote with Products", "service");
            }

            if (options == null)
            {
                throw new ArgumentNullException("options", "Must specify options to generate a quote");
            }

            options.Initialize(this, service);

            // Check that the file extensions are valid
            foreach (String fileName in fileNames)
            {
                if (!service.AcceptsExtension(Path.GetExtension(fileName)))
                {
                    throw new ArgumentOutOfRangeException("fileNames", fileName, "Service does not accept files with this extension");
                }
            }

            // Upload the files
            List<File> addedFiles = new List<File>();

            for (int i = 0; i < fileNames.Length && i < fileURLs.Length; i++)
            {
                addedFiles.Add(this.AddFile(options.SourceLanguage.LanguageCode, fileNames[i], fileURLs[i]));
            }

            return this.GenerateQuote(service, addedFiles, options, referenceFiles);
        }
コード例 #2
0
        /// <summary>
        /// This interface is used to generate a quote from file paths that will be loaded. A quote can contain multiple projects.
        /// </summary>
        /// <param name="service"></param>
        /// <param name="filePaths"></param>
        /// <param name="options"></param>
        /// <param name="referenceFilePaths">If null, will not use reference files</param>
        /// <returns></returns>
        public Quote GenerateQuote(Service service, string[] filePaths, QuoteOptions options, string[] referenceFilePaths = null)
        {
            // Check the service
            if (service == null)
            {
                throw new ArgumentNullException("service", "Must specify a Service to generate a quote");
            }

            if (!service.AcceptsFiles)
            {
                throw new ArgumentException("This service does not accept files.  Please use GenerateQuote with Products", "service");
            }

            if (options == null)
            {
                throw new ArgumentNullException("options", "Must specify options to generate a quote");
            }

            options.Initialize(this, service);

            // Check that the file extensions are valid
            foreach (String filePath in filePaths)
            {
                if (!service.AcceptsExtension(Path.GetExtension(filePath)))
                {
                    throw new ArgumentOutOfRangeException("filePaths", filePath, "Service does not accept files with this extension");
                }
            }

            // Upload the files
            List<File> addedFiles = new List<File>();

            foreach (String filePath in filePaths)
            {
                addedFiles.Add(this.AddFile(options.SourceLanguage.LanguageCode, filePath));
            }

            // Upload the reference
            List<File> referenceFiles = null;

            if (referenceFilePaths != null)
            {
                referenceFiles = new List<File>();
                foreach (String referenceFilePath in referenceFilePaths)
                {
                    referenceFiles.Add(this.AddFile(options.SourceLanguage.LanguageCode, referenceFilePath));
                }
            }

            return this.GenerateQuote(service, addedFiles, options, referenceFiles);
        }