public AMSChannelCollection LoadRelativeChannels(string eventID) { eventID.CheckStringIsNullOrEmpty("eventID"); WhereSqlClauseBuilder builder = new WhereSqlClauseBuilder(); builder.AppendItem("EC.EventID", eventID); string sql = string.Format("SELECT C.*, EC.EventID, EC.DefaultPlaybackUrl, EC.CDNPlaybackUrl, EC.IsDefault FROM AMS.Channels C INNER JOIN AMS.EventsChannels EC ON C.ID = EC.ChannelID WHERE {0} ORDER BY EC.IsDefault DESC", builder.ToSqlString(TSqlBuilder.Instance)); DataTable table = DbHelper.RunSqlReturnDS(sql, this.GetConnectionName()).Tables[0]; AMSChannelCollection channels = new AMSChannelCollection(); foreach (DataRow row in table.Rows) { AMSChannelInEvent channel = new AMSChannelInEvent(); ORMapping.DataRowToObject(row, channel); channels.Add(channel); } return(channels); }
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); }
public static int DeleteAllExpiredPrograms(TimeSpan expiredTime) { int count = 0; AMSChannelCollection channels = GetAllChannels(false); foreach (AMSChannel channel in channels) { CloudMediaContext context = MediaServiceAccountSettings.GetConfig().Accounts.GetCloudMediaContext(channel.AMSAccountName); IChannel amsChannel = GetChannelByID(context, channel.AMSID); if (amsChannel != null) { foreach (IProgram program in amsChannel.Programs.ToArray()) { if (program.State == ProgramState.Stopped && (program.LastModified + expiredTime) < DateTime.UtcNow) { TraceOperation("Delete Program {0}", () => program.Delete(), program.Name); count++; } } } } return(count); }
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); }
public void ListChannelsFromConfig() { AMSChannelSqlAdapter.Instance.ClearAll(); AMSChannelSqlAdapter.Instance.InitChannels(); AMSChannelCollection channels = LiveChannelManager.GetAllChannels(); Output(channels); }
public static AMSChannelCollection ToAMSChannels(this IEnumerable<IChannel> channels) { channels.NullCheck("channels"); AMSChannelCollection result = new AMSChannelCollection(); channels.AsEnumerable().ForEach(c => result.Add(c.ToAMSChannel())); return result; }
public static void SyncChannelInfo(AMSQueueItem message, CancellationToken cancellationToken) { TraceHelper.AMSTaskTraceSource.TraceEvent(TraceEventType.Verbose, 60013, "Start Sync Channel Info"); AMSChannelCollection channels = LiveChannelManager.GetAllChannels(true); AMSChannelSqlAdapter.Instance.UpdateAllChannels(channels); TraceHelper.AMSTaskTraceSource.TraceEvent(TraceEventType.Verbose, 60013, "Complete Sync Channel Info"); }
public static AMSChannelCollection ToAMSChannels(this IEnumerable <IChannel> channels) { channels.NullCheck("channels"); AMSChannelCollection result = new AMSChannelCollection(); channels.AsEnumerable().ForEach(c => result.Add(c.ToAMSChannel())); return(result); }
public void UpdateAllChannelsToDB() { AMSChannelSqlAdapter.Instance.ClearAll(); AMSChannelSqlAdapter.Instance.InitChannels(); AMSChannelCollection channels = LiveChannelManager.GetAllChannels(true); AMSChannelSqlAdapter.Instance.UpdateAllChannels(channels); Output(channels); }
/// <summary> /// 判断同一频道下是否有时间交叉的事件 /// </summary> /// <param name="eventData"></param> /// <param name="additionalChannelID">额外的频道</param> /// <returns></returns> public bool HaveIntersectEvents(AMSEvent eventData, string additionalChannelID = "") { eventData.NullCheck("eventData"); DateTime startTime = TimeZoneContext.Current.ConvertTimeToUtc(eventData.StartTime); DateTime endTime = TimeZoneContext.Current.ConvertTimeToUtc(eventData.EndTime); WhereSqlClauseBuilder builder1 = new WhereSqlClauseBuilder(); builder1.AppendItem("StartTime", startTime, ">="); builder1.AppendItem("StartTime", endTime, "<"); WhereSqlClauseBuilder builder2 = new WhereSqlClauseBuilder(); builder2.AppendItem("EndTime", startTime, ">"); builder2.AppendItem("EndTime", endTime, "<"); WhereSqlClauseBuilder builder3 = new WhereSqlClauseBuilder(); builder3.AppendItem("StartTime", startTime, "<"); builder3.AppendItem("EndTime", startTime, ">"); WhereSqlClauseBuilder builder4 = new WhereSqlClauseBuilder(); builder4.AppendItem("StartTime", endTime, "<"); builder4.AppendItem("EndTime", endTime, ">"); ConnectiveSqlClauseCollection connectiveTime = new ConnectiveSqlClauseCollection(LogicOperatorDefine.Or, builder1, builder2, builder3, builder4); WhereSqlClauseBuilder idBuilder = new WhereSqlClauseBuilder(); idBuilder.AppendItem("ID", eventData.ID, "<>"); AMSChannelCollection channels = this.LoadRelativeChannels(eventData.ID); InSqlClauseBuilder channelIDBuilder = new InSqlClauseBuilder("EC.ChannelID"); channels.ForEach(c => channelIDBuilder.AppendItem(c.ID)); channelIDBuilder.AppendItem(eventData.ChannelID); if (additionalChannelID.IsNotEmpty()) { channelIDBuilder.AppendItem(additionalChannelID); } ConnectiveSqlClauseCollection connective = new ConnectiveSqlClauseCollection(LogicOperatorDefine.And, idBuilder, channelIDBuilder, connectiveTime); string sql = string.Format("SELECT TOP 1 * FROM {0} E INNER JOIN AMS.EventsChannels EC ON E.ID = EC.EventID WHERE {1}", this.GetTableName(), connective.ToSqlString(TSqlBuilder.Instance)); return(this.QueryData(sql).FirstOrDefault() != null); }
public void UpdateAllChannelsWithExistsData() { AMSChannelSqlAdapter.Instance.ClearAll(); AMSChannelSqlAdapter.Instance.InitChannels(); AMSChannelCollection channels = LiveChannelManager.GetAllChannels(true); AMSChannelSqlAdapter.Instance.UpdateAllChannels(channels); AMSChannelCollection channelsLoaded = LiveChannelManager.GetAllChannels(true); Output(channelsLoaded); Assert.AreEqual(channels.Count, channelsLoaded.Count); }
/// <summary> /// 获取所有的频道信息。从数据库中读取,同时和配置文件中的频道合并。 /// 配置文件中不存在的,则标志为Disabled。 /// </summary> /// <param name="mergeInfoFromCloud">是否从云端同步状态</param> /// <returns></returns> public static AMSChannelCollection GetAllChannels(bool mergeInfoFromCloud = false) { AMSChannelCollection channelsInDB = ContractManager.GetAMSChannelAdapter().GetAllChannels(); //AMSChannelCollection channelsFromConfig = GetChannelsFromConfig(); //if (mergeInfoFromCloud) // FillChannelsInfoFromCloud(channelsFromConfig); if (mergeInfoFromCloud) { FillChannelsInfoFromCloud(channelsInDB); } //return channelsInDB.MergeFrom(channelsFromConfig); return(channelsInDB.MergeFrom(channelsInDB)); }
private void BindRelativeChannels() { if (this.Event != null) { AMSChannelCollection channels = AMSEventSqlAdapter.Instance.LoadRelativeChannels(this.Event.ID); this.channels.DataSource = channels; this.channels.DataValueField = "ID"; this.channels.DataTextField = "Name"; this.channels.DataBind(); this.channels.Visible = channels.Count > 1; if (this.Channel != null) { this.channels.Value = this.Channel.ID; } } }
private static void FillChannelsInfoFromCloud(AMSChannelCollection channels) { Dictionary <string, AMSChannelCollection> cloundAMSInfo = new Dictionary <string, AMSChannelCollection>(StringComparer.OrdinalIgnoreCase); foreach (AMSChannel target in channels) { AMSChannelCollection channelsInContext = null; if (cloundAMSInfo.TryGetValue(target.AMSAccountName, out channelsInContext) == false) { CloudMediaContext context = MediaServiceAccountSettings.GetConfig().Accounts.GetCloudMediaContext(target.AMSAccountName); if (context != null) { channelsInContext = context.Channels.ToAMSChannels(); cloundAMSInfo.Add(target.AMSAccountName, channelsInContext); } } if (channelsInContext != null) { AMSChannel channelInCloud = null; if (target.AMSID.IsNotEmpty()) { channelInCloud = channelsInContext.FindChannelByAMSID(target.AMSID); } else if (target.Name.IsNotEmpty()) { channelInCloud = channelsInContext.FindChannelByName(target.Name); } if (channelInCloud != null) { target.FillStatusFromCloud(channelInCloud); } } } }
public static void GenerateStopChannelMessages(CancellationToken cancellationToken) { AMSWorkerSettings settings = AMSWorkerSettings.GetConfig(); AMSChannelCollection channels = AMSChannelSqlAdapter.Instance.LoadNeedStopChannels(settings.Durations.GetDuration("stopChannelLeadTime", TimeSpan.FromHours(1))); AMSQueueItemCollection messages = new AMSQueueItemCollection(); foreach (AMSChannel channel in channels) { AMSQueueItem message = new AMSQueueItem(); message.ItemType = AMSQueueItemType.StopChannel; message.ResourceID = channel.ID; message.ResourceName = channel.Name; messages.Add(message); } GetQueue().AddMessages(string.Empty, messages.ToArray()); }
/// <summary> /// 从配置文件中读取频道信息 /// </summary> /// <returns></returns> private static AMSChannelCollection GetChannelsFromConfig() { MediaServiceAccountSettings accountSettings = MediaServiceAccountSettings.GetConfig(); AMSChannelCollection channels = new AMSChannelCollection(); foreach (LiveChannelConfigurationElement channelElem in LiveChannelSettings.GetConfig().Channels) { if (accountSettings.Accounts.ContainsKey(channelElem.AccountName)) { AMSChannel channel = new AMSChannel(); channel.ID = UuidHelper.NewUuidString(); channel.Name = channelElem.ChannelName; channel.Description = channelElem.Description; channel.AMSAccountName = channelElem.AccountName; channels.Add(channel); } } return(channels); }