public static IEnumerable <T> FilterExportables <T>(this IEnumerable <T> exportables, IServerDefinition serverDefinition = null)
            where T : IExportable
        {
            if (exportables == null)
            {
                return(null);
            }
            //Get all the possible matches
            IEnumerable <T> allMatched = serverDefinition != null?
                                         exportables.Where(x => Match(x.Metadata, serverDefinition)).ToList() : exportables;

            IList <T> list = allMatched.ToList();

            //If specific server type requested and the list has any item with that server type remove the others.
            //for instance is there's server for all server types and one specifically for sql and give metadata is asking for sql then
            //we should return the sql one even if the other service has higher priority

            IList <T> withSameServerType = list.Where(x => serverDefinition.HasSameServerName(x.Metadata)).ToList();

            if (withSameServerType.Any())
            {
                list = withSameServerType;
            }
            IList <T> withSameCategory = list.Where(x => serverDefinition.HasSameCategory(x.Metadata)).ToList();

            if (withSameCategory.Any())
            {
                list = withSameCategory;
            }
            return(list);
        }
 internal static bool EqualsServerDefinition(this IServerDefinition serverDefinition, IServerDefinition otherServerDefinition)
 {
     if (serverDefinition == null && otherServerDefinition == null)
     {
         return(true);
     }
     if (serverDefinition != null && otherServerDefinition != null)
     {
         return(((string.IsNullOrEmpty(serverDefinition.Category) && string.IsNullOrEmpty(otherServerDefinition.Category)) || serverDefinition.HasSameCategory(otherServerDefinition)) &&
                ((string.IsNullOrEmpty(serverDefinition.ServerType) && string.IsNullOrEmpty(otherServerDefinition.ServerType)) || serverDefinition.HasSameServerName(otherServerDefinition)));
     }
     return(false);
 }