Ejemplo n.º 1
0
        private void Window_Initialized(object sender, EventArgs e)
        {
            try
            {
                var tokenCachePath  = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "droptoken");
                var secretCachePath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "dropsecret");
                if (File.Exists(tokenCachePath) && File.Exists(secretCachePath))
                {
                    var cachedUserToken  = File.ReadAllText(tokenCachePath);
                    var cachedUserSecret = File.ReadAllText(secretCachePath);
                    _client = new DropNetClient(appKey, appSecret, cachedUserToken, cachedUserSecret);
                }
                else
                {
                    _client = new DropNetClient(appKey, appSecret);
                    var userToken = _client.GetToken();

                    var tokenUrl = _client.BuildAuthorizeUrl("http://localhost:8000/token");

                    browser1.DocumentCompleted     += Browser1OnDocumentCompleted;
                    browser1.Navigated             += Browser1OnNavigated;
                    browser1.ScriptErrorsSuppressed = true;
                    browser1.Navigate(new Uri(tokenUrl));
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.ToString());
            }
        }
Ejemplo n.º 2
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");
            }
        }
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
        private void downloadVerseDatabase(DropNetClient client)
        {
            const string VerseDbFileName = "verses.sqlite3";

            client.GetMetaDataAsync("/",
                metadata =>
                {
                    var versesDb = metadata.Contents
                        .Where(x => !x.Is_Dir && x.Name == VerseDbFileName)
                        .FirstOrDefault();

                    if (versesDb == null)
                    {
                        notifyError("Could not find '" + VerseDbFileName + "' in your Dropbox root folder.");
                        return;
                    }

                    client.GetFileAsync(versesDb.Path,
                        file =>
                        {
                            var fileBytes = file.RawBytes;
                            var fileStream = new MemoryStream(fileBytes);
                            writeDatabaseToIsolatedStorage(fileStream);
                        },
                        ex => notifyError(ex));
                },
                ex => notifyError(ex));
        }
Ejemplo n.º 5
0
        public FolderBrowser(DropNetClient client)
        {
            _client = client;
            InitializeComponent();

            treeView.Nodes.Add(Recurse("/"));
        }
Ejemplo n.º 6
0
        public DropBoxAuth()
        {
            InitializeComponent();

            _indicator = AddIndicator();
            _client = DropBoxUtils.Create();
        }
 public ActionResult CreateDirectory(string path, string name)
 {
     var _client = new DropNetClient(accessKey, secretAccessKey, userTokenKey, userSecretKey);
     path = Path.Combine(path, name).Replace('\\', '/');
     _client.CreateFolder(path);
     return Content("");
 }
Ejemplo n.º 8
0
        // Shouldn't be constructing client here in static constructor.
        // needs to be 1) not static (need multiple of these)... 2) generated maybe in the GetClient() method.
        static DropboxHelper()
        {
            if (client == null)
            {
                // dummy names, avoiding obvious names.
                var key = ConfigHelper.DropBoxAPIKey;
                var secret = ConfigHelper.DropBoxAPISecret;
                var userSecret = ConfigHelper.DropBoxUserSecret;
                var userToken = ConfigHelper.DropBoxUserToken;

                // Obviously don't share DropBoxAPIKey or DropBoxAPISecret in source. This is to be kept private.
                if (string.IsNullOrEmpty(key))
                {
                    key = APIKeys.DropBoxAPIKey;
                }

                if (string.IsNullOrEmpty(secret))
                {
                    secret = APIKeys.DropBoxAPISecret;
                }

                if (string.IsNullOrEmpty(userSecret) || string.IsNullOrEmpty(userToken))
                {
                    client = new DropNetClient(key, secret);
                }
                else
                {
                    client = new DropNetClient(key, secret, userToken, userSecret, null);
                }
            }
        }
        public JsonResult Browse(string path)
        {
            path = Path.Combine(ContentPaths[0], path).Replace('\\', '/') + "/";

            var _client = new DropNetClient(accessKey, secretAccessKey, userTokenKey, userSecretKey);
            var _metaData = _client.GetMetaData(path);

            BrowseResult result = new BrowseResult();
            result.ContentPaths = ContentPaths;
            result.Path = path;

            result.Files = _metaData.Contents.Where(e => e.Extension != "").Select(e =>
                {
                    long size = 0;
                    if (e.Size.Contains(" B"))
                        size = (long)double.Parse(e.Size.Replace(" B", "").Replace('.', ','));
                    else if( e.Size.Contains(" KB"))
                        size = (long)(double.Parse(e.Size.Replace(" KB", "").Replace('.', ',')) * 1024);
                    else if (e.Size.Contains(" MB"))
                        size = (long)(double.Parse(e.Size.Replace(" MB", "").Replace('.', ',')) * 1024 * 1024);
                    else if (e.Size.Contains(" GB"))
                        size = (long)(double.Parse(e.Size.Replace(" GB", "").Replace('.', ',')) * 1024 * 1024 * 1024);
                    return new FileEntry { Name = e.Name, Size = size };
                });
            result.Directories = _metaData.Contents.Where(e => e.Extension == "").Select(e => new DirectoryEntry { Name = e.Name });

            return this.Json(result);
        }
