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);
        }
Exemple #2
0
        private static async Task <Entry> CreateFolderAsync(IDropbox dropbox, string newFolderName)
        {
            var createFolderEntry = await dropbox.CreateFolderAsync(newFolderName);

            Console.WriteLine("Created folder: {0}", createFolderEntry.Path);
            return(createFolderEntry);
        }
Exemple #3
0
        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)
            }
        }        
Exemple #4
0
        public string Upload(string file)
        {
            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;

            // Create new folder
            string newFolderName     = "New_Folder_" + DateTime.Now.Ticks;
            Entry  createFolderEntry = dropbox.CreateFolderAsync(newFolderName).Result;

            var    splitetFileDirectory = file.Split(new char[] { '/', '\\' });
            string fileName             = splitetFileDirectory[splitetFileDirectory.Length - 1];

            // Upload a file
            Entry uploadFileEntry = dropbox.UploadFileAsync(
                new FileResource(file),                 //("../../DropboxExample.cs"),
                "/" + newFolderName + fileName).Result; //"/DropboxExample.cs").Result;

            // Share a file
            DropboxLink sharedUrl = dropbox.GetShareableLinkAsync(uploadFileEntry.Path).Result;

            //Open the file location
            return(sharedUrl.Url.ToString());
        }
Exemple #5
0
 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);
 }
        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(AppDomain.CurrentDomain.BaseDirectory + "Archivo\\" + nombre, System.IO.FileMode.Create, System.IO.FileAccess.Write);
                _FileStream.Write(file.Content, 0, file.Content.Length);
                _FileStream.Close();
                Process.Start(AppDomain.CurrentDomain.BaseDirectory + "Archivo\\" + nombre);
                estado = true;
                return(estado);
            }
            catch (Exception ex)
            {
                return(estado);
            }
        }
        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);
        }
 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 IDropbox GetDropboxApi()
        {
            DropboxServiceProvider serviceProvider = this.Initialize(this.dropboxAppKey, this.dropboxAppSecret);
            IDropbox currentDropboxApi = serviceProvider.GetApi(this.oauthAccessToken.Value, this.oauthAccessToken.Secret);

            return currentDropboxApi;
        }
        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);
        }
        public void UploadNewUserAvatar(string avatarLocalPath, string username)
        {
            dropbox = ConnectToDropboxAPI();

            string uploadPhotoName = String.Format("/{0}.jpg", username);

            uploadedPhoto = dropbox.UploadFileAsync(new FileResource(avatarLocalPath), uploadPhotoName).Result;
        }
 public FileManagerService(
     IDropbox dropbox,
     IMapper mapper,
     IUnitOfWork uow
     ) : base(mapper, uow)
 {
     _dropbox = dropbox;
 }
        public void UploadNewUserAvatar(string avatarLocalPath, string username)
        {
            dropbox = ConnectToDropboxAPI();

            string uploadPhotoName = String.Format("/{0}.jpg", username);

            uploadedPhoto = dropbox.UploadFileAsync(new FileResource(avatarLocalPath), uploadPhotoName).Result;
        }
        public static Entry UploadImage(string imagePath, IDropbox dropbox, string folderName)
        {
            string imageName = Path.GetFileName(imagePath);

            Entry uploadFileEntry = dropbox.UploadFileAsync(new FileResource(imagePath),
            "/" + folderName + "/" + imageName).Result;

            return uploadFileEntry;
        }
        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 static Entry UploadImage(string imagePath, IDropbox dropbox, string folderName)
        {
            string imageName = Path.GetFileName(imagePath);

            Entry uploadFileEntry = dropbox.UploadFileAsync(new FileResource(imagePath),
                                                            "/" + folderName + "/" + imageName).Result;

            return(uploadFileEntry);
        }
        private static Entry CreateDropboxFolder(IDropbox dropbox, string folderName)
        {
            Entry folderEntry = dropbox
                .CreateFolderAsync(folderName)
                .Result;
            Console.WriteLine("Created folder: {0}", folderEntry.Path);

            return folderEntry;
        }
    private static string DropboxUpload(string fileUrl, IDropbox dropbox, string newFolderName)
    {
        Entry uploadFileEntry = dropbox.UploadFileAsync(
            new FileResource(fileUrl),
            "/" + newFolderName).Result;
        DropboxLink sharedUrl = dropbox.GetShareableLinkAsync(uploadFileEntry.Path).Result;

        return sharedUrl.Url;
    }
    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);
    }
