private Stream Scan(string id, int hand, string checkBoxesStates, string callback) { var result = ""; var message = ""; try { Int32.Parse(id); } catch (Exception) { //toReturn = "Please enter a valid ID"; result = "error"; message = "Please enter a valid ID"; } if (result.Length == 0) { string[] checkBoxes = null; if (hand == 3) checkBoxes = new[] { "1", "1", "1", "1" }; else checkBoxes = checkBoxesStates.Split(','); Scanner scanner = null; MemoryStream ms = null; try { #if DEBUG System.Diagnostics.Debugger.Launch(); #endif var cache = new MemoryCacheServiceClient(); //ArrayList fingersCollection = cache.GetQualityFingerCollection(id); var client = new DataServiceClient(); byte[] buffer = client.GetWSQImages(id); ms = new MemoryStream(buffer); BinaryFormatter formatter = new BinaryFormatter(); formatter.Binder = new WsqSerializationBinder.GenericBinder<WsqImage>(); ArrayList fingersCollection = formatter.Deserialize(ms) as ArrayList; //List<WsqImage> fingersCollection = null; //var bioProcessor = new BioProcessor.BioProcessor(); //bioProcessor.DeserializeWSQArray(buffer, out fingersCollection); scanner = new Scanner(); scanner.FingersCollection = fingersCollection; result = scanner.scan(hand, id, checkBoxes); //var cache = new MemoryCacheServiceClient(); cache.SetDirty(); //var dataContract = new FingerPrintDataContract(); //dataContract.id = id; //dataContract.fingersCollection = scanner.FingersCollection; //cache.Put(dataContract); } catch (Exception ex) { //if (scanner != null) // scanner.Disconnect(); //toReturn = ex.Message; result = "error"; message = ex.Message; } finally { if (ms != null) ms.Close(); } } message = System.Web.HttpUtility.JavaScriptStringEncode(message); //toReturn = callback + "({\"Status\":\"" + toReturn + "\"});"; //toReturn = callback + "({\"error\":\"" + error + "\"});"; WebOperationContext.Current.OutgoingResponse.ContentType = "application/javascript"; //return new MemoryStream(Encoding.UTF8.GetBytes(toReturn)); JavaScriptSerializer serializer = new JavaScriptSerializer(); var str = serializer.Serialize(new { result = result, message = message }); str = callback + "(" + str + ")"; return new MemoryStream(Encoding.UTF8.GetBytes(str)); //IList<Object> UserInfo = new List<Object>(); /* var jsonEmptyData = new { Total = 0, Page = 1, Records = 0, Rows = new { item_id = 0, part_no = "", part_no_description = "", sum_quantity = 0, unit_price = 0d, total_price = 0d } }; return Json(jsonEmptyData, JsonRequestBehavior.AllowGet);*/ //throw new Exception("scan left"); /* string toReturn = id + " --- "; // +checkBoxesStates.Count.ToString(); var serializer = new System.Web.Script.Serialization.JavaScriptSerializer(); StringBuilder sb = new StringBuilder(); sb.Append(callback + "("); sb.Append(serializer.Serialize(toReturn)); sb.Append(");"); WebOperationContext.Current.OutgoingResponse.ContentType = "application/javascript"; return sb.ToString(); */ //WebOperationContext.Current.OutgoingResponse.ContentType = "application/javascript"; //var toReturn = callback + "({\"Status\":\"" + checkBoxesStates.Length + "\"});"; //return new MemoryStream(Encoding.UTF8.GetBytes(toReturn)); //return callback + "({\"Status\":\"OK\"});"; //Context.Response.Clear(); //Context.Response.ContentType = "application/json"; //Context.Response.Write(sb.ToString()); //Context.Response.End(); //return id + " --- "; // +checkBoxesStates.Count.ToString(); }