Exemple #1
0
        // CsvCrt - vytvoreni souboru ".MyGit.Cvs.Csv" pro adresar pol, inicializace: Verze=1
        public static void CsvCrt(DirectoryInfo pol, string searchPattern)
        {
            Console.WriteLine("adresář: {0} - nový adresář, žádné změny", pol.Name);
            // Zaznamy
            List <GitFormat> records = new List <GitFormat>();
            GitFormat        record  = new GitFormat();

            // adresare
            foreach (DirectoryInfo d in pol.GetDirectories())
            {
                record = new GitFormat(d, PrvniV);
                records.Add(record);
            }
            // soubory
            foreach (FileInfo f in pol.GetFiles(searchPattern))
            {
                // Console.WriteLine("File: " + f.FullName + " Name" + f.Name);
                if (f.Name != MyGitFlNm)
                {
                    record = new GitFormat(f, PrvniV);
                    records.Add(record);
                }
            } // for each
            // ulozeni souboru ".MyGit.Cvs.Csv"
            //Console.WriteLine("Git File: " + pol.FullName + @"\" + MyGitFlNm);
            using (var writer = new StreamWriter(pol.FullName + @"\" + MyGitFlNm))
                using (var csv = new CsvWriter(writer, CultureInfo.InvariantCulture)) {
                    csv.WriteRecords(records);
                }
        }
Exemple #2
0
 // CsvChk - porovna 1 soubor, "GitFormat record" vs. "DictGit[record.Name]"
 public static void CsvChk(GitFormat record, List <GitFormat> recsNew, List <GitFormat> recsDel,
                           List <GitFormat> recsUpd, List <GitFormat> recsVer, SortedDictionary <string, GitFormat> DictGit)
 {
     // neni jmeno ".MyGit.Cvs.Csv"
     if (record.Name != MyGitFlNm)
     {
         // kontrola vuci dict
         if (DictGit.ContainsKey(record.Name))
         {
             GitFormat recDict = DictGit[record.Name];
             // vezmu revizi z dict
             record.Version = recDict.Version;
             // klic existuje
             if (record.Equals(recDict))
             {
                 // zaznam nezmenen
             }
             else
             {
                 // navyseni verze
                 record.Plus1();
                 recsVer.Add(record);
             }
             // Pridani a zruseni ze seznamu nalezenych
             recsUpd.Add(record);
             DictGit.Remove(record.Name);
         }
         else
         {
             // novy adresar
             recsNew.Add(record);
             recsUpd.Add(record);
         }
     }
 }
Exemple #3
0
        // CsvChk - porovnani souboru ".MyGit.Cvs.Csv" vuci adresari pol
        public static void CsvChk(DirectoryInfo pol, string searchPattern)
        {
            //Console.WriteLine("CsvChk : Directory {0}", pol.Name);
            // CsvCti - Cteni souboru ".MyGit.Cvs.Csv"
            SortedDictionary <string, GitFormat> DictGit = CsvCti(pol, Hvezda, false);
            // Zaznamy
            List <GitFormat> recsNew = new List <GitFormat>(); // nove
            List <GitFormat> recsDel = new List <GitFormat>(); // smazane
            List <GitFormat> recsUpd = new List <GitFormat>(); // pro ulozeni aktualizace
            List <GitFormat> recsVer = new List <GitFormat>(); // Verze++
            GitFormat        record  = new GitFormat();

            // adresare porovnej
            foreach (DirectoryInfo d in pol.GetDirectories())
            {
                record = new GitFormat(d, PrvniV);
                CsvChk(record, recsNew, recsDel, recsUpd, recsVer, DictGit);
            }
            // soubory porovnej
            foreach (FileInfo f in pol.GetFiles(searchPattern))
            {
                record = new GitFormat(f, PrvniV);
                CsvChk(record, recsNew, recsDel, recsUpd, recsVer, DictGit);
            }

            /*
             * [A] = added (nový soubor)
             * [M] = modified (změněný soubor)
             * [D] = deleted (odstraněný soubor)
             */
            // Protokol
            if (!((recsNew.Count == 0) && (recsVer.Count == 0) && (DictGit.Count == 0)))
            {
                Console.WriteLine("\n\t adresář: " + pol.Name + " - změny");
                // seznam novych
                if (recsNew.Count > 0)
                {
                    Console.WriteLine("\n\t [A] = added (nový soubor):");
                }
                ;
                foreach (GitFormat f in recsNew)
                {
                    Console.WriteLine("[A] Type: " + f.Type + "  Name: " + f.Name + "  Size: " + f.Size + "  DateTime: " + f.DateTime + "  Version: " + f.Version);
                }
                // seznam zmenenych
                if (recsVer.Count > 0)
                {
                    Console.WriteLine("\n\t [M] = modified (změněný soubor):");
                }
                foreach (GitFormat f in recsVer)
                {
                    Console.WriteLine("[M] Type: " + f.Type + "  Name: " + f.Name + "  Size: " + f.Size + "  DateTime: " + f.DateTime + "  Version: " + f.Version);
                }
                // seznam smazanych
                if (DictGit.Count > 0)
                {
                    Console.WriteLine("\n\t [D] = deleted (odstraněný soubor):");
                }
                foreach (KeyValuePair <string, GitFormat> entry in DictGit)
                {
                    // do something with entry.Value or entry.Key
                    GitFormat f = entry.Value;
                    Console.WriteLine("[D] Type: " + f.Type + "  Name: " + f.Name + "  Size: " + f.Size + "  DateTime: " + f.DateTime + "  Version: " + f.Version);
                }

                /*
                 * // seznam aktualnich
                 * Console.WriteLine("\n\t Seznam aktualnich:");
                 * foreach (GitFormat f in recsUpd) {
                 * Console.WriteLine("Type: " + f.Type + "  Name: " + f.Name + "  Size: " + f.Size + "  DateTime: " + f.DateTime + "  Version: " + f.Version);
                 * }  */
                // ulozeni aktualizace do  souboru ".MyGit.Cvs.Csv"
                // Console.WriteLine("Git File: " + pol.FullName + @"\" + MyGitFlNm);
                using (var writer = new StreamWriter(pol.FullName + @"\" + MyGitFlNm))
                    using (var csv = new CsvWriter(writer, CultureInfo.InvariantCulture)) {
                        csv.WriteRecords(recsUpd);
                    }
            }
            else
            {
                Console.WriteLine("\t adresář: " + pol.Name + " - žádná změna");
            }
        }