This is as clean as i can get it.
Thanks Ron
This is the base class that serializes and desrializes
the class objects
it also provides abstract methodes that are called from
its inherited classes.
namespace FDS.DataCollect ionServer.DataP rocessing
{
/// <summary>
/// Summary description for DataProcess.
/// </summary>
public abstract class DataProcess : DbObject
{
/// <summary>
/// Set the public fields to supply settings to
DataProcess.
/// </summary>
[Serializable]
public class ProcessedSettin gs
{
public int LastTubeNumber = tubeNumber;
public string RawDataFile = fileName;
public DateTime LastProductionD ate =
previousProduct ionDate;
/// <summary>
/// Save the object in XML format to a
stream
/// </summary>
/// <param name="s">Stream to save the
object to</param>
public void SaveAsXML(Strea m s)
{
XmlSerializer sr = new
XmlSerializer(t his.GetType());
sr.Serialize(s, this);
}
/// <summary>
/// Create a new ProcessedSettin gs object
initialised from XML data
/// </summary>
/// <param name="s">Stream to load the
XML from</param>
/// <returns>Proces sedSettings
object</returns>
public static ProcessedSettin gs
LoadFromXML(Str eam s)
{
return LoadFromXML(s, typeof
(ProcessedSetti ngs));
}
/// <summary>
/// Create a new object loading members
from the stream in XML format.
/// Derived class should call this from a
static method i.e.:
/// return (ProcessedDeriv edSettings)
LoadFromXML(s, typeof(Processe dDerivedSetting s));
/// </summary>
/// <param name="s">Stream to load the
object from</param>
/// <param name="t">Type of the derived
object</param>
/// <returns></returns>
protected static ProcessedSettin gs
LoadFromXML(Str eam s, Type t)
{
XmlSerializer sr = new
XmlSerializer(t );
try
{
return (ProcessedSetti ngs)
sr.Deserialize( s);
}
catch(Exception e)
{
string errorMessage = "";
errorMessage
= "Message: " + e.Message + "\n";
EventLog log = new
EventLog();
log.Source = "DCServer";
log.WriteEntry
(errorMessage);
return null;
}
}
}
public abstract void LoadSettings();
public abstract void SaveSettings();
}
}
This class inherits from the base cass which prefomes the
serialization and desrializtion and
it extends the base class so that relivent objects to it
can be serialized and desrialized.
namespace FDS.DataCollect ionServer.DataP rocessing
{
/// <summary>
/// Summary description for DataProcessTest ing.
/// </summary>
public class DataProcessTest ing : DataProcess
{
public static DataProcessTest ingSettings
settings;
string fSettings = @"settings.xml" ;
/// <summary>
/// Extends ProcessedSettin gs to add the
settings used by DataProcessTest ingSettings.
/// </summary>
[Serializable]
public class DataProcessTest ingSettings :
DataProcess.Pro cessedSettings
{
public int[] PalletRevolutio ns =
palletrevolutio n;
public int[][] PalletDefects =
palletdefect;
public int[][] HourlyCounts =
hourlyCount;
public int[] Defects = defects;
public static new
DataProcessTest ingSettings LoadFromXML(Str eam s)
{
return
(DataProcessTes tingSettings)Lo adFromXML(s, typeof
(DataProcessTes tingSettings));
}
}
public override void LoadSettings()
{
FileInfo f = new FileInfo
(fSettings);
if(f.Exists)
{
Stream fs = f.OpenRead();
try
{
settings =
DataProcessTest ingSettings.Loa dFromXML(fs);
}
catch(Exception e)
{
string
errorMessage = "";
errorMessage
= "Message: " + e.Message + "\n";
EventLog log =
new EventLog();
log.Source
= "DCServer";
log.WriteEntry
(errorMessage);
}
fs.Close();
base.TubeNumber =
settings.LastTu beNumber;
base.FileName =
settings.RawDat aFile;
base.PreviousPr oductionDate =
settings.LastPr oductionDate;
}
else
{
// File dose not exist
use default settings
settings = new
DataProcessTest ingSettings();
}
}
public override void SaveSettings()
{
settings = new
DataProcessTest ingSettings();
settings.LastTu beNumber =
base.TubeNumber ;
settings.RawDat aFile =
base.FileName;
settings.LastPr oductionDate =
base.PreviousPr oductionDate;
settings.Pallet Revolutions =
palletrevolutio n;
settings.Pallet Defects =
palletdefect;
settings.Hourly Counts =
hourlyCount;
settings.Defect s = defects;
FileInfo f = new FileInfo
(fSettings);
Stream fs = f.OpenWrite();
settings.SaveAs XML(fs);
fs.Close();
}
}
}
This Class call the the Serialize and deserialize objects
when the application starts
and stops
namespace FDS.DataCollect ionServer.DataA cquisition
{
/// <summary>
/// Will provide line or packet oriented
communications to PLC
/// </summary>
public class PLCReader : CommLine
{
// inherited objects
public static DataProcess processData;
private static CommLineSetting s settings;
private static ServerSettings server =
new ServerSettings( );
public void StartReader()
{
server.Settings ();
blocks = server.DMLocati ons;
dmData = new string[blocks];
fcsBeginLen =
server.FcsBegin Length;
fcsEndLen = server.FcsEndLe nght;
GetASCII();
beginChar = ascii
[server.FcsBegin Char];
endChar = ascii
[server.FcsEndCh ar];
ConnectionStrin g =
GetConnectionSt ring();
switch (server.SeverNa me)
{
case "FTA1DC":
processData = new
DataProcessCRTO ne(ConnectionSt ring);
break;
case "FTA3DC":
processData = new
DataProcessCRTT hree(Connection String);
break;
case "FTA4DC":
processData = new
DataProcessCRTF our(ConnectionS tring);
break;
case "PRT1DC":
processData = new
DataProcessPRTO ne(ConnectionSt ring);
break;
case "PRT2DC":
processData = new
DataProcessPRTT wo(ConnectionSt ring);
break;
case "ITCDC":
processData = new
DataProcessITC( ConnectionStrin g);
break;
case "PRJDEV":
processData = new
DataProcessTest ing(ConnectionS tring);
break;
}
// must set line id to obtain
proper shift
processData.Lin eId =
server.LineId;
processData.Get Shift();
processData.Get NewFileName();
// Retrive pervious settings for
data processing
processData.Loa dSettings();
}
public void StopReader()
{
// Save data processing settings
processData.Sav eSettings();
}
}
}
Thanks Ron
This is the base class that serializes and desrializes
the class objects
it also provides abstract methodes that are called from
its inherited classes.
namespace FDS.DataCollect ionServer.DataP rocessing
{
/// <summary>
/// Summary description for DataProcess.
/// </summary>
public abstract class DataProcess : DbObject
{
/// <summary>
/// Set the public fields to supply settings to
DataProcess.
/// </summary>
[Serializable]
public class ProcessedSettin gs
{
public int LastTubeNumber = tubeNumber;
public string RawDataFile = fileName;
public DateTime LastProductionD ate =
previousProduct ionDate;
/// <summary>
/// Save the object in XML format to a
stream
/// </summary>
/// <param name="s">Stream to save the
object to</param>
public void SaveAsXML(Strea m s)
{
XmlSerializer sr = new
XmlSerializer(t his.GetType());
sr.Serialize(s, this);
}
/// <summary>
/// Create a new ProcessedSettin gs object
initialised from XML data
/// </summary>
/// <param name="s">Stream to load the
XML from</param>
/// <returns>Proces sedSettings
object</returns>
public static ProcessedSettin gs
LoadFromXML(Str eam s)
{
return LoadFromXML(s, typeof
(ProcessedSetti ngs));
}
/// <summary>
/// Create a new object loading members
from the stream in XML format.
/// Derived class should call this from a
static method i.e.:
/// return (ProcessedDeriv edSettings)
LoadFromXML(s, typeof(Processe dDerivedSetting s));
/// </summary>
/// <param name="s">Stream to load the
object from</param>
/// <param name="t">Type of the derived
object</param>
/// <returns></returns>
protected static ProcessedSettin gs
LoadFromXML(Str eam s, Type t)
{
XmlSerializer sr = new
XmlSerializer(t );
try
{
return (ProcessedSetti ngs)
sr.Deserialize( s);
}
catch(Exception e)
{
string errorMessage = "";
errorMessage
= "Message: " + e.Message + "\n";
EventLog log = new
EventLog();
log.Source = "DCServer";
log.WriteEntry
(errorMessage);
return null;
}
}
}
public abstract void LoadSettings();
public abstract void SaveSettings();
}
}
This class inherits from the base cass which prefomes the
serialization and desrializtion and
it extends the base class so that relivent objects to it
can be serialized and desrialized.
namespace FDS.DataCollect ionServer.DataP rocessing
{
/// <summary>
/// Summary description for DataProcessTest ing.
/// </summary>
public class DataProcessTest ing : DataProcess
{
public static DataProcessTest ingSettings
settings;
string fSettings = @"settings.xml" ;
/// <summary>
/// Extends ProcessedSettin gs to add the
settings used by DataProcessTest ingSettings.
/// </summary>
[Serializable]
public class DataProcessTest ingSettings :
DataProcess.Pro cessedSettings
{
public int[] PalletRevolutio ns =
palletrevolutio n;
public int[][] PalletDefects =
palletdefect;
public int[][] HourlyCounts =
hourlyCount;
public int[] Defects = defects;
public static new
DataProcessTest ingSettings LoadFromXML(Str eam s)
{
return
(DataProcessTes tingSettings)Lo adFromXML(s, typeof
(DataProcessTes tingSettings));
}
}
public override void LoadSettings()
{
FileInfo f = new FileInfo
(fSettings);
if(f.Exists)
{
Stream fs = f.OpenRead();
try
{
settings =
DataProcessTest ingSettings.Loa dFromXML(fs);
}
catch(Exception e)
{
string
errorMessage = "";
errorMessage
= "Message: " + e.Message + "\n";
EventLog log =
new EventLog();
log.Source
= "DCServer";
log.WriteEntry
(errorMessage);
}
fs.Close();
base.TubeNumber =
settings.LastTu beNumber;
base.FileName =
settings.RawDat aFile;
base.PreviousPr oductionDate =
settings.LastPr oductionDate;
}
else
{
// File dose not exist
use default settings
settings = new
DataProcessTest ingSettings();
}
}
public override void SaveSettings()
{
settings = new
DataProcessTest ingSettings();
settings.LastTu beNumber =
base.TubeNumber ;
settings.RawDat aFile =
base.FileName;
settings.LastPr oductionDate =
base.PreviousPr oductionDate;
settings.Pallet Revolutions =
palletrevolutio n;
settings.Pallet Defects =
palletdefect;
settings.Hourly Counts =
hourlyCount;
settings.Defect s = defects;
FileInfo f = new FileInfo
(fSettings);
Stream fs = f.OpenWrite();
settings.SaveAs XML(fs);
fs.Close();
}
}
}
This Class call the the Serialize and deserialize objects
when the application starts
and stops
namespace FDS.DataCollect ionServer.DataA cquisition
{
/// <summary>
/// Will provide line or packet oriented
communications to PLC
/// </summary>
public class PLCReader : CommLine
{
// inherited objects
public static DataProcess processData;
private static CommLineSetting s settings;
private static ServerSettings server =
new ServerSettings( );
public void StartReader()
{
server.Settings ();
blocks = server.DMLocati ons;
dmData = new string[blocks];
fcsBeginLen =
server.FcsBegin Length;
fcsEndLen = server.FcsEndLe nght;
GetASCII();
beginChar = ascii
[server.FcsBegin Char];
endChar = ascii
[server.FcsEndCh ar];
ConnectionStrin g =
GetConnectionSt ring();
switch (server.SeverNa me)
{
case "FTA1DC":
processData = new
DataProcessCRTO ne(ConnectionSt ring);
break;
case "FTA3DC":
processData = new
DataProcessCRTT hree(Connection String);
break;
case "FTA4DC":
processData = new
DataProcessCRTF our(ConnectionS tring);
break;
case "PRT1DC":
processData = new
DataProcessPRTO ne(ConnectionSt ring);
break;
case "PRT2DC":
processData = new
DataProcessPRTT wo(ConnectionSt ring);
break;
case "ITCDC":
processData = new
DataProcessITC( ConnectionStrin g);
break;
case "PRJDEV":
processData = new
DataProcessTest ing(ConnectionS tring);
break;
}
// must set line id to obtain
proper shift
processData.Lin eId =
server.LineId;
processData.Get Shift();
processData.Get NewFileName();
// Retrive pervious settings for
data processing
processData.Loa dSettings();
}
public void StopReader()
{
// Save data processing settings
processData.Sav eSettings();
}
}
}