public async Task Write <T>(T item, CmsType cmsType, Guid id, string?lang, string?currentUser) where T : CmsItem { var fileName = GenerateFileName(cmsType, id, lang); string itemJson = JsonSerializer.Serialize(item); await _client.SkyDbSetAsString(privateKey, publicKey, new RegistryKey(fileName), itemJson).ConfigureAwait(false); //Write index file for paging and sorting var indexFileName = GenerateFileName(cmsType, "_index", lang); var typeInfo = cmsConfiguration.MenuItems.Where(x => x.Key == cmsType.Value).FirstOrDefault(); if (typeInfo == null) { return; } //Get current index file List <CmsItem>?indexFile = await GetIndexFile(cmsType).ConfigureAwait(false); //Remove existing item CmsItem?oldItem = indexFile.Where(x => x.Id == item.Id).FirstOrDefault(); if (oldItem != null) { indexFile.Remove(oldItem); } var indexItem = new CmsItem { Id = id, CmsType = cmsType, LastModifiedBy = item.LastModifiedBy, LastModifiedDate = item.LastModifiedDate }; if (oldItem != null) { indexItem.CreatedDate = oldItem.CreatedDate; } foreach (var prop in typeInfo.ListViewProperties) { var value = item.AdditionalProperties[prop.Key]; indexItem.AdditionalProperties[prop.Key] = value; } indexFile.Add(indexItem); string indexFileJson = JsonSerializer.Serialize(indexFile); await _client.SkyDbSetAsString(privateKey, publicKey, new RegistryKey(indexFileName), indexFileJson).ConfigureAwait(false); }
private async Task SaveData() { saving = true; success = await client.SkyDbSetAsString(privateKey, publicKey, dataKey, documentText); saving = false; }
public async Task TestSkyDbUpdate() { RegistryKey dataKey = new RegistryKey("skydbtest-" + Guid.NewGuid()); var key = SiaSkynetClient.GenerateKeys(_testSeed); var success = await _client.SkyDbSetAsString(key.privateKey, key.publicKey, dataKey, "update1"); Assert.IsTrue(success); await Task.Delay(TimeSpan.FromSeconds(5)); var success2 = await _client.SkyDbSetAsString(key.privateKey, key.publicKey, dataKey, "update2"); await Task.Delay(TimeSpan.FromSeconds(5)); string result = await _client.SkyDbGetAsString(key.publicKey, dataKey); Assert.IsTrue(success); Assert.IsTrue(success2); Assert.AreEqual("update2", result); }