Ejemplo n.º 1
0
        private Guid EnsureDefaultChannel(ImportGuideChannel channel, ChannelType channelType, bool updateChannelName)
        {
            using (GuideServiceAgent guideServiceAgent = new GuideServiceAgent())
            {
                using (SchedulerServiceAgent schedulerServiceAgent = new SchedulerServiceAgent())
                {
                    Guid guideChannelId = guideServiceAgent.EnsureChannel(channel.ExternalId, channel.ChannelName, channelType);

                    // If we have exactly one channel, check LCN and DisplayName :
                    Channel[] channels = schedulerServiceAgent.GetChannelsForGuideChannel(guideChannelId);
                    if (channels.Length == 1 && updateChannelName)
                    {
                        bool needsToBeSaved = false;
                        if (channels[0].LogicalChannelNumber == null && channel.LogicalChannelNumber.HasValue)
                        {
                            channels[0].LogicalChannelNumber = channel.LogicalChannelNumber;
                            needsToBeSaved = true;
                        }
                        if (channels[0].DisplayName != channel.ChannelName)
                        {
                            channels[0].DisplayName = channel.ChannelName;
                            needsToBeSaved          = true;
                        }

                        if (needsToBeSaved)
                        {
                            schedulerServiceAgent.SaveChannel(channels[0]);
                        }
                    }
                    else if (channels.Length == 0)
                    {
                        // No channels linked to the GuideChannel. If we have an existing channel with the same name, then link it.
                        Channel existingChannel = schedulerServiceAgent.GetChannelByDisplayName(channelType, channel.ChannelName);
                        if (existingChannel != null)
                        {
                            existingChannel.LogicalChannelNumber = channel.LogicalChannelNumber;
                            schedulerServiceAgent.SaveChannel(existingChannel);
                        }
                        else
                        {
                            schedulerServiceAgent.EnsureDefaultChannel(guideChannelId, channelType, channel.ChannelName, null);
                            channels = schedulerServiceAgent.GetChannelsForGuideChannel(guideChannelId);
                            if (channels.Length == 1)
                            {
                                channels[0].LogicalChannelNumber = channel.LogicalChannelNumber;
                                schedulerServiceAgent.SaveChannel(channels[0]);
                            }
                        }
                    }
                    return(guideChannelId);
                }
            }
        }
Ejemplo n.º 2
0
        private Guid EnsureDefaultChannel(ImportGuideChannel channel, ChannelType channelType, bool updateChannelName)
        {
            using (GuideServiceAgent guideServiceAgent = new GuideServiceAgent())
            {
                using (SchedulerServiceAgent schedulerServiceAgent = new SchedulerServiceAgent())
                {
                    Guid guideChannelId = guideServiceAgent.EnsureChannel(channel.ExternalId, channel.ChannelName, channelType);

                    // If we have exactly one channel, check LCN and DisplayName :
                    Channel[] channels = schedulerServiceAgent.GetChannelsForGuideChannel(guideChannelId);
                    if (channels.Length == 1 && updateChannelName)
                    {
                        bool needsToBeSaved = false;
                        if (channels[0].LogicalChannelNumber == null && channel.LogicalChannelNumber.HasValue)
                        {
                            channels[0].LogicalChannelNumber = channel.LogicalChannelNumber;
                            needsToBeSaved = true;
                        }
                        if (channels[0].DisplayName != channel.ChannelName)
                        {
                            channels[0].DisplayName = channel.ChannelName;
                            needsToBeSaved = true;
                        }

                        if (needsToBeSaved)
                        {
                            schedulerServiceAgent.SaveChannel(channels[0]);
                        }
                    }
                    else if(channels.Length == 0)
                    {
                        // No channels linked to the GuideChannel. If we have an existing channel with the same name, then link it.
                        Channel existingChannel = schedulerServiceAgent.GetChannelByDisplayName(channelType, channel.ChannelName);
                        if (existingChannel != null)
                        {
                            existingChannel.LogicalChannelNumber = channel.LogicalChannelNumber;
                            schedulerServiceAgent.SaveChannel(existingChannel);
                        }
                        else
                        {
                            schedulerServiceAgent.EnsureDefaultChannel(guideChannelId, channelType, channel.ChannelName, null);
                            channels = schedulerServiceAgent.GetChannelsForGuideChannel(guideChannelId);
                            if (channels.Length == 1)
                            {
                                channels[0].LogicalChannelNumber = channel.LogicalChannelNumber;
                                schedulerServiceAgent.SaveChannel(channels[0]);
                            }
                        }
                    }
                    return guideChannelId;
                }
            }
        }