/// <summary> /// Called by Alteryx to send each data record to the tool. /// </summary> /// <param name="pRecord">The new record</param> /// <returns>True if Ok</returns> public bool II_PushRecord(AlteryxRecordInfoNet.RecordData pRecord) { var args = new RecordPushedEventArgs(pRecord); this.RecordPushed(this, args); return(args.Success); }
// Receive an inbound record and process it. // Information about the record is held in the recordInfo object // that was passed in to II_Init(), and (hopefully) cached. public bool II_PushRecord(AlteryxRecordInfoNet.RecordData recordDataIn) { DebugMessage($"II_PushRecord() Entering; ToolID={_toolID}"); // If we have no selected field, we can't continue. if (string.IsNullOrWhiteSpace(_selectedField)) { Message($"Selected input field was blank."); return(false); } // Get the FieldBase for the "Input" data the contains the bitmap filename to process. FieldBase filenameFieldBase = null; try { filenameFieldBase = _recordInfoIn.GetFieldByName(_selectedField, false); } catch { Message($"Input column requires a path to a bitmap file."); return(false); } // If that field doesn't exist, we can't continue. if (filenameFieldBase == null) { return(false); } // Get the filename from the current record. string filenameText = ""; try { filenameText = filenameFieldBase.GetAsString(recordDataIn); } catch { return(false); } if (string.IsNullOrEmpty(filenameText)) { return(false); } DebugMessage($"II_PushRecord() Processing [{filenameText}]; ToolID={_toolID}"); // Load Image Bitmap image = null; try { image = (Bitmap)Image.FromFile(filenameText, true); } catch (OutOfMemoryException) { Message($"Failed to load [{filenameText}] - OutOfMemory exception; Check file exists and is an image file of type BMP/DIB/JPEG/GIF/TIFF/PNG format.", MessageStatus.STATUS_Error); return(false); } catch (Exception ex) { string exMessage = ex.Message; string exBaseMessage = ex.GetBaseException()?.Message ?? ""; Message($"Failed to load [{filenameText}]; Exception:[{ex.Message}]; BaseException:[{exBaseMessage}]", MessageStatus.STATUS_Error); return(false); } if (image == null) { Message($"Image object loaded, but null, for file:[{filenameText}]; ToolID={_toolID}", MessageStatus.STATUS_Error); return(false); } // Walk bitmap sequentially, retrieving data int height = image.Height; int width = image.Width; DebugMessage($"II_PushRecord() Processing [{filenameText}]; Total Pixels={height * width}; ToolID={_toolID}"); double dTotalPixelsOnePercent = height * width / 100; double dTotalPixelsTenPercent = height * width / 10; Int64 totalPixelsOnePercent = Math.Max((Int64)dTotalPixelsOnePercent, 1); Int64 totalPixelsTenPercent = Math.Max((Int64)dTotalPixelsTenPercent, 1); Int32 x = 0; Int32 y = 0; Int64 countPixels = 0; for (y = 0; y < height; ++y) { for (x = 0; x < width; ++x) { ++countPixels; Int64 progress = Convert.ToInt64(countPixels / totalPixelsOnePercent); if (countPixels % totalPixelsTenPercent == 0) { Message($"Bitmap Reader Progress: {progress}%; ToolID={_toolID}"); } Color color = image.GetPixel(x, y); pushRecord( x, y, color.R, color.G, color.B, color.A, recordDataIn); } } // Drop the bitmap image.Dispose(); // DIAG // Call to pushRecord() to simulate activity once. //pushRecord("XCoord","YCoord","RValue","GValue","BValue","AlphaValue",recordDataIn); // END DIAG DebugMessage($"II_PushRecord() Exiting; ToolID={_toolID}"); return(true); }
// Receive an inbound record and process it. // Information about the record is held in the recordInfo object // that was passed in to II_Init(), and (hopefully) cached. public bool II_PushRecord(AlteryxRecordInfoNet.RecordData recordDataIn) { DebugMessage($"II_PushRecord() Entering; ToolID={_toolID}"); // If we have no selected field, we can't continue. if (string.IsNullOrWhiteSpace(_selectedField)) { return(false); } // Get the FieldBase for the "Input" data the contains the XML data. FieldBase xmlFieldBase = null; try { xmlFieldBase = _recordInfoIn.GetFieldByName(_selectedField, false); } catch { return(false); } // If that field doesn't exist, we can't continue. if (xmlFieldBase == null) { return(false); } // Get the XML data from the current record. string xmlText = ""; try { xmlText = xmlFieldBase.GetAsString(recordDataIn); } catch { return(false); } if (string.IsNullOrEmpty(xmlText)) { return(false); } // Load XML doc XDocument doc = XDocument.Parse(xmlText); // Write the XmlDeclarations processDeclarations(doc, recordDataIn); // Write the XmlProcessingInstructions processPIs(doc, recordDataIn); // Walk the XML input. // Create one output record for each hierachy level. // Add one record for every attribute foreach (var xElement in doc.Root.DescendantsAndSelf()) { string xPath = xElement.GetAbsoluteXPath(_indexGroups, _pathDelimiter); // The xml hierachy path string textContent = xElement.ShallowValue().Trim(); // Value in the text node // Text Content might be XML encode ie "You & yours" represented as "You & yours". // If this gets recoded to XML, this then becomes "You &amp; yours". if (!textContent.Contains("![CDATA[")) { textContent = System.Net.WebUtility.HtmlDecode(textContent); } pushRecord(xPath, textContent, recordDataIn); foreach (XAttribute xAttribute in xElement.Attributes()) { string xPathAndAttribute = xPath + _attrDelimiter; var sAttribute = xAttribute.ToString(); // xmlns="url" | xmlns:pkg="url" | size="5" var parts = sAttribute.Split('='); xPathAndAttribute += parts[0]; string attrContent = xAttribute.Value; // Could be parts 1 pushRecord(xPathAndAttribute, attrContent, recordDataIn); } } DebugMessage($"II_PushRecord() Exiting; ToolID={_toolID}"); return(true); }
// Receive an inbound record and process it. // Information about the record is held in the recordInfo object // that was passed in to II_Init(), and (hopefully) cached. public bool II_PushRecord(AlteryxRecordInfoNet.RecordData recordDataIn) { DebugMessage($"II_PushRecord() Entering; ToolID={_toolID}"); // If we don't have a group field, no problem, optional // We need an X and Y field, pump out errors if points are not numbers // We will have a concavity, defaulting to zero // Scale Factor still un-known. // Might want an optional max number of points in enclosing polygon // Clear the collection //_dicPoints = new Dictionary<string, List<Tuple<Double, Double>>>(); // Get the point if (string.IsNullOrWhiteSpace(_xField)) { ErrorMessage($"X Field not selected"); return(false); } if (string.IsNullOrWhiteSpace(_yField)) { ErrorMessage($"Y Field not selected"); return(false); } FieldBase xFieldBase = null; try { xFieldBase = _recordInfoIn.GetFieldByName(_xField, false); } catch { ErrorMessage($"X Field [{_xField}] does not exist."); return(false); } FieldBase yFieldBase = null; try { yFieldBase = _recordInfoIn.GetFieldByName(_yField, false); } catch { ErrorMessage($"Y Field [{_yField}] does not exist."); return(false); } if (xFieldBase == null) { ErrorMessage($"X Field [{_xField}] exists but the FieldBase could not be accessed."); return(false); } if (yFieldBase == null) { ErrorMessage($"Y Field [{_yField}] exists but the FieldBase could not be accessed."); return(false); } // Got an X and Y fieldbase string xText = ""; try { xText = xFieldBase.GetAsString(recordDataIn); } catch { ErrorMessage($"X Field [{_xField}] exists but the FieldBase did not yield a value string."); return(false); } string yText = ""; try { yText = yFieldBase.GetAsString(recordDataIn); } catch { ErrorMessage($"Y Field [{_yField}] exists but the FieldBase did not yield a value string."); return(false); } if (string.IsNullOrEmpty(xText)) { ErrorMessage($"X Field [{_xField}] has missing data; Ensure all rows entering this tool have point data; Remove empty rows with a Filter tool ahead of this tool."); return(false); } if (string.IsNullOrEmpty(yText)) { ErrorMessage($"Y Field [{_yField}] has missing data; Ensure all rows entering this tool have point data; Remove empty rows with a Filter tool ahead of this tool."); return(false); } // Got an X and Y string // Convert to double double dX = 0; double dY = 0; try { dX = Convert.ToDouble(xText); } catch { ErrorMessage($"X Field [{_xField}] data element [{xText}] could not be converted to a double value."); return(false); } try { dY = Convert.ToDouble(yText); } catch { ErrorMessage($"Y Field [{_yField}] data element [{yText}] could not be converted to a double value."); return(false); } // Got an X and Y double value; // On to the Groups... // Read group if it exists string currentGroup = "DEFAULT"; if (!string.IsNullOrWhiteSpace(_groupField)) { FieldBase groupFieldBase = null; try { groupFieldBase = _recordInfoIn.GetFieldByName(_groupField, false); } catch { ErrorMessage($"Group Field [{_groupField}] does not exist."); return(false); } // Got the fieldbase for the Group Field if (groupFieldBase == null) { ErrorMessage($"Group Field [{_groupField}] exists but the FieldBase could not be accessed."); return(false); } // Got a non-null fieldbase string groupText = ""; try { groupText = groupFieldBase.GetAsString(recordDataIn); } catch { ErrorMessage($"Group Field [{_groupField}] could not be accessed."); return(false); } if (!string.IsNullOrEmpty(groupText)) { currentGroup = groupText; } } // Get existing list or create new list List <Tuple <Double, Double> > points = null; if (!_dicPoints.TryGetValue(currentGroup, out points)) { // No list yet points = new List <Tuple <Double, Double> >(); _dicPoints.Add(currentGroup, points); } // Should either have the current group list, or a new list. points.Add(new Tuple <Double, Double>(dX, dY)); DebugMessage($"Added point ({xText},{yText}) for Group [{currentGroup}]"); DebugMessage($"II_PushRecord() Exiting; ToolID={_toolID}"); return(true); }