Ejemplo n.º 1
0
        internal DropboxModel()
        {
            try
            {
                DropNetClient client = new DropNetClient("763s7xzmvkxmfkn", "dzl7p8qdt0p1f5v");
                client.GetToken();
                string url = client.BuildAuthorizeUrl();
                Process proc = Process.Start("iexplore", url);
                bool authenticated = false;

                while (!authenticated)
                {
                    System.Threading.Thread.Sleep(5000);

                    try
                    {
                        client.GetAccessToken();
                    }
                    catch { }

                    authenticated = true;
                }

                this.client = client;
            }
            catch (Exception ex)
            {
                LogController.AddEntryDropbox(string.Format("Unable to authenticate user: {0}", ex.Message));
                throw new Exception("Authentication failed");
            }
        }
        public string SaveAttachment(AttachmentRequest request)
        {

            try
            {
                DropNetClient _client = new DropNetClient(AppConstants.DropboxClientId, AppConstants.DropboxClientSecret);


                _client.UserLogin = Storage.Dropbox.Token;

                DropNet.Models.UserLogin login = _client.GetAccessToken();



                Attachment attachment = AppUtility.GetAttachment(request.AttachmentId, request.AuthToken, request.EwsUrl);

                _client.UploadFile("/", attachment.AttachmentName, attachment.AttachmentBytes);
                return "Uploaded Sucessfully.";
            }
            catch (Exception s)
            {
                return s.Message;
            }
               
            //return "";
        }
Ejemplo n.º 3
0
        public static void Main()
        {
            var client = new DropNetClient(DropboxAppKey, DropboxAppSecret);

            var token = client.GetToken();
            var url = client.BuildAuthorizeUrl();

            Console.WriteLine("COPY?PASTE Link: {0}", url);
            Console.WriteLine("Press enter when clicked allow");
            Process.Start(@"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe", url);

            Console.ReadLine();
            var accessToken = client.GetAccessToken();

            client.UseSandbox = true;
            var metaData = client.CreateFolder("NewUpload" + DateTime.Now.ToString());

            string[] dir = Directory.GetFiles("../../images/", "*.JPG");
            foreach (var item in dir)
            {
                Console.WriteLine("Reading file.....");
                FileStream stream = File.Open(item, FileMode.Open);
                var bytes = new byte[stream.Length];
                stream.Read(bytes, 0, (int)stream.Length);
                Console.WriteLine(bytes.Length + " bytes uploading...");
                client.UploadFile("/" + metaData.Name.ToString(), item.Substring(6), bytes);
                Console.WriteLine("{0} uploaded!", item);

                stream.Close();
            }
            Console.WriteLine("Job Done!");
            var picUrl = client.GetShare(metaData.Path);
            Process.Start(@"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe", picUrl.Url);
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            Console.WriteLine("You must first login in your dropbox account.");

            string currentDir = Directory.GetCurrentDirectory();
            DirectoryInfo info = new DirectoryInfo(currentDir).Parent.Parent;

            FileInfo[] pictures = info.GetFiles("*.jpg");

            List<int> indexesOfChosen = new List<int>();

            PrintAndChoosePictures(pictures, indexesOfChosen);

            DropNetClient client = new DropNetClient("8lc93q5ybq85syv", "nt6wrs7m0maixnl");

            var token = client.GetToken();
            var url = client.BuildAuthorizeUrl();

            Clipboard.SetText(url);

            Console.WriteLine("\n\nUrl copied to clipboard. Paste in browser and allow.\nPress any key to continue", url);
            Console.ReadKey(true);

            var accessToken = client.GetAccessToken();

            client.UserLogin.Secret = accessToken.Secret;
            client.UserLogin.Token = accessToken.Token;

            client.UseSandbox = true;


            Console.Write("Enter album name: ");
            var albumName = Console.ReadLine();

            var folder = client.CreateFolder(albumName);

            Console.WriteLine("\nUploading...\n");

            foreach (var i in indexesOfChosen)
            {
                MemoryStream sr = new MemoryStream((int)pictures[i].Length);
                FileStream fs = File.Open(pictures[i].FullName, FileMode.Open);
                
                var bytes = new byte[fs.Length];

                fs.Read(bytes, 0, Convert.ToInt32(fs.Length));

                client.UploadFile(folder.Path, pictures[i].Name, bytes);

                fs.Close();
            }

            var shareUrl = client.GetShare(folder.Path);

            Clipboard.SetText(shareUrl.Url);

            Console.WriteLine(shareUrl.Url);
            Console.WriteLine("Share Url is also in clipboard");
        }
