public ExchangeReport Exchange(LicenseClientConfig licenseClientConfig = null)
 {
     return(Exchange(licenseClientConfig ?? LicenseClientConfig, AppInterfaceAvailable ? new int?(1000) : null));
 }
 public ExchangeReport Exchange(LicenseClientConfig licenseClientConfig, int?skipIfNotNeededForSessionKeepAliveSafetyMarginMilli)
 {
     lock (@lock)
     {
         PropertyGenTimespanInt64 <HttpExchangeReport <AuthRequest, AuthResponse> > authExchange = null;
         PropertyGenTimespanInt64 <HttpExchangeReport <FromClientToServerMessage, FromServerToClientMessage> > propertyGenTimespanInt = null;
         LicenseClientConfig obj = licenseClientConfig ?? LicenseClientConfig;
         licenseClientConfig = obj;
         LicenseClientConfig = obj;
         LicenseClient licenseClient = LicenseClient ?? (LicenseClient = new LicenseClient());
         if (licenseClientConfig != null)
         {
             licenseClient.ServerAddress = licenseClientConfig?.ApiVersionAddress;
             licenseClient.Request       = licenseClientConfig?.Request;
         }
         if (SessionContinue)
         {
             IRateLimitStateInt exchangePayloadRateLimit = ExchangePayloadRateLimit;
             long timeMilli = GetTimeMilli();
             var  obj2      = licenseClient?.ExchangeAuthLast?.Value?.Response?.RequestTimeDistanceMaxMilli -
                              skipIfNotNeededForSessionKeepAliveSafetyMarginMilli;
             if (!exchangePayloadRateLimit.AttemptPass(timeMilli, Math.Max(1000, obj2 ?? 0)))
             {
                 return(null);
             }
             object obj3;
             if (licenseClient == null)
             {
                 obj3 = null;
             }
             else
             {
                 PropertyGenTimespanInt64 <HttpExchangeReport <AuthRequest, AuthResponse> > exchangeAuthLast2 = licenseClient.ExchangeAuthLast;
                 obj3 = exchangeAuthLast2?.Value?.Response?.SessionId;
             }
             string sessionId = (string)obj3;
             FromClientToServerMessage request = new FromClientToServerMessage
             {
                 SessionId = sessionId,
                 Interface = InterfaceAppManager?.ToServer(),
                 Time      = GetTimeMilli()
             };
             propertyGenTimespanInt = licenseClient?.ExchangePayload(request);
             FromServerToClientMessage fromServerToClientMessage = propertyGenTimespanInt?.Value?.Response;
             if (fromServerToClientMessage != null)
             {
                 InterfaceAppManager?.FromServer(fromServerToClientMessage.Interface);
             }
         }
         else if (licenseClient?.AuthCompleted ?? false)
         {
             long?obj4;
             if (licenseClient == null)
             {
                 obj4 = null;
             }
             else
             {
                 PropertyGenTimespanInt64 <HttpExchangeReport <AuthRequest, AuthResponse> > exchangeAuthLast3 = licenseClient.ExchangeAuthLast;
                 obj4 = ((exchangeAuthLast3 != null) ? new long?(exchangeAuthLast3.End) : null);
             }
             long?num = obj4;
             PropertyGenTimespanInt64 <InterfaceAppManager> interfaceAppManagerAtTime = InterfaceAppManagerAtTime;
             if (!(num < ((interfaceAppManagerAtTime != null) ? new long?(interfaceAppManagerAtTime.Begin) : null)))
             {
                 InterfaceAppManagerAtTime = new PropertyGenTimespanInt64 <InterfaceAppManager>(new InterfaceAppManager(InterfaceAppDomainSetupType, InterfaceAppDomainSetupTypeLoadFromMainModule), GetTimeMilli());
             }
         }
         else
         {
             int    exchangeAuthTimeDistanceMinMilli = ExchangeAuthTimeDistanceMinMilli;
             object authResponse;
             if (licenseClient == null)
             {
                 authResponse = null;
             }
             else
             {
                 PropertyGenTimespanInt64 <HttpExchangeReport <AuthRequest, AuthResponse> > exchangeAuthLast4 = licenseClient.ExchangeAuthLast;
                 authResponse = ((exchangeAuthLast4 == null) ? null : exchangeAuthLast4.Value?.Response);
             }
             int num2 = Math.Max(exchangeAuthTimeDistanceMinMilli, AuthTimeDistanceRecommended((AuthResponse)authResponse) ?? 0);
             if (ExchangeAuthRateLimit.AttemptPass(GetTimeMilli(), num2))
             {
                 authExchange = licenseClient?.ExchangeAuth();
             }
         }
         return(new ExchangeReport
         {
             AuthExchange = authExchange,
             PayloadExchange = propertyGenTimespanInt
         });
     }
 }
Exemplo n.º 3
0
        static void SampleRun()
        {
            Console.WriteLine("this program reads the memory of the eve online client process.");
            Console.WriteLine("start an eve online client and login to your account. Then press any key to continue.\n");
            Console.ReadKey();

            var Config = Extension.ConfigReadFromConsole();

            if (null == Config)
            {
                Console.WriteLine("reading config failed.");
                return;
            }

            var licenseClientConfig = new LicenseClientConfig
            {
                ApiVersionAddress = Config.LicenseServerAddress,
                Request           = new AuthRequest
                {
                    ServiceId  = Config.ServiceId,
                    LicenseKey = Config.LicenseKey,
                    Consume    = true,
                },
            };

            Console.WriteLine();
            Console.WriteLine("connecting to " + (licenseClientConfig?.ApiOverviewAddress ?? "") + " using Key \"" + (licenseClientConfig?.Request?.LicenseKey ?? "") + "\" ....");

            var sensorServerDispatcher = new SimpleInterfaceServerDispatcher
            {
                LicenseClientConfig = licenseClientConfig,
            };

            sensorServerDispatcher.CyclicExchangeStart();

            var exchangeAuth = sensorServerDispatcher?.LicenseClient?.ExchangeAuthLast?.Value;

            Console.WriteLine("Auth exchange completed ");

            if (exchangeAuth.AuthSuccess() ?? false)
            {
                Console.WriteLine("successful");
            }
            else
            {
                Console.WriteLine("with error: " + Environment.NewLine + exchangeAuth?.SerializeToString(Newtonsoft.Json.Formatting.Indented));
                return;
            }

            Console.WriteLine("\nstarting to set up the sensor and read from memory.\nthe initial measurement takes longer.");

            for (;;)
            {
                var response = sensorServerDispatcher?.InterfaceAppManager?.MeasurementTakeNewRequest(Config.EveOnlineClientProcessId);

                if (null == response)
                {
                    Console.WriteLine("Sensor Interface not yet ready.");
                }
                else
                {
                    MeasurementReceived(response?.MemoryMeasurement);
                }

                Thread.Sleep(MeasurementTimeDistance);
            }
        }