Esempio n. 1
0
        /// <summary>
        /// Parses the response from the async upload.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        internal void _client_UploadFileCompleted(object sender, UploadFileCompletedEventArgs e)
        {
            try
            {
                Document _result = new Document();

                // Get the response
                string _xml = System.Text.Encoding.Default.GetString(e.Result);

                // Load up the resultant XML
                Response _response = new Response(_xml);

                // Are we cool?
                if (_response.Status != "ok")
                {
                    foreach (int _code in _response.ErrorList.Keys)
                    {
                        // Let the subscribers know, cuz they care.
                        OnErrorOccurred(_code, _response.ErrorList[_code]);
                    }
                }
                else
                {
                    // Parse the response
                    if (_response != null && _response.HasChildNodes && _response.ErrorList.Count < 1)
                    {
                        XmlNode _node = _response.SelectSingleNode("rsp");

                        // Data
                        _result.DocumentId = int.Parse(_node.SelectSingleNode("doc_id").InnerText);
                        _result.AccessKey = _node.SelectSingleNode("access_key").InnerText;

                        // Security
                        if (_node.SelectSingleNode("secret_password") != null)
                        {
                            _result.AccessType = AccessTypes.Private;
                            _result.SecretPassword = _node.SelectSingleNode("secret_password").InnerText;
                        }
                    }
                }

                // Notify those who care.
                Document.OnUploaded(_result);
            }
            catch (Exception _ex)
            {
                OnErrorOccurred(666, _ex.Message, _ex);
            }

        }
 /// <summary>
 /// ctor
 /// </summary>
 /// <param name="document">Document related to the event.</param>
 internal DocumentEventArgs(Document document)
     : base()
 {
     m_document = document;
 }
Esempio n. 3
0
 /// <summary>
 /// Uploads a document into Scribd
 /// </summary>
 /// <param name="stream">A <see cref="Stream"/> to send</param>
 /// <param name="accessType">Access permission of document</param>
 /// <param name="revisionNumber">The document id to save uploaded file as a revision to</param>
 /// <param name="documentType">Type of document</param>
 /// <param name="asynch">Indicates whether to upload file asynchronously.</param>
 /// <returns><see cref="T:Scribd.Net.Document"/> instance of the uploaded document.</returns>
 public static Document Upload(Stream stream, AccessTypes accessType, int revisionNumber, string documentType, bool asynch)
 {
     Document _result = new Document();
     string _fileName = StreamToFile(ref stream);
     if (!string.IsNullOrEmpty(_fileName))
     {
         _result = Document.Upload(_fileName, accessType, revisionNumber, documentType, asynch);
     }
     else
     {
         _result= null;
     }
     try
     {
         File.Delete(_fileName);
     }
     catch { }
     return _result;
 }
