private void OnChange(object sender, FileSystemEventArgs e) { var path = e.FullPath; RRTracer.Trace("watcher watched {0}", path); var guid = uriBuilder.ParseKey(path.Replace('\\', '/')); var contentSignature = uriBuilder.ParseSignature(path.Replace('\\', '/')); if (guid != Guid.Empty) { var resourceType = RRContainer.Current.GetAllInstances <IResourceType>().SingleOrDefault(x => path.EndsWith(x.FileName, true, CultureInfo.InvariantCulture)); if (resourceType != null) { RRTracer.Trace("New Content {0} and watched: {1}", e.ChangeType, path); if (e.ChangeType == WatcherChangeTypes.Deleted) { ReductionRepository.RemoveReduction(guid); } if ((e.ChangeType == WatcherChangeTypes.Created || e.ChangeType == WatcherChangeTypes.Changed)) { ReductionRepository.AddReduction(guid, uriBuilder.BuildResourceUrl(guid, contentSignature, resourceType.GetType())); } } } }
public void ProcessRequest(HttpContextBase context) { var url = context.Request.Url.AbsolutePath; url = url.EndsWith("/") ? url : url + "/"; if (string.IsNullOrEmpty(configuration.ResourcePhysicalPath)) { configuration.ResourcePhysicalPath = hostingEnvironment.MapPath(configuration.ResourceVirtualPath); } var user = context.User == null ? string.Empty : context.User.Identity.Name; if ((configuration.AuthorizedUserList.AllowsAnonymous() || configuration.AuthorizedUserList.Contains(user)) && ipFilter.IsAuthorizedIpAddress(context)) { if (url.ToLowerInvariant().Contains("/flushfailures/")) { queue.ClearFailures(); RRTracer.Trace("Failures Cleared"); } else { var key = uriBuilder.ParseKey(url.ToLower().Replace("/flush/rrflush.aspx/", "-flush")); if (key == Guid.Empty) { key = uriBuilder.ParseKey(url.ToLower().Replace("/flush/", "-flush")); } store.Flush(key); RRTracer.Trace("{0} Flushed {1}", user, key); } if (HttpContext.Current != null) { context.Response.Redirect(string.Format("{0}/dashboard", configuration.ResourceAbsolutePath)); } } else { context.Response.StatusCode = 401; } }
public void Save(byte[] content, string url, string originalUrls) { RRTracer.Trace("Saving {0} to db.", url); var fileName = uriBuilder.ParseFileName(url); var key = uriBuilder.ParseKey(url); var id = Hasher.Hash(fileName); var file = repository[id] ?? new RequestReduceFile(); file.Content = content; file.LastUpdated = DateTime.Now; file.FileName = fileName; file.Key = key; file.RequestReduceFileId = id; file.OriginalName = originalUrls; file.IsExpired = false; FileStore.Save(content, url, originalUrls); repository.Save(file); if (!url.ToLower().EndsWith(".png")) { reductionRepository.AddReduction(key, url); } RRTracer.Trace("{0} saved to db.", url); }
private string TransformDashboard(string dashboard) { var transformed = dashboard.Replace("<%server%>", Environment.MachineName); transformed = transformed.Replace("<%app%>", AppDomain.CurrentDomain.BaseDirectory); transformed = transformed.Replace("<%version%>", Assembly.GetExecutingAssembly().GetName().Version.ToString()); transformed = transformed.Replace("<%processedItem%>", queue.ItemBeingProcessed == null ? "Shhhh. I'm Sleeping" : ListUrls(queue.ItemBeingProcessed.Urls, "::")); var configProps = config.GetType().GetProperties(); var configList = new StringBuilder(); foreach (var item in configProps) { configList.AppendFormat("<tr><td{0}>{1}</td>", item.Name == "JavaScriptUrlsToIgnore" ? " style='vertical-align: top;'" : string.Empty, item.Name); var array = item.GetValue(config, null) as IEnumerable; if (array == null || item.PropertyType.IsAssignableFrom(typeof(string))) { string value = Convert.ToString(item.GetValue(config, null)); string result; switch (item.Name) { case "JavaScriptUrlsToIgnore": result = ListUrls(value, ","); break; case "ConnectionStringName": result = Regex.Replace(value, @";(PWD|PASSWORD)=\S+(;|$)", ";PASSWORD HIDDEN;", RegexOptions.Singleline | RegexOptions.IgnoreCase); break; default: result = value; break; } configList.AppendFormat("<td>{0}</td>", result); } else { configList.Append("<td>"); foreach (var mem in array) { configList.Append(mem); configList.Append("<br/>"); } configList.Append("</td>"); } configList.Append("</tr>"); } transformed = transformed.Replace("<%configs%>", configList.ToString()); var queueArray = queue.ToArray(); var queueList = new StringBuilder(); foreach (var item in queueArray) { if (queueList.Length > 0) { queueList.AppendLine("<hr/>"); } queueList.AppendLine("<ul>"); var urlArray = item.Urls.Split(new[] { "::" }, StringSplitOptions.RemoveEmptyEntries); foreach (var url in urlArray) { queueList.AppendFormat("<li>{0}</li>{1}", url, Environment.NewLine); } queueList.AppendFormat("</ul>"); } transformed = transformed.Replace("<%queue%>", queueList.ToString()); var repoArray = repo.ToArray(); var repoList = new StringBuilder(); foreach (var item in repoArray) { if (repoList.Length <= 0) { repoList.AppendLine("<ul>"); } repoList.AppendFormat("<li>{0} || <a href='{1}/flush/RRflush.aspx'>Flush</a></li>{2}", item, uriBuilder.ParseKey(item).RemoveDashes(), Environment.NewLine); } if (repoList.Length > 0) { repoList.AppendLine("</ul>"); } transformed = transformed.Replace("<%repo%>", repoList.ToString()); var failureList = new StringBuilder(); foreach (var item in queue.Failures) { if (failureList.Length > 0) { failureList.Append("<hr/>"); } failureList.AppendFormat("Key: {0}<br/>", item.Key); failureList.AppendFormat(" First errored on: {0} {1}<br/>", item.Value.CreatedOn.ToShortDateString(), item.Value.CreatedOn.ToLongTimeString()); if (item.Value.Count > 1) { failureList.AppendFormat(" Last errored on: {0} {1}<br/>", item.Value.UpdatedOn.ToShortDateString(), item.Value.UpdatedOn.ToLongTimeString()); } failureList.AppendFormat(" Number: {0}<br/>", item.Value.Count); var exception = item.Value.Exception; int iterator = 0; while (exception != null) { failureList.AppendFormat(" Exception #{0}: {1}<br/>", ++iterator, exception.Message); if (!string.IsNullOrEmpty(exception.StackTrace)) { failureList.AppendFormat(" Stack Trace#{0}: <pre>{1}</pre><br/>", iterator, exception.StackTrace); } exception = exception.InnerException; } } transformed = transformed.Replace("<%failures%>", failureList.ToString()); return(transformed); }