public void GenerateWriters2()
 {
     for (int i = 0; i < 100; i++)
     {
         if (i % 5 == 0)
         {
             writers2.Add(FactoryWriter.CreateWriter(WriterTypes.MessageWriter));
         }
         else if (i % 3 == 0)
         {
             writers2.Add(FactoryWriter.CreateWriter(WriterTypes.ExceptionWriter));
         }
         else
         {
             writers2.Add(FactoryWriter.CreateWriter(WriterTypes.ErrorWriter));
         }
     }
 }
Example #2
0
        static void Main(string[] args)
        {
            ParseCommandLine(args);
            try
            {
                if (InputDir == null)
                {
                    throw new InvalidCommandLineException("Input (inDir) directory isn't set in the command line");
                }
                if (!Directory.Exists(InputDir))
                {
                    throw new InvalidCommandLineException("Input directory doesn't exist (" + InputDir + ")");
                }

                if (TemplatesDir == null)
                {
                    throw new InvalidCommandLineException("Template (templatesDir) directory isn't set in the command line");
                }
                if (!Directory.Exists(TemplatesDir))
                {
                    throw new InvalidCommandLineException("Template directory doesn't exist (" + TemplatesDir + ")");
                }

                if (HlslOutputDir == null)
                {
                    throw new InvalidCommandLineException("Hlsl directory isn't set in the command line");
                }

                if (CppOutputDir == null)
                {
                    throw new InvalidCommandLineException("Cpp output directory isn't set in the command line");
                }
            }
            catch (InvalidCommandLineException ex)
            {
                Console.WriteLine(ex.Message);
            }

            CreateOutputDirectories(false);

            DateTime lastInputUpdateTime;
            string   updateTimeFilepath;

            if (CompareOutputsVersion(out lastInputUpdateTime, out updateTimeFilepath) && !ForceRegenerate)
            {
                return;
            }

            Console.WriteLine("Generating...\n");
            string[] files = Directory.GetFiles(InputDir, "*.sinp", SearchOption.AllDirectories);
            ShaderOutputGlobalContext globalContext = new ShaderOutputGlobalContext();

            foreach (var filepath in files)
            {
                Console.WriteLine("Parsing file " + filepath + '\n');
                try
                {
                    string content = File.ReadAllText(filepath);

                    ShaderInputsParser parser = InitializeAntlr(content);
                    ShaderInputsParser.InputFileContext ctx = parser.inputFile();

                    ShaderInputsVisitor visitor = new ShaderInputsVisitor(globalContext);
                    visitor.Visit(ctx);
                    ShaderOutputContext outputCtx = visitor.OutputContext;

                    //Validator validator = new Validator();
                    //validator.Validate(outputCtx.ConstantBuffers);

                    BindpointManager bindpointManager = new BindpointManager();
                    bindpointManager.AssignBindpoints(outputCtx);

                    string            filename   = Path.GetFileNameWithoutExtension(filepath);
                    HlslHeadersWriter hlslWriter = new HlslHeadersWriter();
                    hlslWriter.WriteHeaders(outputCtx, filename);
                    CppHeaderWriter cppWriter = new CppHeaderWriter();
                    cppWriter.WriteHeaders(outputCtx, filename);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Exception occurred while parsing file " + filepath);
                    Console.WriteLine(ex.Message);
                    Console.WriteLine(ex.StackTrace);
                    throw;
                }
            }
            Console.WriteLine("Writing common structures...");
            CommonStructHeaderWriter commonStructWriter = new CommonStructHeaderWriter();

            commonStructWriter.WriteHeaders(globalContext);

            Console.WriteLine("Writing outputs...\n");
            FactoryWriter factoryWriter = new FactoryWriter();

            factoryWriter.WriteFactory(files);
            Console.WriteLine("Writing done\n");

            UpdateOutputVersionFile(lastInputUpdateTime, updateTimeFilepath);

            Console.Write("Output file timestamp updated\n");

            Console.Write("\n******* SHADERS OUTPUT FILES ARE UPDATED WITH SUCESS ******\n");
        }
