public void AddOpenText(int code, [FromBody] OpenTextInput input) { if (DatabaseContext.Active.Sessions.TryGetValue(code, out AdminInstance admin)) { ThreadPool.QueueUserWorkItem(o => admin.AddClientInput(input)); } }
/// <summary> /// This method is how users add new key /// </summary> /// <param name="input">The Input the user sent us.</param> public void AddUserInput(OpenTextInput input) { lock (ThreadLock) { Groups[0].Members.Add(input); UpdateMemberIndexes(0); } EventStream(); }
/// <summary> /// Switches the group of a specified index /// </summary> /// <param name="key">The Input-Key to the key you want moved</param> /// <param name="targetGroup">The Index of the Group you want the key moved to</param> public void SwitchGroup(Key key, int targetGroup) { lock (ThreadLock) { if (key.Group >= Groups.Count || key.Member >= Groups[key.Group].Members.Count || targetGroup >= Groups.Count) { return; } //Grab the Input we want moved OpenTextInput input = Groups[key.Group].Members[key.Member]; //Update the Index of the Input input.Index = Groups[targetGroup].Members.Count; //Add it to the desired group Groups[targetGroup].Members.Add(input); { //Check if this is in favorites string str = $"{key.Group}-{key.Member}"; if (FavoriteMembers.Contains(str)) { FavoriteMembers.Remove(str); str = $"{targetGroup}-{input.Index}"; FavoriteMembers.Add(str); } } //Remove it from its old location Groups[key.Group].Members.RemoveAt(key.Member); //Remove the Group if it is empty if (key.Group != 0 && Groups[key.Group].Members.Count < 1) { { //Check if this is in favorites if (FavoriteGroups.Contains(key.Group)) { FavoriteGroups.Remove(key.Group); } } Groups.RemoveAt(key.Group); UpdateGroupIndexes(); } else //Otherwise update the Member Indexes { UpdateMemberIndexes(key.Group); } } EventStream(); }
private void ArchiveInput(Key member) { //Grab the Input we want moved OpenTextInput input = Groups[member.Group].Members[member.Member]; { //Check if this is in favorites string str = $"{member.Group}-{member.Member}"; if (FavoriteMembers.Contains(str)) { FavoriteMembers.Remove(str); } } //Remove it from its old location Groups[member.Group].Members.RemoveAt(member.Member); input.Index = Archive.Count; Archive.Add(input); }
/// <summary> /// Adds another option to the vote /// </summary> /// <param name="input">A Open Text input, that is converted into a option</param> public void AddOption(OpenTextInput input) { lock (ThreadLock) { MultipleChoiceOption option = new MultipleChoiceOption { Archive = new List <MultipleChoiceVote>(), Votes = new List <MultipleChoiceVote>(), Description = input.Description, UserID = input.UserID //Title = input.Title, }; Options.Add(option); } EventStream(); }
public void SwitchGroup(IEnumerable <Key> keys, int target) { if (target >= Groups.Count) { return; } foreach (Key key in keys) { if (key.Group == target || key.Group >= Groups.Count || key.Member >= Groups[key.Group].Members.Count) { continue; } //Grab the Input we want moved OpenTextInput input = Groups[key.Group].Members[key.Member]; //Update the Index of the Input input.Index = Groups[target].Members.Count; lock (ThreadLock) { { //Check if this is in favorites string str = $"{key.Group}-{key.Member}"; if (FavoriteMembers.Contains(str)) { FavoriteMembers.Remove(str); str = $"{target}-{input.Index}"; FavoriteMembers.Add(str); } } //Remove it from its old location Groups[key.Group].Members.RemoveAt(key.Member); //Add it to the desired group Groups[target].Members.Add(input); } } for (int i = 1; i < Groups.Count; i++) { if (Groups[i].Members.Count < 1) //TODO: Keep Previously Empty Groups? { int prev = Groups[i].Column; { //Check if this is in favorites if (FavoriteGroups.Contains(i)) { FavoriteGroups.Remove(i); } } Groups.RemoveAt(i); if (Groups.All(check => check.Column != prev)) { RemoveColumn(prev); } i--; } } UpdateGroupIndexes(); foreach (OpenTextGroup group in Groups) { lock (ThreadLock) { UpdateMemberIndexes(group.Index); } } EventStream(); }
/// <summary> /// Merges two inputs into one another /// </summary> /// <param name="parent">This is the key that will still be visible</param> /// <param name="child">This key will be hidden inside parent</param> public void Merge(Key parent, Key child) { lock (ThreadLock) { if (parent.Group >= Groups.Count || parent.Member >= Groups[parent.Group].Members.Count || child.Group >= Groups.Count || child.Member >= Groups[child.Group].Members.Count) { return; } //Check if parent is already merged with something if (Groups[parent.Group].Members[parent.Member] is OpenTextMerged mergedParent) { //Check if child is merged with something if (Groups[child.Group].Members[child.Member] is OpenTextMerged mergedChild) { //Separate the child from all the grand-kids(The child's children) OpenTextInput singleChild = new OpenTextInput { Description = mergedChild.Description, Title = mergedChild.Title, UserID = mergedChild.UserID }; //Gather the grand-kids List <OpenTextInput> grandKids = mergedChild.Children; //Add child and all grand-kids to parent mergedParent.Children.Add(singleChild); foreach (OpenTextInput kid in grandKids) { mergedParent.Children.Add(kid); } } else { //Add the Child to parent mergedParent.Children.Add(Groups[child.Group].Members[child.Member]); } //Check if this is in favorites string str = $"{child.Group}-{child.Member}"; if (FavoriteMembers.Contains(str)) { FavoriteMembers.Remove(str); str = $"{parent.Group}-{parent.Member}"; FavoriteMembers.Add(str); } //Remove the child from its old location Groups[child.Group].Members.RemoveAt(child.Member); UpdateMemberIndexes(child.Group); } else { //Make parent into a merged Input OpenTextMerged merge = new OpenTextMerged { Children = new List <OpenTextInput>(), Description = Groups[parent.Group].Members[parent.Member].Description, Title = Groups[parent.Group].Members[parent.Member].Title, UserID = "Multiple Users", Index = Groups[parent.Group].Members[parent.Member].Index }; //Add Parent as the first child merge.Children.Add(Groups[parent.Group].Members[parent.Member]); //Check if child is merged with something if (Groups[child.Group].Members[child.Member] is OpenTextMerged mergedChild) { //Separate the child from all the grand-kids(The child's children) OpenTextInput singleChild = new OpenTextInput { Description = mergedChild.Description, Title = mergedChild.Title, UserID = mergedChild.UserID }; //Gather the grand-kids List <OpenTextInput> grandKids = mergedChild.Children; //Add child and all grand-kids to parent merge.Children.Add(singleChild); foreach (OpenTextInput kid in grandKids) { merge.Children.Add(kid); } } else { //Add child to new parent merge.Children.Add(Groups[child.Group].Members[child.Member]); } //Check if this is in favorites string str = $"{child.Group}-{child.Member}"; if (FavoriteMembers.Contains(str)) { FavoriteMembers.Remove(str); str = $"{parent.Group}-{parent.Member}"; FavoriteMembers.Add(str); } Groups[child.Group].Members.RemoveAt(child.Member); Groups[parent.Group].Members[parent.Member] = merge; UpdateMemberIndexes(child.Group); } } EventStream(); }