public void Reset() { autoFreeReqs.Clear(); reqs.Clear(); onBatchCompleted = null; loadingCount = 0; }
private bool ProcessBatchTaskRunner() { var starTime = DateTime.Now; var converter = new ImageConverter(_appSettingsRepository.LoadSettings()); int index = 1; int filesToConvert = _batchItems.Count; foreach (var batchItem in _batchItems) { bool outputFileWritten = converter.ConvertImage(batchItem.InputFile, batchItem.OutputFile); if (!outputFileWritten) { Log.Debug($"Failed to convert batchItem: {batchItem.InputFile.FileName} to {batchItem.OutputFile.FileName}"); } batchItem.IsCompleted = outputFileWritten; // Update progress string text = ""; if (outputFileWritten) { text = $"Converted image source: {batchItem.InputFile.FileName} to destination: {batchItem.OutputFile.FilePath}"; } else { text = $"Failed to convert image source: {batchItem.InputFile.FileName} to destination: {batchItem.OutputFile.FilePath}"; } if (index == _batchItems.Count) { text += "\nCompleted image batch job."; } _progress?.Report(new ImageEncodingProgressHandler { FilesCompleted = index, FileCount = filesToConvert, Text = text }); index++; if (!runWorkerThread) { break; } } TimeSpan completionTime = DateTime.Now - starTime; IsRunningBatch = false; OnBatchCompleted?.Invoke(new BatchEventArgs() { SuccessFul = true, TimeSpentProcessing = completionTime }); return(true); }
public void Start(OnBatchCompleted onCompleted) { onBatchCompleted = onCompleted; var assetMgr = AssetManager.GetInstance(); loadingCount = reqs.Count; foreach (var req in reqs) { assetMgr.StartLoad(req); } }
public void Start(string comPort, int baudRate, int batchSize) { DateTime startTime = DateTime.Now; _batchSize = batchSize; if (_port == null) { _port = new SerialPort(comPort, baudRate); _port.DataReceived += (sender, e) => { //string line = _port.ReadExisting().Trim(); string line = _port.ReadLine().Trim(); if (line.StartsWith("R[")) { double r = 0, ir = 0, g = 0, x = 0, y = 0, z = 0; //R[972] IR[709] G[211] //-?[0-9]\d*(\.\d+)? Match match = Regex.Match(line, @"^R\[([0-9]+)\] IR\[([0-9]+)\] G\[([0-9]+)\] X\[(-?[0-9]\d*\.\d+?)\] Y\[(-?[0-9]\d*\.\d+?)\] Z\[(-?[0-9]\d*\.\d+?)\]"); if (match.Groups.Count == 7) { r = double.Parse(match.Groups[1].Value); ir = double.Parse(match.Groups[2].Value); g = double.Parse(match.Groups[3].Value); x = double.Parse(match.Groups[4].Value); y = double.Parse(match.Groups[5].Value); z = double.Parse(match.Groups[6].Value); double mag = Math.Sqrt(x * x + y * y + z * z) - 9.28; rs.Add(r); irs.Add(ir); gs.Add(g); mags.Add(mag); DateTime now = DateTime.Now; double timeStamp = (now - startTime).TotalSeconds; if ((now - _lastSend).TotalMilliseconds >= 50) { double rAverage = rs.Average(); double irAverage = irs.Average(); double gAverage = gs.Average(); double mAverage = mags.Average(); OnLineRead?.Invoke(rAverage, irAverage, gAverage, mAverage, timeStamp); irs.Clear(); rs.Clear(); gs.Clear(); mags.Clear(); } MeasureModel rModel = new MeasureModel { Time = timeStamp, Value = r, }; MeasureModel irModel = new MeasureModel { Time = timeStamp, Value = ir, }; MeasureModel gModel = new MeasureModel { Time = timeStamp, Value = g, }; MeasureModel mModel = new MeasureModel { Time = timeStamp, Value = mag, }; rBatch.Add(rModel); irBatch.Add(irModel); gBatch.Add(gModel); mBatch.Add(mModel); OnEveryLine?.Invoke(rModel, irModel, gModel, mModel, now); if (irBatch.Count >= _batchSize) { OnBatchCompleted?.Invoke(rBatch, irBatch, gBatch, mBatch); rBatch.Clear(); irBatch.Clear(); gBatch.Clear(); mBatch.Clear(); } _lastSend = now; } } }; _port.Open(); } }