async Task<ViewQueryResponse<string>> GetPersonListAsync () { List<MyPerson> database = new List<MyPerson>(); string sourceDirectory = @"/Users/chrisk/source/KiwiRest/RestFiles/App_Data/files"; AfisEngine Afis = new AfisEngine(); DateTime date1 = DateTime.Now; Console.WriteLine("Starting PersonList: " + date1); WebClient client = new WebClient (); string uri = "http://localhost:5984/prints/_all_docs&include_docs=true"; // string data = client.DownloadString (uri); // var fromJson = JsonSerializer.DeserializeFromString<AllDocs>(data); var myCouchClient = new MyCouch.MyCouchClient("http://localhost:5984/prints"); ViewQueryResponse<string> result = null; try { var queryView = new QueryViewRequest("_all_docs"); queryView.Configure(query => query .IncludeDocs(true)); result = await myCouchClient.Views.QueryAsync<string>(queryView); } catch (Exception e) { } return result; }
public static List<MyPerson> GetPersonList () { List<MyPerson> database = new List<MyPerson>(); string sourceDirectory = @"/Users/chrisk/source/KiwiRest/RestFiles/App_Data/files"; AfisEngine Afis = new AfisEngine(); DateTime date1 = DateTime.Now; Console.WriteLine("Starting PersonList: " + date1); WebClient client = new WebClient (); string uri = "http://localhost:5984/prints/_all_docs&include_docs=true"; // string data = client.DownloadString (uri); // var fromJson = JsonSerializer.DeserializeFromString<AllDocs>(data); var myCouchClient = new MyCouch.MyCouchClient("http://localhost:5984/prints"); try { var queryView = new QueryViewRequest("_all_docs"); queryView.Configure(query => query .IncludeDocs(true)); } catch (Exception e) { } try { var files = Directory.EnumerateFiles(sourceDirectory, "*.png"); foreach (string currentFile in files) { DateTime date3 = DateTime.Now; Console.WriteLine("Processing " + currentFile + " at " + date3); string fileName = currentFile.Substring(sourceDirectory.Length + 1); // Directory.Move(currentFile, Path.Combine(archiveDirectory, fileName)); Guid g = Guid.NewGuid (); var guidStr = g.ToString (); MyPerson probe = SourceAfisIdentify.Enroll (currentFile, guidStr, Afis); Console.WriteLine("Adding " + guidStr); DateTime date4 = DateTime.Now; Console.WriteLine("Processed " + currentFile + " at " + date4 + " uuid: " + guidStr); var diffInSeconds = (date4 - date3).TotalSeconds; Console.WriteLine("Finished " + guidStr + " at " + date4 + " Total time: " + diffInSeconds + " seconds"); database.Add (probe); } DateTime date2 = DateTime.Now; var diffInSeconds2 = (date2 - date1).TotalSeconds; Console.WriteLine("Finished PersonList at " + date2 + " Total time: " + diffInSeconds2 + " seconds"); } catch (Exception e) { Console.WriteLine(e.Message); } return database; }
// async Task<ViewQueryResponse<string>> GetPersonListAsync () async Task GetPersonListAsync (Container container) { //List<MyPerson> database = new List<MyPerson>(); //List<MyPerson> database = FilesService.Database; //string sourceDirectory = @"/Users/chrisk/source/KiwiRest/RestFiles/App_Data/files"; //AfisEngine Afis = new AfisEngine(); DateTime date1 = DateTime.Now; Console.WriteLine("Starting FingerprintDatabase: " + date1); // WebClient client = new WebClient (); //string uri = "http://localhost:5984/prints/_all_docs&include_docs=true"; // string data = client.DownloadString (uri); // var fromJson = JsonSerializer.DeserializeFromString<AllDocs>(data); var myCouchClient = new MyCouch.MyCouchClient("http://localhost:5984/prints"); ViewQueryResponse<string> result = null; try { var queryView = new QueryViewRequest("_all_docs"); queryView.Configure(query => query .IncludeDocs(true)); result = await myCouchClient.Views.QueryAsync<string>(queryView); var rows = result.Rows; // foreach (ViewQueryResponse<SimpleFingerprint> row in rows) foreach (ViewQueryResponse<string,string>.Row row in rows) { Console.WriteLine("Lookin' at " + row); string doc = row.IncludedDoc; var person = new MyPerson (); // SimpleFingerprint print = TypeSerializer.DeserializeFromString<SimpleFingerprint>(doc); var jsonObj = JsonSerializer.DeserializeFromString<JsonObject>(doc); person._id = jsonObj["_id"]; var jsonFingerprints = jsonObj["simpleFingerprint"]; //var Filename = jsonObj["Filename"]; // var serialFingerprints = JsonSerializer.DeserializeFromString<List<JsonObject>>(jsonFingerprints); var serialFingerprints = JsonArrayObjects.Parse(jsonFingerprints); //var fps = JsonSerializer.DeserializeFromString<Dictionary<string, string>>(jsonFingerprints); //var fp = JsonSerializer.DeserializeFromString<JsonObject>(jsonObj["simpleFingerprint"]); //SimpleFingerprint sf = JsonSerializer.DeserializeFromString<SimpleFingerprint>(jsonObj["simpleFingerprint"]); List<Fingerprint> fingerprints = new List<Fingerprint> (); foreach (KeyValuePair<string,string> pair in serialFingerprints[0]) { Fingerprint simpleFingerprint = new Fingerprint (); String value = pair.Value; if (value != null) { char[] delimiterChars = { ':' }; string[] printPair = value.Split(delimiterChars); if (printPair[0] == "Base64Template") { byte[] printArray = System.Convert.FromBase64String(printPair[1]); simpleFingerprint.Template = printArray; fingerprints.Add(simpleFingerprint); } } //var print = printPair[1]; //byte[] printArray = System.Convert.FromBase64String(print); //simpleFingerprint.Template = printArray; // simpleFingerprint.Filename = Filename; //fingerprints.Add(simpleFingerprint); // foreach (KeyValuePair<string,string> pair in fprint) { // SimpleFingerprint simpleFingerprint = new SimpleFingerprint (); // var strBase64Template = JsonSerializer.DeserializeFromString<string>(pair.Key); //// simpleFingerprint.Base64Template = strBase64Template["Base64Template"]; // fingerprints.Add(simpleFingerprint); // } } // foreach (KeyValuePair<string,string> pair in serialFingerprints) // { // var prints = JsonSerializer.DeserializeFromString<JsonObject>(pair.Key); // foreach (KeyValuePair<string,string> print in prints) // { // SimpleFingerprint simpleFingerprint = new SimpleFingerprint (); // var strBase64Template = JsonSerializer.DeserializeFromString<string>(print.Key); //// simpleFingerprint.Base64Template = print["Base64Template"]; // fingerprints.Add(simpleFingerprint); // } // } person.Fingerprints = fingerprints; //person.Filename = jsonObj["Filename"]; person.Uuid = jsonObj["Uuid"]; //database.Add(person); FingerprintDatabase.AddData(person); Console.WriteLine("Added person to FingerprintDatabase."); } //container.Register(database); } catch (Exception e) { Console.WriteLine("Error: " + e); } // return result; }