If custom uploader name is same as automated name then don't serialize it

This commit is contained in:
Jaex 2017-09-19 03:33:22 +03:00
parent 4d7f101c4d
commit 637fd4bcac
4 changed files with 26 additions and 25 deletions

View file

@ -118,7 +118,6 @@ private void InitializeControls()
// Custom uploader
txtCustomUploaderLog.AddContextMenu();
eiCustomUploaders.ObjectType = typeof(CustomUploaderItem);
txtCustomUploaderName.HandleCreated += (sender, e) => txtCustomUploaderName.SetWatermark(Resources.UploadersConfigForm_CustomUploader_Name);
CustomUploaderAddDestinationTypes();
cbCustomUploaderRequestType.Items.AddRange(Enum.GetNames(typeof(CustomUploaderRequestType)));
cbCustomUploaderResponseType.Items.AddRange(Helpers.GetLocalizedEnumDescriptions<ResponseType>());

View file

@ -40,6 +40,8 @@ public class CustomUploaderItem
[DefaultValue("")]
public string Name { get; set; }
public bool ShouldSerializeName() => !string.IsNullOrEmpty(Name) && Name != GetAutomaticName();
[DefaultValue(CustomUploaderDestinationType.None)]
public CustomUploaderDestinationType DestinationType { get; set; }
@ -95,19 +97,11 @@ public override string ToString()
{
if (string.IsNullOrEmpty(Name))
{
if (!string.IsNullOrEmpty(RequestURL) && Uri.TryCreate(RequestURL, UriKind.Absolute, out Uri uri))
string name = GetAutomaticName();
if (!string.IsNullOrEmpty(name))
{
string host = uri.Host;
if (!string.IsNullOrEmpty(host))
{
if (host.StartsWith("www."))
{
host = host.Substring(4);
}
return host;
}
return name;
}
return "Name";
@ -116,6 +110,26 @@ public override string ToString()
return Name;
}
private string GetAutomaticName()
{
if (!string.IsNullOrEmpty(RequestURL) && Uri.TryCreate(RequestURL, UriKind.Absolute, out Uri uri))
{
string host = uri.Host;
if (!string.IsNullOrEmpty(host))
{
if (host.StartsWith("www."))
{
host = host.Substring(4);
}
return host;
}
}
return null;
}
public HttpMethod GetHttpMethod()
{
switch (RequestType)

View file

@ -705,15 +705,6 @@ internal static string UploadersConfigForm_BoxListFolders_Box_refresh_folders_li
}
}
/// <summary>
/// Looks up a localized string similar to Name.
/// </summary>
internal static string UploadersConfigForm_CustomUploader_Name {
get {
return ResourceManager.GetString("UploadersConfigForm_CustomUploader_Name", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Error.
/// </summary>

View file

@ -389,9 +389,6 @@ Created folders:</value>
<data name="OAuthControl_OAuthControl_PasteVerificationCodeHere" xml:space="preserve">
<value>Paste verification code here</value>
</data>
<data name="UploadersConfigForm_CustomUploader_Name" xml:space="preserve">
<value>Name</value>
</data>
<data name="GooglePhotos" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\favicons\googlephotos.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>