Beispiel #1
0
        bool IGestoreImpostazione.RemoveImpostazione(ImpostazioneTrasferimento impostazione)
        {
            bool toOut = _impostazioni.Remove(impostazione);

            if (toOut)
            {
                //Creazione dei parametri da passare agli handler dell'evento
                ActionCompletedEvent args = new ActionCompletedEvent
                {
                    ToEntry = EntryFactory.CreateEntry(this, "rimossa", impostazione.CartellaSorgente.Path,
                                                       impostazione.CartellaDestinazione)
                };
                PersistEvent toPersist = new PersistEvent
                {
                    Action    = "rimuovi",
                    ToPersist = impostazione
                };

                //Scateno l'evento
                ToLog?.Invoke(this, args);
                Persist?.Invoke(this, toPersist);
            }
            else
            {
                ActionCompletedEvent args = new ActionCompletedEvent
                {
                    ToEntry = EntryFactory.CreateEntry(this, "nonrimossa", impostazione.CartellaSorgente.Path,
                                                       impostazione.CartellaDestinazione)
                };
                ToLog?.Invoke(this, args);
            }
            return(toOut);
        }
Beispiel #2
0
        public bool AddImpostazione(ImpostazioneTrasferimento impostazione)
        {
            bool toOut = _impostazioni.Add(impostazione);

            //Il log cambia a seconda dell'esito
            if (toOut)
            {
                //Creazione del parametro da passare quando scateno l'evento
                ActionCompletedEvent args = new ActionCompletedEvent
                {
                    ToEntry = EntryFactory.CreateEntry(this, "aggiunta", sorgente: impostazione.CartellaSorgente.Path,
                                                       destinazione: impostazione.CartellaDestinazione)
                };
                PersistEvent toPersist = new PersistEvent
                {
                    ToPersist = impostazione,
                    Action    = "aggiungi"
                };
                //scateno gli handler registrati all'evento
                ToLog?.Invoke(this, args);
                Persist?.Invoke(this, toPersist);
            }
            else
            {
                ActionCompletedEvent args = new ActionCompletedEvent
                {
                    ToEntry = EntryFactory.CreateEntry(this, "nonaggiunta", impostazione.CartellaSorgente.Path,
                                                       impostazione.CartellaDestinazione)
                };
                ToLog?.Invoke(this, args);
            }
            return(toOut);
        }
Beispiel #3
0
 private Entry ReadEntry(CalithaBinReader reader)
 {
     Entry entry = EntryFactory.CreateEntry(reader);
     if (entry == null)
         throw new CGTStructureException("Invalid entry type at byte "+(stream.Position-1));
     return entry;
 }
 public void Visit(Cartella cartella)
 {
     if (cartella.Children.Count > 0)
     {
         //Creo la stringa del path da ricreare
         string dirname   = new DirectoryInfo(cartella.Path).Name;
         string dirToSync = String.Join("\\", _pathDestinazione, dirname);
         //Creo la cartella richiesta se non esiste
         if (!Directory.Exists(dirToSync))
         {
             Directory.CreateDirectory(dirToSync);
             ActionCompletedEvent args = new ActionCompletedEvent
             {
                 ToEntry = EntryFactory.CreateEntry(this, "creata cartella",
                                                    sorgente: cartella.Path, destinazione: dirToSync)
             };
             ToLog?.Invoke(this, args);
         }
         //Memorizzo il vecchio path per quando ho finito di ispezionare i figli
         string oldPath = _pathDestinazione;
         //Il nuovo path è quello di questa cartella
         _pathDestinazione = dirToSync;
         //Entro e sincronizzo le sottocartelle usando il nuovo path
         foreach (FilesystemElement element in cartella.Children)
         {
             element.Accept(this);
         }
         //Ripristino il path vecchio =>(..)
         _pathDestinazione = oldPath;
     }
 }
