/// <summary> /// Uploads given content to a file in the Microsoft OneDrive Cloud Storage with an existing refresh token. /// </summary> /// <param name="ll">current instance of List & Label</param> /// <param name="uploadParameters">requied parameters for Microsoft OneDrive OAuth 2.0 upload silently.</param> /// <param name="credentials">requied parameters for Microsoft OneDrive OAuth 2.0 authentication.</param> public static void UploadSilently(this Reporting.ListLabel ll, MicrosoftOneDriveUploadParameter uploadParameters, MicrosoftOneDriveCredentials credentials) { // Initialize the GraphServiceClient. GraphServiceClient graphClient = SDKHelper.GetAuthenticatedClient(credentials.RefreshToken, uploadParameters.ApplicationId, credentials.ApplicationSecret, credentials.Scope, credentials.RedirectUri); // Add the file. UploadLargeFile(graphClient, uploadParameters.UploadStream, string.Concat(uploadParameters.CloudPath, "/", uploadParameters.CloudFileName)); }
/// <summary> /// Uploads given content to a file in the Dropbox Cloud Storage. /// </summary> /// <param name="ll">current instance of List & Label</param> /// <param name="uploadParameters">requied parameters for Dropbox OAuth 2.0 upload silently.</param> /// <param name="acessToken">The current valid access token.</param> public static void UploadSilently(this Reporting.ListLabel ll, DropboxUploadParameter uploadParameters, string accessToken) { using (var client = new DropboxClient(accessToken)) { if (string.IsNullOrEmpty(uploadParameters.CloudPath) || uploadParameters.CloudPath[0] != '/') //add leading slash { uploadParameters.CloudPath = string.Concat("/", uploadParameters.CloudPath); } CreateFolder(client, uploadParameters.CloudPath); Upload(client, uploadParameters.CloudPath, uploadParameters.CloudFileName, uploadParameters.UploadStream); } }
/// <summary> /// Uploads given content to a file in the Microsoft OneDrive Cloud Storage. /// </summary> /// <param name="ll">current instance of List & Label</param> /// <param name="uploadParameters">requied parameters for Microsoft OneDrive OAuth 2.0 upload.</param> public static async void Upload(this Reporting.ListLabel ll, MicrosoftOneDriveUploadParameter uploadParameters) { var graphClient = AuthenticationHelper.GetAuthenticatedClient(uploadParameters.ApplicationId); if (graphClient != null) { var user = await graphClient.Me.Request().GetAsync(); var uploadedItem = await graphClient .Drive .Root .ItemWithPath($"{uploadParameters.CloudPath}/{uploadParameters.CloudFileName}") .Content .Request() .PutAsync <DriveItem>(uploadParameters.UploadStream); } }
/// <summary> /// Uploads given content to a file in the Google Drive Cloud Storage. /// </summary> /// <param name="ll">current instance of List & Label</param> /// <param name="uploadParameters">requied parameters for Google Drive OAuth 2.0 upload.</param> /// <param name="clientSecretFilePath">The full path of client secret file.</param> public static void Upload(this Reporting.ListLabel ll, GoogleDriveUploadParameter uploadParameters, string clientSecretFilePath) { UserCredential credential; using (var stream = new FileStream(clientSecretFilePath, FileMode.Open, FileAccess.Read)) { string credPath = System.Environment.GetFolderPath( System.Environment.SpecialFolder.Personal); credPath = Path.Combine(credPath, ".credentials/drive-dotnet-quickstart.json"); credential = GoogleWebAuthorizationBroker.AuthorizeAsync( GoogleClientSecrets.Load(stream).Secrets, Scopes, "user2", CancellationToken.None, new FileDataStore(credPath, true)).Result; Upload2GoogleDrive(credential, uploadParameters.UploadStream, uploadParameters.CloudFileName, uploadParameters.CloudPath, uploadParameters.ApplicationName, uploadParameters.MimeType); } }
/// <summary> /// Uploads given content to a file in the Google Drive Cloud Storage. /// </summary> /// <param name="ll">current instance of List & Label</param> /// <param name="uploadParameters">requied parameters for Google Drive OAuth 2.0 upload silently.</param> /// <param name="credentials">requied parameters for Google Drive OAuth 2.0 authentication.</param> public static void UploadSilently(this Reporting.ListLabel ll, GoogleDriveUploadParameter uploadParameters, GoogleDriveCredentials credentials) { var flow = new GoogleAuthorizationCodeFlow(new GoogleAuthorizationCodeFlow.Initializer { ClientSecrets = new ClientSecrets { ClientId = credentials.ClientId, ClientSecret = credentials.ClientSecret }, Scopes = Scopes }); var accessToken = Reporting.DataProviders.GoogleDataProviderHelper.GetAuthToken(credentials.RefreshToken, credentials.ClientId, credentials.ClientSecret); var token = new TokenResponse { AccessToken = accessToken, RefreshToken = credentials.RefreshToken }; var credential = new UserCredential(flow, Environment.UserName, token); Upload2GoogleDrive(credential, uploadParameters.UploadStream, uploadParameters.CloudFileName, uploadParameters.CloudPath, uploadParameters.ApplicationName, uploadParameters.MimeType); }
/// <summary> /// Export a report using current instance of ListLabel and upload it directly to the Google Drive Cloud Storage. /// </summary> /// <param name="ll">current instance of List & Label</param> /// <param name="exportConfiguration">required export configuration for native ListLabel Export method</param> /// <param name="exportParameters">requied parameters for Google Drive OAuth 2.0 upload.</param> /// <param name="clientSecretFilePath">The full path of client secret file.</param> public static void Export(this Reporting.ListLabel ll, ExportConfiguration exportConfiguration, GoogleDriveExportParameter exportParameters, string clientSecretFilePath) { ll.AutoShowSelectFile = false; ll.AutoShowPrintOptions = false; ll.AutoDestination = LlPrintMode.Export; ll.AutoProjectType = LlProject.List; ll.AutoBoxType = LlBoxType.None; exportConfiguration.ExportOptions.Add("Export.Quiet", "1"); string mimeType = string.Empty; switch (exportConfiguration.ExportTarget) { case LlExportTarget.Pdf: exportParameters.CloudFileName += ".pdf"; mimeType = "application/pdf"; break; case LlExportTarget.Rtf: exportParameters.CloudFileName += ".rtf"; mimeType = "application/rtf"; break; case LlExportTarget.Xls: exportParameters.CloudFileName += ".xls"; mimeType = "application/vnd.ms-excel"; break; case LlExportTarget.Xlsx: exportParameters.CloudFileName += ".xlsx"; mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break; case LlExportTarget.Docx: exportParameters.CloudFileName += ".docx"; mimeType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; break; case LlExportTarget.Xps: exportParameters.CloudFileName += ".xps"; mimeType = "application/vnd.ms-xpsdocument"; break; case LlExportTarget.Mhtml: exportParameters.CloudFileName += ".mhtml"; mimeType = "message/rfc822"; break; case LlExportTarget.Text: exportParameters.CloudFileName += ".txt"; mimeType = "text/plain"; break; case LlExportTarget.Pptx: exportParameters.CloudFileName += ".pptx"; mimeType = "application/vnd.openxmlformats-officedocument.presentationml.presentation"; break; default: exportParameters.CloudFileName += ".zip"; mimeType = "application/zip"; exportConfiguration.ExportOptions.Add(LlExportOption.ExportSaveAsZip, "1"); exportConfiguration.ExportOptions.Add(LlExportOption.ExportZipFile, exportParameters.CloudFileName); exportConfiguration.ExportOptions.Add(LlExportOption.ExportZipPath, Path.GetDirectoryName(exportConfiguration.Path)); break; } ll.Export(exportConfiguration); FileStream stream = System.IO.File.Open(string.Concat(Path.GetDirectoryName(exportConfiguration.Path), "\\", exportParameters.CloudFileName), FileMode.Open); Upload(ll, new GoogleDriveUploadParameter() { UploadStream = stream, CloudFileName = exportParameters.CloudFileName, CloudPath = exportParameters.CloudPath, ApplicationName = exportParameters.ApplicationName, MimeType = mimeType }, clientSecretFilePath); }
/// <summary> /// Export a report using current instance of ListLabel and upload it directly to the Dropbox Cloud Storage. /// </summary> /// <param name="ll">current instance of List & Label</param> /// <param name="exportConfiguration">required export configuration for native ListLabel Export method</param> /// <param name="exportParameters">requied parameters to uplaod exported report to Dropbox.</param> /// <param name="appkey">AppKey of your Dropbox App.</param> public static void Export(this Reporting.ListLabel ll, ExportConfiguration exportConfiguration, DropboxExportParameter exportParameters, string appKey) { ll.AutoShowSelectFile = false; ll.AutoShowPrintOptions = false; ll.AutoDestination = LlPrintMode.Export; ll.AutoProjectType = LlProject.List; ll.AutoBoxType = LlBoxType.None; exportConfiguration.ExportOptions.Add("Export.Quiet", "1"); switch (exportConfiguration.ExportTarget) { case LlExportTarget.Pdf: exportParameters.CloudFileName += ".pdf"; break; case LlExportTarget.Rtf: exportParameters.CloudFileName += ".rtf"; break; case LlExportTarget.Xls: exportParameters.CloudFileName += ".xls"; break; case LlExportTarget.Xlsx: exportParameters.CloudFileName += ".xlsx"; break; case LlExportTarget.Docx: exportParameters.CloudFileName += ".docx"; break; case LlExportTarget.Xps: exportParameters.CloudFileName += ".xps"; break; case LlExportTarget.Mhtml: exportParameters.CloudFileName += ".mhtml"; break; case LlExportTarget.Text: exportParameters.CloudFileName += ".txt"; break; case LlExportTarget.Pptx: exportParameters.CloudFileName += ".pptx"; break; default: exportParameters.CloudFileName += ".zip"; exportConfiguration.ExportOptions.Add(LlExportOption.ExportSaveAsZip, "1"); exportConfiguration.ExportOptions.Add(LlExportOption.ExportZipFile, exportParameters.CloudFileName); exportConfiguration.ExportOptions.Add(LlExportOption.ExportZipPath, Path.GetDirectoryName(exportConfiguration.Path)); break; } ll.Export(exportConfiguration); FileStream stream = System.IO.File.Open(string.Concat(Path.GetDirectoryName(exportConfiguration.Path), "\\", exportParameters.CloudFileName), FileMode.Open); Upload(ll, new DropboxUploadParameter() { UploadStream = stream, CloudFileName = exportParameters.CloudFileName, CloudPath = exportParameters.CloudPath }, appKey); }