Exemple #1
0
        public string ReadHash(string Hash, string Collection)
        {
            string sResult = "";

            try
            {
                string Coll2 = Collection;
                //Remove invalid Characters in Path anf File
                foreach (var sChar in Path.GetInvalidPathChars())
                {
                    Coll2 = Coll2.Replace(sChar.ToString(), "");
                    Hash  = Hash.Replace(sChar.ToString(), "");
                }

                sResult = oSrv.GetString(Collection + "\\" + Hash);
                if (!string.IsNullOrEmpty(sResult))
                {
                    oSrv.RefreshAsync(Collection + "\\" + Hash);
                }

#if DEBUG
                //Check if hashes are valid...
                if (Collection != "_full" && Collection != "_chain" && Collection != "_assets")
                {
                    var jData = JObject.Parse(sResult);

                    /*if (jData["#id"] != null)
                     *  jData.Remove("#id");*/
                    if (jData["_date"] != null)
                    {
                        jData.Remove("_date");
                    }
                    if (jData["_index"] != null)
                    {
                        jData.Remove("_index");
                    }

                    string s1 = jaindb.jDB.CalculateHash(jData.ToString(Newtonsoft.Json.Formatting.None));
                    if (Hash != s1)
                    {
                        s1.ToString();
                        return("");
                    }
                }
#endif
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Error ReadHash_1: " + ex.Message.ToString());
            }
            return(sResult);
        }
Exemple #2
0
        public static async Task RunSampleAsync()
        {
            var configurationBuilder = new ConfigurationBuilder();
            var configuration        = configurationBuilder
                                       .AddJsonFile("config.json")
                                       .AddEnvironmentVariables()
                                       .Build();

            var key     = Guid.NewGuid().ToString();
            var message = "Hello, World!";
            var value   = Encoding.UTF8.GetBytes(message);

            Console.WriteLine("Connecting to cache");
            var cache = new SqlServerCache(new SqlServerCacheOptions()
            {
                ConnectionString = configuration["ConnectionString"],
                SchemaName       = configuration["SchemaName"],
                TableName        = configuration["TableName"]
            });

            Console.WriteLine("Connected");

            Console.WriteLine("Cache item key: {0}", key);
            Console.WriteLine($"Setting value '{message}' in cache");
            await cache.SetAsync(
                key,
                value,
                new DistributedCacheEntryOptions().SetSlidingExpiration(TimeSpan.FromSeconds(10)));

            Console.WriteLine("Set");

            Console.WriteLine("Getting value from cache");
            value = await cache.GetAsync(key);

            if (value != null)
            {
                Console.WriteLine("Retrieved: " + Encoding.UTF8.GetString(value, 0, value.Length));
            }
            else
            {
                Console.WriteLine("Not Found");
            }

            Console.WriteLine("Refreshing value in cache");
            await cache.RefreshAsync(key);

            Console.WriteLine("Refreshed");

            Console.WriteLine("Removing value from cache");
            await cache.RemoveAsync(key);

            Console.WriteLine("Removed");

            Console.WriteLine("Getting value from cache again");
            value = await cache.GetAsync(key);

            if (value != null)
            {
                Console.WriteLine("Retrieved: " + Encoding.UTF8.GetString(value, 0, value.Length));
            }
            else
            {
                Console.WriteLine("Not Found");
            }

            Console.ReadLine();
        }
Exemple #3
0
        public async Task RunSampleAsync()
        {
            var key     = Guid.NewGuid().ToString();
            var message = "Hello, World!";
            var value   = Encoding.UTF8.GetBytes(message);

            Console.WriteLine("Connecting to cache");
            var cache = new SqlServerCache(
                new CacheOptions(
                    new SqlServerCacheOptions()
            {
                ConnectionString = Configuration.Get("ConnectionString"),
                SchemaName       = Configuration.Get("SchemaName"),
                TableName        = Configuration.Get("TableName")
            }));
            await cache.ConnectAsync();

            Console.WriteLine("Connected");

            Console.WriteLine("Cache item key: {0}", key);
            Console.WriteLine($"Setting value '{message}' in cache");
            await cache.SetAsync(
                key,
                value,
                new DistributedCacheEntryOptions().SetSlidingExpiration(TimeSpan.FromSeconds(10)));

            Console.WriteLine("Set");

            Console.WriteLine("Getting value from cache");
            value = await cache.GetAsync(key);

            if (value != null)
            {
                Console.WriteLine("Retrieved: " + Encoding.UTF8.GetString(value));
            }
            else
            {
                Console.WriteLine("Not Found");
            }

            Console.WriteLine("Refreshing value in cache");
            await cache.RefreshAsync(key);

            Console.WriteLine("Refreshed");

            Console.WriteLine("Removing value from cache");
            await cache.RemoveAsync(key);

            Console.WriteLine("Removed");

            Console.WriteLine("Getting value from cache again");
            value = await cache.GetAsync(key);

            if (value != null)
            {
                Console.WriteLine("Retrieved: " + Encoding.UTF8.GetString(value));
            }
            else
            {
                Console.WriteLine("Not Found");
            }

            Console.ReadLine();
        }