You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
2.6 KiB
74 lines
2.6 KiB
// Author: Simon Gockner
|
|
// Created: 2020-02-08
|
|
// Copyright(c) 2020 SimonG. All Rights Reserved.
|
|
|
|
using System;
|
|
|
|
namespace GBase.Api.Communication
|
|
{
|
|
/// <summary>
|
|
/// The protocol used for the connection between client and server
|
|
/// </summary>
|
|
public enum ServerProtocol //TODO: Decide which protocols should be usable
|
|
{
|
|
/// <summary>
|
|
/// Http connection
|
|
/// </summary>
|
|
Http,
|
|
|
|
/// <summary>
|
|
/// Https connection
|
|
/// </summary>
|
|
Https,
|
|
|
|
/// <summary>
|
|
/// net.tcp connection
|
|
/// </summary>
|
|
Tcp
|
|
}
|
|
|
|
/// <summary>
|
|
/// Extension methods for the <see cref="ServerProtocol"/> enum
|
|
/// </summary>
|
|
public static class ServerProtocolExtensions
|
|
{
|
|
/// <summary>
|
|
/// Get a protocol string for a <see cref="ServerProtocol"/>
|
|
/// </summary>
|
|
/// <param name="protocol">The <see cref="ServerProtocol"/></param>
|
|
/// <returns>A protocol string for the <see cref="ServerProtocol"/></returns>
|
|
/// <exception cref="ArgumentOutOfRangeException">Invalid protocol passed.</exception>
|
|
public static string GetProtocolString(this ServerProtocol protocol)
|
|
{
|
|
switch (protocol)
|
|
{
|
|
case ServerProtocol.Http:
|
|
return @"http://";
|
|
case ServerProtocol.Https:
|
|
return @"https://";
|
|
case ServerProtocol.Tcp:
|
|
return @"net.tcp://";
|
|
default:
|
|
throw new ArgumentOutOfRangeException(nameof(protocol), protocol, "Invalid Protocol");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get the <see cref="ServerProtocol"/> for a given <see cref="string"/>
|
|
/// </summary>
|
|
/// <param name="string">The given <see cref="string"/></param>
|
|
/// <returns>The <see cref="ServerProtocol"/> for the given <see cref="string"/></returns>
|
|
/// <exception cref="ArgumentOutOfRangeException">Invalid string passed.</exception>
|
|
public static ServerProtocol GetServerProtocolFromString(string @string)
|
|
{
|
|
if (@string.Equals(@"http://") || @string.Equals("http"))
|
|
return ServerProtocol.Http;
|
|
else if (@string.Equals(@"https://") || @string.Equals("https"))
|
|
return ServerProtocol.Https;
|
|
else if (@string.Equals(@"net.tcp://") || @string.Equals("net.tcp") || @string.Equals("tcp"))
|
|
return ServerProtocol.Tcp;
|
|
else
|
|
throw new ArgumentOutOfRangeException(nameof(@string), @string, "Invalid string.");
|
|
}
|
|
}
|
|
} |