-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Basic Win32 Test Client to make sure everything works
Consider it a bit of a reference client. Some refactoring needs to happen to the project so that models can be shared between the server and this project.
- Loading branch information
Showing
27 changed files
with
1,836 additions
and
1 deletion.
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
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,6 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<configuration> | ||
<startup> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" /> | ||
</startup> | ||
</configuration> |
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,43 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Net; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Win32Client.Helpers; | ||
using Win32Client.Models; | ||
|
||
namespace Win32Client.Client | ||
{ | ||
public class YouTubeProxyClient | ||
{ | ||
private WebClient client; | ||
const char separator = '|'; | ||
|
||
|
||
|
||
public YouTubeProxyClient(string baseUrl) | ||
{ | ||
client = new WebClient(); | ||
client.BaseAddress = baseUrl; | ||
} | ||
|
||
public List<SearchResultModel> Search(string terms) | ||
{ | ||
var csvResult = client.DownloadData(string.Format("api/Search/{0}", Uri.EscapeDataString(terms))).MacRomanToString(); | ||
|
||
var results = MacDeserialiser.Deserialize<SearchResultModel>(csvResult); | ||
|
||
return results.ToList(); | ||
} | ||
|
||
public List<ConversionStatusModel> GetVideo(string videoId, string profile) | ||
{ | ||
var csvResult = client.DownloadData(string.Format("api/Video/{0}/?profile={1}", videoId, profile)).MacRomanToString(); | ||
|
||
var results = MacDeserialiser.Deserialize<ConversionStatusModel>(csvResult); | ||
|
||
return results.ToList(); | ||
} | ||
} | ||
} |
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,57 @@ | ||
using Newtonsoft.Json; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Win32Client | ||
{ | ||
public class ClientSettings | ||
{ | ||
const string SettingsFile = "ClientSettings.json"; | ||
|
||
public static ClientSettings GetSettings() | ||
{ | ||
if (File.Exists(SettingsFile)) | ||
{ | ||
try | ||
{ | ||
return JsonConvert.DeserializeObject<ClientSettings>(File.ReadAllText(SettingsFile)); | ||
} | ||
catch (Exception ex) | ||
{ | ||
// Log it? | ||
} | ||
} | ||
return ClientSettings.DefaultSettings; | ||
} | ||
|
||
|
||
|
||
public static ClientSettings DefaultSettings | ||
{ | ||
get | ||
{ | ||
return new ClientSettings | ||
{ | ||
BaseUrl = "http://localhost:9000/", | ||
Profile = "h263" | ||
}; | ||
} | ||
} | ||
|
||
public string BaseUrl | ||
{ | ||
get;set; | ||
} | ||
|
||
public string Profile { get; set; } | ||
|
||
public void SaveSettings() | ||
{ | ||
File.WriteAllText(SettingsFile, JsonConvert.SerializeObject(this)); | ||
} | ||
} | ||
} |
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,29 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Windows.Forms; | ||
|
||
namespace Win32Client.Helpers | ||
{ | ||
public static class ControlHelper | ||
{ | ||
/// <summary> | ||
/// Executes the Action asynchronously on the UI thread, does not block execution on the calling thread. | ||
/// </summary> | ||
/// <param name="control"></param> | ||
/// <param name="code"></param> | ||
public static void UIThread(this Control @this, Action code) | ||
{ | ||
if (@this.InvokeRequired) | ||
{ | ||
@this.BeginInvoke(code); | ||
} | ||
else | ||
{ | ||
code.Invoke(); | ||
} | ||
} | ||
} | ||
} |
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,72 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Win32Client.Helpers | ||
{ | ||
public static class MacDeserialiser | ||
{ | ||
const char CsvSeparator = '|'; | ||
|
||
public static IEnumerable<T> Deserialize<T>(string input) | ||
{ | ||
var fields = | ||
(from mi in typeof(T).GetMembers(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static) | ||
where new[] { MemberTypes.Field, MemberTypes.Property }.Contains(mi.MemberType) | ||
let orderAttr = (ColumnOrderAttribute)Attribute.GetCustomAttribute(mi, typeof(ColumnOrderAttribute)) | ||
orderby orderAttr == null ? int.MaxValue : orderAttr.Order, mi.Name | ||
select mi).ToArray(); | ||
|
||
var lines = input.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); | ||
var result = new List<T>(); | ||
foreach (var line in lines) | ||
{ | ||
var item = line.Split(CsvSeparator); | ||
var record = (T)Activator.CreateInstance(typeof(T)); | ||
|
||
for (int i = 0; i < fields.Length; i++) | ||
{ | ||
var field = fields[i]; | ||
SetValue(field, record, item[i]); | ||
} | ||
result.Add(record); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
private static void SetValue<T>(MemberInfo field, T record, string value) | ||
{ | ||
if (field is FieldInfo) | ||
{ | ||
var fi = (FieldInfo)field; | ||
fi.SetValue(record, Convert.ChangeType(value, fi.FieldType)); | ||
} | ||
else if (field is PropertyInfo) | ||
{ | ||
var pi = (PropertyInfo)field; | ||
if (pi.PropertyType.IsEnum) | ||
pi.SetValue(record, Enum.Parse(pi.PropertyType, value)); | ||
else | ||
pi.SetValue(record, Convert.ChangeType(value, pi.PropertyType)); | ||
} | ||
else | ||
{ | ||
throw new Exception("Unhandled case."); | ||
} | ||
} | ||
|
||
} | ||
|
||
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)] | ||
public class ColumnOrderAttribute : Attribute | ||
{ | ||
public int Order { get; private set; } | ||
public ColumnOrderAttribute(int order) { Order = order; } | ||
} | ||
} | ||
|
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,22 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Win32Client.Helpers | ||
{ | ||
public static class StringExtensions | ||
{ | ||
/// <summary> | ||
/// The Mac Results are in MacRoman encoding, return it back to UTF | ||
/// </summary> | ||
/// <param name="source"></param> | ||
/// <returns></returns> | ||
public static string MacRomanToString(this byte[] source) | ||
{ | ||
return System.Text.Encoding.GetEncoding(10000).GetString(source); | ||
} | ||
|
||
} | ||
} |
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,37 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Win32Client.Helpers; | ||
|
||
namespace Win32Client.Models | ||
{ | ||
public class ConversionStatusModel | ||
{ | ||
[ColumnOrder(1)] | ||
public string VideoId { get; set; } | ||
|
||
[ColumnOrder(2)] | ||
public StatusCodes Status { get; set; } | ||
|
||
[ColumnOrder(3)] | ||
public string Error { get; set; } | ||
|
||
/// <summary> | ||
/// Duration in seconds | ||
/// </summary> | ||
[ColumnOrder(4)] | ||
public int Duration { get; set; } | ||
|
||
[ColumnOrder(5)] | ||
public int Progress { get; set; } | ||
|
||
public enum StatusCodes | ||
{ | ||
Error, | ||
Encoding, | ||
ReadyForDownload | ||
} | ||
} | ||
} |
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,28 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Win32Client.Helpers; | ||
|
||
namespace Win32Client.Models | ||
{ | ||
public class SearchResultModel | ||
{ | ||
|
||
[ColumnOrderAttribute(1)] | ||
public string VideoId { get; set; } | ||
|
||
[ColumnOrderAttribute(2)] | ||
public string Title { get; set; } | ||
|
||
[ColumnOrderAttribute(3)] | ||
public string Description { get; set; } | ||
|
||
[ColumnOrderAttribute(4)] | ||
public string Url { get; set; } | ||
|
||
[ColumnOrderAttribute(5)] | ||
public string ThumbUrl { get; set; } | ||
} | ||
} |
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,22 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using System.Windows.Forms; | ||
|
||
namespace Win32Client | ||
{ | ||
static class Program | ||
{ | ||
/// <summary> | ||
/// The main entry point for the application. | ||
/// </summary> | ||
[STAThread] | ||
static void Main() | ||
{ | ||
Application.EnableVisualStyles(); | ||
Application.SetCompatibleTextRenderingDefault(false); | ||
Application.Run(new Search()); | ||
} | ||
} | ||
} |
Oops, something went wrong.