I got problem with export object to xml file. I need to serialize file with the xml schema to make easier import but I can serialize class becouse exception was throw "Cannot serialze class without paramterless constructor or if I use special generated xmlhelper then throw cannot cast object TechnologyTable to the TechTables.Common.TechnologyTable(it's other class with parameters)
Here is Export function
private void _ExportTechTables(object SelectedItmes)
{
var Tables = (SelectedItmes as IList).Cast<TableListInfo>().ToList();
var Export = new SaveFileDialog();
var serializer = new XmlSerializer(typeof(TechnologyTable));
Export.Filter = "xml files |*.xml";
Export.Title = "Export table to xml file";
DateTime time = DateTime.UtcNow.ToLocalTime();
Export.FileName = "Exported Tables: " + time;
if(Export.ShowDialog() == DialogResult.OK)
{
using (Stream open = File.Open(Export.FileName, FileMode.OpenOrCreate))
{
foreach (var item in Tables)
{
TechTables.Common.TechnologyTable Items = Plc.Instance.TableHandler.GetTable(item.Id, false, false);
serializer.Serialize(open, Items);
}
};
}
}
Here is TechTables.Common.TechnologyTable
public TechnologyTable(int id, string name, Material material, Thickness thickness,
string lens, double focalLength, double nozzleDistance,
bool gasStabilization, bool sensitivitySensor, double sensitivityArea,
bool gasFlushingOn, int gasFlushingTime, double gasFlushingPressure, bool gasFeedbackOn, int gasFeedbackTime,
double gasFeedbackPressure, double gasMaxPressure, bool gasContinuationOn,
int gasContinuationTime, bool isTimeCountEnable, int maxTimeCount, bool isPiercingCountEnable, int maxPiercingCount, bool isColisionCountEnable, int maxColisionCount, Nozzle nozz, bool isTemplate = false, TechnologyTable template = null)
{
Id = id;
IsTimeCountEnable = isTimeCountEnable;
MaxTimeCount = maxTimeCount;
IsPiercingCountEnable = isPiercingCountEnable;
MaxPiercingCount = maxPiercingCount;
IsColisionCountEnable = isColisionCountEnable;
MaxColisionCount = maxColisionCount;
Name = name;
Nozzle = nozz;
Material = material;
Thickness = thickness;
_cuttings = Cuttings;
_piercings = Piercings;
Lens = lens;
FocalLength = focalLength;
NozzleDistance = nozzleDistance;
GasContinuationOn = gasContinuationOn;
GasContinuationTime = gasContinuationTime;
GasFeedbackOn = gasFeedbackOn;
GasFeedbackPressure = gasFeedbackPressure;
GasFeedbackTime = gasFeedbackTime;
GasFlushingOn = gasFlushingOn;
GasFlushingTime = gasFlushingTime;
GasFlushingPressure = gasFlushingPressure;
GasMaxPressure = gasMaxPressure;
GasStabilization = gasStabilization;
SensitivityArea = sensitivityArea;
SensitivitySensor = sensitivitySensor;
IsTemplate = isTemplate;
Template = template;
} #lower property but it's too much to paste them here
And Here is my SerializerHelper
namespace Eagle.eSoft.Eris.ViewModel.ServiceOptions
{
[XmlRoot(ElementName = "material", Namespace =
"http://tempuri.org/XMLSchema.xsd")]
public class Material
{
[XmlElement(ElementName = "Id", Namespace = "http://tempuri.org/XMLSchema.xsd")]
public string Id { get; set; }
[XmlElement(ElementName = "Name", Namespace = "http://tempuri.org/XMLSchema.xsd")]
public string Name { get; set; }
[XmlElement(ElementName = "FullName", Namespace = "http://tempuri.org/XMLSchema.xsd")]
public string FullName { get; set; }
[XmlElement(ElementName = "Code", Namespace = "http://tempuri.org/XMLSchema.xsd")]
public string Code { get; set; }
}
[XmlRoot(ElementName = "thickness", Namespace = "http://tempuri.org/XMLSchema.xsd")]
public class Thickness
{
[XmlElement(ElementName = "thicknessId", Namespace = "http://tempuri.org/XMLSchema.xsd")]
public string ThicknessId { get; set; }
[XmlElement(ElementName = "thicknessValue", Namespace = "http://tempuri.org/XMLSchema.xsd")]
public string ThicknessValue { get; set; }
[XmlElement(ElementName = "unit", Namespace = "http://tempuri.org/XMLSchema.xsd")]
public string Unit { get; set; }
}
[XmlRoot(ElementName = "nozz", Namespace = "http://tempuri.org/XMLSchema.xsd")]
public class Nozz
{
[XmlElement(ElementName = "NozzleID", Namespace = "http://tempuri.org/XMLSchema.xsd")]
public string NozzleID { get; set; }
[XmlElement(ElementName = "NozzleName", Namespace = "http://tempuri.org/XMLSchema.xsd")]
public string NozzleName { get; set; }
[XmlElement(ElementName = "SocketType", Namespace = "http://tempuri.org/XMLSchema.xsd")]
public string SocketType { get; set; }
}
[XmlRoot(ElementName = "TechnologyTable", Namespace = "http://tempuri.org/XMLSchema.xsd")]
public class TechnologyTable
{
[XmlElement(ElementName = "Id", Namespace = "http://tempuri.org/XMLSchema.xsd")]
public string Id { get; set; }
[XmlElement(ElementName = "Name", Namespace = "http://tempuri.org/XMLSchema.xsd")]
public string Name { get; set; }
[XmlElement(ElementName = "material", Namespace = "http://tempuri.org/XMLSchema.xsd")]
public Material Material { get; set; }
[XmlElement(ElementName = "thickness", Namespace = "http://tempuri.org/XMLSchema.xsd")]
public Thickness Thickness { get; set; }
[XmlElement(ElementName = "lens", Namespace = "http://tempuri.org/XMLSchema.xsd")]
public string Lens { get; set; }
[XmlElement(ElementName = "focalLenght", Namespace = "http://tempuri.org/XMLSchema.xsd")]
public string FocalLenght { get; set; }
[XmlElement(ElementName = "nozzleDistance", Namespace = "http://tempuri.org/XMLSchema.xsd")]
public string NozzleDistance { get; set; }
[XmlElement(ElementName = "gasStabilization", Namespace = "http://tempuri.org/XMLSchema.xsd")]
public string GasStabilization { get; set; }
[XmlElement(ElementName = "sensitivitySensor", Namespace = "http://tempuri.org/XMLSchema.xsd")]
public string SensitivitySensor { get; set; }
[XmlElement(ElementName = "sensitivityArea", Namespace = "http://tempuri.org/XMLSchema.xsd")]
public string SensitivityArea { get; set; }
[XmlElement(ElementName = "gasFlushingOn", Namespace = "http://tempuri.org/XMLSchema.xsd")]
public string GasFlushingOn { get; set; }
[XmlElement(ElementName = "gasFlushingTime", Namespace = "http://tempuri.org/XMLSchema.xsd")]
public string GasFlushingTime { get; set; }
[XmlElement(ElementName = "gasFlushingPressure", Namespace = "http://tempuri.org/XMLSchema.xsd")]
public string GasFlushingPressure { get; set; }
[XmlElement(ElementName = "gasFeedbackOn", Namespace = "http://tempuri.org/XMLSchema.xsd")]
public string GasFeedbackOn { get; set; }
[XmlElement(ElementName = "gasFeedbackTime", Namespace = "http://tempuri.org/XMLSchema.xsd")]
public string GasFeedbackTime { get; set; }
[XmlElement(ElementName = "gasFeedBackPressure", Namespace = "http://tempuri.org/XMLSchema.xsd")]
public string GasFeedBackPressure { get; set; }
[XmlElement(ElementName = "gasMaxPressure", Namespace = "http://tempuri.org/XMLSchema.xsd")]
public string GasMaxPressure { get; set; }
[XmlElement(ElementName = "gasContinuationOn", Namespace = "http://tempuri.org/XMLSchema.xsd")]
public string GasContinuationOn { get; set; }
[XmlElement(ElementName = "gasContinuationTime", Namespace = "http://tempuri.org/XMLSchema.xsd")]
public string GasContinuationTime { get; set; }
[XmlElement(ElementName = "isTimeCountEnable", Namespace = "http://tempuri.org/XMLSchema.xsd")]
public string IsTimeCountEnable { get; set; }
[XmlElement(ElementName = "maxTimeCount", Namespace = "http://tempuri.org/XMLSchema.xsd")]
public string MaxTimeCount { get; set; }
[XmlElement(ElementName = "isPiercingCountEnable", Namespace = "http://tempuri.org/XMLSchema.xsd")]
public string IsPiercingCountEnable { get; set; }
[XmlElement(ElementName = "maxPiercingCount", Namespace = "http://tempuri.org/XMLSchema.xsd")]
public string MaxPiercingCount { get; set; }
[XmlElement(ElementName = "isColisionCountEnable", Namespace = "http://tempuri.org/XMLSchema.xsd")]
public string IsColisionCountEnable { get; set; }
[XmlElement(ElementName = "maxColisionCount", Namespace = "http://tempuri.org/XMLSchema.xsd")]
public string MaxColisionCount { get; set; }
[XmlElement(ElementName = "nozz", Namespace = "http://tempuri.org/XMLSchema.xsd")]
public Nozz Nozz { get; set; }
[XmlElement(ElementName = "isTemplate", Namespace = "http://tempuri.org/XMLSchema.xsd")]
public string IsTemplate { get; set; }
[XmlElement(ElementName = "Template", Namespace = "http://tempuri.org/XMLSchema.xsd")]
public string Template { get; set; }
}
[XmlRoot(ElementName = "TechnologyTableList", Namespace = "http://tempuri.org/XMLSchema.xsd")]
public class TechnologyTableSerializer
{
[XmlElement(ElementName = "TechnologyTable", Namespace = "http://tempuri.org/XMLSchema.xsd")]
public List<TechnologyTable> TechnologyTable { get; set; }
[XmlAttribute(AttributeName = "xmlns")]
public string Xmlns { get; set; }
}
}