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 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); }
public void ClientLoginAuthenticatorTest() { Tracing.TraceMsg("Entering ClientLoginAuthenticatorTest"); ClientLoginAuthenticator auth = new ClientLoginAuthenticator( this.ApplicationName, ServiceNames.Documents, this.userName, this.passWord); HttpWebRequest request = auth.CreateHttpWebRequest("GET", new Uri(DocumentsListQuery.documentsBaseUri)); request.Headers.Set(GDataGAuthRequestFactory.GDataVersion, "3.0"); HttpWebResponse response = request.GetResponse() as HttpWebResponse; if (response.StatusCode == HttpStatusCode.Redirect) { request = WebRequest.Create(response.Headers["Location"]) as HttpWebRequest; auth.ApplyAuthenticationToRequest(request); response = request.GetResponse() as HttpWebResponse; } Assert.IsTrue(response.StatusCode == HttpStatusCode.OK); }
void DrawCreateWorkbookGUI() { EditorGUILayout.BeginHorizontal(); DrawHelpButtonGUI("ID_HELP_UPLOAD_WORKBOOK"); DrawLabelHeader("ID_CREATE_WORKBOOK"); EditorGUILayout.EndHorizontal(); EditorGUILayout.Separator(); EditorGUILayout.BeginHorizontal(); Indent(1); GUI.backgroundColor = Color.clear; GUI.color = Color.yellow; bool bDoSave = false; GUI.SetNextControlName("Clear"); if (GUILayout.Button(_BrowseButton, EditorStyles.toolbarButton, GUILayout.Width(24))) { ClearMessages(); string workbookpath = EditorUtility.OpenFilePanel( Localize("ID_SELECT_UPLOAD_WORKBOOK_PATH"), EditorApplication.applicationPath, "*.xls;*.xlsx;*.ods;*.csv;*.txt;*.tsv"); if (!string.IsNullOrEmpty(workbookpath)) { if ((workbookpath.IndexOf(".xls", System.StringComparison.InvariantCultureIgnoreCase) != -1) || (workbookpath.IndexOf(".xlsx", System.StringComparison.InvariantCultureIgnoreCase) != -1) || (workbookpath.IndexOf(".ods", System.StringComparison.InvariantCultureIgnoreCase) != -1) || (workbookpath.IndexOf(".csv", System.StringComparison.InvariantCultureIgnoreCase) != -1) || (workbookpath.IndexOf(".txt", System.StringComparison.InvariantCultureIgnoreCase) != -1) || (workbookpath.IndexOf(".tsv", System.StringComparison.InvariantCultureIgnoreCase) != -1)) { bDoSave = true; } if (bDoSave) { _WorkbookUploadPath = workbookpath; GUI.FocusControl("Clear"); Repaint(); } else { _EditorWarning = Localize("ID_ERROR_UPLOAD_WORKBOOK_PATH"); Debug.LogWarning(_EditorWarning); } } } GUI.backgroundColor = _DefaultBgColor; GUI.color = _DefaultFgColor; EditorGUILayout.TextField(_WorkbookUploadPath); GUILayout.Label(System.String.Empty, GUILayout.Width(5)); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); GUILayout.Label(System.String.Empty); if (CreatingWorkbook) GUI.enabled = false; if (GUILayout.Button(Localize("ID_CREATE"), EditorStyles.miniButton, GUILayout.Width(65))) { ClearMessages(); // We need a DocumentService var service = new Google.GData.Documents.DocumentsService("GoogleFuUploader"); string mimeType = GoogleFuMimeType.GetMimeType(_WorkbookUploadPath); var authenticator = new Google.GData.Client.ClientLoginAuthenticator("UnityGoogleFu", Google.GData.Client.ServiceNames.Documents, _Username, _Password); //service.setUserCredentials(_username, _password); // Instantiate a DocumentEntry object to be inserted. var entry = new Google.GData.Documents.DocumentEntry(); CreatingWorkbook = true; entry.MediaSource = new Google.GData.Client.MediaFileSource(_WorkbookUploadPath, mimeType); // Define the resumable upload link var createUploadUrl = new System.Uri("https://docs.google.com/feeds/upload/create-session/default/private/full"); var link = new Google.GData.Client.AtomLink(createUploadUrl.AbsoluteUri) { Rel = Google.GData.Client.ResumableUpload.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 Google.GData.Client.ResumableUpload.ResumableUploader(); // Set the handlers for the completion and progress events uploader.AsyncOperationCompleted += OnSpreadsheetUploadDone; uploader.AsyncOperationProgress += OnSpreadsheetUploadProgress; // Start the upload process uploader.InsertAsync(authenticator, entry, new object()); _EditorInfo = Localize("ID_CREATING_DATABASE_MESSAGE"); //Repaint(); } GUI.enabled = true; GUILayout.Label(System.String.Empty, GUILayout.Width(5)); EditorGUILayout.EndHorizontal(); }