コード例 #1
0
 public void UploadFolderCreate(string folder, string path, DropNetClient client)
 {
     //client = new DropNetClient(apiKey, appSecret, GetUserLoginDB(tokendb), GetUserLoginDB(secretdb));
     try
     {   //Create a Folder
         if (path == null)
         {
             var metaData = client.GetMetaData("/", null, false);
             if (!(metaData.Contents.Any(c => c.Is_Dir && c.Path == "/" + folder)))
             {
                 client.CreateFolder("/" + folder);
             }
         }
         else
         {
             var metaData = client.GetMetaData(path, null, false);
             if (!(metaData.Contents.Any(c => c.Is_Dir && c.Path == folder)))
             {
                 client.CreateFolder(path + "/" + folder);
             }
         }
     }
     catch (DirectoryNotFoundException ex)
     {
         MessageBox.Show(ex.Message.ToString());
     }
 }
コード例 #2
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);
        }
コード例 #3
0
 private bool Dropbox(User user, byte[] data)
 {
     try
     {
         OnAccountStart(new BackupEventArgs(AccountEnum.Dropbox.ToString()));
         var dropClient = new DropNetClient(DropboxConfigurationSection.DropboxApiKey,
                                            DropboxConfigurationSection.DropboxAppSecret);
         dropClient.UserLogin = new UserLogin
         {
             Secret = user.DropboxAccount.UserSecret,
             Token  = user.DropboxAccount.UserToken
         };
         dropClient.AccountInfo();
         try
         {
             dropClient.UploadFile("/List Defender", "ListDefender " + DateTime.Now + ".zip", data);
         }
         catch (Exception)
         {
             dropClient.CreateFolder("List Defender");
             dropClient.UploadFile("/List Defender", "ListDefender " + DateTime.Now + ".zip", data);
         }
         OnAccountComplete(new BackupEventArgs(AccountEnum.Dropbox.ToString()));
         return(true);
     }
     catch (Exception ex)
     {
         OnShowError(new BackupEventArgs(AccountEnum.Dropbox.ToString()));
         logger.Error("Problems with Dropbox");
         _unitOfWork.DropboxRepository.Delete(user.Id);
         _unitOfWork.Commit();
         return(false);
     }
 }
コード例 #4
0
        public void Can_Create_Folder()
        {
            _client.Login(TestVariables.Email, TestVariables.Password);
            var metaData = _client.CreateFolder("TestFolder1");

            Assert.IsNotNull(metaData);
        }
コード例 #5
0
        public async Task <SyncedDirectory> GetRemoteSyncState()
        {
            try
            {
                //check if the directory exists
                Metadata wikiDir = null;
                try
                {
                    wikiDir = await _dropboxClient.GetMetaDataWithDeleted(GetRemotePath());
                }
                catch
                {
                }

                if (wikiDir == null || wikiDir.IsDeleted || !wikiDir.IsDirectory)
                {
                    await _dropboxClient.CreateFolder(GetRemotePath());
                }

                //get remote files info
                var result = await SniffRemoteDirectory(wikiDir);

                return(result);
            }
            catch (DropboxException ex)
            {
                throw CreateUsableExceptionFrom(ex);
            }
        }
コード例 #6
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");
        }
コード例 #7
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);
        }
コード例 #8
0
        internal MetaData CreateDirectoryInternal(string virtualPath)
        {
            var dir = (DropboxVirtualDirectory)GetDirectory(virtualPath);

            if (dir != null)
            {
                return(dir.MetaData);
            }
            var metaData = Client.CreateFolder(virtualPath);

            if (metaData.Contents == null)
            {
                metaData.Contents = new List <MetaData>();
            }
            RefreshCache(metaData);
            return(metaData);
        }
コード例 #9
0
ファイル: DropManager.cs プロジェクト: oginath/cloud-mgr-test
        public void CreateDirectory(string title, string dirPath)
        {
            dirPath = DropManager.ConvertToDrpPath(dirPath);
            MetaData metaData = null;

            try
            {
                metaData = Client.GetMetaData(dirPath, null, false, false);
            }
            catch
            {
                throw new Exception("Directory not found (cloud)");
            }
            if (!dirPath.ElementAt(dirPath.Length - 1).Equals('/'))
            {
                dirPath = dirPath + "/";
            }
            dirPath = dirPath + title;
            Client.CreateFolder(dirPath);
        }
コード例 #10
0
ファイル: FilTests1.Sandbox.cs プロジェクト: maurodx/DropNet
        public void Can_Create_Folder()
        {
            var metaData = _client.CreateFolder(string.Format("TestFolder1{0:yyyyMMddhhmmss}", DateTime.Now));

            Assert.IsNotNull(metaData);
        }
コード例 #11
0
        }         // Init

        public virtual void Send(string sReportName, DateTime oReportDate, string sFileExtension, byte[] oReportBody)
        {
            const int nRetryCount = 5;

            Debug("Sending {0} report to Dropbox...", sReportName);

            var client = new DropNetClient(m_sAppKey, m_sAppSecret, m_sUserKey, m_sUserSecret, null);

            string sDir = m_sRootPath + "/" + sReportName.Replace(" ", "_");

            MetaData meta = null;

            for (int i = 1; i <= nRetryCount; i++)
            {
                Debug("Looking for the target directory {0}, attempt #{1}...", sDir, i);

                try {
                    meta = client.GetMetaData(sDir);
                    break;
                }
                catch (DropboxException e) {
                    Warn("Exception caught: {0}", e.Message);
                    // Warn("Status code: {0}", e.StatusCode.ToString());
                    // Warn("Response: {0}", e.Response.Content);

                    if (i < nRetryCount)
                    {
                        Debug("Retrying to look for the target directory.");
                    }
                }         // try
            }             // for

            if (meta == null)
            {
                Debug("The target directory not found, creating...");

                try {
                    meta = client.CreateFolder(sDir);
                }
                catch (DropboxException e) {
                    Warn("Exception caught: {0}", e.Message);
                    // Warn("Status code: {0}", e.StatusCode.ToString());
                    // Warn("Response: {0}", e.Response.Content);
                }                 // try
            }
            else
            {
                Debug("The target dir already exists.");
            }

            if (meta == null)
            {
                throw new Exception("Failed to find/create target directory " + sDir);
            }

            var sFileName = string.Format(
                "{0}.{1}",
                oReportDate.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture),
                sFileExtension
                );

            Debug("Uploading {0} to {1}...", sFileName, sDir);

            client.UploadFile(sDir, sFileName, oReportBody);

            Debug("Uploading {0} to {1} complete.", sFileName, sDir);

            Debug("Sending {0} report to Dropbox complete.", sReportName);
        }         // Send