예제 #1
0
        public void Can_Get_File()
        {
            _client.Login(TestVariables.Email, TestVariables.Password);
            var fileInfo = _client.GetFile("/Getting Started.rtf");

            Assert.IsNotNull(fileInfo);
        }
예제 #2
0
        public Dictionary<Guid, string> GetExactOnlineReferences()
        {
            if (!_isAccessToken)
                throw new InvalidOperationException("User must be authorized");

            Dictionary<Guid, string> referenceDictionary = new Dictionary<Guid, string>();
            try
            {
                string references = Encoding.UTF8.GetString(_dropboxClient.GetFile("/" + EXACT_ONLINE_REFERENCES_FILENAME));
                using (StringReader referencesReader = new StringReader(references))
                {
                    string reference = null;
                    while ((reference = referencesReader.ReadLine()) != null)
                    {
                        string[] singleReference = reference.Split(';');
                        referenceDictionary.Add(Guid.Parse(singleReference[0]), singleReference[1]);
                    }
                }
            }
            catch (DropNet.Exceptions.DropboxRestException)
            {
                // Create file for future use
                UploadExactOnlineReferences("");
            }

            return referenceDictionary;
        }
예제 #3
0
        public byte[] loadDataFromRemoteStorage(string filename, string guid)
        {
            string finalFilename = "";

            if (guid.Length > 0)
            {
                finalFilename = guid + "_" + filename;
            }
            else
            {
                finalFilename = filename;
            }
            byte[] data = {};


            try
            {
                data = _client.GetFile("temp_" + finalFilename);
            }
            catch (Exception e)
            {
                if (data.Length == 0)
                {
                    data = _client.GetFile(finalFilename);
                }
            }
            return(data);
        }
예제 #4
0
파일: DropBox.cs 프로젝트: aloisdg/Nepholo
        public Task Download(string id, string name)
        {
            return(Task.Run(() =>
            {
                //_client.GetFileAsync(id,
                //    async response =>
                //    {
                //        using (var sourceStream = new FileStream(name,
                //            FileMode.Append, FileAccess.Write, FileShare.None,
                //            bufferSize: 4096, useAsync: true))
                //        {
                //            var encodedText = Encoding.Unicode.GetBytes(response.Content);
                //            await sourceStream.WriteAsync(encodedText, 0, encodedText.Length);
                //        }
                //    },
                //    error =>
                //    {
                //        Debug.WriteLine(error.Message);
                //        //Do something on error
                //    });

                // Sync
                var fileBytes = _client.GetFile(id);
                ByteArrayToFile(name, fileBytes);
            }));
        }
예제 #5
0
        public void DownloadFile(string FilePath, string DirectoryPath)
        {
            FilePath = DropManager.ConvertToDrpPath(FilePath);

            if (System.IO.Directory.Exists(DirectoryPath))
            {
                MetaData metaData = null;
                try
                {
                    metaData = Client.GetMetaData(FilePath, null, false, false);
                }
                catch
                {
                    throw new Exception("File not found (cloud)");
                }
                if (!metaData.Is_Dir)
                {
                    byte[] FileBytes = Client.GetFile(FilePath);
                    System.IO.File.WriteAllBytes(DirectoryPath + metaData.Name, FileBytes);
                }
                else
                {
                    throw new Exception("Cannot download a directory");
                }
            }
            else
            {
                throw new Exception("Directory not found (local)");
            }
        }
예제 #6
0
        /// <summary>
        /// Download a file from Dropbox
        /// </summary>
        /// <param name="client">Dropnet client</param>
        /// <param name="remotePath">The file's path on Dropbox (use forward slashes for directory separators)</param>
        /// <param name="localPath">The target path</param>
        public static void DownloadFile(this DropNetClient client, string remotePath, string localPath)
        {
            var bytes        = client.GetFile(remotePath);
            var targetFolder = localPath.ParentDirectory();

            if (!Directory.Exists(targetFolder))
            {
                Directory.CreateDirectory(targetFolder);
            }
            File.WriteAllBytes(localPath, bytes);
        }
 public Task <byte[]> GetFile(string remotePath)
 {
     try
     {
         return(_dropboxClient.GetFile(remotePath));
     }
     catch (DropboxException ex)
     {
         throw CreateUsableExceptionFrom(ex);
     }
 }
예제 #8
0
        public string DownloadSerializationAsset(string tagName)
        {
            var client = new DropNetClient(_dropBoxSettings.ApiKey, _dropBoxSettings.ApiSecret, _dropBoxSettings.AccessToken);

            client.UseSandbox = true;
            string artifactPath = String.Format("/Artifacts/{0}/{1}", tagName, ZIP_FILE_NAME);
            var    file         = client.GetFile(artifactPath);
            string tempFile     = Directory.GetCurrentDirectory() + "\\" + ZIP_FILE_NAME;

            File.WriteAllBytes(tempFile, file);

            return(tempFile);
        }
