Beispiel #1
0
        public static Task ShutdownChannelAsync(
            IEventExecutorGroup bossExecutor,
            IEventExecutorGroup workerExecutor,
            IChannelGroup allChannels,
            TimeSpan timeSpan)
        {
            timeSpan = timeSpan.TotalSeconds <= 2 ? TimeSpan.FromSeconds(3) : timeSpan;
            List <Task> tasks = new List <Task>();

            // Close all channels
            if (allChannels != null)
            {
                tasks.Add(allChannels.CloseAsync());
            }

            // Stop boss threads
            if (bossExecutor != null)
            {
                tasks.Add(bossExecutor.ShutdownGracefullyAsync(TimeSpan.FromSeconds(2), timeSpan));
            }

            // Finally stop I/O workers
            if (workerExecutor != null)
            {
                tasks.Add(workerExecutor.ShutdownGracefullyAsync(TimeSpan.FromSeconds(2), timeSpan));
            }
            return(Task.WhenAll(tasks.ToArray()));
        }
		public IndisposableChannelGroup(IChannelGroup inner)
		{
			if (inner == null)
				throw new ArgumentNullException("inner");

			this.inner = inner;
		}
        public override void ChannelActive(IChannelHandlerContext contex)
        {
            IChannelGroup g = _group;

            if (g == null)
            {
                lock (this)
                {
                    if (_group == null)
                    {
                        g = _group = new DefaultChannelGroup(contex.Executor);
                    }
                }
            }
            g?.Add(contex.Channel);
            _poker.Player += 1;
            _poker.AddPlayer(_poker.Player, contex.Channel.RemoteAddress.ToString());
            //contex.WriteAndFlushAsync(g.Count);
            if (_poker.Player == 4)
            {
                contex.WriteAndFlushAsync("Welcome to the game!\n");
                _group.WriteAndFlushAsync("Welcome to the game\n", new EveryOneBut(contex.Channel.Id));
                _poker.IsGameStarted = true;
            }
            Console.WriteLine(_poker.Player);
        }
Beispiel #4
0
        public void OnChannelGroupReady(IChannelGroup channelGroup, string appSecret)
        {
            MobileCenterLog.Warn(MobileCenterLog.LogTag, "Crashes service is not yet supported on this platform.");
            try
            {
#if REFERENCE
#else
                WatsonRegistrationManager.Start(appSecret);
#pragma warning disable CS0612 // Type or member is obsolete
                MobileCenter.CorrelationIdChanged += (s, id) =>
                {
                    WatsonRegistrationManager.SetCorrelationId(id.ToString());
                };

                // Checking for null and setting id needs to be atomic to avoid
                // overwriting
                Guid newId = Guid.NewGuid();
                MobileCenter.TestAndSetCorrelationId(Guid.Empty, ref newId);
#pragma warning restore CS0612 // Type or member is obsolete
#endif
            }
            catch (Exception e)
            {
#if DEBUG
                throw new MobileCenterException("Failed to register crashes with Watson", e);
#endif
            }
        }
        public void OnChannelGroupReady(IChannelGroup channelGroup, string appSecret)
        {
            try
            {
#if REFERENCE
#else
                WatsonRegistrationManager.Start(appSecret);
#pragma warning disable CS0612 // Type or member is obsolete
                AppCenter.CorrelationIdChanged += (s, id) =>
                {
                    WatsonRegistrationManager.SetCorrelationId(id.ToString());
                };

                // Checking for null and setting id needs to be atomic to avoid
                // overwriting
                Guid newId = Guid.NewGuid();
                AppCenter.TestAndSetCorrelationId(Guid.Empty, ref newId);
#pragma warning restore CS0612 // Type or member is obsolete
#endif
            }
            catch (Exception e)
            {
                AppCenterLog.Error(AppCenterLog.LogTag, "Failed to register crashes with Watson", e);
            }
        }
Beispiel #6
0
		public void ProcessReplacing(IChannelGroup inputs, IChannelGroup outputs, int sampleFrames)
		{
			SMALL_NUMBER = -SMALL_NUMBER;

			for (int sampleIndex = 0; sampleIndex < sampleFrames; sampleIndex++)
			{
				float leftOut = 0f;
				float rightOut = 0f;
				float leftIn = inputs.GetChannel(0)[sampleIndex];
				float rightIn = inputs.GetChannel(1)[sampleIndex];
				
				float summedInput = Undenormalise((leftIn + rightIn) * fixedGain);

				// Accumulate comb filters in parallel
				for (int i = 0; i < combCount; i++)
				{
					leftOut += leftCombs[i].Process(summedInput);
					rightOut += rightCombs[i].Process(summedInput);
				}

				// Feed through allpasses in series
				for (int i = 0; i < allPassCount; i++)
				{
					leftOut = leftAllPasses[i].Process(leftOut);
					rightOut = rightAllPasses[i].Process(rightOut);
				}

				outputs.GetChannel(0)[sampleIndex] = leftOut * wet1 + rightOut * wet2 + leftIn * dry;
				outputs.GetChannel(1)[sampleIndex] = rightOut * wet1 + leftOut * wet2 + rightIn * dry;
			}
		}
 public PipelineDispatcherHook(
     IMessagingHost messagingHost)
 {
     _messagingHost  = messagingHost;
     _channelGroup   = _messagingHost.Initialize();
     _messageChannel = _channelGroup.OpenChannel();
 }
