Example #1
0
        public static void FillAMSEvent(this IProgram program, AMSChannel channel, IProgramRelativeEntity eventData)
        {
            if (program != null)
            {
                eventData.AMSProgramID = program.Id;
                eventData.State = program.State.ToAMSEventState();

                IAsset asset = program.Asset;

                if (asset != null)
                {
                    IAssetFile file = asset.AssetFiles.AsEnumerable().FirstOrDefault(a => a.Name.EndsWith(".ism"));

                    if (file != null)
                    {
                        ILocator locator = asset.Locators.FirstOrDefault();

                        if (locator != null)
                        {
                            eventData.DefaultPlaybackUrl = locator.Path + file.Name + "/manifest";
                            eventData.CDNPlaybackUrl = GetCDNPlaybackUrl(locator.Path, eventData.DefaultPlaybackUrl, file.Name, channel.CDNPrefixMode, channel.CDNPrefix);
                        }
                    }
                }
            }
        }
Example #2
0
        public static void StopProgram(AMSChannel channel, AMSEvent eventData, IProgramRelativeEntity retProgramInfo)
        {
            if (channel != null && channel.AMSID.IsNotEmpty())
            {
                CloudMediaContext context = MediaServiceAccountSettings.GetConfig().Accounts.GetCloudMediaContext(channel.AMSAccountName);

                IChannel amsChannel = GetChannelByID(context, channel.AMSID);

                if (amsChannel != null)
                {
                    IProgram program = GetProgramByEvent(amsChannel, eventData);

                    if (program != null)
                    {
                        if (program.State == ProgramState.Running)
                        {
                            TraceOperation("Stop Program {0}", () => program.Stop(), program.Name);
                        }

                        program.FillAMSEvent(channel, retProgramInfo);

                        if (retProgramInfo.State == AMSEventState.NotStart)
                        {
                            retProgramInfo.State = AMSEventState.Completed;
                        }
                    }
                    else
                    {
                        retProgramInfo.State = AMSEventState.Completed;
                    }
                }
            }
        }
Example #3
0
        public void UpdateExistedUserView()
        {
            AMSEventSqlAdapter.Instance.ClearAll();
            AMSUserViewSqlAdapter.Instance.ClearAll();

            AMSChannel channel = DataHelper.PrepareChannelData();

            AMSEvent eventData = DataHelper.PrepareEventData(channel.ID);

            AMSEventSqlAdapter.Instance.Update(eventData);

            AMSUserView userView = DataHelper.PrepareUserView(eventData.ID);

            AMSUserViewSqlAdapter.Instance.UpdateUserView(userView);

            WhereSqlClauseBuilder builder = new WhereSqlClauseBuilder();

            builder.AppendItem("EventID", userView.EventID);
            builder.AppendItem("UserID", userView.UserID);

            AMSUserView userViewLoaded = AMSUserViewSqlAdapter.Instance.LoadByBuilder(builder).Single();

            AMSEvent eventLoaded = AMSEventSqlAdapter.Instance.LoadByID(eventData.ID);

            Assert.AreEqual(1, eventLoaded.Views);

            //再保存一下
            AMSUserViewSqlAdapter.Instance.UpdateUserView(userView);

            eventLoaded = AMSEventSqlAdapter.Instance.LoadByID(eventData.ID);

            //用户观看次数依然是1
            Assert.AreEqual(1, eventLoaded.Views);
        }
Example #4
0
        public static void FillAMSEvent(this IProgram program, AMSChannel channel, IProgramRelativeEntity eventData)
        {
            if (program != null)
            {
                eventData.AMSProgramID = program.Id;
                eventData.State        = program.State.ToAMSEventState();

                IAsset asset = program.Asset;

                if (asset != null)
                {
                    IAssetFile file = asset.AssetFiles.AsEnumerable().FirstOrDefault(a => a.Name.EndsWith(".ism"));

                    if (file != null)
                    {
                        ILocator locator = asset.Locators.FirstOrDefault();

                        if (locator != null)
                        {
                            eventData.DefaultPlaybackUrl = locator.Path + file.Name + "/manifest";
                            eventData.CDNPlaybackUrl     = GetCDNPlaybackUrl(locator.Path, eventData.DefaultPlaybackUrl, file.Name, channel.CDNPrefixMode, channel.CDNPrefix);
                        }
                    }
                }
            }
        }
