Пример #1
0
        private async Task LoadData()
        {
            loading            = true;
            loadedDocumentText = await client.SkyDbGetAsString(publicKey, dataKey, TimeSpan.FromSeconds(10));

            loading = false;
        }
Пример #2
0
        static void Main(string[] args)
        {
            if (args.Length != 2)
            {
                Console.WriteLine("Invalid args - should only be the datakey and the file containing the data you want to put");
                return;
            }

            SiaSkynet.SiaSkynetClient c = new SiaSkynetClient();
            bool   seedFileExists       = File.Exists(@".\seed.txt");
            string seed = "";

            if (seedFileExists)
            {
                Console.WriteLine("seed.txt found, generating keys off it");
                seed = System.IO.File.ReadAllText(@".\seed.txt");
            }
            else
            {
                string generatedSeed = GetUniqueString(64);
                System.IO.File.WriteAllText(@".\seed.txt", generatedSeed);
                seed = generatedSeed;
                Console.WriteLine("seed.txt not found, generating a seed randomly and writing it to seed.txt");
            }
            var keys = SiaSkynetClient.GenerateKeys(seed).Result;

            Console.WriteLine("Updating registry at " + args[0] + " with content in " + args[1]);
            string content = System.IO.File.ReadAllText(args[1]);
            bool   r       = c.SkyDbSet(keys.privateKey, keys.publicKey, args[0], content).Result;

            Console.WriteLine("Registry now contains:");
            string actualContent = c.SkyDbGetAsString(keys.publicKey, args[0]).Result;

            Console.WriteLine(actualContent);
        }
Пример #3
0
        private async Task <List <CmsItem> > GetIndexFile(CmsType cmsType)
        {
            //Get index file
            var indexFileName = GenerateFileName(cmsType, "_index", null);

            //Get current index file
            var json = await _client.SkyDbGetAsString(publicKey, new RegistryKey(indexFileName)).ConfigureAwait(false);

            var indexFile = new List <CmsItem>();

            if (json != null)
            {
                indexFile = JsonSerializer.Deserialize <List <CmsItem> >(json);
                indexFile = indexFile ?? new List <CmsItem>();
            }

            return(indexFile);
        }
Пример #4
0
        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);
        }
Пример #5
0
        /// <summary>
        /// Get list with all documents
        /// </summary>
        /// <returns></returns>
        private async Task <List <DocumentSummary> > GetDocumentList()
        {
            try
            {
                Error = null;
                var json = await client.SkyDbGetAsString(publicKey, listDataKey, TimeSpan.FromSeconds(5));

                if (string.IsNullOrEmpty(json))
                {
                    return(new List <DocumentSummary>());
                }
                else
                {
                    return(JsonSerializer.Deserialize <List <DocumentSummary> >(json) ?? new List <DocumentSummary>());
                }
            }
            catch
            {
                Error = "Unable to get list of documents from Skynet. Please try again.";
            }
            return(new List <DocumentSummary>());
        }
Пример #6
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            var sky = new SiaSkynetClient();
            //var upload = sky.UploadFileAsync("next.tar", File.OpenRead("next.tar"));
            //var skyResult = upload.GetAwaiter().GetResult();
            //Console.WriteLine(skyResult.Skylink);
            //Console.WriteLine(skyResult.Merkleroot);
            //Console.WriteLine(skyResult.Bitfield);

            //var download = sky.DownloadFileAsStringAsync("AAC0uO43g64ULpyrW0zO3bjEknSFbAhm8c-RFP21EQlmSQ");
            //Console.WriteLine(download.Result.file);

            var key   = SiaSkynetClient.GenerateKeys("milkey");
            var dbGet = sky.SkyDbGetAsString(key.publicKey, "blazor-sample");

            Console.WriteLine(dbGet.Result);

            var dbSet = sky.SkyDbSet(key.privateKey, key.publicKey, "blazor-sample", "hello");

            Console.WriteLine(dbSet.Result);
        }