/// <summary> /// Get all groups /// </summary> /// <returns></returns> public async Task <IReadOnlyCollection <Group> > GetGroupsAsync() { CheckInitialized(); HttpClient client = await GetHttpClient().ConfigureAwait(false); string stringResult = await client.GetStringAsync(new Uri(String.Format("{0}groups", ApiBase))).ConfigureAwait(false); List <Group> results = new List <Group>(); JToken token = JToken.Parse(stringResult); if (token.Type == JTokenType.Object) { //Each property is a light var jsonResult = (JObject)token; foreach (var prop in jsonResult.Properties()) { Group?newGroup = JsonConvert.DeserializeObject <Group>(prop.Value.ToString()); if (newGroup != null) { newGroup.Id = prop.Name; results.Add(newGroup); } } } return(results); }
public static bool Is(this CardStatus card, Group?group = null, CardType?type = null, Func <CardStatus, bool> filter = null, Faction?faction = null) { return((faction == null ? true : card.Faction == faction) && (group == null ? true : card.Group == group) && (filter == null ? true : filter(card)) && (type == null ? true : card.Type == type)); }
internal List <Group> GetGroupsByAlliance(int id) { using (MySqlConnection connection = connect()) { MySqlCommand query = new MySqlCommand("SELECT `id` FROM `groups` WHERE `alliance` = ?alliance;", connection); query.Prepare(); query.Parameters.Add("?alliance", id); using (MySqlDataReader reader = query.ExecuteReader()) { List <Group> result = new List <Group>(); while (reader.Read()) { Group?group = GetGroupById((int)(UInt32)reader["id"]); if (group != null) { result.Add((Group)group); } } return(result); } } }
internal List <Group> GetClosestGroupByName(string name) { using (MySqlConnection connection = connect()) { MySqlCommand query = new MySqlCommand("SELECT `id` FROM `groups` WHERE `name` LIKE ?name;", connection); query.Prepare(); query.Parameters.Add("?name", name); using (MySqlDataReader reader = query.ExecuteReader()) { if (!reader.HasRows) { return(null); } List <Group> result = new List <Group>(); while (reader.Read()) { Group?group = GetGroupById((int)(UInt32)reader["id"]); if (group != null) { result.Add((Group)group); } } return(result); } } }
public async Task <Person> UpdatePersonAsync( UpdatePersonRequest request, CancellationToken cancellationToken) { List <Guid> userGroups = request.Groups?.ToList() ?? new List <Guid>(); if (request.NewGroups is { } newGroupNames&& newGroupNames.Any()) { foreach (var newGroup in newGroupNames) { Group?group = await _groupService.AddAsync(newGroup, cancellationToken); userGroups.Add(group.Id); } } Person person = await _personStore.GetByIdAsnc(request.Id, cancellationToken); person.Name = request.Name; person.Groups = userGroups; person.ProfileFaceId = request.ProfileFaceId; person.DateOfBirth = request.DateOfBirth?.Date; await _personStore.UpdateAsync(person, cancellationToken); await _bus.Publish(new PersonUpdatedMessage(person.Id, "Update")); return(person); }
private static async Task HandleListCommand(string alias, string file, string password, string group, IConsole console) { string filepath = await ConsoleHelper.GetPwsFilePath(file, alias); if (!File.Exists(filepath)) { System.Console.Error.WriteLine($"Can't locate a valid file, please check your command parameters or configuration in ~/pwsafe.json"); return; } SecureString secureString = ConsoleHelper.GetSecureString(password); try { using FileStream stream = File.OpenRead(filepath); using MemoryStream ms = new MemoryStream(); stream.CopyTo(ms); ms.Position = 0; PwsFileV3 pwsFile = (PwsFileV3)await PwsFile.OpenAsync(ms, secureString); List <ItemData> items = await PwsFileHelper.ReadAllItemsFromPwsFileV3Async(pwsFile); Group rootGroup = Group.GroupItems(items); if (string.IsNullOrWhiteSpace(group)) { PrintGroup(rootGroup); } else { Group?subGroup = rootGroup.FindSubGroup(item => item.Path == group); if (subGroup is null) { System.Console.Error.WriteLine("No such group, {0}", group); } else { System.Console.WriteLine("Items ({0}):", subGroup.Items.Count); subGroup.Items.ForEach((item) => { System.Console.WriteLine(item.Title); }); System.Console.WriteLine("Groups ({0}):", subGroup.Groups.Count); subGroup.Groups.ForEach((item) => { System.Console.WriteLine(item.Name); }); } } pwsFile.Dispose(); } catch (Exception e) { System.Console.Error.WriteLine(e.Message); throw; } }
public void Setup() { _group = new Group(GroupType.Group); GroupAccess.Instance.Groups = new ConcurrentDictionary <long, Group>(); _group.GroupId = GroupAccess.Instance.GetNextGroupId(); }
public Group(string name, Group?parent = null) { if (string.IsNullOrWhiteSpace(name)) { throw new Exception("Invalid group name"); } this.name = name; this.parent = parent; }
public void EnsureIsGroupOwner(NaheulbookExecutionContext executionContext, Group?group) { if (group == null) { throw new ForbiddenAccessException(); } if (group.MasterId != executionContext.UserId) { throw new ForbiddenAccessException(); } }
public async Task <HueGroup> GetGroup(string id, CancellationToken cancellationToken) { Group?group = await _hueClient.GetGroupAsync(id); if (group == null) { throw new NotFoundException(id); } return(GroupMapper.Map(group)); }
public override async Task OnDisconnectedAsync(Exception exception) { Group?group = GroupManager.RemoveUser(Context.ConnectionId); if (group != null) { await Clients.Groups(group.GroupName).SendAsync(CallbackUsersChanged, group.UserChangeCount, group.Users.Select(a => a.Value).OrderBy(a => a).ToList()); } await base.OnDisconnectedAsync(exception); }
#pragma warning disable CS8614 // Nullability of reference types in type of parameter doesn't match implicitly implemented member. public bool TryGetValue(string key, [NotNullWhen(true)] out Group?value) #pragma warning restore CS8614 { Group group = this[key]; if (group == Group.s_emptyGroup) { value = null; return(false); } value = group; return(true); }
public User CreateUser(Group?group = null, string?name = null) { var faker = new Faker(); var user = new User() { Name = faker.Person.FullName, Groups = new List <Group>(), Id = Guid.NewGuid(), }; if (group != null) { user.Groups.Add(group); } return(user); }
public User CreateUser(Group?group = null, string?name = null, string?email = null, string?password = null) { var faker = new Faker(); var user = new User() { Name = name ?? faker.Person.FullName, Groups = new List <Group>(), Id = Guid.NewGuid(), Email = email ?? faker.Person.Email, Password = password ?? faker.Person.Email }; if (group != null) { user.Groups.Add(group); } return(user); }
/// <summary> /// Get the state of a single group /// </summary> /// <returns></returns> public async Task <Group?> GetGroupAsync(string id) { CheckInitialized(); HttpClient client = await GetHttpClient().ConfigureAwait(false); string stringResult = await client.GetStringAsync(new Uri(String.Format("{0}groups/{1}", ApiBase, id))).ConfigureAwait(false); //#if DEBUG // stringResult = "{ \"type\": null, \"action\": { \"on\": true, \"xy\": [0.5, 0.5] }, \"lights\": [ \"1\", \"2\" ], \"name\": \"bedroom\",}"; //#endif Group?group = DeserializeResult <Group>(stringResult); if (group != null && string.IsNullOrEmpty(group.Id)) { group.Id = id; } return(group); }
/// <summary> /// Create a new permission validator with the given options. /// </summary> /// <param name="partialInfo">The partial permission to validate.</param> /// <param name="group">The group of the permission.</param> /// <param name="options">The option containing default values.</param> public PermissionValidatorFilter(object partialInfo, Group?group, IOptionsMonitor <PermissionOption> options) { switch (partialInfo) { case Kind kind: _kind = kind; break; case string perm: _permission = perm; break; default: throw new ArgumentException($"{nameof(partialInfo)} can only be a permission string or a kind."); } if (group != null) { _group = group.Value; } _options = options; }
public static bool ValueBoolOrDefault(this Group?g, bool Default = false) => g is null || !g.Success || !bool.TryParse(g.Value, out var v) ? Default : v;
public static double ValuedDoubleOrDefault(this Group?g, IFormatProvider format, NumberStyles style = NumberStyles.Float, double Default = double.NaN) => g is null || !g.Success || !double.TryParse(g.Value, style, format, out var v) ? Default : v;
public static double ValuedDoubleOrDefault(this Group?g, double Default = double.NaN) => g is null || !g.Success || !double.TryParse(g.Value, out var v) ? Default : v;
public static int ValueIntOrDefault(this Group?g, int Default = 0) => g is null || !g.Success || !int.TryParse(g.Value, out var v) ? Default : v;
public static string?ValueOrDefault(this Group?g, string?Default = null) => g is null || !g.Success ? Default : g.Value;
/// <summary> /// Returns the scene that has been executed last for a group in a zone. /// </summary> /// <param name="zone">Zone ID</param> /// <param name="group">The target group</param> public async Task <LastCalledScenesResponse> GetLastCalledScene(Zone zone, Group?group = null) { return(await Load <LastCalledScenesResponse>(new Uri("/json/zone/getLastCalledScene", UriKind.Relative) .AddQuery("id", zone).AddQuery("groupID", group is null ? null : (int?)group ?? null))); }
public static Shader?FromStream(IGraphicsDevice graphicsDevice, Stream stream) { using StreamReader sr = new StreamReader(stream, Encoding.Default, true, 4096, true); if (!SHADER_DEFINITION.Equals(sr.ReadLine()?.Trim(), StringComparison.InvariantCultureIgnoreCase)) { return(null); } IList <Group> groups = new List <Group>(1); Group? currentGroup = null; string?line; while ((line = sr.ReadLine()?.Trim()) != null) { if (SHADER_DEFINITION_END.Equals(line, StringComparison.InvariantCultureIgnoreCase)) { break; } if (!s_emptyLineRegex.IsMatch(line)) { Match groupMatch = s_groupRegex.Match(line); if (groupMatch.Success) { groups.Add(currentGroup = new Group(groupMatch.Groups[1].Value)); continue; } Match shaderInfoMatch = s_shaderInfoRegex.Match(line); if (shaderInfoMatch.Success) { if (!Enum.TryParse(shaderInfoMatch.Groups[4].Value, out ShaderFlags flags)) { throw new InvalidDataException( $"shader flags '{shaderInfoMatch.Groups[4].Value}' one or more flags are invalid or unsupported."); } currentGroup?.Add( new ShaderInfo( shaderInfoMatch.Groups[1].Value, shaderInfoMatch.Groups[2].Value, shaderInfoMatch.Groups[3].Value, flags)); } } } string shaderSource = sr.ReadToEnd(); return(new Shader( groups.Select( t => { return (t.Name, t.ShaderInfos.Select( s => { using CompilationResult cr = ShaderBytecode.Compile( shaderSource, s.EntryPoint, s.Profile, s.Flags); if (cr.HasErrors) { throw new InvalidDataException(cr.Message); } return s.Type switch { "vs" => (Shader.Type.VertexShader, (ComObject) new VertexShader(graphicsDevice.Device, cr), ShaderSignature.GetInputSignature(cr), new ShaderReflection(cr)), "ps" => (Shader.Type.PixelShader, (ComObject) new PixelShader(graphicsDevice.Device, cr), ShaderSignature.GetInputSignature(cr), new ShaderReflection(cr)), "ds" => (Shader.Type.DomainShader, (ComObject) new DomainShader(graphicsDevice.Device, cr), ShaderSignature.GetInputSignature(cr), new ShaderReflection(cr)), "gs" => (Shader.Type.GeometryShader, (ComObject) new GeometryShader(graphicsDevice.Device, cr), ShaderSignature.GetInputSignature(cr), new ShaderReflection(cr)), "hs" => (Shader.Type.HullShader, (ComObject) new HullShader(graphicsDevice.Device, cr), ShaderSignature.GetInputSignature(cr), new ShaderReflection(cr)), "cs" => (Shader.Type.ComputeShader, (ComObject) new ComputeShader(graphicsDevice.Device, cr), ShaderSignature.GetInputSignature(cr), new ShaderReflection(cr)), _ => throw new InvalidDataException( $"shader type '{s.Type}' doesn't exists or is unsupported.") }; }) ); }))); }
/// <inheritdoc/> public bool Equals(Group?other) => other != null && base.Equals(other) && Elements.SequencedEquals(other.Elements);
public static IEnumerable <GameCard> FilterCards(this IEnumerable <GameCard> cards, Group?group = null, CardType?type = null, Func <GameCard, bool> filter = null, Faction?faction = null) { return(cards.Where(x => x.Is(group, type, filter, faction))); }