Example #5
0
        /// <summary>
        /// 启动事件中的一个频道和节目
        /// </summary>
        /// <param name="eventData"></param>
        /// <param name="ec"></param>
        /// <param name="cancellationToken"></param>
        private static void StartOneChannelAndProgram(AMSEvent eventData, AMSEventChannel ec, CancellationToken cancellationToken)
        {
            try
            {
                if (ec.State == AMSEventState.NotStart)
                {
                    AMSEventSqlAdapter.Instance.UpdateEventChannelState(ec.EventID, ec.ChannelID, AMSEventState.Starting);
                }

                AMSChannel channel = StartChannel(ec.ChannelID, cancellationToken);

                if (cancellationToken.IsCancellationRequested == false)
                {
                    if (channel != null && channel.State == AMSChannelState.Running)
                    {
                        LockHelper.ExtendLockTime(eventData);

                        StartProgram(eventData, channel, ec, cancellationToken);
                    }
                }
            }
            catch (System.Exception ex)
            {
                TraceHelper.AMSTaskTraceSource.TraceEvent(TraceEventType.Error, 60020, ex.ToString());
            }
        }
Example #6
0
        private void InitAlternateCDNAddress(AMSChannel channel, AMSEvent eventData)
        {
            if (channel != null && eventData != null && channel.AlternateCDNEndpoint.IsNotEmpty())
            {
                VideoAddressType videoAddressType = WebHelper.GetVideoAddressType();
                VideoAddressType targetType       = VideoAddressType.AlternateCDN;
                string           buttonText       = this.switchVideoAddressType.InnerText;

                switch (videoAddressType)
                {
                case VideoAddressType.Default:
                    targetType = VideoAddressType.AlternateCDN;
                    buttonText = "切换到备用CDN";
                    break;

                case VideoAddressType.AlternateCDN:
                    targetType = VideoAddressType.Default;
                    buttonText = "切换到默认地址";
                    break;
                }

                this.targetAddressType.Value          = targetType.ToString();
                this.switchVideoAddressType.InnerText = buttonText;
                this.videoAddressType.Value           = videoAddressType.ToString();
            }
            else
            {
                this.switchVideoAddressType.Attributes["class"] = "btn btn-default disabled";
            }
        }
Example #7
0
        public void CheckAddChannelIntersectEvent()
        {
            AMSEventSqlAdapter.Instance.ClearAll();
            AMSChannelSqlAdapter.Instance.ClearAll();

            AMSChannel originalChannel = DataHelper.PrepareChannelData();

            AMSChannelSqlAdapter.Instance.Update(originalChannel);

            AMSEvent originalEvent = DataHelper.PrepareEventData(originalChannel.ID);

            AMSEventSqlAdapter.Instance.Update(originalEvent);

            AMSChannel theSecondChannel = DataHelper.PrepareChannelData();

            AMSChannelSqlAdapter.Instance.Update(theSecondChannel);

            AMSEventSqlAdapter.Instance.AddChannel(originalEvent.ID, new string[] { theSecondChannel.ID });

            AMSChannel theThirdChannel = DataHelper.PrepareChannelData();

            AMSChannelSqlAdapter.Instance.Update(theThirdChannel);

            AMSEvent newEvent = DataHelper.PrepareEventData(theThirdChannel.ID);

            AMSEventSqlAdapter.Instance.Update(newEvent);

            Assert.IsTrue(AMSEventSqlAdapter.Instance.HaveIntersectEvents(newEvent, theSecondChannel.ID));
        }
Example #8
0
        public static void AddEvent(params string[] channelNames)
        {
            AMSEvent eventData = new AMSEvent();

            eventData.ID = UuidHelper.NewUuidString();

            eventData.Name      = string.Format("新建节目在\"{0}\"{1:yyyy-MM-dd HH:mm:ss.fff}", channelNames[0], DateTime.UtcNow);
            eventData.State     = AMSEventState.NotStart;
            eventData.StartTime = DateTime.Now.AddMinutes(5);
            eventData.EndTime   = DateTime.Now.AddMinutes(35);

            eventData.ChannelID = GetChannelByName(channelNames[0]).ID;

            if (channelNames.Length > 1)
            {
                for (int i = 1; i < channelNames.Length; i++)
                {
                    AMSChannel channel = GetChannelByName(channelNames[i]);

                    AMSEventSqlAdapter.Instance.AddChannel(eventData.ID, new string[] { channel.ID });
                }
            }

            AMSEventSqlAdapter.Instance.Update(eventData);
        }