Beispiel #8
0
        public async Task <AsyncResult <IList <IChannel> > > GetChannelsAsync(IChannelGroup group)
        {
            var          channels   = new List <IChannel>();
            ChannelGroup indexGroup = group as ChannelGroup;

            if (indexGroup == null || !CheckConnection(indexGroup.ServerIndex))
            {
                return(new AsyncResult <IList <IChannel> >(false, null));
            }
            try
            {
                IList <WebChannelBasic> tvChannels = TvServer(indexGroup.ServerIndex).GetChannelsBasic(group.ChannelGroupId);
                foreach (WebChannelBasic webChannel in tvChannels)
                {
                    channels.Add(new Channel {
                        ChannelId = webChannel.Id, Name = webChannel.Title, ServerIndex = indexGroup.ServerIndex
                    });
                }
                return(new AsyncResult <IList <IChannel> >(true, channels));
            }
            catch (Exception ex)
            {
                ServiceRegistration.Get <ILogger>().Error(ex.Message);
                return(new AsyncResult <IList <IChannel> >(false, null));
            }
        }
Beispiel #9
0
        /// <summary>
        /// Tries to get a list of programs for all channels of the given <paramref name="channelGroup"/> and time range.
        /// </summary>
        /// <param name="channelGroup">Channel group</param>
        /// <param name="from">Time from</param>
        /// <param name="to">Time to</param>
        /// <returns><c>true</c> if at least one program could be found</returns>
        public async Task <AsyncResult <IList <IProgram> > > GetProgramsGroupAsync(IChannelGroup channelGroup, DateTime from, DateTime to)
        {
            ChannelGroup indexGroup = channelGroup as ChannelGroup;

            if (indexGroup == null || !CheckConnection(indexGroup.ServerIndex))
            {
                return(new AsyncResult <IList <IProgram> >(false, null));
            }

            var programs = new List <IProgram>();

            try
            {
                IList <WebChannelPrograms <WebProgramDetailed> > tvPrograms = TvServer(indexGroup.ServerIndex).GetProgramsDetailedForGroup(channelGroup.ChannelGroupId, from, to);
                foreach (WebProgramDetailed webProgramDetailed in tvPrograms.SelectMany(webPrograms => webPrograms.Programs))
                {
                    programs.Add(new Program(webProgramDetailed, indexGroup.ServerIndex));
                }
            }
            catch (Exception ex)
            {
                ServiceRegistration.Get <ILogger>().Error(ex.Message);
                return(new AsyncResult <IList <IProgram> >(false, null));
            }
            return(new AsyncResult <IList <IProgram> >(programs.Count > 0, programs));
        }
        public SessionTracker(IChannelGroup channelGroup, IChannelUnit channel, IApplicationSettings applicationSettings)
        {
            // Need to lock in constructor because of the event handler being set for channelGroup.
            lock (_lockObject)
            {
                _channel                   = channel;
                _applicationSettings       = applicationSettings;
                channelGroup.EnqueuingLog += HandleEnqueuingLog;
                var sessionsString = _applicationSettings.GetValue <string>(StorageKey, null);
                if (sessionsString == null)
                {
                    return;
                }
                _sessions = SessionsFromString(sessionsString);

                // Re-write sessions in storage in case of any invalid strings
                _applicationSettings.SetValue(StorageKey, SessionsAsString());
                if (_sessions.Count == 0)
                {
                    return;
                }
                var loadedSessionsString = _sessions.Values.Aggregate("Loaded stored sessions:\n", (current, session) => current + ("\t" + session + "\n"));
                MobileCenterLog.Debug(Analytics.Instance.LogTag, loadedSessionsString);
            }
        }
Beispiel #11
0
        //---------------------------------------------------------------------
        public Task Start(IPAddress ip_address, int port)
        {
            var builder = new ContainerBuilder();

            builder.RegisterModule(new ConfigurationSettingsReader("autofac"));
            this.GatewaySessionListenerContainer = builder.Build();

            var gatewaySessionFactory = new GatewaySessionFactory();

            this.timer          = new System.Timers.Timer();
            this.timer.Interval = 3000;
            this.timer.Elapsed += (obj, evt) =>
            {
                int           count = 0;
                IChannelGroup g     = this.ChannelGroup;
                if (g != null)
                {
                    count = g.Count;
                }

                string title   = Gateway.Instance.ConsoleTitle;
                string version = Gateway.Instance.Version;
                Console.Title = string.Format("{0} {1} ConnectionCount={2}", title, version, count);
            };
            this.timer.Start();

            return(this.gatewayRunner.Start(ip_address, port, gatewaySessionFactory));
        }
        protected async Task InitChannels(IChannelGroup channelGroup)
        {
            _channels = new List <IChannel>();
            Channel   = null;

            if (channelGroup == null)
            {
                return;
            }

            var result = await _tvHandler.ChannelAndGroupInfo.GetChannelsAsync(channelGroup);

            if (result.Success)
            {
                _channels = result.Result;
            }

            IChannel channel = Channel;

            if (channel != null)
            {
                channel = _channels?.FirstOrDefault(c => c.ChannelId == channel.ChannelId);
            }
            if (channel == null)
            {
                channel = _channels?.FirstOrDefault();
            }
            Channel = channel;
            return;
        }
        protected override void UpdateChannels()
        {
            base.UpdateChannels();
            if (_webChannelGroupIndex < _channelGroups.Count)
            {
                IChannelGroup currentGroup = _channelGroups[_webChannelGroupIndex];
                CurrentGroupName = currentGroup.Name;
            }
            _channelList.Clear();
            if (_channels == null)
            {
                return;
            }

            foreach (IChannel channel in _channels)
            {
                // Use local variable, otherwise delegate argument is not fixed
                IChannel currentChannel = channel;

                ChannelProgramListItem item = new ChannelProgramListItem(currentChannel, GetNowAndNextProgramsList(currentChannel))
                {
                    Command = new MethodDelegateCommand(() => Tune(currentChannel))
                };
                item.AdditionalProperties["CHANNEL"] = channel;
                _channelList.Add(item);
            }
            CurrentGroupChannels.FireChange();
        }
        public override void ChannelActive(IChannelHandlerContext ctx)
        {
            IChannelGroup g = Group;

            if (g == null)
            {
                lock (this)
                {
                    if (Group == null)
                    {
                        Group = g = new DefaultChannelGroup(ctx.Executor);
                    }
                }
            }

            // Detect when client disconnects
            ctx.Channel.CloseCompletion.ContinueWith((x) =>
            {
                Logger.Warn("Channel Closed");
                g?.Remove(ctx.Channel);
                OnChannelInactive?.Invoke(ctx.Channel);
            });

            // Add to channels list
            g.Add(ctx.Channel);

            // Send event upstream
            OnChannelActive?.Invoke(ctx.Channel);
        }
