Exemplo n.º 1
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;
        }
Exemplo n.º 2
0
 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);
 }
Exemplo n.º 3
0
 public void SaveChanges(AuthCredential partialCredential)
 {
     this.dbContext.Entry(partialCredential).State = System.Data.Entity.EntityState.Modified;
     this.dbContext.SaveChanges();
 }
Exemplo n.º 4
0
 public bool Delete(AuthCredential credential)
 {
     this.dbContext.AuthCredentials.Remove(credential);
     this.dbContext.SaveChanges();
     return true;
 }
Exemplo n.º 5
0
 public bool Create(AuthCredential credential)
 {
     dbContext.AuthCredentials.Add(credential);
     int result = dbContext.SaveChanges();
     return (result > 0);
 }
Exemplo n.º 6
0
 public MogFile UploadFile(System.IO.MemoryStream ms, string internalName, AuthCredential authCredential, string path)
 {
     byte[] buffer = ms.ToArray();
     return UploadFile(buffer, internalName, authCredential, path);
 }
Exemplo n.º 7
0
        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;
        }
Exemplo n.º 8
0
        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;
        }
Exemplo n.º 9
0
 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);
 }
Exemplo n.º 10
0
 public String GetMedialUrl(string path, AuthCredential credential)
 {
     return null;
     //                return (response != null ? response.Url : null);
 }
Exemplo n.º 11
0
        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;
        }
Exemplo n.º 12
0
        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);
        }