Ejemplo n.º 1
0
        public string LookupID(string name, string value)
        {
            string sResult = "";

            try
            {
                sResult = oSrv.GetString("_key\\" + name.ToLower() + "\\" + value.ToLower());
            }
            catch { }

            return(sResult);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        public void Init()
        {
            if (Settings == null)
            {
                Settings = new Dictionary <string, string>();
            }

            try
            {
                if (!File.Exists(Assembly.GetExecutingAssembly().Location.Replace(".dll", ".json")))
                {
                    File.WriteAllText(Assembly.GetExecutingAssembly().Location.Replace(".dll", ".json"), Properties.Resources.Plugin_SQLCache);
                }

                if (File.Exists(Assembly.GetExecutingAssembly().Location.Replace(".dll", ".json")))
                {
                    JConfig             = JObject.Parse(File.ReadAllText(Assembly.GetExecutingAssembly().Location.Replace(".dll", ".json")));
                    bReadOnly           = JConfig["ReadOnly"].Value <bool>();
                    ContinueAfterWrite  = JConfig["ContinueAfterWrite"].Value <bool>();
                    CacheFull           = JConfig["CacheFull"].Value <bool>();
                    CacheKeys           = JConfig["CacheKeys"].Value <bool>();
                    SQLConnectionString = JConfig["SQLConnectionString"].Value <string>();
                    SQLTable            = JConfig["SQLTable"].Value <string>();
                    SlidingExpiration   = JConfig["SlidingExpiration"].Value <int>();
                }
                else
                {
                    JConfig = new JObject();
                }

                try
                {
                    SqlServerCacheOptions oOption = new SqlServerCacheOptions()
                    {
                        ConnectionString         = SQLConnectionString,
                        SchemaName               = "dbo",
                        TableName                = "JCache",
                        DefaultSlidingExpiration = new TimeSpan(0, 0, 0, SlidingExpiration)
                    };

                    oSrv = new SqlServerCache(oOption);
                    oSrv.SetString("key1", "value1", new DistributedCacheEntryOptions()
                    {
                        SlidingExpiration = new TimeSpan(1000)
                    });
                }
                catch
                {
                    try
                    {
                        using (SqlConnection connection = new SqlConnection(SQLConnectionString))
                        {
                            SqlCommand command = new SqlCommand(Properties.Resources.CreateTable, connection);
                            command.Connection.Open();
                            command.ExecuteNonQuery();
                        }

                        SqlServerCacheOptions oOption = new SqlServerCacheOptions()
                        {
                            ConnectionString         = SQLConnectionString,
                            SchemaName               = "dbo",
                            TableName                = "JCache",
                            DefaultSlidingExpiration = new TimeSpan(0, 0, 0, SlidingExpiration)
                        };

                        oSrv = new SqlServerCache(oOption);
                        Console.WriteLine("SQL Table 'JCache' created...");
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Error: " + ex.Message);
                    }
                }

                oSrv.SetString("key1", "value1", new DistributedCacheEntryOptions()
                {
                    SlidingExpiration = new TimeSpan(1000)
                });
                Console.WriteLine(oSrv.GetString("key1"));
            }
            catch { }
        }