Esempio n. 1
0
        public async Task DispatchDeviceConnected(
            [EventHubTrigger(Const.EventHubNames.DeviceConnected, Connection = Const.ConnectionString.EventHubsConnectionStringDeviceConnected)] string eventData,
            ILogger log)
        {
            log.EnterJson("EventData: {0}", new object[] { eventData });
            Result result = null;

            DeviceConnectionEvent[] events = null;

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

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

                foreach (DeviceConnectionEvent deviceConnectionEvent in events)
                {
                    try
                    {
                        if (!deviceConnectionEvent.HasNecessary())
                        {
                            log.Error(nameof(Resources.CO_DSP_DDC_016));
                            StoreUnexpectedEvent(Const.EventHubNames.DeviceConnected, deviceConnectionEvent.RawBody, actionIfFailedWhenStoreUnexpected);
                            continue;
                        }

                        Guid     edgeId    = deviceConnectionEvent.EdgeId;
                        DateTime eventTime = deviceConnectionEvent.EventTime;
                        result = await _service.StoreDeviceConnected(edgeId, eventTime);

                        if (!result.IsSuccess())
                        {
                            // DeviceConnectedイベントにはメッセージIDが存在しない
                            StoreUnexpectedEvent(Const.EventHubNames.DeviceConnected, deviceConnectionEvent.RawBody, actionIfFailedWhenStoreUnexpected);
                        }
                    }
                    catch (Exception e)
                    {
                        log.Error(e, nameof(Resources.CO_DSP_DDC_013));
                        StoreUnexpectedEvent(Const.EventHubNames.DeviceConnected, deviceConnectionEvent.RawBody, actionIfFailedWhenStoreUnexpected);
                    }
                }
            }
            finally
            {
                log.LeaveJson("Response: {0}", result);
            }
        }
Esempio n. 2
0
        public async Task RequestRemoteAsync_SendSuccess_ReturnsSucceed()
        {
            // 以下の確認をしたい。
            //      ・DBから取得したエッジIDに対して処理を行う。
            //      ・設定から取得したメッセージを送る。
            //      ・引数セッションコードをその中に含む

            var builder = new TestDiProviderBuilder();
            IDispatchService testTarget = builder.Build().GetService <IDispatchService>();
            // testTarget.StoreDXABillingLog();

            ////HACK:下記はWarning除け用の仮コードです。
            Guid     guid      = Guid.NewGuid();
            DateTime eventTime = default(DateTime);
            await testTarget.StoreDeviceConnected(guid, eventTime);
        }