Beispiel #15
0
        public override void ChannelActive(IChannelHandlerContext contex)
        {
            IChannelGroup g = Group;

            if (g == null)
            {
                lock (this)
                {
                    g = Group ?? (Group = new DefaultChannelGroup(contex.Executor));
                }
            }
            base.ChannelActive(contex);
            string msg = $"欢迎 to {0} secure chat server! { Dns.GetHostName()}\n";

            ReplyContent <string> reply = new ReplyContent <string>()
            {
                ConnectionId = $"{contex.Channel.Id}",
                Cmd          = 0,
                Scope        = 0,
                Message      = msg
            };

            contex.WriteAndFlushAsync(reply.ToString());
            g.Add(contex.Channel);
        }
        //public bool GetChannels(IChannelGroup group, out IList<IChannel> channels)
        public async Task <AsyncResult <IList <IChannel> > > GetChannelsAsync(IChannelGroup group)
        {
            try
            {
                CpAction       action       = GetAction(Consts.ACTION_GET_CHANNELS);
                IList <object> inParameters = new List <object> {
                    group.ChannelGroupId
                };
                IList <object> outParameters = await action.InvokeAsync(inParameters);

                bool            success     = (bool)outParameters[0];
                IList <Channel> channelList = (IList <Channel>)outParameters[1];
                if (success)
                {
                    var channels = channelList.Cast <IChannel>().ToList();
                    foreach (var channel in channels)
                    {
                        _channelCache[channel.ChannelId] = channel;
                    }
                    return(new AsyncResult <IList <IChannel> >(true, channels));
                }
            }
            catch (Exception ex)
            {
                NotifyException(ex);
            }
            return(new AsyncResult <IList <IChannel> >(false, null));
        }
Beispiel #17
0
        protected void GetNowAndNextProgramsList()
        {
            IChannelGroup currentChannelGroup = CurrentChannelGroup;

            if (_tvHandler.ProgramInfo == null || currentChannelGroup == null)
            {
                return;
            }
            IDictionary <int, IProgram[]> programs;

            _tvHandler.ProgramInfo.GetNowAndNextForChannelGroup(currentChannelGroup, out programs);
            lock (CurrentGroupChannels.SyncRoot)
                foreach (ChannelProgramListItem channelItem in CurrentGroupChannels)
                {
                    IProgram[] nowNext;
                    IProgram   currentProgram = null;
                    IProgram   nextProgram    = null;
                    IChannel   channel        = channelItem.Channel;
                    if (programs != null && programs.TryGetValue(channel.ChannelId, out nowNext))
                    {
                        currentProgram = nowNext.Length > 0 ? nowNext[0] : null;
                        nextProgram    = nowNext.Length > 1 ? nowNext[1] : null;
                    }

                    CreateProgramListItem(currentProgram, channelItem.Programs[0], channel);
                    CreateProgramListItem(nextProgram, channelItem.Programs[1], channel, currentProgram);
                }
        }
        public override void ChannelRegistered(IChannelHandlerContext context)
        {
            var group = _group;

            if (group == null)
            {
                lock (_channel)
                {
                    if (_group == null)
                    {
                        group = _group = new DefaultChannelGroup(context.Executor);
                    }
                }
            }

            EndPoint = _channel.RemoteAddress as IPEndPoint;

            group.Add(context.Channel);

            _log = new SessionLogger(typeof(WorldTcpHandler), $"([{EndPoint?.Address}]:{EndPoint?.Port}) ");

            if (!SessionManager.RegisterAsync(this).Result)
            {
                SendPacket(new SessionLoginResponse
                {
                    SessionLoginResponseType = SessionLoginResponseType.MaxConnectionsReached
                });
                _log.Debug("Client has reached maximum connections per Ip, disconnecting!");
                Disconnect();
                return;
            }

            _log.Debug("Client has been accepted");
        }
        public async Task <AsyncResult <IList <IProgram> > > GetProgramsGroupAsync(IChannelGroup channelGroup, DateTime from, DateTime to)
        {
            try
            {
                CpAction       action       = GetAction(Consts.ACTION_GET_PROGRAMS_GROUP);
                IList <object> inParameters = new List <object>
                {
                    channelGroup.ChannelGroupId,
                    from,
                    to
                };

                IList <object> outParameters = await action.InvokeAsync(inParameters);

                bool success = (bool)outParameters[0];
                if (success)
                {
                    IList <Program>  programList = (IList <Program>)outParameters[1];
                    IList <IProgram> programs    = programList.Distinct(ProgramComparer.Instance).ToList();
                    return(new AsyncResult <IList <IProgram> >(true, programs));
                }
            }
            catch (Exception ex)
            {
                NotifyException(ex);
            }
            return(new AsyncResult <IList <IProgram> >(false, null));
        }
