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; }
public String GetMedialUrl(string path, AuthCredential credential) { if (String.IsNullOrEmpty(path)) { return null; } var _client = new DropNetClient(MogConstants.DROPBOX_KEY, MogConstants.DROPBOX_SECRET); UserLogin User = new UserLogin() { Token = credential.Token, Secret = credential.Secret }; _client.UserLogin = User; _client.UseSandbox = true; ShareResponse response = _client.GetMedia(path); return (response != null ? response.Url : null); }
public void SaveChanges(AuthCredential partialCredential) { this.dbContext.Entry(partialCredential).State = System.Data.Entity.EntityState.Modified; this.dbContext.SaveChanges(); }
public bool Delete(AuthCredential credential) { this.dbContext.AuthCredentials.Remove(credential); this.dbContext.SaveChanges(); return true; }
public bool Create(AuthCredential credential) { dbContext.AuthCredentials.Add(credential); int result = dbContext.SaveChanges(); return (result > 0); }
public MogFile UploadFile(System.IO.MemoryStream ms, string internalName, AuthCredential authCredential, string path) { byte[] buffer = ms.ToArray(); return UploadFile(buffer, internalName, authCredential, path); }
private MetaData Upload(byte[] data, string filename, AuthCredential credential, string remotePath = null) { UserLogin User = new UserLogin() { Token = credential.Token, Secret = credential.Secret }; string file = System.IO.Path.GetFileName(filename); var _client = new DropNetClient(MogConstants.DROPBOX_KEY, MogConstants.DROPBOX_SECRET); _client.UserLogin = User; _client.UseSandbox = true; if (String.IsNullOrEmpty(remotePath)) { remotePath = "/"; } var uploaded = _client.UploadFile(remotePath, file, data); //FileInfo return uploaded; }
public MogFile UploadFile(byte[] data, string filename, AuthCredential credential, string remotePath = null) { MetaData meta = this.Upload(data, filename, credential, remotePath); if (!String.IsNullOrEmpty(meta.Name)) {//ok upload went fine ProjectFile file = new ProjectFile(); file.InternalName = meta.Name; file.DisplayName = meta.Name; file.CreatedOn = DateTime.Now; file.Path = meta.Path; return file; } return null; }
public MogFile UploadFile(string filename, AuthCredential credential, string remotePath = null) { //upload file to dropbox //if everything is OK, return the file byte[] data = System.IO.File.ReadAllBytes(filename); return UploadFile(data, filename, credential, remotePath); }
public String GetMedialUrl(string path, AuthCredential credential) { return null; // return (response != null ? response.Url : null); }
private object Upload(byte[] data, string filename, AuthCredential credential, string remotePath = null) { string file = System.IO.Path.GetFileName(filename); OAuthToken token = new OAuthToken(); token.AccessToken = credential.Token; token.AuthenticationToken = credential.Authentication; token.RefreshToken = credential.Refresh; dynamic result = null; OAuthError error = null; string destinationFolderId = null; try { destinationFolderId = createFolderIfNotExists("", remotePath, token, out error); } catch (UnauthorizedAccessException ) { RequestAccessTokenByRefreshToken(token.RefreshToken, MogConstants.SKYDRIVE_REDIRECTURL, out token, out error); credential.Token = token.AccessToken; credential.Authentication = token.AuthenticationToken; credential.Refresh = token.RefreshToken; this.repoAuthCredential.SaveChanges(credential); destinationFolderId = createFolderIfNotExists("", remotePath, token, out error); } var url = string.Format("{0}/{1}/files/{2}?access_token={3}", skydriveApiUrl, destinationFolderId, filename, token.AccessToken); try { var request = (HttpWebRequest)HttpWebRequest.Create(url); request.Method = "PUT"; request.ContentLength = data.Length; using (var dataStream = request.GetRequestStream()) { dataStream.Write(data, 0, data.Length); } WebResponse response = request.GetResponse(); StreamReader reader = new StreamReader(response.GetResponseStream()); string json = reader.ReadToEnd(); result = JsonConvert.DeserializeObject<dynamic>(json); } catch (Exception e) { //todo : do something with exception } return result; }
public void RegisterAccount(OAuthToken token, UserProfileInfo user) { LiveAuthClient auth = new LiveAuthClient(clientId, clientSecret, MogConstants.SKYDRIVE_REDIRECTURL); AuthCredential credential = new AuthCredential(); credential.CloudService = CloudStorageServices.Skydrive; credential.Token = token.AccessToken; credential.Refresh = token.RefreshToken; credential.Authentication = token.AuthenticationToken; credential.Status = CredentialStatus.Approved; credential.UserId = user.Id; credential.Login = auth.GetUserId(token.AuthenticationToken); this.repoAuthCredential.Create(credential); }