Example #9
0
        public void IncludeCompletedAndNeedStartEventsLoadNeedStopChannels()
        {
            AMSEventSqlAdapter.Instance.ClearAll();
            AMSChannelSqlAdapter.Instance.ClearAll();

            AMSChannel channel = DataHelper.PrepareChannelData();

            AMSChannelSqlAdapter.Instance.Update(channel);

            AMSEvent prevEventData = DataHelper.PrepareEventData(channel.ID);

            prevEventData.StartTime = DateTime.Now.AddHours(-2);
            prevEventData.EndTime   = DateTime.Now.AddHours(-1);

            AMSEventSqlAdapter.Instance.Update(prevEventData);

            AMSEvent nextEventData = DataHelper.PrepareEventData(channel.ID);

            nextEventData.StartTime = DateTime.Now.AddMinutes(30);
            nextEventData.EndTime   = DateTime.Now.AddHours(3);

            AMSEventSqlAdapter.Instance.Update(prevEventData);

            AMSChannelCollection needToStopChannels = AMSChannelSqlAdapter.Instance.LoadNeedStopChannels(TimeSpan.FromHours(1));

            needToStopChannels.Output();
            Assert.AreEqual(1, needToStopChannels.Count);
        }
Example #10
0
        public void AddChannelInEventExecutor()
        {
            AMSEventSqlAdapter.Instance.ClearAll();
            AMSChannelSqlAdapter.Instance.ClearAll();

            AMSChannel channel = DataHelper.PrepareChannelData();

            AMSChannelSqlAdapter.Instance.Update(channel);

            AMSEvent eventData = DataHelper.PrepareEventData(channel.ID);

            AMSEventSqlAdapter.Instance.Update(eventData);

            AMSChannel newChannel = DataHelper.PrepareChannelData();

            AMSChannelSqlAdapter.Instance.Update(newChannel);

            AMSAddChannelInEventExecutor executor = new AMSAddChannelInEventExecutor(eventData.ID, newChannel.ID);

            executor.Execute();

            AMSChannelCollection channels = AMSEventSqlAdapter.Instance.LoadRelativeChannels(eventData.ID);

            channels.Output();
            Assert.AreEqual(2, channels.Count);
        }
Example #11
0
        private static AMSChannel GetChannelByName(string channelName)
        {
            AMSChannel channel = AMSChannelSqlAdapter.Instance.Load(builder => builder.AppendItem("Name", channelName)).SingleOrDefault();

            (channel == null).TrueThrow("不能根据{0}找到频道", channelName);

            return(channel);
        }
Example #12
0
        private static void StartProgram(AMSEvent eventData, AMSChannel channel, AMSEventChannel ec, CancellationToken cancellationToken)
        {
            TraceHelper.AMSTaskTraceSource.TraceEvent(TraceEventType.Verbose, 60017, "Start Program:\n{0}", channel.ToTraceInfo());

            SimulateOrExecuteAction(() => LiveChannelManager.StartProgram(channel, eventData, ec), () => ec.State = AMSEventState.Running);

            AMSEventSqlAdapter.Instance.UpdateEventChannel(ec);

            TraceHelper.AMSTaskTraceSource.TraceEvent(TraceEventType.Verbose, 60017, "Program Started:\n{0}", channel.ToTraceInfo());
        }
Example #13
0
        public static void AreEqual(this AMSChannel expected, AMSChannel actual)
        {
            Assert.IsNotNull(expected);
            Assert.IsNotNull(actual);

            Assert.AreEqual(expected.ID, actual.ID);
            Assert.AreEqual(expected.Name, actual.Name);
            Assert.AreEqual(expected.Description, actual.Description);
            Assert.AreEqual(expected.State, actual.State);
        }
Example #14
0
        public static void AreEqual(this AMSChannel expected, AMSChannel actual)
        {
            Assert.IsNotNull(expected);
            Assert.IsNotNull(actual);

            Assert.AreEqual(expected.ID, actual.ID);
            Assert.AreEqual(expected.Name, actual.Name);
            Assert.AreEqual(expected.Description, actual.Description);
            Assert.AreEqual(expected.State, actual.State);
        }
