public static string GetParents(int value) { return(Smart.Format(AppSettings.CurrentCultureInfo, _instance.Value._parentsText.Text, value, Math.Abs(value))); }
public static string GetAuthorDate(int value) { return(Smart.Format(AppSettings.CurrentCultureInfo, _instance.Value._authorDateText.Text, value, Math.Abs(value))); }
public static string GetNYearsAgoText(int value) { return(Smart.Format(AppSettings.CurrentCultureInfo, _instance.Value._yearsAgo.Text, value, Math.Abs(value))); }
public void Invoke_extensions_by_name_or_shortname(string format, object arg0, string expectedResult) { var actualResult = Smart.Format(new CultureInfo("en-US"), format, arg0); // must be culture with decimal point Assert.AreEqual(expectedResult, actualResult); }
public override string ToString() => Smart.Format(Localization.Dictionary[_key] ?? $"`{_key}`", _args);
public static string GetCommitHash(int value) { return(Smart.Format(AppSettings.CurrentCultureInfo, _instance.Value._commitHashText.Text, value, Math.Abs(value))); }
public override async Task <Message> HandleMessage(Message msg) { var byType = msg.AsEnumerable().GroupBy(x => x.GetType()); foreach (var group in byType) { var sample = group.First(); MessageContext context = new MessageContext(sample, this); string connectionString = Connection != null?Smart.Format(Connection, context) : null; string dbName = Smart.Format(Database, context); string tableName = Smart.Format(Table, context); if (String.IsNullOrWhiteSpace(connectionString)) { string dbPath = Path.Combine(AHostProxy.Current.BaseDirectory, "Databases"); if (!Directory.Exists(dbPath)) { Directory.CreateDirectory(dbPath); } string dbFile = Path.Combine(dbPath, dbName); connectionString = String.Format(_defaultConnection, dbFile); } if (String.IsNullOrWhiteSpace(tableName)) { tableName = dbName; } try { // Warning: At the moment, .ToConnection() blindly assumes its always SQLite using (DbConnection connection = connectionString.ToConnection()) { connection.Open(); var tables = connection.GetSchema("Tables"); bool tableExists = tables.Rows.Contains(tableName); // ToDo: develop something more flexible that supports user // defined schemas. For now we'll just use the message's structure. if (!tableExists) { var ctcmd = connection.CreateCommand(); ctcmd.CommandText = sample.ToCreateTable(tableName); ctcmd.ExecuteScalar(); } foreach (var m in group) { DbCommand cmd = m.ToInsertOrReplace(connection, tableName); await cmd.ExecuteNonQueryAsync(); } } } catch (Exception ex) { logger.Error(ex, "Error saving to DB"); } } return(msg); }
public static string GetCommitDate(int value) { string v = Smart.Format(AppSettings.CurrentCultureInfo, _instance.Value._commitDateText.Text, value, Math.Abs(value)); return(v); }
/// <summary> /// Filters the hierarchal conflicts asynchronous. /// </summary> /// <param name="conflictResult">The conflict result.</param> /// <param name="selectedDefinitionOverride">The selected definition override.</param> /// <returns>Task.</returns> protected virtual async Task FilterHierarchalConflictsAsync(IConflictResult conflictResult, IHierarchicalDefinitions selectedDefinitionOverride = null) { while (filteringConflicts) { await Task.Delay(25); } filteringConflicts = true; var index = PreviousConflictIndex; PreviousConflictIndex = null; if (conflictResult != null && conflictResult.Conflicts != null) { var conflicts = conflictResult.Conflicts.GetHierarchicalDefinitions().ToList(); var resolved = new List <IHierarchicalDefinitions>(); if (conflictResult.ResolvedConflicts != null) { resolved.AddRange(conflictResult.ResolvedConflicts.GetHierarchicalDefinitions()); } if (conflictResult.IgnoredConflicts != null) { resolved.AddRange(conflictResult.IgnoredConflicts.GetHierarchicalDefinitions()); } if (conflictResult.RuleIgnoredConflicts != null) { resolved.AddRange(conflictResult.RuleIgnoredConflicts.GetHierarchicalDefinitions()); } foreach (var topLevelResolvedConflicts in resolved) { IEnumerable <IHierarchicalDefinitions> topLevelConflicts; if (topLevelResolvedConflicts.Name.StartsWith(Shared.Constants.LocalizationDirectory, StringComparison.OrdinalIgnoreCase)) { topLevelConflicts = conflicts.Where(p => p.Name.StartsWith(Shared.Constants.LocalizationDirectory, StringComparison.OrdinalIgnoreCase)); } else { topLevelConflicts = conflicts.Where(p => p.Name.Equals(topLevelResolvedConflicts.Name)); } if (topLevelConflicts.Count() > 0) { foreach (var topLevelConflict in topLevelConflicts) { foreach (var childResolvedConflict in topLevelResolvedConflicts.Children) { var child = topLevelConflict.Children.FirstOrDefault(p => p.Key.Equals(childResolvedConflict.Key)); if (child != null) { topLevelConflict.Children.Remove(child); } } } } conflicts.RemoveAll(p => p.Children == null || p.Children.Count == 0); } var invalid = conflictResult.AllConflicts.GetByValueType(Parser.Common.ValueType.Invalid); if (invalid?.Count() > 0) { var invalidDef = DIResolver.Get <IHierarchicalDefinitions>(); invalidDef.Name = Invalid; invalidDef.Key = InvalidKey; var children = new List <IHierarchicalDefinitions>(); foreach (var item in invalid) { var invalidChild = DIResolver.Get <IHierarchicalDefinitions>(); invalidChild.Name = item.File; var message = item.ErrorColumn.HasValue || item.ErrorLine.HasValue ? localizationManager.GetResource(LocalizationResources.Conflict_Solver.InvalidConflicts.Error) : localizationManager.GetResource(LocalizationResources.Conflict_Solver.InvalidConflicts.ErrorNoLine); invalidChild.Key = Smart.Format(message, new { item.ModName, Line = item.ErrorLine, Column = item.ErrorColumn, Environment.NewLine, Message = item.ErrorMessage, item.File }); invalidChild.AdditionalData = item; children.Add(invalidChild); } invalidDef.Children = children; conflicts.Add(invalidDef); } HierarchalConflicts = conflicts.ToObservableCollection(); NumberOfConflictsCaption = Smart.Format(localizationManager.GetResource(LocalizationResources.Conflict_Solver.ConflictCount), new { Count = conflicts.Where(p => p.Key != InvalidKey).SelectMany(p => p.Children).Count() }); if (HierarchalConflicts.Count() > 0 && SelectedParentConflict == null) { SelectedParentConflict = HierarchalConflicts.FirstOrDefault(); } if (SelectedParentConflict != null) { var conflictName = SelectedParentConflict.Name; SelectedParentConflict = null; var newSelected = HierarchalConflicts.FirstOrDefault(p => p.Name.Equals(conflictName)); if (newSelected != null) { PreviousConflictIndex = index; if (selectedDefinitionOverride != null) { var overrideMatch = newSelected.Children.FirstOrDefault(p => p.Key.Equals(selectedDefinitionOverride.Key)); if (overrideMatch != null) { PreviousConflictIndex = newSelected.Children.ToList().IndexOf(overrideMatch); } } if (PreviousConflictIndex.GetValueOrDefault() > (newSelected.Children.Count - 1)) { PreviousConflictIndex = newSelected.Children.Count - 1; } SelectedParentConflict = newSelected; } } } else { HierarchalConflicts = null; } filteringConflicts = false; }
public void Nesting_can_access_outer_scopes(string format, string expectedOutput) { var actual = Smart.Format(format, data); Assert.AreEqual(expectedOutput, actual); }
public void Nesting_can_access_root_via_number(string format, string expectedOutput) { var actual = Smart.Format(format, data); Assert.AreEqual(expectedOutput, actual); }
public async Task <ActionResult> ShrineOfSecrets(string branch = "live") { ShrineResponse shrine; try { shrine = await _dbdService.GetShrine(branch); if (shrine == null) { throw new InvalidOperationException(); } } catch (Exception) { return(Content("Uh oh, we failed to retrieve the shrine from dbd servers :/")); } var useRealFix = _dbdService.PerkInfos.TryGetValue(BranchToDepotBranch(branch), out var perkInfos); foreach (var item in shrine.Items) { if (useRealFix && perkInfos.TryGetValue(item.Id, out var perk)) { item.Name = perk.DisplayName; } else { item.Name = CorrectPerkName(item.Id); } } var format = (string)Request.Query["format"]; if (!string.IsNullOrEmpty(Request.Query["pretty"])) { if (!string.IsNullOrEmpty(format)) { try { return(Content(Smart.Format(format, shrine))); } catch (Exception e) { return(Json(new { success = false, type = "Format Exception", reason = e.Message })); } } else { try { var output = new StringBuilder(); foreach (var item in shrine.Items) { if (!item.Cost.Any()) { continue; } output.Append($"{item.Name} : {item.Cost[0].Price}"); if (item != shrine.Items.Last()) { output.Append(", "); } } output.Append(" | "); var changesIn = shrine.EndDate - DateTime.Now; output.Append( $"Shrine changes in {changesIn.Days} days, {changesIn.Hours} hours, and {changesIn.Minutes} mins"); return(Content(output.ToString())); } catch { return(Content("Uhhhh, we failed to parse the data retrieved, contact me to fix")); } } } else { return(Json(shrine, ShrineConverter.Settings)); } }