Beispiel #20
0
        public bool GetProgramsGroup(IChannelGroup channelGroup, DateTime from, DateTime to, out IList <IProgram> programs)
        {
            programs = null;
            try
            {
                CpAction       action       = GetAction(Consts.ACTION_GET_PROGRAMS_GROUP);
                IList <object> inParameters = new List <object>
                {
                    channelGroup.ChannelGroupId,
                    from,
                    to
                };

                IList <object> outParameters = action.InvokeAction(inParameters);
                bool           success       = (bool)outParameters[0];
                if (success)
                {
                    IList <Program> programList = (IList <Program>)outParameters[1];
                    programs = programList.Distinct(ProgramComparer.Instance).ToList(); // Using custom comparer to filter out duplicated programs.
                    return(true);
                }
            }
            catch (Exception ex)
            {
                NotifyException(ex);
            }
            return(false);
        }
        public bool GetNowAndNextForChannelGroup(IChannelGroup channelGroup, out IDictionary <int, IProgram[]> nowNextPrograms)
        {
            var result = GetNowAndNextForChannelGroupAsync(channelGroup).Result;

            nowNextPrograms = result.Result;
            return(result.Success);
        }
        public bool GetChannels(IChannelGroup group, out IList <IChannel> channels)
        {
            channels = new List <IChannel>();
            ChannelGroup indexGroup = group as ChannelGroup;

            if (indexGroup == null)
            {
                return(false);
            }
            if (!CheckConnection(indexGroup.ServerIndex))
            {
                return(false);
            }
            try
            {
                IList <WebChannelBasic> tvChannels = TvServer(indexGroup.ServerIndex).GetChannelsBasic(group.ChannelGroupId);
                foreach (WebChannelBasic webChannel in tvChannels)
                {
                    channels.Add(new Channel {
                        ChannelId = webChannel.Id, Name = webChannel.Title, ServerIndex = indexGroup.ServerIndex
                    });
                }
                return(true);
            }
            catch (Exception ex)
            {
                ServiceRegistration.Get <ILogger>().Error(ex.Message);
                return(false);
            }
        }
        /// <summary>
        /// Tries to get a list of programs for all channels of the given <paramref name="channelGroup"/> and time range.
        /// </summary>
        /// <param name="channelGroup">Channel group</param>
        /// <param name="from">Time from</param>
        /// <param name="to">Time to</param>
        /// <param name="programs">Returns programs</param>
        /// <returns><c>true</c> if at least one program could be found</returns>
        public bool GetProgramsGroup(IChannelGroup channelGroup, DateTime @from, DateTime to, out IList <IProgram> programs)
        {
            programs = null;
            ChannelGroup indexGroup = channelGroup as ChannelGroup;

            if (indexGroup == null)
            {
                return(false);
            }

            if (!CheckConnection(indexGroup.ServerIndex))
            {
                return(false);
            }

            programs = new List <IProgram>();
            try
            {
                IList <WebChannelPrograms <WebProgramDetailed> > tvPrograms = TvServer(indexGroup.ServerIndex).GetProgramsDetailedForGroup(channelGroup.ChannelGroupId, from, to);
                foreach (WebProgramDetailed webProgramDetailed in tvPrograms.SelectMany(webPrograms => webPrograms.Programs))
                {
                    programs.Add(new Program(webProgramDetailed, indexGroup.ServerIndex));
                }
            }
            catch (Exception ex)
            {
                ServiceRegistration.Get <ILogger>().Error(ex.Message);
                return(false);
            }
            return(programs.Count > 0);
        }
 public override void OnChannelGroupReady(IChannelGroup channelGroup, string appSecret)
 {
     lock (_serviceLock)
     {
         base.OnChannelGroupReady(channelGroup, appSecret);
         if (ApplicationLifecycleHelper == null)
         {
             // If it isn't null, that likely means that a test provided its own lifecycle helper
             ApplicationLifecycleHelper = new ApplicationLifecycleHelper();
         }
         ApplyEnabledState(InstanceEnabled);
         if (ApplicationLifecycleHelper.HasShownWindow && !ApplicationLifecycleHelper.IsSuspended)
         {
             SessionTracker?.Resume();
             _hasStarted = true;
         }
         else
         {
             ApplicationLifecycleHelper.ApplicationStarted += (sender, e) =>
             {
                 SessionTracker?.Resume();
                 _hasStarted = true;
             };
         }
         ApplicationLifecycleHelper.ApplicationResuming  += (sender, e) => SessionTracker?.Resume();
         ApplicationLifecycleHelper.ApplicationSuspended += (sender, e) => SessionTracker?.Pause();
     }
 }
        protected async Task GetNowAndNextProgramsList_Async()
        {
            IChannelGroup currentChannelGroup = CurrentChannelGroup;

            if (_tvHandler.ProgramInfo == null || currentChannelGroup == null)
            {
                return;
            }

            var result = await _tvHandler.ProgramInfo.GetNowAndNextForChannelGroupAsync(currentChannelGroup);

            if (!result.Success)
            {
                return;
            }

            var programs = result.Result;

            lock (CurrentGroupChannels.SyncRoot)
                foreach (ChannelProgramListItem channelItem in CurrentGroupChannels)
                {
                    IProgram[] nowNext;
                    IProgram   currentProgram = null;
                    IProgram   nextProgram    = null;
                    IChannel   channel        = channelItem.Channel;
                    if (programs != null && programs.TryGetValue(channel.ChannelId, out nowNext))
                    {
                        currentProgram = nowNext.Length > 0 ? nowNext[0] : null;
                        nextProgram    = nowNext.Length > 1 ? nowNext[1] : null;
                    }

                    CreateProgramListItem(currentProgram, channelItem.Programs[0], channel);
                    CreateProgramListItem(nextProgram, channelItem.Programs[1], channel, currentProgram);
                }
        }