예제 #9
0
        private FileInfo Retrieve()
        {
            var data = client.GetFile("default.scrumr");

            using (var fs = new FileStream(SyncPath.FullName, FileMode.Create))
            {
                for (int i = 0; i < data.Length; i++)
                {
                    fs.WriteByte(data[i]);
                }
            }

            return(SyncPath);
        }
예제 #10
0
        protected override string PerformExecution(Dictionary <string, string> evaluatedValues)
        {
            if (SelectedSource != null)
            {
                var oauthSource = ResourceCatalog.Instance.GetResource <OauthSource>(GlobalConstants.ServerWorkspaceID, SelectedSource.ResourceID);
                if (oauthSource == null || oauthSource.ResourceType != ResourceType.OauthSource)
                {
                    return("Failure: Source has been deleted.");
                }
                SelectedSource = oauthSource;
            }

            if (evaluatedValues["Operation"] == "Write File")
            {
                var destinationFileName = evaluatedValues["DestinationPath"];
                var destinationPath     = "/";
                if (destinationFileName.Contains("/"))
                {
                    destinationPath     = destinationFileName.Substring(0, 1 + destinationFileName.LastIndexOf("/", StringComparison.Ordinal));
                    destinationFileName = destinationFileName.Substring(destinationFileName.LastIndexOf("/", StringComparison.Ordinal) + 1);
                }
                var output = DropNetClient.UploadFile(destinationPath, destinationFileName, File.ReadAllBytes(evaluatedValues["SourceFile"]));
                if (output == null)
                {
                    Dev2Logger.Log.Error("Unable to upload. Result is null. This indicates that there is no internet connection");
                    return("Failure");
                }
                Dev2Logger.Log.Debug(String.Format("File uploaded to dropbox {0}", output.Path));
                return("Success");
            }
            // ReSharper disable RedundantIfElseBlock
            else if (evaluatedValues["Operation"] == "Read File")
            // ReSharper restore RedundantIfElseBlock
            {
                var destinationFileName = evaluatedValues["SourceFile"];

                File.WriteAllBytes(destinationFileName, DropNetClient.GetFile(evaluatedValues["DestinationPath"]));

                Dev2Logger.Log.Debug(String.Format("File written to local file system {0}", destinationFileName));
                return("Success");
            }
            return("Failure");
        }
예제 #11
0
        private void DownloadChunk(object state)
        {
            var chunk = state as CachedFileChunk;

            if (chunk == null)
            {
                return;
            }
            var readBegin = chunk.Range.Minimum;
            var readEnd   = chunk.Range.Maximum;

            if (chunk.Count < PreloadWindow)
            {
                readEnd = readBegin + PreloadWindow;
            }
            if (readEnd > _metaData.Bytes)
            {
                readEnd = (int)_metaData.Bytes;
            }
            var buf = _client.GetFile(_file.UnixFullFileName, readBegin, readEnd, string.Empty);

            Write(buf, chunk.Offset, buf.Length);
            chunk.DoneEvent.Set();
        }
예제 #12
0
        public void Can_Get_File()
        {
            var fileInfo = _client.GetFile("/Sandbox.rtf");

            Assert.IsNotNull(fileInfo);
        }
예제 #13
0
 public byte[] GetFile(string path)
 {
     return(_dropBoxClient.GetFile(path));
 }
예제 #14
0
 internal byte[] GetBytes(string virtualPath)
 {
     return(Client.GetFile(virtualPath));
 }
