/// <summary> /// List all detected cloud storages /// </summary> public static List <StorageStatus> DetectCloudStorage() { List <StorageStatus> cloudstorages = new List <StorageStatus>(); if (DropboxHelper.IsInstalled()) { // currently only support one driver Model.Driver driver = Model.DriverCollection.Instance.FindOne(); Model.CloudStorage cloudstorage = Model.CloudStorageCollection.Instance.FindOne(Query.EQ("Type", "dropbox")); if (cloudstorage != null) { cloudstorages.Add(new StorageStatus { type = "dropbox", connected = true, quota = cloudstorage.Quota, used = new DropboxFileStorage(driver, cloudstorage).GetUsedSize() } ); } else { cloudstorages.Add(new StorageStatus { type = "dropbox", connected = false } ); } } return(cloudstorages); }
private void loginForm_Load(object sender, EventArgs e) { this.parent = (MainForm)this.MdiParent; this.parent.StatusLabel = this.LABEL; this.URI_TOKEN = new Uri(this.parent.BaseLink + "Token"); //Dropbox downloader try { string imageLocation = "avatar.png"; DropboxHelper dh = new DropboxHelper(); BackgroundWorker bgw = new BackgroundWorker(); bgw.DoWork += delegate { dh.Run().Wait(); dh.Download(imageLocation).Wait(); using (var fs = new System.IO.FileStream(imageLocation, System.IO.FileMode.Open)) { var bmp = new Bitmap(fs); this.pictureBox.Image = (Bitmap)bmp.Clone(); } MessageBox.Show("Downloaded pic from dropbox.", "Success"); }; bgw.RunWorkerAsync(); } catch { //silent excception } }
static void Main() { DropboxHelper dh = new DropboxHelper(); // check if it is Up & Running // Lists all files in profiles folder dh.Run().Wait(); // download file with specific name from profiles folder // saves it in bin/debug dh.Download("pesho.bmp").Wait(); try { dh.Download("jm.bmp").Wait(); } catch (Exception ex) { Console.WriteLine(ex.Message); } // upload file with specific name from // bin/debug dh.UploadProfilePicture("gosho.bmp").Wait(); }
public void AddHome(AddHomeBindingModel home) { var homeToAdd = AutoMapper.Mapper.Map <AddHomeBindingModel, Home>(home); if (home.ProfilePicture != null) { var profilePicture = PictureHelper.ConvertToBytes(home.ProfilePicture); string linkToProfilePicture = String.Empty; using (var dbx = new DropboxClient(DropboxHelper.AccessToken)) { linkToProfilePicture = DropboxHelper.Upload(dbx, "/Homes/" + home.Name, "profile.png", profilePicture).ToString(); } homeToAdd.ProfilePicture = linkToProfilePicture; } else { homeToAdd.ProfilePicture = "/Defaults/home.png"; } GeocodingHelper.SetLocation(homeToAdd.Location); homeToAdd.PostedDate = DateTime.Now; repository.Insert(homeToAdd); this.repository.Commit(); }
static UrlType GetUrlType(string url) { UrlType urlType = UrlType.Local; if (AzureHelper.MatchHandler(url)) { urlType = UrlType.Azure; } else if (AzureHelper.MatchFileHandler(url)) { urlType = UrlType.AzureFile; } else if (S3Helper.MatchHandler(url)) { urlType = UrlType.S3; } else if (SkyDriveHelper.MatchHandler(url)) { urlType = UrlType.SkyDrive; } else if (SharepointHelper.MatchHandler(url)) { urlType = UrlType.Sharepoint; } else if (DropboxHelper.MatchHandler(url)) { urlType = UrlType.Dropbox; } else { urlType = UrlType.Local; // local filesystem. } return(urlType); }
public DropboxHandler(ITracer tracer, IDeploymentStatusManager status, IDeploymentSettingsManager settings, IEnvironment environment) { _dropBoxHelper = new DropboxHelper(tracer, status, settings, environment); }
protected void btnTest_Click(object sender, EventArgs e) { try { if (!Singleton.IsRunningBatch()) { lock (_object) { Singleton.CreateSingletonFile(); Logger.Log("Backup database into dropbox start"); DropboxHelper.BackUp(); Logger.Log("Backup database into dropbox end"); Singleton.DeleteSingletonFile(); } } lblTest.Text = "Backup successful!"; } catch (Exception ex) { Singleton.DeleteSingletonFile(); Logger.Log(ex.Message + Environment.NewLine + ex.StackTrace); lblTest.Text = ex.Message; } }
private async Task <string> GetPhotoUrl() { var backupUrl = @"https://cdn.pixabay.com/photo/2016/04/01/09/26/emote-1299362_1280.png"; // GET DROPBOX FOLDERS var photoUrl = string.Empty; try { // CREATE DROPBOX HELPER var helper = new DropboxHelper(); // GET ALL PHOTO PATHS var filePaths = await helper.GetFilePaths(); // SELECT RANDOM FILE var index = new Random().Next(filePaths.Count); // GET PUBLICLY ACCESSIBLE URI photoUrl = await helper.GetFileUri(filePaths[index]); } catch { // If anything fails, send a sad face photoUrl = backupUrl; } return(photoUrl); }
/// <summary> /// Connect Waveface to Dropbox /// </summary> /// <param name="quota"></param> /// <exception cref="Wammer.Station.Management.DropboxNoSyncFolderException"> /// Dropbox sync folder does not exist /// </exception> /// <exception cref="Wammer.Station.Management.WrongAccountException"> /// Link to inconsistent Dropbox account /// </exception> /// <exception cref="Wammer.Station.Management.DropboxNotInstalledException"> /// Dropbox is not installed /// </exception> public static void ConnectDropbox(long quota) { try { if (!DropboxHelper.IsInstalled()) { throw new DropboxNotInstalledException("Dropbox is not installed"); } string folder = DropboxHelper.GetSyncFolder(); CloudResponse res = CloudServer.request <CloudResponse>( new WebClient(), StationMgmtURL + "cloudstorage/dropbox/connect", new Dictionary <object, object> { { "quota", quota }, { "folder", folder } }, true ); } catch (Cloud.WammerCloudException e) { ExtractApiRetMsg(e); throw; } }
/// <summary> /// Update Dropbox quota for Waveface /// </summary> /// <param name="quota"></param> /// <exception cref="Wammer.Station.Management.DropboxNotConnectedException"> /// Waveface has not connected to Dropbox /// </exception> /// <exception cref="Wammer.Station.Management.DropboxNotInstalledException"> /// Dropbox is not installed /// </exception> public static void UpdateDropbox(long quota) { try { if (!DropboxHelper.IsInstalled()) { throw new DropboxNotInstalledException("Dropbox is not installed"); } CloudResponse res = CloudServer.request <CloudResponse>( new WebClient(), StationMgmtURL + "cloudstorage/dropbox/update", new Dictionary <object, object> { { "quota", quota } }, true ); } catch (Cloud.WammerCloudException e) { ExtractApiRetMsg(e); throw; } }
public DropboxHandler(ITracer tracer, IServerRepository repository, IDeploymentSettingsManager settings, IEnvironment environment) { _tracer = tracer; _settings = settings; _dropBoxHelper = new DropboxHelper(tracer, repository, settings, environment); }
public DropboxHandler(ITracer tracer, IDeploymentStatusManager status, IDeploymentSettingsManager settings, IEnvironment environment, IRepositoryFactory repositoryFactory) { _settings = settings; _repositoryFactory = repositoryFactory; _dropBoxHelper = new DropboxHelper(tracer, status, settings, environment); }
// really dont like the idea of storing plain passwords. // need to encrypt the app.config soon. public DropboxHandler(string url) { if (!string.IsNullOrWhiteSpace(url)) { // Create default client. Can override later if required. client = DropboxHelper.GetClient(); baseUrl = url; defaultBlobPrefix = GetBlobPrefixFromUrl(url); } }
protected void Page_Load(object sender, EventArgs e) { try { // Lock on the readonly object. if (!Singleton.IsRunningBatch()) { Singleton.CreateSingletonFile(); Logger.Log("Backup database start"); CommonList.BackUp(); Logger.Log("Backup database end"); Logger.Log("Save summary fee daily start"); CommonList.SaveSummaryPayFeeDaily(); Logger.Log("Save summary fee daily end"); int day = Convert.ToInt32(WebConfigurationManager.AppSettings["RentBike.EndDayOfMonth"]); if (day == 0) { day = 6; } if (Helper.IsDay(day)) { Logger.Log("Save summary fee montly start"); CommonList.SaveSummaryPayFeeMonthly(); Logger.Log("Save summary fee montly start"); } Logger.Log("Auto extend contract start"); CommonList.AutoExtendContract(); Logger.Log("Auto extend contract end"); Logger.Log("Auto create dummy inout start"); CommonList.CreateDummyInout(); Logger.Log("Auto create dummy inout end"); Logger.Log("Backup database into dropbox start"); DropboxHelper.BackUp(); Logger.Log("Backup database into dropbox end"); } } catch (Exception ex) { Logger.Log("Error Entry at: " + ex.Message + Environment.NewLine + ex.StackTrace); } finally { Singleton.DeleteSingletonFile(); } }
private string ConvertPath(string path) { int lastSlash = path.LastIndexOf('/'); string folder = path.Substring(0, lastSlash); string file = path.Substring(lastSlash); using (var dbx = new DropboxClient(DropboxHelper.AccessToken)) { byte[] imageByteData = DropboxHelper.Download(dbx, folder, file); string imageBase64Data = Convert.ToBase64String(imageByteData); string imageDataURL = string.Format("data:image/png;base64,{0}", imageBase64Data); return(imageDataURL); } }
private void StopListeners() { try { LocationHelper.StopTracking(); SensorHelper.StopTracking(); BatteryHelper.StopTracking(); GTalkHelper.StopTracking(); SkypeHelper.StopTracking(); OutlookHelper.StopTracking(); DropboxHelper.StopTracking(); } catch (Exception exception) { Log.Error(exception); } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ExportButton_Click(object sender, EventArgs e) { if (Datastore.Transactions.TransactionHistory.Count == 0) { MessageBox.Show("There are no transactions to export"); return; } var result = MessageBox.Show("Exporting transactions to Dropbox will clear all transactions in YNABcompanion. Are you sure you want to proceed?", "", MessageBoxButton.OKCancel); if (result == MessageBoxResult.Cancel) { return; } ProgressBar.Visibility = Visibility.Visible; ProgressBar.IsIndeterminate = true; if (!DropboxHelper.IsSetup()) { DropboxHelper.Setup(this, delegate { ExportButton_Click(sender, e); }); } else { bool success = true; Task.Run(async() => { int i = 0; Dictionary <String, String> csvStrings = GetCsvStrings(); foreach (KeyValuePair <String, String> pair in csvStrings) { success = await DropboxHelper.ExportTextFile("YNABcompanion", pair.Key + ".csv", pair.Value, delegate { ExportCompleted(new List <String>(csvStrings.Keys)); }, ++i == csvStrings.Count); if (!success) { Deployment.Current.Dispatcher.BeginInvoke(() => { MessageBox.Show("You cannot export transactions without network connectivity."); ProgressBar.IsIndeterminate = false; ProgressBar.Visibility = Visibility.Collapsed; }); break; } } }); } }
private static void ConfigureDropbox() { var authorizeUrl = DropboxHelper.BuildAuthorizeUrl(); Console.WriteLine("Configuring AzureCopy for Dropbox:\n\n"); Console.WriteLine("Please open a browser and enter the URL:\n" + authorizeUrl + "\n"); Console.WriteLine("Once you log in with your Dropbox Account, please return to this screen and press enter.\n"); Console.ReadKey(); Console.WriteLine("Modifying config file with code"); Console.WriteLine("Thankyou.... enjoy AzureCopy"); var userLoginTuple = DropboxHelper.GetAccessToken(); ConfigHelper.DropBoxUserSecret = userLoginTuple.Item1.ToString(); ConfigHelper.DropBoxUserToken = userLoginTuple.Item2.ToString(); ConfigHelper.SaveConfig(); }
/// <summary> /// /// </summary> /// <param name="path"></param> private async void FillPage(String path = "") { if (DropboxListBox.Items.Count > 0) { DropboxListBox.ScrollIntoView(DropboxListBox.Items[0]); } ProgressBar.Visibility = Visibility.Visible; ProgressBar.IsIndeterminate = true; String jsonMetadata = await DropboxHelper.GetMetaData(path); Metadata meta = new Metadata(jsonMetadata); DataContext = meta; ParentFolderTextBox.Visibility = (meta.Path != "/") ? Visibility.Visible : Visibility.Collapsed; ProgressBar.IsIndeterminate = false; ProgressBar.Visibility = Visibility.Collapsed; }
/// <summary> /// /// </summary> /// <param name="path"></param> private async void ImportCsvAndPopulateDataStructures(String path) { ProgressBar.Visibility = Visibility.Visible; ProgressBar.IsIndeterminate = true; String csvString = await DropboxHelper.ImportTextFile(path); if (csvString != "") { Datastore.Parse(csvString); } else { MessageBox.Show("Import failed. The csv file may not be valid. Please export the budget and/or register again."); } ProgressBar.Visibility = Visibility.Collapsed; ProgressBar.IsIndeterminate = false; NavigationService.GoBack(); }
/// <summary> /// Makes a usable URL for a blob. This will need to handle security on the source blob. /// Each cloud provider is different. /// Cloud providers developed: /// Azure /// S3xx /// /// Cloud providers soon: /// Dropbox /// Onedrive /// </summary> /// <param name="origBlob"></param> /// <returns></returns> private static string GeneratedAccessibleUrl(BasicBlobContainer origBlob) { var sourceUrl = origBlob.Url; // +"/" + origBlob.Name; string url = ""; // if S3, then generate signed url. if (S3Helper.MatchHandler(sourceUrl)) { var bucket = S3Helper.GetBucketFromUrl(sourceUrl); var key = origBlob.Name; url = S3Helper.GeneratePreSignedUrl(bucket, key); } else if (AzureHelper.MatchHandler(sourceUrl)) { // generate Azure signed url. var client = AzureHelper.GetSourceCloudBlobClient(sourceUrl); var policy = new SharedAccessBlobPolicy(); policy.SharedAccessStartTime = DateTime.UtcNow.AddMinutes(-1); policy.SharedAccessExpiryTime = DateTime.UtcNow.AddMinutes(ConfigHelper.SharedAccessSignatureDurationInSeconds / 60); policy.Permissions = SharedAccessBlobPermissions.Read; var blob = client.GetBlobReferenceFromServer(new Uri(sourceUrl)); url = sourceUrl + blob.GetSharedAccessSignature(policy); } else if (DropboxHelper.MatchHandler(sourceUrl)) { // need shorter url. (no base url); var uri = new Uri(sourceUrl); var shortUrl = uri.PathAndQuery; var client = DropboxHelper.GetClient(); var media = client.GetMedia(shortUrl); return(media.Url); } else if (SkyDriveHelper.MatchHandler(sourceUrl)) { throw new NotImplementedException("Blobcopy against onedrive is not implemented yet"); } Console.WriteLine("shared url is {0}", url); return(url); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ImportButton_Click(object sender, EventArgs e) { ProgressBar.Visibility = Visibility.Collapsed; ProgressBar.IsIndeterminate = false; if (!DropboxHelper.IsSetup()) { ProgressBar.Visibility = Visibility.Visible; ProgressBar.IsIndeterminate = true; DropboxHelper.Setup(this, delegate { ImportButton_Click(sender, e); }); } else { if (!NetworkInterface.GetIsNetworkAvailable()) { MessageBox.Show("You can not import YNAB data without network connectivity."); } else { NavigationService.Navigate(new Uri("//FileExplorer.xaml", UriKind.Relative)); } } }
private void button1_Click(object sender, EventArgs e) { this.openFileDialog.Title = "Select an avatar."; this.openFileDialog.FileName = ""; this.openFileDialog.Filter = "PNG Images|*.png|JPEG Images|*.jpg|GIF Images|*.gif|BITMAPS|*.bmp"; bool toUpload = false; string imageLocation = string.Empty; if (this.openFileDialog.ShowDialog() == DialogResult.OK) { imageLocation = this.openFileDialog.FileName; using (var fs = new System.IO.FileStream(imageLocation, System.IO.FileMode.Open)) { var bmp = new Bitmap(fs); this.pictureBox.Image = (Bitmap)bmp.Clone(); toUpload = true; } } this.openFileDialog.Dispose(); if (toUpload) { DropboxHelper dh = new DropboxHelper(); BackgroundWorker bgw = new BackgroundWorker(); bgw.DoWork += delegate { dh.Run().Wait(); dh.UploadProfilePicture(imageLocation).Wait(); MessageBox.Show("Uploaded pic to dropbox.", "Success"); }; bgw.RunWorkerAsync(); } }
private void DropboxButton_Click(object sender, RoutedEventArgs e) { DropboxHelper.StartTracking(); }