Example #1
0
        /// <summary>
        /// Option for on-demand initialization to prevent sudden lag during evaluation.
        /// The calling assembly is loaded via Extensibility unless specified otherwise.
        /// </summary>
        public static void Initialize(bool loadCallingAssembly = true, bool force = false)
        {
            if (loadCallingAssembly)
            {
                Assembly callingAssembly = Assembly.GetCallingAssembly();

                Extensibility.LoadedExtensions.Add(callingAssembly);
            }

            FunctionRegistry.Init(force);
            TokenTypeRegistry.RegisterTokens(force);
            HelpLibrary.Init(force);
            Parser.Init(force);
        }
Example #2
0
        public async Task <IActionResult> UploadFiles(IFormFile file)
        {
            try
            {
                DateTime       currentDateTime = DateTime.Now;
                List <Student> listStudent     = null;

                var filePath = Path.GetTempFileName();

                if (file != null)
                {
                    using (var stream = new FileStream(filePath, FileMode.Create))
                    {
                        await file.CopyToAsync(stream);
                    }
                }

                List <Student> myTest = new List <Student>();
                myTest.Add(new Student
                {
                    Name      = "aaaa",
                    BirthDate = DateTime.Now,
                    Cpf       = "11111"
                });
                myTest.Add(new Student
                {
                    Name      = "aaaa",
                    BirthDate = DateTime.Now,
                    Cpf       = "11111"
                });

                //HelpLibrary.SerializeObject<List<Student>>(myTest);

                string fileInfoExtension = new FileInfo(file.FileName).Extension.ToUpper();

                if (fileInfoExtension == ".JSON")
                {
                    listStudent = HelpLibrary.DeserializeFromJson <List <Student> >(System.IO.File.ReadAllText(filePath));
                }
                else if (fileInfoExtension == ".XML")
                {
                    listStudent = HelpLibrary.DeserializeFromXml <List <Student> >(System.IO.File.ReadAllText(filePath));
                }

                listStudent.ForEach(p =>
                {
                    Student student = _context.Student.Where(s => s.Cpf == p.Cpf).FirstOrDefault();

                    if (student != null)
                    {
                        student.DateUpdate = currentDateTime;
                        student.Name       = p.Name;
                        student.BirthDate  = p.BirthDate;

                        _context.Update(student);
                    }
                    else
                    {
                        p.DateRegister = currentDateTime;
                        _context.Add(p);
                    }
                });

                //Save changes
                _context.SaveChanges();
                return(Ok());
            }
            catch
            {
                return(BadRequest());
            }
        }