Beispiel #26
0
 public bool GetChannels(IChannelGroup group, out IList <IChannel> channels)
 {
     channels = null;
     try
     {
         CpAction       action       = GetAction(Consts.ACTION_GET_CHANNELS);
         IList <object> inParameters = new List <object> {
             group.ChannelGroupId
         };
         IList <object>  outParameters = action.InvokeAction(inParameters);
         bool            success       = (bool)outParameters[0];
         IList <Channel> channelList   = (IList <Channel>)outParameters[1];
         if (success)
         {
             channels = channelList.Cast <IChannel>().ToList();
             foreach (var channel in channels)
             {
                 _channelCache[channel.ChannelId] = channel;
             }
             return(true);
         }
         return(false);
     }
     catch (Exception ex)
     {
         NotifyException(ex);
         return(false);
     }
 }
Beispiel #27
0
 public override void ProcessReplacing(IChannelGroup inputs, IChannelGroup outputs, int sampleFrames)
 {
     for(int i = 0; i < sampleFrames; i++)
     {
         outputs.GetChannel(0)[i] = gain.Process(inputs.GetChannel(0)[i]);
     }
 }
        public bool GetProgramsGroup(IChannelGroup channelGroup, DateTime from, DateTime to, out IList <IProgram> programs)
        {
            var result = GetProgramsGroupAsync(channelGroup, from, to).Result;

            programs = result.Result;
            return(result.Success);
        }
        protected override void UpdateChannels()
        {
            base.UpdateChannels();
            if (_webChannelGroupIndex < _channelGroups.Count)
            {
                IChannelGroup currentGroup = _channelGroups[_webChannelGroupIndex];
                CurrentGroupName = currentGroup.Name;
            }
            _channelList.Clear();
            if (_channels == null)
            {
                return;
            }

            foreach (IChannel channel in _channels)
            {
                // Use local variable, otherwise delegate argument is not fixed
                IChannel currentChannel = channel;

                ChannelProgramListItem item = new ChannelProgramListItem(currentChannel, null)
                {
                    Programs = new ItemsList {
                        GetNoProgramPlaceholder(), GetNoProgramPlaceholder()
                    },
                    Command = new MethodDelegateCommand(() => Tune(currentChannel))
                };
                item.AdditionalProperties["CHANNEL"] = channel;
                // Load programs asynchronously, this increases performance of list building
                GetNowAndNextProgramsList(item, currentChannel);
                _channelList.Add(item);
            }
            CurrentGroupChannels.FireChange();
        }
        protected virtual void AddChannelGroup(string name, IChannelGroup group)
        {
            Log.Debug(group.DispatchOnly ?
                      "Adding dispatch-only channel group '{0}'." : "Adding full-duplex channel group '{0}'", name);

            group.Initialize();
            this.groups[name] = group;
        }
 /// <summary>
 /// Method that is called to signal start of the Push service.
 /// </summary>
 /// <param name="channelGroup"></param>
 /// <param name="appSecret"></param>
 public override void OnChannelGroupReady(IChannelGroup channelGroup, string appSecret)
 {
     using (_mutex.GetLock())
     {
         base.OnChannelGroupReady(channelGroup, appSecret);
         ApplyEnabledState(IsEnabledAsync().Result);
     }
 }
		protected virtual void AddChannelGroup(string name, IChannelGroup group)
		{
			Log.Debug(group.DispatchOnly ?
				"Adding dispatch-only channel group '{0}'." : "Adding full-duplex channel group '{0}'", name);

			group.Initialize();
			this.groups[name] = group;
		}
 public override void OnChannelGroupReady(IChannelGroup channelGroup, string appSecret)
 {
     lock (_serviceLock)
     {
         base.OnChannelGroupReady(channelGroup, appSecret);
         ApplyEnabledState(InstanceEnabled);
     }
 }
Beispiel #34
0
 protected void SetGroupName()
 {
     if (_webChannelGroupIndex < _channelGroups.Count)
     {
         IChannelGroup group = _channelGroups[_webChannelGroupIndex];
         GroupName = group.Name;
     }
 }
Beispiel #35
0
        public override void ProcessReplacing(IChannelGroup inputs, IChannelGroup outputs, int sampleFrames)
		{
			for(int i = 0; i < sampleFrames; i++)
			{
				float level = GetLevel(i, sampleFrames, inputs.GetChannel(0), inputs.GetChannel(1));

				SideChain(level);

				outputs.GetChannel(0)[i] = inputs.GetChannel(0)[i] * gain;
                outputs.GetChannel(1)[i] = inputs.GetChannel(1)[i] * gain;
			}
		}
