Skip to content
This repository has been archived by the owner on Aug 20, 2024. It is now read-only.

Commit

Permalink
Merge branch 'feature/uri-object-for-parsing' into version/1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
小傅Fox committed Mar 7, 2015
2 parents 7582eb9 + 48d3fad commit 2e71c1d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 45 deletions.
75 changes: 35 additions & 40 deletions URLSchemeHandler/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,62 +4,57 @@
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
using WiAuth.ClassLibrary;
using System.Text.RegularExpressions;

namespace WiAuth.URLSchemeHandler
{
class Program
{
const string auth_prefix = "wiauth://authorize&";
const string scheme_name = "wiauth";
const string uri_host = "authorize";
static void Main(string[] args)
{
if (args.Count() == 1)
{
if (args[0].StartsWith(auth_prefix))
var uri = new Uri(args[0]);
if (uri.Scheme != scheme_name)
{
#if DEBUG
Console.WriteLine("Authorize");
#endif
var cb = args[0].Replace(auth_prefix, "");
try
{
cb = cb.Substring(0, cb.Length - 1);
}
catch (System.ArgumentOutOfRangeException)
{
}
catch (Exception ex)
{
WiAuth.ClassLibrary.Error.ThrowError(ex);
}
#if DEBUG
Console.WriteLine("Callback: {0}", cb);
#endif
var proccess = "\"" + AppDomain.CurrentDomain.BaseDirectory + "auth.exe\"";
#if DEBUG
Console.WriteLine("Call: {0}", proccess);
#endif
try
{
Process.Start(proccess, cb);
}
catch (System.ComponentModel.Win32Exception ex)
{
WiAuth.ClassLibrary.Error.ThrowError(ex.Message + " >>> " + proccess);
}
catch (Exception ex)
{
WiAuth.ClassLibrary.Error.ThrowError(ex);
}
return;
Invaid();
}
switch (uri.Host)
{
case uri_host:
{
var query = uri.Fragment;
Process.Start(AppDomain.CurrentDomain.BaseDirectory + "auth.exe", query);
break;
}
default:
{
Invaid();
break;
}
}
return;
}
Invaid(args);
Invaid();
}

private static void Invaid(string[] args)
private static void Invaid()
{
WiAuth.ClassLibrary.Error.ThrowError(new Exception("Invaid parameters."));
Error.ThrowError(new Exception("Invaid parameters."));
}

private static string GetParam(string query, string paramName)
{
Regex urlRegex = new Regex(@"(?:^|/?|&)" + paramName + "=([^&]*)(?:&|$)");
Match m = urlRegex.Match(query.ToLower());
if (m.Success)
{
return m.Groups[1].Value;
}
throw new KeyNotFoundException();
}
}
}
10 changes: 5 additions & 5 deletions URLSchemeHandler/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("c2985ded-2f8b-4918-b456-486f5eac290d")]

// 程序集的版本信息由下面四个值组成:
// 程序集的版本信息由下面四个值组成:
//
// 主版本
// 次版本
// 次版本
// 生成号
// 修订号
//
// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
// 方法是按如下所示使用“*”:
// 方法是按如下所示使用“*”:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.19")]
[assembly: AssemblyFileVersion("1.0.0.19")]
[assembly: AssemblyVersion("1.1.0.4")]
[assembly: AssemblyFileVersion("1.1.0.4")]

0 comments on commit 2e71c1d

Please sign in to comment.