Ejemplo n.º 1
0
        private void pobierz(object browser)
        {
            System.Windows.Forms.WebBrowser bro = browser as System.Windows.Forms.WebBrowser;

            HtmlElementCollection coll = null;
            bool gotowy = false;

loop:
            try
            {
                bro.Invoke(new Action(() => { coll = bro.Document.GetElementsByTagName("span"); }));
                foreach (HtmlElement h in coll)
                {
                    if (h.InnerText == "DOKUMENT WYGENEROWANY")
                    {
                        gotowy = true;
                    }
                }
            }
            catch { goto loop; }
            if (gotowy == false)
            {
                goto loop;
            }

            HtmlElementCollection colls = null;


            bro.Invoke(new Action(() =>
            {
                try
                {
                    colls = bro.Document.GetElementsByTagName("a");
                    HtmlElementCollection szukajNazwy = bro.Document.GetElementsByTagName("span");
                    string nazwa = null;
                    foreach (HtmlElement span in szukajNazwy)
                    {
                        if (span.InnerText.ToString().Contains(".SWX"))
                        {
                            nazwa = span.InnerText.Substring(0, span.InnerText.Length - 4);
                        }
                    }

                    foreach (HtmlElement h in colls)
                    {
                        if (h.InnerText == "pobierz plik")
                        {
                            progressBar.Value++;

                            Uri url = new Uri(h.GetAttribute("href").ToString());

                            HttpWebRequest wr  = (HttpWebRequest)WebRequest.Create(url);
                            wr.Credentials     = CredentialCache.DefaultCredentials;
                            wr.CookieContainer = new CookieContainer();
                            Cookie cookie      = getCookie(bro.Document.Cookie);
                            wr.CookieContainer.Add(cookie);


                            HttpWebResponse ws = (HttpWebResponse)wr.GetResponse();

                            Stream stream = ws.GetResponseStream();

                            Stream output = new FileStream(sciezkaZapisu + "\\" + nazwa + ".SWZ", FileMode.OpenOrCreate);

                            stream.CopyTo(output);

                            stream.Close();
                            output.Close();


                            HtmlElementCollection inputs = bro.Document.GetElementsByTagName("input");

                            foreach (HtmlElement ht in inputs)
                            {
                                if (ht.GetAttribute("value").ToString() == "Zakończ →")
                                {
                                    webBrowser1.DocumentCompleted += webBrowser1_DocumentCompleted6;
                                    ht.InvokeMember("Click");
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    MyMessageBox.Show("Treść błędu:\n" + ex.Message, "Błąd", MyMessageBoxButtons.Ok);
                    progressLabel.Content = "";
                    return;
                }
            }
                                  ));
        }
Ejemplo n.º 2
0
        public static List <Element> deserializuj(String file)
        {
            try
            {
                XmlDocument     xml      = new XmlDocument();
                List <Element>  elementy = new List <Element>();
                Queue <Element> queue    = new Queue <Element>();
                XmlNodeList     nodeList;

                List <XmlNode>  connectionsNodes = new List <XmlNode>();
                Queue <Element> childrenNodes    = new Queue <Element>();

                List <Element> elementyNaLiscie = new List <Element>();

                while (true)
                {
                    try
                    {
                        xml.Load(file);

                        break;
                    }
                    catch (Exception)
                    {
                        MyMessageBox.Show(" o ");
                    }
                }

                if (xml.ChildNodes[0] != null)
                {
                    nodeList = xml.ChildNodes[0].ChildNodes;
                }
                else
                {
                    MyMessageBox.Show("Plik XML jest uszkodzony, brakuje głównego węzła Connections");
                    return(elementy);
                }

                foreach (XmlNode node in nodeList)
                {
                    Element element = null;

                    switch (node.Attributes["Type"].InnerText)
                    {
                    case "Folder":
                        deserializujFolder(node, out element);
                        break;

                    case "Klient":
                        deserializujKlienta(node, out element);
                        break;

                    case "TeamViewer":
                        deserializujTeamViewer(node, out element);
                        break;

                    case "Rdp":
                        deserializujRdp(node, out element);
                        break;

                    case "WebBrowser":
                        deserializujWebBrowser(node, out element);
                        break;

                    default:
                        break;
                    }

                    if (string.IsNullOrWhiteSpace(element.group))
                    {
                        elementy.Add(element);
                        elementyNaLiscie.Add(element);
                    }
                    else
                    {
                        childrenNodes.Enqueue(element);
                    }
                }

                while (childrenNodes.Count > 0)
                {
                    Element tempElement = null;
                    var     fol         = childrenNodes.Dequeue();

                    if (elementyNaLiscie.Any(f => f.id == fol.group))
                    {
                        tempElement = elementyNaLiscie.Single(f => f.id == fol.group);
                        tempElement.Items.Add(fol);
                        elementyNaLiscie.Add(fol);
                    }
                    else
                    {
                        childrenNodes.Enqueue(fol);
                    }
                }

                elementy = elementy.OrderBy(e => e.nazwa).ToList();
                return(elementy);
            }
            catch (Exception ex)
            {
                MyMessageBox.Show("Treść błędu: \n" + ex.Message, "Wystąpił nieoczekiwany błąd", MyMessageBoxButtons.Ok);
                return(null);
            }
        }
Ejemplo n.º 3
0
        private void zapisz()
        {
            Regex reg = new Regex(@"^[A-ZĄĆĘŁŃÓŚŹŻa-ząćęłńóśźż0-9 ]*$");

            if (string.IsNullOrWhiteSpace(rodzajComboBox.Text) ||
                string.IsNullOrWhiteSpace(nazwaTextBox.Text) ||
                string.IsNullOrWhiteSpace(loginTextBox.Text) ||
                string.IsNullOrWhiteSpace(hasloTextBox.Text))
            {
                MessageBox.Show("Uzupełnij wszystkie pola!", "Błąd", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            else if (!reg.IsMatch(nazwaTextBox.Text))
            {
                MyMessageBox.Show("Wprowadzono nieprawidłowe znaki w pole nazwy");
            }
            else
            {
                if (thisRemoteId == null)// dodanie nowego połączenia
                {
                    //############# DODAJ TEAMVIEWER ###############################################################################
                    if (rodzajComboBox.Text == "TeamViewer")
                    {
                        Serializator.serializuj(new TeamViewer(nazwaTextBox.Text, klientId, "", hasloTextBox.Text, "TeamViewer", loginTextBox.Text));
                    }

                    //############# DODAJ RDP ###############################################################################
                    else if (rodzajComboBox.Text == "RDP")
                    {
                        if (!string.IsNullOrWhiteSpace(adresTextBox.Text))
                        {
                            Serializator.serializuj(new Rdp(nazwaTextBox.Text, klientId, "", hasloTextBox.Text, "Rdp", adresTextBox.Text, loginTextBox.Text));
                        }
                        else
                        {
                            MessageBox.Show("Uzupełnij wszystkie pola!", "Błąd", MessageBoxButton.OK, MessageBoxImage.Warning);
                            return;
                        }
                    }
                }
                else// edycja połączenia
                {
                    XmlDocument xml = new XmlDocument();

                    xml.Load(Properties.Settings.Default.baseXmlPath);

                    XmlNodeList connectionsNodes = null;

                    if (xml.ChildNodes[0] != null)
                    {
                        connectionsNodes = xml.ChildNodes[0].ChildNodes;
                    }
                    else
                    {
                        MyMessageBox.Show("Plik XML jest uszkodzony, brakuje głównego węzła Connections");
                    }

                    XmlNodeList remoteNodes;
                    if (rodzajComboBox.SelectedIndex == 0)
                    {
                        remoteNodes = xml.GetElementsByTagName("TeamViewer");
                    }
                    else
                    {
                        remoteNodes = xml.GetElementsByTagName("Rdp");
                    }

                    foreach (XmlNode node in remoteNodes)
                    {
                        if (node.Attributes["Id"].InnerText == thisRemoteId)
                        {
                            if (node.Attributes["Type"].InnerText == "TeamViewer")
                            {
                                node.Attributes["Name"].InnerText         = nazwaTextBox.Text;
                                node.Attributes["Password"].InnerText     = hasloTextBox.Text;
                                node.Attributes["TeamViewerId"].InnerText = loginTextBox.Text;
                            }
                            else if (node.Attributes["Type"].InnerText == "Rdp")
                            {
                                node.Attributes["Name"].InnerText     = nazwaTextBox.Text;
                                node.Attributes["Address"].InnerText  = adresTextBox.Text;
                                node.Attributes["Login"].InnerText    = loginTextBox.Text;
                                node.Attributes["Password"].InnerText = hasloTextBox.Text;
                            }
                        }
                    }
                    xml.Save(Properties.Settings.Default.baseXmlPath);
                }

                MainWindow.aktualizujTreeView(MainWindow.listOfClients);
                this.Close();
            }
        }
Ejemplo n.º 4
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);
            }
        }