public string scan(int hand, string id, string[] checks) { var retCode = new StringBuilder(); int count = 3; int offset = 0; if ((ErrorCode = _sc.fpsConnect()) != 0) { //var err = GetError(_sc); Disconnect(); throw new Exception("No device found"); //throw new Exception(err); } else { if (hand == 0) // only left hand { count = 1; offset = 0; } else if (hand == 1) // only right hand { count = 2; offset = 4; } else if (hand == 2) // only thumbs { count = 3; offset = 7; } else if (hand == 3) // all 10 fingers { hand = 0; count = 3; offset = 0; } for (int i = hand; i < count; i++, hand++) { if ((ErrorCode = scanFingers(i, checks)) != 0) { //var err = GetError(_sc); Disconnect(); throw new Exception("No fingers selected"); } for (int k = 0; k < 4; k++) { if (hand == 2 && k == 0) continue; if (_sc.ArrayOfWSQ[k] != null && ((WsqImage)_sc.ArrayOfWSQ[k]).Content != null) { _fingersCollection[k + offset] = _sc.ArrayOfWSQ[k]; if (hand == 0) retCode.Insert(0, '0'); else retCode.Append('0'); } else { //if (checks.Length > k && checks[k] == "1") if (hand == 0) retCode.Insert(0, '1'); else retCode.Append('1'); //else //retCode.Append('0'); } } offset += 4; if (offset == 8) offset = 7; } if (ErrorCode == 0) { byte[] buff = null; MemoryStream ms = new MemoryStream(); // Construct a BinaryFormatter and use it to serialize the data to the stream. BinaryFormatter formatter = new BinaryFormatter(); try { formatter.Serialize(ms, _fingersCollection as ArrayList); buff = ms.ToArray(); var client = new DataServiceClient(); client.saveWsqInDatabase(Convert.ToInt32(id), buff); //client.SetWSQImages(Convert.ToInt32(id), ref buff); //SendImage(IMAGE_TYPE.wsq, Convert.ToInt32(id), ref buff); //saveWsqInDatabase(id, buff); } catch (SerializationException ex) { retCode.Clear(); retCode.Append(ex.Message); } catch (Exception ex) { retCode.Clear(); retCode.Append(ex.Message); } finally { ms.Close(); } } else { var err = GetError(_sc); Disconnect(); throw new Exception(err); } } _sc.fpsDisconnect(); _sc = null; return retCode.ToString(); }