Exemple #1
0
        /*
         * public static Stream GetDocUri_NON_FUNZIONA(DocumentsRequest request, Document doc, Document.DownloadType type)
         * {
         *  // NON FUNZIONA (porca putt...!)
         *  string docID = doc.ResourceId.Replace("document:", "");
         *  string uriS = "http://docs.google.com/feeds/download/documents/Export?" +
         *      "docID=" + docID +
         *      "&exportFormat=" + type.ToString();
         *  Uri target = new Uri(uriS);
         *  return request.Service.Query(target);
         * }
         */

        public static Stream GetDocExportStream(DocumentsRequest request, Document doc, Document.DownloadType downloadtype)
        {
            // Questa funziona ma mi pare na stronz...
            string format = downloadtype.ToString();
            string url    =
                doc.DocumentEntry.Content.AbsoluteUri +
                "&exportFormat=" + format + "&format=" + format;

            return(request.Service.Query(new Uri(url)));
        }
Exemple #2
0
        /// <summary>
        /// ...
        /// </summary>
        private string ConvertDownloadTypeToFileExtension(Document.DownloadType dt)
        {
            switch (dt)
            {
            case (Document.DownloadType.doc): return("docx");

            case (Document.DownloadType.xls): return("xlsx");

            case (Document.DownloadType.ppt): return("pptx");

            default: return(dt.ToString());
            }
        }
Exemple #3
0
            public Stream Download(ITaskItem input, Document.DownloadType type, string baseDomain = null, int sheetNumber = 0)
            {
                input.LoadCustomMetadata();
                Document.DocumentType documentType = input.RequireDocumentType();

                Service s        = this.Service;
                string  queryUri = this.BuildDocumentPartialExportUrl(input.RequireExportUri());

                switch (documentType)
                {
                case Document.DocumentType.Spreadsheet:
                    s = this.Service;
                    switch (type)
                    {
                    case Document.DownloadType.xls:
                        queryUri += "xls";
                        break;

                    case Document.DownloadType.csv:
                        queryUri += "csv&gid=" + sheetNumber.ToString();
                        break;

                    case Document.DownloadType.pdf:
                        queryUri += "pdf";
                        break;

                    case Document.DownloadType.ods:
                        queryUri += "ods";
                        break;

                    case Document.DownloadType.tsv:
                        queryUri += "tsv&gid=" + sheetNumber.ToString();;
                        break;

                    case Document.DownloadType.html:
                        queryUri += "html";
                        break;

                    default:
                        throw new ArgumentException("type is invalid for a spreadsheet");
                    }
                    break;

                case Document.DocumentType.Presentation:
                    switch (type)
                    {
                    case Document.DownloadType.swf:
                        queryUri += "swf";
                        break;

                    case Document.DownloadType.pdf:
                        queryUri += "pdf";
                        break;

                    case Document.DownloadType.ppt:
                        queryUri += "ppt";
                        break;

                    default:
                        throw new ArgumentException("type is invalid for a presentation");
                    }
                    break;

                case Document.DocumentType.Unknown:
                    break;

                default:
                    queryUri += type.ToString();
                    break;
                }

                Uri target = new Uri(queryUri);

                return(s.Query(target));
            }
        /// <summary>
        /// downloads a document.
        /// </summary>
        /// <param name="document">The document to download. It needs to have the document type set, as well as the id link</param>
        /// <param name="type">The output format of the document you want to download</param>
        /// <param name="sheetNumber">When requesting a CSV or TSV file you must specify an additional parameter called
        /// gid which indicates which grid, or sheet, you wish to get (the index is 0 based, so gid 1
        /// actually refers to the second sheet sheet on a given spreadsheet). </param>
        /// <param name="baseDomain">if null, default is used. Otherwise needs to specify the domain to download from, ending with a slash</param>
        /// <returns></returns>
        public Stream Download(Document document, Document.DownloadType type, string baseDomain, int sheetNumber)
        {
            if (document.Type == Document.DocumentType.Unknown)
            {
                throw new ArgumentException("Document has an unknown type");
            }

            if (document.Type == Document.DocumentType.Folder)
            {
                throw new ArgumentException("Document is a folder, can not be downloaded");
            }

            // now figure out the parameters
            string queryUri = "";

            Service s = this.Service;

            switch (document.Type)
            {
            case Document.DocumentType.Spreadsheet:
                // spreadsheet has a different parameter
                if (baseDomain == null)
                {
                    baseDomain = "http://spreadsheets.google.com/";
                }
                queryUri = baseDomain + "feeds/download/spreadsheets/Export?key=" + document.ResourceId + "&exportFormat=";
                s        = this.spreadsheetsService;
                switch (type)
                {
                case Document.DownloadType.xls:
                    queryUri += "xls";
                    break;

                case Document.DownloadType.csv:
                    queryUri += "csv&gid=" + sheetNumber.ToString();
                    break;

                case Document.DownloadType.pdf:
                    queryUri += "pdf";
                    break;

                case Document.DownloadType.ods:
                    queryUri += "ods";
                    break;

                case Document.DownloadType.tsv:
                    queryUri += "tsv&gid=" + sheetNumber.ToString();;
                    break;

                case Document.DownloadType.html:
                    queryUri += "html";
                    break;

                default:
                    throw new ArgumentException("type is invalid for a spreadsheet");
                }
                break;

            case Document.DocumentType.Presentation:
                if (baseDomain == null)
                {
                    baseDomain = "http://docs.google.com/";
                }

                queryUri = baseDomain + "feeds/download/presentations/Export?docID=" + document.ResourceId + "&exportFormat=";
                switch (type)
                {
                case Document.DownloadType.swf:
                    queryUri += "swf";
                    break;

                case Document.DownloadType.pdf:
                    queryUri += "pdf";
                    break;

                case Document.DownloadType.ppt:
                    queryUri += "ppt";
                    break;

                default:
                    throw new ArgumentException("type is invalid for a presentation");
                }
                break;

            default:
                if (baseDomain == null)
                {
                    baseDomain = "http://docs.google.com/";
                }

                queryUri = baseDomain + "feeds/download/documents/Export?docID=" + document.ResourceId + "&exportFormat=" + type.ToString();
                break;
            }

            Uri target = new Uri(queryUri);

            return(s.Query(target));
        }
