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 Google.GData.Documents.DocumentsService("Google2Unity"); var mimeType = Google2uMimeType.GetMimeType(instance.WorkbookUploadPath); var authenticator = new OAuth2Authenticator("Google2Unity", _authParameters); // Instantiate a DocumentEntry object to be inserted. var entry = new Google.GData.Documents.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 = 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, 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); } } }
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(); }