private void Generate(object msPeriodGenerate) { Bitmap image; int msImageGenerated; int msFramePeriod; int millisecondsDelay; var sw = new Stopwatch(); while (true) { try { sw.Restart(); image = GenerateGrayImage(); msImageGenerated = (int)sw.ElapsedMilliseconds; millisecondsDelay = (int)msPeriodGenerate - msImageGenerated; if (millisecondsDelay > 0) { Thread.Sleep(millisecondsDelay); } sw.Stop(); msFramePeriod = (int)sw.ElapsedMilliseconds; ImageGenerated?.Invoke(image, msImageGenerated, msFramePeriod); } catch (Exception ex) { ShowMessage?.Invoke(ex.Message); } } }
public async Task Send_command_to_generate_svg_from_mol_should_publish_one_ImageGenerated_event(ImageGenerated expectedEvent) { expectedEvent.Image.Format = "svg"; if (expectedEvent.Image.Height < 16) { expectedEvent.Image.Height = 16; } if (expectedEvent.Image.Width < 16) { expectedEvent.Image.Width = 16; } await fixture.BlobStorage.AddFileAsync(expectedEvent.BlobId, _fileName, Resource.aspirin, _contentType, BUCKET); await fixture.Harness.Bus.Publish(new GenerateImage(expectedEvent.Id, BUCKET, expectedEvent.BlobId, expectedEvent.Image, expectedEvent.CorrelationId, expectedEvent.UserId)); //fixture.AllEvents // .Should().ContainItemsAssignableTo<ImageGenerated>() // .And.ContainSingle(); //var @event = fixture.AllEvents.First(); //@event.ShouldBeEquivalentTo(expectedEvent, // options => options // .Excluding(p => p.TimeStamp) // .Excluding(p => p.Version) // ); }
public async Task Send_command_to_generate_image_from_mol_should_publish_one_ImageGenerated_event([Frozen] ImageGenerated expectedEvent) { await fixture.BlobStorage.AddFileAsync(expectedEvent.BlobId, _fileName, Resource.aspirin, _contentType, BUCKET); foreach (string format in fixture.ImageFormatsForMolFile) { expectedEvent.Image.Format = format; await fixture.Harness.Bus.Publish <GenerateImage>(new GenerateImage(expectedEvent.Id, BUCKET, expectedEvent.BlobId, expectedEvent.Image, expectedEvent.CorrelationId, expectedEvent.UserId)); //fixture.AllEvents // .Should().ContainItemsAssignableTo<ImageGenerated>() // .And.ContainSingle(); //var @event = fixture.AllEvents.First(); //@event.ShouldBeEquivalentTo(expectedEvent, // options => options // .Excluding(p => p.TimeStamp) // .Excluding(p => p.Version) // ); } }
public string ToSimpleJSON(string indent) { string initPath = ""; StringBuilder ans = new StringBuilder(); ans.Append(indent + "{ \"InitPath\":\"REPLACEINITPATHHERE\", "); ans.AppendLine(indent + "\"StreamPosition\":\"" + StreamPosition + "\", "); string preindent = indent; indent += " "; if (FinishedPaths != null) { ans.AppendLine(indent + "\"Paths\":["); int pathcount = 0; foreach (var path in FinishedPaths) { if (pathcount > 0) { ans.AppendLine(","); } pathcount++; var iscomplete = SafeGetElement(path, "IsComplete"); var steps = SafeGetElement(path, "Steps"); if (steps != null) { int idx = 0; ans.Append(indent + " { \"Path\":["); foreach (var step in steps) { var nodename = SafeGetElement(step, "OptionalTargetNodeName").ToString().Trim(); if (idx > 0) { ans.Append(", "); } ans.Append("\"" + nodename + "\""); idx++; if (pathcount == 1) { if (initPath.Length > 0) { initPath += "->"; } initPath += nodename; } var actions = SafeGetElement(step, "Actions"); if (actions != null && actions.Count > 0) { foreach (var action in actions) { //var actionnodename = action["NodeName"]; //var actionresult = action["Result"]; //if (actionnodename != null && actionresult != null) //{ // try // { // ans.Append(", \"" + actionnodename.ToString() + ":" + actionnodename.Value + "\""); // } // catch (Exception ex) // { // } //} //else if (actionresult != null) //{ // var ischecked = actionresult["IsChecked"]; // ans.Append(", \"" + ischecked.ToString() + "\""); //} } } } ans.Append("] }"); } } ans.AppendLine(); if ((Children != null && Children.Count > 0) || BasicMLTags != null) { ans.AppendLine(indent + "], "); } else { ans.AppendLine(indent + "]"); } } if (Children != null && Children.Count > 0) { ans.AppendLine(indent + "\"Children\":["); int childcount = 0; foreach (DynamicHyperTagViewModel child in Children) { var childContent = child.ToSimpleJSON(indent + " "); childcount++; if (childcount > 1) { ans.AppendLine(", "); } ans.Append(childContent); } ans.AppendLine(); if (BasicMLTags != null) { ans.AppendLine(indent + "], "); } else { ans.AppendLine(indent + "]"); } } if (BasicMLTags != null) { ans.AppendLine(indent + "\"BasicMLTags\":["); int labelcount = 0; foreach (string labeltext in BasicMLTags.Labels) { if (labelcount > 0) { ans.AppendLine(", "); } string jsonTagArray = ""; string[] tokens = labeltext.Split(','); bool firstToken = true; foreach (string token in tokens) { if (firstToken == false) { jsonTagArray += ", "; } jsonTagArray += "\"" + token.Trim() + "\""; firstToken = false; } ans.AppendLine(indent + " {"); ans.AppendLine(indent + " \"TagType\":\"TextConfidenceTag\", "); ans.AppendLine(indent + " \"TagArray\":[" + jsonTagArray + "], "); string ifmore = "\" "; if (!string.IsNullOrEmpty(ImageGenerated)) { ifmore = "\", "; } ans.AppendLine(indent + " \"Confidence\":\"" + BasicMLTags.Confidences[labelcount] + ifmore); if (!string.IsNullOrEmpty(ImageGenerated)) { string fixpath = ImageGenerated.Replace(@"\", @"/").Replace("\"", "\\\""); ans.AppendLine(indent + " \"Thumbnail\":\"" + fixpath + "\""); } ans.Append(indent + " }"); labelcount++; } ans.AppendLine(); ans.AppendLine(indent + "]"); if (string.IsNullOrEmpty(initPath)) { initPath = "OrionsAI"; } } ans.Append(preindent + "}"); return(ans.ToString().Replace("REPLACEINITPATHHERE", initPath)); }