-
Notifications
You must be signed in to change notification settings - Fork 483
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
2,454 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<configuration> | ||
<configSections> | ||
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" > | ||
<section name="Smartstore.WebApi.Client.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" /> | ||
</sectionGroup> | ||
</configSections> | ||
<userSettings> | ||
<Smartstore.WebApi.Client.Properties.Settings> | ||
<setting name="ApiPublicKey" serializeAs="String"> | ||
<value /> | ||
</setting> | ||
<setting name="ApiSecretKey" serializeAs="String"> | ||
<value /> | ||
</setting> | ||
<setting name="ApiUrl" serializeAs="String"> | ||
<value /> | ||
</setting> | ||
<setting name="ApiPaths" serializeAs="String"> | ||
<value /> | ||
</setting> | ||
<setting name="ApiContent" serializeAs="String"> | ||
<value /> | ||
</setting> | ||
<setting name="ApiQuery" serializeAs="String"> | ||
<value /> | ||
</setting> | ||
<setting name="ApiPaths2" serializeAs="String"> | ||
<value /> | ||
</setting> | ||
<setting name="ApiVersion" serializeAs="String"> | ||
<value /> | ||
</setting> | ||
<setting name="ApiHeaders" serializeAs="String"> | ||
<value /> | ||
</setting> | ||
<setting name="FileUpload" serializeAs="String"> | ||
<value /> | ||
</setting> | ||
<setting name="ApiProxyPort" serializeAs="String"> | ||
<value /> | ||
</setting> | ||
</Smartstore.WebApi.Client.Properties.Settings> | ||
</userSettings> | ||
</configuration> |
62 changes: 62 additions & 0 deletions
62
tools/Smartstore.WebApi.Client/Extensions/ComboBoxExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using System.Text; | ||
|
||
namespace Smartstore.WebApi.Client | ||
{ | ||
internal static class ComboBoxExtensions | ||
{ | ||
private const char _delimiter = '¶'; | ||
|
||
public static void InsertRolled(this ComboBox combo, string str, int max) | ||
{ | ||
if (!string.IsNullOrEmpty(str)) | ||
{ | ||
int i; | ||
for (i = combo.Items.Count - 1; i >= 0; --i) | ||
{ | ||
if (string.Compare(combo.Items[i].ToString(), str, true) == 0) | ||
combo.Items.RemoveAt(i); | ||
} | ||
|
||
combo.Items.Insert(0, str); | ||
|
||
for (i = combo.Items.Count - 1; i > max; --i) | ||
{ | ||
combo.Items.RemoveAt(i); | ||
} | ||
|
||
combo.Text = str; | ||
} | ||
} | ||
|
||
public static void FromString(this ComboBox.ObjectCollection coll, string values) | ||
{ | ||
if (!string.IsNullOrWhiteSpace(values)) | ||
{ | ||
string[] items = values.Split(new[] { _delimiter }, StringSplitOptions.RemoveEmptyEntries); | ||
coll.AddRange(items); | ||
} | ||
} | ||
|
||
public static string IntoString(this ComboBox.ObjectCollection coll) | ||
{ | ||
if (coll.Count <= 0) | ||
return string.Empty; | ||
|
||
var sb = new StringBuilder(); | ||
foreach (var item in coll) | ||
{ | ||
if (sb.Length > 0) | ||
sb.Append(_delimiter); | ||
sb.Append(item); | ||
} | ||
|
||
return string.Join(_delimiter.ToString(), sb.ToString()); | ||
} | ||
|
||
public static void RemoveCurrent(this ComboBox combo) | ||
{ | ||
combo.Items.Remove(combo.Text); | ||
combo.ResetText(); | ||
} | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
tools/Smartstore.WebApi.Client/Extensions/StringExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using System.Diagnostics; | ||
using System.Globalization; | ||
|
||
namespace Smartstore.WebApi.Client | ||
{ | ||
internal static class StringExtensions | ||
{ | ||
public static void Dump(this string value, bool appendMarks = false) | ||
{ | ||
Debug.WriteLine(value); | ||
Debug.WriteLineIf(appendMarks, "------------------------------------------------"); | ||
} | ||
|
||
public static DialogResult Box(this string message, MessageBoxButtons buttons = MessageBoxButtons.OK, MessageBoxIcon icon = MessageBoxIcon.Information) | ||
{ | ||
return MessageBox.Show(message, Program.AppName, buttons, icon); | ||
} | ||
|
||
public static int ToInt(this string value, int defaultValue = 0) | ||
{ | ||
int result; | ||
if (int.TryParse(value, out result)) | ||
{ | ||
return result; | ||
} | ||
return defaultValue; | ||
} | ||
|
||
public static string EmptyNull(this string value) | ||
{ | ||
return (value ?? string.Empty).Trim(); | ||
} | ||
|
||
public static bool IsEmpty(this string value) | ||
{ | ||
return string.IsNullOrWhiteSpace(value); | ||
} | ||
|
||
public static bool HasValue(this string value) | ||
{ | ||
return !string.IsNullOrWhiteSpace(value); | ||
} | ||
|
||
public static string FormatInvariant(this string format, params object[] objects) | ||
{ | ||
return string.Format(CultureInfo.InvariantCulture, format, objects); | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
tools/Smartstore.WebApi.Client/HttpClient/WebApiRequestContext.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System.Text; | ||
|
||
namespace Smartstore.WebApi.Client | ||
{ | ||
public class WebApiRequestContext | ||
{ | ||
public string PublicKey { get; set; } | ||
public string SecretKey { get; set; } | ||
|
||
public string Url { get; set; } | ||
public int ProxyPort { get; set; } | ||
public string HttpMethod { get; set; } | ||
public string HttpAcceptType { get; set; } | ||
public string AdditionalHeaders { get; set; } | ||
|
||
public bool IsValid => !string.IsNullOrWhiteSpace(PublicKey) && !string.IsNullOrWhiteSpace(SecretKey) && | ||
!string.IsNullOrWhiteSpace(Url) && | ||
!string.IsNullOrWhiteSpace(HttpMethod) && !string.IsNullOrWhiteSpace(HttpAcceptType); | ||
|
||
public override string ToString() | ||
{ | ||
var sb = new StringBuilder(); | ||
|
||
sb.AppendLine("PublicKey: " + PublicKey); | ||
sb.AppendLine("SecretKey: " + SecretKey); | ||
sb.AppendLine("Url: " + Url); | ||
sb.AppendLine("Proxy Port: " + (ProxyPort > 0 ? ProxyPort.ToString() : string.Empty)); | ||
sb.AppendLine("HttpMethod: " + HttpMethod); | ||
sb.AppendLine("HttpAcceptType: " + HttpAcceptType); | ||
|
||
return sb.ToString(); | ||
} | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
tools/Smartstore.WebApi.Client/HttpClient/WebApiResponse.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using Newtonsoft.Json.Linq; | ||
using Smartstore.WebApi.Client.Models; | ||
|
||
namespace Smartstore.WebApi.Client | ||
{ | ||
public class WebApiResponse | ||
{ | ||
public string Status { get; set; } | ||
public string Headers { get; set; } | ||
public string Content { get; set; } | ||
public string ContentType { get; set; } | ||
public long ContentLength { get; set; } | ||
|
||
/// <seealso cref="http://weblog.west-wind.com/posts/2012/Aug/30/Using-JSONNET-for-dynamic-JSON-parsing" /> | ||
/// <seealso cref="http://james.newtonking.com/json/help/index.html?topic=html/QueryJsonDynamic.htm" /> | ||
/// <seealso cref="http://james.newtonking.com/json/help/index.html?topic=html/LINQtoJSON.htm" /> | ||
public List<Customer> ParseCustomers() | ||
{ | ||
if (string.IsNullOrWhiteSpace(Content)) | ||
{ | ||
return null; | ||
} | ||
|
||
// dynamic dynamicJson = JObject.Parse(response.Content); | ||
|
||
// foreach (dynamic customer in dynamicJson.value) | ||
// { | ||
// string str = string.Format("{0} {1} {2}", customer.Id, customer.CustomerGuid, customer.Email); | ||
//str.Dump(); | ||
// } | ||
|
||
var json = JObject.Parse(Content); | ||
string metadata = (string)json["@odata.context"]; | ||
|
||
if (!string.IsNullOrWhiteSpace(metadata) && metadata.EndsWith("#Customers")) | ||
{ | ||
var customers = json["value"].Select(x => x.ToObject<Customer>()).ToList(); | ||
return customers; | ||
} | ||
|
||
return null; | ||
} | ||
} | ||
} |
Oops, something went wrong.