// Author: Simon Gockner
// Created: 2020-02-08
// Copyright(c) 2020 SimonG. All Rights Reserved.
using System;
namespace GBase.Api.Communication
{
///
/// The protocol used for the connection between client and server
///
public enum ServerProtocol //TODO: Decide which protocols should be usable
{
///
/// Http connection
///
Http,
///
/// Https connection
///
Https,
///
/// net.tcp connection
///
Tcp
}
///
/// Extension methods for the enum
///
public static class ServerProtocolExtensions
{
///
/// Get a protocol string for a
///
/// The
/// A protocol string for the
/// Invalid protocol passed.
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");
}
}
///
/// Get the for a given
///
/// The given
/// The for the given
/// Invalid string passed.
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.");
}
}
}