Example #15
0
        public static AMSChannel PrepareChannelData()
        {
            AMSChannel channel = new AMSChannel();

            channel.ID = UuidHelper.NewUuidString();
            channel.Name = "Test Channel";
            channel.Description = "Test Channel Description";
            channel.State = AMSChannelState.Running;

            return channel;
        }
Example #16
0
        public static AMSChannel PrepareChannelData()
        {
            AMSChannel channel = new AMSChannel();

            channel.ID          = UuidHelper.NewUuidString();
            channel.Name        = "Test Channel";
            channel.Description = "Test Channel Description";
            channel.State       = AMSChannelState.Running;

            return(channel);
        }
Example #17
0
        public static AMSChannel ToAMSChannel(this IChannel channel)
        {
            channel.NullCheck("channel");

            AMSChannel result = new AMSChannel();

            result.ID = channel.Id;

            channel.FillAMSChannel(result);

            return(result);
        }
Example #18
0
        public static AMSChannel ToAMSChannel(this IChannel channel)
        {
            channel.NullCheck("channel");

            AMSChannel result = new AMSChannel();

            result.ID = channel.Id;

            channel.FillAMSChannel(result);

            return result;
        }
Example #19
0
        public void UpdateAMSChannel()
        {
            AMSChannelSqlAdapter.Instance.ClearAll();

            AMSChannel channel = DataHelper.PrepareChannelData();

            AMSChannelSqlAdapter.Instance.Update(channel);

            AMSChannel channelLoaded = AMSChannelSqlAdapter.Instance.LoadByInBuilder(builder => builder.AppendItem(channel.ID), "ID").SingleOrDefault();

            Assert.IsNotNull(channelLoaded);
            channel.AreEqual(channelLoaded);
        }
Example #20
0
        public void UpdateAMSEvent()
        {
            AMSEventSqlAdapter.Instance.ClearAll();

            AMSChannel channel = DataHelper.PrepareChannelData();

            AMSEvent eventData = DataHelper.PrepareEventData(channel.ID);

            AMSEventSqlAdapter.Instance.Update(eventData);
            AMSEvent eventLoaded = AMSEventSqlAdapter.Instance.LoadByChannelID(channel.ID).SingleOrDefault();

            Assert.IsNotNull(eventLoaded);
            eventData.AreEqual(eventLoaded);
        }
Example #21
0
        public static string ToTraceInfo(this AMSChannel channel)
        {
            StringBuilder strB = new StringBuilder();

            StringWriter writer = new StringWriter(strB);

            writer.WriteLine("ID: {0}", channel.ID);
            writer.WriteLine("AccountName: {0}", channel.AMSAccountName);
            writer.WriteLine("Channel ID: {0}", channel.AMSID);
            writer.WriteLine("Name: {0}", channel.Name);
            writer.WriteLine("State: {0}", channel.State);
            writer.WriteLine("LastModified: {0:yyyy-MM-dd HH:mm:ss}", channel.AMSLastModified);

            return(strB.ToString());
        }
Example #22
0
        private static string ChangeVideoAddress(AMSChannel channel, string url, VideoAddressType addressType)
        {
            string result = url;

            if (channel != null && channel.AlternateCDNEndpoint.IsNotEmpty() && url.IsNotEmpty())
            {
                Uri target = new Uri(url);

                if (addressType == VideoAddressType.AlternateCDN)
                {
                    result = MergePlaybackCDNHost(target, channel.AlternateCDNEndpoint);
                }
            }

            return(result);
        }
Example #23
0
        public void LoadNeedStartEventOutTimeFrame()
        {
            AMSEventSqlAdapter.Instance.ClearAll();

            AMSChannel channel = DataHelper.PrepareChannelData();

            AMSEvent eventData = DataHelper.PrepareEventData(channel.ID);

            eventData.StartTime = DateTime.Now.Add(TimeSpan.FromMinutes(10));

            AMSEventSqlAdapter.Instance.Update(eventData);

            AMSEventCollection eventsLoaded = AMSEventSqlAdapter.Instance.LoadNeedStartEvents(TimeSpan.FromMinutes(5));

            Assert.AreEqual(0, eventsLoaded.Count);
        }
