Esempio n. 1
0
 static string GenTimetableJson(Parsers.TimetableOLD.Models.Timetable timetableResult)
 {
     // experimental 1.5 old json format
     Parsers.TimetableOLD2.Models.Timetable t = (Parsers.TimetableOLD2.Models.Timetable)timetableResult;
     if (forceDateNow)
     {
         t.Date = DateTime.Now;
     }
     Parsers.TimetableOLD3.Models.Timetable t3 = (Parsers.TimetableOLD3.Models.Timetable)t;
     return(JsonConvert.SerializeObject(t3));
 }
Esempio n. 2
0
        private void BParse_Click(object sender, EventArgs e)
        {
            // parsuj pliki z listboxów na typ stary Timetable
            string output;

            bUpload.Enabled = true;
            //try
            //{
            Parsers.TimetableOLD.Models.Timetable ParseNew()
            {
                //PLIKI .pwzim
                DateTime      lastDate      = new DateTime();
                List <string> filesContents = new List <string>();

                foreach (string filePath in lbNewFiles.Items)
                {
                    StreamReader streamReader = new StreamReader(filePath);
                    FileInfo     fileInfo     = new FileInfo(filePath);
                    if (fileInfo.LastWriteTime > lastDate)
                    {
                        lastDate = fileInfo.LastWriteTime;
                    }
                    filesContents.Add(streamReader.ReadToEnd());
                    streamReader.Close();
                }
                return((Parsers.TimetableOLD.Models.Timetable)Parsers.TimetableNew.Parser.ParseTimetableFiles(filesContents, lastDate));
            }

            Parsers.TimetableOLD.Models.Timetable ParseOld()
            {
                //PLIKI .txt
                List <string> filepaths = new List <string>();

                foreach (string fp in lbOldFiles.Items)
                {
                    filepaths.Add(fp);
                }
                return(Parsers.TimetableOLD.Parser.ParseTimetableFiles(filepaths));
            }

            if (lbNewFiles.Items.Count > 0 && lbOldFiles.Items.Count > 0)
            {
                Parsers.TimetableOLD.Models.Timetable tOLD  = ParseNew();
                Parsers.TimetableOLD.Models.Timetable tOLD2 = ParseOld();
                //merge
                Parsers.TimetableOLD.Models.Timetable tResult = tOLD.MergeTimetables(tOLD2);
                if (forceDateNow)
                {
                    tResult.Date = DateTime.Now;
                }
                timetableResult = tResult;

                output = JsonConvert.SerializeObject(tResult);
            }
            else if (lbNewFiles.Items.Count > 0)
            {
                Parsers.TimetableOLD.Models.Timetable tOLD = ParseNew();
                if (forceDateNow)
                {
                    tOLD.Date = DateTime.Now;
                }
                timetableResult = tOLD;

                output = JsonConvert.SerializeObject(tOLD);
            }
            else if (lbOldFiles.Items.Count > 0)
            {
                Parsers.TimetableOLD.Models.Timetable tOLD2 = ParseOld();
                if (forceDateNow)
                {
                    tOLD2.Date = DateTime.Now;
                }
                timetableResult = tOLD2;

                output = JsonConvert.SerializeObject(tOLD2);
            }
            else
            {
                output          = "Brak plików";
                bUpload.Enabled = false;
            }
            //}
            //catch (Exception ex)
            //{
            //    // jak są errory to przycisk upload na szaro
            //    output = ex.Message;
            //    bUpload.Enabled = false;
            //}
            // cały output (albo errory) do richboxa
            rtbOutput.Text = output;
            // zmiana label pochodzenie jsona na "z plików"
            label2.Text = "Json wygenereowany z plików:";
        }