Ejemplo n.º 5
0
 public void fire_up_the_client()
 {
     var dropnet = new DropNetClient(ApiKey, AppSecret);
     var uselogin = dropnet.GetToken();
     Debug.WriteLine("Token: " + uselogin.Token);
     Debug.WriteLine("Secret: " + uselogin.Secret);
     var url = dropnet.BuildAuthorizeUrl(uselogin);
     Debug.WriteLine("Url: " + url); //Authorize App
     var token = dropnet.GetAccessToken();
     Debug.WriteLine("UsrToken: " + token.Token);
     Debug.WriteLine("UsrSecret: " + token.Secret);
 }
Ejemplo n.º 6
0
        private void Browser1OnDocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            if (e.Url.AbsolutePath == "/token")
            {
                var response = _client.GetAccessToken();
                Debug.WriteLine("token {0}, secret {1}", response.Token, response.Secret);
                var tokenCachePath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "droptoken");
                File.WriteAllText(tokenCachePath, response.Token);

                var secretCachePath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "dropsecret");
                File.WriteAllText(secretCachePath, response.Secret);
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Logs in to dropbox.
        /// </summary>
        /// <returns>Drop box client object.</returns>
        private static DropNetClient DropBoxLogIn()
        {
            DropNetClient client = new DropNetClient(APP_KEY, APP_SECRET);
            var token = client.GetToken();
            var url = client.BuildAuthorizeUrl();

            Console.WriteLine("Copy paste the link in your browser. Press any key when done.");
            Console.WriteLine(url);
            Console.ReadKey();

            var accessToken = client.GetAccessToken();

            client.UserLogin.Secret = accessToken.Secret;
            client.UserLogin.Token = accessToken.Token;
            client.UseSandbox = true;
            return client;
        }
Ejemplo n.º 8
0
        public static void Main()
        {
            var client = new DropNetClient(apiKey, apiSecret);

            client.GetToken();
            var url = client.BuildAuthorizeUrl();

            Console.WriteLine("Open \"{0}\" in browser.", url);
            Console.WriteLine("Press [Enter] when you click on [Allow]");
            OpenBrowser(url);

            Console.ReadLine();
            client.GetAccessToken();

            client.UseSandbox = true;
            var metaData = client.CreateFolder("HW-Pictures - " + date);

            string[] dir = Directory.GetFiles("../../images/", "*.jpg");
            foreach (var file in dir)
            {
                Console.Write("Uploading");
                while (true)
                {
                    FileStream stream = File.Open(file, FileMode.Open);
                    var bytes = new byte[stream.Length];
                    stream.Read(bytes, 0, (int)stream.Length);

                    client.UploadFile("/" + metaData.Name, file.Substring(6), bytes);

                    for (var i = 0; i < 10; i++)
                    {
                        Console.Write(".");
                        Thread.Sleep(300);
                    }

                    stream.Close();

                    Console.WriteLine();
                    break;
                }
            }

            Console.WriteLine("Done!");
            var pictureUrl = client.GetShare(metaData.Path);
            OpenBrowser(pictureUrl.Url);
        }