Ejemplo n.º 10
0
        private DropboxHelper()
        {
            //_client = new DropNetClient("yre3pe1t1rsub96", "i9qrsbs5mbzkn2g", "05kuo18k341af6z", "kjij2aqhmzjk9wm");
            try
            {
                var _setting = EmployeeManagement._context.GetSharedPreferences("dropbox_token", FileCreationMode.Private);
                string _userSecret = _setting.GetString("dropbox_secret", string.Empty);
                string _userToken = _setting.GetString("dropbox_token", string.Empty);
                if (string.IsNullOrEmpty(_userSecret) || string.IsNullOrEmpty(_userToken))
                {
                    _client = new DropNetClient("yre3pe1t1rsub96", "i9qrsbs5mbzkn2g");
                    _isLogined = false;
                }
                else
                {
                    _client = new DropNetClient("yre3pe1t1rsub96", "i9qrsbs5mbzkn2g", _userToken, _userSecret);
                    _isLogined = true;
                }
            }
            catch (System.Exception ex)
            {
                _client = new DropNetClient("yre3pe1t1rsub96", "i9qrsbs5mbzkn2g");
                _isLogined = false;
            }

            _client.UseSandbox = true;
        }
Ejemplo n.º 11
0
        public MainWindow()
        {
            try
            {
                this.dropNetClient = new DropNetClient(API_KEY, APP_SECRET);
                this.dropNetClient.UseSandbox = true;
                this.employees = HierarchyGenerator.GenerateEmployees();

                InitializeComponent();

                this.importDataBtn.Click += (sender, eventArgs) =>
                {
                    var reportsPage = new ReportsPage(employees);
                    this.pagesFrame.Navigate(reportsPage);
                    this.currentPage = reportsPage;
                };
                this.exportToDropBoxBtn.Click += ExportToDropBoxAccount;
                this.exportToWordBtn.Click += (sender, e) =>
                {
                    try
                    {
                        ExportToWordFile(sender, e);
                    }
                    catch (Exception ex)
                    {
                        ShowError(ex);
                    }
                };
                this.aboutBtn.Click += ShowAboutBox;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        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 "";
        }
 static Dropbox()
 {
     client = new DropNetClient(
         ConfigurationManager.AppSettings.Get("DropboxClientID"),
         ConfigurationManager.AppSettings.Get("DropboxSecret"),
         ConfigurationManager.AppSettings.Get("DropboxAccessToken"));
 }
Ejemplo n.º 14
0
        public override SyncInfo Initialize(DatabaseInfo info)
        {
            if (info == null)
                throw new ArgumentNullException("info");

            var details = info.Details;
            var url = new Uri(details.Url);
            _client = CreateClient(url.UserInfo);

            _info = new SyncInfo
            {
                Path = url.LocalPath,
                Modified = details.Modified,
                HasLocalChanges = details.HasLocalChanges,
            };

            info.OpenDatabaseFile(x =>
            {
                using (var buffer = new MemoryStream())
                {
                    BufferEx.CopyStream(x, buffer);
                    _info.Database = buffer.ToArray();
                }
            });

            return _info;
        }
        public ActionResult Image(string filename)
        {
            var _client = new DropNetClient(accessKey, secretAccessKey, userTokenKey, userSecretKey);
            var file = _client.GetFile("/Public/Images/" + filename);

            return File(file, Common.GetMimeType(filename));
        }
Ejemplo n.º 16
0
        public string AskForRegistrationUrl(UserProfileInfo user, string redirectUrl, out int tempCredentialId)
        {
            var _client = new DropNetClient(MogConstants.DROPBOX_KEY, MogConstants.DROPBOX_SECRET);
            UserLogin login = _client.GetToken();
            // UserLogin login = _client.GetAccessToken();
            var url = _client.BuildAuthorizeUrl(login, redirectUrl);
            var query = repoAuthCredential.GetByUserId(user.Id);
            List<AuthCredential> existingCredentials = null;
            if (query != null)
            {//TODO : gerer le cas des accounts multiples
                existingCredentials = query.Where(a => a.CloudService == CloudStorageServices.Dropbox).ToList();
                foreach (var credential in existingCredentials)
                {
                    repoAuthCredential.Delete(credential);
                }
            }

            AuthCredential newCredential = new AuthCredential();
            newCredential.Token = login.Token;
            newCredential.Secret = login.Secret;
            newCredential.UserId = user.Id;
            newCredential.CloudService = CloudStorageServices.Dropbox;
            this.repoAuthCredential.Create(newCredential);
            tempCredentialId = newCredential.Id;

            return url;
        }
Ejemplo n.º 17
0
    /// <summary>
    /// Start dropbox sync
    /// </summary>
    public void Start()
    {
      Debug.Assert(_ws.HasDropBoxToken);

      _client = new DropNetClient(
                  AppSetting.DROPBOX_API_KEY,
                  AppSetting.DROPBOX_API_SECRET,
                  _ws.DropBoxToken,
                  _ws.DropBoxSecret);

      //
      // is first time sync?
      //
      bool isfirstsync = (_ws.HasLastSyncHashCode == false);
      if (isfirstsync)
      {
        Log("First sync:{0}...", _ws.Name);
        _client.GetMetaDataAsync(_ws.DropBoxPath,
                                 OnFirstSyncMetaDataReceived,
                                 OnFirstSyncMetaDataError);
        return;
      }

      Log("Sync was done once before");
      SyncFiles();
    }
Ejemplo n.º 18
0
    public static void Login(Action<string, string> callback)
    {
      var json = StorageIo.ReadTextFile(LOGIN_HELPER_FILE);
      if (string.IsNullOrEmpty(json))
      {
        var client = new DropNetClient(AppSetting.DROPBOX_API_KEY,
                                       AppSetting.DROPBOX_API_SECRET);
        client.LoginAsync(
          "*****@*****.**",
          "emfkqqkrtm",
          (login) =>
          {
            string[] credintial = new string[]
            {
              login.Token,
              login.Secret
            };
            var jsonsaving = JsonConvert.SerializeObject(credintial);
            StorageIo.WriteTextFile(LOGIN_HELPER_FILE, jsonsaving);

            ThreadUtil.UiCall(() => callback(login.Token, login.Secret));
          },
          (err) =>
          {
            MessageBox.Show("err happened:" + err.Response);
          }
        );

        return;
      }

      string[] info = JsonConvert.DeserializeObject<string[]>(json);
      callback(info[0], info[1]);
    }
Ejemplo n.º 19
0
        public MainRegistry()
        {
            ForSingletonOf<ICache>().Use<WebBasedCache>();

            For<ServerVariables>().Use(ctx => new ServerVariables(ctx.GetInstance<HttpContextBase>().Request.ServerVariables));
            For<RequestHeaders>().Use(ctx => new RequestHeaders(ctx.GetInstance<HttpContextBase>().Request.Headers));

            DbAccessBits();

#if DEBUG
            For<ICloudStorageFacade>().Use<FileSystemFacade>();
#else
            For<DropNetClient>().Use(ctx =>
            {
                var cfg = ctx.GetInstance<DropboxSettings>();
                var dropnet = new DropNetClient(cfg.ApiKey, cfg.AppSecret, cfg.UserToken, cfg.UserSecret)
                {
                    UseSandbox = true
                };
                return dropnet;
            });
            For<ICloudStorageFacade>().Use<DropboxFacade>();
#endif

            Scan(s =>
            {
                s.TheCallingAssembly();
                s.AddAllTypesOf<ISearchPlugin>();
                s.Convention<WireUpSettings>();
            });
        }
Ejemplo n.º 20
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");
        }
 public DropboxCloudStorage()
 {
     this.client = new DropNetClient(
         DropboxAppKey,
         DropboxAppSecret,
         OauthAccessTokenValue,
         OauthAccessTokenSecret);
 }