Esempio n. 3
0
        static Parsers.TimetableOLD.Models.Timetable Parse(List <string> txts, List <string> pwzims)
        {
            if (txts.Count == 0 && pwzims.Count == 0)
            {
                throw new Exception("Nothing to parse!");
            }


            Parsers.TimetableOLD.Models.Timetable ParseNew()
            {
                //PLIKI .pwzim
                DateTime      lastDate      = new DateTime();
                List <string> filesContents = new List <string>();

                foreach (string filePath in pwzims)
                {
                    StreamReader streamReader = new StreamReader(filePath);
                    FileInfo     fileInfo     = new FileInfo(filePath);
                    if (fileInfo.LastWriteTime > lastDate)
                    {
                        lastDate = fileInfo.LastWriteTime;
                    }
                    filesContents.Add(streamReader.ReadToEnd());
                    streamReader.Close();
                }
                return((Parsers.TimetableOLD.Models.Timetable)Parsers.TimetableNew.Parser.ParseTimetableFiles(filesContents, lastDate));
            }

            Parsers.TimetableOLD.Models.Timetable ParseOld()
            {
                return(Parsers.TimetableOLD.Parser.ParseTimetableFiles(txts));
            }

            if (pwzims.Count > 0 && txts.Count > 0)
            {
                Parsers.TimetableOLD.Models.Timetable tOLD  = ParseNew();
                Parsers.TimetableOLD.Models.Timetable tOLD2 = ParseOld();
                //merge
                Parsers.TimetableOLD.Models.Timetable tResult = tOLD.MergeTimetables(tOLD2);
                if (forceDateNow)
                {
                    tResult.Date = DateTime.Now;
                }
                return(tResult);
            }
            else if (pwzims.Count > 0)
            {
                Parsers.TimetableOLD.Models.Timetable tOLD = ParseNew();
                if (forceDateNow)
                {
                    tOLD.Date = DateTime.Now;
                }
                return(tOLD);
            }
            else
            {
                Parsers.TimetableOLD.Models.Timetable tOLD2 = ParseOld();
                if (forceDateNow)
                {
                    tOLD2.Date = DateTime.Now;
                }
                return(tOLD2);
            }
        }
