public DropBoxClient(string appKey, string appSecret) { this.dropboxAppKey = appKey; this.dropboxAppSecret = appSecret; this.dropboxServiceProvider = new DropboxServiceProvider(this.dropboxAppKey, this.dropboxAppSecret, AccessLevel.AppFolder); }
static void Main() { DropboxServiceProvider dropboxServiceProvider = new DropboxServiceProvider(DropboxAppKey, DropboxAppSecret, AccessLevel.AppFolder); // Authenticate the application (if not authenticated) and load the OAuth token if (!File.Exists(OAuthTokenFileName)) { AuthorizeAppOAuth(dropboxServiceProvider); } OAuthToken oauthAccessToken = LoadOAuthToken(); // Login in Dropbox IDropbox dropbox = dropboxServiceProvider.GetApi(oauthAccessToken.Value, oauthAccessToken.Secret); // Display user name (from his profile) DropboxProfile profile = dropbox.GetUserProfileAsync().Result; Console.WriteLine("Hi " + profile.DisplayName + "!"); // Create new folder string newFolderName = "New_Folder_" + DateTime.Now.Ticks; Entry createFolderEntry = dropbox.CreateFolderAsync(newFolderName).Result; Console.WriteLine("Created folder: {0}", createFolderEntry.Path); // Upload a file Entry uploadFileEntry = dropbox.UploadFileAsync( new FileResource("../../DropboxExample.cs"), "/" + newFolderName + "/DropboxExample.cs").Result; Console.WriteLine("Uploaded a file: {0}", uploadFileEntry.Path); // Share a file DropboxLink sharedUrl = dropbox.GetShareableLinkAsync(uploadFileEntry.Path).Result; Process.Start(sharedUrl.Url); }
public void UploadFile() { var filePath = string.Empty; if (HttpContext.Current.Request.Files.AllKeys.Any()) { var httpPostedFile = HttpContext.Current.Request.Files["UploadedImage"]; if (httpPostedFile != null) { var fileSavePath = Path.Combine(HttpContext.Current.Server.MapPath("~/UploadedFiles"), httpPostedFile.FileName); filePath = fileSavePath; name = httpPostedFile.FileName; httpPostedFile.SaveAs(fileSavePath); } } DropboxServiceProvider dropboxServiceProvider = new DropboxServiceProvider(DropboxAppKey, DropboxAppSecret, AccessLevel.AppFolder); IDropbox dropbox = dropboxServiceProvider.GetApi("ewl8tryz0hmkulda", "p1n05i71cfhohlu"); Entry uploadFileEntry = dropbox.UploadFileAsync(new FileResource(string.Format(filePath)), string.Format("/DateFirstImagesDb/{0}", name)).Result; var link = dropbox.GetMediaLinkAsync(string.Format("/DateFirstImagesDb/{0}", name)); var avatarUrl = link.Result.Url; var userManager = Request.GetOwinContext().GetUserManager<ApplicationUserManager>(); var loginUser = userManager.FindById(User.Identity.GetUserId()); var userForUpdate = this.data.Users.GetById(loginUser.Id); userForUpdate.AvatarUrl = avatarUrl; data.SaveChanges(); }
private DropboxImageUploader() { this.dropboxServiceProvider = new DropboxServiceProvider(DropboxAppKey, DropboxAppSecret, AccessLevel.Full); this.oauthAccessToken = new OAuthToken(OauthAccessTokenValue, OauthAccessTokenSecret); // this.oauthAccessToken = this.LoadOAuthToken(); this.client = new WebClient(); this.dropbox = this.dropboxServiceProvider.GetApi(this.oauthAccessToken.Value, this.oauthAccessToken.Secret); }
private void Initialize() { try { Console.WriteLine("DropboxCoreService - Initialize - Initializing service..."); var diskToken = LoadTokenFromDisk(); var oauthAccessToken = new OAuthToken(diskToken.Value, diskToken.Secret); _dropboxServiceProvider = new DropboxServiceProvider(DropboxAppKey, DropboxAppSecret, AccessLevel.AppFolder); _dropbox = _dropboxServiceProvider.GetApi(oauthAccessToken.Value, oauthAccessToken.Secret); //dropbox.Locale = CultureInfo.CurrentUICulture.IetfLanguageTag; HasLinkedAccount = true; Console.WriteLine("DropboxCoreService - Initialize - Finished initializing service!"); } catch (AggregateException ae) { HasLinkedAccount = false; ae.Handle(ex => { if (ex is DropboxApiException) { Console.WriteLine("DropboxCoreService - Initialize - Exception: {0}", ex); return true; } // Ignore exceptions; if we cannot login on initialize, the user will have to relink the app later. // The UI should check the HasLinkedAccount property to see if Dropbox is available. return true; }); } catch (Exception ex) { // Ignore exceptions (see previous comment) } }
public static void Main() { DropboxServiceProvider dropboxServiceProvider = new DropboxServiceProvider(DropboxAppKey, DropboxAppSecret, AccessLevel.AppFolder); // Authenticate the application (if not authenticated) and load the OAuth token if (!File.Exists(OAuthTokenFileName)) { AuthorizeAppOAuth(dropboxServiceProvider); } OAuthToken oauthAccessToken = LoadOAuthToken(); // Login in Dropbox IDropbox dropbox = dropboxServiceProvider.GetApi(oauthAccessToken.Value, oauthAccessToken.Secret); // Create new folder string newFolderName = "Test"; Entry createFolderEntry = dropbox.CreateFolderAsync(newFolderName).Result; Console.WriteLine("Created folder: {0}", createFolderEntry.Path); // Upload a file Entry uploadFileEntry = dropbox.UploadFileAsync( new FileResource("../../cat.jpg"), "/" + newFolderName + "/cat.jpg").Result; Console.WriteLine("Uploaded a file: {0}", uploadFileEntry.Path); // Share a file DropboxLink sharedUrl = dropbox.GetShareableLinkAsync(uploadFileEntry.Path).Result; Process.Start(sharedUrl.Url); }
public MainWindow() { InitializeComponent(); dropboxServiceProvider = new DropboxServiceProvider(DropboxAppKey, DropboxAppSecret, AccessLevel.AppFolder); }
public static void Main(string[] args) { // Pleace fill the DropboxAppKey and DropboxAppSecret with your credentionals before you test the app. DropboxServiceProvider dropboxServiceProvider = new DropboxServiceProvider(DropboxAppKey, DropboxAppSecret, AccessLevel.AppFolder); var oauthAccessToken = AuthorizeAppOAuth(dropboxServiceProvider); IDropbox dropbox = dropboxServiceProvider.GetApi(oauthAccessToken.Value, oauthAccessToken.Secret); DropboxProfile profile = dropbox.GetUserProfileAsync().Result; Console.WriteLine("Hi " + profile.DisplayName + "!"); string newFolderName = "Your_New_Images_Folder"; Entry createFolderEntry = dropbox.CreateFolderAsync(newFolderName).Result; var imageAsFileResource = new FileResource("../../Images/image1.jpg"); var pathToUpload = "/" + newFolderName + "/image1.jpg"; Entry uploadFileEntry = dropbox.UploadFileAsync(imageAsFileResource, pathToUpload).Result; Console.WriteLine("Uploaded a file: {0}", uploadFileEntry.Path); DropboxLink sharedUrl = dropbox.GetShareableLinkAsync(uploadFileEntry.Path).Result; Process.Start(sharedUrl.Url); }
private static void AuthorizeAppOAuth(DropboxServiceProvider dropboxServiceProvider) { // Authorization without callback url Console.Write("Getting request token..."); OAuthToken oauthToken = dropboxServiceProvider.OAuthOperations.FetchRequestTokenAsync(null, null).Result; Console.WriteLine("Done."); OAuth1Parameters parameters = new OAuth1Parameters(); string authenticateUrl = dropboxServiceProvider.OAuthOperations.BuildAuthorizeUrl( oauthToken.Value, parameters); Console.WriteLine("Redirect the user for authorization to {0}", authenticateUrl); Process.Start(authenticateUrl); Console.Write("Press [Enter] when authorization attempt has succeeded."); Console.ReadLine(); Console.Write("Getting access token..."); AuthorizedRequestToken requestToken = new AuthorizedRequestToken(oauthToken, null); OAuthToken oauthAccessToken = dropboxServiceProvider.OAuthOperations.ExchangeForAccessTokenAsync(requestToken, null).Result; Console.WriteLine("Done."); string[] oauthData = new string[] { oauthAccessToken.Value, oauthAccessToken.Secret }; File.WriteAllLines(OAuthTokenFileName, oauthData); }
public string UploadFileToDropBox(string filePath, string fileName) { DropboxServiceProvider dropboxServiceProvider = new DropboxServiceProvider(DropboxAppKey, DropboxAppSecret, AccessLevel.AppFolder); // Authenticate the application (if not authenticated) and load the OAuth token // TODO - throw exception if auth file is not found //if (!File.Exists(OAuthTokenFileName)) //{ // AuthorizeAppOAuth(dropboxServiceProvider); //} OAuthToken oauthAccessToken = LoadOAuthToken(); // Login in Dropbox IDropbox dropbox = dropboxServiceProvider.GetApi(oauthAccessToken.Value, oauthAccessToken.Secret); // Display user name (from his profile) //DropboxProfile profile = dropbox.GetUserProfileAsync().Result; //Console.WriteLine("Hi " + profile.DisplayName + "!"); // Create new folder string newFolderName = DateTime.Now.Ticks.ToString(); //Entry createFolderEntry = dropbox.CreateFolderAsync(newFolderName).Result; Entry createFolderEntry = dropbox.CreateFolder(newFolderName); // Upload a file Entry uploadFileEntry = dropbox.UploadFile( new FileResource(filePath), "/" + newFolderName + "/" + fileName); // Share a file //DropboxLink sharedUrl = dropbox.GetShareableLinkAsync(uploadFileEntry.Path).Result; string sharedUrl = dropbox.GetMediaLink(uploadFileEntry.Path).Url.ToString(); // var ret = sharedUrl.Url.ToString(); return sharedUrl; }
public string LoadImage(string path) { DropboxServiceProvider dropboxServiceProvider = new DropboxServiceProvider(DropboxAppKey, DropboxAppSecret, AccessLevel.AppFolder); // Authenticate the application (if not authenticated) and load the OAuth token if (!File.Exists(OAuthTokenFileName)) { AuthorizeAppOAuth(dropboxServiceProvider); } OAuthToken oauthAccessToken = LoadOAuthToken(); // Login in Dropbox IDropbox dropbox = dropboxServiceProvider.GetApi(oauthAccessToken.Value, oauthAccessToken.Secret); var place = "FeedbackSystemUploads"; // Upload a file var extension = path.Split('.'); var imageName = string.Format("{0}.{1}", DateTime.Now.Ticks, extension[extension.Length - 1]); Entry uploadFileEntry = dropbox.UploadFileAsync( new FileResource(path), string.Format("/{0}/{1}", place, imageName)).Result; //Console.WriteLine("Uploaded a file: {0}", place); // Share a file DropboxLink sharedUrl = dropbox.GetShareableLinkAsync(uploadFileEntry.Path).Result; Process.Start(sharedUrl.Url); return imageName; }
public static string DropboxInit(string filePath) { DropboxServiceProvider dropboxServiceProvider = new DropboxServiceProvider(DropboxAppKey, DropboxAppSecret, AccessLevel.AppFolder); // Authenticate the application (if not authenticated) and load the OAuth token if (!File.Exists(OAuthTokenFileName)) { AuthorizeAppOAuth(dropboxServiceProvider); } OAuthToken oauthAccessToken = LoadOAuthToken(); // Login in Dropbox IDropbox dropbox = dropboxServiceProvider.GetApi(oauthAccessToken.Value, oauthAccessToken.Secret); //get the file name var fileUrl = filePath.Split('/', '\\'); int lastIndex = fileUrl.Length; string fileName = fileUrl[lastIndex - 1]; // Create new folder string newFolderName = "New_Folder_" + DateTime.Now.Ticks; Entry createFolderEntry = dropbox.CreateFolderAsync(newFolderName).Result; //add the file name to the folder newFolderName += "/" + fileName; string uploadFileEntry = DropboxUpload(filePath, dropbox, newFolderName); // Share a file return uploadFileEntry; }
private DropboxServiceProvider Initialize(string key, string secret) { DropboxServiceProvider dropboxServiceProvider = new DropboxServiceProvider(key, secret, AccessLevel.AppFolder); this.oauthAccessToken = this.LoadOAuthToken(); return dropboxServiceProvider; }
public static void Main() { DropboxServiceProvider dropboxServiceProvider = new DropboxServiceProvider(DropboxAppKey, DropboxAppSecret, AccessLevel.AppFolder); // Authenticate the application (if not authenticated) and load the OAuth token if (!File.Exists(OAuthTokenFileName)) { AuthorizeAppOAuth(dropboxServiceProvider); } OAuthToken oauthAccessToken = LoadOAuthToken(); // Login in Dropbox IDropbox dropbox = dropboxServiceProvider.GetApi(oauthAccessToken.Value, oauthAccessToken.Secret); // Display user name (from his profile) DropboxProfile profile = dropbox.GetUserProfileAsync().Result; Console.WriteLine("Hi " + profile.DisplayName + "!"); // Create new folder string newFolderName = "FootballPics"; Entry createFolderEntry = dropbox.CreateFolderAsync(newFolderName).Result; Console.WriteLine("Created folder: {0}", createFolderEntry.Path); // Upload a file Entry uploadFileEntry1 = dropbox.UploadFileAsync( new FileResource("../../Pictures/DelPiero1.jpg"), "/" + newFolderName + "/DelPiero1.jpg").Result; Console.WriteLine("Uploaded a file: {0}", uploadFileEntry1.Path); Entry uploadFileEntry2 = dropbox.UploadFileAsync( new FileResource("../../Pictures/DelPiero2.jpg"), "/" + newFolderName + "/DelPiero2.jpg").Result; Console.WriteLine("Uploaded a file: {0}", uploadFileEntry2.Path); Entry uploadFileEntry3 = dropbox.UploadFileAsync( new FileResource("../../Pictures/Raul1.jpg"), "/" + newFolderName + "/Raul1.jpg").Result; Console.WriteLine("Uploaded a file: {0}", uploadFileEntry3.Path); Entry uploadFileEntry4 = dropbox.UploadFileAsync( new FileResource("../../Pictures/Raul2.jpg"), "/" + newFolderName + "/Raul2.jpg").Result; Console.WriteLine("Uploaded a file: {0}", uploadFileEntry4.Path); // Share a file DropboxLink sharedUrl1 = dropbox.GetShareableLinkAsync(uploadFileEntry1.Path).Result; Process.Start(sharedUrl1.Url); DropboxLink sharedUrl2 = dropbox.GetShareableLinkAsync(uploadFileEntry2.Path).Result; Process.Start(sharedUrl2.Url); DropboxLink sharedUrl3 = dropbox.GetShareableLinkAsync(uploadFileEntry3.Path).Result; Process.Start(sharedUrl3.Url); DropboxLink sharedUrl4 = dropbox.GetShareableLinkAsync(uploadFileEntry4.Path).Result; Process.Start(sharedUrl4.Url); }
private IDropbox Authenticate(DropboxServiceProvider dropboxServiceProvider, DropboxProvider provider, string OAuthTokenFileName) { OAuthToken oauthAccessToken = new OAuthToken("ng8ydj1aoljno9fk", "fyqdn9sv71fn8on"); // Login in Dropbox IDropbox dropbox = dropboxServiceProvider.GetApi(oauthAccessToken.Value, oauthAccessToken.Secret); return dropbox; }
public DropboxService() { DropboxServiceProvider dropboxServiceProvider = new DropboxServiceProvider(DropboxAppKey, DropboxAppSecret, AccessLevel.AppFolder); IDropbox dropbox = dropboxServiceProvider.GetApi(appToken, appTokenSecret); DropboxProfile profile = dropbox.GetUserProfileAsync().Result; this.currentDropbox = dropbox; }
public static string AttachToPlace(string image, string address) { DropboxProvider dropboxProvider = new DropboxProvider(); DropboxServiceProvider dropboxServiceProvider = new DropboxServiceProvider(DropboxAppKey, DropboxAppSecret, AccessLevel.AppFolder); IDropbox dropbox = dropboxProvider.Authenticate(dropboxServiceProvider, dropboxProvider, OAuthTokenFileName); string resultUrl = dropboxProvider.TakeUrl(dropbox, image, address); return resultUrl; }
public string UploadFile() { DropboxServiceProvider dropboxServiceProvider = new DropboxServiceProvider(DropboxAppKey, DropboxAppSecret, AccessLevel.AppFolder); // Authenticate the application (if not authenticated) and load the OAuth token //if (!File.Exists(OAuthTokenFileName)) //{ // AuthorizeAppOAuth(dropboxServiceProvider); //} OAuthToken oauthAccessToken = new OAuthToken("fvjpvp0isfjsgyd7", "2u9zc9h1r0say01"); // Login in Dropbox IDropbox dropbox = dropboxServiceProvider.GetApi(oauthAccessToken.Value, oauthAccessToken.Secret); // Display user name (from his profile) DropboxProfile profile = dropbox.GetUserProfileAsync().Result; Console.WriteLine("Hi " + profile.DisplayName + "!"); // Create new folder string newFolderName = "RecipeImages"; Directory.CreateDirectory("../../DropboxLisa"); using (FileStream output = File.OpenWrite("../../DropboxLisa/" + DateTime.Now.Ticks + this.fileName )) { CopyStream(imageStream, output); } // Upload a file string[] files = Directory.GetFiles("../../DropboxLisa"); List<Entry> uploadedFiles = new List<Entry>(); foreach (var file in files) { Entry uploadFileEntry = dropbox.UploadFileAsync( new FileResource(Path.GetFullPath(file)), "/" + newFolderName + "/" + Path.GetFileName(file)).Result; uploadedFiles.Add(uploadFileEntry); Console.WriteLine("Uploaded a file: {0}", uploadFileEntry.Path); } //Delete the file DeleteDirectory("\\DropboxLisa"); string fileUrl = string.Empty; foreach (var file in uploadedFiles) { DropboxLink fileShareUrl = dropbox.GetMediaLinkAsync(file.Path).Result; // files fileUrl = fileShareUrl.Url; } return fileUrl; }
private DropboxServiceProvider Initialize(string key, string secret) { DropboxServiceProvider dropboxServiceProvider = new DropboxServiceProvider(key, secret, AccessLevel.AppFolder); if (!File.Exists(OAuthTokenFileName)) { this.AuthorizeAppOAuth(dropboxServiceProvider); } this.oauthAccessToken = this.LoadOAuthToken(); return dropboxServiceProvider; }
private static IDropbox CreatingFile() { DropboxServiceProvider dropboxServiceProvider = new DropboxServiceProvider(DropboxAppKey, DropboxAppSecret, AccessLevel.AppFolder); // Authenticate the application (if not authenticated) and load the OAuth token OAuthToken oauthAccessToken = new OAuthToken("jxfhttvyu86uiy7r", "in5chjjhszsdiem"); // Login in Dropbox IDropbox dropbox = dropboxServiceProvider.GetApi(oauthAccessToken.Value, oauthAccessToken.Secret); return dropbox; }
private static void Main() { DropboxServiceProvider dropboxServiceProvider = new DropboxServiceProvider(AppKey, AppSecret, AccessLevel.AppFolder); if (!File.Exists(OAuthTokenFileName)) { AuthorizeAppViaOAuth(dropboxServiceProvider); } OAuthToken oAuthAccessToken = LoadOAuthToken(); IDropbox dropbox = dropboxServiceProvider.GetApi(oAuthAccessToken.Value, oAuthAccessToken.Secret); Entry folderEntry = new Entry(); string folderName = string.Empty; while (true) { try { Console.WriteLine("Folder name:"); folderName = Console.ReadLine(); folderEntry = dropbox.CreateFolderAsync(folderName).Result; Console.WriteLine("Folder '{0}' created.", folderEntry.Path); break; } catch (Exception ex) { Console.WriteLine(ex.InnerException.Message); } } Console.WriteLine("Number of files to upload:"); int filesCount = int.Parse(Console.ReadLine()); for (int i = 0; i < filesCount; i++) { Console.WriteLine("File path:"); string filePath = Console.ReadLine().Trim(); Entry uploadFileEntry = dropbox.UploadFileAsync( new FileResource(filePath), "/" + folderName + "/" + Path.GetFileName(filePath)).Result; Console.WriteLine("File '{0}' uploaded.", uploadFileEntry.Path); } DropboxLink sharedUrl = dropbox.GetShareableLinkAsync(folderEntry.Path).Result; Console.WriteLine(sharedUrl.Url); Process.Start(sharedUrl.Url); }
static void Main() { DropboxServiceProvider dropboxServiceProvider = new DropboxServiceProvider(DropboxAppKey, DropboxAppSecret, AccessLevel.AppFolder); // Authenticate the application (if not authenticated) and load the OAuth token if (!File.Exists(OAuthTokenFileName)) { AuthorizeAppOAuth(dropboxServiceProvider); } OAuthToken oauthAccessToken = LoadOAuthToken(); // Login in Dropbox IDropbox dropbox = dropboxServiceProvider.GetApi(oauthAccessToken.Value, oauthAccessToken.Secret); // Display user name (from his profile) DropboxProfile profile = dropbox.GetUserProfileAsync().Result; Console.WriteLine("Hi " + profile.DisplayName + "!"); // Specify the path to the folder on your disk Console.WriteLine("Please enter the full path to the photo album folder on the disk"); string folderPath = Console.ReadLine(); var filePaths = Directory.GetFiles(folderPath); var fileNames = new List<string>(); foreach (var path in filePaths) { fileNames.Add(path.Substring(path.LastIndexOf('\\') + 1)); } // Create new folder string newFolderName = "PhotoGallery_" + DateTime.Now.Ticks; Entry createFolderEntry = dropbox.CreateFolderAsync(newFolderName).Result; Console.WriteLine("Created folder: {0}", createFolderEntry.Path); // Upload a file var fileCounter = 0; foreach (var path in filePaths) { Entry uploadFileEntry = dropbox.UploadFileAsync( new FileResource(path), "/" + newFolderName + "/" + fileNames[fileCounter]).Result; Console.WriteLine("Uploaded a file: {0}", uploadFileEntry.Path); fileCounter++; } // Share a file DropboxLink sharedUrl = dropbox.GetShareableLinkAsync(createFolderEntry.Path).Result; Process.Start(sharedUrl.Url); }
static void Main() { DropboxServiceProvider dropboxServiceProvider = new DropboxServiceProvider(DropboxAppKey, DropboxAppSecret, AccessLevel.AppFolder); if (!File.Exists(OAuthTokenFileName)) { AuthorizeAppOAuth(dropboxServiceProvider); } OAuthToken oauthAccessToken = LoadOAuthToken(); IDropbox dropbox = dropboxServiceProvider.GetApi(oauthAccessToken.Value, oauthAccessToken.Secret); Entry createFolderEntry = new Entry(); string newFolderName = string.Empty; while (true) { try { Console.WriteLine("Please enter name of photo album folder"); newFolderName = Console.ReadLine(); createFolderEntry = dropbox.CreateFolderAsync(newFolderName).Result; Console.WriteLine("Created folder: {0}", createFolderEntry.Path); break; } catch (Exception ex) { Console.WriteLine("This folder already exists; " + ex.InnerException.Message); } } Console.WriteLine("Eneter number of files to upload"); int count = int.Parse(Console.ReadLine()); for (int i = 0; i < count; i++) { Console.WriteLine("Enter file path"); string filePath = Console.ReadLine(); Entry uploadFileEntry = dropbox.UploadFileAsync( new FileResource(filePath), "/" + newFolderName + "/" + Path.GetFileName(filePath).Trim()).Result; Console.WriteLine("Uploaded a file: {0}", uploadFileEntry.Path); } DropboxLink sharedUrl = dropbox.GetShareableLinkAsync(createFolderEntry.Path).Result; Console.WriteLine(sharedUrl.Url); Process.Start(sharedUrl.Url); }
private void AuthorizeAppOAuth(DropboxServiceProvider dropboxServiceProvider) { OAuthToken oauthToken = dropboxServiceProvider.OAuthOperations.FetchRequestTokenAsync(null, null).Result; OAuth1Parameters parameters = new OAuth1Parameters(); string authenticateUrl = dropboxServiceProvider.OAuthOperations.BuildAuthorizeUrl(oauthToken.Value, parameters); Process.Start(authenticateUrl); AuthorizedRequestToken requestToken = new AuthorizedRequestToken(oauthToken, null); OAuthToken oauthAccessToken = dropboxServiceProvider.OAuthOperations.ExchangeForAccessTokenAsync(requestToken, null).Result; string[] oauthData = new string[] { oauthAccessToken.Value, oauthAccessToken.Secret }; File.WriteAllLines(OAuthTokenFileName, oauthData); }
static void Main() { DropboxServiceProvider dropboxServiceProvider = new DropboxServiceProvider(DropboxAppKey, DropboxAppSecret, AccessLevel.AppFolder); // Authenticate the application (if not authenticated) and load the OAuth token if (!File.Exists(OAuthTokenFileName)) { AuthorizeAppOAuth(dropboxServiceProvider); } OAuthToken oauthAccessToken = LoadOAuthToken(); // Login in Dropbox IDropbox dropbox = dropboxServiceProvider.GetApi(oauthAccessToken.Value, oauthAccessToken.Secret); // Display user name (from his profile) DropboxProfile profile = dropbox.GetUserProfileAsync().Result; Console.WriteLine("Hi " + profile.DisplayName + "!"); // Create new folder string newFolderName = "BatmanAlbum"; DeltaPage deltaPage = dropbox.DeltaAsync(null).Result; var isFolderExist = deltaPage.Entries.Any(x => x.Path == ("/" + newFolderName).ToLower()); if (!isFolderExist) { Entry createFolderEntry = dropbox.CreateFolderAsync(newFolderName).Result; Console.WriteLine("Created folder: {0}", createFolderEntry.Path); } var folderPath = @"../../Pics"; DirectoryInfo picturesFolder = new DirectoryInfo(folderPath); foreach (var fileName in picturesFolder.GetFiles("*.jpg")) { // Upload a file Entry uploadFileEntry = dropbox.UploadFileAsync( new FileResource(fileName.FullName), "/" + newFolderName + "/" + fileName.Name).Result; Console.WriteLine("Uploaded a file: {0}", uploadFileEntry.Path); // Share a file DropboxLink sharedUrl = dropbox.GetShareableLinkAsync(uploadFileEntry.Path).Result; Process.Start(sharedUrl.Url); } }
static void Main() { // Start the project - Ctrl + F5 // You will be asked to sign in your DropBox account or to register if you do not have an account yet // Then the API will create a folder in your dropbox and will upload 2 photos in this folder // (The photos are in the VS project folder) // Then you may share the photos through the Dropbox sharing functionality DropboxServiceProvider dropboxServiceProvider = new DropboxServiceProvider(DropboxAppKey, DropboxAppSecret, AccessLevel.AppFolder); // Authenticate the application (if not authenticated) and load the OAuth token if (!File.Exists(OAuthTokenFileName)) { AuthorizeAppOAuth(dropboxServiceProvider); } OAuthToken oauthAccessToken = LoadOAuthToken(); // Login in Dropbox IDropbox dropbox = dropboxServiceProvider.GetApi(oauthAccessToken.Value, oauthAccessToken.Secret); // Display user name (from his profile) DropboxProfile profile = dropbox.GetUserProfileAsync().Result; Console.WriteLine("Hi " + profile.DisplayName + "!"); // Create new folder string newFolderName = "PhotoAlbum_" + DateTime.Now.Ticks; Entry createFolderEntry = dropbox.CreateFolderAsync(newFolderName).Result; Console.WriteLine("Created folder: {0}", createFolderEntry.Path); // Upload a file Entry uploadFileEntry = dropbox.UploadFileAsync( new FileResource("../../Agassi_Federer.jpg"), "/" + newFolderName + "/Agassi_Federer.jpg").Result; Console.WriteLine("Uploaded a file: {0}", uploadFileEntry.Path); Entry uploadFileEntry2 = dropbox.UploadFileAsync( new FileResource("../../Nadal.jpg"), "/" + newFolderName + "/Nadal.jpg").Result; Console.WriteLine("Uploaded a file: {0}", uploadFileEntry.Path); // Share a file DropboxLink sharedUrl = dropbox.GetShareableLinkAsync(createFolderEntry.Path).Result; Process.Start(sharedUrl.Url); Console.WriteLine("Link for sharing the album photos: {0}", sharedUrl.Url); Console.WriteLine("Link expires on: {0}", sharedUrl.ExpireDate); }
public IDropbox ConnectToDropboxAPI() { DropboxServiceProvider dropboxServiceProvider = new DropboxServiceProvider(DropboxAppKey, DropboxAppSecret, AccessLevel.AppFolder); // Authenticate the application (if not authenticated) and load the OAuth token if (!File.Exists(OAuthTokenFileName)) { AuthorizeAppOAuth(dropboxServiceProvider); } OAuthToken oauthAccessToken = LoadOAuthToken(); // Login in Dropbox dropbox = dropboxServiceProvider.GetApi(oauthAccessToken.Value, oauthAccessToken.Secret); return dropbox; }
//Save the newly became authorization strings in a file to reuse them later (not authorize again every time) private void AuthorizeAppOAuth(DropboxServiceProvider dropboxServiceProvider) { // Authorization without callback url OAuthToken oauthToken = dropboxServiceProvider.OAuthOperations.FetchRequestTokenAsync(null, null).Result; OAuth1Parameters parameters = new OAuth1Parameters(); string authenticateUrl = dropboxServiceProvider.OAuthOperations.BuildAuthorizeUrl( oauthToken.Value, parameters); Process.Start(authenticateUrl); AuthorizedRequestToken requestToken = new AuthorizedRequestToken(oauthToken, null); OAuthToken oauthAccessToken = dropboxServiceProvider.OAuthOperations.ExchangeForAccessTokenAsync(requestToken, null).Result; string[] oauthData = new string[] { oauthAccessToken.Value, oauthAccessToken.Secret }; File.WriteAllLines(OAuthTokenFileName, oauthData); }
static void Main() { if (DropboxAppKey.IndexOf('*') > 0 || DropboxAppSecret.IndexOf('*') > 0) { Console.WriteLine("Please setup your Dropbox Application Key and Secret into the code"); return; } DropboxServiceProvider dropboxServiceProvider = new DropboxServiceProvider(DropboxAppKey, DropboxAppSecret, AccessLevel.AppFolder); // Authenticate the application (if not authenticated) and load the OAuth token if (!File.Exists(OAuthTokenFileName)) { AuthorizeAppOAuth(dropboxServiceProvider); } OAuthToken oauthAccessToken = LoadOAuthToken(); // Login in Dropbox IDropbox dropbox = dropboxServiceProvider.GetApi(oauthAccessToken.Value, oauthAccessToken.Secret); // Create new folder string newFolderName = "Pictures_Folder_" + DateTime.Now.Ticks; Entry createFolderEntry = dropbox.CreateFolderAsync(newFolderName).Result; Console.WriteLine("Created folder: {0}", createFolderEntry.Path); // Upload pictures (get their path and name from text file) using (var sr = new StreamReader("../../PicturesList.txt")) { while (!sr.EndOfStream) { string filename = sr.ReadLine().Trim(); if (filename.Length > 0) { Entry uploadFileEntry = dropbox.UploadFileAsync( new FileResource("../../" + filename), "/" + newFolderName + "/" + filename).Result; Console.WriteLine("Uploaded a file: {0}", uploadFileEntry.Path); } } } // Share a file DropboxLink sharedUrl = dropbox.GetShareableLinkAsync(createFolderEntry.Path).Result; Process.Start(sharedUrl.Url); }
public IDropbox ConnectToDropboxAPI() { DropboxServiceProvider dropboxServiceProvider = new DropboxServiceProvider(DropboxAppKey, DropboxAppSecret, AccessLevel.AppFolder); // Authenticate the application (if not authenticated) and load the OAuth token if (!File.Exists(OAuthTokenFileName)) { AuthorizeAppOAuth(dropboxServiceProvider); } OAuthToken oauthAccessToken = LoadOAuthToken(); // Login in Dropbox dropbox = dropboxServiceProvider.GetApi(oauthAccessToken.Value, oauthAccessToken.Secret); return(dropbox); }
public void PostFile(FileModel file) { DropboxServiceProvider dropboxServiceProvider = new DropboxServiceProvider(DropboxAppKey, DropboxAppSecret, AccessLevel.AppFolder); OAuthToken oauthAccessToken = new OAuthToken("9gyo6l0xq3l7kdd0", "ly7ayinrqbocfy8"); // Login in Dropbox IDropbox dropbox = dropboxServiceProvider.GetApi(oauthAccessToken.Value, oauthAccessToken.Secret); // Create new folder string newFolderName = "New_Folder_" + DateTime.Now.Ticks; Entry createFolderEntry = dropbox.CreateFolderAsync(newFolderName).Result; // Upload a file IResource fileResource = new FileResource(file.Path + "/" + file.Name); Entry uploadFileEntry = dropbox.UploadFileAsync(fileResource, "/" + newFolderName + "/" + file.Name).Result; // Share a file DropboxLink sharedUrl = dropbox.GetMediaLinkAsync(uploadFileEntry.Path).Result; // Update database Message newMessage = new Message() { Content = sharedUrl.Url.ToString(), SendTime = DateTime.Now, User = (from users in db.Users where users.UserId == file.UserId select users).FirstOrDefault(), UserId = file.UserId, RecieverId = file.RecieverId }; if (file.IsProfilePic) { User currentUser = (from users in db.Users where users.UserId == file.UserId select users).FirstOrDefault(); currentUser.ProfilePicUrl = sharedUrl.Url.ToString(); } db.Messages.Add(newMessage); db.SaveChanges(); }
static void Main() { DropboxServiceProvider dropboxServiceProvider = new DropboxServiceProvider(DropboxAppKey, DropboxAppSecret, AccessLevel.AppFolder); // Authenticate the application (if not authenticated) and load the OAuth token if (!File.Exists(OAuthTokenFileName)) { AuthorizeAppOAuth(dropboxServiceProvider); } OAuthToken oauthAccessToken = LoadOAuthToken(); // Login in Dropbox IDropbox dropbox = dropboxServiceProvider.GetApi(oauthAccessToken.Value, oauthAccessToken.Secret); // Display user name (from his profile) DropboxProfile profile = dropbox.GetUserProfileAsync().Result; Console.WriteLine("Hi " + profile.DisplayName + "!"); // Create new folder string newFolderName = "PhotoAlbum_" + DateTime.Now.Ticks; Entry createFolderEntry = dropbox.CreateFolderAsync(newFolderName).Result; Console.WriteLine("Created folder: {0}", createFolderEntry.Path); // Upload a file Entry uploadFileEntry = dropbox.UploadFileAsync( new FileResource("../../girl1.jpg"), "/" + newFolderName + "/girl1.jpg").Result; Console.WriteLine("Uploaded a file: {0}", uploadFileEntry.Path); Entry uploadFileEntry2 = dropbox.UploadFileAsync( new FileResource("../../girl2.jpg"), "/" + newFolderName + "/girl12.jpg").Result; Console.WriteLine("Uploaded a file: {0}", uploadFileEntry.Path); // Share a file DropboxLink sharedUrl = dropbox.GetShareableLinkAsync(createFolderEntry.Path).Result; Process.Start(sharedUrl.Url); }
private static void Main() { var dropboxServiceProvider = new DropboxServiceProvider(DropboxAppKey, DropboxAppSecret, AccessLevel.AppFolder); // Authenticate the application (if not authenticated) and load the OAuth token if (!File.Exists(OAuthTokenFileName)) { AuthorizeAppOAuth(dropboxServiceProvider); } OAuthToken oauthAccessToken = LoadOAuthToken(); // Login in Dropbox IDropbox dropbox = dropboxServiceProvider.GetApi(oauthAccessToken.Value, oauthAccessToken.Secret); // Display user name (from his profile) DropboxProfile profile = dropbox.GetUserProfileAsync().Result; Console.WriteLine("Hi " + profile.DisplayName + "!"); // Create new folder string newFolderName = "Images_" + DateTime.Now.Ticks; Entry createFolderEntry = dropbox.CreateFolderAsync(newFolderName).Result; Console.WriteLine("Created folder: {0}", createFolderEntry.Path); foreach (var file in Directory.GetFiles(ImagesFolder)) { var resource = new FileResource(file); var fileName = resource.File.Name; // Upload Image var upload = dropbox.UploadFileAsync(resource, fileName, true, null, CancellationToken.None).Result; // Print path Console.WriteLine("Uploaded a file: {0}", upload.Path); // Share Image var sharedUrl = dropbox.GetShareableLinkAsync(upload.Path).Result; Process.Start(sharedUrl.Url); } }
public override bool Ejecutar() { string consumerKey = "dbhvzaf6ugr4k6q"; string consumerSecret = "q35bdvwgrut9bq4"; string accessToken = (usuario as Clases.Usuario).AccesToken; string accessTokenSecret = (usuario as Clases.Usuario).AccesSecret; bool estado = false; try { DropboxServiceProvider serviceProvider = new DropboxServiceProvider(consumerKey, consumerSecret, AccessLevel.AppFolder); IDropbox dropboxApi = serviceProvider.GetApi(accessToken, accessTokenSecret); dropboxApi.DeleteAsync("/RapidNote/" + nombre); estado = true; return(estado); } catch (Exception ex) { return(estado); } }
public static void Main() { DropboxServiceProvider dropboxServiceProvider = new DropboxServiceProvider(DropboxAppKey, DropboxAppSecret, AccessLevel.AppFolder); if (!File.Exists(OAuthTokenFileName)) { AuthorizeAppOAuth(dropboxServiceProvider); } OAuthToken oauthAccessToken = LoadOAuthToken(); var api = dropboxServiceProvider.GetApi(oauthAccessToken.Value, oauthAccessToken.Secret); Entry uploadFileEntry = api.UploadFileAsync( new FileResource("1.jpg"),"1.jpg").Result; Console.WriteLine("Uploaded a file: {0}", uploadFileEntry.Path); uploadFileEntry = api.UploadFileAsync( new FileResource("2.jpg"), "2.jpg").Result; Console.WriteLine("Uploaded a file: {0}", uploadFileEntry.Path); }
public static void Main() { DropboxServiceProvider dropboxServiceProvider = new DropboxServiceProvider(DropboxAppKey, DropboxAppSecret, AccessLevel.AppFolder); if (!File.Exists(OAuthTokenFileName)) { AuthorizeAppOAuth(dropboxServiceProvider); } OAuthToken oauthAccessToken = LoadOAuthToken(); var api = dropboxServiceProvider.GetApi(oauthAccessToken.Value, oauthAccessToken.Secret); Entry uploadFileEntry = api.UploadFileAsync( new FileResource("1.jpg"), "1.jpg").Result; Console.WriteLine("Uploaded a file: {0}", uploadFileEntry.Path); uploadFileEntry = api.UploadFileAsync( new FileResource("2.jpg"), "2.jpg").Result; Console.WriteLine("Uploaded a file: {0}", uploadFileEntry.Path); }
public void AuthorizeAppOAuth(DropboxServiceProvider dropboxServiceProvider, string OAuthTokenFileName) { OAuthToken oauthToken = dropboxServiceProvider.OAuthOperations.FetchRequestToken(null, null); OAuth1Parameters parameters = new OAuth1Parameters(); string authenticateUrl = dropboxServiceProvider.OAuthOperations.BuildAuthorizeUrl( oauthToken.Value, parameters); //Process.Start(authenticateUrl); AuthorizedRequestToken requestToken = new AuthorizedRequestToken(oauthToken, null); OAuthToken oauthAccessToken = dropboxServiceProvider.OAuthOperations.ExchangeForAccessToken(requestToken, null); string[] oauthData = new string[] { oauthAccessToken.Value, oauthAccessToken.Secret }; File.WriteAllLines(OAuthTokenFileName, oauthData); }
public override bool Ejecutar() { try { usuario = FabricaEntidad.CrearUsuario(); DropboxServiceProvider dropbocServiceProvider = new DropboxServiceProvider(DropboxAppKey, DropboxAppSecret, AccessLevel.Full); oauthToken = Comandodrop.Token; AuthorizedRequestToken requestToken = new AuthorizedRequestToken(oauthToken, null); OAuthToken oauthAccessToken = dropbocServiceProvider.OAuthOperations.ExchangeForAccessTokenAsync(requestToken, null).Result; (usuario as Clases.Usuario).AccesToken = oauthAccessToken.Value; (usuario as Clases.Usuario).AccesSecret = oauthAccessToken.Secret; IDAOUsuario accion = FabricaDAO.CrearFabricaDeDAO(1).CrearDAOUsuario(); accion.InsertarToken(correo, usuario); if (log.IsInfoEnabled) { log.Info(correo.ToString()); } estado = true; return(estado); } catch (AggregateException ae) { ae.Handle(ex => { if (ex is DropboxApiException) { Console.WriteLine(ex.Message); if (log.IsErrorEnabled) { log.Error(ex.Message, ex); } return(estado = false); } return(estado = false); }); return(estado); } }
public void UploadFile() { var filePath = string.Empty; var albumId = Request.Headers.FirstOrDefault(h => h.Key == "X-Album-Id").Value.First(); if (HttpContext.Current.Request.Files.AllKeys.Any()) { var httpPostedFile = HttpContext.Current.Request.Files["UploadedImage"]; if (httpPostedFile != null) { var fileSavePath = Path.Combine(HttpContext.Current.Server.MapPath("~/"), httpPostedFile.FileName); filePath = fileSavePath; this.name = httpPostedFile.FileName; httpPostedFile.SaveAs(fileSavePath); } } DropboxServiceProvider dropboxServiceProvider = new DropboxServiceProvider(DropboxAppKey, DropboxAppSecret, AccessLevel.Full); IDropbox dropbox = dropboxServiceProvider.GetApi(DropboxReturnedAppKey, DropboxReturnedAppSecret); Entry uploadFileEntry = dropbox.UploadFileAsync(new FileResource(string.Format(filePath)), string.Format(DataFirstPath, this.name)).Result; var link = dropbox.GetMediaLinkAsync(string.Format(DataFirstPath, this.name)); var urlForDb = link.Result.Url; int albumIdReal = int.Parse(albumId); var image = new Image() { AlbumId = albumIdReal, OriginalFileName = this.name, UrlPath = urlForDb }; this.data.Images.Add(image); this.data.SaveChanges(); }
public override bool Ejecutar() { string consumerKey = "dbhvzaf6ugr4k6q"; string consumerSecret = "q35bdvwgrut9bq4"; string accessToken = (usuario as Clases.Usuario).AccesToken; string accessTokenSecret = (usuario as Clases.Usuario).AccesSecret; bool estado = false; try { DropboxServiceProvider serviceProvider = new DropboxServiceProvider(consumerKey, consumerSecret, AccessLevel.AppFolder); IDropbox dropboxApi = serviceProvider.GetApi(accessToken, accessTokenSecret); var file = dropboxApi.DownloadFileAsync("/RapidNote/" + nombre).Result; System.IO.FileStream _FileStream = new System.IO.FileStream(@"C:\prueba\" + nombre, System.IO.FileMode.Create, System.IO.FileAccess.Write); _FileStream.Write(file.Content, 0, file.Content.Length); _FileStream.Close(); estado = true; return(estado); } catch (Exception ex) { return(estado); } }
public string UploadFileToDropBox(string filePath, string fileName) { DropboxServiceProvider dropboxServiceProvider = new DropboxServiceProvider(DropboxAppKey, DropboxAppSecret, AccessLevel.AppFolder); // Authenticate the application (if not authenticated) and load the OAuth token // TODO - throw exception if auth file is not found //if (!File.Exists(OAuthTokenFileName)) //{ // AuthorizeAppOAuth(dropboxServiceProvider); //} OAuthToken oauthAccessToken = LoadOAuthToken(); // Login in Dropbox IDropbox dropbox = dropboxServiceProvider.GetApi(oauthAccessToken.Value, oauthAccessToken.Secret); // Display user name (from his profile) //DropboxProfile profile = dropbox.GetUserProfileAsync().Result; //Console.WriteLine("Hi " + profile.DisplayName + "!"); // Create new folder string newFolderName = DateTime.Now.Ticks.ToString(); //Entry createFolderEntry = dropbox.CreateFolderAsync(newFolderName).Result; Entry createFolderEntry = dropbox.CreateFolder(newFolderName); // Upload a file Entry uploadFileEntry = dropbox.UploadFile( new FileResource(filePath), "/" + newFolderName + "/" + fileName); // Share a file //DropboxLink sharedUrl = dropbox.GetShareableLinkAsync(uploadFileEntry.Path).Result; string sharedUrl = dropbox.GetMediaLink(uploadFileEntry.Path).Url.ToString(); // var ret = sharedUrl.Url.ToString(); return(sharedUrl); }
private void AuthorizeAppOAuth(DropboxServiceProvider dropboxServiceProvider) { OAuthToken oauthToken = dropboxServiceProvider .OAuthOperations .FetchRequestTokenAsync(null, null).Result; OAuth1Parameters parameters = new OAuth1Parameters(); string authenticateUrl = dropboxServiceProvider .OAuthOperations .BuildAuthorizeUrl(oauthToken.Value, parameters); Process.Start(authenticateUrl); Console.Write("Press [Enter] when authorization attempt has succeeded."); Console.ReadLine(); AuthorizedRequestToken requestToken = new AuthorizedRequestToken(oauthToken, null); OAuthToken oauthAccessToken = dropboxServiceProvider .OAuthOperations .ExchangeForAccessTokenAsync(requestToken, null).Result; string[] oauthData = new string[] { oauthAccessToken.Value, oauthAccessToken.Secret }; File.WriteAllLines(OAuthTokenFileName, oauthData); }
public DropboxHelper() { this.serviceProvider = new DropboxServiceProvider(Constants.DropboxAppKey, Constants.DropboxAppSecret, AccessLevel.AppFolder); this.dropbox = serviceProvider.GetApi(Constants.DropboxAppToken, Constants.DropboxAppTokenSecret); }
private void Worker() { Interface.Oxide.LogInfo("[DropBox] Initialized"); _Settings = _DataFileSystem.ReadObject <Settings>(Path.Combine(_ConfigDirectory, "DropBox")); if (_Settings.FileList == null) { _Settings = new Settings(); _Settings.BackupOxideConfig = true; _Settings.BackupOxideData = true; _Settings.BackupOxideLang = true; _Settings.BackupOxideLogs = true; _Settings.BackupOxidePlugins = true; _Settings.FileList = new List <string>(); _Settings.UserToken = ""; _Settings.UserSecret = ""; _Settings.BackupName = "Oxide DropBox Extension"; _Settings.BackupInterval = 3600; _Settings.DropboxApi = new Dictionary <string, string>(); _Settings.DropboxApi.Add("DropboxAppKey", ""); _Settings.DropboxApi.Add("DropboxAppSecret", ""); _DataFileSystem.WriteObject <Settings>(Path.Combine(_ConfigDirectory, "DropBox"), _Settings); } if (_Settings.BackupInterval < 3600) { Interface.Oxide.LogError("[DropBox] You can't set backup interval lower than 1 hour."); _Settings.BackupInterval = 3600; _DataFileSystem.WriteObject <Settings>(Path.Combine(_ConfigDirectory, "DropBox"), _Settings); } if ((string.IsNullOrEmpty(_Settings.DropboxApi["DropboxAppKey"])) || (string.IsNullOrEmpty(_Settings.DropboxApi["DropboxAppSecret"]))) { _running = false; Interface.Oxide.LogWarning("[DropBox] To able to use DropBox Extension you need to set DropboxAppKey and DropboxAppSecret in config file."); } if (_running) { DropboxServiceProvider dropboxServiceProvider = new DropboxServiceProvider(_Settings.DropboxApi["DropboxAppKey"], _Settings.DropboxApi["DropboxAppSecret"], AccessLevel.Full); OAuthToken oauthAccessToken = null; bool Authorized = false; IDropbox dropbox = null; do { if ((_running) && (string.IsNullOrEmpty(_Settings.UserToken) || string.IsNullOrEmpty(_Settings.UserSecret))) { Interface.Oxide.LogInfo("[DropBox] Getting request token..."); OAuthToken oauthToken = dropboxServiceProvider.OAuthOperations.FetchRequestToken(null, null); Interface.Oxide.LogInfo("[DropBox] Done"); OAuth1Parameters parameters = new OAuth1Parameters(); string authenticateUrl = dropboxServiceProvider.OAuthOperations.BuildAuthenticateUrl(oauthToken.Value, parameters); Interface.Oxide.LogInfo("[DropBox] Redirect user for authorization"); Interface.Oxide.LogInfo("[DropBox] {0}", authenticateUrl); while ((_running) && (Authorized == false)) { try { AuthorizedRequestToken requestToken = new AuthorizedRequestToken(oauthToken, null); oauthAccessToken = dropboxServiceProvider.OAuthOperations.ExchangeForAccessToken(requestToken, null); Authorized = true; _Settings.UserToken = oauthAccessToken.Value; _Settings.UserSecret = oauthAccessToken.Secret; _DataFileSystem.WriteObject <Settings>(Path.Combine(_ConfigDirectory, "DropBox"), _Settings); } catch { Thread.Sleep(5000); } } } else if (_running) { oauthAccessToken = new OAuthToken(_Settings.UserToken, _Settings.UserSecret); } if (_running) { try { Interface.Oxide.LogInfo("[DropBox] Authorizing"); dropbox = dropboxServiceProvider.GetApi(oauthAccessToken.Value, oauthAccessToken.Secret); Interface.Oxide.LogInfo("[DropBox] Authorization Succeed"); Authorized = true; } catch { Interface.Oxide.LogWarning("[DropBox] Authorization Failed"); _Settings.UserToken = ""; _Settings.UserSecret = ""; _DataFileSystem.WriteObject <Settings>(Path.Combine(_ConfigDirectory, "DropBox"), _Settings); Authorized = false; } } } while ((_running) && (Authorized == false)); if ((_running) && (dropbox != null) && (Authorized == true)) { DropboxProfile profile = dropbox.GetUserProfile(); Interface.Oxide.LogInfo("[DropBox] Current Dropbox User : {0}({1})", profile.DisplayName, profile.Email); DateTime NextUpdate = DateTime.Now.AddSeconds(60); Interface.Oxide.LogInfo("[DropBox] First Backup : {0}", NextUpdate.ToString()); while (_running) { if (DateTime.Now < NextUpdate) { Thread.Sleep(1000); } else { string BackUpRoot = Path.Combine(Interface.Oxide.RootDirectory, "OxideExtBackup"); string OxideBackUpRoot = Path.Combine(BackUpRoot, "Oxide"); string FileBackUpRoot = Path.Combine(BackUpRoot, "Files"); Directory.CreateDirectory(BackUpRoot); DirectoryInfo OxideExtBackup = new DirectoryInfo(BackUpRoot); foreach (FileInfo file in OxideExtBackup.GetFiles()) { file.Delete(); } foreach (DirectoryInfo subDirectory in OxideExtBackup.GetDirectories()) { subDirectory.Delete(true); } Directory.CreateDirectory(OxideBackUpRoot); Directory.CreateDirectory(FileBackUpRoot); if (_Settings.BackupOxideConfig) { DirectoryCopy(Interface.Oxide.ConfigDirectory, Path.Combine(OxideBackUpRoot, "config"), true); } if (_Settings.BackupOxideData) { DirectoryCopy(Interface.Oxide.DataDirectory, Path.Combine(OxideBackUpRoot, "data"), true); } if (_Settings.BackupOxideLang) { DirectoryCopy(Interface.Oxide.LangDirectory, Path.Combine(OxideBackUpRoot, "lang"), true); } if (_Settings.BackupOxideLogs) { DirectoryCopy(Interface.Oxide.LogDirectory, Path.Combine(OxideBackUpRoot, "logs"), true); } if (_Settings.BackupOxidePlugins) { DirectoryCopy(Interface.Oxide.PluginDirectory, Path.Combine(OxideBackUpRoot, "plugins"), true); } foreach (string Current in _Settings.FileList) { if (!string.IsNullOrEmpty(Current)) { string CurrentPath = Path.GetFullPath(Path.Combine(Interface.Oxide.RootDirectory, Current)); if (!CurrentPath.StartsWith(Interface.Oxide.RootDirectory, StringComparison.Ordinal)) { Interface.Oxide.LogError("[DropBox] You may only access game releated directories..."); } else if ((File.GetAttributes(CurrentPath) & FileAttributes.Directory) == FileAttributes.Directory) { if (CurrentPath != Interface.Oxide.RootDirectory) { DirectoryCopy(CurrentPath, Path.Combine(FileBackUpRoot, new DirectoryInfo(CurrentPath).Name), true); } } else { File.Copy(CurrentPath, Path.Combine(FileBackUpRoot, new FileInfo(CurrentPath).Name)); } } } string FileName = string.Format("{0}.{1}.{2}.{3}.{4}.{5}.zip", DateTime.UtcNow.Year, DateTime.UtcNow.Month, DateTime.UtcNow.Day, DateTime.UtcNow.Hour, DateTime.UtcNow.Minute, DateTime.UtcNow.Second); FileStream fsOut = File.Create(Path.Combine(Interface.Oxide.RootDirectory, FileName)); ZipOutputStream zipStream = new ZipOutputStream(fsOut); zipStream.SetLevel(3); string folderName = Path.Combine(Interface.Oxide.RootDirectory, "OxideExtBackup"); int folderOffset = folderName.Length + (folderName.EndsWith("\\") ? 0 : 1); CompressFolder(folderName, zipStream, folderOffset); zipStream.IsStreamOwner = true; zipStream.Close(); Interface.Oxide.LogInfo("[DropBox] Uploading..."); Entry uploadFileEntry = dropbox.UploadFile(new FileResource(Path.Combine(Interface.Oxide.RootDirectory, FileName)), string.Format("/{0}/{1}", _Settings.BackupName, FileName), true, null); Directory.Delete(folderName, true); File.Delete(Path.Combine(Interface.Oxide.RootDirectory, FileName)); NextUpdate = NextUpdate.AddSeconds(_Settings.BackupInterval); Interface.Oxide.LogInfo("[DropBox] Uploading Complated.Next Backup : {0}", NextUpdate.ToString()); } } } } }
static void Main(string[] args) { try { DropboxServiceProvider dropboxServiceProvider = new DropboxServiceProvider(DropboxAppKey, DropboxAppSecret, AccessLevel.Full); #if NET_4_0 /* OAuth 1.0 'dance' */ // Authorization without callback url Console.Write("Getting request token..."); OAuthToken oauthToken = dropboxServiceProvider.OAuthOperations.FetchRequestTokenAsync(null, null).Result; Console.WriteLine("Done"); OAuth1Parameters parameters = new OAuth1Parameters(); //parameters.Add("locale", CultureInfo.CurrentUICulture.IetfLanguageTag); // for a localized version of the authorization website string authenticateUrl = dropboxServiceProvider.OAuthOperations.BuildAuthorizeUrl(oauthToken.Value, parameters); Console.WriteLine("Redirect user for authorization"); Process.Start(authenticateUrl); Console.Write("Press any key when authorization attempt has succeeded"); Console.ReadLine(); Console.Write("Getting access token..."); AuthorizedRequestToken requestToken = new AuthorizedRequestToken(oauthToken, null); OAuthToken oauthAccessToken = dropboxServiceProvider.OAuthOperations.ExchangeForAccessTokenAsync(requestToken, null).Result; Console.WriteLine("Done"); /* API */ IDropbox dropbox = dropboxServiceProvider.GetApi(oauthAccessToken.Value, oauthAccessToken.Secret); //dropbox.Locale = CultureInfo.CurrentUICulture.IetfLanguageTag; DropboxProfile profile = dropbox.GetUserProfileAsync().Result; Console.WriteLine("Hi " + profile.DisplayName + "!"); // Use step by step debugging, or not /* * Entry createFolderEntry = dropbox.CreateFolderAsync("Spring Social").Result; * Entry uploadFileEntry = dropbox.UploadFileAsync( * new AssemblyResource("assembly://Spring.ConsoleQuickStart/Spring.ConsoleQuickStart/File.txt"), * "/Spring Social/File.txt", true, null, CancellationToken.None).Result; * Entry copyEntry = dropbox.CopyAsync("Spring Social/File.txt", "Spring Social/File_copy.txt").Result; * Entry deleteEntry = dropbox.DeleteAsync("Spring Social/File.txt").Result; * Entry moveEntry = dropbox.MoveAsync("Spring Social/File_copy.txt", "Spring Social/File.txt").Result; * dropbox.DownloadFileAsync("Spring Social/File.txt") * .ContinueWith(task => * { * Console.WriteLine("File '{0}' downloaded ({1})", task.Result.Metadata.Path, task.Result.Metadata.Size); * // Save file to "C:\Spring Social.txt" * using (FileStream fileStream = new FileStream(@"C:\Spring Social.txt", FileMode.Create)) * { * fileStream.Write(task.Result.Content, 0, task.Result.Content.Length); * } * }); * Entry folderMetadata = dropbox.GetMetadataAsync("Spring Social").Result; * IList<Entry> revisionsEntries = dropbox.GetRevisionsAsync("Spring Social/File.txt").Result; * Entry restoreEntry = dropbox.RestoreAsync("Spring Social/File.txt", revisionsEntries[2].Revision).Result; * IList<Entry> searchResults = dropbox.SearchAsync("Spring Social/", ".txt").Result; * DropboxLink shareableLink = dropbox.GetShareableLinkAsync("Spring Social/File.txt").Result; * DropboxLink mediaLink = dropbox.GetMediaLinkAsync("Spring Social/File.txt").Result; * Entry uploadImageEntry = dropbox.UploadFileAsync( * new AssemblyResource("assembly://Spring.ConsoleQuickStart/Spring.ConsoleQuickStart/Image.png"), * "/Spring Social/Image.png", true, null, CancellationToken.None).Result; * dropbox.DownloadThumbnailAsync("Spring Social/Image.png", ThumbnailFormat.Png, ThumbnailSize.Medium) * .ContinueWith(task => * { * Console.WriteLine("Thumbnail '{0}' downloaded ({1})", task.Result.Metadata.Path, task.Result.Metadata.Size); * // Save file to "C:\Thumbnail_Medium.png" * using (FileStream fileStream = new FileStream(@"C:\Thumbnail_Medium.png", FileMode.Create)) * { * fileStream.Write(task.Result.Content, 0, task.Result.Content.Length); * } * }); */ } catch (AggregateException ae) { ae.Handle(ex => { if (ex is DropboxApiException) { Console.WriteLine(ex.Message); return(true); } return(false); }); } #else /* OAuth 1.0 'dance' */ // Authorization without callback url Console.Write("Getting request token..."); OAuthToken oauthToken = dropboxServiceProvider.OAuthOperations.FetchRequestToken(null, null); Console.WriteLine("Done"); OAuth1Parameters parameters = new OAuth1Parameters(); //parameters.Add("locale", CultureInfo.CurrentUICulture.IetfLanguageTag); // for a localized version of the authorization website string authenticateUrl = dropboxServiceProvider.OAuthOperations.BuildAuthorizeUrl(oauthToken.Value, parameters); Console.WriteLine("Redirect user for authorization"); Process.Start(authenticateUrl); Console.Write("Press any key when authorization attempt has succeeded"); Console.ReadLine(); Console.Write("Getting access token..."); AuthorizedRequestToken requestToken = new AuthorizedRequestToken(oauthToken, null); OAuthToken oauthAccessToken = dropboxServiceProvider.OAuthOperations.ExchangeForAccessToken(requestToken, null); Console.WriteLine("Done"); /* API */ IDropbox dropbox = dropboxServiceProvider.GetApi(oauthAccessToken.Value, oauthAccessToken.Secret); //dropbox.Locale = CultureInfo.CurrentUICulture.IetfLanguageTag; DropboxProfile profile = dropbox.GetUserProfile(); Console.WriteLine("Hi " + profile.DisplayName + "!"); // Use step by step debugging, or not /* * Entry createFolderEntry = dropbox.CreateFolder("Spring Social"); * Entry uploadFileEntry = dropbox.UploadFile( * new AssemblyResource("assembly://Spring.ConsoleQuickStart/Spring.ConsoleQuickStart/File.txt"), * "/Spring Social/File.txt", true, null); * Entry copyEntry = dropbox.Copy("Spring Social/File.txt", "Spring Social/File_copy.txt"); * Entry deleteEntry = dropbox.Delete("Spring Social/File.txt"); * Entry moveEntry = dropbox.Move("Spring Social/File_copy.txt", "Spring Social/File.txt"); * var fileCanceler = dropbox.DownloadFileAsync("Spring Social/File.txt", * r => * { * Console.WriteLine("File '{0}' downloaded ({1})", r.Response.Metadata.Path, r.Response.Metadata.Size); * // Save file to "C:\Spring Social.txt" * using (FileStream fileStream = new FileStream(@"C:\Spring Social.txt", FileMode.Create)) * { * fileStream.Write(r.Response.Content, 0, r.Response.Content.Length); * } * }); * Entry folderMetadata = dropbox.GetMetadata("Spring Social"); * IList<Entry> revisionsEntries = dropbox.GetRevisions("Spring Social/File.txt"); * Entry restoreEntry = dropbox.Restore("Spring Social/File.txt", revisionsEntries[2].Revision); * IList<Entry> searchResults = dropbox.Search("Spring Social/", ".txt"); * DropboxLink shareableLink = dropbox.GetShareableLink("Spring Social/File.txt"); * DropboxLink mediaLink = dropbox.GetMediaLink("Spring Social/File.txt"); * Entry uploadImageEntry = dropbox.UploadFile( * new AssemblyResource("assembly://Spring.ConsoleQuickStart/Spring.ConsoleQuickStart/Image.png"), * "/Spring Social/Image.png", true, null); * var thumbnailCanceler = dropbox.DownloadThumbnailAsync("Spring Social/Image.png", ThumbnailFormat.Png, ThumbnailSize.Medium, * r => * { * Console.WriteLine("Thumbnail '{0}' downloaded ({1})", r.Response.Metadata.Path, r.Response.Metadata.Size); * // Save file to "C:\Thumbnail_Medium.png" * using (FileStream fileStream = new FileStream(@"C:\Thumbnail_Medium.png", FileMode.Create)) * { * fileStream.Write(r.Response.Content, 0, r.Response.Content.Length); * } * }); */ }