Esempio n. 4
0
        /// <summary>
        /// This method searches for the specified query within the scribd documents
        /// </summary>
        /// <param name="query">Criteria used in search</param>
        /// <param name="scope">Whether to search all of scribd OR just within one 
        /// user/'s documents. If scope is set to "user" and session_key is not provided, 
        /// the documents uploaded by the API user will be searched. If scope is set 
        /// to "user" and session_key is given, the documents uploaded by the session 
        /// user will be searched. If scope is "all", only public documents will be 
        /// searched. Set to "user" by default.</param>
        /// <param name="maxResults">Number of results to return: Default 10, max 1000</param>
        /// <param name="startIndex">Number to start at: Default 1. Cannot exceed 1000</param>
        /// <returns>The <see cref="T:Search.Result"/></returns>
        internal static Result InnerFind(string query, SearchScope scope, int maxResults, int startIndex)
        {
            if (Search.ThumbnailSize == null) { Search.ThumbnailSize = new System.Drawing.Size(71, 100); }

            // Validate params
            if (maxResults > 1000) { maxResults = 1000; }
            if (startIndex < 1 || startIndex > 1000) { startIndex = 1; }

            List<Document> _documents = new List<Document>();
            int _totalAvailable = 0, _firstResultIndex = 0;

            // Generate request
            using (Request _request = new Request(Service.Instance.InternalUser))
            {
                _request.MethodName = "docs.search";
                _request.Parameters.Add("query", query);
                _request.Parameters.Add("num_results", maxResults.ToString());
                _request.Parameters.Add("num_start", startIndex.ToString());
                _request.Parameters.Add("scope", Enum.GetName(typeof(SearchScope),scope).ToLower());

                // Get Results
                using (Response _response = Service.Instance.PostRequest(_request))
                {
                    // Parse response
                    if (_response != null && _response.HasChildNodes && _response.ErrorList.Count < 1)
                    {
                        _totalAvailable = int.Parse(_response.SelectSingleNode(@"/rsp/result_set").Attributes["totalResultsAvailable"].Value);
                        _firstResultIndex = int.Parse(_response.SelectSingleNode(@"/rsp/result_set").Attributes["firstResultPosition"].Value);

                        XmlNodeList _list = _response.GetElementsByTagName("result");
                        if (_list.Count > 0)
                        {
                            foreach (XmlNode _node in _list)
                            {
                                Document _item = new Document(0, Search.ThumbnailSize);
                                _item.DocumentId = int.Parse(_node.SelectSingleNode("doc_id").InnerText);
                                _item.Title = _node.SelectSingleNode("title").InnerText.Trim();
                                _item.Description = _node.SelectSingleNode("description").InnerText.Trim();
                                _item.ThumbnailUrl = new Uri(_node.SelectSingleNode("thumbnail_url").InnerText);

                                if (_node.SelectSingleNode("access_key") != null)
                                {
                                    _item.AccessKey = _node.SelectSingleNode("access_key").InnerText;
                                }

                                // Tags
                                string _tags = _node.SelectSingleNode("tags").InnerText;
                                foreach (string _tag in _tags.Split(','))
                                {
                                    _item.TagList.Add(_tag.Trim());
                                }

                                _documents.Add(_item);
                            }
                        }
                    }
                }
            }

            // Set the criteria used to the result
            Criteria _criteria = new Criteria();
            _criteria.Query = query;
            _criteria.Scope = scope;
            _criteria.MaxResults = maxResults;
            _criteria.StartIndex = startIndex;

            return new Result(_criteria, _documents, _totalAvailable, _firstResultIndex);
        }
Esempio n. 5
0
        /// <summary>
        /// Saves multiple documents with the given template
        /// settings.
        /// </summary>
        /// <param name="documents">Documents to modify and save.</param>
        /// <param name="template"><see cref="T:Scribd.Net.Document"/> template to use.</param>
        public static void BulkSave(List<Document> documents, Document template)
        {
            // Parse out the document id's and call the 
            // overload
            List<int> _idList = new List<int>();
            foreach (Document _document in documents)
            {
                _idList.Add(_document.DocumentId);
            }

            BulkSave(_idList.ToArray(), template);
        }
