private void DoWithInitCheck(int channelId, ConnectorEventType eventType, Func <Entity, ConnectorEvent> thingsToDo)
        {
            if (channelId != _config.ChannelId)
            {
                return;
            }

            var channelEntity = _channelHelper.InitiateChannelConfiguration(channelId);

            if (channelEntity == null)
            {
                ConnectorEventHelper.InitiateEvent(_config, eventType, $"Failed perform {eventType}. Could not find the channel.", -1, true);
                return;
            }

            try
            {
                var connectorEvent = thingsToDo(channelEntity);

                _entityService.FlushCache();
                _resourceElementFactory.FlushCache();

                var message = $"{eventType} done for channel {channelEntity.Id} ({channelEntity.DisplayName.Data})";

                ConnectorEventHelper.UpdateEvent(connectorEvent, message, 100);
            }
            catch (Exception ex)
            {
                IntegrationLogger.Write(LogLevel.Error, "Exception in ChannelEntityAdded", ex);
                ConnectorEventHelper.InitiateEvent(_config, eventType, ex.Message, -1, true);

                _entityService.FlushCache();
                _resourceElementFactory.FlushCache();
            }
        }
Ejemplo n.º 2
0
        internal ConnectorEvent InitiateConnectorEvent(ConnectorEventType messageType, string message, int percentage, bool error = false)
        {
            string channelId;

            _context.Settings.TryGetValue("CHANNEL_ID", out channelId);
            ConnectorEvent connectorEvent = new ConnectorEvent
            {
                ChannelId          = int.Parse(channelId ?? "0"),
                ConnectorEventType = messageType,
                ConnectorId        = _context.ExtensionId,
                EventTime          = DateTime.Now,
                SessionId          = Guid.NewGuid(),
                Percentage         = percentage,
                IsError            = error,
                Message            = message
            };

            _context.Log(LogLevel.Information, connectorEvent.Message);
            return(connectorEvent);
        }
Ejemplo n.º 3
0
        internal static ConnectorEvent InitiateEvent(IConfiguration config, ConnectorEventType messageType, string message, int percentage, bool error = false)
        {
            if (!error)
            {
                IntegrationLogger.Write(LogLevel.Debug, message);
            }

            ConnectorEvent connectorEvent = new ConnectorEvent
            {
                ChannelId          = config.ChannelId,
                ConnectorEventType = messageType,
                ConnectorId        = config.Id,
                EventTime          = DateTime.Now,
                SessionId          = Guid.NewGuid(),
                Percentage         = percentage,
                IsError            = error,
                Message            = message
            };

            ReportManager.Instance.WriteEvent(connectorEvent);
            return(connectorEvent);
        }
 private void DoWithInitCheck(int channelId, ConnectorEventType eventType, Func <Entity, Task <ConnectorEvent> > thingsToDo)
 {
     DoWithInitCheck(channelId, eventType, x => AsyncHelper.RunSync(() => thingsToDo(x)));
 }