public virtual string Serialize() { var res = StringWork.CombinePieces( string.Empty, Ident, Value?.Serialize() ?? string.Empty ); if (!string.IsNullOrEmpty(Comment) && !string.IsNullOrWhiteSpace(Comment)) { if (Ident != string.Empty) { res = res.PadRight(StyleCommentPad, ' '); res += "#"; } else if (!this.IsDividerComment()) { res += " "; } res += Comment; } return(res); }
private static void testWork() { System.Console.WriteLine("### testWork ###"); Work<String> stringWork = new StringWork("foo", "one", "two", "three"); System.Console.WriteLine(stringWork); stringWork.updateProgress("one"); System.Console.WriteLine(stringWork); stringWork.updateProgress("two"); System.Console.WriteLine(stringWork); try { stringWork.updateProgress("two"); System.Console.WriteLine(stringWork); } catch (InvalidUpdateParameterException e) { System.Console.WriteLine(e.Message); } try { stringWork.updateProgress("no"); System.Console.WriteLine(stringWork); } catch (InvalidUpdateParameterException e) { System.Console.WriteLine(e.Message); } stringWork.updateProgress("three"); System.Console.WriteLine(stringWork); System.Console.WriteLine("\n\n"); }
public Dictionary <string, ItemList <FilterEconomy.Model.NinjaItem> > PerformRequest(string league, string variation, string branchKey, string url, string prefix, RequestType requestType, string baseStoragePath, string ninjaUrl) { var economySegmentBranch = url; var directoryPath = $"{baseStoragePath}/{variation}/{league}/{StringWork.GetDateString()}"; var fileName = $"{branchKey}.txt"; var fileFullPath = $"{directoryPath}/{fileName}"; string responseString; try { if (File.Exists(fileFullPath) && requestType != RequestType.ForceOnline) { // Load existing file responseString = FileWork.ReadFromFile(fileFullPath); } else { // Request online file var urlRequest = $"{ninjaUrl}{economySegmentBranch}{prefix}league={variation}"; responseString = new RestRequest(urlRequest).Execute(); // poeNinja down -> use most recent local file if (responseString == null || responseString.Length < 400) { var recentFile = Directory.EnumerateDirectories(directoryPath.Replace(StringWork.GetDateString(), "")).OrderByDescending(Directory.GetCreationTime).FirstOrDefault(); if (recentFile != null) { responseString = FileWork.ReadFromFile(recentFile + "/" + fileName); if (responseString != null && responseString.Length >= 400) { if (!didShowNinjaOfflineMessage) { InfoPopUpMessageDisplay.ShowInfoMessageBox("Could not connect to poeNinja. used recent local file instead: " + recentFile + "/" + fileName); this.didShowNinjaOfflineMessage = true; } } } } // Store locally Task.Run(() => FileWork.WriteTextAsync(fileFullPath, responseString)); } if (responseString == null || responseString.Length < 400) { InfoPopUpMessageDisplay.ShowError("poeNinja web request or file content is null/short:\n\n\n" + responseString); responseString = ""; } } catch { throw new Exception("Failed to load economy file: " + branchKey); } var result = NinjaParser.CreateOverviewDictionary(NinjaParser.ParseNinjaString(responseString).ToList()); return(result); }
public void WhiteSpaceInsertTest() { //Arrange var source = "GardenTable"; var expected = "Garden Table"; var workingString = new StringWork(); //Act var actual = workingString.WhiteSpaceInsert(source); //Assert Assert.AreEqual(expected, actual); }
private ItemTieringData ConvertToItemInformation(KeyValuePair <string, ItemList <NinjaItem> > z) { var ecoData = EconomyData.EconomyTierlistOverview[this.GetBranchKey()][z.Key]; return(new ItemTieringData() { Name = z.Key, Value = z.Value, Count = z.Value.Count, LowestPrice = ecoData?.LowestPrice ?? 0, HighestPrice = ecoData?.HighestPrice ?? 0, Multiplier = ecoData?.ValueMultiplier ?? 0, Valid = ecoData?.Valid, Tier = StringWork.CombinePieces(", ", TierListData.GetTiersForBasetypeSafe(CurrentBranchKey, z.Key)) }); }
public string Serialize() { switch (this.Type) { case FilterEntryType.Content: var comment = string.Join(" ", string.Join(" ", GenerationTags.Select(x => x.Serialize()).ToList()), this.TierTags?.Serialize(), HeaderComment).Trim(); if (!string.IsNullOrEmpty(comment)) { comment = $"# {comment}"; } return(StringWork.CombinePieces(string.Empty, HeaderValue, comment)); case FilterEntryType.Filler: case FilterEntryType.Comment: default: return(string.Empty); } }
public string Serialize() { return($"${StringWork.CombinePieces("->", this.Tags)}"); }
static void Main(string[] args) { bool exit = true; Console.WriteLine("Введите строку:"); string buf_str = Console.ReadLine(); ConsoleKeyInfo Key; while (exit) { Console.Clear(); Console.WriteLine("Ваша строка:\n{0}", buf_str); Console.WriteLine("Выберите действие:\n1.Найти самое маленькое слово\n2.Найти самое большое слово"); Key = Console.ReadKey(); switch (Key.KeyChar) { case '1': { Console.WriteLine("\nЧто использовать?\n1.string\n2.StringBuilder\n3.char[]"); Key = Console.ReadKey(); switch (Key.KeyChar) { case '1': { StringWork.OutSmallestWord(buf_str); break; } case '2': { StringBuilder string_builder = new StringBuilder(); string_builder.Append(buf_str); StringWork.OutSmallestWord(string_builder); break; } case '3': { char[] char_string = new char[buf_str.Length]; buf_str.CopyTo(0, char_string, 0, buf_str.Length); StringWork.OutSmallestWord(char_string); break; } default: { Console.WriteLine("\nТакого пункта нет!"); break; } } break; } case '2': { Console.WriteLine("\nЧто использовать?\n1.string\n2.StringBuilder\n3.char[]"); Key = Console.ReadKey(); switch (Key.KeyChar) { case '1': { StringWork.OutBiggestWord(buf_str); break; } case '2': { StringBuilder string_builder = new StringBuilder(buf_str); StringWork.OutBiggestWord(string_builder); break; } case '3': { char[] char_string = new char[buf_str.Length]; buf_str.CopyTo(0, char_string, 0, buf_str.Length); StringWork.OutBiggestWord(char_string); break; } default: { Console.WriteLine("\nТакого пункта нет!"); break; } } break; } default: { Console.WriteLine("\nТакого пункта нет!"); break; } } Console.WriteLine("Ещё?"); exit = Convert.ToBoolean(Console.ReadLine()); } }
public string Serialize() { return(StringWork.CombinePieces(string.Empty, this.Value.Select(x => x.Serialize()).ToArray())); }
public Dictionary <string, ItemList <FilterEconomy.Model.NinjaItem> > PerformRequest(string league, string leagueType, string branchKey, string url, string baseStoragePath) { var economySegmentBranch = url; var directoryPath = $"{baseStoragePath}/{leagueType}/{league}/{StringWork.GetDateString()}"; var fileName = $"{branchKey}.txt"; var fileFullPath = $"{directoryPath}/{fileName}"; string responseString; try { if (FilterPolishConfig.ActiveRequestMode != RequestType.ForceOnline && File.Exists(fileFullPath)) { // Load existing file LoggingFacade.LogInfo($"Loading Economy: Loading Cached File {fileFullPath}"); responseString = FileWork.ReadFromFile(fileFullPath); } else { // Request online file string variation = this.CreateNinjaLeagueParameter(league, leagueType); var urlRequest = $"{economySegmentBranch}&league={variation}"; try { responseString = new RestRequest(urlRequest).Execute(); } catch (Exception) { LoggingFacade.LogError($"Loading Economy: Requesting From Ninja {urlRequest}"); responseString = null; } // poeNinja down -> use most recent local file if ((responseString == null || responseString.Length < 400) && FilterPolishConfig.ActiveRequestMode == RequestType.Dynamic) { var recentFile = Directory .EnumerateDirectories(directoryPath.Replace(StringWork.GetDateString(), "")) .Where(x => File.Exists(x + "/" + fileName)) .OrderByDescending(Directory.GetCreationTime) .FirstOrDefault(); if (recentFile != null && File.Exists(recentFile + "/" + fileName)) { responseString = FileWork.ReadFromFile(recentFile + "/" + fileName); if (responseString != null && responseString.Length >= 400) { if (!didShowNinjaOfflineMessage) { LoggingFacade.LogWarning("Could not connect to poeNinja. used recent local file instead: " + recentFile + "/" + fileName); this.didShowNinjaOfflineMessage = true; } } } else { throw new Exception("did not find any old ninja files"); } } if (!string.IsNullOrEmpty(responseString) && FilterPolishConfig.ActiveRequestMode == RequestType.Dynamic) { // Store locally FileWork.WriteText(fileFullPath, responseString); } } if (responseString == null || responseString.Length < 400) { LoggingFacade.LogError("poeNinja web request or file content is null/short:\n\n\n" + responseString); throw new Exception("poeNinja web request or file content is null/short:\n\n\n" + responseString); } } catch (Exception e) { LoggingFacade.LogError("Failed to load economy file: " + branchKey + ": " + e); return(null); } var result = NinjaParser.CreateOverviewDictionary(NinjaParser.ParseNinjaString(responseString, branchKey).ToList()); return(result); }
public static string StringOperations(string text, StringWork method) { string newString = method(text); return(newString); }