Example #1
0
        // Button Aggiorna Selezionati -> Tab creato dal file di configurazione XML
        private void BtnAggiornaXml_Clicked(object sender, EventArgs e)
        {
            ElementToSync el       = _toSync.Find(x => x.Name == ctlTab.SelectedTab.Text); // Get elemento da sincronizzare che corrisponde alla tab selezionata
            List <string> selected = listaXml.CheckedItems.Cast <string>().ToList();       // Get lista dei file selezionati

            if (el != null)
            {
                if (selected.Count() > 0)
                {
                    string command = el.Script + " ";
                    foreach (string name in selected)
                    {
                        command += name + " ";
                    }
                    commandLog = new CommandLog();
                    _sshConnection.ExecuteCommand(command, commandLog);
                    commandLog.Show();

                    ctlTab.SelectedTab.Controls.Clear();
                    ManageXmlTab(ctlTab.SelectedTab);
                }
                else
                {
                    MessageBox.Show("Non è stato selezionato alcun elemento", "Attenzione", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
        }
Example #2
0
        private void ManageXmlTab(TabPage selectedTab)
        {
            ElementToSync el = _toSync.Find(x => x.Name == selectedTab.Text); // Get elemento da sincronizzare che corrisponde alla tab selezionata

            if (el != null)
            {
                if (el.CommandLineArguments) // Di default è settato a false.
                {
                    // L'utente deve avere la possibilità di scegliere cosa aggiornare
                    Button selezionaCartella = new Button();
                    selezionaCartella.Text     = "Seleziona cartella";
                    selezionaCartella.Width    = 153;
                    selezionaCartella.Height   = 106;
                    selezionaCartella.Location = new System.Drawing.Point(279, 194);
                    selezionaCartella.UseVisualStyleBackColor = true;
                    selezionaCartella.Click += new EventHandler(SelezionaCartella_Clicked);

                    selectedTab.Controls.Add(selezionaCartella);
                }
                else
                {
                    // L'utente ha a disposizione un solo Button "Aggiorna Tutto" che semplicemente esegue el.Script
                    Button btnAggiornaTuttoXml = new Button();
                    btnAggiornaTuttoXml.Text     = "Aggiorna Tutto";
                    btnAggiornaTuttoXml.Width    = 153;
                    btnAggiornaTuttoXml.Height   = 106;
                    btnAggiornaTuttoXml.Location = new System.Drawing.Point(279, 194);
                    btnAggiornaTuttoXml.UseVisualStyleBackColor = true;
                    btnAggiornaTuttoXml.Click += new EventHandler(BtnAggiornaTuttoXml_Clicked);

                    selectedTab.Controls.Add(btnAggiornaTuttoXml);
                }
            }
        }
Example #3
0
        // Button Aggiorna Tutto -> Tab creato dal file di configurazione XML
        private void BtnAggiornaTuttoXml_Clicked(object sender, EventArgs e)
        {
            ElementToSync el = _toSync.Find(x => x.Name == ctlTab.SelectedTab.Text); // Get elemento da sincronizzare che corrisponde alla tab selezionata

            commandLog = new CommandLog();                                           // Creo finestra che mi mostrerà lo stato di avanzamento del comando
            _sshConnection.ExecuteCommand(el.Script, commandLog);                    // Eseguo comando
            commandLog.Show();
        }
Example #4
0
        private string AskDirectory(ElementToSync el, string initialDirectory)
        {
            string path = string.Empty;

            // Apri Dialog per permettere all'utente di selezionare la cartella
            CommonOpenFileDialog dialog = new CommonOpenFileDialog();

            dialog.InitialDirectory = initialDirectory;
            dialog.IsFolderPicker   = true;

            if (dialog.ShowDialog() == CommonFileDialogResult.Ok)
            {
                path = dialog.FileName;
            }
            else
            {
                path = "";
            }
            return(path);
        }
Example #5
0
        // Funzione per leggere il file di configurazione XML.

        /* FILE XML:
         * inizia con <toupdate>
         * All'interno di toupdate è possibile inserire qualsiasi script. es:
         * <Modelli3D>
         * All'interno di Modelli3D devo specificare:
         * - <script> : script usato [STRINGA]
         * - <commandlinearguments> : lo script va eseguito con o senza argomenti? [BOOLEANO]
         * Se lo script va eseguito con argomenti, bisogna aggiungere:
         * - <source> : dove vado a prendere i file che dovranno essere selezionati dall'utente? [STRINGA]
         * E' possibile inserire altri parametri, quali:
         * - <endswith> : come deve finire il nome del file (es. <endswith> <item>C.obj</item> </endswith>) [LISTA DI STRINGHE]
         * - <notendswith> : come non può finire il nome del file (es. <notendswith> <item>a.jpg</item><item>b.jpg</item> </notendswith> [LISTA DI STRINGHE]
         * - <searchrecursively> : i file devono essere ricercati anche nelle sottocartelle? [BOOLEANO]
         *
         */
        private void ReadXml()
        {
            _toSync = new List <ElementToSync>();

            XmlDocument xmlDoc = new XmlDocument();

            try
            {
                //xmlDoc.Load("sincro.xml");

                xmlDoc.Load(Path.GetDirectoryName(Application.ExecutablePath) + "\\sincro.xml");
            } catch (Exception ex)
            {
                MessageBox.Show("Errore apertura file di configurazione XML:\n" + ex);
                Environment.Exit(5);
            }

            foreach (XmlNode i in xmlDoc.ChildNodes)
            {
                if (i.LocalName == "toupdate")
                {
                    foreach (XmlNode item in i.ChildNodes)
                    {
                        string        name = item.LocalName, script = "", source = "";
                        bool          commandLineArguments = false, searchRecursively = false;
                        List <string> notEndsWith = new List <string>();
                        List <string> endsWith    = new List <string>();

                        foreach (XmlNode child in item.ChildNodes)
                        {
                            if (child.LocalName == "script")
                            {
                                script = child.FirstChild.Value;
                            }
                            else if (child.LocalName == "commandlinearguments")
                            {
                                commandLineArguments = Convert.ToBoolean(child.FirstChild.Value);
                            }
                            else if (child.LocalName == "source")
                            {
                                source = child.FirstChild.Value;
                            }
                            else if (child.LocalName == "searchrecursively")
                            {
                                searchRecursively = Convert.ToBoolean(child.FirstChild.Value);
                            }
                            else if (child.LocalName == "endswith")
                            {
                                foreach (XmlNode endsChild in child.ChildNodes)
                                {
                                    endsWith.Add(endsChild.FirstChild.Value);
                                }
                            }
                            else if (child.LocalName == "notendswith")
                            {
                                foreach (XmlNode notEndsChild in child.ChildNodes)
                                {
                                    notEndsWith.Add(notEndsChild.FirstChild.Value);
                                }
                            }
                        }
                        if (string.IsNullOrEmpty(script))
                        {
                            MessageBox.Show("Configurazione XML di " + name + ": è necessario inserire l'elemento <script>", "Errore", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                        else
                        {
                            ElementToSync el = new ElementToSync(name, script, commandLineArguments, source, searchRecursively, endsWith, notEndsWith);
                            _toSync.Add(el);
                        }
                    }
                }
            }

            // Creo un nuovo TAB per ogni elemento trovato nel file di configurazione
            foreach (ElementToSync el in _toSync)
            {
                TabPage newTab = new TabPage(el.Name);
                newTab.BackColor = System.Drawing.Color.WhiteSmoke;
                ctlTab.TabPages.Add(newTab);
            }
        }
Example #6
0
        private void SelezionaCartella_Clicked(object sender, EventArgs e)
        {
            ElementToSync el = _toSync.Find(x => x.Name == ctlTab.SelectedTab.Text);                        // Get elemento da sincronizzare che corrisponde alla tab selezionata

            string initialDirectory = @"\\xnfs\thema\" + el.Source.Replace("/mnt/", "").Replace("/", "\\"); // Setto directory iniziale Windows
            string path             = AskDirectory(el, initialDirectory);                                   // Genero finestra di scelta cartella e ritorno il path scelto dall'utente
            bool   isParent         = IsDirectoryParent(initialDirectory, path);                            // Controllo che il path sia valido (deve essere una subdir di initialDirectory o initialDirectory stessa)

            ctlTab.SelectedTab.Controls.Clear();

            if (!isParent) // Se il path non è valido, mostra il messaggio di errore ed esci
            {
                MessageBox.Show("La cartella selezionata non è valida.\nUsare una sottocartella della cartella " + initialDirectory + " o la cartella stessa.", "Attenzione", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                ManageXmlTab(ctlTab.SelectedTab);
            }
            else
            {
                // Genera a runtime gli elementi che permetteranno all'utente di selezionare i file ed aggiornarli/selezionare un'altra cartella

                // Label descrizione
                Label lblSelezionaFile = new Label();
                lblSelezionaFile.Text     = "Seleziona i file che vuoi aggiornare:";
                lblSelezionaFile.Width    = 200;
                lblSelezionaFile.Location = new System.Drawing.Point(260, 60);
                ctlTab.SelectedTab.Controls.Add(lblSelezionaFile);

                // Label "Cerca"
                Label lblCercaXml = new Label();
                lblCercaXml.Text     = "Cerca:";
                lblCercaXml.Width    = 40;
                lblCercaXml.Location = new System.Drawing.Point(237, 85);
                ctlTab.SelectedTab.Controls.Add(lblCercaXml);

                // Textbox di ricerca per l'implementazione del filtro
                TextBox boxRicercaXml = new TextBox();
                boxRicercaXml.Width    = 193;
                boxRicercaXml.Location = new System.Drawing.Point(290, 83);
                ctlTab.SelectedTab.Controls.Add(boxRicercaXml);
                boxRicercaXml.TextChanged += new EventHandler(BoxRicercaXml_TextChanged);

                // Lista di tutti gli elementi presenti nella cartella. E' possibile checkarli
                listaXml              = new CheckedListBox();
                listaXml.Width        = 253;
                listaXml.Height       = 244;
                listaXml.Location     = new System.Drawing.Point(230, 110);
                listaXml.CheckOnClick = true;
                ctlTab.SelectedTab.Controls.Add(listaXml);

                // Button per aggiornare i file selezionati
                Button btnAggiornaXml = new Button();
                btnAggiornaXml.Text     = "Aggiorna Selezionati";
                btnAggiornaXml.Width    = 153;
                btnAggiornaXml.Height   = 25;
                btnAggiornaXml.Location = new System.Drawing.Point(279, 385);
                btnAggiornaXml.UseVisualStyleBackColor = true;
                btnAggiornaXml.Click += new EventHandler(BtnAggiornaXml_Clicked);
                ctlTab.SelectedTab.Controls.Add(btnAggiornaXml);

                // Button per selezionare un'altra cartella
                Button btnSelezionaAltraCartella = new Button();
                btnSelezionaAltraCartella.Text     = "Seleziona Altra Cartella";
                btnSelezionaAltraCartella.Width    = 153;
                btnSelezionaAltraCartella.Height   = 25;
                btnSelezionaAltraCartella.Location = new System.Drawing.Point(279, 420);
                btnSelezionaAltraCartella.UseVisualStyleBackColor = true;
                btnSelezionaAltraCartella.Click += new EventHandler(BtnSelezionaAltraCartella_Clicked);
                ctlTab.SelectedTab.Controls.Add(btnSelezionaAltraCartella);

                // Codice per riempire la lista dei file presenti nella cartella scelta
                DirectoryInfo d        = new DirectoryInfo(path);
                string        toSearch = "*"; // Cerco qualsiasi file

                FileInfo[] files = null;
                try
                {
                    if (el.SearchRecursively)
                    {
                        files = d.GetFiles(toSearch, SearchOption.AllDirectories);
                    }
                    else
                    {
                        files = d.GetFiles(toSearch);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Non è stato possibile elencare i file nella cartella selezionata.\nErrore: " + ex, "Errore", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    ctlTab.SelectedTab.Controls.Clear();
                    ManageXmlTab(ctlTab.SelectedTab);
                    return;
                }

                if (files != null)
                {
                    _lsXml = new List <string>();
                    var fInOrder = files.OrderBy(x => x.Name); // Ordino i file per nome

                    foreach (FileInfo f in fInOrder)
                    {
                        if (el.NotEndsWith.Count > 0)
                        {
                            if (el.EndsWith.Count() > 0)
                            {
                                if (el.EndsWith.Any(s => f.Name.EndsWith(s)) && !el.NotEndsWith.Any(s => f.Name.EndsWith(s))) // Il filtraggio offerto da Windows non funziona bene in certi casi, me ne occupo io
                                {
                                    listaXml.Items.Add(f.Name);
                                    _lsXml.Add(f.Name);
                                }
                            }
                            else
                            {
                                if (!el.NotEndsWith.Any(s => f.Name.EndsWith(s)))
                                {
                                    listaXml.Items.Add(f.Name);
                                    _lsXml.Add(f.Name);
                                }
                            }
                        }
                        else
                        {
                            if (el.EndsWith.Count() > 0)
                            {
                                if (el.EndsWith.Any(s => f.Name.EndsWith(s))) // Il filtraggio offerto da Windows non funziona bene in certi casi, me ne occupo io
                                {
                                    listaXml.Items.Add(f.Name);
                                    _lsXml.Add(f.Name);
                                }
                            }
                            else
                            {
                                listaXml.Items.Add(f.Name);
                                _lsXml.Add(f.Name);
                            }
                        }
                    }
                }
            }
        }