|
| 1 | +using System; |
| 2 | +using System.IO; |
| 3 | +using System.Text.RegularExpressions; |
| 4 | +using System.Windows.Media; |
| 5 | +using Newtonsoft.Json; |
| 6 | +using UIssueTracker.UserControls; |
| 7 | +using System.Collections.Generic; |
| 8 | +using Newtonsoft.Json.Linq; |
| 9 | + |
| 10 | +namespace UIssueTracker.Classes |
| 11 | +{ |
| 12 | + public class Constants |
| 13 | + { |
| 14 | + public static readonly string PRODUCT_NAME = "Unreal Issue Tracker"; |
| 15 | + public static readonly string BUG_URL = @"https://issues.unrealengine.com/feed/bugs"; |
| 16 | + public static readonly string FIX_URL = @"https://issues.unrealengine.com/feed/fixes"; |
| 17 | + |
| 18 | + private static readonly string IssueTrackerFileExtension = ".uitf"; |
| 19 | + private static readonly string IssueFilesDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal) + @"\" + PRODUCT_NAME + @"\"; |
| 20 | + private static readonly string IssueTrackerHistoryDirectory = IssueFilesDirectory + @"History\"; |
| 21 | + private static readonly string IssueTrackerHistoryFile = IssueTrackerHistoryDirectory + "IssueHistory.uithf"; |
| 22 | + |
| 23 | + public enum IssueResolution |
| 24 | + { |
| 25 | + Backlogged, |
| 26 | + ByDesign, |
| 27 | + CannotReproduce, |
| 28 | + Duplicate, |
| 29 | + Fixed, |
| 30 | + NonIssue, |
| 31 | + Unresolved, |
| 32 | + WontDo, |
| 33 | + WontFix, |
| 34 | + None |
| 35 | + } |
| 36 | + |
| 37 | + private static void CreateIssueFileLocation() |
| 38 | + { |
| 39 | + if (Directory.Exists(IssueFilesDirectory) == false) |
| 40 | + { |
| 41 | + Directory.CreateDirectory(IssueFilesDirectory); |
| 42 | + } |
| 43 | + } |
| 44 | + |
| 45 | + private static void CreateHistoryFile() |
| 46 | + { |
| 47 | + if (File.Exists(IssueTrackerHistoryFile) == false) |
| 48 | + { |
| 49 | + if (Directory.Exists(IssueTrackerHistoryDirectory) == false) |
| 50 | + { |
| 51 | + Directory.CreateDirectory(IssueTrackerHistoryDirectory); |
| 52 | + } |
| 53 | + JObject EmptyJson = new JObject(); |
| 54 | + File.WriteAllText(IssueTrackerHistoryFile, EmptyJson.ToString(Formatting.Indented)); |
| 55 | + } |
| 56 | + } |
| 57 | + |
| 58 | + public static bool IsSubscribedToIssue(string IssueNumber) |
| 59 | + { |
| 60 | + return File.Exists(IssueFilesDirectory + IssueNumber + IssueTrackerFileExtension); |
| 61 | + } |
| 62 | + |
| 63 | + public static bool SaveToHistory(IssueDetails issueDetails) |
| 64 | + { |
| 65 | + CreateHistoryFile(); |
| 66 | + HistoryIssue historyIssue = JsonConvert.DeserializeObject<HistoryIssue>(File.ReadAllText(IssueTrackerHistoryFile)); |
| 67 | + if (historyIssue.IssueHistory.ContainsKey(GetIssueNumber(issueDetails.IssueURL)) == false) |
| 68 | + { |
| 69 | + historyIssue.IssueHistory.Add(GetIssueNumber(issueDetails.IssueURL), issueDetails.CurrentIssueTitle); |
| 70 | + string serializedJson = JsonConvert.SerializeObject(historyIssue, Formatting.Indented); |
| 71 | + File.WriteAllText(IssueTrackerHistoryFile, serializedJson); |
| 72 | + return true; |
| 73 | + } |
| 74 | + return false; |
| 75 | + } |
| 76 | + |
| 77 | + public static bool SubscribeToIssue(IssueDetails issueDetails) |
| 78 | + { |
| 79 | + CreateIssueFileLocation(); |
| 80 | + string IssueNumber = GetIssueNumber(issueDetails.IssueURL); |
| 81 | + if (IsSubscribedToIssue(IssueNumber) == false) |
| 82 | + { |
| 83 | + SubscribeIssue subscribeIssue = new SubscribeIssue(); |
| 84 | + subscribeIssue.SubscribedIssueResolution = issueDetails.CurrentIssueStatus; |
| 85 | + subscribeIssue.SubscribedIssueTitle = issueDetails.CurrentIssueTitle; |
| 86 | + subscribeIssue.SubscribedIssueID = IssueNumber; |
| 87 | + subscribeIssue.SubscribedIssueLink = issueDetails.IssueURL; |
| 88 | + subscribeIssue.SubscribedIssueDescription = issueDetails.CurrentIssueDescription; |
| 89 | + subscribeIssue.SubscribedIssueRepro = issueDetails.CurrentIssueRepro; |
| 90 | + subscribeIssue.SubscribedIssueMoreInfo = issueDetails.CurrentIssueAnswerHubLink; |
| 91 | + string SubscribeIssueJson = JsonConvert.SerializeObject(subscribeIssue, Formatting.Indented); |
| 92 | + File.WriteAllText(IssueFilesDirectory + IssueNumber + IssueTrackerFileExtension, SubscribeIssueJson); |
| 93 | + return true; |
| 94 | + } |
| 95 | + return false; |
| 96 | + } |
| 97 | + |
| 98 | + public static void UnSubscribeFromIssue(string IssueNumber) |
| 99 | + { |
| 100 | + string FileLocation = IssueFilesDirectory + IssueNumber + IssueTrackerFileExtension; |
| 101 | + File.Delete(FileLocation); |
| 102 | + } |
| 103 | + |
| 104 | + public static SubscribeIssue GetSubscribedIssue(string IssueFilePath) |
| 105 | + { |
| 106 | + return JsonConvert.DeserializeObject<SubscribeIssue>(File.ReadAllText(IssueFilePath)); |
| 107 | + } |
| 108 | + |
| 109 | + public static string GetIssueNumber(string IssueLink) |
| 110 | + { |
| 111 | + return IssueLink.Replace(@"https://issues.unrealengine.com/issue/", ""); |
| 112 | + } |
| 113 | + |
| 114 | + public static string GetIssueFilesDirectory() |
| 115 | + { |
| 116 | + return IssueFilesDirectory; |
| 117 | + } |
| 118 | + |
| 119 | + public static string GetIssuesHistoryFile() |
| 120 | + { |
| 121 | + return IssueTrackerHistoryFile; |
| 122 | + } |
| 123 | + |
| 124 | + public static SolidColorBrush ToSolidColorBrush(string hex_code) |
| 125 | + { |
| 126 | + return (SolidColorBrush)new BrushConverter().ConvertFromString(hex_code); |
| 127 | + } |
| 128 | + |
| 129 | + public static IssueResolution GetResolution(string ResolutionName) |
| 130 | + { |
| 131 | + IssueResolution issueResolution = IssueResolution.None; |
| 132 | + switch (ResolutionName.ToLower()) |
| 133 | + { |
| 134 | + case "backlogged": |
| 135 | + issueResolution = IssueResolution.Backlogged; |
| 136 | + break; |
| 137 | + case "by design": |
| 138 | + issueResolution = IssueResolution.ByDesign; |
| 139 | + break; |
| 140 | + case "cannot reproduce": |
| 141 | + issueResolution = IssueResolution.CannotReproduce; |
| 142 | + break; |
| 143 | + case "duplicate": |
| 144 | + issueResolution = IssueResolution.Duplicate; |
| 145 | + break; |
| 146 | + case "fixed": |
| 147 | + issueResolution = IssueResolution.Fixed; |
| 148 | + break; |
| 149 | + case "non-issue": |
| 150 | + issueResolution = IssueResolution.NonIssue; |
| 151 | + break; |
| 152 | + case "unresolved": |
| 153 | + issueResolution = IssueResolution.Unresolved; |
| 154 | + break; |
| 155 | + case "won't do": |
| 156 | + issueResolution = IssueResolution.WontDo; |
| 157 | + break; |
| 158 | + case "won't fix": |
| 159 | + issueResolution = IssueResolution.WontFix; |
| 160 | + break; |
| 161 | + default: |
| 162 | + break; |
| 163 | + |
| 164 | + } |
| 165 | + return issueResolution; |
| 166 | + } |
| 167 | + |
| 168 | + public static SolidColorBrush GetResolutionColor(string ResolutionName) |
| 169 | + { |
| 170 | + return GetColorByIssueResolution(GetResolution(ResolutionName)); |
| 171 | + } |
| 172 | + |
| 173 | + private static SolidColorBrush GetColorByIssueResolution(IssueResolution issueResolution) |
| 174 | + { |
| 175 | + string hex_code = "#FF304FFE"; |
| 176 | + switch(issueResolution) |
| 177 | + { |
| 178 | + case IssueResolution.Backlogged: |
| 179 | + hex_code = "#FF7F261D"; |
| 180 | + break; |
| 181 | + case IssueResolution.ByDesign: |
| 182 | + hex_code = "#FF27AE60"; |
| 183 | + break; |
| 184 | + case IssueResolution.CannotReproduce: |
| 185 | + hex_code = "#FFF39C12"; |
| 186 | + break; |
| 187 | + case IssueResolution.Duplicate: |
| 188 | + hex_code = "#FF95A5A6"; |
| 189 | + break; |
| 190 | + case IssueResolution.Fixed: |
| 191 | + hex_code = "#FF2ECC71"; |
| 192 | + break; |
| 193 | + case IssueResolution.NonIssue: |
| 194 | + hex_code = "#FFBBBBBB"; |
| 195 | + break; |
| 196 | + case IssueResolution.Unresolved: |
| 197 | + hex_code = "#FFE74C3C"; |
| 198 | + break; |
| 199 | + case IssueResolution.WontDo: |
| 200 | + hex_code = "#FF171717"; |
| 201 | + break; |
| 202 | + case IssueResolution.WontFix: |
| 203 | + hex_code = "#FF34495E"; |
| 204 | + break; |
| 205 | + default: |
| 206 | + break; |
| 207 | + |
| 208 | + } |
| 209 | + return (SolidColorBrush)new BrushConverter().ConvertFromString(hex_code); |
| 210 | + } |
| 211 | + |
| 212 | + public static string RemoveHtmlTags(string html) |
| 213 | + { |
| 214 | + string ReturnValue = html.Replace(@"amp;", string.Empty); |
| 215 | + Regex.Replace(ReturnValue, "<.+?>", string.Empty); |
| 216 | + return ReturnValue; |
| 217 | + } |
| 218 | + } |
| 219 | + |
| 220 | + public class SubscribeIssue |
| 221 | + { |
| 222 | + public string SubscribedIssueID { get; set; } |
| 223 | + public string SubscribedIssueTitle { get; set; } |
| 224 | + public string SubscribedIssueResolution { get; set; } |
| 225 | + public string SubscribedIssueLink { get; set; } |
| 226 | + public string SubscribedIssueDescription { get; set; } |
| 227 | + public string SubscribedIssueRepro { get; set; } |
| 228 | + public string SubscribedIssueMoreInfo { get; set; } // AnswerHub or UDN link. |
| 229 | + } |
| 230 | + |
| 231 | + public class HistoryIssue |
| 232 | + { |
| 233 | + public Dictionary<string, string> IssueHistory = new Dictionary<string, string>(); |
| 234 | + } |
| 235 | +} |
0 commit comments