using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Linq;
using AppRes = Eugen.ESystem.Windows.Forms.Properties.AppResources;


namespace Eugen.ESystem.Windows.Forms
{
    internal class SaveXML
    {
        public string FileName { get; set; }
        public string Topic = ""; //z.B. "NX-Portal"
        public string Group { get; set; } //z.B. "Tools"
        public string[] Keys { get; set; } //z.B. "CleanUp"
        public string[] Values { get; set; } //z.B. "M:\ug\Tools\CleanUp\CleanUp.exe"
        public string[] Attributes { get; set; } //z.B. "-h"

        public void Save()
        {
            //Namensraum definieren
            XNamespace ns = "https://www.engelglobal.com/de/at/index.html";

            //Wurzelelement erzeugen
            XElement rootElement = new XElement(ns + Topic);

            //Namensraum als Attribut angeben
            rootElement.Add(new XAttribute("xmlns", ns));

            //Der Wert
            for (int i = 0; i < Values.Length; i++)
            {
                XElement groupElement = new XElement(ns + Group.Replace(" ", "_"));
                groupElement.Add(new XAttribute(Keys[i], Values[i]));
                groupElement.Add(new XAttribute("Attribute", Attributes[i]));

                rootElement.Add(groupElement);
            }

            rootElement.Save(FileName);

            MessageBox.Show(AppRes.msgBoxTxt003, AppRes.msgBoxCapt003, MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
    }
}