Beispiel #5
0
 public void RimuoviUtente(string utente)
 {
     if (_blacklist.EliminaUtenteCattivo(utente))
     {
         //Creazione del parametro da passare quando scateno l'evento
         ActionCompletedEvent args = new ActionCompletedEvent
         {
             ToEntry = EntryFactory.CreateEntry(this, "rimosso", utente)
         };
         //scateno gli handler registrati all'evento
         PersistEvent toPersist = new PersistEvent
         {
             Action    = "rimuovi",
             ToPersist = utente
         };
         //scateno gli handler registrati all'evento
         ToLog?.Invoke(this, args);
         Persist?.Invoke(this, toPersist);
     }
     else
     {
         //Creazione del parametro da passare quando scateno l'evento
         ActionCompletedEvent args = new ActionCompletedEvent
         {
             ToEntry = EntryFactory.CreateEntry(this, "nonrimosso", utente)
         };
         //scateno gli handler registrati all'evento
         ToLog?.Invoke(this, args);
     }
 }
Beispiel #6
0
 public void AggiungiUtente(string utente)
 {
     if (_blacklist.AggiungiUtenteCattivo(utente))
     {
         //Col fatto che questa viene chiamata dal thread della sincronizzazione va
         //Risolto con l'escamotage
         _blacklistView.AddRow(utente);
         //_blacklistView.DataGridViewBlacklist.Rows.Add(utente);
         //Creazione del parametro da passare quando scateno l'evento
         ActionCompletedEvent args = new ActionCompletedEvent
         {
             ToEntry = EntryFactory.CreateEntry(this, "aggiunto", utente)
         };
         PersistEvent toPersist = new PersistEvent
         {
             Action    = "aggiungi",
             ToPersist = utente
         };
         //scateno gli handler registrati all'evento
         ToLog?.Invoke(this, args);
         Persist?.Invoke(this, toPersist);
     }
     else
     {
         //Creazione del parametro da passare quando scateno l'evento
         ActionCompletedEvent args = new ActionCompletedEvent
         {
             ToEntry = EntryFactory.CreateEntry(this, "nonaggiunto", utente)
         };
         //scateno gli handler registrati all'evento
         ToLog?.Invoke(this, args);
     }
 }
        private Entry ReadEntry(ReaderBin reader)
        {
            Entry entry = EntryFactory.CreateEntry(reader);

            if (entry == null)
            {
                throw new CGTStructureException("Invalid entry type at byte " + (stream.Position - 1));
            }
            return(entry);
        }
Beispiel #8
0
        static void Main(string[] args)
        {
            var jrePath = Environment.GetEnvironmentVariable("JAVA_HOME");
            var entry   = EntryFactory.CreateEntry(Path.Combine(jrePath, "jre", "*"));
            var data    = entry.ReadClass("java.lang.Object");

            Console.WriteLine(data);
            var reader = new ClassReader(data);//@"E:\workcode\zbj\八戒招聘\hr-saas\zbj-zhaopin-admin\zbj-hr-saas-web-manage-ui\target\classes\com\zbj\hr\listener\TaskServlet.class"

            Console.WriteLine("jvm class magic:{0}", reader.ReadU4());
        }
Beispiel #9
0
        public CompositeEntry(string path)
        {
            var paths = path.Split(Path.PathSeparator, StringSplitOptions.RemoveEmptyEntries);

            entries = new IEntry[paths.Length];
            for (var i = 0; i < paths.Length; i++)
            {
                var entryPath = paths[i];
                entries[i] = EntryFactory.CreateEntry(entryPath);
            }
        }
Beispiel #10
0
        public void EntryProcessesCountiresNamesOnCreation()
        {
            var countriesToProcess = new Dictionary <string, string>()
            {
                { " Azerbaijan", "Azerbaijan" },
                { "Russian Federation", "Russia" },
                { "Viet Nam", "Vietnam" },
                { "United Kingdom", "UK" },
                { "Taiwan*", "Taiwan" },
                { "Gambia, The", "Gambia" },
                { "The Gambia", "Gambia" },
                { "Korea, South", "South Korea" },
                { "Macao SAR", "China" },
                { "Iran (Islamic Republic of)", "Iran" },
                { "Hong Kong SAR", "China" },
                { "Bahamas, The", "Bahamas" },
                { "The Bahamas", "Bahamas" },
                { "Mainland China", "China" },
                { "Taipei and environs", "Taiwan" },
                { "St. Martin", "France" },
                { "Republic of the Congo", "Congo (Brazzaville)" },
                { "Republic of Moldova", "Moldova" },
                { "Republic of Ireland", "Ireland" },
            };

            foreach (var(countryFromReport, actualCountryName) in countriesToProcess)
            {
                var row = new Row(new[]
                {
                    new Field(FieldId.CountryRegion, countryFromReport),
                }, RowVersion.JHopkinsV1);

                Assert.That(_factory.CreateEntry(row).CountryRegion, Is.EqualTo(actualCountryName));
            }
        }