Exemple #20
0
        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 DropboxService()
        {
            DropboxServiceProvider dropboxServiceProvider =
                new DropboxServiceProvider(DropboxAppKey, DropboxAppSecret, AccessLevel.AppFolder);

            IDropbox dropbox = dropboxServiceProvider.GetApi(appToken, appTokenSecret);

            DropboxProfile profile = dropbox.GetUserProfileAsync().Result;

            this.currentDropbox = dropbox;
        }
        private static Entry UploadFileAsync(IDropbox dropbox, string targetFolderPath, string sourceFilePath)
        {
            var sourceFileName = Path.GetFileName(sourceFilePath);

            var uploadFileEntry = dropbox.UploadFileAsync(
                            new FileResource(sourceFilePath),
                            targetFolderPath + "/" + sourceFileName).Result;

            Console.WriteLine("Uploaded a file: {0}", uploadFileEntry.Path);
            return uploadFileEntry;
        }
Exemple #23
0
        private static Entry UploadFileAsync(IDropbox dropbox, string targetFolderPath, string sourceFilePath)
        {
            var sourceFileName = Path.GetFileName(sourceFilePath);

            var uploadFileEntry = dropbox.UploadFileAsync(
                new FileResource(sourceFilePath),
                targetFolderPath + "/" + sourceFileName).Result;

            Console.WriteLine("Uploaded a file: {0}", uploadFileEntry.Path);
            return(uploadFileEntry);
        }
        // GET: /Dropbox/Browser
        public ActionResult Browser(string path)
        {
            string   tokenValue    = Session["TokenValue"] as string;
            string   tokenSecret   = Session["TokenSecret"] as string;
            IDropbox dropboxClient = dropboxProvider.GetApi(tokenValue, tokenSecret);
            //dropboxClient.Locale = System.Globalization.CultureInfo.CurrentUICulture.IetfLanguageTag; // for a localized version of the content response

            Entry root = dropboxClient.GetMetadataAsync(path).Result;

            return(View(root));
        }
Exemple #25
0
 public CompanyService(
     ICompanyRepository companyRepository,
     IMapper mapper,
     IUnitOfWork uow,
     IDropbox dropbox,
     IFileManagerService fileManagerService
     ) : base(mapper, uow)
 {
     _companyRepository  = companyRepository;
     _dropbox            = dropbox;
     _fileManagerService = fileManagerService;
 }
Exemple #26
0
        public static string DropboxShareFile(Stream stream, string filename)
        {
            //OAuthToken oauthAccessToken = LoadOAuthToken();
            IDropbox dropbox = dropboxServiceProvider.GetApi(oAuthToken[0], oAuthToken[1]);

            Entry uploadFileEntry = dropbox.UploadFileAsync(new StreamResource(stream)
                                                            , filename).Result;

            var sharedUrl = dropbox.GetMediaLinkAsync(uploadFileEntry.Path).Result;

            return(sharedUrl.Url + "?dl=1");  // we can download the file directly
        }
        private string DropboxShareFile(string path, string filename)
        {
            DropboxServiceProvider dropboxServiceProvider =
                new DropboxServiceProvider(this.appAuth.Value, this.appAuth.Secret, AccessLevel.AppFolder);
            IDropbox dropbox = dropboxServiceProvider.GetApi(this.userAuth.Value, this.userAuth.Secret);

            Entry uploadFileEntry = dropbox.UploadFileAsync(
                new FileResource(path), filename).Result;

            var sharedUrl = dropbox.GetMediaLinkAsync(uploadFileEntry.Path).Result;

            return(sharedUrl.Url + "?dl=1");  // we can download the file directly
        }
        public void ShowProfile()
        {
            IDropbox dropboxClient = this.DropboxServiceProvider.GetApi(this.OAuthToken.Value, this.OAuthToken.Secret);

            dropboxClient.GetUserProfileAsync(
                r =>
            {
                if (r.Error == null)
                {
                    this.Profile = r.Response;
                }
            });
        }
        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);
        }
        private static List<Entry> UploadFiles(IDropbox dataContext, string targetFolderPath, string sourceFolderPath)
        {
            var uploadedFileEntries = new List<Entry>();

            var filePaths = Directory.GetFiles(sourceFolderPath);
            foreach (var filePath in filePaths)
            {
                var uploadFileEntry = UploadFileAsync(dataContext, targetFolderPath, filePath);
                uploadedFileEntries.Add(uploadFileEntry);
            }

            return uploadedFileEntries;
        }
    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);
    }
