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 FileInfo() { FileInfo file = CreateFileForTheCurrentDirectory(); FileResource res = new FileResource(TemporaryFileName); Assert.AreEqual(file.FullName.ToLowerInvariant(), res.File.FullName.ToLowerInvariant(), "The bare file name all by itself must have resolved to a file in the current directory of the currently executing domain."); }
internal static void Main() { //Console.WriteLine(votterData.Pictures.All().Count()); // Testing Dropbox var dropbox = new DropBoxCloudConnector(); string testPicture = @"../../Resources/1.png"; var file = new FileResource(testPicture); var uploadedGirl = dropbox.UploadGirlsToCloud(file); var uploadedBoy = dropbox.UploadBoysToCloud(file); var picGirlLink = dropbox.GetPictureLink("/Girls/1.png"); var picBoyLink = dropbox.GetPictureLink("/Boys/1.png"); Console.WriteLine(picGirlLink.Url); Console.WriteLine(picBoyLink.Url); // Testing Pubnub var pubnub = new PubnubAlert(); pubnub.Start(); while (true) { string msg = Console.ReadLine(); pubnub.PublishMessage(msg); } }
public void FileResourceValidStream() { FileInfo file = GetAssemblyLocation(Assembly.GetExecutingAssembly()); FileResource res = new FileResource(file.FullName); using (Stream stream = res.GetStream()) { Assert.IsNotNull(stream); Assert.IsTrue(stream.CanRead); } }
internal static void Main() { // Console.WriteLine(CFHData.Files.All()); // Testing Dropbox var dropbox = new DropBoxCloudConnector(); string testFile = @"../../Resources/1.png"; var file = new FileResource(testFile); var uploadedGirl = dropbox.UploadFileToCloud(file); var fileLink = dropbox.GetFileLink("/File/1.png"); Console.WriteLine(fileLink.Url); }
public void PostFile(FileModel file) { DropboxServiceProvider dropboxServiceProvider = new DropboxServiceProvider(DropboxAppKey, DropboxAppSecret, AccessLevel.AppFolder); OAuthToken oauthAccessToken = new OAuthToken("9gyo6l0xq3l7kdd0", "ly7ayinrqbocfy8"); // Login in Dropbox IDropbox dropbox = dropboxServiceProvider.GetApi(oauthAccessToken.Value, oauthAccessToken.Secret); // Create new folder string newFolderName = "New_Folder_" + DateTime.Now.Ticks; Entry createFolderEntry = dropbox.CreateFolderAsync(newFolderName).Result; // Upload a file IResource fileResource = new FileResource(file.Path + "/" + file.Name); Entry uploadFileEntry = dropbox.UploadFileAsync(fileResource, "/" + newFolderName + "/" + file.Name).Result; // Share a file DropboxLink sharedUrl = dropbox.GetMediaLinkAsync(uploadFileEntry.Path).Result; // Update database Message newMessage = new Message() { Content = sharedUrl.Url.ToString(), SendTime = DateTime.Now, User = (from users in db.Users where users.UserId == file.UserId select users).FirstOrDefault(), UserId = file.UserId, RecieverId = file.RecieverId }; if (file.IsProfilePic) { User currentUser = (from users in db.Users where users.UserId == file.UserId select users).FirstOrDefault(); currentUser.ProfilePicUrl = sharedUrl.Url.ToString(); } db.Messages.Add(newMessage); db.SaveChanges(); }
private static void Main() { var 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 = "Images_" + DateTime.Now.Ticks; Entry createFolderEntry = dropbox.CreateFolderAsync(newFolderName).Result; Console.WriteLine("Created folder: {0}", createFolderEntry.Path); foreach (var file in Directory.GetFiles(ImagesFolder)) { var resource = new FileResource(file); var fileName = resource.File.Name; // Upload Image var upload = dropbox.UploadFileAsync(resource, fileName, true, null, CancellationToken.None).Result; // Print path Console.WriteLine("Uploaded a file: {0}", upload.Path); // Share Image var sharedUrl = dropbox.GetShareableLinkAsync(upload.Path).Result; Process.Start(sharedUrl.Url); } }
public void ReadStreamMultipleTimes() { FileInfo file = GetAssemblyLocation(Assembly.GetExecutingAssembly()); FileResource res = new FileResource(file.FullName); Assert.IsFalse(res.IsOpen); using (Stream stream = res.GetStream()) { Assert.IsNotNull(stream); } using (Stream stream = res.GetStream()) { Assert.IsNotNull(stream); } }
public void GetUri() { FileResource res = new FileResource(TemporaryFileName); Assert.IsNotNull(res.Uri); }
public void FileSystemResourceOpenNonExistanceFile() { FileResource res = new FileResource(TemporaryFileName); Stream stream = res.GetStream(); }
public void CreateFileSystemResourceWithPathName() { FileResource res = new FileResource(TemporaryFileName); Assert.AreEqual(TemporaryFileName, res.File.Name); }
public Entry UploadBoysToCloud(FileResource resource) { string collection = "/" + BoysCollection + "/" + resource.File.Name; var entry = this.dropBoxCloud.UploadToCloud(resource, collection); return entry; }
public async Task<IHttpActionResult> Add(string message, int problemId) { var problem = this.data.Problems.Find(problemId); if (problem == null) { return NotFound(); } if (Request.Content.IsMimeMultipartContent()) { var path = Path.GetTempPath(); var streamProvider = new MultipartFormDataStreamProvider(path); await Request.Content.ReadAsMultipartAsync(streamProvider); foreach (MultipartFileData fileData in streamProvider.FileData) { if (string.IsNullOrEmpty(fileData.Headers.ContentDisposition.FileName)) { return BadRequest(); } string fileName = fileData.Headers.ContentDisposition.FileName; if (fileName.StartsWith("\"") && fileName.EndsWith("\"")) { fileName = fileName.Trim('"'); } if (fileName.Contains(@"/") || fileName.Contains(@"\")) { fileName = Path.GetFileName(fileName); } var finalPath = Path.Combine(StoragePath, fileName); File.Move(fileData.LocalFileName, finalPath); var file = new FileResource(finalPath); var uploadedfFile = this.dropbox.UploadFileToCloud(file); var fileUrl = dropbox.GetFileLink(uploadedfFile.Path).Url; var downloadPath = new DownloadPath() { AddDate = DateTime.Now, Link = fileUrl, Message = message, }; problem.DownloadPaths.Add(downloadPath); try { this.data.SaveChanges(); } catch (Exception) { return BadRequest(); } return Ok(downloadPath.Link); } return Ok(); } else { return BadRequest(); } }
public void WriteWithCustomExtension() { IResource body = new FileResource(@"C:\Dummy.myext"); MockHttpOutputMessage message = new MockHttpOutputMessage(); converter.MimeMapping.Add(".myext", "spring/custom"); converter.Write(body, null, message); Assert.AreEqual(new MediaType("spring", "custom"), message.Headers.ContentType, "Invalid content-type"); }
public void WriteWithUnknownExtension() { IResource body = new FileResource(@"C:\Dummy.unknown"); MockHttpOutputMessage message = new MockHttpOutputMessage(); converter.Write(body, null, message); Assert.AreEqual(new MediaType("application", "octet-stream"), message.Headers.ContentType, "Invalid content-type"); }
public void WriteWithKnownExtension() { IResource body = new FileResource(@"C:\Dummy.txt"); MockHttpOutputMessage message = new MockHttpOutputMessage(); converter.Write(body, null, message); Assert.AreEqual(new MediaType("text", "plain"), message.Headers.ContentType, "Invalid content-type"); }
public Entry UploadToCloud(FileResource resource, string folder) { Entry uploadFileEntry = this.dropboxApi.UploadFileAsync(resource, folder).Result; return uploadFileEntry; }