Skip to content

Commit a44b19e

Browse files
committed
2 parents dedc9b8 + d34a571 commit a44b19e

File tree

6 files changed

+61
-27
lines changed

6 files changed

+61
-27
lines changed

Library/ClassLibraryCSV/ClassLibraryCsvExtensionMethods.cs

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -747,10 +747,10 @@ public static string ReplaceDefaults(this string inputValue, string old1, string
747747
/// <summary>
748748
/// Replace placeholder in a template with value of property
749749
/// </summary>
750-
/// <param name="template">The template, e.G. ID:{ID}</param>
750+
/// <param name="template">The template with placeholder in {}, e.G. ID:{ID} </param>
751751
/// <param name="obj">The object that is used to look at the properties</param>
752752
/// <returns>Any found property placeholder is replaced by the property value</returns>
753-
public static string ReplacePlaceholder(this string template, object obj)
753+
public static string ReplacePlaceholderWithPropertyValues(this string template, object obj)
754754
{
755755
if (template.IndexOf('{') == -1)
756756
return template;
@@ -775,7 +775,40 @@ public static string ReplacePlaceholder(this string template, object obj)
775775
foreach (var pro in placeholder)
776776
template = template.ReplaceCaseInsensitive(pro.Key, pro.Value);
777777

778-
return template;
778+
return template.Replace(" ", " ");
779+
}
780+
781+
/// <summary>
782+
/// Replace placeholder in a template with the text provide in the parameters the order of the placeholders is important not their contend
783+
/// </summary>
784+
/// <param name="template">The template with placeholder in {}, e.G. ID:{ID} </param>
785+
/// <param name="values">a variable number of text that will replace the placeholder in order of appearance</param>
786+
/// <returns>Any found property placeholder is replaced by the provide text</returns>
787+
public static string ReplacePlaceholderWithText(this string template, params string[] values)
788+
{
789+
if (template.IndexOf('{') == -1)
790+
return template;
791+
792+
// get all placeholders in {}
793+
var rgx = new Regex(@"\{[^\}]+\}");
794+
795+
var placeholder = new Dictionary<string, string>();
796+
var index = 0;
797+
foreach (Match match in rgx.Matches(template))
798+
{
799+
if (index >= values.Length)
800+
break;
801+
if (!placeholder.ContainsKey(match.Value))
802+
{
803+
placeholder.Add(match.Value, values[index++]);
804+
}
805+
}
806+
807+
// replace them with the property value from setting
808+
foreach (var pro in placeholder)
809+
template = template.ReplaceCaseInsensitive(pro.Key, pro.Value);
810+
811+
return template.Replace(" ", " ");
779812
}
780813

781814
/// <summary>

Library/ClassLibraryCSV/RemoteAccess.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,11 @@ public virtual string User
115115
}
116116
}
117117

118-
[XmlAttribute]
118+
[XmlAttribute("Password")]
119119
[DefaultValue("")]
120120
[Browsable(true)]
121121
[ReadOnly(false)]
122-
public virtual string Password
122+
public virtual string EncryptedPassword
123123
{
124124
get => m_EncryptedPassword;
125125
set
@@ -128,7 +128,7 @@ public virtual string Password
128128
if (m_EncryptedPassword.Equals(newVal))
129129
return;
130130
m_EncryptedPassword = newVal;
131-
NotifyPropertyChanged(nameof(Password));
131+
NotifyPropertyChanged(nameof(EncryptedPassword));
132132
}
133133
}
134134

@@ -143,7 +143,7 @@ public void CopyTo(RemoteAccess other)
143143
{
144144
if (other == null)
145145
return;
146-
other.Password = Password;
146+
other.EncryptedPassword = EncryptedPassword;
147147
other.User = User;
148148
other.HostName = HostName;
149149
other.Protocol = Protocol;
@@ -161,7 +161,7 @@ public bool Equals(RemoteAccess other)
161161
return false;
162162
if (ReferenceEquals(this, other))
163163
return true;
164-
return string.Equals(Password, other.Password) && m_Protocol == other.Protocol &&
164+
return string.Equals(EncryptedPassword, other.EncryptedPassword) && m_Protocol == other.Protocol &&
165165
string.Equals(HostName, other.HostName, StringComparison.OrdinalIgnoreCase) &&
166166
string.Equals(User, other.User, StringComparison.OrdinalIgnoreCase);
167167
}

