1. system idle time judgment
An automatic login and logout function is required. When you move the mouse or enter the keyboard, the user is deemed to be online. Otherwise, the user exits automatically after the set time. Fortunately, the predecessors left such a class:
Mousekeyboardoperate:
Using system; using system. runtime. interopservices; namespace SCADA. RTDB. framework. helpers {// <summary> // class mousekeyboardoperate // </Summary> public class mousekeyboardoperate {// <summary> // create a struct to return the capture time/ // </Summary> layoutkind. sequential is used to force members to be laid out in the order in which they appear. [Structlayout (layoutkind. sequential)] struct lastinputinfo {// <summary> /// set the capacity of the struct block /// </Summary> the delealas attribute instructs you how to mail data between hosted and unmanaged code. [Financialas (unmanagedtype. u4)] public int cbsize; // <summary> // capture time /// </Summary> [financialas (unmanagedtype. u4)] public uint dwtime;} static lastinputinfo vlastinputinfo; Public mousekeyboardoperate () {vlastinputinfo = new lastinputinfo ();} [dllimport ("user32.dll")] private Static extern bool getlastinputinfo (ref lastinputinfo plii); // <summary> // get the time when no operation is performed on the keyboard or mouse /// </Summary> /// <RET Urns> the time interval from the last time the user used the system, in seconds </returns> Public static long getlastinputtime () {// lastinputinfo vlastinputinfo = new lastinputinfo (); vlastinputinfo. cbsize = marshal. sizeof (vlastinputinfo); If (! Getlastinputinfo (ref vlastinputinfo) {return 0;} else {Long Count = environment. tickcount-(long) vlastinputinfo. dwtime; long icount = count/1000; return icount ;}}}}
Call mousekeyboardoperate. getlastinputtime () to obtain the number of seconds currently idle. If you move the mouse or enter this value on the keyboard, the value will change to 0 immediately.
Ii. Name verification.
When the name set of a model object, we need to verify its validity. It cannot contain special characters or begin with a number.
public class NameValidationHelper { public static bool IsValidIdentifierName(string name) { // Grammar: // <identifier> ::= <identifier_start> ( <identifier_start> | <identifier_extend> )* // <identifier_start> ::= [{Lu}{Ll}{Lt}{Lo}{Nl}(‘_‘)] // <identifier_extend> ::= [{Mn}{Mc}{Lm}{Nd}] UnicodeCategory uc; for (int i = 0; i < name.Length; i++) { uc = Char.GetUnicodeCategory(name[i]); bool idStart = (uc == UnicodeCategory.UppercaseLetter || // (Lu) uc == UnicodeCategory.LowercaseLetter || // (Ll) uc == UnicodeCategory.TitlecaseLetter || // (Lt) uc == UnicodeCategory.OtherLetter || // (Lo) uc == UnicodeCategory.LetterNumber || // (Nl) name[i] == ‘_‘); bool idExtend = (uc == UnicodeCategory.NonSpacingMark || // (Mn) uc == UnicodeCategory.SpacingCombiningMark || // (Mc) uc == UnicodeCategory.ModifierLetter || // (Lm) uc == UnicodeCategory.DecimalDigitNumber); // (Nd) if (i == 0) { if (!idStart) { return false; } } else if (!(idStart || idExtend)) { return false; } } return true; } }
Call isvalididentifiername for verification.
3. Get the special folder path
String mydesktop = environment. getfolderpath (environment. specialfolder. desktop );
Environment defines many specialized paths. Can be obtained directly.