Ejemplo n.º 1
0
        private void dodajElementAsync(object obj)
        {
            Klient klient = obj as Klient;

            db.DodajElement(klient);
        }
Ejemplo n.º 2
0
        public static void serializuj(Element obj)
        {
            try
            {
                string      connectionsPath = Properties.Settings.Default.baseXmlPath;
                XmlDocument xml             = new XmlDocument();

                xml.Load(connectionsPath);
                XmlNode rootNode = xml["Connections"];

                XmlNode connectNode = xml.CreateElement(obj.GetType().Name);

                connectNode.Attributes.Append(xml.CreateAttribute("Id"));
                connectNode.Attributes.Append(xml.CreateAttribute("Group"));
                connectNode.Attributes.Append(xml.CreateAttribute("Name"));
                connectNode.Attributes.Append(xml.CreateAttribute("Type"));
                connectNode.Attributes.Append(xml.CreateAttribute("Description"));

                connectNode.Attributes["Id"].InnerText = obj.id.ToString();

                if (obj.parent is Folder)
                {
                    connectNode.Attributes["Group"].InnerText = (obj.parent as Folder).id.ToString();
                }
                else if (!string.IsNullOrWhiteSpace(obj.group))
                {
                    connectNode.Attributes["Group"].InnerText = obj.group;
                }
                else
                {
                    connectNode.Attributes["Group"].InnerText = "";
                }

                connectNode.Attributes["Description"].InnerText = obj.opis;

                if (obj is Klient)
                {
                    Klient klient = (Klient)obj;

                    connectNode.Attributes["Type"].InnerText = "Klient";
                    connectNode.Attributes["Name"].InnerText = klient.nazwa;


                    XmlNode emails = xml.CreateElement("Emails");

                    for (int i = 0; i < klient.emailList.Count; i++)
                    {
                        XmlNode email = xml.CreateElement("Email");
                        email.Attributes.Append(xml.CreateAttribute("Address"));
                        email.Attributes["Address"].InnerText = klient.emailList[i].adresEmail;
                        emails.AppendChild(email);
                    }

                    connectNode.AppendChild(emails);


                    XmlNode phones = xml.CreateElement("Phones");

                    for (int i = 0; i < klient.telefonList.Count; i++)
                    {
                        XmlNode phone = xml.CreateElement("Phone");
                        phone.Attributes.Append(xml.CreateAttribute("Name"));
                        phone.Attributes.Append(xml.CreateAttribute("Number"));
                        phone.Attributes["Name"].InnerText   = klient.telefonList[i].nazwa;
                        phone.Attributes["Number"].InnerText = klient.telefonList[i].numer;
                        phones.AppendChild(phone);
                    }

                    connectNode.AppendChild(phones);


                    XmlNode credentials = xml.CreateElement("Credentials");

                    for (int i = 0; i < klient.daneLogowaniaList.Count; i++)
                    {
                        XmlNode credential = xml.CreateElement("Credential");
                        credential.Attributes.Append(xml.CreateAttribute("Login"));
                        credential.Attributes.Append(xml.CreateAttribute("Password"));
                        credential.Attributes.Append(xml.CreateAttribute("Type"));
                        credential.Attributes["Login"].InnerText    = klient.daneLogowaniaList[i].login;
                        credential.Attributes["Password"].InnerText = klient.daneLogowaniaList[i].haslo;
                        credential.Attributes["Type"].InnerText     = klient.daneLogowaniaList[i].system;
                        credentials.AppendChild(credential);
                    }
                    connectNode.AppendChild(credentials);
                }
                else if (obj is Folder) // if obj is Folder
                {
                    connectNode.Attributes["Type"].InnerText = "Folder";
                    connectNode.Attributes["Name"].InnerText = obj.nazwa;
                }
                else if (obj is TeamViewer)
                {
                    TeamViewer tv = obj as TeamViewer;
                    connectNode.Attributes.Append(xml.CreateAttribute("TeamViewerId"));
                    connectNode.Attributes.Append(xml.CreateAttribute("Password"));

                    connectNode.Attributes["Name"].InnerText         = tv.nazwa;
                    connectNode.Attributes["Type"].InnerText         = "TeamViewer";
                    connectNode.Attributes["TeamViewerId"].InnerText = tv.teamViewerId;
                    if (string.IsNullOrWhiteSpace(tv.haslo))
                    {
                        tv.haslo = Properties.Settings.Default.defaultPasswordOfTeamViewer;
                    }
                    connectNode.Attributes["Password"].InnerText = tv.haslo;
                }
                else if (obj is Rdp)
                {
                    Rdp rdp = obj as Rdp;
                    connectNode.Attributes.Append(xml.CreateAttribute("Address"));
                    connectNode.Attributes.Append(xml.CreateAttribute("Login"));
                    connectNode.Attributes.Append(xml.CreateAttribute("Password"));

                    connectNode.Attributes["Name"].InnerText     = rdp.nazwa;
                    connectNode.Attributes["Type"].InnerText     = "Rdp";
                    connectNode.Attributes["Address"].InnerText  = rdp.adresRDP;
                    connectNode.Attributes["Login"].InnerText    = rdp.login;
                    connectNode.Attributes["Password"].InnerText = rdp.haslo;
                }


                rootNode.AppendChild(connectNode);

                xml.Save(connectionsPath);
            }
            catch (Exception ex)
            {
                MyMessageBox.Show("Treść błędu: \n" + ex.Message, "Wystąpił nieoczekiwany błąd", MyMessageBoxButtons.Ok);
            }
        }