public static void SaveSetting(string machineName, string applicationName, string groupName, string name, string value, string tag) { machineName = machineName ?? PlayoutDbContext.DefaultName; applicationName = applicationName ?? PlayoutDbContext.DefaultName; using (var context = new PlayoutDbContext()) { var scope = context.SettingScopes.Single(i => i.MachineName == machineName && i.ApplicationName == applicationName); groupName = groupName ?? PlayoutDbContext.DefaultName; var dbEntity = context.Settings.SingleOrDefault(s => s.ScopeId == scope.Id && s.Name == name && s.GroupName == groupName); if (dbEntity != null) { dbEntity.Value = value; dbEntity.Tag = tag; } else { var setting = new SettingInfo { ScopeId = scope.Id, GroupName = groupName, Name = name, Value = value, Tag = tag }; context.Settings.Add(setting); } context.SaveChanges(); } }
public static void DeleteMediaFile(MediaFileEntity entity, string applicationName, Guid userId, string userName) { using (var context = new PlayoutDbContext()) { var item = context.MediaFiles.SingleOrDefault(i => i.Id == entity.Id); if (item != null) { item.Deleted = true; item.DeleteTime = DateTime.Now; var action = new UserAction(); action.ApplicationName = applicationName; action.Category = UserActionCategory.Remove; //action.Data= action.Description = string.Format("素材ID:{3}, 标题:{0},原始文件名:{1},时长:{2}。", entity.Title, entity.OriginalFileName, TimeSpan.FromSeconds(entity.Duration), entity.Id); action.Name = "删除素材"; //action.Tag = ""; action.UserId = userId; action.UserName = userName; context.UserActions.Add(action); context.SaveChanges(); } } }
public static void AddMediaFile(MediaFileEntity entity, string applicationName, Guid userId, string userName) { using (var context = new PlayoutDbContext()) { entity.CreatorId = userId; entity.OriginalFileName = System.IO.Path.GetFileName(entity.OriginalFileName); context.MediaFiles.Add(entity); var action = new UserAction(); action.ApplicationName = applicationName; action.Category = UserActionCategory.Add; //action.Data= action.Description = string.Format("标题:{0},原始文件名:{1},时长:{2}。", entity.Title, entity.OriginalFileName, TimeSpan.FromSeconds(entity.Duration)); action.Name = "导入素材"; //action.Tag = ""; action.UserId = userId; action.UserName = userName; context.UserActions.Add(action); context.SaveChanges(); } }
public static void Save(IEnumerable <ChannelInfo> newItems, List <ChannelInfo> updatedItems, List <ChannelInfo> removeItems) { using (var context = new PlayoutDbContext()) { //var allItems = context.ChannelInfos.ToArray(); foreach (var item in newItems) { context.ChannelInfos.Add(item); } foreach (var item in updatedItems) { context.Entry(item).State = EntityState.Modified; } foreach (var item in removeItems) { context.Entry(item).State = EntityState.Deleted; } try { context.SaveChanges(); } catch (Exception ex) { } } }
public static Guid AddPlayRecord(PlayRecord playRecord) { using (var context = new PlayoutDbContext()) { context.PlayRecords.Add(playRecord); context.SaveChanges(); return(playRecord.Id); } }
public static void SavePlaybill(PlaybillEntity billEntity, IList <PlayItemEntity> playItemEntities, IUser currentUser) { // NOTE:节目单时间冲突验证是通过数据库触发器来实现的。 using (var context = new PlayoutDbContext()) { if (billEntity.PlaybillItems != null) { billEntity.PlaybillItems.Clear(); } else { billEntity.PlaybillItems = new List <PlaybillItemEntity>(); } PlaybillEntity entity = billEntity; if (entity.Id != Guid.Empty) { context.Database.ExecuteSqlCommand("delete from PlaybillItems where PlaybillId=@p0", billEntity.Id); entity = context.Playbills.SingleOrDefault(i => i.Id == billEntity.Id); if (entity == null) { return; } entity.PlaybillItems = new List <PlaybillItemEntity>(); entity.StartTime = billEntity.StartTime; entity.Duration = billEntity.Duration; entity.LastEditorId = currentUser.Id; } else { entity.CreatorId = currentUser.Id; entity.LastEditorId = currentUser.Id; context.Playbills.Add(entity); } for (int i = 0; i < playItemEntities.Count; i++) { var playItemEntity = playItemEntities[i]; if (!entity.PlaybillItems.Contains(playItemEntity.PlaybillItem)) { playItemEntity.PlaybillItem.Playbill = entity; entity.PlaybillItems.Add(playItemEntity.PlaybillItem); } context.PlayItems.Add(playItemEntity); } // TODO: add action context.SaveChanges(); if (billEntity.Id == Guid.Empty) { billEntity.Id = entity.Id; } } }
public static void AddAction(UserAction action) { //action.CreationTime = DateTime.Now; using (var context = new PlayoutDbContext()) { context.UserActions.Add(action); context.SaveChanges(); } }
public static void Save(IEnumerable <BMDSwitcherInfo> newItems, List <BMDSwitcherInfo> updatedItems, List <BMDSwitcherInfo> removeItems, Func <BMDSwitcherInfo, IEnumerable <BMDSwitcherInputInfo> > factory) { using (var context = new PlayoutDbContext()) { var allItems = context.BMDSwitchers.ToArray(); foreach (var item in newItems) { context.BMDSwitchers.Add(item); foreach (var inputItem in factory(item)) { item.InputInfos.Add(inputItem); } } foreach (var item in updatedItems) { var updateItem = allItems.SingleOrDefault(i => i.Id == item.Id); if (updateItem != null) { updateItem.Name = item.Name; updateItem.Address = item.Address; } } foreach (var item in removeItems) { var removeItem = allItems.SingleOrDefault(i => i.Id == item.Id); if (removeItem != null) { context.BMDSwitchers.Remove(removeItem); } } context.SaveChanges(); } }
public static void Save(Guid switcherId, IEnumerable <BMDSwitcherInputInfo> switcherInputInfos) { using (var context = new PlayoutDbContext()) { var dbEntities = context.BMDSwitchers.Include("InputInfos") .Single(i => i.Id == switcherId).InputInfos; // context.BMDSwitcherInputs.Where(i=>i.SwitcherId==switcherId).ToArray(); foreach (var info in switcherInputInfos) { var dbEntity = dbEntities.SingleOrDefault(i => i.Id == info.Id); if (dbEntity != null && dbEntity.ChannelId != info.ChannelId) { dbEntity.ChannelId = info.ChannelId; } } try { context.SaveChanges(); } catch (Exception ex) { } } }
public static void Register(string machineName, string applicationName) { using (var context = new PlayoutDbContext()) { bool changed = false; var machines = context.Machines.ToList(); var machine = machines.SingleOrDefault(m => m.Name == machineName); MachineInfo newMachine = null; if (machine == null) { newMachine = new MachineInfo { Name = machineName }; context.Machines.Add(newMachine); foreach (var app in context.Applications) { context.SettingScopes.Add(new SettingScope { ApplicationName = app.Name, MachineName = machineName }); } changed = true; } var application = context.Applications.SingleOrDefault(a => a.Name == applicationName); if (application == null) { context.Applications.Add(new ApplicationInfo { Name = applicationName }); bool found = false; foreach (var mac in context.Machines.Local) { if (mac == newMachine) { found = true; } context.SettingScopes.Add(new SettingScope { ApplicationName = applicationName, MachineName = mac.Name }); } if (newMachine != null && !found) { Debug.WriteLine("未发现新的MachineName"); context.SettingScopes.Add(new SettingScope { ApplicationName = applicationName, MachineName = machineName }); } else { Debug.WriteLine("已发现新的MachineName"); } changed = true; } if (changed) { context.SaveChanges(); } } }