Ejemplo n.º 22
0
 private void Group1NextButtonClick(object sender, EventArgs e)
 {
     groupBox1.Enabled = false;
     _client = new DropNetClient(AppKey.Text, AppSecret.Text);
     _client.UserLogin = _client.GetToken();
     webBrowser.Navigate(_client.BuildAuthorizeUrl());
     groupBox2.Enabled = true;
 }
Ejemplo n.º 23
0
        public DropboxMediaSource(DropboxMediaSourceSettings settings)
        {
            _media = new List<Media>();
            Settings = settings;

            Client = new DropNetClient(Settings.ApplicationKey, Settings.ApplicationSecret, Settings.UserToken,
                            Settings.UserSecret) { UseSandbox = Settings.Sandbox };
        }
Ejemplo n.º 24
0
 protected DropNetClient GetAuthorizedClient()
 {
     var dropnet = new DropNetClient(ApiKey, AppSecret, UserToken, UserSecret)
     {
         UseSandbox = true
     };
     return dropnet;
 }
Ejemplo n.º 25
0
 public static void CreateAccount(string email, string firstName, string lastName, string password, Action<RestResponse> callback)
 {
     if (_client == null)
     {
         _client = new DropNetClient(ApiKey, AppSecret, string.Empty, string.Empty);
     }
     _client.CreateAccountAsync(email, firstName, lastName, password, callback);
 }
