protected void ExecuteUpload(IExecutePicasaUploaderWorkflowMessage message, ClientLoginAuthenticator picasaAuthenticator, PicasaEntry picasaEntry) { var cancellationTokenSource = new CancellationTokenSource(); var cancellationToken = cancellationTokenSource.Token; var task = Task.Factory.StartNew(()=>{}); task.ContinueWith((t) => { if (!cancellationToken.IsCancellationRequested) { PicasaUploaderService.Uploaders.Add(message, new CancellableTask { Task = task, CancellationTokenSource = cancellationTokenSource }); var resumableUploader = new ResumableUploader(message.Settings.Upload.ChunkSize); resumableUploader.AsyncOperationCompleted += OnResumableUploaderAsyncOperationCompleted; resumableUploader.AsyncOperationProgress += OnResumableUploaderAsyncOperationProgress; cancellationToken.Register(() => resumableUploader.CancelAsync(message)); resumableUploader.InsertAsync(picasaAuthenticator, picasaEntry, message); } cancellationToken.ThrowIfCancellationRequested(); } , cancellationToken); }
public void CreateTemplate() { DocumentsService service = new DocumentsService(applicationName); DocumentEntry entry = new DocumentEntry(); // Set the document title entry.Title.Text = spreadsheetName; entry.IsSpreadsheet = true; // Set the media source entry.MediaSource = new MediaFileSource(GetStreamWithTemplate(), applicationName, "text/csv"); // Define the resumable upload link Uri createUploadUrl = new Uri("https://docs.google.com/feeds/upload/create-session/default/private/full"); 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 = service; // Instantiate the ResumableUploader component. ResumableUploader uploader = new ResumableUploader(); // Start the upload process uploader.Insert(new ClientLoginAuthenticator(applicationName,ServiceNames.Documents,userName,password), entry); }
public async Task UploadToYouTube(HttpPostedFile postedFile, string title) { UploadingDispatcher.SetProgress(uploadId, 2); Video video = new Video(); video.Title = title; video.Tags.Add(new MediaCategory("Autos", YouTubeNameTable.CategorySchema)); video.Private = false; video.MediaSource = new MediaFileSource(postedFile.InputStream, postedFile.FileName, postedFile.ContentType); var link = new AtomLink("http://uploads.gdata.youtube.com/resumable/feeds/api/users/default/uploads"); link.Rel = ResumableUploader.CreateMediaRelation; video.YouTubeEntry.Links.Add(link); var youtubeApiKey = ConfigurationManager.AppSettings["youtubeApiKey"]; var applicationName = ConfigurationManager.AppSettings["applicationName"]; var youtubeUserName = ConfigurationManager.AppSettings["youtubeUserName"]; var youtubePassword = ConfigurationManager.AppSettings["youtubePassword"]; var youtubeChunksize = int.Parse(ConfigurationManager.AppSettings["youtubeChunksize"]); var resumableUploader = new ResumableUploader(youtubeChunksize); resumableUploader.AsyncOperationCompleted += resumableUploader_AsyncOperationCompleted; resumableUploader.AsyncOperationProgress += resumableUploader_AsyncOperationProgress; var youTubeAuthenticator = new ClientLoginAuthenticator(applicationName, ServiceNames.YouTube, youtubeUserName, youtubePassword); youTubeAuthenticator.DeveloperKey = youtubeApiKey; resumableUploader.InsertAsync(youTubeAuthenticator, video.YouTubeEntry, uploadId); }
private WebResponse Update(Authenticator authentication, AbstractEntry payload, AsyncData data) { Uri initialUri = ResumableUploader.GetResumableEditUri(payload.Links); if (initialUri == null) { throw new ArgumentException("payload did not contain a resumabled edit media Uri"); } Uri resumeUri = InitiateUpload(initialUri, authentication, payload); return(UploadStream(HttpMethods.Put, resumeUri, authentication, payload.MediaSource.Data, payload.MediaSource.ContentType, data)); }
private WebResponse Insert(Authenticator authentication, AbstractEntry payload, AsyncData data) { WebResponse r = null; Uri initialUri = ResumableUploader.GetResumableCreateUri(payload.Links); if (initialUri == null) { throw new ArgumentException("payload did not contain a resumable create media Uri"); } Uri resumeUri = InitiateUpload(initialUri, authentication, payload); using (Stream s = payload.MediaSource.GetDataStream()) { r = UploadStream(HttpMethods.Post, resumeUri, authentication, s, payload.MediaSource.ContentType, data); } return(r); }
public void DoWorkbookUpload(object in_instance) { var instance = in_instance as Google2uData; if (instance == null) return; if (!string.IsNullOrEmpty(instance.WorkbookUploadPath)) { try { // We need a DocumentService var service = new DocumentsService("Google2Unity"); var mimeType = Google2uMimeType.GetMimeType(instance.WorkbookUploadPath); var authenticator = new OAuth2Authenticator("Google2Unity", _authParameters); // Instantiate a DocumentEntry object to be inserted. var entry = new DocumentEntry { MediaSource = new MediaFileSource(instance.WorkbookUploadPath, mimeType) }; // Define the resumable upload link var createUploadUrl = new Uri("https://docs.google.com/feeds/upload/create-session/default/private/full"); var link = new AtomLink(createUploadUrl.AbsoluteUri) { Rel = ResumableUploader.CreateMediaRelation }; entry.Links.Add(link); // Set the service to be used to parse the returned entry entry.Service = service; // Instantiate the ResumableUploader component. var uploader = new ResumableUploader(); // Set the handlers for the completion and progress events uploader.AsyncOperationCompleted += OnSpreadsheetUploadDone; uploader.AsyncOperationProgress += OnSpreadsheetUploadProgress; // Start the upload process uploader.InsertAsync(authenticator, entry, instance); } catch (Exception) { PushNotification( "There is a problem with your credentials. Clear the credentials and Re-Authorize G2U"); //instance.Messages.Add(new G2GUIMessage(GFGUIMessageType.InvalidLogin, ex.Message)); instance.Commands.Remove(GFCommand.WaitingForUpload); } } }
// helper to create a ResumableUploader object and setup the event handlers private void EnsureRU() { this.ru = new ResumableUploader((int)this.ChunkSize.Value); this.ru.AsyncOperationCompleted += new AsyncOperationCompletedEventHandler(this.OnDone); this.ru.AsyncOperationProgress += new AsyncOperationProgressEventHandler(this.OnProgress); }
public static void CreateGoogleNote(/*Document parentFolder, */Document googleNote, object UserData, DocumentsRequest documentsRequest, ResumableUploader uploader, OAuth2Authenticator authenticator) { // Define the resumable upload link Uri createUploadUrl = new Uri("https://docs.google.com/feeds/upload/create-session/default/private/full"); //Uri createUploadUrl = new Uri(GoogleNotesFolder.AtomEntry.EditUri.ToString()); AtomLink link = new AtomLink(createUploadUrl.AbsoluteUri); link.Rel = ResumableUploader.CreateMediaRelation; googleNote.DocumentEntry.Links.Add(link); //if (parentFolder != null) // googleNote.DocumentEntry.ParentFolders.Add(new AtomLink(parentFolder.DocumentEntry.SelfUri.ToString())); // Set the service to be used to parse the returned entry googleNote.DocumentEntry.Service = documentsRequest.Service; // Start the upload process //uploader.InsertAsync(_authenticator, match.GoogleNote.DocumentEntry, new object()); uploader.InsertAsync(authenticator, googleNote.DocumentEntry, UserData); }
public void SaveGoogleNote(NoteMatch match) { Outlook.NoteItem outlookNoteItem = match.OutlookNote; //try //{ //ToDo: Somewhow, the content is not uploaded to Google, only an empty document //match.GoogleNote = SaveGoogleNote(match.GoogleNote); //New approach how to update an existing document: https://developers.google.com/google-apps/documents-list/#updatingchanging_documents_and_files // Instantiate the ResumableUploader component. ResumableUploader uploader = new ResumableUploader(); // Set the handlers for the completion and progress events //uploader.AsyncOperationProgress += new AsyncOperationProgressEventHandler(OnProgress); //ToDo: Therefoe I use DocumentService.UploadDocument instead and move it to the NotesFolder string oldOutlookGoogleNoteId = NotePropertiesUtils.GetOutlookGoogleNoteId(this, outlookNoteItem); if (match.GoogleNote.DocumentEntry.Id.Uri != null) { //DocumentsRequest.Delete(new Uri(Google.GData.Documents.DocumentsListQuery.documentsBaseUri + "/" + match.GoogleNote.ResourceId), match.GoogleNote.ETag); ////DocumentsRequest.Delete(match.GoogleNote); //ToDo: Currently, the Delete only removes the Notes label from the document but keeps the document in the root folder //NotePropertiesUtils.ResetOutlookGoogleNoteId(this, outlookNoteItem); ////ToDo: Currently, the Delete only removes the Notes label from the document but keeps the document in the root folder //Document deletedNote = LoadGoogleNotes(match.GoogleNote.DocumentEntry.Id); //if (deletedNote != null) // DocumentsRequest.Delete(deletedNote); // Start the update process. uploader.AsyncOperationCompleted += new AsyncOperationCompletedEventHandler(OnGoogleNoteUpdated); uploader.UpdateAsync(authenticator, match.GoogleNote.DocumentEntry, match); //uploader.Update(_authenticator, match.GoogleNote.DocumentEntry); } else { uploader.AsyncOperationCompleted += new AsyncOperationCompletedEventHandler(OnGoogleNoteCreated); CreateGoogleNote(match.GoogleNote, match, DocumentsRequest, uploader, authenticator); } match.AsyncUpdateCompleted = false; //Google.GData.Documents.DocumentEntry entry = DocumentsRequest.Service.UploadDocument(NotePropertiesUtils.GetFileName(outlookNoteItem.EntryID, SyncProfile), match.GoogleNote.Title.Replace(":", String.Empty)); //Document newNote = LoadGoogleNotes(entry.Id); //match.GoogleNote = DocumentsRequest.MoveDocumentTo(GoogleNotesFolder, newNote); //First delete old temporary file, because it was saved with old GoogleNoteID, because every sync to Google becomes a new ID, because updateMedia doesn't work //File.Delete(NotePropertiesUtils.GetFileName(oldOutlookGoogleNoteId, SyncProfile)); //UpdateNoteMatchId(match); //} //finally //{ // Marshal.ReleaseComObject(outlookNoteItem); // outlookNoteItem = null; //} }
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); }
public void CreateNewNote() { string gmailUsername; string syncProfile; GoogleAPITests.LoadSettings(out gmailUsername, out syncProfile); DocumentsRequest service; var scopes = new List<string>(); //Contacts-Scope scopes.Add("https://www.google.com/m8/feeds"); //Notes-Scope scopes.Add("https://docs.google.com/feeds/"); //scopes.Add("https://docs.googleusercontent.com/"); //scopes.Add("https://spreadsheets.google.com/feeds/"); //Calendar-Scope //scopes.Add("https://www.googleapis.com/auth/calendar"); scopes.Add(CalendarService.Scope.Calendar); UserCredential credential; byte[] jsonSecrets = Properties.Resources.client_secrets; using (var stream = new MemoryStream(jsonSecrets)) { FileDataStore fDS = new FileDataStore(Logger.AuthFolder, true); GoogleClientSecrets clientSecrets = GoogleClientSecrets.Load(stream); credential = GCSMOAuth2WebAuthorizationBroker.AuthorizeAsync( clientSecrets.Secrets, scopes.ToArray(), gmailUsername, CancellationToken.None, fDS). Result; OAuth2Parameters parameters = new OAuth2Parameters { ClientId = clientSecrets.Secrets.ClientId, ClientSecret = clientSecrets.Secrets.ClientSecret, // Note: AccessToken is valid only for 60 minutes AccessToken = credential.Token.AccessToken, RefreshToken = credential.Token.RefreshToken }; RequestSettings settings = new RequestSettings("GoContactSyncMod", parameters); service = new DocumentsRequest(settings); //Instantiate an Authenticator object according to your authentication, to use ResumableUploader _authenticator = new OAuth2Authenticator("GCSM Unit Tests", parameters); } //Delete previously created test note. DeleteTestNote(service); Document newEntry = new Document(); newEntry.Type = Document.DocumentType.Document; newEntry.Title = "AN_OUTLOOK_TEST_NOTE"; string file = NotePropertiesUtils.CreateNoteFile("AN_OUTLOOK_TEST_NOTE", "This is just a test note to test GoContactSyncMod", null); newEntry.MediaSource = new MediaFileSource(file, MediaFileSource.GetContentTypeForFileName(file)); #region normal flow, only working to create documents without content (metadata only), e.g. for Notes folder Document createdEntry = Synchronizer.SaveGoogleNote(null, newEntry, service); Assert.IsNotNull(createdEntry.DocumentEntry.Id.Uri); Logger.Log("Created Google note", EventType.Information); //Wait 5 seconds to give the testcase the chance to finish System.Threading.Thread.Sleep(5000); //delete test note DeleteTestNote(service); #endregion #region workaround flow to use UploadDocument, not needed anymore because of new approach to use ResumableUploader //Google.GData.Documents.DocumentEntry createdEntry2 = service.Service.UploadDocument(file, newEntry.Title); //Assert.IsNotNull(createdEntry2.Id.Uri); ////delete test note //DeleteTestNote(service); #endregion #region New approach how to update an existing document: https://developers.google.com/google-apps/documents-list/#updatingchanging_documents_and_files //Instantiate the ResumableUploader component. ResumableUploader uploader = new ResumableUploader(); uploader.AsyncOperationCompleted += new AsyncOperationCompletedEventHandler(OnGoogleNoteCreated); Synchronizer.CreateGoogleNote(newEntry, file, service, uploader, _authenticator); #endregion //Wait 5 seconds to give the testcase the chance to finish the Async events System.Threading.Thread.Sleep(5000); DeleteTestNote(service); }