Library/ClassLibraryCSVUnitTest/ExtensionTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ public void ReplacePlaceholder()
2323
ID = "12234"
2424
};
2525

26-
Assert.AreEqual("This is a test 12234", "This is a test {Id}".ReplacePlaceholder(csv));
27-
Assert.AreEqual("This is fileName a test 12234", "This is {FileName} a test {Id}".ReplacePlaceholder(csv));
28-
Assert.AreEqual("This is {nonsense} a test", "This is {nonsense} a test".ReplacePlaceholder(csv));
26+
Assert.AreEqual("This is a test 12234", "This is a test {Id}".ReplacePlaceholderWithPropertyValues(csv));
27+
Assert.AreEqual("This is fileName a test 12234", "This is {FileName} a test {Id}".ReplacePlaceholderWithPropertyValues(csv));
28+
Assert.AreEqual("This is {nonsense} a test", "This is {nonsense} a test".ReplacePlaceholderWithPropertyValues(csv));
2929
}
3030
}
3131
}

Library/ClassLibraryCSVUnitTest/RemoteAccessTests.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* If not, see http://www.gnu.org/licenses/ .
1212
*
1313
*/
14+
1415
using Microsoft.VisualStudio.TestTools.UnitTesting;
1516

1617
namespace CsvTools.Tests
@@ -32,7 +33,7 @@ public void EqualsTest()
3233
public void RemoteAccessTest()
3334
{
3435
var testCase = new RemoteAccess();
35-
bool hasFired = false;
36+
var hasFired = false;
3637
testCase.PropertyChanged += delegate (object sender, System.ComponentModel.PropertyChangedEventArgs e)
3738
{
3839
hasFired = true;
@@ -51,11 +52,11 @@ public void RemoteAccessTest()
5152
testCase.User = "Hello";
5253
Assert.IsFalse(hasFired);
5354

54-
testCase.Password = "World";
55+
testCase.EncryptedPassword = "World";
5556
Assert.IsTrue(hasFired);
56-
Assert.AreEqual("World", testCase.Password);
57+
Assert.AreEqual("World", testCase.EncryptedPassword);
5758
hasFired = false;
58-
testCase.Password = "World";
59+
testCase.EncryptedPassword = "World";
5960
Assert.IsFalse(hasFired);
6061
}
6162
}

Library/SharedAssemblyInfo.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@
1414
//
1515
// You can specify all the values or you can default the Build and Revision Numbers by using the '*'
1616
// as shown below: [assembly: AssemblyVersion("1.0.*")]
17-
[assembly: AssemblyVersion("1.6.4.404")]
18-
[assembly: AssemblyFileVersion("1.6.4.404")]
19-
[assembly: AssemblyInformationalVersion("1.6.4.404")] // a.k.a. "Product version"
17+
[assembly: AssemblyVersion("1.6.4.407")]
18+
[assembly: AssemblyFileVersion("1.6.4.407")]
19+
[assembly: AssemblyInformationalVersion("1.6.4.407")] // a.k.a. "Product version"

Library/WinFormControls/TimedMessage.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -210,15 +210,6 @@ public DialogResult Show(Form owner, string message, string title, MessageBoxBut
210210

211211
m_MessageBoxButtons = buttons;
212212

213-
if (!string.IsNullOrEmpty(button1Text))
214-
button1.Text = button1Text;
215-
216-
if (!string.IsNullOrEmpty(button2Text))
217-
button2.Text = button2Text;
218-
219-
if (!string.IsNullOrEmpty(button3Text))
220-
button3.Text = button3Text;
221-
222213
// One Button
223214
if (buttons == MessageBoxButtons.OK)
224215
{
@@ -289,6 +280,15 @@ public DialogResult Show(Form owner, string message, string title, MessageBoxBut
289280
CancelButton = button3;
290281
}
291282

283+
if (!string.IsNullOrEmpty(button1Text))
284+
button1.Text = button1Text;
285+
286+
if (!string.IsNullOrEmpty(button2Text))
287+
button2.Text = button2Text;
288+
289+
if (!string.IsNullOrEmpty(button3Text))
290+
button3.Text = button3Text;
291+
292292
if (defaultButton == MessageBoxDefaultButton.Button1)
293293
{
294294
AcceptButton = button1;

0 commit comments

Comments
 (0)