Beispiel #36
0
        public override void ProcessReplacing(IChannelGroup inputs, IChannelGroup outputs, int sampleFrames)
        {
            for(int frame = 0; frame < sampleFrames; frame++)
            {
                while (events.HasEvent(frame))
                {
                    MidiEvent midiEvent = events.Next();

                    if (midiEvent.Status == MidiStatus.NoteOn)
                    {
                        noteOn = true;
                    }
                    else if (midiEvent.Status == MidiStatus.NoteOff)
                    {
                        noteOn = false;
                    }
                }

                if (noteOn)
                {
                    outputs.GetChannel(0)[frame] = (float) random.NextDouble()*volume;
                }
            }
        }
    public bool GetProgramsGroup(IChannelGroup channelGroup, DateTime from, DateTime to, out IList<IProgram> programs)
    {
#if TVE3
      programs = new List<IProgram>();
      foreach (var channel in _tvBusiness.GetTVGuideChannelsForGroup(channelGroup.ChannelGroupId))
        CollectionUtils.AddAll(programs, _tvBusiness.GetPrograms(TvDatabase.Channel.Retrieve(channel.IdChannel), from, to).Select(p => p.ToProgram()));
#else
      IProgramService programService = GlobalServiceProvider.Instance.Get<IProgramService>();
      IChannelGroupService channelGroupService = GlobalServiceProvider.Instance.Get<IChannelGroupService>();

      var channels = channelGroupService.GetChannelGroup(channelGroup.ChannelGroupId).GroupMaps.Select(groupMap => groupMap.Channel);
      IDictionary<int, IList<Program>> programEntities = programService.GetProgramsForAllChannels(from, to, channels);

      programs = programEntities.Values.SelectMany(x => x).Select(p => p.ToProgram()).Distinct(ProgramComparer.Instance).ToList();
#endif
      return programs.Count > 0;
    }
    public bool GetChannels(IChannelGroup group, out IList<IChannel> channels)
    {
#if TVE3
      channels = _tvBusiness.GetChannelsInGroup(TvDatabase.ChannelGroup.Retrieve(group.ChannelGroupId))
        // Bug? SortOrder contains logical channel number, not the group sort order?
        // .OrderBy(c => c.SortOrder)
        .Where(c=> c.VisibleInGuide)
        .Select(c => c.ToChannel())
        .ToList();
#else
      IChannelGroupService channelGroupService = GlobalServiceProvider.Instance.Get<IChannelGroupService>();
      channels = channelGroupService.GetChannelGroup(group.ChannelGroupId).GroupMaps
        .Where(groupMap => groupMap.Channel.VisibleInGuide)
        .OrderBy(groupMap => groupMap.SortOrder)
        .Select(groupMap => groupMap.Channel.ToChannel())
        .ToList();
#endif
      return true;
    }
 public bool GetChannels(IChannelGroup group, out IList<IChannel> channels)
 {
     channels = new List<IChannel>();
       ChannelGroup indexGroup = group as ChannelGroup;
       if (indexGroup == null)
     return false;
       if (!CheckConnection(indexGroup.ServerIndex))
     return false;
       try
       {
     IList<WebChannelBasic> tvChannels = TvServer(indexGroup.ServerIndex).GetChannelsBasic(group.ChannelGroupId);
     foreach (WebChannelBasic webChannel in tvChannels)
     {
       channels.Add(new Channel { ChannelId = webChannel.Id, Name = webChannel.DisplayName, ServerIndex = indexGroup.ServerIndex });
     }
     return true;
       }
       catch (Exception ex)
       {
     ServiceRegistration.Get<ILogger>().Error(ex.Message);
     return false;
       }
 }
    public bool GetProgramsGroup(IChannelGroup channelGroup, DateTime from, DateTime to, out IList<IProgram> programs)
    {
      programs = null;
      try
      {
        CpAction action = GetAction(Consts.ACTION_GET_PROGRAMS_GROUP);
        IList<object> inParameters = new List<object>
            {
              channelGroup.ChannelGroupId,
              from,
              to
            };

        IList<object> outParameters = action.InvokeAction(inParameters);
        bool success = (bool)outParameters[0];
        if (success)
        {
          IList<Program> programList = (IList<Program>)outParameters[1];
          programs = programList.Distinct(ProgramComparer.Instance).ToList(); // Using custom comparer to filter out duplicated programs.
          return true;
        }
      }
      catch (Exception ex)
      {
        NotifyException(ex);
      }
      return false;
    }
 public bool GetChannels(IChannelGroup group, out IList<IChannel> channels)
 {
   channels = null;
   try
   {
     CpAction action = GetAction(Consts.ACTION_GET_CHANNELS);
     IList<object> inParameters = new List<object> { group.ChannelGroupId };
     IList<object> outParameters = action.InvokeAction(inParameters);
     bool success = (bool)outParameters[0];
     IList<Channel> channelList = (IList<Channel>)outParameters[1];
     if (success)
     {
       channels = channelList.Cast<IChannel>().ToList();
       return true;
     }
     return false;
   }
   catch (Exception ex)
   {
     NotifyException(ex);
     return false;
   }
 }
