private void ProcessRemoteFile(
            StorageFile remoteFile,
            List <StorageItem> localItems,
            EncryptedFolder folder,
            SyncConcurrentQueue queue,
            IStorage localStorage,
            string localFolderPath)
        {
            var encryptedFile = folder.Files.FirstOrDefault(f => f.EncryptedName == remoteFile.Name);

            if (encryptedFile == null)
            {
                // remote file does not exists in db, we can't recrypt it
                // todo add sync error
                return;
            }

            var localPath  = Path.Combine(localFolderPath, encryptedFile.Name);
            var localItem  = localItems.OfType <StorageFile>().FirstOrDefault(l => l.Name == encryptedFile.Name);
            var itemStatus = GetItemStatus(localItem, remoteFile, encryptedFile);

            if (itemStatus != null)
            {
                queue.Enqueue(
                    new QueueItem
                {
                    Status        = itemStatus.Value,
                    LocalStorage  = localStorage,
                    LocalPath     = localPath,
                    RemotePath    = remoteFile.FullPath,
                    RemoteStorage = this.remoteStorage,
                    EncryptedFile = encryptedFile
                });
            }
        }
        private void ProcessLocalFile(
            StorageFile localFile,
            List <StorageItem> remoteItems,
            EncryptedFolder folder,
            SyncConcurrentQueue queue,
            IStorage localStorage,
            string remoteFolderPath)
        {
            var encryptedFile = folder.Files.FirstOrDefault(f => f.Name == localFile.Name);

            if (encryptedFile == null)
            {
                // file doesn't exists in remote
                encryptedFile = new EncryptedFile
                {
                    Name            = localFile.Name,
                    Created         = localFile.Modified,
                    Modified        = localFile.Modified,
                    EncryptedName   = Guid.NewGuid().ToString(),
                    UnencryptedSize = localFile.Size,
                    // todo Hash =
                    FolderId = folder.Id,
                    Folder   = folder
                };
                encryptedFile = this.db.Files.Add(encryptedFile).Entity;
                this.db.SaveChangesAsync();
            }
            else
            {
                var remoteExists = remoteItems.Any(x => x.Name == encryptedFile.EncryptedName);
                if (remoteExists)
                {
                    // already processed at remote processing
                    return;
                }
            }

            queue.Enqueue(
                new QueueItem
            {
                Status        = QueueItemStatus.WaitingForUpload,
                LocalStorage  = localStorage,
                LocalPath     = localFile.FullPath,
                RemotePath    = Path.Combine(remoteFolderPath, encryptedFile.EncryptedName),
                RemoteStorage = this.remoteStorage,
                EncryptedFile = encryptedFile
            });
        }