Ejemplo n.º 9
0
        public DropStorage(Action<string> webViewCallback)
        {
            _webViewCallback = webViewCallback;

            _client = new DropNetClient(DROPBOX_APP_KEY, DROPBOX_APP_SECRET);

            //Get Request Token 
            _client.GetToken();

            var authUri = _client.BuildAuthorizeUrl();
            //Process.Start(authUri);
            _webViewCallback(authUri);

            //don't need it, web view callback is blocking 
            //var dlg = new AuthDlg(StorageType.Dropbox);
            //dlg.ShowDialog();

            _accessToken = _client.GetAccessToken(); //Store this token for "remember me" function
        }
        public ActionResult AuthCallback(string uid, string oauth_token, string redirectUrl) {
            if(string.IsNullOrEmpty(uid) || string.IsNullOrEmpty(oauth_token)) 
                return new HttpUnauthorizedResult();

            try {
                var settings = _orchard.WorkContext.CurrentSite.As<DropboxSettingsPart>();
                var userLogin = _httpContext.Current().Session["DropnetUserLogin"] as UserLogin;

                var client = new DropNetClient(settings.ApiKey, settings.ApiSecret,
                                               userLogin.Token, userLogin.Secret);
                _httpContext.Current().Session["DropnetUserLogin"] = client.GetAccessToken();
                var userSettings = _orchard.WorkContext.CurrentUser.As<DropboxUserSettingsPart>();
                userSettings.UserToken = client.UserLogin.Token;
                userSettings.UserSecret = client.UserLogin.Secret;
                return View();
            }
            catch (DropboxException dbe) {
                Logger.Error(dbe, "Authorise");
                return View("Index_SetupApi");
            }   
        }
        public static void Main()
        {
            var client = new DropNetClient(DropboxAppKey, DropboxAppSecret);

            var token = client.GetToken();
            var url = client.BuildAuthorizeUrl();

            Console.WriteLine("Open browser with in : {0}", url);
            Console.WriteLine("Press enter when clicked allow");
            Process.Start(@"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe",
              url);

            Console.ReadLine();
            var accessToken = client.GetAccessToken();

            client.UseSandbox = true;
            var metaData = client.CreateFolder("Pictures" + DateTime.Now);

            var dir = Directory.GetFiles("../../Photos", "*.jpg");

            foreach (var item in dir)
            {
                Console.WriteLine("Uploading.....");
                var stream = File.Open(item, FileMode.Open);
                var bytes = new byte[stream.Length];
                stream.Read(bytes, 0, (int)stream.Length);

                client.UploadFile("/" + metaData.Name, item.Substring(6), bytes);

                stream.Close();
            }

            var picUrl = client.GetShare(metaData.Path);
            Process.Start(@"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe",
             picUrl.Url);
        }
Ejemplo n.º 12
0
        public static void syncAcc(bool resync)
        {
            //Testing Connection

            try
            {
                Ping pSender = new Ping();

                PingReply pResult = pSender.Send("8.8.8.8");

                if (pResult.Status == IPStatus.Success)
                {
                    Console.WriteLine("Internet available");
                }
                else
                {
                    Exception exc = new Exception("no internetconnection");

                    throw exc;
                }

            }
            catch (Exception)
            {
                MessageBox.Show("Please make sure your connection to the internet is available");
                return;
            }

            DropNetClient dbClient = new DropNetClient(Program.Config.AppKey, Program.Config.AppSecret);
            #if DEBUG
            dbClient.UseSandbox = true;
            #endif

            if (String.IsNullOrEmpty(Properties.Settings.Default.DropBoxUserToken) || resync)
            {
                try
                {
                    dbClient.GetToken();
                }
                catch (Exception)
                {

                    throw;
                }

                var url = dbClient.BuildAuthorizeUrl();

                Browser_frm browser = new Browser_frm();
                browser.Navigate(url,false);
                browser.ShowDialog();

                try
                {

                    var accessToken = dbClient.GetAccessToken();

                    MessageBox.Show(accessToken.Token);

                    Properties.Settings.Default.DropBoxUserSecret = accessToken.Secret;
                    Properties.Settings.Default.DropBoxUserToken = accessToken.Token;
                    Properties.Settings.Default.Save();
                    MessageBox.Show("Login Saved");

                }
                catch (Exception)
                {

                    throw;
                }

            }
            else
            {
                MessageBox.Show("already synchronized");
            }
        }