Ejemplo n.º 26
0
 public void Connect()
 {
     Client = new DropNetClient("a8bg7nzyskpde54", "cxv67uum3k93pfv");
     Client.UserLogin = new UserLogin { Token = "t44b3y1zjw0aeqri", Secret = "fc2cfuft0zg2381" };
     //Client.GetToken();
     //string AuthorizeUrl = Client.BuildAuthorizeUrl();
     //Process.Start(AuthorizeUrl);
     //UserLogin AccessToken = Client.GetAccessToken();
 }
Ejemplo n.º 27
0
        public void Login()
        {
            AccessToken at = this.AccessToken;

            this.Client = new DropNetClient(
                        ServerControler.apiKey ,
                        ServerControler.appSecret ,
                        at.UserToken , at.UserSecret , null );
        }
Ejemplo n.º 28
0
        public CloudService(IConfigService configService)
        {
            _configService = configService;
            var config = _configService.Current;

            _dropBoxClient = new DropNetClient(
                apiKey: config.Cloud.ConsumerKey,
                appSecret: config.Cloud.ConsumerSecret,
                userToken: config.Cloud.UserToken,
                userSecret: config.Cloud.UserSecret);
        }
        public string GetAuthorizationUrl()
        {
            DropNetClient _client = new DropNetClient(AppConstants.DropboxClientId, AppConstants.DropboxClientSecret);
            
             var token = _client.GetToken();
             Storage.Dropbox.Token = token;
            var url = _client.BuildAuthorizeUrl(RedirectUrl + "?dropboxcallback=1");
            

            return url;
        }
Ejemplo n.º 30
0
 private void ConnectToCloud()
 {
     try
     {
         _client = new DropNetClient(_configuration.ApiKey, _configuration.AppSecret, _configuration.AccessToken);
     }
     catch (Exception)
     {
         throw new CloudException("Couldn't connect to cloud");
     }
 }
Ejemplo n.º 31
0
        /// <summary>
        /// Uploads an album in dropbox client. 
        /// </summary>
        /// <param name="client">The dropbox client.</param>
        /// <returns></returns>
        private static ShareResponse UploadAlbum(DropNetClient client)
        {
            var folder = client.CreateFolder(ALBUM_NAME);
            DirectoryInfo info = new DirectoryInfo(ALBUM_FOLDER);
            FileInfo[] images = info.GetFiles(IMAGES_EXTENSION);

            UploadImages(client, folder, images);

            var shareUrl = client.GetShare(folder.Path);
            return shareUrl;
        }
Ejemplo n.º 32
0
 public SIM(DropNetClient client)
 {
     this.Client = client;
 }