예제 #1
0
 public UnreliableFlowControl(short channelId, int connectionId, IChannelContext ctx, UnreliableChannelConfig config = null)
 {
     m_ChannelId    = channelId;
     m_ConnectionId = connectionId;
     m_Context      = ctx;
     m_Config       = config ?? new UnreliableChannelConfig();
     m_ReceiveQueue = new UnreliableFragmentQueue(m_Config);
 }
예제 #2
0
 public ReliableFlowControl(short channelId, int connectionId, IChannelContext ctx, ReliableChannelConfig config = null)
 {
     m_ChannelId    = channelId;
     m_ConnectionId = connectionId;
     m_Context      = ctx;
     m_Config       = config ?? new ReliableChannelConfig();
     m_ReceiveQueue = new ReliableFragmentQueue(m_Config);
     m_TimeoutTimer = m_Config.Timeout;
 }
예제 #3
0
 public void Register(ISubActivityContext context)
 {
     if (context is IVerticalContext)
     {
         _verticalContext = (IVerticalContext)context;
     }
     else if (context is ICommunityContext)
     {
         _communityContext = (ICommunityContext)context;
     }
     else if (context is ILocationContext)
     {
         _locationContext = (ILocationContext)context;
     }
     else if (context is IChannelContext)
     {
         _channelContext = (IChannelContext)context;
     }
 }
예제 #4
0
 public ChannelManager(IChannelContext ctx)
 {
     m_Context = ctx;
 }
예제 #5
0
 public void Init(short channelId, IChannelContext ctx)
 {
     m_ChannelId = channelId;
     m_Context   = ctx;
 }
예제 #6
0
        public void LoadChannels()
        {
            var errors = new List <Exception>();

            GroupInfo          deafaultGroup = GetOrCreateDefaultGroup();
            List <ChannelInfo> allChannels   = _dataAdapter.GetChannels();
            List <GroupInfo>   allGroups     = _dataAdapter.GetGroups();

            allChannels.ForEach(channelInfo =>
            {
                try
                {
                    // Если канал не принадлежит ни одной группе, то включаем его в группу по умолчанию
                    if (!allGroups.Any(group => group.Channels.Contains(channelInfo.LINK)))
                    {
                        var map = new GroupChannelMap()
                        {
                            GroupLINK = deafaultGroup.LINK, ChannelLINK = channelInfo.LINK
                        };
                        _dataAdapter.SaveGroupMap(map);
                    }
                }
                catch (Exception ex)
                {
                    lock (errors)
                    {
                        errors.Add(ex);
                    }
                }
            });
            RefreshGroups();

            // Создание и запуск каналов
            allChannels.ForEach(channelInfo =>
                                //allChannels.AsParallel().ForAll(channelInfo =>
            {
                try
                {
                    MicroserviceDescription description = _addinManager.FindMicroservice(channelInfo.Provider);
                    if (description == null)
                    {
                        channelInfo.Enabled = false;
                    }
                    else
                    {
                        channelInfo.SetDescription(description);
                    }

                    if (channelInfo.IsSystem())
                    {
                        channelInfo.SetRealAddress(_busSettings.Database.ConnectionString);
                    }

                    _dataAdapter.SaveChannelInfo(channelInfo);

                    if (channelInfo.Enabled)
                    {
                        IChannelContext context = _contextFactory.CreateContext(channelInfo);
                        if (!_channels.TryAdd(channelInfo.VirtAddress, context))
                        {
                            context.Dispose();
                            throw new InvalidOperationException($"Канал {channelInfo.VirtAddress} уже существует.");
                        }
                    }
                }
                catch (Exception ex)
                {
                    lock (errors)
                    {
                        errors.Add(ex);
                    }
                }
            });


            _channels.Values.ToList().ForEach(context =>
                                              //_channels.Values.AsParallel().ForAll(context =>
            {
                ChannelInfo channelInfo  = context.ChannelInfo;
                ChannelSettings settings = channelInfo.ChannelSettings();
                if (settings.AutoOpen)
                {
                    try
                    {
                        IChannel channel = context.CreateChannelAsync().Result;
                        //channel.SetSettingsAsync();
                        channel.OpenAsync().Wait();
                    }
                    catch (Exception ex)
                    {
                        lock (errors)
                        {
                            errors.Add(ex);
                        }
                    }
                }
            });

            _channels.Values.ToList().ForEach(context =>
                                              //_channels.Values.AsParallel().ForAll(context =>
            {
                ChannelInfo channelInfo = context.ChannelInfo;
                IChannel channel        = context.Channel;
                if (channel != null && channel.IsOpened)
                {
                    ChannelSettings settings = channelInfo.ChannelSettings();
                    if (settings.AutoRun)
                    {
                        try
                        {
                            channel.RunAsync().Wait();
                        }
                        catch (Exception ex)
                        {
                            lock (errors)
                            {
                                errors.Add(ex);
                            }
                        }
                    }
                }
            });

            if (errors.Count > 0)
            {
                throw new AggregateException(errors);
            }
        }