Beispiel #42
0
        /// <summary>
        /// Method to open and maintain outstanding channels
        /// to the publish and subscribe lists
        /// </summary>
        protected void SetupGroupChannels()
        {
            Logger.Debug ("SetupGroupChannels - called");

            string[] pubArgs = {"publish"};
            string[] subArgs = {"subscribe"};
            string[] blockedArgs = {"deny"};
            ObjectPath objectPath;

            try {
                // First setup a channel to the publish list
                uint[] pubHandles = tlpConnection.RequestHandles (HandleType.List, pubArgs);
                objectPath =
                    tlpConnection.RequestChannel (
                        org.freedesktop.Telepathy.ChannelType.ContactList,
                        HandleType.List,
                        pubHandles[0],
                        true);

                publishGroup =
                    Bus.Session.GetObject<IChannelGroup> (connInfo.BusName, objectPath);
                publishGroup.MembersChanged += OnPublishedMembersChanged;

                uint groupFlags = publishGroup.GroupFlags;
                Logger.Debug ("Group Flags: {0}", groupFlags);
                if ((((uint) groupFlags & (uint) ChannelGroupFlag.CanAdd) == (uint) ChannelGroupFlag.CanAdd))
                    Logger.Debug ("  can add");
                if (((uint) groupFlags & (uint) ChannelGroupFlag.CanRemove) == (uint) ChannelGroupFlag.CanRemove)
                    Logger.Debug ("  can remove");
                if (((uint) groupFlags & (uint) ChannelGroupFlag.CanRescind) == (uint) ChannelGroupFlag.CanRescind)
                    Logger.Debug ("  can rescind");
                if (((uint) groupFlags & (uint) ChannelGroupFlag.MessageAdd) == (uint) ChannelGroupFlag.MessageAdd)
                    Logger.Debug ("  can add messages");
                if (((uint) groupFlags & (uint) ChannelGroupFlag.MessageRemove) == (uint) ChannelGroupFlag.MessageRemove)
                    Logger.Debug ("  can remove messages");
                if (((uint) groupFlags & (uint) ChannelGroupFlag.MessageAccept) == (uint) ChannelGroupFlag.MessageAccept)
                    Logger.Debug ("  can accept messages");
                if (((uint) groupFlags & (uint) ChannelGroupFlag.MessageReject) == (uint) ChannelGroupFlag.MessageReject)
                    Logger.Debug ("  can reject messages");
                if (((uint) groupFlags & (uint) ChannelGroupFlag.MessageRescind) == (uint) ChannelGroupFlag.MessageRescind)
                    Logger.Debug ("  can rescind messages");

                // Next setup a channel to the subscribe list
                uint[] subHandles = tlpConnection.RequestHandles (HandleType.List, subArgs);
                objectPath =
                    tlpConnection.RequestChannel (
                        org.freedesktop.Telepathy.ChannelType.ContactList,
                        HandleType.List,
                        subHandles[0],
                        true);

                subscribeGroup =
                    Bus.Session.GetObject<IChannelGroup> (connInfo.BusName, objectPath);
                subscribeGroup.MembersChanged += OnSubscribedMembersChanged;

                // Next setup a channel to the blocked list
                uint[] blockedHandles =
                    tlpConnection.RequestHandles (HandleType.List, blockedArgs);
                objectPath =
                    tlpConnection.RequestChannel (
                        org.freedesktop.Telepathy.ChannelType.ContactList,
                        HandleType.List,
                        blockedHandles[0],
                        true);

                denyGroup =
                    Bus.Session.GetObject<IChannelGroup> (connInfo.BusName, objectPath);

                denyGroup.MembersChanged += OnBlockedMembersChanged;

            } catch (Exception sgc) {
                Logger.Debug ("Failed setting up group channels");
                Logger.Debug (sgc.Message);
                Logger.Debug (sgc.StackTrace);
            }
        }
    public bool GetNowAndNextForChannelGroup(IChannelGroup channelGroup, out IDictionary<int, IProgram[]> nowNextPrograms)
    {
      try
      {
        CpAction action = GetAction(Consts.ACTION_GET_NOW_NEXT_PROGRAM_FOR_GROUP);
        IList<object> inParameters = new List<object>
            {
              channelGroup.ChannelGroupId
            };

        IList<object> outParameters = action.InvokeAction(inParameters);
        bool success = (bool)outParameters[0];
        if (success)
        {
          DateTime now = DateTime.Now;
          nowNextPrograms = new Dictionary<int, IProgram[]>();
          var programs = (IList<Program>)outParameters[1];
          foreach (Program program in programs)
          {
            IProgram[] nowNext;
            int channelId = program.ChannelId;
            if (!nowNextPrograms.TryGetValue(channelId, out nowNext))
              nowNext = new IProgram[2];

            if (program.StartTime > now)
              nowNext[1] = program;
            else
              nowNext[0] = program;

            nowNextPrograms[channelId] = nowNext;
          }
          return true;
        }
      }
      catch (Exception ex)
      {
        NotifyException(ex);
      }
      nowNextPrograms = null;
      return false;
    }
    /// <summary>
    /// Tries to get a list of programs for all channels of the given <paramref name="channelGroup"/> and time range.
    /// </summary>
    /// <param name="channelGroup">Channel group</param>
    /// <param name="from">Time from</param>
    /// <param name="to">Time to</param>
    /// <param name="programs">Returns programs</param>
    /// <returns><c>true</c> if at least one program could be found</returns>
    public bool GetProgramsGroup (IChannelGroup channelGroup, DateTime @from, DateTime to, out IList<IProgram> programs)
    {
      programs = null;
      ChannelGroup indexGroup = channelGroup as ChannelGroup;
      if (indexGroup == null)
        return false;

      if (!CheckConnection(indexGroup.ServerIndex))
        return false;

      programs = new List<IProgram>();
      try
      {
        IList<WebChannelPrograms<WebProgramDetailed>> tvPrograms = TvServer(indexGroup.ServerIndex).GetProgramsDetailedForGroup(channelGroup.ChannelGroupId, from, to);
        foreach (WebProgramDetailed webProgramDetailed in tvPrograms.SelectMany(webPrograms => webPrograms.Programs))
          programs.Add(new Program(webProgramDetailed, indexGroup.ServerIndex));
      }
      catch (Exception ex)
      {
        ServiceRegistration.Get<ILogger>().Error(ex.Message);
        return false;
      }
      return programs.Count > 0;
    }
		public AsynchronousMessenger(IChannelGroup channelGroup)
		{
			this.channelGroup = channelGroup;
		}
Beispiel #46
0
    public override bool GetProgramsGroup(IChannelGroup channelGroup, DateTime from, DateTime to, out IList<IProgram> programs)
    {
      IProgramService programService = GlobalServiceProvider.Instance.Get<IProgramService>();
      IChannelGroupService channelGroupService = GlobalServiceProvider.Instance.Get<IChannelGroupService>();

      var channels = channelGroupService.GetChannelGroup(channelGroup.ChannelGroupId).GroupMaps.Select(groupMap => groupMap.Channel);
      IDictionary<int, IList<Program>> programEntities = programService.GetProgramsForAllChannels(from, to, channels);

      programs = programEntities.Values.SelectMany(x => x).Select(p => p.ToProgram()).Distinct(ProgramComparer.Instance).ToList();
      return programs.Count > 0;
    }