Esempio n. 4
0
        static void Main()
        {
            Console.WriteLine("Reading from input folder");
            Console.WriteLine("Searching for txt files...");
            string[] filesPathsArray = Directory.GetFiles(@".\input\", "*.txt");
            Console.WriteLine("Found " + filesPathsArray.Length + " txt file" + (filesPathsArray.Length == 1 ? "" : "s"));

            //Console.WriteLine("Reading files");
            //DateTime lastDate = new DateTime();
            //List<string> filesContents = new List<string>();
            //foreach (var filePath in filesPathsArray)
            //{
            //    StreamReader streamReader = new StreamReader(filePath);
            //    FileInfo fileInfo = new FileInfo(filePath);
            //    if (fileInfo.LastWriteTime > lastDate) lastDate = fileInfo.LastWriteTime;
            //    filesContents.Add(streamReader.ReadToEnd());
            //    streamReader.Close();
            //}

            string[] odps = { "1", "2", "3" };
            string   odp;

            do
            {
                Console.WriteLine("Co chcesz zrobić?:");
                Console.WriteLine("1. nowe pliki -> JSONy");
                Console.WriteLine("2. stare pliki -> JSONy");
                Console.WriteLine("3. nowe pliki -> stare pliki");
                odp = Console.ReadKey().KeyChar.ToString();
            } while (!odps.Contains(odp));

            if (odp is "1")
            {
                Console.WriteLine("Reading files");
                DateTime      lastDate      = new DateTime();
                List <string> filesContents = new List <string>();
                foreach (var filePath in filesPathsArray)
                {
                    StreamReader streamReader = new StreamReader(filePath);
                    FileInfo     fileInfo     = new FileInfo(filePath);
                    if (fileInfo.LastWriteTime > lastDate)
                    {
                        lastDate = fileInfo.LastWriteTime;
                    }
                    filesContents.Add(streamReader.ReadToEnd());
                    streamReader.Close();
                }

                Console.WriteLine("\nGenerowanie jsonów");
                Parsers.TimetableNew.Models.Timetable tn = Parsers.TimetableNew.Parser.ParseTimetableFiles(filesContents, lastDate);

                Console.WriteLine("Writing to timetable.json");
                StreamWriter streamWriter = new StreamWriter("output/timetable.json");
                streamWriter.Write(JsonConvert.SerializeObject(tn));
                streamWriter.Close();

                Parsers.TimetableOLD.Models.Timetable tOLD = (Parsers.TimetableOLD.Models.Timetable)tn;

                Console.WriteLine("Writing to timetableOLD.json");
                StreamWriter streamWriter2 = new StreamWriter("output/timetableOLD.json");
                streamWriter2.Write(JsonConvert.SerializeObject(tOLD));
                streamWriter2.Close();

                //counting events
                int tEventsNumber  = 0;
                int tmEventsNumber = ((List <Parsers.TimetableOLD.Models.TimetableEvent>)tOLD.Events).Count;
                foreach (var item in tn.AcademicYears)
                {
                    foreach (var item0 in item.Departments)
                    {
                        foreach (var item2 in item0.Modes)
                        {
                            foreach (var item3 in item2.Fields)
                            {
                                foreach (var item4 in item3.Semesters)
                                {
                                    foreach (var item5 in item4.Days)
                                    {
                                        tEventsNumber += item5.Events.Count;
                                    }
                                }
                            }
                        }
                    }
                }

                Console.WriteLine("Done");
                Console.WriteLine("new json has: " + tEventsNumber + " events");
                Console.WriteLine("old json has: " + tmEventsNumber + " events");
            }
            else if (odp is "2")
            {
                Console.WriteLine("Reading files");
                List <string> filepaths = filesPathsArray.ToList();

                Console.WriteLine("\nGenerowanie jsonów");
                Parsers.TimetableOLD.Models.Timetable tOLD = Parsers.TimetableOLD.Parser.ParseTimetableFiles(filepaths);

                Console.WriteLine("Writing to timetableOLD.json");
                StreamWriter streamWriter = new StreamWriter("output/timetableOLD.json");
                streamWriter.Write(JsonConvert.SerializeObject(tOLD));
                streamWriter.Close();

                Parsers.TimetableNew.Models.Timetable tn = (Parsers.TimetableNew.Models.Timetable)tOLD;

                Console.WriteLine("Writing to timetable.json");
                StreamWriter streamWriter2 = new StreamWriter("output/timetable.json");
                streamWriter2.Write(JsonConvert.SerializeObject(tn));
                streamWriter2.Close();

                //counting events
                int tEventsNumber  = 0;
                int tmEventsNumber = ((List <Parsers.TimetableOLD.Models.TimetableEvent>)tOLD.Events).Count;
                foreach (var item in tn.AcademicYears)
                {
                    foreach (var item0 in item.Departments)
                    {
                        foreach (var item2 in item0.Modes)
                        {
                            foreach (var item3 in item2.Fields)
                            {
                                foreach (var item4 in item3.Semesters)
                                {
                                    foreach (var item5 in item4.Days)
                                    {
                                        tEventsNumber += item5.Events.Count;
                                    }
                                }
                            }
                        }
                    }
                }

                Console.WriteLine("Done");
                Console.WriteLine("new json has: " + tEventsNumber + " events");
                Console.WriteLine("old json has: " + tmEventsNumber + " events");
            }
            else
            {
                Console.WriteLine("Reading files");
                DateTime      lastDate      = new DateTime();
                List <string> filesContents = new List <string>();
                foreach (var filePath in filesPathsArray)
                {
                    StreamReader streamReader = new StreamReader(filePath);
                    FileInfo     fileInfo     = new FileInfo(filePath);
                    if (fileInfo.LastWriteTime > lastDate)
                    {
                        lastDate = fileInfo.LastWriteTime;
                    }
                    filesContents.Add(streamReader.ReadToEnd());
                    streamReader.Close();
                }
                Console.WriteLine("\nGenerowanie starych plików");
                Console.WriteLine("Parsing");
                Parsers.TimetableNew.Models.Timetable tn   = Parsers.TimetableNew.Parser.ParseTimetableFiles(filesContents, lastDate);
                Parsers.TimetableOLD.Models.Timetable tOLD = (Parsers.TimetableOLD.Models.Timetable)tn;
                Parsers.TimetableOLD.Parser.SaveTimetableToFiles(tOLD, "output");

                Console.WriteLine("Done");
            }
            Console.ReadLine();
        }