/// <summary>
        /// setup the Equipment template
        /// </summary>
        /// <returns></returns>
        public List <templateOutput> GetXmlTemplateOutput()
        {
            var templateOutputs = new List <templateOutput>();

            TagGenLink = EquipName + "." + Suffix;

            if (BaseAddressParam.Equals(BaseAddr.Status))
            {
                AddressOffset = TagAddress - BaseAddrPairs[BaseAddr.Status.ToString()];
                templateOutputs.Add(TomPriceEquipmentTemplate.GetEquipmentType_VarDiscreteOutputs(this));
            }

            //require both tag and alarm tag
            if (BaseAddressParam == BaseAddr.Alarm)
            {
                AddressOffset = TagAddress - BaseAddrPairs[BaseAddr.Alarm.ToString()];
                templateOutputs.Add(TomPriceEquipmentTemplate.GetEquipmentType_VarDiscreteOutputs(this));
                templateOutputs.Add(TomPriceEquipmentTemplate.GetEquipmentType_DigAlmOutputs(this));
            }

            //create tag and trend tag (if required)
            if (BaseAddressParam.Equals(BaseAddr.Analog))
            {
                AddressOffset = TagAddress - BaseAddrPairs[BaseAddr.Analog.ToString()];
                templateOutputs.Add(TomPriceEquipmentTemplate.GetEquipmentType_VarAnalogOutputs(this));

                if (SetTrends)
                {
                    templateOutputs.Add(TomPriceEquipmentTemplate.GetEquipmentType_TrnOutputs(this));
                }
            }

            //create totalisers
            if (BaseAddressParam.Equals(BaseAddr.Totalisers))
            {
                AddressOffset = TagAddress - BaseAddrPairs[BaseAddr.Totalisers.ToString()];
                templateOutputs.Add(TomPriceEquipmentTemplate.GetEquipmentType_VarAnalogOutputs(this));
            }

            //create calculated variable (if specified)
            if (IsCalCulated)
            {
                templateOutputs.Add(TomPriceEquipmentTemplate.GetEquipmentType_CalculatedCommandVariable(this));
            }

            return(templateOutputs);
        }
        /// <summary>
        ///
        /// </summary>
        public bool ConvertTagsInExcelToTemplate(DataSet ds)
        {
            foreach (DataTable dtTable in ds.Tables)
            {
                //DEBUG
                if (dtTable.TableName.Contains("Chlo"))
                {
                    log.Debug("stop");
                }

                var equipmentTypeTemplate = new template {
                    desc = dtTable.TableName
                };                                                                     //name of worksheet - equipment type name
                equipmentTypeTemplate.param = TomPriceEquipmentTemplate.GetEquipmentType_Param(dtTable.TableName, "");
                equipmentTypeTemplate.input = TomPriceEquipmentTemplate.GetEquipmentType_Input();
                var templateOutputs = new List <templateOutput>();
                //get baseaddress?
                var baseAddressList = new Dictionary <string, int>();
                foreach (DataRow row in dtTable.AsEnumerable().Take(4))
                {
                    baseAddressList.Add(row["Tag Name"].ToString(), int.Parse(row["Address"].ToString()));
                }

                //put the information into class
                var    outputparams = new List <EquipmentTypeOutputParam>();
                string equipment    = "";
                foreach (DataRow row in dtTable.AsEnumerable().Skip(4))
                {
                    //inner exception
                    if (row.IsNull("Tag Name"))
                    {
                        continue;
                    }
                    string tagName = row["Tag Name"].ToString().Replace('.', '_');
                    equipment = row.IsNull("Equipment") ? equipment : row["Equipment"].ToString();
                    var nameSplit = tagName.Split(new char[] { '_', '.' });

                    try
                    {
                        int.TryParse(Regex.Match(row["Address"].ToString(), @"\d+").Value, out int plcNumericAddress);
                        var outputparam = new EquipmentTypeOutputParam
                        {
                            EquipName        = dtTable.TableName.Replace(" ", string.Empty),
                            Comment          = row["Comment"].ToString(),
                            DataType         = row["Data Type"].ToString(),
                            Suffix           = tagName.Substring(tagName.IndexOf(equipment) + equipment.Length).TrimStart(new char[] { '_', '.', ',', '|' }), //suffix is anything after equipment name string
                            Prefix           = nameSplit[0],
                            BaseAddrPairs    = baseAddressList,
                            BaseAddressParam = !row.IsNull("Tag Type") ? (BaseAddr)Enum.Parse(typeof(BaseAddr), row["Tag Type"].ToString()):BaseAddr.None,
                            TagAddress       = plcNumericAddress,
                            AlmCategory      = row.IsNull("Category") ? "" : row["Category"].ToString(),
                            RawZero          = row.IsNull("Raw Zero Scale") ? "0" : row["Raw Zero Scale"].ToString(),
                            RawFull          = row.IsNull("Raw Full Scale") ? "0" : row["Raw Full Scale"].ToString(),
                            EngZero          = row.IsNull("Eng Zero Scale") ? "0" : row["Eng Zero Scale"].ToString(),
                            EngFull          = row.IsNull("Eng Full Scale") ? "0" : row["Eng Full Scale"].ToString(),
                            SetTrends        = row.IsNull("Set Trend") ? false : bool.Parse(row["Set Trend"].ToString()),
                            Units            = row.IsNull("Eng Units") ? string.Empty : row["Eng Units"].ToString(),
                            Format           = row.IsNull("Format") ? string.Empty : row["Format"].ToString()
                        };

                        if (!row.IsNull(@"I/O Device"))
                        {
                            if (row["I/O Device"].ToString().Equals("CICODESVR"))
                            {
                                outputparam.DeviceIO     = row["I/O Device"].ToString();
                                outputparam.FuncName     = row["Address"].ToString();
                                outputparam.IsCalCulated = true;
                            }
                            else
                            {
                                outputparam.DeviceIO = row["I/O Device"].ToString();
                            }
                        }

                        outputparams.Add(outputparam);
                    }
                    catch (Exception ex)
                    {
                        log.ErrorFormat("ConvertTagToTemplate:{0},{1}", tagName, ex);
                    }
                }

                //find duplicates in list?
                var result = outputparams.GroupBy(x => x.Suffix.TrimStart(new char[] { '_', '.', ',' })).Select(y => new { suffix = y.Key, count = y.Count() });
                foreach (var rec in result.Where(a => a.count > 1))
                {
                    log.WarnFormat("Please correct tag list: possible duplication of tags, suffux: {0} for {1}", rec.suffix, dtTable.TableName);
                }

                //get xml formatted string from outputparams
                outputparams.ForEach(s => templateOutputs.AddRange(s.GetXmlTemplateOutput()));
                if (templateOutputs.Count > 0)
                {
                    equipmentTypeTemplate.output = templateOutputs.ToArray();
                }

                //add to list
                EquipmentTypeTemplates.Add(equipmentTypeTemplate);
            }
            //serialise to XML
            EquipmentTypeTemplates.ForEach(s => SerializeEquipmentTypeTemplate(s, s.desc));

            return(EquipmentTypeTemplates.Count > 0);
        }