/// <summary> /// Handles the ItemCommand event of the TimeEntriesDataGrid control. /// </summary> /// <param name="source">The source of the event.</param> /// <param name="e">The <see cref="T:System.Web.UI.WebControls.DataGridCommandEventArgs"/> instance containing the event data.</param> protected void TimeEntriesDataGrid_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) { var id = Convert.ToInt32(e.CommandArgument); if (!IssueWorkReportManager.Delete(id)) { return; } var history = new IssueHistory { IssueId = IssueId, CreatedUserName = Security.GetUserName(), DateChanged = DateTime.Now, FieldChanged = ResourceStrings.GetGlobalResource(GlobalResources.SharedResources, "TimeLogged", "Time Logged"), OldValue = string.Empty, NewValue = ResourceStrings.GetGlobalResource(GlobalResources.SharedResources, "Deleted", "Deleted"), TriggerLastUpdateChange = true }; IssueHistoryManager.SaveOrUpdate(history); var changes = new List <IssueHistory> { history }; IssueNotificationManager.SendIssueNotifications(IssueId, changes); BindTimeEntries(); }
/// <summary> /// Handles the ItemDataBound event of the TimeEntriesDataGrid control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="T:System.Web.UI.WebControls.DataGridItemEventArgs"/> instance containing the event data.</param> protected void TimeEntriesDataGridItemDataBound(object sender, DataGridItemEventArgs e) { var delete = string.Format("return confirm('{0}');", GetLocalResourceObject("DeleteTimeEntry")); switch (e.Item.ItemType) { case ListItemType.Item: case ListItemType.AlternatingItem: _total += Convert.ToDouble(e.Item.Cells[1].Text); ((ImageButton)e.Item.FindControl("cmdDelete")).OnClientClick = delete; break; case ListItemType.Footer: //Use the footer to display the summary row. e.Item.Cells[0].Text = ResourceStrings.GetGlobalResource(GlobalResources.SharedResources, "TotalHours", "Total Hours"); e.Item.Cells[0].Attributes.Add("align", "left"); e.Item.Cells[0].Style.Add("font-weight", "bold"); e.Item.Cells[0].Style.Add("padding-top", "10px"); e.Item.Cells[0].Style.Add("border-top", "1px solid #999"); e.Item.Cells[1].Attributes.Add("align", "left"); e.Item.Cells[1].Style.Add("border-top", "1px solid #999"); e.Item.Cells[1].Style.Add("padding-top", "10px"); e.Item.Cells[1].Text = _total.ToString(); e.Item.Cells[2].Style.Add("border-top", "1px solid #999"); e.Item.Cells[3].Style.Add("border-top", "1px solid #999"); e.Item.Cells[4].Style.Add("border-top", "1px solid #999"); break; } }
/// <summary> /// Deletes the resolution. /// </summary> /// <param name="id">The id for the item to be deleted.</param> /// <param name="cannotDeleteMessage">If</param> /// <returns></returns> public static bool Delete(int id, out string cannotDeleteMessage) { if (id <= Globals.NEW_ID) { throw (new ArgumentOutOfRangeException("id")); } var entity = GetById(id); cannotDeleteMessage = string.Empty; if (entity == null) { return(true); } var canBeDeleted = DataProviderManager.Provider.CanDeleteResolution(entity.Id); if (canBeDeleted) { return(DataProviderManager.Provider.DeleteResolution(entity.Id)); } cannotDeleteMessage = ResourceStrings.GetGlobalResource(GlobalResources.Exceptions, "DeleteItemAssignedToIssueError"); cannotDeleteMessage = string.Format(cannotDeleteMessage, entity.Name, ResourceStrings.GetGlobalResource(GlobalResources.SharedResources, "Resolution", "resolution").ToLower()); return(false); }
private static void LocalizeUnassigned(Issue issue) { if (NeedLocalize) { LocalizeUnassigned(issue, ResourceStrings.GetGlobalResource(GlobalResources.SharedResources, "Unassigned", "Unassigned")); } }
public RepositoryMapping() { Config cfg = new Config(); FileSystemHelper fs = new FileSystemHelper(cfg); ResourceStrings r = new ResourceStrings(cfg); PathHelper = new AppUrlHelper(fs, r); }
/// <summary> /// Builds the JavaScript for all of the strings in the localised strings map passed across. /// </summary> /// <param name="stringsMap"></param> /// <returns></returns> private string BuildLanguageStrings(ResourceStrings stringsMap) { var result = new StringBuilder(); foreach (var stringName in stringsMap.GetStringNames().OrderBy(r => r)) { result.AppendFormat(" VRS.$$.{0} = {1};\r\n", stringName, JavascriptHelper.FormatStringLiteral(stringsMap.GetLocalisedString(stringName))); } return(result.ToString()); }
private static void LocalizeUnassigned(List <Issue> issues) { if (NeedLocalize) { var s = ResourceStrings.GetGlobalResource(GlobalResources.SharedResources, "Unassigned", "Unassigned"); foreach (var issue in issues) { LocalizeUnassigned(issue, s); } } }
/// <summary> /// Gets the resource strings for the culture passed across. /// </summary> /// <param name="cultureName"></param> /// <returns></returns> private ResourceStrings FetchResourceStrings(string cultureName) { ResourceStrings result; lock (_SyncLock) { if (!_ResourceStringsMap.TryGetValue(cultureName, out result)) { result = new ResourceStrings(typeof(WebSiteStrings), cultureName); _ResourceStringsMap.Add(cultureName, result); } } return(result); }
public HomeController() { this.Config = new Config(); this.Resources = new ResourceStrings(Config); this.FileSystem = new FileSystemHelper(Config); this.PathHelper = new AppUrlHelper(FileSystem, Resources); this.InitializeTableOfContentsRepository(); this.ApplicationSamplesRepository = new ApplicationSampleRepository(Resources.Culture, this.FileSystem); this.SampleRepository = new SampleRepository(Resources.Culture, this.FileSystem); this.ControlRepository = new ControlRepository(Resources.Culture, this.FileSystem); this.SampleSourceCodeRepository = new SampleSourceCodeRepository(this.PathHelper); this.InitializeHelpContentRepository(); this.LocalizedSampleStringRepository = new LocalizedSampleStringRepository(this.Resources.Culture); }
// For testing purposes public HomeController(ResourceStrings resources, Config config, FileSystemHelper fileSystem, AppUrlHelper urlHelper, TableOfContentsRepository tocRepository, ApplicationSampleRepository appSampleRepository, SampleRepository sampleRepository, ControlRepository controlRepository, HelpContentRepository helpContentRepository, SampleSourceCodeRepository sampleSourceRepository) { this.Resources = resources; this.Config = config; this.FileSystem = fileSystem; this.PathHelper = urlHelper; this.TableOfContentsRepository = tocRepository; this.ApplicationSamplesRepository = appSampleRepository; this.SampleRepository = sampleRepository; this.ControlRepository = controlRepository; this.HelpContentRepository = helpContentRepository; this.SampleSourceCodeRepository = sampleSourceRepository; }
/// <summary> /// Handles the Click event of the cmdAddBugTimeEntry control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> protected void AddTimeEntry_Click(object sender, EventArgs e) { if (DurationTextBox.Text.Trim().Length == 0) { return; } var selectedWorkDate = TimeEntryDate.SelectedValue == null ? DateTime.MinValue : (DateTime)TimeEntryDate.SelectedValue; var workDuration = Convert.ToDecimal(DurationTextBox.Text); var workReport = new IssueWorkReport { CommentText = CommentHtmlEditor.Text.Trim(), CreatorUserName = Context.User.Identity.Name, Duration = workDuration, IssueId = IssueId, WorkDate = selectedWorkDate }; IssueWorkReportManager.SaveOrUpdate(workReport); var history = new IssueHistory { IssueId = IssueId, CreatedUserName = Security.GetUserName(), DateChanged = DateTime.Now, FieldChanged = ResourceStrings.GetGlobalResource(GlobalResources.SharedResources, "TimeLogged", "Time Logged"), OldValue = string.Empty, NewValue = DurationTextBox.Text.Trim(), TriggerLastUpdateChange = true }; IssueHistoryManager.SaveOrUpdate(history); var changes = new List <IssueHistory> { history }; IssueNotificationManager.SendIssueNotifications(IssueId, changes); CommentHtmlEditor.Text = string.Empty; DurationTextBox.Text = string.Empty; BindTimeEntries(); }
/// <summary> /// Handles the Click event of the cmdUpdate control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param> protected void CmdAddRelatedIssueClick(object sender, EventArgs e) { if (IssueIdTextBox.Text == String.Empty) { return; } if (!Page.IsValid) { return; } RelatedIssuesMessage.Visible = false; var issueId = Utilities.ParseFullIssueId(IssueIdTextBox.Text.Trim()); if (issueId <= Globals.NEW_ID) { return; } RelatedIssueManager.CreateNewRelatedIssue(IssueId, issueId); IssueIdTextBox.Text = String.Empty; var history = new IssueHistory { IssueId = IssueId, CreatedUserName = Security.GetUserName(), DateChanged = DateTime.Now, FieldChanged = ResourceStrings.GetGlobalResource(GlobalResources.SharedResources, "RelatedIssue", "Related Issue"), OldValue = string.Empty, NewValue = ResourceStrings.GetGlobalResource(GlobalResources.SharedResources, "Added", "Added"), TriggerLastUpdateChange = true }; IssueHistoryManager.SaveOrUpdate(history); var changes = new List <IssueHistory> { history }; IssueNotificationManager.SendIssueNotifications(IssueId, changes); BindRelated(); }
public IEnumerable <string> GetSprites(string path, SearchOption option) { var fullPath = Prefix + path.Replace("\\", ".").Replace("/", ".").Replace(" ", "_"); var resources = ResourceStrings.Where(r => r.StartsWith(fullPath, StringComparison.OrdinalIgnoreCase)); if (option == SearchOption.TopDirectoryOnly) { // input: SpriteResources.spritesheets.body.female.tanned.png // after the split the fullPath is removed we are left with .tanned.png // we then split and count the '.' which should return an empty string, tanned and png // for deeper levels it should add more . // a potential bug here is if the filename includes a '.' it will not be included resources = resources.Where(r => r.Replace(fullPath, string.Empty).Split('.').Length == 3); } return(resources); }
/// <summary> /// Gets the resource strings for the culture passed across. /// </summary> /// <param name="cultureName"></param> /// <returns></returns> private ResourceStrings FetchResourceStrings(string cultureName) { var resourceMap = _ResourceStringsMap; if (!resourceMap.TryGetValue(cultureName, out ResourceStrings result)) { lock (_SyncLock) { if (!_ResourceStringsMap.TryGetValue(cultureName, out result)) { resourceMap = CollectionHelper.ShallowCopy(_ResourceStringsMap); result = new ResourceStrings(typeof(WebSiteStrings), cultureName); resourceMap.Add(cultureName, result); _ResourceStringsMap = resourceMap; } } } return(result); }
/// <summary> /// GRDs the bugs item command. /// </summary> /// <param name="s">The s.</param> /// <param name="e">The <see cref="System.Web.UI.WebControls.DataGridCommandEventArgs"/> instance containing the event data.</param> protected void GrdBugsItemCommand(Object s, DataGridCommandEventArgs e) { var commandArgument = e.CommandArgument.ToString(); var commandName = e.CommandName.ToLower().Trim(); var currentIssueId = Globals.NEW_ID; switch (commandName) { case "delete": currentIssueId = int.Parse(commandArgument); RelatedIssueManager.DeleteParentIssue(IssueId, currentIssueId); break; } if (currentIssueId > Globals.NEW_ID) { var history = new IssueHistory { IssueId = IssueId, CreatedUserName = Security.GetUserName(), DateChanged = DateTime.Now, FieldChanged = ResourceStrings.GetGlobalResource(GlobalResources.SharedResources, "ParentIssue", "Parent Issue"), OldValue = string.Empty, NewValue = ResourceStrings.GetGlobalResource(GlobalResources.SharedResources, "Deleted", "Deleted"), TriggerLastUpdateChange = true }; IssueHistoryManager.SaveOrUpdate(history); var changes = new List <IssueHistory> { history }; IssueNotificationManager.SendIssueNotifications(IssueId, changes); } BindRelated(); }
/// <summary> /// Handles the Click event of the cmdAddComment control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> protected void CmdAddCommentClick(object sender, EventArgs e) { if (CommentHtmlEditor.Text.Trim().Length == 0) { return; } var comment = new IssueComment { IssueId = IssueId, Comment = CommentHtmlEditor.Text.Trim(), CreatorUserName = Security.GetUserName(), DateCreated = DateTime.Now }; var result = IssueCommentManager.SaveOrUpdate(comment); if (result) { //add history record var history = new IssueHistory { IssueId = IssueId, CreatedUserName = Security.GetUserName(), DateChanged = DateTime.Now, FieldChanged = ResourceStrings.GetGlobalResource(GlobalResources.SharedResources, "Comment", "Comment"), OldValue = string.Empty, NewValue = ResourceStrings.GetGlobalResource(GlobalResources.SharedResources, "Added", "Added"), TriggerLastUpdateChange = true }; IssueHistoryManager.SaveOrUpdate(history); } CommentHtmlEditor.Text = String.Empty; BindComments(); }
/// <summary> /// Gets the issue changes. /// </summary> /// <param name="originalIssue">The original issue.</param> /// <param name="issueToCompare">The issue to compare.</param> /// <returns></returns> public static List <IssueHistory> GetIssueChanges(Issue originalIssue, Issue issueToCompare) { var issueChanges = new List <IssueHistory>(); if (originalIssue != null && issueToCompare != null) { var history = new IssueHistory { CreatedUserName = issueToCompare.CreatorUserName, IssueId = originalIssue.Id, DateChanged = DateTime.Now }; if (originalIssue.Title.ToLower() != issueToCompare.Title.ToLower()) { issueChanges.Add(GetNewIssueHistory(history, "Title", originalIssue.Title, issueToCompare.Title)); } if (originalIssue.Description.ToLower() != issueToCompare.Description.ToLower()) { issueChanges.Add(GetNewIssueHistory(history, "Description", originalIssue.Description, issueToCompare.Description)); } if (originalIssue.CategoryId != issueToCompare.CategoryId) { issueChanges.Add(GetNewIssueHistory(history, "Category", originalIssue.CategoryName, issueToCompare.CategoryName)); } if (originalIssue.PriorityId != issueToCompare.PriorityId) { issueChanges.Add(GetNewIssueHistory(history, "Priority", originalIssue.PriorityName, issueToCompare.PriorityName)); } if (originalIssue.StatusId != issueToCompare.StatusId) { issueChanges.Add(GetNewIssueHistory(history, "Status", originalIssue.StatusName, issueToCompare.StatusName)); } if (originalIssue.MilestoneId != issueToCompare.MilestoneId) { issueChanges.Add(GetNewIssueHistory(history, "Milestone", originalIssue.MilestoneName, issueToCompare.MilestoneName)); } if (originalIssue.AffectedMilestoneId != issueToCompare.AffectedMilestoneId) { issueChanges.Add(GetNewIssueHistory(history, "Affected Milestone", originalIssue.AffectedMilestoneName, issueToCompare.AffectedMilestoneName)); } if (originalIssue.IssueTypeId != issueToCompare.IssueTypeId) { issueChanges.Add(GetNewIssueHistory(history, "Issue Type", originalIssue.IssueTypeName, issueToCompare.IssueTypeName)); } if (originalIssue.ResolutionId != issueToCompare.ResolutionId) { issueChanges.Add(GetNewIssueHistory(history, "Resolution", originalIssue.ResolutionName, issueToCompare.ResolutionName)); } var unassignedLiteral = ResourceStrings.GetGlobalResource(GlobalResources.SharedResources, "Unassigned", "Unassigned"); var newAssignedUserName = String.IsNullOrEmpty(issueToCompare.AssignedUserName) ? unassignedLiteral : issueToCompare.AssignedUserName; if (originalIssue.AssignedUserName != newAssignedUserName) { // if the new assigned user is the unassigned user then don't trigger the new assignee notification issueToCompare.SendNewAssigneeNotification = (newAssignedUserName != unassignedLiteral); issueToCompare.NewAssignee = true; var newAssignedDisplayName = (newAssignedUserName == unassignedLiteral) ? newAssignedUserName : UserManager.GetUserDisplayName(newAssignedUserName); issueChanges.Add(GetNewIssueHistory(history, "Assigned to", originalIssue.AssignedDisplayName, newAssignedDisplayName)); } var newOwnerUserName = String.IsNullOrEmpty(issueToCompare.OwnerUserName) ? unassignedLiteral : issueToCompare.OwnerUserName; if (originalIssue.OwnerUserName != newOwnerUserName) { var newOwnerDisplayName = (newOwnerUserName == unassignedLiteral) ? newOwnerUserName : UserManager.GetUserDisplayName(issueToCompare.OwnerUserName); issueChanges.Add(GetNewIssueHistory(history, "Owner", originalIssue.OwnerDisplayName, newOwnerDisplayName)); } if (originalIssue.Estimation != issueToCompare.Estimation) { issueChanges.Add(GetNewIssueHistory(history, "Estimation", Utilities.EstimationToString(originalIssue.Estimation), Utilities.EstimationToString(issueToCompare.Estimation))); } if (originalIssue.Visibility != issueToCompare.Visibility) { issueChanges.Add(GetNewIssueHistory(history, "Visibility", Utilities.GetBooleanAsString(originalIssue.Visibility.ToBool()), Utilities.GetBooleanAsString(issueToCompare.Visibility.ToBool()))); } if (originalIssue.DueDate != issueToCompare.DueDate) { var originalDate = originalIssue.DueDate == DateTime.MinValue ? string.Empty : originalIssue.DueDate.ToShortDateString(); var newDate = issueToCompare.DueDate == DateTime.MinValue ? string.Empty : issueToCompare.DueDate.ToShortDateString(); issueChanges.Add(GetNewIssueHistory(history, "Due Date", originalDate, newDate)); } if (originalIssue.Progress != issueToCompare.Progress) { var nfi = new NumberFormatInfo { PercentDecimalDigits = 0 }; var oldProgress = originalIssue.Progress.Equals(0) ? 0 : (originalIssue.Progress.To <double>() / 100); var newProgress = issueToCompare.Progress.Equals(0) ? 0 : (issueToCompare.Progress.To <double>() / 100); issueChanges.Add(GetNewIssueHistory(history, "Progress", oldProgress.ToString("P", nfi), newProgress.ToString("P", nfi))); } } else { throw new Exception("Unable to retrieve original issue data"); } return(issueChanges); }
private bool ProcessNewComment(List <string> recipients, POP3_ClientMessage message, Mail_Message mailHeader, MailboxReaderResult result) { string messageFrom = string.Empty; if (mailHeader.From.Count > 0) { messageFrom = string.Join("; ", mailHeader.From.ToList().Select(p => p.Address).ToArray()).Trim(); } bool processed = false; foreach (var address in recipients) { Regex isReply = new Regex(@"(.*)(\+iid-)(\d+)@(.*)"); Match commentMatch = isReply.Match(address); if (commentMatch.Success && commentMatch.Groups.Count >= 4) { // we are in a reply and group 4 must contain the id of the original issue int issueId; if (int.TryParse(commentMatch.Groups[3].Value, out issueId)) { var _currentIssue = IssueManager.GetById(issueId); if (_currentIssue != null) { var project = ProjectManager.GetById(_currentIssue.ProjectId); var mailbody = Mail_Message.ParseFromByte(message.MessageToByte()); bool isHtml; List <MIME_Entity> attachments = null; string content = GetMessageContent(mailbody, project, out isHtml, ref attachments); IssueComment comment = new IssueComment { IssueId = issueId, Comment = content, DateCreated = mailHeader.Date }; // try to find if the creator is valid user in the project, otherwise take // the user defined in the mailbox config var users = UserManager.GetUsersByProjectId(project.Id); var emails = messageFrom.Split(';').Select(e => e.Trim().ToLower()); var user = users.Find(x => emails.Contains(x.Email.ToLower())); if (user != null) { comment.CreatorUserName = user.UserName; } else { // user not found continue; } var saved = IssueCommentManager.SaveOrUpdate(comment); if (saved) { //add history record var history = new IssueHistory { IssueId = issueId, CreatedUserName = comment.CreatorUserName, DateChanged = comment.DateCreated, FieldChanged = ResourceStrings.GetGlobalResource(GlobalResources.SharedResources, "Comment", "Comment"), OldValue = string.Empty, NewValue = ResourceStrings.GetGlobalResource(GlobalResources.SharedResources, "Added", "Added"), TriggerLastUpdateChange = true }; IssueHistoryManager.SaveOrUpdate(history); var projectFolderPath = Path.Combine(Config.UploadsFolderPath, project.UploadPath); // save attachments as new files int attachmentsSavedCount = 1; foreach (MIME_Entity mimeEntity in attachments) { string fileName; var contentType = mimeEntity.ContentType.Type.ToLower(); var attachment = new IssueAttachment { Id = 0, Description = "File attached by mailbox reader", DateCreated = DateTime.Now, ContentType = mimeEntity.ContentType.TypeWithSubtype, CreatorDisplayName = user.DisplayName, CreatorUserName = user.UserName, IssueId = issueId, ProjectFolderPath = projectFolderPath }; attachment.Attachment = ((MIME_b_SinglepartBase)mimeEntity.Body).Data; if (contentType.Equals("attachment")) // this is an attached email { fileName = mimeEntity.ContentDisposition.Param_FileName; } else if (contentType.Equals("message")) // message has no filename so we create one { fileName = string.Format("Attached_Message_{0}.eml", attachmentsSavedCount); } else { fileName = string.IsNullOrWhiteSpace(mimeEntity.ContentType.Param_Name) ? string.Format("untitled.{0}", mimeEntity.ContentType.SubType) : mimeEntity.ContentType.Param_Name; } attachment.FileName = fileName; var saveFile = IsAllowedFileExtension(fileName); var fileSaved = false; // can we save the file? if (saveFile) { fileSaved = IssueAttachmentManager.SaveOrUpdate(attachment); if (fileSaved) { attachmentsSavedCount++; } else { LogWarning("MailboxReader: Attachment could not be saved, please see previous logs"); } } } processed = true; // add the entry if the save did not throw any exceptions result.MailboxEntries.Add(new MailboxEntry()); } } } } } return(processed); }
private static ResourceStrings ProcessResXResources(string resourceFileName) { // default return object is null, meaning we are outputting the JS code directly // and don't want to replace any referenced resources in the sources ResourceStrings resourceStrings = null; using (ResXResourceReader reader = new ResXResourceReader(resourceFileName)) { // get an enumerator so we can itemize all the key/value pairs IDictionaryEnumerator enumerator = reader.GetEnumerator(); // create an object out of the dictionary resourceStrings = new ResourceStrings(enumerator); } return resourceStrings; }
int IVsColorableItem.GetDisplayName(out string pbstrName) { pbstrName = ResourceStrings.GetColorNameString(mySetting.LocalizedNameId); return(VSConstants.S_OK); }
/// <summary> /// Deletes the IssueAttachment. /// </summary> /// <param name="issueAttachmentId">The issue attachment id.</param> /// <returns></returns> public static bool Delete(int issueAttachmentId) { var att = GetById(issueAttachmentId); var issue = IssueManager.GetById(att.IssueId); var project = ProjectManager.GetById(issue.ProjectId); if (DataProviderManager.Provider.DeleteIssueAttachment(issueAttachmentId)) { try { var history = new IssueHistory { IssueId = att.IssueId, CreatedUserName = Security.GetUserName(), DateChanged = DateTime.Now, FieldChanged = ResourceStrings.GetGlobalResource(GlobalResources.SharedResources, "Attachment", "Attachment"), OldValue = att.FileName, NewValue = ResourceStrings.GetGlobalResource(GlobalResources.SharedResources, "Deleted", "Deleted"), TriggerLastUpdateChange = true }; IssueHistoryManager.SaveOrUpdate(history); var changes = new List <IssueHistory> { history }; IssueNotificationManager.SendIssueNotifications(att.IssueId, changes); } catch (Exception ex) { if (Log.IsErrorEnabled) { Log.Error(ex); } } if (HostSettingManager.Get(HostSettingNames.AttachmentStorageType, 0) == (int)IssueAttachmentStorageTypes.FileSystem) { //delete IssueAttachment from file system. try { if (string.IsNullOrEmpty(project.UploadPath)) { project.UploadPath = project.Id.ToString();//use project id as pathroot } var filePath = String.Format(@"{2}{0}\{1}", project.UploadPath, att.FileName, HostSettingManager.Get(HostSettingNames.AttachmentUploadPath)); if (filePath.StartsWith("~")) { filePath = HttpContext.Current.Server.MapPath(filePath); } if (File.Exists(filePath)) { File.Delete(filePath); } else { Log.Info(String.Format("Failed to locate file {0} to delete, it may have been moved or manually deleted", filePath)); } } catch (Exception ex) { //set user to log4net context, so we can use %X{user} in the appenders if (HttpContext.Current.User != null && HttpContext.Current.User.Identity.IsAuthenticated) { MDC.Set("user", HttpContext.Current.User.Identity.Name); } if (Log.IsErrorEnabled) { Log.Error(String.Format("Error Deleting IssueAttachment - {0}", String.Format("{0}\\{1}", project.UploadPath, att.FileName)), ex); } throw new ApplicationException(LoggingManager.GetErrorMessageResource("AttachmentDeleteError"), ex); } } } return(true); }
/// <summary> /// Uploads the document. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> protected void UploadDocument(object sender, EventArgs e) { // get the current file var uploadFile = AspUploadFile.PostedFile; // if there was a file uploaded if (uploadFile != null && uploadFile.ContentLength > 0) { var inValidReason = string.Empty; var fileName = Path.GetFileName(uploadFile.FileName); var validFile = IssueAttachmentManager.IsValidFile(fileName, out inValidReason); if (validFile) { byte[] fileBytes; using (var input = uploadFile.InputStream) { fileBytes = new byte[uploadFile.ContentLength]; input.Read(fileBytes, 0, uploadFile.ContentLength); } var attachment = new IssueAttachment { Id = Globals.NEW_ID, Attachment = fileBytes, Description = AttachmentDescription.Text.Trim(), DateCreated = DateTime.Now, ContentType = uploadFile.ContentType, CreatorDisplayName = string.Empty, CreatorUserName = Security.GetUserName(), FileName = fileName, IssueId = IssueId, Size = fileBytes.Length }; if (!IssueAttachmentManager.SaveOrUpdate(attachment)) { AttachmentsMessage.ShowErrorMessage(string.Format(GetGlobalResourceObject("Exceptions", "SaveAttachmentError").ToString(), uploadFile.FileName)); if (Log.IsWarnEnabled) Log.Warn(string.Format(GetGlobalResourceObject("Exceptions", "SaveAttachmentError").ToString(), uploadFile.FileName)); return; } //add history record and send notifications var history = new IssueHistory { IssueId = IssueId, CreatedUserName = Security.GetUserName(), DateChanged = DateTime.Now, FieldChanged = ResourceStrings.GetGlobalResource(GlobalResources.SharedResources, "Attachment", "Attachment"), OldValue = fileName, NewValue = ResourceStrings.GetGlobalResource(GlobalResources.SharedResources, "Added", "Added"), TriggerLastUpdateChange = true }; IssueHistoryManager.SaveOrUpdate(history); var changes = new List<IssueHistory> { history }; IssueNotificationManager.SendIssueNotifications(IssueId, changes); BindAttachments(); } else AttachmentsMessage.ShowErrorMessage(inValidReason); } }
private int ProcessCssFile(string sourceFileName, string encodingName, ResourceStrings resourceStrings, StringBuilder outputBuilder, ref long sourceLength) { int retVal = 0; // blank line before WriteProgress(); try { // read the input file var source = ReadInputFile(sourceFileName, encodingName, ref sourceLength); // process input source... CssParser parser = new CssParser(); parser.CssError += new EventHandler<CssErrorEventArgs>(OnCssError); parser.FileContext = string.IsNullOrEmpty(sourceFileName) ? "stdin" : sourceFileName; parser.Settings.CommentMode = m_cssComments; parser.Settings.ExpandOutput = m_prettyPrint; parser.Settings.IndentSpaces = m_indentSize; parser.Settings.TermSemicolons = m_terminateWithSemicolon; parser.Settings.ColorNames = m_colorNames; parser.Settings.MinifyExpressions = m_minifyExpressions; parser.Settings.AllowEmbeddedAspNetBlocks = m_allowAspNet; parser.ValueReplacements = resourceStrings; // if the kill switch was set to 1 (don't preserve important comments), then // we just want to set the comment mode to none, regardless of what the actual comment // mode may be. if ((m_killSwitch & 1) != 0) { parser.Settings.CommentMode = CssComment.None; } // crunch the source and output to the string builder we were passed string crunchedStyles = parser.Parse(source); if (crunchedStyles != null) { Debug.WriteLine(crunchedStyles); } else { // there was an error and no output was generated retVal = 1; } if (m_echoInput) { // just echo the input to the output outputBuilder.Append(source); } else if (!string.IsNullOrEmpty(crunchedStyles)) { // send the crunched styles to the output outputBuilder.Append(crunchedStyles); } } catch (IOException e) { // probably an error with the input file retVal = 1; System.Diagnostics.Debug.WriteLine(e.ToString()); WriteError("AM-IO", e.Message); } return retVal; }