Esempio n. 1
0
        public void DispatchInventory(
            [EventHubTrigger(Const.MessageSchemaId.MS029, Connection = Const.ConnectionString.EventHubsConnectionStringMs029)] string eventData,
            ILogger log)
        {
            log.EnterJson("EventData: {0}", new object[] { eventData });
            Result result = null;

            DispatchedEvent[] dispatchedEvents = null;
            void actionIfFailedWhenStoreUnexpected(Exception ex, string json) => log.Error(ex, nameof(Resources.CO_DSP_DII_003), new object[] { json });

            try
            {
                try
                {
                    dispatchedEvents = GetDispatchedEvents(eventData, log);
                }
                catch (Exception e)
                {
                    // イベント情報が正常に読み解けなかった場合
                    log.Error(e, nameof(Resources.CO_DSP_DII_006));
                    StoreUnexpectedEvent(Const.MessageSchemaId.MS029, eventData, actionIfFailedWhenStoreUnexpected);
                    return;
                }

                foreach (DispatchedEvent dispatchedEvent in dispatchedEvents)
                {
                    var messageId = dispatchedEvent?.MessageId;
                    try
                    {
                        RmsEvent rmsEvent = ConvertEventDataToRmsEvent(dispatchedEvent);

                        if (rmsEvent == null)
                        {
                            // イベントに必要なデータが不足している場合
                            log.Error(nameof(Resources.CO_DSP_DII_006));
                            StoreUnexpectedEvent(Const.MessageSchemaId.MS029, dispatchedEvent.RawBody, actionIfFailedWhenStoreUnexpected, messageId);
                            continue;
                        }

                        result = _service.StoreInventory(rmsEvent);

                        if (!result.IsSuccess())
                        {
                            StoreUnexpectedEvent(Const.MessageSchemaId.MS029, dispatchedEvent.RawBody, actionIfFailedWhenStoreUnexpected, messageId);
                        }
                    }
                    catch (Exception e)
                    {
                        log.Error(e, nameof(Resources.CO_DSP_DII_001));
                        StoreUnexpectedEvent(Const.MessageSchemaId.MS029, dispatchedEvent.RawBody, actionIfFailedWhenStoreUnexpected, messageId);
                    }
                }
            }
            finally
            {
                log.LeaveJson("Response: {0}", result);
            }
        }