Ejemplo n.º 1
0
        public override string GenerateTransformer()
        {
            StringBuilder sb           = new StringBuilder();
            string        inputColumn  = InputColumns.Count() > 0 ? InputColumns[0] : "\"Features\"";
            string        outputColumn = OutputColumns.Count() > 0 ? OutputColumns[0] : throw new Exception($"output columns for the suggested transform: {MethodName} are null");

            sb.Append(MethodName);
            sb.Append("(");
            sb.Append("new []{");
            for (int i = 0; i < InputColumns.Length; i++)
            {
                sb.Append("new ");
                sb.Append(ArgumentsName);
                sb.Append("(");
                sb.Append(OutputColumns[i]);
                sb.Append(",");
                sb.Append(InputColumns[i]);
                sb.Append(")");
                sb.Append(",");
            }
            sb.Remove(sb.Length - 1, 1); // remove extra ,
            sb.Append("}");
            sb.Append(")");
            return(sb.ToString());
        }
Ejemplo n.º 2
0
        public override string GenerateTransformer()
        {
            string inputColumn  = InputColumns.Count() == 1 ? InputColumns[0] : throw new Exception($"input columns for the suggested transform: {MethodName} is not exactly one.");
            string outputColumn = OutputColumns.Count() == 1 ? OutputColumns[0] : throw new Exception($"output columns for the suggested transform: {MethodName} it not exactly one.");

            return($"ExtractPixels({outputColumn}, {inputColumn})");
        }
Ejemplo n.º 3
0
        public override string GenerateTransformer()
        {
            string inputColumn  = InputColumns.Count() == 1 ? InputColumns[0] : throw new Exception($"input columns for the suggested transform: {MethodName} is not exactly one.");
            string outputColumn = OutputColumns.Count() == 1 ? OutputColumns[0] : throw new Exception($"output columns for the suggested transform: {MethodName} it not exactly one.");

            // example: Transforms.LoadImages(output, inputfolder, input)
            return($"{MethodName}({outputColumn}, {@"null"}, {inputColumn})");
        }
Ejemplo n.º 4
0
        public override string GenerateTransformer()
        {
            StringBuilder sb           = new StringBuilder();
            string        inputColumn  = InputColumns.Count() > 0 ? InputColumns[0] : "\"Features\"";
            string        outputColumn = OutputColumns.Count() > 0 ? OutputColumns[0] : throw new Exception($"output columns for the suggested transform: {MethodName} are null");

            sb.Append(MethodName);
            sb.Append("(");
            sb.Append(outputColumn);
            sb.Append(",");
            sb.Append(inputColumn);
            sb.Append(")");
            return(sb.ToString());
        }
