I have the following two methods that write to file various data line by line. Both methods differ from each other only by few lines what would be the best way to refactor them that when in future I want to add another method (for example, CreateXYZLegacyInFile
) it would be least time consuming.
public string CreateCVTLegacyInFile()
{
try
{
string dllLocation = string.Format("{0}\\{1}\\cvt\\", dllWorkingDirectory, FactoryCode);
string inFile = string.Empty;
inFile += AddLineWithMarks(dllLocation);
inFile += AddLineWithMarks(mainData.CalculationReference);
inFile += AddLineWithMarks(DateTime.Now.ToString("MM/dd/yy").Replace('-', '/'));
inFile += AddLineWithMarks(mainData.Designer);
inFile += AddLineWithMarks(mainData.TransformerType);
inFile += AddLine(mainData.TransformerSize);
inFile += AddLineWithMarks(mainData.TransformerModel);
inFile += AddLineWithMarks(mainData.MainStandard);
inFile += AddLineWithMarks(mainData.SecondaryStandard);
inFile += AddLine(mainData.Frequency);
inFile += AddLine(mainData.HighestSystemVoltage);
inFile += AddLine(mainData.PowerFrequencyInsulationLevel);
inFile += AddLine(mainData.LightningInsulationLevel + "," + mainData.SwitchingInsulationLevel);
inFile += AddLineWithMarks(vtData.RatedVoltage);
inFile += AddLineWithMarks(capacitanceData.NominalIntermediateVoltage);
inFile += AddLine(vtData.VoltageFactor);
inFile += AddLineWithMarks(vtData.VoltageFactorTime);
inFile += AddLine(mainData.MinimumAmbientTemperature + "," + mainData.MaximumAmbientTemperature + "," + mainData.AverageAmbientTemperature);
inFile += AddLineWithMarks(capacitanceData.CVDType);
inFile += AddLineWithMarks(capacitanceData.EMUType);
inFile += AddLine(capacitanceData.EquivalentCapacitance);
inFile += AddLine(capacitanceData.TotalNumberOfElements + "," + capacitanceData.NumberOfElementsSelected);
inFile += AddLine(capacitanceData.CapacitanceTotal + "," + capacitanceData.CapacitanceSecond + "," +
capacitanceData.CapacitanceFirst + "," + capacitanceData.CapacitanceElement);
inFile += AddLine(mainData.InsulatorCreepageDistance + "," + mainData.InsulatorFlashoverDistance);
inFile += AddLineWithMarks(mainData.InsulatorType);
inFile += AddLineWithMarks(mainData.InsulatorColor);
inFile += AddLineWithMarks(mainData.PrimaryMarkings);
inFile += AddLineWithMarks(capacitanceData.IsPotentialGroundSwitch);
inFile += AddLineWithMarks(mainData.IsAutoMode);
inFile += AddLineWithMarks(mainData.IsSpecialDesign);
if (vtData.IsSpecialDesign)
{
string areEnabledMarkings = string.Empty;
areEnabledMarkings += SpData.IsSelectionOfSecondaryTurns + ",";
areEnabledMarkings += SpData.IsSelectionOfPrimaryWire + ",";
areEnabledMarkings += SpData.IsSelectionOfSecondaryWire;
inFile += AddLine(areEnabledMarkings);
if (SpData.IsSelectionOfSecondaryTurns == "T")
{
inFile += AddLine(SpData.SecondaryTurnFirstWinding);
}
if (SpData.IsSelectionOfPrimaryWire == "T")
{
inFile += AddLineWithMarks(SpData.PrimaryWindingWireDimension);
}
if (SpData.IsSelectionOfSecondaryWire == "T")
{
foreach (var item in SpData.SecondaryWindingWireDimensions)
{
inFile += AddLineWithMarks(item.SecondaryMainWindingWireDimension);
inFile += AddLineWithMarks(item.SecondaryTappedWindingWireDimension);
}
}
}
inFile += AddLineWithMarks(mainData.SerialNumberPrefix.ToString());
inFile += AddLineWithMarks(mainData.SerialNumberSuffix.ToString());
inFile += AddLineWithMarks(string.Empty); //XLNUMSUB ??
inFile += AddLine(windingsData.Count.ToString());
foreach (WindingData windingData in windingsData)
{
if (vtData.IsExtendedNumberOfClasses)
{
inFile += AddLineWithMarks("X");
inFile += AddLine(windingData.NumberOfClassRequests);
}
inFile += AddLineWithMarks(windingData.TapMarking);
inFile += AddLineWithMarks(windingData.EarthMarking);
inFile += AddLineWithMarks(windingData.NominalVoltageTapped);
inFile += AddLineWithMarks(windingData.NominalVoltageMain);
inFile += extractBurdenAndAccuracyClassData(windingData.MainTerminalBurdenAndAccuracy);
inFile += extractBurdenAndAccuracyClassData(windingData.MainTerminalOtherWindingBurdenAndAccuracy);
if (vtData.IsExtendedNumberOfClasses)
{
inFile += extractBurdenAndAccuracyClassData(windingData.TappedTerminalBurdenAndAccuracy);
inFile += extractBurdenAndAccuracyClassData(windingData.TappedTerminalOtherWindingBurdenAndAccuracy);
}
inFile += AddLineWithMarks(windingData.Fuse);
foreach (string terminalMarking in windingData.TerminalMarking)
{
inFile += AddLineWithMarks(terminalMarking);
}
}
string gyrStatus = string.Empty;
gyrStatus += " ";//ALERT TOTAL
gyrStatus += translateGYRStatus(commonTransformerProperties.TransformerTypeAndSizeStatus);
gyrStatus += translateGYRStatus(commonTransformerProperties.AverageAmbientTemperatureStatus);
gyrStatus += translateGYRStatus(capacitorVoltageDivider.Insulator.Status);
gyrStatus += " "; //Shell NO
gyrStatus += " "; //Ipn
gyrStatus += " "; //OMS
gyrStatus += (intermediateVoltageTransformer.IsPotentialGround) ? "Y" : "G";
gyrStatus += translateGYRStatus(intermediateVoltageTransformer.Status);
gyrStatus += translateGYRStatus(capacitorVoltageDivider.CVDStatus);
gyrStatus += translateGYRStatus(secondaryWindings.FuseStatus);
gyrStatus += " ";// Alert STATUS
inFile += AddLineWithMarks(gyrStatus);
return inFile;
}
catch (Exception ex)
{
throw ex;
}
}
public string CreateVTLegacyInFile()
{
try
{
string dllLocation = string.Format("{0}\\{1}\\vt\\", dllWorkingDirectory, FactoryCode);
string inFile = string.Empty;
inFile += AddLineWithMarks(dllLocation);
inFile += AddLineWithMarks(mainData.CalculationReference);
inFile += AddLineWithMarks(DateTime.Now.ToString("MM/dd/yy").Replace('-', '/'));
inFile += AddLineWithMarks(mainData.Designer);
inFile += AddLineWithMarks(mainData.TransformerType );
inFile += AddLine(mainData.TransformerSize + mainData.TransformerExtension); // added
inFile += AddLineWithMarks(mainData.TransformerModel);
inFile += AddLineWithMarks(mainData.MainStandard);
inFile += AddLineWithMarks(mainData.SecondaryStandard);
inFile += AddLine(mainData.Frequency);
inFile += AddLine(mainData.HighestSystemVoltage);
inFile += AddLine(mainData.PowerFrequencyInsulationLevel);
inFile += AddLine(mainData.LightningInsulationLevel + "," + mainData.SwitchingInsulationLevel);
inFile += AddLineWithMarks(vtData.RatedVoltage);
inFile += AddLine(vtData.VoltageFactor);
inFile += AddLineWithMarks(vtData.VoltageFactorTime);
inFile += AddLineWithMarks(vtData.ThermalBurden);
inFile += AddLine(mainData.MinimumAmbientTemperature + "," + mainData.MaximumAmbientTemperature + "," + mainData.AverageAmbientTemperature);
inFile += AddLine(mainData.InsulatorCreepageDistance + "," + mainData.InsulatorFlashoverDistance);
inFile += AddLineWithMarks(mainData.InsulatorType);
inFile += AddLineWithMarks(mainData.InsulatorColor);
inFile += AddLineWithMarks(mainData.PrimaryMarkings);
inFile += AddLineWithMarks(emuData.IsExtendedNeutralTerminal);
inFile += AddLineWithMarks(mainData.IsAutoMode);
inFile += AddLineWithMarks(mainData.IsSpecialDesign);
if (vtData.IsSpecialDesign)
{
string areEnabledMarkings = string.Empty;
areEnabledMarkings += SpData.IsSelectionOfSecondaryTurns + ",";
areEnabledMarkings += SpData.IsSelectionOfPrimaryWire + ",";
areEnabledMarkings += SpData.IsSelectionOfSecondaryWire;
inFile += AddLine(areEnabledMarkings);
if (SpData.IsSelectionOfSecondaryTurns == "T")
{
inFile += AddLine(SpData.SecondaryTurnFirstWinding);
}
if (SpData.IsSelectionOfPrimaryWire == "T")
{
inFile += AddLineWithMarks(SpData.PrimaryWindingWireDimension);
}
if (SpData.IsSelectionOfSecondaryWire == "T")
{
foreach (var item in SpData.SecondaryWindingWireDimensions)
{
inFile += AddLineWithMarks(item.SecondaryMainWindingWireDimension);
inFile += AddLineWithMarks(item.SecondaryTappedWindingWireDimension);
}
}
}
inFile += AddLineWithMarks(mainData.SerialNumberPrefix.ToString());
inFile += AddLineWithMarks(mainData.SerialNumberSuffix.ToString());
inFile += AddLineWithMarks(string.Empty); //XLNUMSUB ??
inFile += AddLine(windingsData.Count.ToString());
foreach (WindingData windingData in windingsData)
{
if (vtData.IsExtendedNumberOfClasses)
{
inFile += AddLineWithMarks("X");
inFile += AddLine(windingData.NumberOfClassRequests);
}
inFile += AddLineWithMarks(windingData.TapMarking);
inFile += AddLineWithMarks(windingData.EarthMarking);
inFile += AddLineWithMarks(windingData.NominalVoltageTapped);
inFile += AddLineWithMarks(windingData.NominalVoltageMain);
inFile += extractBurdenAndAccuracyClassData(windingData.MainTerminalBurdenAndAccuracy);
inFile += extractBurdenAndAccuracyClassData(windingData.MainTerminalOtherWindingBurdenAndAccuracy);
if (vtData.IsExtendedNumberOfClasses)
{
inFile += extractBurdenAndAccuracyClassData(windingData.TappedTerminalBurdenAndAccuracy);
inFile += extractBurdenAndAccuracyClassData(windingData.TappedTerminalOtherWindingBurdenAndAccuracy);
}
inFile += AddLineWithMarks(windingData.Fuse);
foreach (string terminalMarking in windingData.TerminalMarking)
{
inFile += AddLineWithMarks(terminalMarking);
}
}
string gyrStatus = string.Empty;
gyrStatus += " ";//ALERT TOTAL
gyrStatus += translateGYRStatus(commonTransformerProperties.TransformerTypeAndSizeStatus);
gyrStatus += translateGYRStatus(commonTransformerProperties.AverageAmbientTemperatureStatus);
gyrStatus += translateGYRStatus(Insulator.Status);
gyrStatus += " "; //Shell NO
gyrStatus += " "; //Ipn
gyrStatus += " "; //OMS
gyrStatus += translateGYRStatus(secondaryWindings.FuseStatus);
gyrStatus += " ";// Alert STATUS
inFile += AddLineWithMarks(gyrStatus);
return inFile;
}
catch (Exception ex)
{
throw ex;
}
}
inFile
as astring
and instead useStringBuilder
. \$\endgroup\$