Пример #1
0
        private List <InaraAPIEvent> IndexAndFilterAPIEvents(List <InaraAPIEvent> events, InaraConfiguration inaraConfiguration)
        {
            // Flag each event with a unique ID we can use when processing responses
            List <InaraAPIEvent> indexedEvents = new List <InaraAPIEvent>();

            for (int i = 0; i < events.Count; i++)
            {
                InaraAPIEvent indexedEvent = events[i];
                indexedEvent.eventCustomID = i;

                // Exclude and discard events with issues that have returned a code 400 error in this instance.
                if (invalidAPIEvents.Contains(indexedEvent.eventName))
                {
                    continue;
                }

                // Exclude and discard old / stale events
                if (inaraConfiguration?.lastSync > indexedEvent.eventTimeStamp)
                {
                    continue;
                }

                // Inara will ignore the "setCommunityGoal" event while EDDI is in development mode (i.e. beta).
                if (indexedEvent.eventName == "setCommunityGoal" && eddiIsBeta)
                {
                    continue;
                }

                // Note: the Inara Responder does not queue events while the game is in beta.

                indexedEvents.Add(indexedEvent);
            }

            return(indexedEvents);
        }
Пример #2
0
 public void EnqueueAPIEvent(InaraAPIEvent inaraAPIEvent)
 {
     if (!(inaraAPIEvent is null) && lastSync < inaraAPIEvent.eventTimeStamp)
     {
         Instance.queuedAPIEvents.Enqueue(inaraAPIEvent);
     }
 }
Пример #3
0
 public void EnqueueAPIEvent(InaraAPIEvent inaraAPIEvent)
 {
     if (inaraAPIEvent.eventName.StartsWith("get"))
     {
         Logging.Error("Cannot enqueue 'get' Inara API events as these require an immediate response. Send these directly.");
         return;
     }
     queuedAPIEvents.Add(inaraAPIEvent);
 }
Пример #4
0
        private List <InaraAPIEvent> IndexAndFilterAPIEvents(List <InaraAPIEvent> events, InaraConfiguration inaraConfiguration)
        {
            // If we don't have a commander name then only use `get` events and re-enqueue the rest.
            if (string.IsNullOrEmpty(inaraConfiguration.commanderName))
            {
                var commanderUpdateEvents = events.Where(e => !e.eventName.StartsWith("get")).ToList();
                ReEnqueueAPIEvents(commanderUpdateEvents);
                events = events.Except(commanderUpdateEvents).ToList();
            }

            // Flag each event with a unique ID we can use when processing responses
            List <InaraAPIEvent> indexedEvents = new List <InaraAPIEvent>();

            for (int i = 0; i < events.Count; i++)
            {
                InaraAPIEvent indexedEvent = events[i];
                indexedEvent.eventCustomID = i;

                // Exclude and discard events with issues that have returned a code 400 error in this instance.
                if (invalidAPIEvents.Contains(indexedEvent.eventName))
                {
                    continue;
                }

                // Exclude and discard old / stale events
                if (inaraConfiguration?.lastSync > indexedEvent.eventTimestamp)
                {
                    continue;
                }

                // Inara will ignore the "setCommunityGoal" event while EDDI is in development mode (i.e. beta).
                if (indexedEvent.eventName == "setCommunityGoal" && eddiIsBeta)
                {
                    continue;
                }

                // Note: the Inara Responder does not queue events while the game is in beta.

                indexedEvents.Add(indexedEvent);
            }

            return(indexedEvents);
        }
Пример #5
0
        // If you need to do some testing on Inara's API, please set the `isDeveloped` boolean header property to true.
        public List <InaraResponse> SendEventBatch(ref List <InaraAPIEvent> events, bool sendEvenForBetaGame = false)
        {
            if (!sendEvenForBetaGame && gameInBeta)
            {
                return(null);
            }

            List <InaraResponse> inaraResponses = new List <InaraResponse>();

            if (string.IsNullOrEmpty(apiKey))
            {
                return(inaraResponses);
            }

            // Flag each event with a unique ID we can use when processing responses
            List <InaraAPIEvent> indexedEvents = new List <InaraAPIEvent>();

            for (int i = 0; i < events.Count; i++)
            {
                InaraAPIEvent indexedEvent = events[i];
                indexedEvent.eventCustomID = i;
                indexedEvents.Add(indexedEvent);
            }

            var           client       = new RestClient("https://inara.cz/inapi/v1/");
            var           request      = new RestRequest(Method.POST);
            InaraSendJson inaraRequest = new InaraSendJson()
            {
                header = new Dictionary <string, object>()
                {
                    // Per private conversation with Artie and per Inara API docs, the `isDeveloped` property
                    // should (counterintuitively) be set to true when the an application is in development.
                    // Quote: `it's "true" because the app "is (being) developed"`
                    // Quote: `isDeveloped is meant as "the app is currently being developed and may be broken`
                    { "appName", "EDDI" },
                    { "appVersion", Constants.EDDI_VERSION.ToString() },
                    { "isDeveloped", eddiInBeta },
                    { "commanderName", commanderName ?? (eddiInBeta ? "TestCmdr" : null) },
                    { "commanderFrontierID", commanderFrontierID },
                    { "APIkey", apiKey }
                },
                events = indexedEvents
            };

            request.RequestFormat = DataFormat.Json;
            request.AddBody(inaraRequest); // uses JsonSerializer

            Logging.Debug("Sending to Inara: " + client.BuildUri(request).AbsoluteUri);
            var clientResponse = client.Execute <InaraResponses>(request);

            if (clientResponse.IsSuccessful)
            {
                InaraResponses response = clientResponse.Data;
                if (validateResponse(response.header, ref indexedEvents))
                {
                    foreach (InaraResponse inaraResponse in response.events)
                    {
                        if (validateResponse(inaraResponse, ref indexedEvents))
                        {
                            inaraResponses.Add(inaraResponse);
                        }
                    }
                }
                return(inaraResponses);
            }
            else
            {
                Logging.Warn("Unable to connect to the Inara server.", clientResponse.ErrorMessage);
                foreach (InaraAPIEvent inaraAPIEvent in events)
                {
                    // Re-enqueue and send at a later time.
                    EnqueueAPIEvent(inaraAPIEvent);
                }
                return(null);
            }
        }