public string EnrollUser(string FPSerialNumber, string FirstName, string LastName, string template, bool bNotEnroll) { if (myFinger != null) { ReleaseFingerprint(); } // myFinger.SetTextBox("Request Enroll User :"******"{")) { fingerSerial = "{" + FPSerialNumber; } else { fingerSerial = FPSerialNumber; } if (!FPSerialNumber.Contains("}")) { fingerSerial += "}"; } Guid guid; if (!IsGuid(fingerSerial, out guid)) { return(null); } } FingerData newfinger = new FingerData(); UserClass TheUser = new UserClass(); if (!String.IsNullOrEmpty(template)) { BinaryFormatter bf = new BinaryFormatter(); MemoryStream mem = new MemoryStream(Convert.FromBase64String(template)); TheUser = (UserClass)bf.Deserialize(mem); } else { TheUser.firstName = FirstName; TheUser.lastName = LastName; } if (!bNotEnroll) { newfinger.CopyUserToFinger(TheUser); EnrollmentProcess Enroller = new EnrollmentProcess(fingerSerial, newfinger); Enroller.ShowDialog(); // process enrollment newfinger.CopyFingerToUser(TheUser); } BinaryFormatter bf2 = new BinaryFormatter(); MemoryStream mem2 = new MemoryStream(); bf2.Serialize(mem2, TheUser); return(Convert.ToBase64String(mem2.ToArray())); }
public int LoadFingerprintTemplates(string[] templates) { if (myFinger == null) { return(-1); } myFinger.SetTextBox("Request LoadFingerPrint :" + templates.Length, DateTime.Now); myFinger.UserList.Clear(); foreach (string data in templates) { if (data != null) { try { UserClass TheUser = new UserClass(); BinaryFormatter bf = new BinaryFormatter(); MemoryStream mem = new MemoryStream(Convert.FromBase64String(data)); TheUser = (UserClass)bf.Deserialize(mem); myFinger.UserList.Add(TheUser); int enrolledFinger = 0; for (int j = 0; j < TheUser.strFingerprint.Length; j++) { if (TheUser.strFingerprint[j] != null) { enrolledFinger++; } } myFinger.SetTextBox("Find :" + TheUser.firstName + " " + TheUser.lastName + " with " + enrolledFinger.ToString() + " enrolled finger(s) ", DateTime.Now); for (int i = 0; i < TheUser.strFingerprint.Length; i++) { if (TheUser.strFingerprint[i] != null) { FingerIndexValue fiv = (FingerIndexValue)i; myFinger.SetTextBox("Load :" + TheUser.firstName + " " + TheUser.lastName + " : " + fiv.ToString(), DateTime.Now); } } } catch (Exception exp) { string err = "Error during Deserialization : " + exp.Message; myFinger.SetTextBox(err + "\r\nFailed template : " + data, DateTime.Now); } } else { myFinger.SetTextBox("try to Load null template", DateTime.Now); } } myFinger.SetTextBox(myFinger.UserList.Count + " Templates loaded", DateTime.Now); return(myFinger.UserList.Count); }