private void ProcessImage(DeviceSettings DeviceSettings) { try { // MWArray[] argsIn = new MWArray[6]; string blobname = DeviceSettings.CurrentCaptureName; argsIn[0] = GetBlobSasUri(blobname); // Path / Uri of the image (with Shared Access Signature for MATLAB) argsIn[1] = DeviceSettings.VarianceThreshold; //var_thresh = 0.0025; % variance threshold argsIn[2] = DeviceSettings.DistanceMapThreshold; //dist_thresh = 8.5; % distance - map threshold argsIn[3] = DeviceSettings.RGThreshold; //RG_thresh = 3.75; % R.R.G.threshold argsIn[4] = DeviceSettings.RestrictedFillingThreshold; //fill_area = 4; % Restricted filling threshold argsIn[5] = DeviceSettings.DilateValue; // dilate_value = 16; % Size of square SE used for dilation of dist.- map mask MWArray[] argsOut = new MWArray[3]; // [TEFL, real_length, img_colored] FilamentDetection filamentDetection = new FilamentDetection(); filamentDetection.new_detectFilaments(3, ref argsOut, argsIn); // MATLAB call // double fl = (double)((MWNumericArray)argsOut[0]); // FL (TEFL) double[] single_lengths; if (((MWNumericArray)argsOut[1]).IsEmpty) { single_lengths = new double[] { } } ; else { single_lengths = (double[])((MWNumericArray)argsOut[1]).ToVector(MWArrayComponent.Real); // TODO: NullReference checks } int h1 = 0, h2 = 0, h3 = 0, h4 = 0, h5 = 0, h6 = 0, h7 = 0, h8 = 0, h9 = 0, h10 = 0; for (int i = 0; i < single_lengths.Length; i++) { switch (GetInterval(single_lengths[i])) { case 0: h1++; break; case 1: h2++; break; case 2: h3++; break; case 3: h4++; break; case 4: h5++; break; case 5: h6++; break; case 6: h7++; break; case 7: h8++; break; case 8: h9++; break; case 9: h10++; break; default: break; } } double fc = single_lengths.Length; // FC // colored image CloudBlockBlob blob; string coloredImage = argsOut[2].ToString(); using (System.IO.FileStream fs = new System.IO.FileStream(coloredImage, System.IO.FileMode.Open)) { blob = GenerateBlobAsync().Result; fs.Position = 0; blob.UploadFromStream(fs); } File.Delete(coloredImage); // using (IsmIoTPortalContext db = new IsmIoTPortalContext()) { /* * IsmDeviceId ist Foreign-Key von FilamentData zu IsmDevice */ int id = db.IsmDevices.Where(d => d.DeviceId == DeviceSettings.DeviceId).First().IsmDeviceId; IsmIoTPortal.Models.FilamentData fildata = new IsmIoTPortal.Models.FilamentData(fc, fl, id, h1, h2, h3, h4, h5, h6, h7, h8, h9, h10, DeviceSettings.DeviceId, DeviceSettings.CurrentCaptureName, blob.Name); // 1.) Sende in Queue für DashboardBroker // FilamentData ist [DataContract], somit sind die Objekte mit DataContractSerializer serialisierbar var queueMessage = new BrokeredMessage(fildata); queueMessage.Label = IsmIoTPortal.CommandType.PRV; // BrokeredMessage.Label reicht aus um Nachrichtentyp festzulegen // CapturePeriod als Information für DashboardBroker mitsenden. queueMessage.Properties.Add(new KeyValuePair <string, object>("capturePeriod", DeviceSettings.CapturePeriod)); queueClient.SendAsync(queueMessage).Wait(); /* * // 1.) Sende Daten an Dashboards * signalRHubProxy.Invoke<string>("DataForDashboard", fildata.DeviceId, fildata.BlobUriImg, fildata.FC.ToString(), fildata.FL.ToString(), fildata.BlobUriColoredImg).ContinueWith(t => * { * //Console.WriteLine(t.Result); * this.OnLogMessage(new LogMessageEventArgs(String.Format("{0} > Send Filament Data to Dashboard <br>BlobUriimg: {1}", DateTime.Now.ToString(), fildata.BlobUriImg))); * }); */ // 2.) Bei DAT sende die Daten in EventHub, bei PRV nicht if (DeviceSettings.StateName == IsmIoTPortal.DeviceStates.RUN_STATE) { ForwaredFilamentDataToEventHub(fildata); } } } catch (Exception ex) { this.OnLogMessage(new LogMessageEventArgs(String.Format("{0} > ProcessImage Exception: {1} <br>", DateTime.Now.ToString(), ex.Message))); } }
private async Task RunAsync(CancellationToken cancellationToken) { // Receive Messages from dashboardqueue Queue and send message to SignalR Hub to update dashboards OnMessageOptions options = new OnMessageOptions(); options.AutoComplete = true; //options.AutoRenewTimeout = TimeSpan.FromMinutes(1); // Gets or sets the maximum duration within which the lock will be renewed automatically. This value should be greater than the longest message lock duration; for example, the LockDuration Property. options.MaxConcurrentCalls = 1; options.ExceptionReceived += OnMessage_ExceptionReceived; //Stopwatch sw = new Stopwatch(); Client.OnMessage((message) => { switch (message.Label) { // PRV: Update the Canvas in Dashboard with Images and Matlab Results case CommandType.PRV: // /* * object cp; * message.Properties.TryGetValue("capturePeriod", out cp); * int capturePeriod = (int)cp; * capturePeriod *= 1000; * int delay = 0; */ //FilamentData data = message.GetBody<FilamentData>(); IsmIoTPortal.Models.FilamentData data = message.GetBody <IsmIoTPortal.Models.FilamentData>(); // /* * if(sw.IsRunning) * { * sw.Stop(); * if((delay = sw.Elapsed.Milliseconds - capturePeriod) < 0) * { * delay = Math.Abs(delay); * Thread.Sleep(delay); * sw.Reset(); * } * } */ // Get full URI with Shared Access Signature to send to Portal var imgUri = GetBlobSasUri(data.BlobUriImg); var colImgUri = GetBlobSasUri(data.BlobUriColoredImg); signalRHelper.DataDorDashboardTask(data.DeviceId, imgUri, data.FC.ToString(), data.FL.ToString(), colImgUri).ContinueWith(t => { }, cancellationToken); /*sw.Start();*/ //message.Complete(); break; // UPDATE_DASHBOARD_CONTROLS: Update the Control Elements in Dashboard with the Values from the Device case CommandType.UPDATE_DASHBOARD_CONTROLS: DeviceSettings deviceSettings = message.GetBody <DeviceSettings>(); //Sende Values der Controls mit SignalR and Dashboard signalRHelper.ValuesForDashboardControlsTask(deviceSettings.DeviceId, (int)deviceSettings.CapturePeriod, deviceSettings.VarianceThreshold, deviceSettings.DistanceMapThreshold, deviceSettings.RGThreshold, deviceSettings.RestrictedFillingThreshold, deviceSettings.DilateValue).ContinueWith(t => { }, cancellationToken); //message.Complete(); break; default: break; } }, options); // TODO: Ersetzen Sie Folgendes durch Ihre eigene Logik. while (!cancellationToken.IsCancellationRequested) { //Trace.TraceInformation("Working"); await Task.Delay(1000); } }