Hierarchy
In the previous episode, we divide the people who send the query message into "contact" and "stranger" categories, the application will automatically reply to "contact", ignoring "stranger", in this episode, we will introduce two other types: "Whitelist" and "blacklist". If you have seen the previous episode, you should know that "contacts" and "strangers" are mutually exclusive, and that the difference between them is whether the phone number exists in a contact. Whitelist and blacklist are the two types of subdivisions that are developed on contacts, and they are mutually exclusive, and whitelist allows all queries to be executed, while "blacklist" disables all queries. As for "strangers," we will give it a "sign-up" opportunity to request that it be added to the contact. These four levels will be expressed through the Accesslevel enumeration:
Code 1
In this episode, we will achieve the following effect on the basis of this "hierarchy":
Access level
Actions allowed
Whitelist
Pingstatus, Pingschedule
Contact
Pingstatus
Stranger
Signup
Blacklist
N/A
Whitelist & Blacklist
Because the whitelist and blacklist are essentially just two sets of names, we choose the simplest text file to store, one record at a line. The white list and blacklist management are handled by Whitelistmanager and Blacklistmanager respectively:
Figure 1
The task of reading/writing text files is given to ReadAllLines and Writealllines two methods:
Code 2
Because the whitelist and blacklist are mutually exclusive, so when we add a name to any list, we have to make sure that the name doesn't appear on another list, for example, when we add a name to the whitelist, if the name is already on the blacklist, remove the name from the blacklist first, Because we use BindingList, the check can be expanded when the ListChanged event is triggered:
Code 3
Next, we need two forms to edit whitelist and blacklist:
Figure 2
Is it 211.html ">" > think the two forms look familiar? In fact, they mimic the practice of status texts Editor (see "WM has about II (II): Continuous Improvement", figure 1), so this is not detailed here.
Finally, we need to place two menu items on the main form to open whitelist Editor and blacklist Editor:
Figure 3
Now, let's take a look at the run effect, at the beginning, the whitelist and blacklist are empty, we open whitelist Editor, click the Add button:
Figure 4
Click the ... button on the right side of the TextBox and the Choosecontactdialog dialog box opens:
Figure 5
When a contact is selected, the Choosecontactdialog dialog box closes, and the name of the selected contact appears in the textbox below Whitelist Editor:
Figure 6
Click OK to add the name to the whitelist and repeat the previous steps to add another contact:
Figure 7
Click the OK button in the upper-right corner of whitelist editor to close the form and save the whitelist. Next, open blacklist Editor and add Allen Lee to the blacklist by referring to the above steps:
Figure 8
Since whitelist and blacklist are mutually exclusive, then the whitelist should not have Allen Lee, open whitelist Editor Verify:
Figure 9
Continue >> Next [1th] [page 2nd] [3rd]