Example #24
0
        public void EventTimeValidationExecutor()
        {
            AMSEventSqlAdapter.Instance.ClearAll();

            AMSChannel channel = DataHelper.PrepareChannelData();

            AMSEvent eventData = DataHelper.PrepareEventData(channel.ID);

            eventData.StartTime = DateTime.Now;
            eventData.EndTime   = DateTime.Now.AddDays(-1);

            AMSEditEntityExecutor <AMSEvent> executor = new AMSEditEntityExecutor <AMSEvent>(eventData,
                                                                                             data => AMSEventSqlAdapter.Instance.Update(data), AMSOperationType.EditEvent);

            executor.Execute();
        }
Example #25
0
        public static void Output(this AMSChannel channel)
        {
            if (channel != null)
            {
                Console.WriteLine("ID: {0}", channel.ID);
                Console.WriteLine("Name: {0}", channel.Name);
                Console.WriteLine("AMSAccountName: {0}", channel.AMSAccountName);
                Console.WriteLine("AMSID: {0}", channel.AMSID);

                if (channel is AMSChannelInEvent)
                {
                    Console.WriteLine("IsDefault: {0}", ((AMSChannelInEvent)channel).IsDefault);
                    Console.WriteLine("DefaultPlaybackUrl: {0}", ((AMSChannelInEvent)channel).DefaultPlaybackUrl);
                    Console.WriteLine("CDNPlaybackUrl: {0}", ((AMSChannelInEvent)channel).CDNPlaybackUrl);
                }
            }
        }
Example #26
0
        public static void AddMooncakeEvent()
        {
            AMSEvent eventData = new AMSEvent();

            eventData.ID = UuidHelper.NewUuidString();

            eventData.Name      = string.Format("新建节目{0:yyyy-MM-dd HH:mm:ss.fff}", DateTime.UtcNow);
            eventData.State     = AMSEventState.NotStart;
            eventData.StartTime = DateTime.UtcNow.AddMinutes(5);
            eventData.EndTime   = DateTime.UtcNow.AddMinutes(35);

            AMSChannel channel = AMSChannelSqlAdapter.Instance.Load(builder => builder.AppendItem("Name", TestChannelName)).SingleOrDefault();

            eventData.ChannelID = channel.ID;

            AMSEventSqlAdapter.Instance.Update(eventData);
        }
Example #27
0
        public void CheckNewIntersectEvent()
        {
            AMSEventSqlAdapter.Instance.ClearAll();
            AMSChannelSqlAdapter.Instance.ClearAll();

            AMSChannel originalChannel = DataHelper.PrepareChannelData();

            AMSChannelSqlAdapter.Instance.Update(originalChannel);

            AMSEvent originalEvent = DataHelper.PrepareEventData(originalChannel.ID);

            AMSEventSqlAdapter.Instance.Update(originalEvent);

            AMSEvent newEvent = DataHelper.PrepareEventData(originalChannel.ID);

            Assert.IsTrue(AMSEventSqlAdapter.Instance.HaveIntersectEvents(newEvent));
        }
Example #28
0
        public void LoadNeedStopEventInTimeFrame()
        {
            AMSEventSqlAdapter.Instance.ClearAll();

            AMSChannel channel = DataHelper.PrepareChannelData();

            AMSEvent eventData = DataHelper.PrepareEventData(channel.ID);

            eventData.State   = AMSEventState.Running;
            eventData.EndTime = DateTime.UtcNow.Add(-TimeSpan.FromMinutes(10));

            AMSEventSqlAdapter.Instance.Update(eventData);

            AMSEventCollection eventsLoaded = AMSEventSqlAdapter.Instance.LoadNeedStopEvents();

            Assert.IsTrue(eventsLoaded.Count > 0);
        }
Example #29
0
        public static string GetSingleEventJson(AMSChannel channel, AMSEvent eventData, VideoAddressType addressType)
        {
            var simpleEventData = new
            {
                id          = eventData.ID,
                channelID   = eventData.ChannelID,
                name        = eventData.Name,
                description = eventData.Description,
                speakers    = eventData.Speakers,
                url         = ChangeVideoAddress(channel, eventData.CDNPlaybackUrl, addressType),
                poster      = eventData.PosterUrl,
                views       = string.Format("{0:#,##0}", eventData.Views),
                startTime   = string.Format("{0:yyyy-MM-dd HH:mm:ss}", eventData.StartTime),
                endTime     = string.Format("{0:yyyy-MM-dd HH:mm:ss}", eventData.EndTime)
            };

            return(JSONSerializerExecute.Serialize(simpleEventData));
        }
