EKG_Project.IO.Atrial_Fibr_Data_Worker.Save C# (CSharp) Method

Save() public method

public Save ( ECG_Data data ) : void
data EKG_Project.Modules.ECG_Data
return void
        public void Save(ECG_Data data)
        {
            if (data is Atrial_Fibr_Data)
            {
                Atrial_Fibr_Data basicData = data as Atrial_Fibr_Data;

                ECG_Worker ew = new ECG_Worker();
                XmlDocument file = new XmlDocument();
                string fileName = analysisName + "_Data.xml";
                file.Load(System.IO.Path.Combine(directory, fileName));
                XmlNode root = file.SelectSingleNode("EKG");

                XmlElement module = file.CreateElement(string.Empty, "module", string.Empty);
                string moduleName = this.GetType().Name;
                moduleName = moduleName.Replace("_Data_Worker", "");

                XmlNodeList existingModules = file.SelectNodes("EKG/module");
                foreach (XmlNode existingModule in existingModules)
                {
                    if (existingModule.Attributes["name"].Value == moduleName)
                    {
                        root.RemoveChild(existingModule);
                    }
                }

                module.SetAttribute("name", moduleName);
                root.AppendChild(module);

                List<Tuple<bool, int[], string, string>> afDetection = basicData.AfDetection;
                foreach (var tuple in afDetection)
                {
                    XmlElement detectedAF = file.CreateElement(string.Empty, "detectedAF", string.Empty);
                    module.AppendChild(detectedAF);

                    XmlElement detected = file.CreateElement(string.Empty, "detected", string.Empty);
                    XmlText detectedValue = file.CreateTextNode(tuple.Item1.ToString());
                    detected.AppendChild(detectedValue);
                    detectedAF.AppendChild(detected);

                    XmlElement detectedPoints = file.CreateElement(string.Empty, "detectedPoints", string.Empty);
                    string detectedPointsText = null;
                    foreach (var value in tuple.Item2)
                    {
                        detectedPointsText += value.ToString() + " ";
                    }

                    XmlText detectedPointsValue = file.CreateTextNode(detectedPointsText);
                    detectedPoints.AppendChild(detectedPointsValue);
                    detectedAF.AppendChild(detectedPoints);

                    XmlElement detectedS = file.CreateElement(string.Empty, "detectedS", string.Empty);
                    XmlText detectedSValue = file.CreateTextNode(tuple.Item3);
                    detectedS.AppendChild(detectedSValue);
                    detectedAF.AppendChild(detectedS);

                    XmlElement timeofAF = file.CreateElement(string.Empty, "timeofAF", string.Empty);
                    XmlText timeofAFValue = file.CreateTextNode(tuple.Item4);
                    timeofAF.AppendChild(timeofAFValue);
                    detectedAF.AppendChild(timeofAF);

                }

                ew.InternalXMLFile = file;

                file.Save(System.IO.Path.Combine(directory, fileName));

            }
        }