Esempio n. 6
0
        /// <summary>
        /// Saves multiple documents with the given template
        /// settings.
        /// </summary>
        /// <param name="documentId">Array of document identifiers to modify and save.</param>
        /// <param name="template"><see cref="T:Scribd.Net.Document"/> template to use.</param>
        public static void BulkSave(int[] documentId, Document template)
        {
            using (Request _request = new Request())
            {
                _request.MethodName = "docs.changeSettings";

                // Concat the doc_id's into CSV
                StringBuilder _idList = new StringBuilder();
                foreach (int _id in documentId)
                {
                    _idList.AppendFormat("{0},", _id.ToString());
                }
                _request.Parameters.Add("doc_ids", _idList.ToString().TrimEnd(','));
                _request.Parameters.Add("title", template.Title);
                _request.Parameters.Add("description", template.Description);
                _request.Parameters.Add("access", template.AccessType == AccessTypes.Public ? "public" : "private");

                // License
                switch (template.License)
                {
                    case CCLicenseTypes.BY: _request.Parameters.Add("license", "by"); break;
                    case CCLicenseTypes.BY_NC: _request.Parameters.Add("license", "by-nc"); break;
                    case CCLicenseTypes.BY_NC_ND: _request.Parameters.Add("license", "by-nc-nd"); break;
                    case CCLicenseTypes.BY_NC_SA: _request.Parameters.Add("license", "by-nc-sa"); break;
                    case CCLicenseTypes.BY_ND: _request.Parameters.Add("license", "by-nd"); break;
                    case CCLicenseTypes.BY_SA: _request.Parameters.Add("license", "by-sa"); break;
                    case CCLicenseTypes.C: _request.Parameters.Add("license", "c"); break;
                    case CCLicenseTypes.PD: _request.Parameters.Add("license", "pd"); break;
                    default: break;
                }

                // Ads
                switch (template.ShowAds)
                {
                    case ShowAdsTypes.Default: _request.Parameters.Add("show-ads", "default"); break;
                    case ShowAdsTypes.True: _request.Parameters.Add("show-ads", "true"); break;
                    case ShowAdsTypes.False: _request.Parameters.Add("show-ads", "false"); break;
                    default: break;
                }

                if (template.LinkBackURL != null && !string.IsNullOrEmpty(template.LinkBackURL.ToString()))
                {
                    _request.Parameters.Add("link_back_url", template.LinkBackURL.ToString());
                }

                if (!string.IsNullOrEmpty(template.Category)) { _request.Parameters.Add("category", template.Category); }

                // Tags
                if (template.TagList.Count > 0)
                {
                    StringBuilder _tags = new StringBuilder();
                    foreach (string _tag in template.TagList)
                    {
                        // No blank Tags, thankyouverymuch!
                        if (!string.IsNullOrEmpty(_tag))
                            _tags.AppendFormat("{0},", _tag);
                    }
                    _request.Parameters.Add("tags", _tags.ToString().TrimEnd(','));
                }

                if (!string.IsNullOrEmpty(template.Author)) { _request.Parameters.Add("author", template.Author); }
                if (!string.IsNullOrEmpty(template.Publisher)) { _request.Parameters.Add("publisher", template.Publisher); }
                if (!template.WhenPublished.Equals(DateTime.MinValue)) { _request.Parameters.Add("when_published", string.Format("YYYY-MM-DD", template.WhenPublished)); }
                if (!string.IsNullOrEmpty(template.Edition)) { _request.Parameters.Add("edition", template.Edition); }
                _request.Parameters.Add("disable_upload_link", template.DisableUploadLink ? "1" : "0");
                _request.Parameters.Add("disable_print", template.DisablePrint ? "1" : "0");
                _request.Parameters.Add("disable_select_text", template.DisableSelectText ? "1" : "0");
                _request.Parameters.Add("disable_about_dialog", template.DisableAboutDialog ? "1" : "0"); ;
                _request.Parameters.Add("disable_info_dialog", template.DisableInfoDialog ? "1" : "0");
                _request.Parameters.Add("disable_view_mode_change", template.DisableViewModeChange ? "1" : "0");
                _request.Parameters.Add("disable_related_docs", template.DisableRelatedDocuments ? "1" : "0");

                if (template.StoreSettings != null)
                {
                    template.StoreSettings.PopulateParameters(_request.Parameters);
                }
                             
                // Post our request.
                Service.Instance.PostRequest(_request);
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Returns the Flash embedding code for this document.
        /// </summary>
        /// <param name="document">The source document to embed.</param>
        /// <param name="startingPage">The page to start on.</param>
        /// <param name="viewMode">The way the pages should be displayed.</param>
        /// <param name="viewHeight">The height of the embeded document.</param>
        /// <param name="viewWidth">The width of the embeded document.</param>
        /// <returns>String</returns>
        public static string GetEmbedCode(Document document, int startingPage, ViewMode viewMode, string viewHeight, string viewWidth)
        {
            string _viewMode = Enum.GetName(typeof(ViewMode), viewMode);
            if (string.IsNullOrEmpty(viewHeight)) { viewHeight = "500"; }
            if (string.IsNullOrEmpty(viewWidth)) { viewWidth = "100%"; }
            if (startingPage < 1) { startingPage = 1; }

            StringBuilder _sb = new StringBuilder();

            _sb.AppendFormat(@"<object codebase=""http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0"" id=""doc_296323{0}"" name=""doc_296323{0}"" classid=""clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"" align=""middle"" height=""500"" width=""100%"">", document.DocumentId.ToString());
            _sb.AppendFormat(@"<param name=""movie"" value=""http://documents.scribd.com/ScribdViewer.swf?document_id={0}&access_key={1}&page={2}&version={3}&auto_size=true&viewMode={4}"">", document.DocumentId.ToString(), document.AccessKey, startingPage.ToString(), "1", _viewMode);
            _sb.Append(@"<param name=""quality"" value=""high"">");
            _sb.Append(@"<param name=""play"" value=""true"">");
            _sb.Append(@"<param name=""loop"" value=""true"">");
            _sb.Append(@"<param name=""scale"" value=""showall"">");
            _sb.Append(@"<param name=""wmode"" value=""opaque"">");
            _sb.Append(@"<param name=""devicefont"" value=""false"">");
            _sb.Append(@"<param name=""bgcolor"" value=""#ffffff"">");
            _sb.Append(@"<param name=""menu"" value=""true"">");
            _sb.Append(@"<param name=""allowFullScreen"" value=""true"">");
            _sb.Append(@"<param name=""allowScriptAccess"" value=""always"">");
            _sb.Append(@"<param name=""salign"" value="""">");
            _sb.AppendFormat(@"<embed src=""http://documents.scribd.com/ScribdViewer.swf?document_id={0}&access_key={1}&page={2}&version={3}&auto_size=true&viewMode={4}"" quality=""high"" pluginspage=""http://www.macromedia.com/go/getflashplayer"" play=""true"" loop=""true"" scale=""showall"" wmode=""opaque"" devicefont=""false"" bgcolor=""#ffffff"" name=""doc_296323{0}_object"" menu=""true"" allowfullscreen=""true"" allowscriptaccess=""always"" salign="""" type=""application/x-shockwave-flash"" align=""middle""  height=""{5}"" width=""{6}""></embed>", document.DocumentId.ToString(), document.AccessKey, startingPage.ToString(), "1", _viewMode, viewHeight, viewWidth);
            _sb.Append(@"</object>");
            _sb.Append(@"<div style=""font-size:10px;text-align:center;width:100%"">");
            _sb.AppendFormat(@"<a href=""http://www.scribd.com/doc/{0}"">{1}</a> - <a href=""http://www.scribd.com/upload"">Upload a Document to Scribd</a></div><div style=""display:none""> Read this document on Scribd: <a href=""http://www.scribd.com/doc/{0}"">{1}</a> </div>", document.DocumentId.ToString(), document.Title);

            return _sb.ToString();
        }
Esempio n. 8
0
 /// <summary>
 /// Notify subscribers of a download.
 /// </summary>
 /// <param name="document">Downloaded document</param>
 internal static void OnDownloaded(Document document)
 {
     if (Downloaded != null)
     {
         Downloaded(document, new DocumentEventArgs(document));
     }
 }
Esempio n. 9
0
        /// <summary>
        /// This method retrieves a list of documents for a given user.
        /// </summary>
        /// <param name="user"></param>
        /// <param name="limit">The number of documents to return. You can paginate through the full list using the limit and offset parameters. The maximum limit is 1000. </param>
        /// <param name="offset">The offset into the list of documents. You can paginate through the full list using the limit and offset parameters.</param>
        /// <param name="includeDetails">Additionally retrieves detailed document information.</param>
        /// <returns></returns>
        public static List<Document> GetList(User user, int limit, int offset, bool includeDetails)
        {
            List<Document> _result = new List<Document>();

            // Build the request
            using (Request _request = new Request(user))
            {
                _request.MethodName = "docs.getList";
                
                // Currently the 'use_api_account' parameter isn't working. Since "false == not using the param at all" just
                // comment it out.
                //_request.Parameters.Add("use_api_account", "false");

                _request.Parameters.Add("limit", limit.ToString());
                _request.Parameters.Add("offset", offset.ToString());

                // Get the response
                using (Response _response = Service.Instance.PostRequest(_request))
                {
                    // Parse the response
                    if (_response != null && _response.HasChildNodes && _response.ErrorList.Count < 1)
                    {
                        XmlNodeList _list = _response.GetElementsByTagName("result");
                        if (_list.Count > 0)
                        {
                            foreach (XmlNode _node in _list)
                            {
                                Document _item = new Document();

                                _item.DocumentId = int.Parse(_node.SelectSingleNode("doc_id").InnerText);
                                _item.Title = _node.SelectSingleNode("title").InnerText.Trim();
                                _item.Description = _node.SelectSingleNode("description").InnerText.Trim();
                                _item.AccessKey = _node.SelectSingleNode("access_key").InnerText;

                                switch (_node.SelectSingleNode("conversion_status").InnerText.Trim().ToLower())
                                {
                                    case "displayable": _item.ConversionStatus = ConversionStatusTypes.Displayable; break;
                                    case "done": _item.ConversionStatus = ConversionStatusTypes.Done; break;
                                    case "error": _item.ConversionStatus = ConversionStatusTypes.Error; break;
                                    case "processing": _item.ConversionStatus = ConversionStatusTypes.Processing; break;
                                    case "published": _item.ConversionStatus = ConversionStatusTypes.Published; break;
                                    default: _item.ConversionStatus = ConversionStatusTypes.None_Specified; break;
                                }

                                // We're going to default to public
                                _item.AccessType = AccessTypes.Public;

                                // We've got a password - it's private!
                                if (_node.SelectSingleNode("secret_password") != null)
                                {
                                    _item.AccessType = AccessTypes.Private;
                                    _item.SecretPassword = _node.SelectSingleNode("secret_password").InnerText;
                                }

                                // Get all the properties.
                                Document _temp = Document.Download(_item.DocumentId);

                                _result.Add(_temp);
                            }
                        }
                    }
                }
            }
            return _result;
        }
Esempio n. 10
0
        /// <summary>
        /// Downloads a document from Scribd.
        /// </summary>
        /// <param name="documentId">Identifier of the document</param>
        /// <returns><see cref="T:Scribd.Net.Document"/></returns>
        /// <example><![CDATA[
        ///		Scribd.Net.Document myDocument = Scribd.Net.Document.Download(39402);
        /// ]]></example>
        public static Document Download(int documentId)
        {
            Document _result = new Document();
            _result.DocumentId = documentId;

            // Give subscribers a chance to bail.
            DocumentEventArgs _arguments = new DocumentEventArgs(_result);
            OnBeforeDownload(_arguments);
            if (_arguments.Cancel)
            {
                return _result;
            }

            // Set up our request
            using (Request _request = new Request())
            {
                _request.MethodName = "docs.getSettings";
                _request.Parameters.Add("doc_id", documentId.ToString());

                // Grab our response
                using (Response _response = Service.Instance.PostRequest(_request))
                {

                    // Parse the response
                    if (_response != null && _response.HasChildNodes && _response.ErrorList.Count < 1)
                    {
                        XmlNode _node = _response.SelectSingleNode("rsp");

                        // Data
                        _result.DocumentId = int.Parse(_node.SelectSingleNode("doc_id").InnerText);
                        _result.Title = _node.SelectSingleNode("title").InnerText.Trim();
                        _result.Description = _node.SelectSingleNode("description").InnerText.Trim();
                        _result.AccessKey = _node.SelectSingleNode("access_key").InnerText;
                        _result.AccessType = _node.SelectSingleNode("access").InnerText == "private" ? AccessTypes.Private : AccessTypes.Public;

                        // Depends on version of the Scribd API ...
                        string _url = _node.SelectSingleNode("thumbnail_url") == null ? string.Empty : _node.SelectSingleNode("thumbnail_url").InnerText;
                        _result.ThumbnailUrl = new Uri(_url);

                        // Link to the large image
                        _result.LargeImageURL = new Uri(_url.Replace("thumb", "large"));

                        // License
                        switch (_node.SelectSingleNode("license").InnerText.ToLower())
                        {
                            case "by": _result.License = CCLicenseTypes.BY; break;
                            case "by-nc": _result.License = CCLicenseTypes.BY_NC; break;
                            case "by-nc-nd": _result.License = CCLicenseTypes.BY_NC_ND; break;
                            case "by-nc-sa": _result.License = CCLicenseTypes.BY_NC_SA; break;
                            case "by-nd": _result.License = CCLicenseTypes.BY_ND; break;
                            case "by-sa": _result.License = CCLicenseTypes.BY_SA; break;
                            case "c": _result.License = CCLicenseTypes.C; break;
                            case "pd": _result.License = CCLicenseTypes.PD; break;
                            default: _result.License = CCLicenseTypes.None_Specified; break;
                        }

                        // 2010.04.06 - JPD - This has been removed from the API.
                        // Show Ads
                        //switch (_node.SelectSingleNode("show_ads").InnerText.ToLower())
                        //{
                        //    case "default": _result.ShowAds = ShowAdsTypes.Default; break;
                        //    case "true": _result.ShowAds = ShowAdsTypes.True; break;
                        //    case "false": _result.ShowAds = ShowAdsTypes.False; break;
                        //    default: _result.ShowAds = ShowAdsTypes.Default; break;
                        //}

                        // Tags
                        if (_node.SelectSingleNode("tags") != null) // Doing this now in case they decide to dump "tags" too...grr
                        {
                            string _tags = _node.SelectSingleNode("tags").InnerText;
                            foreach (string _tag in _tags.Split(','))
                            {
                                _result.TagList.Add(_tag.Trim());
                            }
                        }

                        // Security
                        if (_node.SelectSingleNode("secret_password") != null)
                        {
                            _result.AccessType = AccessTypes.Private;
                            _result.SecretPassword = _node.SelectSingleNode("secret_password").InnerText;
                        }

                        if (_node.SelectSingleNode("link_back_url") != null)
                        {
                            _result.LinkBackURL = new Uri( _node.SelectSingleNode("link_back_url").InnerText);
                        }

                        if (_node.SelectSingleNode("page_count") != null)
                        {
                            //_result.PageCount = int.Parse(_node.SelectSingleNode("page_count").InnerText);
                            int pc;
                            int.TryParse(_node.SelectSingleNode("page_count").InnerText, out pc);
                            _result.PageCount = pc;
                        }

                        // Category
                        if (_node.SelectSingleNode("category_id") != null)
                        {
                            int cat;
                            int.TryParse(_node.SelectSingleNode("category_id").InnerText, out cat);
                            _result.CategoryId = cat;

                            // TODO:  Set Category property
                            
                        }

                        // Download Formats
                        if (_node.SelectSingleNode("download_formats") != null)
                        {
                            _result.DownloadFormats.AddRange(_node.SelectSingleNode("download_formats").InnerText.Split(','));
                        }


                        if (_node.SelectSingleNode("author") != null)
                        {
                            _result.Author = _node.SelectSingleNode("author").InnerText;
                        }

                        if (_node.SelectSingleNode("publisher") != null)
                        {
                            _result.Publisher = _node.SelectSingleNode("publisher").InnerText;
                        }

                        if (_node.SelectSingleNode("when_published") != null)
                        {
                            if (_node.SelectSingleNode("when_published").InnerText != "")
                            {
                                _result.WhenPublished = Convert.ToDateTime(_node.SelectSingleNode("when_published").InnerText);
                            }
                        }

                        if (_node.SelectSingleNode("edition") != null)
                        {
                            _result.Edition = _node.SelectSingleNode("edition").InnerText;  
                        }

                        _result.StoreSettings = new DocumentStore();

                        if (_node.SelectSingleNode("page_restriction_type") != null)
                        {
                            switch (_node.SelectSingleNode("page_restriction_type").InnerText.ToLower())
                            {
                                case "automatic": _result.StoreSettings.RestrictionType = PageRestrictionTypes.Automatic; break;
                                case "max_pages": _result.StoreSettings.RestrictionType = PageRestrictionTypes.MaxPages; break;
                                case "max_percentage": _result.StoreSettings.RestrictionType = PageRestrictionTypes.MaxPercentage; break;
                                case "page_range": _result.StoreSettings.RestrictionType = PageRestrictionTypes.PageRange; break;
                                default: _result.StoreSettings.RestrictionType = PageRestrictionTypes.Automatic; break;
                            }
                        }

                        if (_node.SelectSingleNode("max_pages") != null)
                        {
                            _result.StoreSettings.MaxPages = Convert.ToInt32(_node.SelectSingleNode("max_pages").InnerText);
                        }

                        if (_node.SelectSingleNode("max_percentage") != null)
                        {
                            _result.StoreSettings.MaxPercentage = Convert.ToInt32(_node.SelectSingleNode("max_percentage").InnerText);
                        }

                        if (_node.SelectSingleNode("page_range") != null)
                        {
                            _result.StoreSettings.PageRange =_node.SelectSingleNode("page_range").InnerText;
                        }

                        if (_node.SelectSingleNode("allow_search_targeting") != null)
                        {
                            _result.StoreSettings.AllowSearchTargeting = Convert.ToBoolean(_node.SelectSingleNode("allow_search_targeting").InnerText);
                        }

                        if (_node.SelectSingleNode("obfuscate_numbers") != null)
                        {
                            _result.StoreSettings.ObfuscateNumbers = Convert.ToBoolean(_node.SelectSingleNode("obfuscate_numbers").InnerText);
                        }

                        if (_node.SelectSingleNode("allow_search_indexing") != null)
                        {
                            _result.StoreSettings.AllowSearchIndexing = Convert.ToBoolean(_node.SelectSingleNode("allow_search_indexing").InnerText);
                        }

                        if (_node.SelectSingleNode("price") != null)
                        {
                            _result.StoreSettings.Price = (float)Convert.ToDouble(_node.SelectSingleNode("price").InnerText);
                        }

                        if (_node.SelectSingleNode("min_price") != null)
                        {
                            _result.StoreSettings.MinPrice = (float)Convert.ToDouble(_node.SelectSingleNode("min_price").InnerText);
                        }

                        if (_node.SelectSingleNode("max_price") != null)
                        {
                            _result.StoreSettings.MaxPrice = (float)Convert.ToDouble(_node.SelectSingleNode("max_price").InnerText);
                        }

                    }
                }
                // Notify subscribers
                OnDownloaded(_result);
            }
            // Get out!
            return _result;
        }
Esempio n. 11
0
        /// <summary>
        /// Uploads a document into Scribd
        /// </summary>
        /// <param name="path">Local or Url path to the file</param>
        /// <param name="accessType">Access permission of document</param>
        /// <param name="revisionNumber">The document id to save uploaded file as a revision to</param>
        /// <param name="documentType">Type of document</param>
        /// <param name="paidContent">Is this paid content or not</param>
        /// <param name="downloadType">Download options to support</param>
        /// <param name="asynch">Synch of Asych upload?</param>
        /// <returns><see cref="T:Scribd.Net.Document"/> instance of the uploaded document.</returns>
        private static Document _Upload(string path, AccessTypes accessType, int revisionNumber, string documentType,
            bool paidContent, DownloadAndDRMTypes downloadType, bool asynch)
        {
            Document _result = new Document();

            // Build our request
            using (Request _request = new Request())
            {
                // Is this from a URL?
                if (path.StartsWith(@"http://")  || path.StartsWith(@"https://"))
                {
                    // Upload to Scribd via URL
                    _request.MethodName = "docs.uploadFromUrl";
                    _request.Parameters.Add("url", path);
                }
                else
                {
                    // Don't.
                    _request.MethodName = "docs.upload";
                    _request.Parameters.Add("file", path);

                }

                if (!string.IsNullOrEmpty(documentType))
                {
                    _request.Parameters.Add("doc_type", documentType.ToLower());
                }

                _request.Parameters.Add("access", accessType == AccessTypes.Public ? "public" : "private");

                if (revisionNumber != 0)
                {
                    _request.Parameters.Add("rev_id", revisionNumber.ToString());
                }

                if (paidContent)
                {
                    _request.Parameters.Add("paid_content", "1");
                    if (downloadType != DownloadAndDRMTypes.Default)
                    {
                        switch (downloadType)
                        {
                            case DownloadAndDRMTypes.DownloadDRM:               _request.Parameters.Add("download_and_drm", "download-drm"); break;
                            case DownloadAndDRMTypes.DownloadPDF:               _request.Parameters.Add("download_and_drm", "download-pdf"); break;
                            case DownloadAndDRMTypes.DownloadPDFandOriginal:    _request.Parameters.Add("download_and_drm", "download-pdf-orig"); break;
                            case DownloadAndDRMTypes.ViewOnly:                  _request.Parameters.Add("download_and_drm", "view-only"); break;
                        }
                    }
                }

                if (asynch)
                {
                    // Post it asychronously
                    Service.Instance.PostFileUploadRequest(_request);
                }
                else
                {
                    // Post is sychronously

                    // Get our response
                    Response _response = Service.Instance.PostRequest(_request);

                    // Parse the response
                    if (_response != null && _response.HasChildNodes && _response.ErrorList.Count < 1)
                    {
                        XmlNode _node = _response.SelectSingleNode("rsp");

                        // Data
                        _result.DocumentId = int.Parse(_node.SelectSingleNode("doc_id").InnerText);
                        _result.AccessKey = _node.SelectSingleNode("access_key").InnerText;

                        // Security
                        if (_node.SelectSingleNode("secret_password") != null)
                        {
                            _result.AccessType = AccessTypes.Private;
                            _result.SecretPassword = _node.SelectSingleNode("secret_password").InnerText;
                        }
                    }

                    // Notify subscribers
                    OnUploaded(_result);
                }
            }
            return _result;
        }