예제 #15
0
        static public void filesync()
        {
            //Testing Connection

            if (!LauncherHelper.TestConnection())
            {
                return;
            }


            if (String.IsNullOrEmpty(Properties.Settings.Default.DropBoxUserToken))
            {
                syncAcc(false);
            }

            DropNetClient dbClient = new DropNetClient(Program.Config.AppKey, Program.Config.AppSecret, Properties.Settings.Default.DropBoxUserToken, Properties.Settings.Default.DropBoxUserSecret);

#if DEBUG
            dbClient.UseSandbox = true;
#endif

            DropNet.Models.MetaData meta;

            try
            {
                meta = dbClient.GetMetaData("/");
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.StackTrace + "\n maybe your account is not in the Dropbox Dev group for this App");
                return;
            }


            List <string> filelist = new List <string>();

            if (!Directory.Exists(Program.Config.LauncherDir + "/deck/"))
            {
                Directory.CreateDirectory(Program.Config.LauncherDir + "/deck/");
            }

            if (!Directory.Exists(Program.Config.LauncherDir + "/replay/"))
            {
                Directory.CreateDirectory(Program.Config.LauncherDir + "/replay/");
            }

            foreach (string item in Directory.GetFiles(Program.Config.LauncherDir + "/deck/"))
            {
                filelist.Add(item);
            }


            foreach (string item in Directory.GetFiles(Program.Config.LauncherDir + "/replay/"))
            {
                filelist.Add(item);
            }


            foreach (DropNet.Models.MetaData file in meta.Contents)
            {
                if (Path.GetExtension(file.Name) == ".ydk")
                {
                    if (File.Exists(Program.Config.LauncherDir + "/deck/" + file.Name))
                    {
                        if (DateTime.Compare(file.ModifiedDate, File.GetLastWriteTime(Program.Config.LauncherDir + "/deck/" + file.Name)) < 0)
                        {
                            FileStream fs = new FileStream(Program.Config.LauncherDir + "/deck/" + file.Name, FileMode.Create);
                            fs.Write(dbClient.GetFile(file.Name), 0, dbClient.GetFile(file.Name).Length);
                            fs.Close();
                        }
                        else if (DateTime.Compare(file.ModifiedDate, File.GetLastWriteTime(Program.Config.LauncherDir + "/deck/" + file.Name)) > 0)
                        {
                            FileStream fs     = File.OpenRead(Program.Config.LauncherDir + "/deck/" + file.Name);
                            byte[]     upfile = new byte[fs.Length];
                            fs.Read(upfile, 0, upfile.Length);
                            fs.Close();
                            dbClient.UploadFile("/", file.Name, upfile);
                        }
                    }
                    else
                    {
                        FileStream fs = new FileStream(Program.Config.LauncherDir + "/deck/" + file.Name, FileMode.Create);
                        fs.Write(dbClient.GetFile(file.Name), 0, dbClient.GetFile(file.Name).Length);
                        fs.Close();
                    }
                }
                else if (Path.GetExtension(file.Name) == ".yrp")
                {
                    if (File.Exists(Program.Config.LauncherDir + "/replay/" + file.Name))
                    {
                        if (DateTime.Compare(file.ModifiedDate, File.GetLastWriteTime(Program.Config.LauncherDir + "/deck/" + file.Name)) < 0)
                        {
                            FileStream fs = new FileStream(Program.Config.LauncherDir + "/replay/" + file.Name, FileMode.Create);
                            fs.Write(dbClient.GetFile(file.Name), 0, dbClient.GetFile(file.Name).Length);
                            fs.Close();
                        }
                        else if (DateTime.Compare(file.ModifiedDate, File.GetLastWriteTime(Program.Config.LauncherDir + "/deck/" + file.Name)) > 0)
                        {
                            FileStream fs     = File.OpenRead(Program.Config.LauncherDir + "/replay/" + file.Name);
                            byte[]     upfile = new byte[fs.Length];
                            fs.Read(upfile, 0, upfile.Length);
                            fs.Close();
                            dbClient.UploadFile("/", file.Name, upfile);
                        }
                    }
                    else
                    {
                        FileStream fs = new FileStream(Program.Config.LauncherDir + "/replay/" + file.Name, FileMode.Create);
                        fs.Write(dbClient.GetFile(file.Name), 0, dbClient.GetFile(file.Name).Length);
                        fs.Close();
                    }
                }
            }

            if (filelist.Count > meta.Contents.Count)
            {
                foreach (string file in filelist)
                {
                    if (Path.GetExtension(file) == ".ydk")
                    {
                        FileStream fs     = File.OpenRead(Program.Config.LauncherDir + "/deck/" + Path.GetFileName(file));
                        byte[]     upfile = new byte[fs.Length];
                        fs.Read(upfile, 0, upfile.Length);
                        fs.Close();
                        dbClient.UploadFile("/", Path.GetFileName(file), upfile);
                    }
                    else if (Path.GetExtension(file) == ".yrp")
                    {
                        FileStream fs     = File.OpenRead(Program.Config.LauncherDir + "/replay/" + Path.GetFileName(file));
                        byte[]     upfile = new byte[fs.Length];
                        fs.Read(upfile, 0, upfile.Length);
                        fs.Close();
                        dbClient.UploadFile("/", Path.GetFileName(file), upfile);
                    }
                }
            }

            //MessageBox.Show("yeah!!");
        }
예제 #16
0
        public byte[] DownloadFile(string path)
        {
            var fileBytes = client.GetFile(path);

            return(fileBytes);
        }
예제 #17
0
        public void Can_Get_File()
        {
            var fileInfo = _client.GetFile("/Getting Started.rtf");

            Assert.IsNotNull(fileInfo);
        }
예제 #18
0
 public FileResult Download(string filePath, string fileName)
 {
     byte[] file = _dropBoxClient.GetFile(filePath);
     return(File(file, System.Net.Mime.MediaTypeNames.Application.Octet, fileName));
 }