Ejemplo n.º 13
0
        internal static void Main(string[] args)
        {
            Console.WriteLine("Please login in your dropbox account.");
            Console.WriteLine(new string('-', 30));
            Console.Write("Press any key when ready");
            Console.ReadLine();
            Console.WriteLine(new string('-', 30));

            var currentDir = Directory.GetCurrentDirectory();
            var dirFiles = new DirectoryInfo(currentDir).Parent.Parent;

           var pictures = dirFiles.GetFiles("*.jpg");

           var chosenPhotosIndexes = new List<int>();

            PrintAndChoosePictures(pictures, chosenPhotosIndexes);

            DropNetClient client = new DropNetClient("0yfo5pqlswvwahb", "vi8gx0704m78ahy");

            var token = client.GetToken();
            var url = client.BuildAuthorizeUrl();

            Clipboard.SetText(url);
            Console.WriteLine(new string('-', 30));
            Console.WriteLine("App Url was copied to clipboard. Please paste it in your browser and click \"Allow\".");
            Console.WriteLine();
            Console.Write("Press any key when ready");
            Console.ReadKey(true);

            var accessToken = client.GetAccessToken();

            client.UserLogin.Secret = accessToken.Secret;
            client.UserLogin.Token = accessToken.Token;

            client.UseSandbox = true;

            Console.WriteLine();
            Console.Write("Please enter an album name: ");
            var albumName = Console.ReadLine();

            var folder = client.CreateFolder(albumName);

            Console.WriteLine(new string('-', 30));
            Console.WriteLine("Uploading...");

            foreach (var index in chosenPhotosIndexes)
            {
                MemoryStream sr = new MemoryStream((int)pictures[index].Length);
                FileStream fs = File.Open(pictures[index].FullName, FileMode.Open);

                var bytes = new byte[fs.Length];

                fs.Read(bytes, 0, Convert.ToInt32(fs.Length));

                client.UploadFile(folder.Path, pictures[index].Name, bytes);

                fs.Close();
            }

            var shareUrl = client.GetShare(folder.Path);

            Clipboard.SetText(shareUrl.Url);

            Console.WriteLine("Url: {0}", shareUrl.Url);
            Console.WriteLine();
            Console.WriteLine("Sharing Url copied to clipboard. Enjoy the cat pics!");
        }
Ejemplo n.º 14
0
        public void RegisterAccount(int tempCredentialId)
        {
            AuthCredential partialCredential = this.repoAuthCredential.GetById(tempCredentialId);

            try
            {
                UserLogin lg = new UserLogin { Token = partialCredential.Token, Secret = partialCredential.Secret };
                DropNetClient client = new DropNetClient(MogConstants.DROPBOX_KEY, MogConstants.DROPBOX_SECRET);
                client.UserLogin = lg;
                UserLogin accessToken = client.GetAccessToken();

                partialCredential.Token = accessToken.Token;
                partialCredential.Secret = accessToken.Secret;
                partialCredential.Status = CredentialStatus.Approved;
                this.repoAuthCredential.SaveChanges(partialCredential);
            }
            catch (DropNet.Exceptions.DropboxException exc)
            {//
                this.repoAuthCredential.Delete(partialCredential);
                throw new Exception("failed to register accoutn", exc);
            }
        }
 public ActionResult DropboxCallback(string code, string state)
 {
     if (code == null)
     {
         ViewBag.Message = "Application not authorized to acces user's files";
         return RedirectToAction("Manage", "StorageManagement");
     }
     var t = Session["DropboxStateString"];
     if (!state.Equals(Session["DropboxStateString"]))
         return new HttpUnauthorizedResult();
     Session.Remove("DropboxStateString");
     var client = new DropNetClient(AppCredentials.DROPBOX_APP_KEY, AppCredentials.DROPBOX_APP_SECRET, DropNetClient.AuthenticationMethod.OAuth2);
     var callbackUrl = Url.Action("DropboxCallback", "StorageManagement", null, Request.Url.Scheme);
     var accessToken = client.GetAccessToken(code, callbackUrl);
     string currentUserId = User.Identity.GetUserId();
     var currentUser = db.Users.FirstOrDefault(x => x.Id == currentUserId);
     StorageService dropboxService = new StorageService
     {
         ServiceType = StorageService.ServiceTypes.Dropbox,               
         AccessToken = Utility.Encryption.Encrypt(accessToken.Token)
     };
     currentUser.StorageServices.Add(dropboxService);
     db.SaveChanges();
     Session["DropBoxStatus"] = StorageService.ServiceStatus.Connected;
     Session["DropBoxClient"] = client;            
     return RedirectToAction("Index", "Home");
 }