Exemple #5
0
        /// <summary>
        /// downloads a document.
        /// </summary>
        /// <param name="document">The document to download. It needs to have the document type set, as well as the id link</param>
        /// <param name="type">The output format of the document you want to download</param>
        /// <param name="sheetNumber">When requesting a CSV or TSV file you must specify an additional parameter called
        /// gid which indicates which grid, or sheet, you wish to get (the index is 0-based, so gid 1
        /// actually refers to the second sheet sheet on a given spreadsheet). </param>
        /// <param name="baseDomain">OBSOLETE - if null, default is used. Otherwise needs to specify the domain to download from, ending with a slash</param>
        /// <returns></returns>
        public Stream Download(Document document, Document.DownloadType type, string baseDomain, int sheetNumber)
        {
            if (document.Type == Document.DocumentType.Folder)
            {
                throw new ArgumentException("Document is a folder, can not be downloaded");
            }

            Service s        = this.Service;
            string  queryUri = this.BuildDocumentPartialExportUrl(document.DocumentEntry.Content.Src.ToString());

            switch (document.Type)
            {
            case Document.DocumentType.Spreadsheet:
                s = this.spreadsheetsService;
                switch (type)
                {
                case Document.DownloadType.xls:
                    queryUri += "xls";
                    break;

                case Document.DownloadType.csv:
                    queryUri += "csv&gid=" + sheetNumber.ToString();
                    break;

                case Document.DownloadType.pdf:
                    queryUri += "pdf";
                    break;

                case Document.DownloadType.ods:
                    queryUri += "ods";
                    break;

                case Document.DownloadType.tsv:
                    queryUri += "tsv&gid=" + sheetNumber.ToString();;
                    break;

                case Document.DownloadType.html:
                    queryUri += "html";
                    break;

                default:
                    throw new ArgumentException("type is invalid for a spreadsheet");
                }
                break;

            case Document.DocumentType.Presentation:
                switch (type)
                {
                case Document.DownloadType.swf:
                    queryUri += "swf";
                    break;

                case Document.DownloadType.pdf:
                    queryUri += "pdf";
                    break;

                case Document.DownloadType.ppt:
                    queryUri += "ppt";
                    break;

                default:
                    throw new ArgumentException("type is invalid for a presentation");
                }
                break;

            case Document.DocumentType.Unknown:
                break;

            default:
                queryUri += type.ToString();
                break;
            }

            Uri target = new Uri(queryUri);

            return(s.Query(target));
        }