Beispiel #11
0
        public WildcardEntry(string path)
        {
            var realPath = path.TrimEnd('*');
            var jars     = Directory.GetFiles(realPath, "*.*", SearchOption.AllDirectories).Where(f => f.EndsWith(".jar", StringComparison.OrdinalIgnoreCase) || f.EndsWith(".zip", StringComparison.OrdinalIgnoreCase)).ToArray();

            entries    = new IEntry[jars.Length + 1];
            entries[0] = EntryFactory.CreateEntry(realPath);
            for (var i = 0; i < jars.Length; i++)
            {
                var entryPath = jars[i];
                entries[i + 1] = EntryFactory.CreateEntry(entryPath);
            }
        }
Beispiel #12
0
        private List <Section> GetStaticSections(string xmlString)
        {
            List <Section> sections = new List <Section>();

            //var utf8 = Encoding.GetEncoding("UTF-8");

            var document = ResourceHelper.GetNotesStaticText();

            var parameters = new Params {
                Year = Godina
            };

            foreach (var element in document.Root.Descendants("Sections").First().Descendants("Section"))
            {
                Entry entry = EntryFactory.CreateEntry(element, parameters);
                if (entry != null)
                {
                    sections.Add((Section)entry);
                }
            }

            return(sections);
        }
Beispiel #13
0
        public void TestReturnType()
        {
            Entry entry = EntryFactory.CreateEntry(new ImpostazioneTrasferimento.ImpostazioneTrasferimentoController(), "ciao");

            Assert.IsInstanceOf(new EntryImpostazione("cioa", "mi", "u").GetType(), entry);
        }
        public void Visit(FileWrapper file)
        {
            FileInfo source      = new FileInfo(file.Path);
            String   fileDstPath = String.Join("\\", _pathDestinazione, source.Name);

            //Trovo l'autore del file
            string author = File.GetAccessControl(file.Path).GetOwner(typeof(System.Security.Principal.NTAccount)).ToString();

            //Prova va spostato sotto

            if (!author.Equals(string.Join("\\", Utente.GetNomeHost(), Utente.GetNomeUtente())))
            {
                if (!_blacklistController.IsBlackListed(author))
                {
                    bool riconosciuto = _viewHome.ChiediScelta(author);
                    if (riconosciuto)
                    {
                        //Se esiste Confronto gli hash se sono diversi sincronizzo
                        if (File.Exists(fileDstPath))
                        {
                            var    sourceStream = new FileStream(file.Path, FileMode.Open, FileAccess.Read);
                            String srcSum       = GetChecksumBuffered(sourceStream);
                            var    dstStream    = new FileStream(fileDstPath, FileMode.Open, FileAccess.Read);
                            String dstSum       = GetChecksumBuffered(dstStream);

                            //Se gli hash non sono uguali
                            if (!srcSum.Equals(dstSum))
                            {
                                File.Copy(file.Path, fileDstPath);
                                ActionCompletedEvent args = new ActionCompletedEvent
                                {
                                    ToEntry = EntryFactory.CreateEntry(this, "file copiato", sorgente: file.Path, destinazione: fileDstPath)
                                };
                                ToLog?.Invoke(this, args);
                            }
                        }
                        //Copio diretto
                        else
                        {
                            File.Copy(file.Path, fileDstPath);
                            ActionCompletedEvent args = new ActionCompletedEvent
                            {
                                ToEntry = EntryFactory.CreateEntry(this, "file copiato", sorgente: file.Path, destinazione: fileDstPath)
                            };
                            ToLog?.Invoke(this, args);
                        }
                    }
                    else
                    {
                        _blacklistController.AggiungiUtente(author);
                        //Elimino il file
                        File.Delete(file.Path);
                        ActionCompletedEvent args = new ActionCompletedEvent
                        {
                            ToEntry = EntryFactory.CreateEntry(this, "file eliminato", sorgente: file.Path)
                        };
                        ToLog?.Invoke(this, args);
                    }
                }
            }
            //Il file è del proprietario non c'è bisogno di chiamare la blacklist
            else
            {
                if (File.Exists(fileDstPath))
                {
                    var    sourceStream = new FileStream(file.Path, FileMode.Open, FileAccess.Read);
                    String srcSum       = GetChecksumBuffered(sourceStream);
                    var    dstStream    = new FileStream(fileDstPath, FileMode.Open, FileAccess.Read);
                    String dstSum       = GetChecksumBuffered(dstStream);

                    //Se gli hash non sono uguali
                    if (!srcSum.Equals(dstSum))
                    {
                        ActionCompletedEvent args = new ActionCompletedEvent
                        {
                            ToEntry = EntryFactory.CreateEntry(this, "file copiato", sorgente: file.Path, destinazione: fileDstPath)
                        };
                        ToLog?.Invoke(this, args);
                        File.Copy(file.Path, fileDstPath);
                    }
                }
                //Copio diretto
                else
                {
                    ActionCompletedEvent args = new ActionCompletedEvent
                    {
                        ToEntry = EntryFactory.CreateEntry(this, "file copiato", sorgente: file.Path, destinazione: fileDstPath)
                    };
                    ToLog?.Invoke(this, args);
                    File.Copy(file.Path, fileDstPath);
                }
            }
        }
