Esempio n. 1
0
        protected List <T> GetListAll <T>(string commandText, params string[] referTables) where T : class
        {
            try
            {
                if (UseCaching && referTables.Length > 0)
                {
                    spCachedName = commandText;

                    keyCached =
                        (ConnectionUtil.Instance.GetConnectionString() + ":" + spCachedName + ":" + typeof(T).FullName).
                        GetHashCode().ToString();

                    if (String.IsNullOrEmpty(macAddresses))
                    {
                        macAddresses = GetMacAddress();
                    }

                    isRefreshedCache = IsRefreshed(keyCached, macAddresses);

                    if (isRefreshedCache == true && CacheIsolatedStorage.Contains(keyCached))
                    {
                        return(CacheIsolatedStorage[keyCached] as List <T>);
                    }

                    this.referTables = referTables;

                    if (CacheIsolatedStorage.Contains(keyCached))
                    {
                        var genericThread = (GenericThread <T>)threadCache;

                        if (genericThread == null || genericThread.ThreadState == ThreadState.Stopped ||
                            genericThread.ThreadState == ThreadState.Unstarted ||
                            genericThread.ThreadState == ThreadState.Aborted)
                        {
                            threadCache = new GenericThread <T>(GetCache <T>);

                            genericThread = (GenericThread <T>)threadCache;

                            genericThread.Start();
                        }

                        return(CacheIsolatedStorage[keyCached] as List <T>);
                    }

                    var result = GetListAll <T>(spCachedName);

                    CacheIsolatedStorage.Add(keyCached, result);

                    for (var i = 0; i < referTables.Length; i++)
                    {
                        referTables[i] = referTables[i].GetHashCode().ToString();
                    }

                    SaveCg(keyCached, macAddresses, String.Format(",{0},", String.Join(",", referTables)), isRefreshedCache != null);

                    return(result);
                }

                return(GetListAll <T>(commandText));
            }
            catch (Exception ex)
            {
                throw new ManagedException(ex.Message, false, commandText, referTables);
            }
        }
Esempio n. 2
0
        private void GetCache <T>() where T : class
        {
            List <T> result = null;

            if (!String.IsNullOrEmpty(TrackField) &&

                spCachedName.ToLower().Trim().StartsWith("select "))
            {
                var lastRefreshed = LastRefreshed(keyCached, macAddresses);

                if (lastRefreshed > DateTime.MinValue)
                {
                    result = CacheIsolatedStorage[keyCached] as List <T>;

                    var tmp =

                        GetListCommand <T>(

                            spCachedName +

                            (spCachedName.ToLower().Contains(" where ") ? " and " : " where ") +

                            String.Format("{0} >= to_date(:lastRereshed, 'dd/mm/rrrr')", TrackField),

                            lastRefreshed.ToString("dd/MM/yyyy"));

                    foreach (var objData in tmp)
                    {
                        if (result != null)
                        {
                            var obj2 = result.Find(delegate(T match) { return(match.Equals(objData)); });

                            if (obj2 != null)
                            {
                                result[result.IndexOf(obj2)] = objData;
                            }

                            else
                            {
                                result.Add(objData);
                            }
                        }
                    }
                }
                else
                {
                    result = GetListCommand <T>(spCachedName);
                }
            }
            else
            {
                result = GetListCommand <T>(spCachedName);
            }

            CacheIsolatedStorage.Add(keyCached, result);

            //result = null;

            //GC.Collect();

            //if (!String.IsNullOrEmpty(Convert.ToString(result)))
            //    File.AppendAllText(AppDomain.CurrentDomain.BaseDirectory + String.Format("\\{0}.log", Path.GetRandomFileName()),
            //                       Convert.ToString(result));

            for (int i = 0; i < referTables.Length; i++)
            {
                referTables[i] = referTables[i].GetHashCode().ToString();
            }

            SaveCg(keyCached, macAddresses, String.Format(",{0},", String.Join(",", referTables)), isRefreshedCache != null);
        }