Ejemplo n.º 1
0
        /// <summary>
        /// Upload the specified data file to the cloud storage service.
        /// </summary>
        /// <param name="clipboardDataPath">The full path to the clipboard data folder.</param>
        /// <param name="cloudFolder">The <see cref="CloudFolder"/> that contains informations about the application folder.</param>
        /// <param name="cloudDataPassword">The supposed password that we will use to encrypt the data before uploading it to the cloud.</param>
        /// <param name="dataIdentifier">The data identifier used to determines which file will be uploaded.</param>
        /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
        private async Task UploadDataFileAsync(string clipboardDataPath, CloudFolder cloudFolder, SecureString cloudDataPassword, DataIdentifier dataIdentifier)
        {
            var dataService                = ServiceLocator.GetService <DataService>();
            var fileName                   = $"{dataIdentifier.Identifier}.dat";
            var cloudDataFilePath          = Path.Combine(cloudFolder.FullPath, fileName);
            var localDataFilePath          = Path.Combine(clipboardDataPath, fileName);
            var temporaryLocalDataFilePath = Path.Combine(clipboardDataPath, $"{fileName}.temp");
            var localDataPassword          = SecurityHelper.ToSecureString(SecurityHelper.EncryptString(SecurityHelper.ToSecureString(dataIdentifier.Identifier.ToString())));

            Requires.NotNull(localDataPassword, nameof(localDataPassword));

            if (!File.Exists(localDataFilePath))
            {
                Logger.Instance.Warning($"Data file {dataIdentifier.Identifier} not found locally, it has probably been removed while synchronizing.");
                return;
            }

            using (var fileStream = File.OpenRead(localDataFilePath))
                using (var temporaryLocalFileStream = File.Open(temporaryLocalDataFilePath, FileMode.OpenOrCreate, FileAccess.ReadWrite))
                    using (var localAesStream = new AesStream(fileStream, localDataPassword, SecurityHelper.GetSaltKeys(localDataPassword).GetBytes(16)))
                        using (var cloudAesStream = new AesStream(temporaryLocalFileStream, cloudDataPassword, SecurityHelper.GetSaltKeys(cloudDataPassword).GetBytes(16)))
                        {
                            dataService.CopyData(localAesStream, cloudAesStream);
                            await CurrentCloudStorageProvider.UploadFileAsync(temporaryLocalFileStream, cloudDataFilePath);
                        }

            if (File.Exists(temporaryLocalDataFilePath))
            {
                File.Delete(temporaryLocalDataFilePath);
            }
        }
Ejemplo n.º 2
0
        public void Favorites()
        {
            string docs = Settings.Username + "/Documents";

            RunTest(CloudFolder.SetFavorite(Api, docs, true));
            ShowList(CloudFolder.GetFavorites(Api, Settings.Username, CloudInfo.Properties.All));
            RunTest(CloudFolder.SetFavorite(Api, docs, true));
            ShowList(CloudFolder.GetFavorites(Api, Settings.Username));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Delete a data from the server
        /// </summary>
        /// <param name="cloudFolder">The <see cref="CloudFolder"/> that contains informations about the application folder.</param>
        /// <param name="dataIdentifier">The data identifier used to determines which file will be uploaded.</param>
        /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
        private async Task DeleteFileAsync(CloudFolder cloudFolder, DataIdentifier dataIdentifier)
        {
            var fileName          = $"{dataIdentifier.Identifier}.dat";
            var cloudDataFilePath = Path.Combine(cloudFolder.FullPath, fileName);

            if (cloudFolder.Files.Any(file => file.FullPath == cloudDataFilePath))
            {
                await CurrentCloudStorageProvider.DeleteFileAsync(cloudDataFilePath);
            }
        }
Ejemplo n.º 4
0
        public IHttpActionResult addCloudFolder([FromBody] CloudFolder cloudFolder, string parentFolderCode)
        {
            if (cloudFolder == null)
            {
                return(BadRequest("Invalid Data"));
            }

            if (cloudFolder.Name == null || cloudFolder.Name.Length == 0)
            {
                return(BadRequest(""));
            }

            int?parentID = null;

            if (parentFolderCode != null && parentFolderCode != "0")
            {
                var parent = DB.CloudFolders.Where(item => item.Code == parentFolderCode).FirstOrDefault();
                if (parent != null)
                {
                    parentID = parent.ID;
                }
            }

            int userID    = UserInfo.GetCurrentUserID();
            int companyID = UserInfo.GetCurrentCompanyID();

            cloudFolder.Code           = Guid.NewGuid().ToString("N");
            cloudFolder.CreateByID     = userID;
            cloudFolder.CreateDatetime = DateTime.Now;
            cloudFolder.CompanyID      = companyID;
            cloudFolder.ParentID       = parentID;

            if (!_repository.Insert(cloudFolder, out msg, true))
            {
                return(BadRequest(msg));
            }

            return(Ok(cloudFolder));
        }
Ejemplo n.º 5
0
        public IHttpActionResult UploadFile(string uploadFolderCode)
        {
            int           companyID = UserInfo.GetCurrentCompanyID();
            UploadMessage returnMsg = _uploadFile(companyID.ToString(), "oa");

            if (returnMsg.Status > 0)
            {
                return(BadRequest(returnMsg.ErrorMsg));
            }
            else
            {
                CloudFolder cloudFolder = DB.CloudFolders.Where(item => item.Code == uploadFolderCode && item.CompanyID == companyID).FirstOrDefault();
                if (cloudFolder != null)
                {
                    CloudFile cf = new CloudFile();
                    cf.CloudFolderID        = cloudFolder.ID;
                    cf.CompanyID            = companyID;
                    cf.EntityCode           = "Cloud";
                    cf.OriginName           = returnMsg.OriginName;
                    cf.FileName             = returnMsg.FileName;
                    cf.FileTypeName         = returnMsg.FileType;
                    cf.FileSize             = returnMsg.FileSize;
                    cf.FilePath             = returnMsg.UploadFilePath;
                    cf.DiskUploadPath       = returnMsg.DiskUploadPath;
                    cf.CreateDatetime       = DateTime.Now;
                    cf.CreateByID           = UserInfo.GetCurrentUserID();
                    cf.IsValidImage         = returnMsg.IsImage;
                    cf.HasThumbnail         = returnMsg.HasThumbnail;
                    cf.OriginDiskUploadPath = returnMsg.OriginDiskUploadPath;
                    cf.OriginFilePath       = returnMsg.OriginFilePath;

                    DB.CloudFiles.Add(cf);
                    DB.SaveChanges();
                }
                return(Ok(returnMsg));
            }
        }
Ejemplo n.º 6
0
 public void DeleteFolder()
 {
     RunTest(CloudFolder.Delete(Api, Settings.Username + "/Documents/test"));
 }
Ejemplo n.º 7
0
 public void ListAll()
 {
     ShowList(CloudFolder.List(Api, Settings.Username + "/Documents", CloudInfo.Properties.All));
 }
Ejemplo n.º 8
0
 public void List()
 {
     ShowList(CloudFolder.List(Api, Settings.Username));
 }