Example #30
0
        public void UpdateEventExecutor()
        {
            AMSEventSqlAdapter.Instance.ClearAll();

            AMSChannel channel = DataHelper.PrepareChannelData();

            AMSEvent eventData = DataHelper.PrepareEventData(channel.ID);

            AMSEditEntityExecutor <AMSEvent> executor = new AMSEditEntityExecutor <AMSEvent>(eventData,
                                                                                             data => AMSEventSqlAdapter.Instance.Update(data), AMSOperationType.EditEvent);

            executor.Execute();

            AMSEvent eventLoaded = AMSEventSqlAdapter.Instance.LoadByChannelID(channel.ID).SingleOrDefault();

            Assert.IsNotNull(eventLoaded);
            eventData.AreEqual(eventLoaded);
        }
Example #31
0
        public static void StartChannel(AMSChannel channel)
        {
            if (channel != null && channel.AMSID.IsNotEmpty())
            {
                CloudMediaContext context = MediaServiceAccountSettings.GetConfig().Accounts.GetCloudMediaContext(channel.AMSAccountName);

                IChannel amsChannel = GetChannelByID(context, channel.AMSID);

                if (amsChannel != null)
                {
                    if (amsChannel.State == ChannelState.Stopped)
                    {
                        TraceOperation("Channel {0}", () => amsChannel.Start(), amsChannel.Name);
                    }

                    amsChannel.FillAMSChannel(channel);
                }
            }
        }
Example #32
0
        private static void StopProgram(AMSEvent eventData, AMSEventChannel ec, CancellationToken cancellationToken)
        {
            TraceHelper.AMSTaskTraceSource.TraceEvent(TraceEventType.Verbose, 60018, "Stop Program:\n{0}", eventData.ToTraceInfo());

            AMSChannel channel = AMSChannelSqlAdapter.Instance.LoadByID(ec.ChannelID);

            if (channel != null)
            {
                SimulateOrExecuteAction(() => LiveChannelManager.StopProgram(channel, eventData, ec), () => ec.State = AMSEventState.Completed);
            }
            else
            {
                ec.State = AMSEventState.Completed;
            }

            AMSEventSqlAdapter.Instance.UpdateEventChannel(ec);

            TraceHelper.AMSTaskTraceSource.TraceEvent(TraceEventType.Verbose, 60018, "Program Stopped:\n{0}", eventData.ToTraceInfo());
        }
Example #33
0
        public static void FillAMSChannel(this IChannel channel, AMSChannel result)
        {
            channel.NullCheck("channel");
            result.NullCheck("result");

            result.AMSID = channel.Id;
            result.Name = channel.Name;
            result.Description = channel.Description;
            result.State = channel.State.ToAMSChannelState();
            result.AMSLastModified = channel.LastModified;

            if (channel.Preview != null)
                result.PreviewUrl = channel.Preview.Endpoints.GetDefaultUrl();

            if (channel.Input != null)
            {
                result.PrimaryInputUrl = channel.Input.Endpoints.GetDefaultUrl();
                result.SecondaryInputUrl = channel.Input.Endpoints.GetSecondaryUrl();
            }
        }
Example #34
0
        public static void StopChannel(AMSQueueItem message, CancellationToken cancellationToken)
        {
            AMSChannel channel = AMSChannelSqlAdapter.Instance.LoadByID(message.ResourceID);

            if (channel != null)
            {
                TraceHelper.AMSTaskTraceSource.TraceEvent(TraceEventType.Verbose, 60014, "Stop Channel:\n{0}", channel.ToTraceInfo());

                if (channel.State == AMSChannelState.Stopped)
                {
                    AMSChannelSqlAdapter.Instance.UpdateState(channel.ID, AMSChannelState.Stopping);
                }

                SimulateOrExecuteAction(() => LiveChannelManager.StopChannel(channel), () => channel.State = AMSChannelState.Stopped);

                AMSChannelSqlAdapter.Instance.Update(channel);

                TraceHelper.AMSTaskTraceSource.TraceEvent(TraceEventType.Verbose, 60014, "Channel Stopped:\n{0}", channel.ToTraceInfo());
            }
        }
