Menu

[59aa80]: / FeedbackGeneratorQQ / Utils / AttributesHelper.cs  Maximize  Restore  History

Download this file

131 lines (115 with data), 4.3 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
namespace FeedbackGeneratorQQ.Utils
{
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using FeedbackGeneratorQQ.Models;
public static class AttributesHelper
{
/// <summary>
/// Default attributes root folder
/// </summary>
private const string _attributesFolder = "AttributeTemplates";
/// <summary>
/// Default template name
/// </summary>
private const string _templateName = "Template.xml";
/// <summary>
/// Default template root node
/// </summary>
public const string TemplateRootNode = "Template";
/// <summary>
/// %sheHe% and %heShe% replacer
/// </summary>
private static string _sheHeReplacer;
/// <summary>
/// %SheHe% and %HeShe% replacer
/// </summary>
private static string _sheHeUpperReplacer;
/// <summary>
/// %himHer% and %herHim% replacer
/// </summary>
private static string _himHerReplacer;
/// <summary>
/// %himselfHerself% and %herselfHimself% replacer
/// </summary>
private static string _himselfHerselfReplacer;
/// <summary>
/// %hisHer% and %herHis% replacer
/// </summary>
private static string _hisHerReplacer;
/// <summary>
/// %HisHer% and %HerHis% replacer
/// </summary>
private static string _hisHerUpperReplacer;
private static string GetAppPath()
{
return System.AppDomain.CurrentDomain.BaseDirectory;
}
private static string GetAttributesFolderPath()
{
return Path.Combine(GetAppPath(), _attributesFolder);
}
public static string GetAttributePath(string attributeFolder)
{
return Path.Combine(attributeFolder, _templateName);
}
/// <summary>
/// Gets attributes and their content
/// </summary>
/// <returns> Returns list of attributes (Task) </returns>
public static Task<IEnumerable<AttributeModel>> GetAttributesAsync()
{
return Task.Factory.StartNew(() =>
{
return Directory.EnumerateDirectories(GetAttributesFolderPath(), "*", SearchOption.TopDirectoryOnly)
.Select(path => new AttributeModel(path))
.Where(attributeModel => attributeModel.Types.Any());
});
}
/// <summary>
/// Configures replacers based on selected gender
/// </summary>
/// <param name="gender"> The gender </param>
public static void ConfigureReplacers(string gender)
{
bool isMale = gender.Equals("Male");
_sheHeReplacer = isMale ? "he" : "she";
_sheHeUpperReplacer = isMale ? "He" : "She";
_himHerReplacer = isMale ? "him" : "her";
_himselfHerselfReplacer = isMale ? "himself" : "herself";
_hisHerReplacer = isMale ? "his" : "her";
_hisHerUpperReplacer = isMale ? "His" : "Her";
}
/// <summary>
/// Replaces all known replacers into the given message
/// </summary>
/// <param name="inputMessage"> The input message </param>
/// <param name="firstName"> The first name </param>
/// <param name="lastName"> The last name </param>
/// <returns> Returns updated message </returns>
public static string ApplyReplacers(
string inputMessage,
string firstName,
string lastName)
{
return inputMessage
.Replace("%UserName%", $"{firstName} {lastName}")
.Replace("%LastName%", lastName)
.Replace("%FirstName%", firstName)
.Replace("%SheHe%", _sheHeUpperReplacer)
.Replace("%HeShe%", _sheHeUpperReplacer)
.Replace("%sheHe%", _sheHeReplacer)
.Replace("%heShe%", _sheHeReplacer)
.Replace("%himHer%", _himHerReplacer)
.Replace("%herHim%", _himHerReplacer)
.Replace("%himselfHerself%", _himselfHerselfReplacer)
.Replace("%herselfHimself%", _himselfHerselfReplacer)
.Replace("%HisHer%", _hisHerUpperReplacer)
.Replace("%HerHis%", _hisHerUpperReplacer)
.Replace("%hisHer%", _hisHerReplacer)
.Replace("%herHis%", _hisHerReplacer);
}
}
}
MongoDB Logo MongoDB