-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update Sample project to .NET Core 2.0
- Loading branch information
Showing
8 changed files
with
84 additions
and
169 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
// https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Sample", | ||
"type": "coreclr", | ||
"request": "launch", | ||
"preLaunchTask": "build_sample", | ||
"program": "${workspaceFolder}/Bynder/Sample/bin/Debug/netcoreapp2.0/Bynder.Sample.dll", | ||
"cwd": "${workspaceFolder}/Bynder/Sample", | ||
"console": "internalConsole", | ||
"internalConsoleOptions": "openOnSessionStart", | ||
"logging": { | ||
"moduleLoad": false | ||
} | ||
} | ||
] | ||
} |
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,15 @@ | ||
{ | ||
"version": "2.0.0", | ||
"tasks": [ | ||
{ | ||
"label": "build_sample", | ||
"command": "dotnet", | ||
"type": "process", | ||
"args": [ | ||
"build", | ||
"${workspaceFolder}/Bynder/Sample/Bynder.Sample.csproj" | ||
], | ||
"problemMatcher": "$msCompile" | ||
} | ||
] | ||
} |
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,22 +1,25 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net461</TargetFramework> | ||
<TargetFramework>netcoreapp2.0</TargetFramework> | ||
<AssemblyVersion>1.2.2.0</AssemblyVersion> | ||
<FileVersion>1.2.2.0</FileVersion> | ||
<Company>Bynder</Company> | ||
<Product>Bynder.Sample</Product> | ||
<Copyright>Copyright © Bynder</Copyright> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="System.Configuration" /> | ||
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\Api\Bynder.Api.csproj" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<EmbeddedResource Include="Image\bynder-logo.png"> | ||
<None Update="Config.json"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</EmbeddedResource> | ||
</None> | ||
<None Update="Image\bynder-logo.png"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
</ItemGroup> | ||
</Project> |
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,5 @@ | ||
{ | ||
"api_base_url": "", | ||
"consumer_key": "", | ||
"consumer_secret": "" | ||
} |
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 |
---|---|---|
@@ -1,112 +1,34 @@ | ||
// Copyright (c) Bynder. All rights reserved. | ||
// Copyright (c) Bynder. All rights reserved. | ||
// Licensed under the MIT License. See LICENSE file in the project root for full license information. | ||
|
||
using System; | ||
using System; | ||
using System.Diagnostics; | ||
using Microsoft.Win32; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace Bynder.Sample.OauthUtils | ||
{ | ||
/// <summary> | ||
/// Class to open the Browser with a specific Url. If default explorer is internet explorer | ||
/// we will add -nomerge parameter so we can close it when login is successful. | ||
/// For other browsers probably it will not be able to close it after a successful login. | ||
/// Class to open the Browser with a specific Url. | ||
/// </summary> | ||
public sealed class Browser : IDisposable | ||
public sealed class Browser | ||
{ | ||
/// <summary> | ||
/// Process information | ||
/// </summary> | ||
private readonly Process _proc; | ||
|
||
/// <summary> | ||
/// Creates an instance of browser that will create a process with the default browser pointing to | ||
/// the Url passed. | ||
/// Creates an instance of browser that will open the default browser pointing to the Url passed. | ||
/// </summary> | ||
/// <param name="url">Url we want to open the browser with</param> | ||
/// <param name="waitForToken">token to notify if possible, if the user closes the browser</param> | ||
public Browser(string url, WaitForToken waitForToken) | ||
{ | ||
var browserPath = GetBrowserPath(); | ||
_proc = Process.Start(browserPath, GetBrowserArguments(browserPath, url)); | ||
if (waitForToken != null | ||
&& _proc != null) | ||
{ | ||
_proc.EnableRaisingEvents = true; | ||
_proc.Exited += (sender, e) => waitForToken.WaitHandle.Set(); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Kills started process if possible. | ||
/// </summary> | ||
public void Dispose() | ||
public Browser(string url) | ||
{ | ||
if (_proc != null) | ||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) | ||
{ | ||
try | ||
{ | ||
_proc.Kill(); | ||
} | ||
catch (InvalidOperationException) | ||
{ | ||
// When openning browser for login, if explorer already opened this exception is thrown. Is not an error, so no action | ||
return; | ||
} | ||
Process.Start(new ProcessStartInfo("cmd", $"/c start {url}")); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Gets default browser path. http://stackoverflow.com/questions/13621467/how-to-find-default-web-browser-using-c | ||
/// </summary> | ||
/// <returns>default browser path</returns> | ||
private static string GetBrowserPath() | ||
{ | ||
string browser = string.Empty; | ||
RegistryKey key = null; | ||
try | ||
{ | ||
key = Registry.ClassesRoot.OpenSubKey(@"HTTP\shell\open\command"); | ||
|
||
// trim off quotes | ||
if (key != null) | ||
{ | ||
browser = key.GetValue(null).ToString().ToLower().Trim(new[] { '"' }); | ||
} | ||
|
||
const string ExeExtension = ".exe"; | ||
if (!browser.EndsWith(ExeExtension)) | ||
{ | ||
// get rid of everything after the ".exe" | ||
browser = browser.Substring(0, browser.LastIndexOf(ExeExtension, StringComparison.InvariantCultureIgnoreCase) + 4); | ||
} | ||
} | ||
finally | ||
{ | ||
if (key != null) | ||
{ | ||
key.Close(); | ||
} | ||
} | ||
|
||
return browser; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the arguments to open the default browser with. In case the default browser is | ||
/// iexplorer it adds the -nomerge argument so a new process is created and we can close it. | ||
/// </summary> | ||
/// <param name="browserPath">default browser path</param> | ||
/// <param name="url">Url we want to open</param> | ||
/// <returns>arguments string</returns> | ||
private string GetBrowserArguments(string browserPath, string url) | ||
{ | ||
if (browserPath.ToLower().Contains("iexplore.exe")) | ||
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) | ||
{ | ||
return $"-nomerge {url}"; | ||
Process.Start("open", url); | ||
} | ||
|
||
return url; | ||
Console.WriteLine(string.Format("Open the url in your browser: {0}", url)); | ||
} | ||
} | ||
} |
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