Beispiel #15
0
        public ModelLog.Log LeggiLog()
        {
            ModelLog.Log log = new ModelLog.Log();
            try
            {
                using (StreamReader readtext = new StreamReader(_filename))
                {
                    string readMeText = null;
                    while ((readMeText = readtext.ReadLine()) != null)
                    {
                        //  29 / 06 / 2018 09:14:20 Blacklist aggiunto DESKTOP-TF7TLNM\massi    riccardo
                        //  29 / 06 / 2018 09:14:20 Impostazione aggiunta    DESKTOP - TF7TLNM\massi mydir   yourDir
                        //Esempio righe da parsare

                        //Parsing della parte fissa.
                        string[] fields     = readMeText.Split('\t');
                        string[] dateHour   = fields[0].Split(' ');
                        string   date       = dateHour[0];
                        string   hour       = dateHour[1];
                        string   entryType  = fields[1];
                        string   operazione = fields[2];
                        string   utente     = fields[3];

                        //Assegno i parametri che variano
                        switch (entryType)
                        {
                        case ("Blacklist"):
                            string badUser = fields[4];
                            log.AddEntry(EntryFactory.CreateEntry(entryType, operazione, date, hour,
                                                                  utenteMalevolo: badUser, utenteProprietario: Utente.GetNomeUtente()));
                            break;

                        case ("Impostazione"):
                            string sorgente     = fields[4];
                            string destinazione = fields[5];
                            log.AddEntry(EntryFactory.CreateEntry(entryType, operazione, date, hour,
                                                                  sorgente: sorgente, destinazione: destinazione));
                            break;

                        case ("Sincronizzazione"):
                            string source = fields[4];
                            if (operazione.Equals("file eliminato"))
                            {
                                log.AddEntry(EntryFactory.CreateEntry(entryType, operazione, date, hour,
                                                                      sorgente: source));
                            }
                            else
                            {
                                string dst = fields[5];
                                log.AddEntry(EntryFactory.CreateEntry(entryType, operazione, date, hour,
                                                                      sorgente: source, destinazione: dst));
                            }
                            break;
                        }
                    }
                }
            }catch (Exception e)
            {
            }
            return(log);
        }