Example #1
0
 void Errorhandler_Loggeditem(object sender, CedLib.LogEventArgs Le)
 {
     richTextBox1.Text += "\nNew item logged!: " + Le.Logitem();
 }
Example #2
0
            public static CachedReply CachedRequest(Uri ContentUrl, bool getfresh = false, DirectoryInfo CacheDir = null, CedLib.Logging logger = null)
            {
                bool FromCache = false;

                if (CacheDir == null)
                    CacheDir = new DirectoryInfo("./WebCache");

                FileStream fstream = null;
                if (!Directory.Exists(CacheDir.ToString()))
                    Directory.CreateDirectory(CacheDir.ToString());
                string cachedfilename = CedLib.misc_usefulfunctions.MakeValidFileName(ContentUrl.AbsoluteUri.ToLower());
                cachedfilename = CacheDir.ToString() + "/" + cachedfilename;
                if (!File.Exists(cachedfilename))
                {
                    if (logger != null)
                        logger.log("URL is not cached, getting fresh content..", CedLib.Logging.Priority.Notice);
                    System.Net.WebClient Wclient = new System.Net.WebClient();
                    byte[] kaas = Wclient.DownloadData(ContentUrl);
                    File.WriteAllBytes(cachedfilename, kaas);
                }
                else if (File.Exists(cachedfilename) && getfresh)
                {
                    if (logger != null)
                        logger.log("Getting fresh download on request and caching it..", CedLib.Logging.Priority.Notice);
                    System.Net.WebClient Wclient = new System.Net.WebClient();
                    byte[] kaas = Wclient.DownloadData(ContentUrl);
                    File.WriteAllBytes(cachedfilename, kaas);
                }
                else
                {
                    if (logger != null)
                        logger.log("Getting cached reply..", CedLib.Logging.Priority.Info);
                    FromCache = true;
                }
                fstream = new FileStream(cachedfilename, FileMode.Open);
                return new CachedReply(fstream, FromCache);
            }