public RecipeStep Dequeue(string executionId) { Logger.Information("Dequeuing recipe steps."); if (!_appDataFolder.DirectoryExists(Path.Combine(_recipeQueueFolder, executionId))) { return(null); } RecipeStep recipeStep = null; int stepIndex = GetFirstStepIndex(executionId); if (stepIndex >= 0) { var stepPath = Path.Combine(_recipeQueueFolder, executionId + Path.DirectorySeparatorChar + stepIndex); // string to xelement var stepElement = XElement.Parse(_appDataFolder.ReadFile(stepPath)); var stepName = stepElement.Element("Name").Value; var stepId = stepElement.Attr("Id"); var recipeName = stepElement.Attr("RecipeName"); Logger.Information("Dequeuing recipe step '{0}'.", stepName); recipeStep = new RecipeStep(id: stepId, recipeName: recipeName, name: stepName, step: stepElement.Element(stepName)); _appDataFolder.DeleteFile(stepPath); } if (stepIndex < 0) { _appDataFolder.DeleteFile(Path.Combine(_recipeQueueFolder, executionId)); } return(recipeStep); }
public RecipeStep Dequeue(string executionId) { if (!_appDataFolder.DirectoryExists(Path.Combine(_recipeQueueFolder, executionId))) { return(null); } RecipeStep recipeStep = null; int stepIndex = GetFirstStepIndex(executionId); if (stepIndex >= 0) { var stepPath = Path.Combine(_recipeQueueFolder, executionId + Path.DirectorySeparatorChar + stepIndex); // string to xelement var stepElement = XElement.Parse(_appDataFolder.ReadFile(stepPath)); var stepName = stepElement.Element("Name").Value; recipeStep = new RecipeStep { Name = stepName, Step = stepElement.Element(stepName) }; _appDataFolder.DeleteFile(stepPath); } if (stepIndex < 0) { _appDataFolder.DeleteFile(Path.Combine(_recipeQueueFolder, executionId)); } return(recipeStep); }
public void Remove(string key) { Retry(() => { var filename = GetCacheItemFilename(key); if (_appDataFolder.FileExists(filename)) { _appDataFolder.DeleteFile(filename); } }); }
public void Release() { _rwLock.EnterWriteLock(); try { if (_released || !_appDataFolder.FileExists(_path)) { // nothing to do, might happen if re-granted, and already released return; } _released = true; // check it has not been granted in the meantime var current = _appDataFolder.ReadFile(_path); if (current == _content) { _appDataFolder.DeleteFile(_path); } } finally { _rwLock.ExitWriteLock(); } }
/// <summary> /// Deletes the settings file /// </summary> public void DeleteSettings(string indexName) { var settingsFilename = GetSettingsFileName(indexName); if (_appDataFolder.FileExists(settingsFilename)) { _appDataFolder.DeleteFile(settingsFilename); } }
public void DeleteAssembly(string moduleName) { var path = PrecompiledAssemblyPath(moduleName); if (_appDataFolder.FileExists(path)) { Logger.Information("Deleting assembly for module \"{0}\" from probing directory", moduleName); _appDataFolder.DeleteFile(path); } }
/// <summary> /// 删除程序集。 /// </summary> /// <param name="descriptor">程序集描述符。</param> public void DeleteAssembly(AssemblyDescriptor descriptor) { var path = PrecompiledAssemblyPath(descriptor); if (!_appDataFolder.FileExists(path)) { return; } Logger.Information("从程序集探测目录删除程序集 {0}", descriptor.ToString()); _appDataFolder.DeleteFile(path); }
public void Remove(string key) { var hash = GetCacheItemFileHash(key); lock (String.Intern(hash)) { Retry(() => { var filename = _appDataFolder.Combine(_metadata, hash); if (_appDataFolder.FileExists(filename)) { _appDataFolder.DeleteFile(filename); } }); Retry(() => { var filename = _appDataFolder.Combine(_content, hash); if (_appDataFolder.FileExists(filename)) { _appDataFolder.DeleteFile(filename); } }); } }
public void Sweep() { foreach (var filename in _appDataFolder.ListFiles(_metadata).ToArray()) { var hash = Path.GetFileName(filename); var validUntilUtc = _cacheManager.Get(hash, context => { _signals.When(hash); using (var stream = _appDataFolder.OpenFile(filename)) { var cacheItem = FileSystemOutputCacheStorageProvider.DeserializeMetadata(stream); return(cacheItem.ValidUntilUtc); } }); if (_clock.UtcNow > validUntilUtc) { _appDataFolder.DeleteFile(_appDataFolder.Combine(_metadata, hash)); _appDataFolder.DeleteFile(_appDataFolder.Combine(_content, hash)); _signals.Trigger(filename); } } }
public void Sweep() { foreach (var filename in _appDataFolder.ListFiles(_root).ToArray()) { var validUntilUtc = _cacheManager.Get(filename, context => { _signals.When(filename); using (var stream = _appDataFolder.OpenFile(filename)) { var cacheItem = FileSystemOutputCacheStorageProvider.Deserialize(stream); return(cacheItem.ValidUntilUtc); } }); if (_clock.UtcNow > validUntilUtc) { _appDataFolder.DeleteFile(filename); _signals.Trigger(filename); } } }
public void Sweep() { Logger.Debug("Beginning sweep for TrailLogTrimmingBackgroundTask."); try { // This task should look for audit trail log files older than a timespan // and delete them if any are found. if (GetIsTimeToTrim()) { var logFilePath = LaserAuditTrailHelper.GetLogsFilePath(); var logFileExtension = LaserAuditTrailHelper.GetAppenderFileExtension(); var fileNameBeginning = Path.Combine( logFilePath, LaserAuditTrailHelper.GetAppenderFileName( GetSiteSettings().SiteName)) .Replace(Path.DirectorySeparatorChar, '/'); var myLogs = _appDataFolder .ListFiles(logFilePath) .Where(fn => fn.StartsWith(fileNameBeginning)); // get the logs older than the specific timespan and delete them // Retention timespan: anything older will be deleted var retentionPeriod = TimeSpan.FromDays(GetAuditTrailSettings().RetentionPeriod); var dateThreshold = (_clock.UtcNow.EndOfDay() - retentionPeriod); foreach (var fileName in myLogs) { var lastWriteTime = _appDataFolder.GetFileLastWriteTimeUtc(fileName); if (lastWriteTime <= dateThreshold) { // file is older than the limit for retention. Delete it. _appDataFolder.DeleteFile(fileName); } } } } catch (Exception ex) { Logger.Error(ex, "Error during sweep for TrailLogTrimmingBackgroundTask."); } finally { Logger.Debug("Ending sweep for TrailLogTrimmingBackgroundTask."); } }
public void Clear() { _appDataFolder.DeleteFile(_appDataFolder.Combine("Sites", _shellSettings.Name, "mappings.bin")); }
public void EnsureGenerate() { var baseUrl = _orchardServices.WorkContext.CurrentSite.BaseUrl; var part = _orchardServices.WorkContext.CurrentSite.As <WarmupSettingsPart>(); // do nothing while the base url setting is not defined if (String.IsNullOrWhiteSpace(baseUrl)) { return; } // prevent multiple appdomains from rebuilding the static page concurrently (e.g., command line) ILockFile lockFile = null; if (!_lockFileManager.TryAcquireLock(_lockFilename, ref lockFile)) { return; } using (lockFile) { // check if we need to regenerate the pages by reading the last time it has been done // 1- if the warmup file doesn't exists, generate the pages // 2- otherwise, if the scheduled generation option is on, check if the delay is over if (_appDataFolder.FileExists(_warmupPath)) { try { var warmupContent = _appDataFolder.ReadFile(_warmupPath); var expired = XmlConvert.ToDateTimeOffset(warmupContent).AddMinutes(part.Delay); if (expired > _clock.UtcNow) { return; } } catch { // invalid file, delete continue processing _appDataFolder.DeleteFile(_warmupPath); } } // delete peviously generated pages, by reading the Warmup Report file try { var encodedPrefix = WarmupUtility.EncodeUrl("http://www."); foreach (var reportEntry in _reportManager.Read()) { try { // use FileName as the SiteBaseUrl could have changed in the meantime var path = _appDataFolder.Combine(BaseFolder, reportEntry.Filename); _appDataFolder.DeleteFile(path); // delete the www-less version too if it's available if (reportEntry.Filename.StartsWith(encodedPrefix, StringComparison.OrdinalIgnoreCase)) { var filename = WarmupUtility.EncodeUrl("http://") + reportEntry.Filename.Substring(encodedPrefix.Length); path = _appDataFolder.Combine(BaseFolder, filename); _appDataFolder.DeleteFile(path); } } catch (Exception e) { Logger.Error(e, "Could not delete specific warmup file: ", reportEntry.Filename); } } } catch (Exception e) { Logger.Error(e, "Could not read warmup report file"); } var reportEntries = new List <ReportEntry>(); if (!String.IsNullOrEmpty(part.Urls)) { // loop over every relative url to generate the contents using (var urlReader = new StringReader(part.Urls)) { string relativeUrl; while (null != (relativeUrl = urlReader.ReadLine())) { if (String.IsNullOrWhiteSpace(relativeUrl)) { continue; } string url = null; relativeUrl = relativeUrl.Trim(); try { url = VirtualPathUtility.RemoveTrailingSlash(baseUrl) + relativeUrl; var filename = WarmupUtility.EncodeUrl(url.TrimEnd('/')); var path = _appDataFolder.Combine(BaseFolder, filename); var download = _webDownloader.Download(url); if (download != null) { if (download.StatusCode == HttpStatusCode.OK) { // success _appDataFolder.CreateFile(path, download.Content); reportEntries.Add(new ReportEntry { RelativeUrl = relativeUrl, Filename = filename, StatusCode = (int)download.StatusCode, CreatedUtc = _clock.UtcNow }); // if the base url contains http://www, then also render the www-less one); if (url.StartsWith("http://www.", StringComparison.OrdinalIgnoreCase)) { url = "http://" + url.Substring("http://www.".Length); filename = WarmupUtility.EncodeUrl(url.TrimEnd('/')); path = _appDataFolder.Combine(BaseFolder, filename); _appDataFolder.CreateFile(path, download.Content); } } else { reportEntries.Add(new ReportEntry { RelativeUrl = relativeUrl, Filename = filename, StatusCode = (int)download.StatusCode, CreatedUtc = _clock.UtcNow }); } } else { // download failed reportEntries.Add(new ReportEntry { RelativeUrl = relativeUrl, Filename = filename, StatusCode = 0, CreatedUtc = _clock.UtcNow }); } } catch (Exception e) { Logger.Error(e, "Could not extract warmup page content for: ", url); } } } } _reportManager.Create(reportEntries); // finally write the time the generation has been executed _appDataFolder.CreateFile(_warmupPath, XmlConvert.ToString(_clock.UtcNow, XmlDateTimeSerializationMode.Utc)); } }