Exemple #32
0
        private static List <Entry> UploadFiles(IDropbox dataContext, string targetFolderPath, string sourceFolderPath)
        {
            var uploadedFileEntries = new List <Entry>();

            var filePaths = Directory.GetFiles(sourceFolderPath);

            foreach (var filePath in filePaths)
            {
                var uploadFileEntry = UploadFileAsync(dataContext, targetFolderPath, filePath);
                uploadedFileEntries.Add(uploadFileEntry);
            }

            return(uploadedFileEntries);
        }
        // GET: /Dropbox/Callback
        public ActionResult Callback()
        {
            OAuthToken             requestToken           = Session["RequestToken"] as OAuthToken;
            AuthorizedRequestToken authorizedRequestToken = new AuthorizedRequestToken(requestToken, null);
            OAuthToken             token = dropboxProvider.OAuthOperations.ExchangeForAccessTokenAsync(authorizedRequestToken, null).Result;

            Session["TokenValue"]  = token.Value;
            Session["TokenSecret"] = token.Secret;

            IDropbox       dropboxClient = dropboxProvider.GetApi(token.Value, token.Secret);
            DropboxProfile profile       = dropboxClient.GetUserProfileAsync().Result;

            return(View(profile));
        }
Exemple #34
0
        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);
            }
        }
        private void SendFile(string filePath)
        {
            OAuthToken oauthAccessToken = LoadOAuthToken();

            dropbox = dropboxServiceProvider.GetApi(oauthAccessToken.Value, oauthAccessToken.Secret);
            
            string newFolderName = "New_Folder_" + DateTime.Now.Ticks;
         
            Entry uploadFileEntry = dropbox.UploadFileAsync(
                new FileResource(filePath),
                "/" + newFolderName + "/" + new FileInfo(filePath).Name).Result;
            
            DropboxLink sharedUrl = dropbox.GetShareableLinkAsync(uploadFileEntry.Path).Result;
            Process.Start(sharedUrl.Url);

            MessageBox.Show("File sent successfully!");
        }
        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;
        }
Exemple #37
0
        static void Main()
        {
            IDropbox dataContext = GetDropboxContext();

            // Create new folder
            string newFolderName     = "SharedGallery" + DateTime.Now.Ticks;
            var    targetFolderEntry = CreateFolderAsync(dataContext, newFolderName).Result;

            // Upload files from local folder
            var sourceFolderPath = @"..\..\sourceImages";
            var uploadFileEntry  = UploadFiles(dataContext, targetFolderEntry.Path, sourceFolderPath);

            // Share the folder
            DropboxLink sharedUrl = dataContext.GetShareableLinkAsync(targetFolderEntry.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);
        }
Exemple #39
0
        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 string TakeUrl(IDropbox dropbox, string image, string address)
        {
            // Create new folder
            // string newFolderName = "Test";
            // Entry createFolderEntry = dropbox.CreateFolder(newFolderName);
            //Console.WriteLine("Created folder: {0}", createFolderEntry.Path);

            HttpClient client = new HttpClient();

            byte[] imageAsByteArr = client.GetByteArrayAsync(address).Result;

            Entry uplodeImage = dropbox.UploadFile(new ByteArrayResource(imageAsByteArr), "/" + image);
            // Upload a file
            // Entry uploadFileEntry = dropbox.UploadFile(new FileResource("../../TestImages/" + image), "/" + image);

            // take url
            DropboxLink link = dropbox.GetMediaLink(uplodeImage.Path);
            string url = link.Url;
            return url;
        }
        private string TakeUrl(IDropbox dropbox, string image, string address)
        {
            // Create new folder
            // string newFolderName = "Test";
            // Entry createFolderEntry = dropbox.CreateFolder(newFolderName);
            //Console.WriteLine("Created folder: {0}", createFolderEntry.Path);

            HttpClient client = new HttpClient();

            byte[] imageAsByteArr = client.GetByteArrayAsync(address).Result;

            Entry uplodeImage = dropbox.UploadFile(new ByteArrayResource(imageAsByteArr), "/" + image);
            // Upload a file
            // Entry uploadFileEntry = dropbox.UploadFile(new FileResource("../../TestImages/" + image), "/" + image);

            // take url
            DropboxLink link = dropbox.GetMediaLink(uplodeImage.Path);
            string      url  = link.Url;

            return(url);
        }
