//thats the main configuration function
        private XchangeDescriptor[] ReadExchangeDescriptorConfiguration(IConfiguration section)
        {
            var descriptors     = section.GetChildren();
            int exchangeConfigs = descriptors.Count();

            XchangeDescriptor[] exchanges = new XchangeDescriptor[exchangeConfigs + 1];
            if (exchangeConfigs == 0)
            {
                return(exchanges);
            }

            foreach (var exchange in descriptors)
            {
                var exchangeDescriptor = new XchangeDescriptor();
                exchangeDescriptor.Name            = exchange.GetValue <string>("Name");
                exchangeDescriptor.BaseUrl         = exchange.GetValue <string>("BaseUrl");
                exchangeDescriptor.ApiKeyString    = exchange.GetValue <string>("ApiKeyString");
                exchangeDescriptor.SignString      = exchange.GetValue <string>("SignString");
                exchangeDescriptor.TimeStampString = exchange.GetValue <string>("TimeStampString");
                var exchangeEnum = Enum.Parse <Xchange>(exchangeDescriptor.Name);
                exchangeDescriptor.Id          = (int)exchangeEnum;
                exchangeDescriptor.DomainTypes = XchangeConfigToolkit.GenerateTypesDictionary(_dataTypes, exchange.GetSection("DomainTypes"));
                exchangeDescriptor.EndPoints   = GeneratingEndPoints(exchange, exchangeDescriptor.BaseUrl);
                exchangeDescriptor.SetEndPointReturnTypes();
                exchangeDescriptor.SocketDescriptor = ReadSocketConfig(exchange);
                //not tested and not needed yet! exchangeDescriptor.SocketDescriptor.TypeDescriptors = XchangeConfigToolkit.GenerateTypesDictionary(_dataTypes, exchange.GetSection("Socket:Types"));
                exchangeDescriptor.SocketDescriptor.Xchange = exchangeEnum;
                exchangeDescriptor.SocketDescriptor.SubscriptionArgs.Each(s => s.Value.ReturnType = exchangeDescriptor.DomainTypes.GetValueOrDefault(s.Key));
                if (VerifyExchangeDescriptor(exchangeDescriptor))
                {
                    exchanges[exchangeDescriptor.Id] = exchangeDescriptor;
                }
            }
            return(exchanges);
        }
 private bool VerifyExchangeDescriptor(XchangeDescriptor descriptor)
 {
     if (descriptor.EndPoints[(int)XchangeHttpOperation.Unknown] != null)
     {
         return(false);
     }
     return(true);
 }
Example #3
0
 public static void SetEndPointReturnTypes(this XchangeDescriptor descriptor)
 {
     foreach (var endP in descriptor.EndPoints)
     {
         if (endP is null)
         {
             continue;
         }
         var typename = endP.Result;
         if (descriptor.DomainTypes.ContainsKey(typename))
         {
             endP.ReturnType = descriptor.DomainTypes[typename];
         }
         if (descriptor.DomainTypes.ContainsKey(typename + "Dto"))
         {
             endP.ReturnType = descriptor.DomainTypes[typename + "Dto"];
         }
     }
 }
Example #4
0
 public static int CountEndpoints(this XchangeDescriptor descriptor) => descriptor.EndPoints.Length - 1;