Beispiel #47
0
 public abstract void ProcessReplacing(IChannelGroup inputs, IChannelGroup outputs, int sampleFrames);
 public abstract bool GetChannels(IChannelGroup group, out IList<IChannel> channels);
 public abstract bool GetProgramsGroup(IChannelGroup channelGroup, DateTime from, DateTime to, out IList<IProgram> programs);
    public virtual bool GetNowAndNextForChannelGroup(IChannelGroup channelGroup, out IDictionary<int, IProgram[]> nowNextPrograms)
    {
      nowNextPrograms = new Dictionary<int, IProgram[]>();
      IList<IChannel> channels;
      if (!GetChannels(channelGroup, out channels))
        return false;

      foreach (IChannel channel in channels)
      {
        IProgram programNow;
        IProgram programNext;
        if (GetNowNextProgram(channel, out programNow, out programNext))
          nowNextPrograms[channel.ChannelId] = new[] { programNow, programNext };
      }
      return true;
    }
Beispiel #51
0
	    public override void ProcessReplacing(IChannelGroup inputs, IChannelGroup outputs, int sampleFrames)
		{
			reverb.ProcessReplacing(inputs, outputs, sampleFrames);
		}
    public bool GetNowAndNextForChannelGroup(IChannelGroup channelGroup, out IDictionary<int, IProgram[]> programs)
    {
      programs = null;
      ChannelGroup indexGroup = channelGroup as ChannelGroup;
      if (indexGroup == null)
        return false;

      if (!CheckConnection(indexGroup.ServerIndex))
        return false;

      programs = new Dictionary<int, IProgram[]>();
      try
      {
        IList<IChannel> channels;
        if (!GetChannels(indexGroup, out channels))
          return false;

        foreach (IChannel channel in channels)
        {
          IProgram[] nowNext = new IProgram[2];
          IList<WebProgramDetailed> tvPrograms = TvServer(indexGroup.ServerIndex).GetNowNextWebProgramDetailedForChannel(channel.ChannelId);
          if (tvPrograms.Count == 0)
            continue;

          if (tvPrograms.Count > 0 && tvPrograms[0] != null)
            nowNext[0]= new Program(tvPrograms[0], indexGroup.ServerIndex);
          if (tvPrograms.Count > 1 && tvPrograms[1] != null)
            nowNext[1]= new Program(tvPrograms[1], indexGroup.ServerIndex);
          programs[channel.ChannelId] = nowNext;
        }
      }
      catch (Exception ex)
      {
        ServiceRegistration.Get<ILogger>().Error(ex.Message);
        return false;
      }
      return true;
    }
Beispiel #53
0
 public override bool GetChannels(IChannelGroup group, out IList<IChannel> channels)
 {
   if (group.ChannelGroupId < 0)
   {
     var radioGroup = RadioChannelGroup.Retrieve(-group.ChannelGroupId);
     var radioChannels = radioGroup.ReferringRadioGroupMap().OrderBy(rgm => rgm.SortOrder).Select(rgm => rgm.ReferencedChannel());
     channels = radioChannels
       .Where(c => c.VisibleInGuide)
       .Select(c => c.ToChannel())
       .Where(c => c != null)
       .ToList();
   }
   else
   {
     channels = _tvBusiness.GetChannelsInGroup(TvDatabase.ChannelGroup.Retrieve(group.ChannelGroupId))
       // Bug? SortOrder contains logical channel number, not the group sort order?
       // .OrderBy(c => c.SortOrder)
       .Where(c => c.VisibleInGuide)
       .Select(c => c.ToChannel())
       .Where(c => c != null)
       .ToList();
   }
   return true;
 }
Beispiel #54
0
 public override bool GetChannels(IChannelGroup group, out IList<IChannel> channels)
 {
   IChannelGroupService channelGroupService = GlobalServiceProvider.Instance.Get<IChannelGroupService>();
   channels = channelGroupService.GetChannelGroup(group.ChannelGroupId).GroupMaps
     .Where(groupMap => groupMap.Channel.VisibleInGuide)
     .OrderBy(groupMap => groupMap.SortOrder)
     .Select(groupMap => groupMap.Channel.ToChannel())
     .ToList();
   return true;
 }
Beispiel #55
0
 public override bool GetProgramsGroup(IChannelGroup channelGroup, DateTime from, DateTime to, out IList<IProgram> programs)
 {
   programs = new List<IProgram>();
   if (channelGroup.ChannelGroupId < 0)
   {
     foreach (var channel in _tvBusiness.GetRadioGuideChannelsForGroup(-channelGroup.ChannelGroupId))
       CollectionUtils.AddAll(programs, _tvBusiness.GetPrograms(TvDatabase.Channel.Retrieve(channel.IdChannel), from, to).Select(p => p.ToProgram()));
   }
   else
   {
     foreach (var channel in _tvBusiness.GetTVGuideChannelsForGroup(channelGroup.ChannelGroupId))
       CollectionUtils.AddAll(programs, _tvBusiness.GetPrograms(TvDatabase.Channel.Retrieve(channel.IdChannel), from, to).Select(p => p.ToProgram()));
   }
   return programs.Count > 0;
 }
 public bool GetChannels(IChannelGroup group, out IList<IChannel> channels)
 {
   IChannelGroupService channelGroupService = GlobalServiceProvider.Get<IChannelGroupService>();
   channels = channelGroupService.GetChannelGroup(group.ChannelGroupId).GroupMaps
     .Select(groupMap => groupMap.Channel.ToChannel())
     .ToList();
   return true;
 }