Exemple #42
0
        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);
            }
        }
Exemple #43
0
 public DropboxService()
 {
     this.dropboxAppKey = DropboxConstants.DropboxAppKey;
     this.dropboxAppSecret = DropboxConstants.DropboxAppSecret;
     this.dropboxApi = this.GetDropboxApi();
 }
Exemple #44
0
 public DropboxService()
 {
     this.dropboxAppKey = WebStorageConstants.DropboxAppKey;
     this.dropboxAppSecret = WebStorageConstants.DropboxAppSecret;
     this.dropboxApi = this.GetDropboxApi();
 }
Exemple #45
0
        private void ContinueLinkApp(AuthenticationToken token)
        {
            try
            {
                // Get access token either from parameter or from API
                OAuthToken oauthAccessToken = null;
                if (token == null)
                {
                    AuthorizedRequestToken requestToken = new AuthorizedRequestToken(_oauthToken, null);
                    oauthAccessToken = _dropboxServiceProvider.OAuthOperations.ExchangeForAccessTokenAsync(requestToken, null).Result;
                }
                else
                {
                    oauthAccessToken = new OAuthToken(token.Value, token.Secret);
                }

                if (OnCloudAuthenticationStatusChanged != null)
                    OnCloudAuthenticationStatusChanged(CloudAuthenticationStatusType.RequestAccessToken);

                // Get Dropbox API instance
                _dropbox = _dropboxServiceProvider.GetApi(oauthAccessToken.Value, oauthAccessToken.Secret);
                //dropbox.Locale = CultureInfo.CurrentUICulture.IetfLanguageTag;

                // Test Dropbox API connection (get user name from profile)
                DropboxProfile profile = _dropbox.GetUserProfileAsync().Result;
                HasLinkedAccount = true;

                // Save token to hard disk
                SaveTokenToDisk(new AuthenticationToken() {
                    Value = oauthAccessToken.Value, 
                    Secret = oauthAccessToken.Secret,
                    UserName = profile.DisplayName
                });
                
                if (OnCloudAuthenticationStatusChanged != null)
                    OnCloudAuthenticationStatusChanged(CloudAuthenticationStatusType.ConnectedToDropbox);
            }
            catch (AggregateException ae)
            {
                HasLinkedAccount = false;
                ae.Handle(ex =>
                {
                    if (ex is DropboxApiException)
                    {
                        Console.WriteLine(ex.Message);
                        return true;
                    }
                    return false;
                });
            }
        }
 private static void Share(IDropbox dropbox, Entry fileOrFolderEntry)
 {
     DropboxLink sharedUrl = dropbox
                             .GetShareableLinkAsync(fileOrFolderEntry.Path)
                             .Result;
     Process.Start(sharedUrl.Url);
     Console.WriteLine("Folder {0} shared!", fileOrFolderEntry.Path);
 }
        private static void Upload(IDropbox dropbox, string path, string folderName)
        {
            DirectoryInfo directory = new DirectoryInfo(path);

            foreach (var file in directory.GetFiles())
            {
                Entry uploadFileEntry = dropbox
                    .UploadFileAsync(new FileResource(file.FullName), "/" + folderName + "/" + file.Name)
                    .Result;
                Console.WriteLine("Uploaded file: {0}", uploadFileEntry.Path);
            }
        }
 public DropBoxCloud(string key, string secret)
 {
     this.dropboxAppKey = key;
     this.dropboxAppSecret = secret;
     this.dropboxApi = this.GetDropboxApi();
 }
Exemple #49
0
 public void UnlinkApp()
 {
     DeleteTokenFromDisk();
     HasLinkedAccount = false;
     _dropbox = null;
 }
 public DropboxHelper()
 {
     this.serviceProvider = new DropboxServiceProvider(Constants.DropboxAppKey, Constants.DropboxAppSecret, AccessLevel.AppFolder);
     this.dropbox = serviceProvider.GetApi(Constants.DropboxAppToken, Constants.DropboxAppTokenSecret);
 }
 private static async Task<Entry> CreateFolderAsync(IDropbox dropbox, string newFolderName)
 {
     var createFolderEntry = await dropbox.CreateFolderAsync(newFolderName);
     Console.WriteLine("Created folder: {0}", createFolderEntry.Path);
     return createFolderEntry;
 }