Example #35
0
        /// <summary>
        /// 启动频道,并且更新频道状态
        /// </summary>
        /// <param name="channelID"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        private static AMSChannel StartChannel(string channelID, CancellationToken cancellationToken)
        {
            AMSChannel channel = AMSChannelSqlAdapter.Instance.LoadByID(channelID);

            if (channel != null)
            {
                TraceHelper.AMSTaskTraceSource.TraceEvent(TraceEventType.Verbose, 60016, "Start Channel:\n{0}", channel.ToTraceInfo());

                if (channel.State == AMSChannelState.Stopped)
                {
                    AMSChannelSqlAdapter.Instance.UpdateState(channel.ID, AMSChannelState.Starting);
                }

                SimulateOrExecuteAction(() => LiveChannelManager.StartChannel(channel), () => channel.State = AMSChannelState.Running);
                AMSChannelSqlAdapter.Instance.Update(channel);

                TraceHelper.AMSTaskTraceSource.TraceEvent(TraceEventType.Verbose, 60016, "Channel Started:\n{0}", channel.ToTraceInfo());
            }

            return(channel);
        }
Example #36
0
        private static string ChangeVideoAddress(AMSChannel channel, string url, VideoAddressType addressType)
        {
            string result = url;

            if (channel != null && channel.AlternateCDNEndpoint.IsNotEmpty() && url.IsNotEmpty())
            {
                Uri target = new Uri(url);

                if (addressType == VideoAddressType.AlternateCDN)
                    result = MergePlaybackCDNHost(target, channel.AlternateCDNEndpoint);
            }

            return result;
        }
Example #37
0
        public static string GetSingleEventJson(AMSChannel channel, AMSEvent eventData, VideoAddressType addressType)
        {
            var simpleEventData = new
            {
                id = eventData.ID,
                channelID = eventData.ChannelID,
                name = eventData.Name,
                description = eventData.Description,
                speakers = eventData.Speakers,
                url = ChangeVideoAddress(channel, eventData.CDNPlaybackUrl, addressType),
                poster = eventData.PosterUrl,
                views = string.Format("{0:#,##0}", eventData.Views),
                startTime = string.Format("{0:yyyy-MM-dd HH:mm:ss}", eventData.StartTime),
                endTime = string.Format("{0:yyyy-MM-dd HH:mm:ss}", eventData.EndTime)
            };

            return JSONSerializerExecute.Serialize(simpleEventData);
        }
Example #38
0
        private void InitAlternateCDNAddress(AMSChannel channel, AMSEvent eventData)
        {
            if (channel != null && eventData != null && channel.AlternateCDNEndpoint.IsNotEmpty())
            {
                VideoAddressType videoAddressType = WebHelper.GetVideoAddressType();
                VideoAddressType targetType = VideoAddressType.AlternateCDN;
                string buttonText = this.switchVideoAddressType.InnerText;

                switch (videoAddressType)
                {
                    case VideoAddressType.Default:
                        targetType = VideoAddressType.AlternateCDN;
                        buttonText = "切换到备用CDN";
                        break;
                    case VideoAddressType.AlternateCDN:
                        targetType = VideoAddressType.Default;
                        buttonText = "切换到默认地址";
                        break;
                }

                this.targetAddressType.Value = targetType.ToString();
                this.switchVideoAddressType.InnerText = buttonText;
                this.videoAddressType.Value = videoAddressType.ToString();
            }
            else
            {
                this.switchVideoAddressType.Attributes["class"] = "btn btn-default disabled";
            }
        }
Example #39
0
        private static void InnerStartProgram(AMSEvent eventData, AMSChannel channel, AMSEventChannel ec, CancellationToken cancellationToken)
        {
            TraceHelper.AMSTaskTraceSource.TraceEvent(TraceEventType.Verbose, 60017, "Start Program:\n{0}", channel.ToTraceInfo());

            SimulateOrExecuteAction(() => LiveChannelManager.StartProgram(channel, eventData, ec), () => ec.State = AMSEventState.Running);

            AMSEventSqlAdapter.Instance.UpdateEventChannel(ec);

            TraceHelper.AMSTaskTraceSource.TraceEvent(TraceEventType.Verbose, 60017, "Program Started:\n{0}", channel.ToTraceInfo());
        }