Example #3
0
        static void Main(string[] args)
        {
            if (args.Length > 3)
            {
                Console.WriteLine("Nie może być więcej niź 3 parametry");
                return;
            }
            string defaultAdresPlikuCSV       = "data.csv",
                   defaultAdresDocelowyWyniku = "result.xml",
                   defaultTypDanych           = "xml";
            string sourceFilePath,
                   aimFilePath;

            sourceFilePath = ((args[0] == null) || (args[0] == "")) ? defaultAdresPlikuCSV : args[0];
            aimFilePath    = ((args[1] == null) || (args[1] == "")) ? defaultAdresDocelowyWyniku : args[1];
            string formatDanych = ((args[2] == null) || (args[2] == "")) ? defaultTypDanych : args[2];

            Console.WriteLine("args[0] " + args[0] +
                              "args[1] " + args[1] +
                              "args[2] " + args[2] +
                              "\n sourceFilePath " + sourceFilePath +
                              "aimFile " + aimFilePath +
                              "formatDanych " + formatDanych);

            var students = new List <Student>();

            Dictionary <string, int> hashCourses = new Dictionary <string, int>();

            using (StreamWriter logStreamWriter = new StreamWriter("log.txt", false, System.Text.Encoding.Default)) {
                try
                {
                    using (var stream = new StreamReader(new FileInfo(sourceFilePath).OpenRead()))
                    {
                        string line = null;
                        while ((line = stream.ReadLine()) != null)
                        {
                            string[] studentParametrs = line.Split(',');

                            bool   isMessageForLog = false;
                            string infoStudent     = "";
                            for (int i = 0; i < studentParametrs.Length; i++)
                            {
                                infoStudent += " " + studentParametrs[i];
                            }

                            if (studentParametrs.Length < 9)
                            {
                                infoStudent = "Student: " + infoStudent + " ma " + studentParametrs.Length + " parametrów, " +
                                              "a potrzebno mieć 9";
                                logStreamWriter.Write(infoStudent + "\n");
                                logStreamWriter.Flush();
                                continue;
                            }
                            for (int i = 0; i < studentParametrs.Length; i++)
                            {
                                if (studentParametrs[i] == null || studentParametrs[i] == "")
                                {
                                    infoStudent    += "; Ma pusty parametry";
                                    isMessageForLog = true;
                                    break;
                                }
                            }
                            var studies = new Studies
                            {
                                Name = studentParametrs[2],
                                Mode = studentParametrs[3]
                            };

                            var st = new Student
                            {
                                Ska         = studentParametrs[4],
                                Fname       = studentParametrs[0],
                                Lname       = studentParametrs[1],
                                Birthdate   = studentParametrs[5],
                                Email       = studentParametrs[6],
                                MothersName = studentParametrs[7],
                                FathersName = studentParametrs[8],
                                Studies     = studies
                            };


                            for (int i = 0; i < students.Count; i++)
                            {
                                if (students[i].Equals(st))
                                {
                                    infoStudent    += " ; Takij student już istnieje w Baze Dannych";
                                    isMessageForLog = true;
                                }
                            }

                            if (isMessageForLog)
                            {
                                logStreamWriter.Write(infoStudent + "\n");
                                logStreamWriter.Flush();
                                continue;
                            }

                            students.Add(st);
                            string courseName = studentParametrs[2];
                            if (hashCourses.ContainsKey(courseName))
                            {
                                hashCourses[courseName]++;
                            }
                            else
                            {
                                hashCourses.Add(courseName, 1);
                            }
                        }
                    }
                }
                catch (FileNotFoundException fnfe)
                {
                    logStreamWriter.WriteLine("Plik " + fnfe.FileName + " nie istnieje");
                    logStreamWriter.Flush();
                }
                catch (DirectoryNotFoundException dnfe) {
                    logStreamWriter.WriteLine("Podana ścieżka jest niepoprawna");
                    logStreamWriter.Flush();
                }
            }

            var myWriter = FactoryWriter.createWriter(formatDanych);

            myWriter.WriteDataIntoFile(students, hashCourses, aimFilePath);
            Console.WriteLine("Program finshed!");
        }