public async Task <SaveToCloudOutput> SaveToCloudAsync(CloudBkCollection cloudBkCollection)
    {
        if (!await _googleDriveClient.TestAsync())
        {
            return(new SaveToCloudOutput
            {
                IsOk = false,
                Message = "google not login"
            });
        }

        await _googleDriveClient.UploadAsync(cloudBkCollection);

        var googleDriveStatics = await _simpleDataStorage.GetOrDefaultAsync <GoogleDriveStatics>();

        googleDriveStatics.LastSuccessUploadTime = _clock.UtcNow;
        await _simpleDataStorage.SaveAsync(googleDriveStatics);

        var re = new SaveToCloudOutput
        {
            IsOk = true
        };

        return(re);
    }
Пример #2
0
    public async Task LoadCloudCollectionAsync(CloudBkCollection cloudBkCollection)
    {
        var bks = await _bkRepo.GetAllAsync();

        var dictByUrlHash = bks.ToDictionary(x => x.UrlHash);

        foreach (var(urlHash, cloudBk) in cloudBkCollection.Bks)
        {
            if (dictByUrlHash.TryGetValue(urlHash, out var localBk))
            {
                localBk.Tags = cloudBk.Tags;
                await _bkRepo.UpsertAsync(localBk);
            }
        }

        var cloudTags = cloudBkCollection.Bks.SelectMany(x => x.Value.Tags).ToHashSet();

        foreach (var cloudBkTag in cloudTags)
        {
            await AppendTagsAsync(cloudBkTag);
        }

        await _bkMetadataRepo.UpsertAsync(new BkMetadata
        {
            EtagVersion    = cloudBkCollection.EtagVersion,
            LastUpdateTime = cloudBkCollection.LastUpdateTime,
            Id             = Consts.SingleOneDataId
        });
    }
Пример #3
0
    public async Task <SaveToCloudOutput> SaveToCloudAsync(CloudBkCollection cloudBkCollection)
    {
        var resp = await _cloudBkApi.SaveToCloudAsync(cloudBkCollection);

        await resp.EnsureSuccessStatusCodeAsync();

        return(resp.Content !);
    }