Ejemplo n.º 5
0
        public override string GenerateTransformer()
        {
            StringBuilder sb           = new StringBuilder();
            string        inputColumn  = InputColumns.Count() > 0 ? InputColumns[0] : "\"Features\"";
            string        outputColumn = OutputColumns.Count() > 0 ? OutputColumns[0] : throw new Exception($"output columns for the suggested transform: {MethodName} are null");

            sb.Append(MethodName);
            sb.Append("(");
            sb.Append(outputColumn);
            sb.Append(",");
            sb.Append("new []{");
            foreach (var col in InputColumns)
            {
                sb.Append(col);
                sb.Append(",");
            }
            sb.Remove(sb.Length - 1, 1);
            sb.Append("}");
            sb.Append(")");
            return(sb.ToString());
        }
        /// <summary>
        /// PreExecute Phase for initialization of internal runtime structures
        /// </summary>
        public override void PreExecute()
        {
            bool fireAgain = true;

            rowsProcessed = 0;
            ComponentMetaData.FireInformation(0, this.ComponentMetaData.Name, "Pre-Execute phase is beginning.", string.Empty, 0, ref fireAgain);

            IDTSInput input = ComponentMetaData.InputCollection[0];

            inputBufferColumns = new List <InputBufferColumnInfo>(input.InputColumnCollection.Count);

            for (int i = 0; i < input.InputColumnCollection.Count; i++)
            {
                IDTSInputColumn column = input.InputColumnCollection[i];

                inputBufferColumns.Add(new InputBufferColumnInfo(BufferManager.FindColumnByLineageID(input.Buffer, column.LineageID),
                                                                 column.Name, column.ID, column.LineageID, 0, column.DataType, column.Length, column.Precision, column.Scale));
            }

            outputColumns = new List <XmlColumn>();
            IDTSOutput output = ComponentMetaData.OutputCollection[0];

            foreach (IDTSOutputColumn col in output.OutputColumnCollection)
            {
                SaveOptions saveOptions       = SaveOptions.None;
                bool        serializeDataType = false;
                bool        serializeLineage  = false;
                string      sourceID          = string.Empty;
                string      sourceName        = string.Empty;
                List <int>  cols = null;

                foreach (IDTSCustomProperty prop in col.CustomPropertyCollection)
                {
                    if (prop.Name == Resources.XmlSaveOptionPropertyName)
                    {
                        saveOptions = (SaveOptions)prop.Value;
                    }
                    else if (prop.Name == Resources.XmlSerializeDataTypeName)
                    {
                        serializeDataType = (bool)prop.Value;
                    }
                    else if (prop.Name == Resources.XmlSerializeLineageName)
                    {
                        serializeLineage = (bool)prop.Value;
                    }
                    else if (prop.Name == Resources.XmlInputColumnsPropertyname)
                    {
                        string colsStr     = prop.Value.ToString();
                        var    colLineages = InputColumns.ParseInputLineages(colsStr);

                        cols = new List <int>(colLineages.Count);

                        foreach (int lineageID in colLineages)
                        {
                            int idx = inputBufferColumns.FindIndex(ibci => ibci.LineageID == lineageID);
                            cols.Add(idx);
                        }
                    }
                    else if (prop.Name == Resources.XmlSourceIdPropertyName)
                    {
                        sourceName = prop.Value.ToString();
                    }
                    else if (prop.Name == Resources.XmlSourceNamePropertyName)
                    {
                        sourceID = prop.Value.ToString();
                    }
                }

                int index = BufferManager.FindColumnByLineageID(input.Buffer, col.LineageID);
                outputColumns.Add(new XmlColumn(index, col.Name, col.DataType, saveOptions, serializeLineage, serializeDataType, cols, sourceID, sourceName, col.Length));
            }
        }
        /// <summary>
        /// Upgrades the component from earlier versions
        /// </summary>
        /// <param name="pipelineVersion"></param>
        public override void PerformUpgrade(int pipelineVersion)
        {
            DtsPipelineComponentAttribute componentAttribute = (DtsPipelineComponentAttribute)Attribute.GetCustomAttribute(this.GetType(), typeof(DtsPipelineComponentAttribute), false);
            int currentVersion = componentAttribute.CurrentVersion;

            // Get the attributes for the SSIS Package
            int metadataVersion = ComponentMetaData.Version;

            if (currentVersion < ComponentMetaData.Version)
            {
                throw new Exception(Properties.Resources.ErrorWrongRuntimeVersion);
            }
            else if (currentVersion > ComponentMetaData.Version)
            {
                IDTSInput  input         = ComponentMetaData.InputCollection[0];
                List <int> propsToRemove = new List <int>();
                List <KeyValuePair <int, int> > colLienagesSort = new List <KeyValuePair <int, int> >(input.InputColumnCollection.Count);

                string sourceID   = string.Empty;
                string sourceName = string.Empty;
                try
                {
                    IDTSCustomProperty prop = ComponentMetaData.CustomPropertyCollection[Resources.ColumnsToXmlSourceNameProperty];
                    if (prop != null)
                    {
                        sourceName = prop.Value.ToString();
                        ComponentMetaData.CustomPropertyCollection.RemoveObjectByID(prop.ID);
                    }
                }
                catch { }

                try
                {
                    IDTSCustomProperty prop = ComponentMetaData.CustomPropertyCollection[Resources.ColumnsToXmlSourceIDProperty];
                    if (prop != null)
                    {
                        sourceID = prop.Value.ToString();
                        ComponentMetaData.CustomPropertyCollection.RemoveObjectByID(prop.ID);
                    }
                }
                catch
                { }

                foreach (IDTSInputColumn col in input.InputColumnCollection)
                {
                    int sortOrder           = int.MaxValue;
                    IDTSCustomProperty prop = null;
                    propsToRemove = new List <int>();

                    foreach (IDTSCustomProperty p in col.CustomPropertyCollection)
                    {
                        if (p.Name == Resources.InputSortOrderPropertyName)
                        {
                            sortOrder = (int)p.Value;
                            propsToRemove.Add(p.ID);
                            break;
                        }
                    }

                    colLienagesSort.Add(new KeyValuePair <int, int>(col.LineageID, sortOrder));

                    foreach (int id in propsToRemove)
                    {
                        col.CustomPropertyCollection.RemoveObjectByID(id);
                    }
                }

                colLienagesSort.Sort((a, b) => a.Value.CompareTo(b.Value));


                IDTSOutput output = ComponentMetaData.OutputCollection[0];

                foreach (IDTSOutputColumn col in output.OutputColumnCollection)
                {
                    SetPropertyType setProp = SetPropertyType.All;
                    bool            additionalPropertyExists = false;

                    bool setDataType = !(col.DataType == DataType.DT_NTEXT || (col.DataType == DataType.DT_WSTR && col.Length <= 4000));

                    foreach (IDTSCustomProperty prop in col.CustomPropertyCollection)
                    {
                        if (prop.Name == Resources.XmlSaveOptionPropertyName)
                        {
                            setProp ^= SetPropertyType.XmlSaveOptions;
                        }
                        else if (prop.Name == Resources.XmlSerializeLineageName)
                        {
                            setProp ^= SetPropertyType.XmlSerializeLineage;
                        }
                        else if (prop.Name == Resources.XmlSerializeDataTypeName)
                        {
                            setProp ^= SetPropertyType.XmlSerializeDataType;
                        }
                        else if (prop.Name == Resources.XmlInputColumnsPropertyname)
                        {
                            setProp ^= SetPropertyType.XmlInputColumns;
                        }
                        else if (prop.Name == Resources.XmlSourceIdPropertyName)
                        {
                            setProp ^= SetPropertyType.XMlSourceID;
                        }
                        else if (prop.Name == Resources.XmlSourceNamePropertyName)
                        {
                            setProp ^= SetPropertyType.XmlSourceName;
                        }
                        else
                        {
                            additionalPropertyExists = true;
                        }
                    }

                    if (setProp != SetPropertyType.None || additionalPropertyExists || setDataType)
                    {
                        SetXmlColumnProperties(col, setProp, setDataType);
                    }

                    if ((setProp & SetPropertyType.XmlInputColumns) == SetPropertyType.XmlInputColumns && colLienagesSort.Count > 0)
                    {
                        string lineages = InputColumns.BuildInputLineagesString(colLienagesSort.ConvertAll <int>(kvp => kvp.Key));
                        col.CustomPropertyCollection[Resources.XmlInputColumnsPropertyname].Value = lineages;
                    }

                    if ((setProp & SetPropertyType.XMlSourceID) == SetPropertyType.XMlSourceID)
                    {
                        col.CustomPropertyCollection[Resources.XmlSourceIdPropertyName].Value = sourceID;
                    }

                    if ((setProp & SetPropertyType.XmlSourceName) == SetPropertyType.XmlSourceName)
                    {
                        col.CustomPropertyCollection[Resources.XmlSourceNamePropertyName].Value = sourceName;
                    }
                }

                ComponentMetaData.Version = currentVersion;
            }
        }
        /// <summary>
        /// Validate HashColumnsTransform metadata
        /// </summary>
        /// <returns></returns>
        public override DTSValidationStatus Validate()
        {
            if (ComponentMetaData.InputCollection.Count != 1)
            {
                FireComponentMetadataError(0, Resources.ErrorIncorrectNumberOfInputs);
                return(DTSValidationStatus.VS_NEEDSNEWMETADATA);
            }

            if (ComponentMetaData.OutputCollection.Count != 1)
            {
                FireComponentMetadataError(0, Resources.ErrorIncorrectNumberOfOutputs);
                return(DTSValidationStatus.VS_NEEDSNEWMETADATA);
            }

            IDTSInput        input  = ComponentMetaData.InputCollection[0];
            IDTSVirtualInput vInput = input.GetVirtualInput();

            foreach (IDTSInputColumn column in input.InputColumnCollection)
            {
                try
                {
                    IDTSVirtualInputColumn100 vColumn = vInput.VirtualInputColumnCollection.GetVirtualInputColumnByLineageID(column.LineageID);
                }
                catch
                {
                    FireComponentMetadataError(0, string.Format(Resources.ErrorInputColumnNotInUpstreamComponent, column.IdentificationString));
                    inputColumnsValid = false;
                    return(DTSValidationStatus.VS_NEEDSNEWMETADATA);
                }
            }

            IDTSOutput output = ComponentMetaData.OutputCollection[0];
            List <IDTSOutputColumn> redundantColumns = new List <IDTSOutputColumn>(output.OutputColumnCollection.Count);
            bool       xmlColumnExists      = false;
            List <int> missingLineages      = new List <int>();
            List <int> missingInputLineages = new List <int>();
            bool       missingError         = false;

            foreach (IDTSOutputColumn outputColumn in output.OutputColumnCollection)
            {
                bool isRendundant  = true;
                bool isInputColumn = false;
                foreach (IDTSInputColumn inputColumn in input.InputColumnCollection)
                {
                    if (inputColumn.Name == outputColumn.Name)
                    {
                        isRendundant  = false;
                        isInputColumn = true;
                        break;
                    }
                }


                //Check if XML Column;
                if (!isInputColumn)
                {
                    foreach (IDTSCustomProperty prop in outputColumn.CustomPropertyCollection)
                    {
                        if (prop.Name == Resources.XmlInputColumnsPropertyname)
                        {
                            isRendundant    = false;
                            xmlColumnExists = true;

                            var lineages = InputColumns.ParseInputLineages(prop.Value.ToString());

                            foreach (IDTSInputColumn icol in input.InputColumnCollection)
                            {
                                int l = icol.LineageID;
                                lineages.Remove(l);
                                if (lineages.Count == 0)
                                {
                                    break;
                                }
                            }

                            if (lineages.Count > 0)
                            {
                                foreach (int l in lineages)
                                {
                                    if (!missingInputLineages.Contains(l))
                                    {
                                        missingInputLineages.Add(l);
                                    }
                                }

                                foreach (IDTSVirtualInputColumn vcol in vInput.VirtualInputColumnCollection)
                                {
                                    int l = vcol.LineageID;
                                    lineages.Remove(l);
                                    if (lineages.Count == 0)
                                    {
                                        break;
                                    }
                                }

                                if (lineages.Count > 0)
                                {
                                    foreach (int l in lineages)
                                    {
                                        if (!missingLineages.Contains(l))
                                        {
                                            missingLineages.Add(l);
                                        }
                                    }
                                }
                            }
                        }
                        if (prop.Name == Resources.XmlSaveOptionPropertyName)
                        {
                            isRendundant    = false;
                            xmlColumnExists = true;

                            if (!Enum.IsDefined(typeof(SaveOptions), prop.Value))
                            {
                                FireComponentMetadataError(0, string.Format(Resources.ErrorInvalidSaveOption, outputColumn.Name));
                                return(DTSValidationStatus.VS_NEEDSNEWMETADATA);
                            }
                            else
                            {
                                if (outputColumn.DataType != DataType.DT_NTEXT && outputColumn.DataType != DataType.DT_WSTR)
                                {
                                    FireComponentMetadataError(0, string.Format(Resources.ErrorInvalidDataType, outputColumn.Name));
                                    return(DTSValidationStatus.VS_NEEDSNEWMETADATA);
                                }
                            }
                        }
                    }
                }

                //add redundand column to redundand list
                if (isRendundant)
                {
                    redundantColumns.Add(outputColumn);
                }
            }


            if (missingLineages.Count > 0)
            {
                string ml = string.Join(", ", missingLineages.ConvertAll <string>(l => l.ToString()).ToArray());

                FireComponentMetadataError(0, string.Format("Output columns are referencing input column lineages which do not exists: {0}", ml));
                missingError = true;
            }

            if (missingInputLineages.Count > 0)
            {
                string ml = string.Join(", ", missingInputLineages.ConvertAll <string>(l => l.ToString()).ToArray());

                FireComponentMetadataError(0, string.Format("Output columns are referencing input column lineages which are not selected as Input columns: {0}", ml));
                missingError = true;
            }

            if (missingError)
            {
                return(DTSValidationStatus.VS_NEEDSNEWMETADATA);
            }



            //remove redundand output columns
            foreach (IDTSOutputColumn col in redundantColumns)
            {
                output.OutputColumnCollection.RemoveObjectByID(col.ID);
            }

            //If XmlColumn does not exists, create a default one
            if (!xmlColumnExists)
            {
                IDTSOutputColumn xmlCol = output.OutputColumnCollection.New();
                xmlCol.Name        = Resources.XmlColumnDefaultName;
                xmlCol.Description = Resources.XmlColumnDefaultDesccription;

                SetXmlColumnProperties(xmlCol);
            }

            return(DTSValidationStatus.VS_ISVALID);
        }
