예제 #1
0
        public void downLoadFile(string id, MemoryStream fileToDownload)
        {
            string     absoluteFilePath = rootPath + "\\" + id;
            FileStream fstream          = new FileStream(absoluteFilePath, FileMode.Create);

            fileToDownload.WriteTo(fstream);
            fstream.Close();
            fileToDownload.Close();
            TemporaryFileInformation curFile = new TemporaryFileInformation(DateTime.Now, absoluteFilePath);

            cachedFiles.Add(id, curFile);
        }
예제 #2
0
        /*
         * Will check to see if cachedFiles contains a valid instance of the requested file.
         * Returns true if it does, if false, will remove the entry in the cache, and on the disk.
         */
        public bool containsValidInstanceOfFile(string fileID)
        {
            TemporaryFileInformation curFileInfo = null;

            cachedFiles.TryGetValue(fileID, out curFileInfo);
            if (curFileInfo == null)
            {
                //was not present in the cache
                return(false);
            }
            DateTime curTime     = DateTime.Now;
            TimeSpan timeElapsed = DateTime.Now.Subtract(curFileInfo.TimeCreated);

            if (timeElapsed.TotalMinutes <= TIMEVALIDMINUTES)
            {
                //file is still 'fresh' enough
                return(true);
            }
            return(false);
        }