Esempio n. 1
0
        private void OnGoogleNoteCreated(object sender, AsyncOperationCompletedEventArgs e)
        {
            DocumentEntry entry = e.Entry as DocumentEntry;

            Assert.IsNotNull(entry);

            Logger.Log("Created Google note", EventType.Information);

            //Now update the same entry
            //Instantiate the ResumableUploader component.
            ResumableUploader uploader = new ResumableUploader();

            uploader.AsyncOperationCompleted += new AsyncOperationCompletedEventHandler(OnGoogleNoteUpdated);
            uploader.UpdateAsync(_authenticator, entry, e.UserState);
        }
Esempio n. 2
0
        public void uploadFile(string fileName, DocumentEntry parentFolder)
        {
            if (cancel())
            {
                return;
            }
            string fileExtension = System.IO.Path.GetExtension(fileName).ToLower();

            if (!m_fileFilters.ContainsKey(fileExtension))
            {
                return;
            }
            int CHUNK_SIZE       = 1;
            ResumableUploader ru = new ResumableUploader(CHUNK_SIZE);

            ru.AsyncOperationCompleted += new AsyncOperationCompletedEventHandler(this.OnDone);
            ru.AsyncOperationProgress  += new AsyncOperationProgressEventHandler(this.OnProgress);

            // Check if entry exists
            FolderQuery contentQuery = new FolderQuery(parentFolder.ResourceId);

            contentQuery.Title      = Path.GetFileName(fileName);
            contentQuery.TitleExact = true;
            DocumentsFeed contents   = m_service.Query(contentQuery);
            bool          fileExists = contents.Entries.Count > 0;
            DocumentEntry entry      = fileExists?contents.Entries[0] as DocumentEntry:new DocumentEntry();

            entry.Title.Text = Path.GetFileName(fileName);
            string mimeType = m_fileFilters[fileExtension];

            entry.MediaSource = new MediaFileSource(fileName, mimeType);
            // Define the resumable upload link
            string notConvert = "?convert=false";
            Uri    createUploadUrl;

            if (parentFolder == null)
            {
                createUploadUrl = new Uri("https://docs.google.com/feeds/upload/create-session/default/private/full" + notConvert);
            }
            else
            {
                createUploadUrl = new Uri("https://docs.google.com/feeds/upload/create-session/default/private/full/" + parentFolder.ResourceId + "/contents" + notConvert);
            }
            AtomLink link = new AtomLink(createUploadUrl.AbsoluteUri);

            link.Rel = ResumableUploader.CreateMediaRelation;
            entry.Links.Add(link);

            // Set the service to be used to parse the returned entry
            entry.Service = m_service;

            // Instantiate the ResumableUploader component.
            ResumableUploader uploader = new ResumableUploader();

            // Set the handlers for the completion and progress events
            uploader.AsyncOperationCompleted += new AsyncOperationCompletedEventHandler(OnDone);
            uploader.AsyncOperationProgress  += new AsyncOperationProgressEventHandler(OnProgress);
            ClientLoginAuthenticator cla = new ClientLoginAuthenticator("uploader", ServiceNames.Documents, m_username, m_password);

            // Start the upload process
            if (cancel())
            {
                return;
            }
            if (fileExists)
            {
                uploader.UpdateAsync(cla, entry, new Object());
            }
            else
            {
                uploader.InsertAsync(cla, entry, new Object());
            }
        }