Ejemplo n.º 9
0
 public void AddColumn(ITableColumn column) => InputColumns.Add(column);
Ejemplo n.º 10
0
        public void Populate() 
        {
            if (DefinitionType == TableDefinitionType.FREE)
            {
                return; // Nothing to do
            }

            Length = 0;

            if (DefinitionType == TableDefinitionType.PROJECTION) // There are import dimensions so copy data from another set (projection of another set)
            {
                List<DcColumn> inColumns = InputColumns.Where(d => d.GetData().IsAppendData).ToList();

                foreach(DcColumn inColumn in inColumns)
                {
                    inColumn.GetData().Translate();
                    inColumn.GetData().Evaluate(); // Delegate to column evaluation - it will add records from column expression
                }
            }
            else if (DefinitionType == TableDefinitionType.PRODUCT) // Product of local sets (no project/de-project from another set)
            {
                // Input variable for where formula
                DcVariable thisVariable = new Variable(this.Schema.Name, this.Name, "this");
                thisVariable.TypeSchema = this.Schema;
                thisVariable.TypeTable = this;

                // Evaluator expression for where formula
                ExprNode outputExpr = this.WhereExpr;
                if(outputExpr != null)
                {
                    outputExpr.OutputVariable.SchemaName = this.Schema.Name;
                    outputExpr.OutputVariable.TypeName = "Boolean";
                    outputExpr.OutputVariable.TypeSchema = this.Schema;
                    outputExpr.OutputVariable.TypeTable = this.Schema.GetPrimitiveType("Boolean");
                    outputExpr.Resolve(this.Space, new List<DcVariable>() { thisVariable });

                    outputExpr.EvaluateBegin();
                }

                DcTableWriter tableWriter = this.GetTableWriter();
                tableWriter.Open();

                //
                // Find all local greater dimensions to be varied (including the super-dim)
                //
                DcColumn[] cols = Columns.Where(x => x.IsKey && !x.IsPrimitive).ToArray();
                int colCount = cols.Length; // Dimensionality - how many free dimensions
                object[] vals = new object[colCount]; // A record with values for each free dimension being varied

                // Prepare columns
                foreach (DcColumn col in cols)
                {
                    col.GetData().AutoIndex = true; // We need true to correctly evaluate where condition and correctly remove last element if it is wrong
                    //col.GetData().Nullify();
                }

                //
                // The current state of the search procedure
                //
                Rowid[] lengths = new Rowid[colCount]; // Size of each dimension being varied (how many offsets in each dimension)
                for (int i = 0; i < colCount; i++) lengths[i] = cols[i].Output.GetData().Length;

                Rowid[] offsets = new Rowid[colCount]; // The current point/offset for each dimensions during search
                for (int i = 0; i < colCount; i++) offsets[i] = -1;

                int top = -1; // The current level/top where we change the offset. Depth of recursion.
                do ++top; while (top < colCount && lengths[top] == 0);

                // Alternative recursive iteration: http://stackoverflow.com/questions/13655299/c-sharp-most-efficient-way-to-iterate-through-multiple-arrays-list
                while (top >= 0)
                {
                    if (top == colCount) // New element is ready. Process it.
                    {
                        // Initialize a record and append it
                        for (int i = 0; i < colCount; i++)
                        {
                            vals[i] = offsets[i];
                        }
                        Rowid input = tableWriter.Append(cols, vals);

                        //
                        // Now check if this appended element satisfies the where expression and if not then remove it
                        //
                        if (outputExpr != null)
                        {
                            // Set 'this' variable to the last elements (that has been just appended) which will be read by the expression
                            thisVariable.SetValue(this.GetData().Length - 1);

                            // Evaluate expression
                            outputExpr.Evaluate();

                            bool satisfies = (bool)outputExpr.OutputVariable.GetValue();

                            if (!satisfies)
                            {
                                Length = Length - 1; // Remove elements
                            }
                        }

                        top--;
                        while (top >= 0 && lengths[top] == 0) // Go up by skipping empty dimensions and reseting 
                        { offsets[top--] = -1; }
                    }
                    else
                    {
                        // Find the next valid offset
                        offsets[top]++;

                        if (offsets[top] < lengths[top]) // Offset chosen
                        {
                            do ++top;
                            while (top < colCount && lengths[top] == 0); // Go up (forward) by skipping empty dimensions
                        }
                        else // Level is finished. Go back.
                        {
                            do { offsets[top--] = -1; }
                            while (top >= 0 && lengths[top] == 0); // Go down (backward) by skipping empty dimensions and reseting 
                        }
                    }
                }

                // Prepare columns
                foreach (DcColumn col in cols)
                {
                    col.GetData().Reindex();
                    col.GetData().AutoIndex = true;
                }

                if (tableWriter != null)
                {
                    tableWriter.Close();
                }
                if (outputExpr != null)
                {
                    outputExpr.EvaluateEnd();
                }
            }
            else
            {
                throw new NotImplementedException("This table definition type is not implemented and cannot be populated.");
            }

        }
        public BufferToolConfig(string anXMLProfile)
        {
            // Open XML
            myFileFuncs   = new FileFunctions();
            myStringFuncs = new StringFunctions();
            string strXMLFile = anXMLProfile; // The user has specified this and we've checked it exists.

            foundXML  = true;                 // In this version we have already checked that it exists.
            loadedXML = true;

            // Go forth and obtain all information.
            // Firstly, read the file.
            if (foundXML)
            {
                XmlDocument xmlConfig = new XmlDocument();
                try
                {
                    xmlConfig.Load(strXMLFile);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error in XML file; cannot load. System error message: " + ex.Message, "XML Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    loadedXML = false;
                    return;
                }
                string  strRawText;
                XmlNode currNode = xmlConfig.DocumentElement.FirstChild; // This gets us the DataBuffer.
                xmlDataBuffer = (XmlElement)currNode;

                // XML loaded successfully; get all of the detail in the Config object.

                try
                {
                    logFilePath = xmlDataBuffer["LogFilePath"].InnerText;
                }
                catch
                {
                    MessageBox.Show("Could not locate the item 'LogFilePath' in the XML file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    loadedXML = false;
                    return;
                }

                try
                {
                    defaultClearLog = false;
                    string strDefaultClearLogFile = xmlDataBuffer["DefaultClearLogFile"].InnerText;
                    if (strDefaultClearLogFile == "Yes")
                    {
                        defaultClearLog = true;
                    }
                }
                catch
                {
                    MessageBox.Show("Could not locate the item 'DefaultClearLogFile' in the XML file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    loadedXML = false;
                    return;
                }

                try
                {
                    defaultPath = xmlDataBuffer["DefaultPath"].InnerText;
                }
                catch
                {
                    MessageBox.Show("Could not locate the item 'DefaultPath' in the XML file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    loadedXML = false;
                    return;
                }

                try
                {
                    layerPath = xmlDataBuffer["LayerPath"].InnerText;
                }
                catch
                {
                    MessageBox.Show("Could not locate the item 'LayerPath' in the XML file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    loadedXML = false;
                    return;
                }

                //try
                //{
                //    tempFilePath = xmlDataBuffer["TempFilePath"].InnerText;
                //}
                //catch
                //{
                //    MessageBox.Show("Could not locate the item 'TempFilePath' in the XML file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                //    loadedXML = false;
                //    return;
                //}

                // Locate the GIS Layers.
                XmlElement MapLayerCollection = null;
                try
                {
                    MapLayerCollection = xmlDataBuffer["InLayers"];
                }
                catch
                {
                    MessageBox.Show("Could not locate the item 'InLayers' in the XML file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    loadedXML = false;
                    return;
                }
                // Now cycle through them.
                foreach (XmlNode aNode in MapLayerCollection)
                {
                    MapLayer thisLayer = new MapLayer();
                    string   strName   = aNode.Name;
                    strName = strName.Replace("_", " "); // Replace any underscores with spaces for better display.
                    thisLayer.DisplayName = strName;

                    try
                    {
                        thisLayer.LayerName = aNode["LayerName"].InnerText;
                    }
                    catch
                    {
                        MessageBox.Show("Could not locate the item 'LayerName' for map layer " + thisLayer.DisplayName + " in the XML file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        loadedXML = false;
                        return;
                    }

                    // Sort out the columns. This is pretty involved.
                    try
                    {
                        InputColumns theInputColumns = new InputColumns();
                        string       strColumnList   = aNode["Columns"].InnerText;
                        // We have the format (inputColumn1 "outputColumn1", inputColumn2, inputColumn3, "outputColumn3", "inputText" "outputColumn4", ...)
                        // Firstly split the list at the commas.
                        List <string> strColumnDefList = strColumnList.Split(',').ToList();
                        // Go through these and sort out what's what.
                        foreach (string aColumnDef in strColumnDefList)
                        {
                            InputColumn thisInputColumn = new InputColumn();
                            // Check if the first character is a "\"". If so, we deal with it slightly differently.
                            string        strColumnDef = aColumnDef.Trim(); // Remove any spaces.
                            List <string> strColItems  = new List <string>();
                            if (strColumnDef.Substring(0, 1) == "\"")
                            {
                                // find the first entry.
                                int position; // First character is a '"' so we don't want to find that.
                                int start = 0;
                                // Extract the items from the string.
                                position = strColumnDef.IndexOf('\"', start + 1);
                                if (position == 0)
                                {
                                    position = 1;
                                }
                                if (position > 0)
                                {
                                    string strResult = strColumnDef.Substring(start, position - start + 1).Trim();
                                    strColItems.Add(strResult);
                                    //start = position;
                                }
                                // The second item is split by string.
                                List <string> strAllEntries = strColumnDef.Split(' ').ToList();
                                string        theEntry      = strAllEntries[strAllEntries.Count - 1]; // Last entry.
                                strColItems.Add(theEntry.Trim('"'));                                  // Trim quotes if they are there.
                            }
                            else
                            {
                                // Split at space.
                                strColItems = strColumnDef.Split(' ').ToList();
                            }
                            // Test to see how many elements.
                            if (strColItems.Count == 1)
                            {
                                thisInputColumn.InputName  = strColItems[0].Trim();
                                thisInputColumn.OutputName = strColItems[0].Trim(); // They are both the same.
                            }
                            else if (strColItems.Count == 2)
                            {
                                thisInputColumn.InputName  = strColItems[0].Trim();
                                thisInputColumn.OutputName = strColItems[1].Trim('"'); // Trim quotes if they are there
                            }
                            else
                            {
                                // More than two elements; that's not right.
                                MessageBox.Show("The column entry " + strColItems[0] + " for map layer " + thisLayer.DisplayName + " in the XML file contains " + strColItems.Count.ToString() + " items. It should only have two.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                loadedXML = false;
                                return;
                            }

                            theInputColumns.Add(thisInputColumn);
                        }
                        thisLayer.InputColumns = theInputColumns;
                    }
                    catch
                    {
                        MessageBox.Show("Could not locate the item 'Columns' for map layer " + thisLayer.DisplayName + " in the XML file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        loadedXML = false;
                        return;
                    }

                    try
                    {
                        thisLayer.WhereClause = aNode["WhereClause"].InnerText;
                    }
                    catch
                    {
                        MessageBox.Show("Could not locate the item 'WhereClause' for map layer " + thisLayer.DisplayName + " in the XML file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        loadedXML = false;
                        return;
                    }

                    //try
                    //{
                    //    thisLayer.SortOrder = aNode["SortOrder"].InnerText;
                    //}
                    //catch
                    //{
                    //    MessageBox.Show("Could not locate the item 'SortOrder' for map layer " + thisLayer.DisplayName + " in the XML file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    //    loadedXML = false;
                    //    return;
                    //}

                    try
                    {
                        int  a;
                        bool blResult = int.TryParse(aNode["BufferSize"].InnerText, out a);
                        if (blResult)
                        {
                            thisLayer.BufferSize = a;
                        }
                        else
                        {
                            MessageBox.Show("Could not locate the item 'BufferSize' for map layer " + thisLayer.DisplayName + " in the XML file, or the item is not an integer", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            loadedXML = false;
                            return;
                        }
                    }
                    catch
                    {
                        MessageBox.Show("Could not locate the item 'BufferSize' for map layer " + thisLayer.DisplayName + " in the XML file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        loadedXML = false;
                        return;
                    }

                    try
                    {
                        int  a;
                        bool blResult = int.TryParse(aNode["DissolveSize"].InnerText, out a);
                        if (blResult)
                        {
                            thisLayer.DissolveSize = a;
                        }
                        else
                        {
                            MessageBox.Show("Could not locate the item 'DissolveSize' for map layer " + thisLayer.DisplayName + " in the XML file, or the item is not an integer", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            loadedXML = false;
                            return;
                        }
                    }
                    catch
                    {
                        MessageBox.Show("Could not locate the item 'BufferSize' for map layer " + thisLayer.DisplayName + " in the XML file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        loadedXML = false;
                        return;
                    }


                    // if everything is correct, add to the list.
                    if (loadedXML)
                    {
                        inputLayers.Add(thisLayer);
                    }
                }

                // Now get the output layer definition
                XmlElement OutLayerDef = null;
                try
                {
                    OutLayerDef = xmlDataBuffer["OutLayer"];
                }
                catch
                {
                    MessageBox.Show("Could not locate the item 'OutLayer' in the XML file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    loadedXML = false;
                    return;
                }

                // Get to the columns
                XmlNode ColumnNode = null;
                try
                {
                    ColumnNode = OutLayerDef["Columns"];
                }
                catch
                {
                    MessageBox.Show("Could not locate the item 'Columns' for the OutLayer in the XML file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    loadedXML = false;
                    return;
                }


                // Get all the columns.
                OutputColumns theOutputColumns = new OutputColumns();
                foreach (XmlNode aNode in ColumnNode)
                {
                    OutputColumn thisColumn = new OutputColumn();
                    thisColumn.ColumnName = aNode.Name;

                    try
                    {
                        thisColumn.ColumnName = aNode["ColumnName"].InnerText;
                    }
                    catch
                    {
                        MessageBox.Show("Could not locate the item 'ColumnName' for output column " + thisColumn.ColumnTag + " in the XML file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        loadedXML = false;
                        return;
                    }

                    // List of accepted types.
                    List <string> ColumnTypes = new List <string>()
                    {
                        "key", "cluster", "first", "common", "min", "max", "range"
                    };
                    try
                    {
                        strRawText = aNode["ColumnType"].InnerText.ToLower();
                        if (ColumnTypes.Contains(strRawText))
                        {
                            thisColumn.ColumnType = strRawText; // Always lower case.

                            // Now also add this type to the relevant output column in ALL the input layers.
                            foreach (MapLayer aLayer in inputLayers)
                            {
                                // Find the output column with the same name.
                                bool blFoundIt = false;
                                foreach (InputColumn aColumn in aLayer.InputColumns)
                                {
                                    if (aColumn.OutputName == thisColumn.ColumnName)
                                    {
                                        aColumn.ColumnType = strRawText;
                                        blFoundIt          = true;
                                        break;
                                    }
                                }
                                if (!blFoundIt)
                                {
                                    MessageBox.Show("The output column " + thisColumn.ColumnName + " was not found for map layer " + aLayer.LayerName, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                    loadedXML = false;
                                    return;
                                }
                            }
                        }
                        else
                        {
                            MessageBox.Show("The value for 'ColumnType' for output column " + thisColumn.ColumnTag + " in the XML file is not valid", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            loadedXML = false;
                            return;
                        }
                    }
                    catch
                    {
                        MessageBox.Show("Could not locate the item 'ColumnType' for output column " + thisColumn.ColumnTag + " in the XML file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        loadedXML = false;
                        return;
                    }

                    List <string> FieldTypes = new List <string>()
                    {
                        "TEXT", "FLOAT", "DOUBLE", "SHORT", "LONG", "DATE"
                    };
                    try
                    {
                        strRawText = aNode["FieldType"].InnerText.ToUpper();
                        if (FieldTypes.Contains(strRawText))
                        {
                            thisColumn.FieldType = strRawText; // Always upper case.

                            // Now also add this type to the relevant output column in ALL the input layers.
                            foreach (MapLayer aLayer in inputLayers)
                            {
                                // Find the output column with the same name.
                                bool blFoundIt = false;
                                foreach (InputColumn aColumn in aLayer.InputColumns)
                                {
                                    if (aColumn.OutputName == thisColumn.ColumnName)
                                    {
                                        aColumn.FieldType = strRawText;
                                        blFoundIt         = true;
                                        break;
                                    }
                                }
                                if (!blFoundIt)
                                {
                                    MessageBox.Show("The output column " + thisColumn.ColumnName + " was not found for map layer " + aLayer.LayerName, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                    loadedXML = false;
                                    return;
                                }
                            }
                        }
                        else
                        {
                            MessageBox.Show("The value for 'FieldType' for output column " + thisColumn.ColumnTag + " in the XML file is not valid", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            loadedXML = false;
                            return;
                        }
                    }
                    catch
                    {
                        MessageBox.Show("Could not locate the item 'ColumnType' for output column " + thisColumn.ColumnTag + " in the XML file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        loadedXML = false;
                        return;
                    }

                    try
                    {
                        int  a;
                        bool blResult = int.TryParse(aNode["ColumnLength"].InnerText, out a);
                        if (blResult)
                        {
                            thisColumn.ColumnLength = a;

                            // Now also add this length to the relevant output column in ALL the input layers.
                            foreach (MapLayer aLayer in inputLayers)
                            {
                                // Find the output column with the same name.
                                bool blFoundIt = false;
                                foreach (InputColumn aColumn in aLayer.InputColumns)
                                {
                                    if (aColumn.OutputName == thisColumn.ColumnName)
                                    {
                                        aColumn.FieldLength = a;
                                        blFoundIt           = true;
                                        break;
                                    }
                                }
                                if (!blFoundIt)
                                {
                                    MessageBox.Show("The output column " + thisColumn.ColumnName + " was not found for map layer " + aLayer.LayerName, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                    loadedXML = false;
                                    return;
                                }
                            }
                        }
                        else
                        {
                            MessageBox.Show("Could not locate the item 'ColumnLength' for map layer " + thisColumn.ColumnTag + " in the XML file, or the item is not an integer", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            loadedXML = false;
                            return;
                        }
                    }
                    catch
                    {
                        MessageBox.Show("Could not locate the item 'ColumnLength' for map layer " + thisColumn.ColumnTag + " in the XML file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        loadedXML = false;
                        return;
                    }

                    if (loadedXML)
                    {
                        theOutputColumns.Add(thisColumn);
                    }
                }

                // Add the columns to the output layer definition
                outputLayer.OutputColumns = theOutputColumns;

                // Get the rest of the output layer definition
                try
                {
                    outputLayer.LayerPath = layerPath + @"\";
                    outputLayer.LayerFile = OutLayerDef["LayerFile"].InnerText;
                }
                catch
                {
                    MessageBox.Show("Could not locate the item 'LayerFile' for the OutLayer in the XML file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    loadedXML = false;
                    return;
                }

                try
                {
                    List <string> OutputFormatList = new List <string>()
                    {
                        "shape", "gdb"
                    };
                    strRawText = OutLayerDef["OutputFormat"].InnerText.ToLower();
                    if (OutputFormatList.Contains(strRawText))
                    {
                        outputLayer.Format = strRawText;
                    }
                    else
                    {
                        MessageBox.Show("The entry for the output layer's OutputFormat in the XML file is not valid.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        loadedXML = false;
                    }
                }
                catch
                {
                    MessageBox.Show("Could not locate the item 'OutputFormat' for the OutLayer in the XML file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    loadedXML = false;
                    return;
                }
            }
            else
            {
                foundXML = false; // this has to be checked first; all other properties are empty.
            }
        }