/*
         *      public string getWindowDetails(Window window) {
         *
         *
         *          if (window.Id != "") {
         *              if (window.Id == "HomeHealthDesktop") {
         *                  WindowTools windowTools = new WindowTools();
         *                  Tab tab = (Tab)windowTools.GetIUIItemList<Tab>(window)[0];
         *                  ITabPage iTabPage = tab.Pages.Where(x => x.IsSelected).FirstOrDefault();
         *                  if (iTabPage.Name.Replace(" ", "").Contains("EditCarePlan")) {
         *                      return $"Id_{window.Id}_EditCarePlan_items_{window.Items.Count}";
         *                  }
         *                  return $"Id_{window.Id}_{iTabPage.Name.Replace(" ", "")}_items_{window.Items.Count}";
         *              }
         *              return $"Id_{window.Id}_items_{window.Items.Count}";
         *          }
         *          if (window.Name != "") {
         *              return $"Name_{window.Name.Replace(" ", "")}_items_{window.Items.Count}";
         *          }
         *          if (window.PrimaryIdentification != "") {
         *              return $"Prime_{window.PrimaryIdentification}_items_{window.Items.Count}";
         *          }
         *          return $"LOC_{window.Location.X}_{window.Location.Y}_items_{window.Items.Count}";
         *      }
         *
         */
        public void serializeWindowItems(Window window, string windowName, string path)
        {
            XmlToolSet  ts  = new XmlToolSet();
            XmlDocument doc = ts.newDoc("Items");

            foreach (var item in window.Items)
            {
                string       typeName = item.GetType().ToString();
                XmlNode      node     = ts.CreateElement(doc, typeName.Remove(0, typeName.LastIndexOf(".") + 1));
                XmlAttribute Label    = ts.CreateAttribute(doc, "Label", windowName);
                node = ts.AddAttribute(node, Label);


                XmlAttribute Name = ts.CreateAttribute(doc, "Name", item.Name);
                node = ts.AddAttribute(node, Name);
                XmlAttribute PrimeId = ts.CreateAttribute(doc, "PrimeId", item.PrimaryIdentification);
                node = ts.AddAttribute(node, PrimeId);
                XmlAttribute Id = ts.CreateAttribute(doc, "Id", item.Id);
                node = ts.AddAttribute(node, Id);
                XmlAttribute isEnabled = ts.CreateAttribute(doc, "isEnabled", item.Enabled.ToString());
                node = ts.AddAttribute(node, isEnabled);
                XmlAttribute Bounds = ts.CreateAttribute(doc, "Bounds", item.Bounds.ToString());
                node = ts.AddAttribute(node, Bounds);
                XmlAttribute BorderColour = ts.CreateAttribute(doc, "BorderColour", item.BorderColor.ToString());
                node = ts.AddAttribute(node, BorderColour);


                doc = ts.AddNode(doc, node);
            }
            doc.Save(path);


            /*
             * XmlAttribute Name = ts.CreateAttribute(doc, "Name", Regex.Replace(item.Name, @"[^a-zA-Z0-9]", ""));
             * node = ts.AddAttribute(node, Name);
             * XmlAttribute PrimeId = ts.CreateAttribute(doc, "PrimeId", Regex.Replace(item.PrimaryIdentification, @"[^a-zA-Z0-9]", ""));
             * node = ts.AddAttribute(node, PrimeId);
             * XmlAttribute Id = ts.CreateAttribute(doc, "Id", Regex.Replace(item.Id, @"[^a-zA-Z0-9]", ""));
             * node = ts.AddAttribute(node, Id);
             * XmlAttribute isEnabled = ts.CreateAttribute(doc, "isEnabled", item.Enabled.ToString());
             * node = ts.AddAttribute(node, isEnabled);
             * XmlAttribute Bounds = ts.CreateAttribute(doc, "Bounds", item.Bounds.ToString());
             * node = ts.AddAttribute(node, Bounds);
             * XmlAttribute BorderColour = ts.CreateAttribute(doc, "BorderColour", item.BorderColor.ToString());
             * node = ts.AddAttribute(node, BorderColour);
             *
             *
             *
             *              XmlNode node = ts.CreateElement(doc, item.PrimaryIdentification);
             *              XmlAttribute itemCount = ts.CreateAttribute(doc, "itemCount", window.Items.Count.ToString());
             *              node = ts.AddAttribute(node, itemCount);
             *              XmlAttribute isModal = ts.CreateAttribute(doc, "isModal", window.IsModal.ToString());
             *              node = ts.AddAttribute(node, isModal);
             *              XmlAttribute bounds = ts.CreateAttribute(doc, "bounds", window.Bounds.ToString());
             *              node = ts.AddAttribute(node, bounds);
             *              doc = ts.AddNode(doc, node);
             *              doc.Save(path);
             */
        }
        public void serializeWindow(Window window, string windowName, string windowPath, string itemPath)
        {
            XmlToolSet ts = new XmlToolSet();
            string     entryName;

            if (!CheckPath(windowPath))
            {
                XmlDocument document = ts.newDoc("Windows");
                document.Save(windowPath);
            }
            if (!IsWindowMapped(windowName, windowPath))
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(windowPath);
                XmlNode baseNode = ts.CreateElement(doc, windowName);


                entryName = getWindowDetails(window);

                XmlNode      node      = ts.CreateElement(doc, entryName);
                XmlAttribute itemCount = ts.CreateAttribute(doc, "itemCount", window.Items.Count.ToString());
                node = ts.AddAttribute(node, itemCount);
                XmlAttribute isModal = ts.CreateAttribute(doc, "isModal", window.IsModal.ToString());
                node = ts.AddAttribute(node, isModal);
                XmlAttribute bounds = ts.CreateAttribute(doc, "bounds", window.Bounds.ToString());
                node = ts.AddAttribute(node, bounds);

                itemPath = $"{itemPath}{windowName}.xml";

                XmlAttribute url = ts.CreateAttribute(doc, "url", itemPath);
                node = ts.AddAttribute(node, url);

                //baseNode.AppendChild(node);
                //doc = ts.AddNode(doc, baseNode);

                doc = ts.AddNode(doc, node);
                doc.Save(windowPath);
                Console.WriteLine("New Window Added");
                serializeWindowItems(window, windowName, itemPath);
                return;
            }
            Console.WriteLine("Window Already Added");
        }