public static AppElement[] GetAppElements(AppGroup group) { switch (group.Name) { case GroupNameMediaCenters: return(new[] { new AppElement("Emby"), new AppElement("Kodi"), new AppElement("Media Portal"), new AppElement("Plex") }); case GroupNameOnlineStreamingServices: return(new[] { new AppElement("Netlfix"), new AppElement("Amazon Prime"), new AppElement("ARD Mediathek"), new AppElement("ZDF Mediathek"), new AppElement("RTL Now"), new AppElement("Vox Now") }); case GroupNameGamingPortals: return(new[] { new AppElement("Steam"), new AppElement("Origin"), new AppElement("EmulationStation") }); } return(null); }
public void AddAppInfo(AppGroup appGroup, AppType appType) { if (appType != null) { appGroup.CreateNewAppInfo(appType); } }
public static AppGroup Load(string appDataPath) { var sett = new XmlReaderSettings(); sett.IgnoreWhitespace = true; sett.IgnoreComments = true; if (!File.Exists(appDataPath)) { return(null); } var result = new AppGroup(); using (XmlReader reader = XmlReader.Create(appDataPath, sett)) { reader.ReadStartElement("AppGroup"); reader.ReadStartElement("AppTypes"); while (reader.IsStartElement()) { result.AppTypes.Add(ReadAppType(reader)); } reader.ReadEndElement(); reader.ReadStartElement("LastAppInfoID"); result.LastAppInfoID = reader.ReadContentAsInt(); reader.ReadEndElement(); reader.ReadEndElement(); } return(result); }
public static void Save(string xmlPath, AppGroup appGroup) { XmlWriterSettings sett = new XmlWriterSettings(); sett.Indent = true; using (XmlWriter writer = XmlWriter.Create(xmlPath, sett)) { //writer.Settings.NewLineHandling = NewLineHandling. writer.WriteStartElement("AppGroup"); writer.WriteStartAttribute("Name"); writer.WriteValue(appGroup.AppGroupName ?? String.Empty); writer.WriteEndAttribute(); writer.WriteStartAttribute("LastAppInfoID"); writer.WriteValue(appGroup.LastAppInfoID); writer.WriteEndAttribute(); foreach (var item in appGroup.AppTypes) { WriteAppType(writer, item); } writer.WriteEndElement(); } }
public List <AppGroup> GetAllGroups() { List <AppGroup> allGroups = new List <AppGroup>(); SqlConnection con = null; try { con = connect(false); string query = "select * from AppGroup"; SqlCommand cmd = new SqlCommand(query, con); SqlDataReader sdr = cmd.ExecuteReader(); while (sdr.Read()) { AppGroup ag = new AppGroup(); ag.GroupID = (int)sdr["groupID"]; ag.GroupName = Convert.ToString(sdr["groupName"]); ag.GroupImg = Convert.ToString(sdr["groupImg"]); allGroups.Add(ag); } return(allGroups); } catch (Exception exp) { throw (exp); } finally { con.Close(); } }
public void InsertAppType(AppGroup appGroup, AppType addAppType, AppType beforeAppType) { if (appGroup == null) { return; } if (addAppType == null) { return; } if (beforeAppType == null) { appGroup.AppTypes.Insert(0, addAppType); return; } int ix = appGroup.AppTypes.IndexOf(beforeAppType); if (ix >= 0) { foreach (var item in addAppType.AppInfos) { PrepareItem(item); } appGroup.AppTypes.Insert(ix, addAppType); } }
public int UpdateGroupName(AppGroup appGroup) { SqlConnection con = null; SqlCommand cmd; try { con = connect(false); string str = "update AppGroup " + $"set groupName = '{appGroup.GroupName}' " + $"where groupId = {appGroup.GroupID}"; cmd = new SqlCommand(str, con); return(cmd.ExecuteNonQuery()); } catch (Exception ex) { return(0); throw (ex); } finally { if (con != null) { con.Close(); } } }
public int AddUsers2UserInGroup(AppGroup appGroup) { SqlConnection con = null; SqlCommand cmd; try { con = connect(false); string query = ""; foreach (var p in appGroup.Participiants) { query += $"exec spAddUser2UserInGroup @providedUserID={p.UserID}, @providedGroupID={appGroup.GroupID}\r\n"; } cmd = new SqlCommand(query, con); return(cmd.ExecuteNonQuery()); } catch (Exception exp) { throw exp; } finally { con.Close(); } }
public void FindApp(AppGroup appGroup, string appNamePart) { if (_QuickSearchWnd == null) { _QuickSearchWnd = new QuickSearch(); _QuickSearchWnd.Owner = _WorkItem.MainWindow; _QuickSearchWnd.WindowStartupLocation = WindowStartupLocation.CenterOwner; _QuickSearchWnd.SearchString = appNamePart; _QuickSearchWnd.SerachStringChanged += (s, e) => FindApp(appGroup, _QuickSearchWnd.SearchString); _QuickSearchWnd.Closed += (s, e) => EndSearch(); _QuickSearchWnd.ItemSelected += (s, e) => SearchSucceded(); //_QuickSearchWnd.FoundItems = appGroup.FindApps(appNamePart); _QuickSearchWnd.Show(); _SearchTimer.IsEnabled = true; } else { _SearchTimer.Stop(); _SearchTimer.Start(); //var apps = _QuickSearchWnd.FoundItems as AppInfoCollection; var apps = appGroup.FindApps(appNamePart); if (apps != null) { _QuickSearchWnd.FoundItems = apps; } } }
private async Task <bool> InitializeGroup() { var app = await _appService.GetApplicationByName(DefaultApplication); if (!app.HasData) { return(false); } var superAdmin = new AppGroup() { Name = SystemDefaultGroups.SuperAdmin.ToString(), Description = "Group Super Admin", ApplicationId = app.Object.Id }; var admin = new AppGroup() { Name = SystemDefaultGroups.Admin.ToString(), Description = "Group for Admin", ApplicationId = app.Object.Id }; var viewer = new AppGroup() { Name = SystemDefaultGroups.DefaultUser.ToString(), Description = "Group for Viewer", ApplicationId = app.Object.Id }; await _groupService.AddNewGroup(superAdmin); await _groupService.AddNewGroup(admin); await _groupService.AddNewGroup(viewer); return(true); }
public void Update(AppGroup appGroup) { if (_appGroupRepository.CheckContains(x => x.Name == appGroup.Name && x.Id != appGroup.Id)) { throw new NameDuplicatedException("Tên không được trùng"); } _appGroupRepository.Update(appGroup); }
public AppGroup Add(AppGroup appGroup) { if (_appGroupRepository.CheckContains(x => x.Name == appGroup.Name)) { throw new NameDuplicatedException("Tên không được trùng"); } return(_appGroupRepository.Add(appGroup)); }
public IActionResult Create([FromBody] CreateUserGroupModel model) { if (!_currentUser.HasRole(Permission.UserAccountAdmin)) { return(Forbidden()); } _logger.LogInformation("Creating a new user group: {0}", model.Name); _logger.LogDebug("Request body: {0}", JsonSerializer.Serialize(model)); Result <string> name = ((Maybe <string>)model.Name) .ToResult("User group name is not specified") .OnSuccess(d => d.Trim()) .Ensure(d => d.Length >= 5, "User group name is too short") .Ensure(d => d.Length <= 50, "User group name is too long") .Ensure(d => new Regex(@"^([a-zA-Z0-9 ])*$", RegexOptions.CultureInvariant, TimeSpan.FromSeconds(2)).IsMatch(d) , "User group contains invalid characters"); Result <string> description = ((Maybe <string>)model.Description) .ToResult("User group description is not specified") .OnSuccess(d => d.Trim()) .Ensure(d => d.Length <= 250, "User group name is too long"); Result result = Result.Combine(name, description); if (result.IsFailure) { return(Error(result.Error)); } if (_groupRepo.HasGroup(name.Value)) { return(Error("Specified user group already exist")); } AppGroup group = new AppGroup(name.Value, description.Value); model.SelectedPermissions ??= new string[] { }; if (model.SelectedPermissions.Any()) // has selected permissions { Result <List <AppPermission> > selectedPermissions = GetMatchingPermissions(_permissionRepo, model.SelectedPermissions); if (selectedPermissions.IsFailure) { return(Error(selectedPermissions.Error)); } group.AddPermissions(selectedPermissions.Value); } _groupRepo.Insert(group); return(Ok("User group added")); }
public async Task <OutResult> AddUserToGroup(AppUser user, AppGroup group) { var groupUser = new GroupUser() { UserId = user.Id, GroupId = group.Id, User = user, Group = group }; return(await _groupUserRepository.Insert(groupUser)); }
protected void CleanStatistic(AppGroup apps) { var statPeriod = DateTime.Now.AddMonths(-_WorkItem.Settings.StatisticPeriod); foreach (var appTypes in apps.AppTypes) { foreach (var item in appTypes.AppInfos) { item.RunHistory.DeleteAll(s => s.RunTime < statPeriod); } } }
public AppStatCollection(AppGroup apps) { foreach (var appType in apps.AppTypes) { foreach (var item in appType.AppInfos) { Add(new AppStat(item)); } } NormalizeRuns(); }
public AppGroup PostAppGroup(AppGroup appGroup) { SqlConnection con = null; SqlCommand cmd; try { con = connect(false); string str = "DECLARE @LastGroupID int;" + $"insert into AppGroup (groupName) values('{appGroup.GroupName}')" + "select @LastGroupID = SCOPE_IDENTITY();" + "insert into UserInGroup (userID, groupID, isAdmin) values " + $"({appGroup.UserID},@LastGroupID,1)"; foreach (var user in appGroup.Participiants) { str += $",({user.UserID},@LastGroupID,0)"; } str += "select @LastGroupID"; cmd = new SqlCommand(str, con); appGroup.GroupID = Convert.ToInt32(cmd.ExecuteScalar()); con.Close(); con = connect(false); str = $"select userName from AppUser where userID = {appGroup.UserID}"; cmd = new SqlCommand(str, con); SqlDataReader sdr = cmd.ExecuteReader(); AppUser admin = new AppUser(); if (sdr.Read()) { admin.UserName = (string)sdr["userName"]; } admin.UserID = appGroup.UserID; admin.IsAdmin = true; appGroup.Participiants.Add(admin); return(appGroup); } catch (Exception ex) { throw (ex); } finally { if (con != null) { con.Close(); } } }
public AppType AddEmptyAppType(AppGroup appGroup, AppType beforeAppType) { var newAppType = new AppType() { AppTypeName = Strings.APPLICATIONS }; InsertAppType( appGroup, newAppType, beforeAppType); return(newAppType); }
public void AddScned(AppGroup appGroup, IEnumerable <AppInfo> list) { if (list == null) { return; } var appType = new AppType() { AppTypeName = appGroup.GetDefaultTypeName() }; appGroup.AppTypes.Add(appType); appType.AppInfos.AddRange(list); appGroup.GroupByFolders(appType); }
protected void LoadData() { AppGroup apps = null; bool readNew = false; try { apps = AppGroupLoader.Load2( _WorkItem.DataPath, _WorkItem.StatPath); CleanStatistic(apps); readNew = true; //apps = XmlSerializeHelper.DeserializeItem( // _WorkItem.AppData.GetType(), // _WorkItem.DataPath) as AppGroup; } catch {; } if (!readNew) { try { apps = AppGroupLoader.Load(_WorkItem.DataPath); } catch {; } } _WorkItem.RecycleBin = AppGroupLoader.LoadRecycleBin(_WorkItem.RecycleBinPath); if (apps != null) { _WorkItem.AppData = apps; _WorkItem.AppData.CorrectAppInfoID(); } else { _WorkItem.AppData = new AppGroup(); _WorkItem.AppData.AppTypes.Add(new AppType() { AppTypeName = Strings.APPLICATIONS }); } }
public HttpResponseMessage Details(HttpRequestMessage request, int id) { if (id == 0) { return(request.CreateErrorResponse(HttpStatusCode.BadRequest, nameof(id) + " is required.")); } AppGroup appGroup = _appGroupService.GetDetail(id); var appGroupViewModel = Mapper.Map <AppGroup, AppGroupViewModel>(appGroup); appGroupViewModel.Roles = Mapper.Map <IEnumerable <AppRole>, IEnumerable <AppRoleViewModel> >(_appRoleService.GetListRoleByGroupId(id)); if (appGroup == null) { return(request.CreateErrorResponse(HttpStatusCode.NoContent, "No group")); } return(request.CreateResponse(HttpStatusCode.OK, appGroupViewModel)); }
public MainWorkItem() { AMSetttingsFactory.WorkItem = this; _Settings = AMSetttingsFactory.DefaultSettingsBag.Settings; _Commands = new AppCommands(this); _KbrdHook = new KeyboardHook(); //#if RELEASE //_MsHook = new MouseHook(); //#endif _ImageLoader = new AsyncImageLoader(); _MainWindow = new MainWindow(this); _TrayIcon = new WinForms.NotifyIcon(); _AppData = new AppGroup(); _RecycleBin = new DeletedAppCollection(); UpdateRunning = false; }
public void Init( MainWorkItem workItem, AppGroup appGroup, AppInfo appInfo, AppType appType, DeletedAppCollection deletedApps, AppStatCollection stat) { _AppGroup = appGroup; _Controller = new AppManagerController(workItem); AppTypes.ItemsSource = appGroup.AppTypes; _AppTypes = appGroup.AppTypes; AppTypeSelector.ItemsSource = appGroup.AppTypes; DeletedAppList.ItemsSource = deletedApps; _DeletedApps = deletedApps; StatList.ItemsSource = stat; //AppScanType.ItemsSource = appGroup.AppTypes; if (appInfo != null) { AppType selAppType = appGroup.FindAppType(appInfo); AppTypes.SelectedItem = selAppType; AppTypeSelector.SelectedItem = selAppType; _ItemToSelect = appInfo; AppList.SelectedItem = appInfo; AppTabs.SelectedIndex = 1; } if (appType != null) { AppType selAppType = appGroup.AppTypes.FindBySource(appType); AppTypes.SelectedItem = selAppType; AppTypeSelector.SelectedItem = selAppType; _ItemToSelect = appGroup.CreateNewAppInfo(selAppType); AppList.SelectedItem = _ItemToSelect; AppTabs.SelectedIndex = 1; } }
public void MoveType(AppGroup appGroup, AppType appType, bool up) { if (appGroup == null) { return; } if (appType == null) { return; } int ix = appGroup.AppTypes.IndexOf(appType); int ix2 = up ? ix - 1 : ix + 1; if (ix2 >= 0 && ix2 < appGroup.AppTypes.Count) { appGroup.AppTypes.Move(ix, ix2); } }
public ActionResult CreateGroup(CreateGroup model) { if (!ModelState.IsValid) { return(View(model)); } AppGroup group = new AppGroup() { Name = model.Name, InviteCode = "12310", Creator = new AppUser() { Id = Guid.Parse(User.Identity.GetUserId()) } }; groupRepository.Save(group); return(RedirectToAction("Index", "Home")); }
public static void SaveAppStat(string xmlPath, AppGroup appData) { XmlWriterSettings sett = new XmlWriterSettings(); sett.Indent = true; using (XmlWriter writer = XmlWriter.Create(xmlPath, sett)) { writer.WriteStartElement("AppStat"); foreach (var appType in appData.AppTypes) { foreach (var app in appType.AppInfos) { WriteAppStat(writer, app); } } writer.WriteEndElement(); } }
public void RestoreApp(AppGroup appGroup, DeletedAppCollection deletedApp, DeletedAppCollection recycleBin, AppType restore, string newAppTypeName) { if (deletedApp == null) { return; } if (newAppTypeName != null) { restore = new AppType() { AppTypeName = newAppTypeName }; appGroup.AppTypes.Add(restore); } for (int i = 0; i < deletedApp.Count; i++) { var item = deletedApp[i] as DeletedApp; var appTypeName = (item.DeletedFrom ?? restore).AppTypeName; var at = appGroup.FindAppType(appTypeName); if (at == null) { at = new AppType { AppTypeName = appTypeName }; appGroup.AppTypes.Add(at); } var ai = appGroup.CreateNewAppInfo( at, item.App.AppName, item.App.ExecPath, item.App.ImagePath); recycleBin.Remove(item); } }
public void AddAppType(AppGroup appGroup, AppType beforeAppType) { //if (appType == null) // return; InputBox input = new InputBox(Strings.ENTER_APP_TYPE_NAME); input.InputText = Strings.APPLICATIONS; input.Owner = _WorkItem.MainWindow; input.WindowStartupLocation = WindowStartupLocation.CenterOwner; if (input.ShowDialog() ?? false) { InsertAppType( appGroup, new AppType() { AppTypeName = input.InputText }, beforeAppType); } }
public void AddScned(AppGroup appGroup, AppType appType, string newAppTypeName, IEnumerable <AppInfo> list) { if (list == null) { return; } if (appType == null && newAppTypeName == null) { return; } if (newAppTypeName != null) { appType = new AppType() { AppTypeName = newAppTypeName }; appGroup.AppTypes.Add(appType); } appType.AppInfos.AddRange(list); }
public AppInfoCollection FindApps( IEnumerable <string> pathList, IEnumerable <string> extList, AppGroup appData, DeletedAppCollection recycleBin, bool excludeExisting, bool excludeBin) { var result = FindApps( pathList, extList, true); if (excludeExisting && result != null) { for (int i = result.Count - 1; i >= 0; i--) { if (appData.FindAppByExecPath(result[i].ExecPath) != null) { result.RemoveAt(i); } } } if (excludeBin && result != null) { for (int i = result.Count - 1; i >= 0; i--) { if (recycleBin.FindByApp(null, result[i]) != null) { result.RemoveAt(i); } } } return(result); }