public static StepMap LoadFromFile(string fileName, IIdeTracer tracer) { try { var serializer = new StepMapSetializer(); using (var reader = new StreamReader(fileName, Encoding.UTF8)) { var stepMap = serializer.Deserialize(reader); if (stepMap.FileVersion != CURRENT_VERSION) { tracer.Trace(string.Format("StepMap has wrong file version"), typeof(StepMap).Name); return(null); } if (stepMap.IntegrationVersion != GetIntegrationVersion()) { tracer.Trace(string.Format("StepMap file is generated by another SpecFlow version."), typeof(StepMap).Name); return(null); } tracer.Trace(string.Format("StepMap with {0} feature files and {1} step definitions loaded", stepMap.FeatureFileCount, stepMap.StepDefinitionCount), typeof(StepMap).Name); return(stepMap); } } catch (Exception loadException) { tracer.Trace(string.Format("StepMap loading error: {0}", loadException), typeof(StepMap).Name); return(null); } }
public void SaveToFile(string fileName, IIdeTracer tracer) { try { string folder = Path.GetDirectoryName(fileName); Debug.Assert(folder != null); if (!Directory.Exists(folder)) { Directory.CreateDirectory(folder); } var serializer = new StepMapSetializer(); string tempFileName = fileName + ".new"; using (var writer = new StreamWriter(tempFileName, false, Encoding.UTF8)) { serializer.Serialize(writer, this); } File.Copy(tempFileName, fileName, true); File.Delete(tempFileName); tracer.Trace(string.Format("StepMap with {0} feature files and {1} step definitions saved", FeatureFileCount, StepDefinitionCount), GetType().Name); } catch (Exception saveException) { tracer.Trace(string.Format("StepMap saving error: {0}", saveException), typeof(StepMap).Name); } }