Example #1
0
        internal static bool GetCachedFile(string url, string post_parameters, out byte[] binary, out string response_url, out string cached_file)
        {
            //if (!Properties.General.Default.flagUseFilesFromCache || url == null)
            //{
            //    binary = null;
            //    response_url = null;
            //    return false;
            //}
            lock (static_lock_variable)
            {
                if (cache_map == null)
                {
                    if (!restore_cache() && !LogMessage.AskYesNo("Could not restore cache! Continue with no cache?", false))
                    {
                        Log.Exit("Could not restore cache.");
                    }
                }
            }
            lock (cache_map)
            {
                try
                {
                    string url_post = get_url_with_post(url, post_parameters);

                    CacheInfo ci = null;
                    if (custom_cache != null)
                    {
                        string url_key = custom_cache.CreateUrlKey(url_post);
                        cache_map.TryGetValue(url_key, out ci);
                    }
                    if (ci == null)
                    {
                        cache_map.TryGetValue(url_post, out ci);
                    }
                    if (ci == null)
                    {
                        binary       = null;
                        response_url = null;
                        cached_file  = null;
                        return(false);
                    }
                    cached_file = Log.WorkDir + "\\" + ci.path;
                    binary      = File.ReadAllBytes(cached_file);
                    if (ci.response_url != null)
                    {
                        response_url = ci.response_url;
                    }
                    else
                    {
                        response_url = url;
                    }
                    return(true);
                }
                catch (Exception e)
                {
                    Log.Main.Error(e);
                    binary       = null;
                    response_url = null;
                    cached_file  = null;
                    return(false);
                }
            }
        }
Example #2
0
        static void add2cache_map(string url, string path, string response_url)
        {
            lock (cache_map)
            {
                if (url != response_url)
                    cache_map[url] = new CacheInfo(response_url, path);
                else
                    cache_map[url] = new CacheInfo(path);
                if (url != response_url && !string.IsNullOrEmpty(response_url))
                {//POST responses are not added!
                    cache_map[response_url] = new CacheInfo(response_url, path);
                }
                if (custom_cache != null)
                {
                    string url_key = custom_cache.CreateUrlKey(url);
                    if (!cache_map.ContainsKey(url_key))
                        cache_map[url_key] = new CacheInfo(response_url, path);

                    if (url != response_url && response_url != null)
                    {
                        url_key = custom_cache.CreateUrlKey(response_url);
                        if (!cache_map.ContainsKey(url_key))
                            cache_map[url_key] = new CacheInfo(response_url, path);
                    }
                }
            }
        }