public static void AddResume(ResumeDbContext context, string dateFolder) { try { // add this check so resume doesn't get imported twice if (dateFolder[0] == 'r') { ResumeFiles files = new ResumeFiles(dateFolder); // Utilities.LoadType<Resume>(context, $"{ResumeFileStrings.ProjectRoot}/{dateFolder}/{ResumeFileStrings.Resume}", writeJson); if (File.Exists(files.Resume)) { Resume resume = Utilities.SerializeYml <Resume>(files.Resume); context.Add(resume); } context.SaveChanges(); if (File.Exists(files.ResumeEducations)) { ResumeEducationsJson resumeEducationsJson = Utilities.SerializeYml <ResumeEducationsJson>(files.ResumeEducations); IList <ResumeEducations> resumeEducations = resumeEducationsJson.ResumeEducations; AddItemsReverse(context, resumeEducations); } if (File.Exists(files.ResumeJobs)) { ResumeJobsJson resumeJobsJson = Utilities.SerializeYml <ResumeJobsJson>(files.ResumeJobs); IList <ResumeJobs> resumeJobs = resumeJobsJson.ResumeJobs; AddItemsReverse(context, resumeJobs); } if (File.Exists(files.ResumeSkills)) { ResumeSkillsJson resumeSkillsJson = Utilities.SerializeYml <ResumeSkillsJson>(files.ResumeSkills); IList <ResumeSkills> resumeSkills = resumeSkillsJson.ResumeSkills; AddItemsReverse(context, resumeSkills); } if (File.Exists(files.ResumeSocials)) { ResumeSocialsJson resumeSocialsJson = Utilities.SerializeYml <ResumeSocialsJson>(files.ResumeSocials); IList <ResumeSocials> resumeSocials = resumeSocialsJson.ResumeSocials; AddItemsReverse(context, resumeSocials); } if (File.Exists(files.ResumeSpokenLanguages)) { ResumeSpokenLanguagesJson resumeSpokenLanguagesJson = Utilities.SerializeYml <ResumeSpokenLanguagesJson>(files.ResumeSpokenLanguages); IList <ResumeSpokenLanguages> resumeSpokenLanguages = resumeSpokenLanguagesJson.ResumeSpokenLanguages; AddItemsReverse(context, resumeSpokenLanguages); } context.SaveChanges(); } } catch (Exception e) { Console.WriteLine("##############################"); Console.WriteLine("Resume Add Fail"); Console.WriteLine(e); } }
public static void AddResumeData(ResumeDbContext context, string dateFolder) { try { if (dateFolder[0] == 'd') { ResumeFiles files = new ResumeFiles(dateFolder); // Utilities.LoadType<Resume>(context, files.Resume, writeJson); if (File.Exists(files.Resume)) { Resume resume = Utilities.SerializeYml <Resume>(files.Resume); context.Add(resume); } if (File.Exists(files.Education)) { EducationJson educationJson = Utilities.SerializeYml <EducationJson>(files.Education); IList <Education> educations = educationJson.Educations; AddItems(context, educations); } if (File.Exists(files.Job)) { JobJson jobJson = Utilities.SerializeYml <JobJson>(files.Job); IList <Job> jobs = jobJson.Jobs; AddItems(context, jobs); } if (File.Exists(files.Skill)) { SkillJson skillJson = Utilities.SerializeYml <SkillJson>(files.Skill); IList <Skill> skills = skillJson.Skills; AddItems(context, skills); } if (File.Exists(files.Social)) { SocialJson socialJson = Utilities.SerializeYml <SocialJson>(files.Social); IList <Social> socials = socialJson.Socials; AddItems(context, socials); } if (File.Exists(files.SpokenLanguages)) { SpokenLanguagesJson spokenLanguagesJson = Utilities.SerializeYml <SpokenLanguagesJson>(files.SpokenLanguages); IList <SpokenLanguages> spokenLanguages = spokenLanguagesJson.SpokenLanguages; AddItems(context, spokenLanguages); } context.SaveChanges(); } } catch (Exception e) { Console.WriteLine("##############################"); Console.WriteLine("Resume Data Add Fail"); Console.WriteLine(e); } }
public static void WriteJson(string dateFolder) { ResumeFiles files = new ResumeFiles(dateFolder); foreach (string file in files) { Utilities.YmlToJsonFile(file); } }
public static void WriteHardResume(string dateFolder, Resume resume) { ResumeFiles files = new ResumeFiles(dateFolder); string ymlPath = files.HardResume; // write to json string jsonDCircle = JsonConvert.SerializeObject( resume, new JsonSerializerSettings() { ReferenceLoopHandling = ReferenceLoopHandling.Ignore, Formatting = Formatting.Indented, ContractResolver = new DefaultContractResolver { NamingStrategy = new CamelCaseNamingStrategy() } } ); string jsonPath = ymlPath.Replace("yml", "json"); Resume resumeDCircle = JsonConvert.DeserializeObject <Resume>(jsonDCircle); ResumeDTO parsed = parseResume(resumeDCircle); string json = JsonConvert.SerializeObject( parsed, new JsonSerializerSettings() { ReferenceLoopHandling = ReferenceLoopHandling.Ignore, Formatting = Formatting.Indented, ContractResolver = new DefaultContractResolver { NamingStrategy = new CamelCaseNamingStrategy() } } ); using (StreamWriter w = new StreamWriter(jsonPath)) { w.Write(json); Console.WriteLine("##############################"); Console.WriteLine($"JSON wrote at {jsonPath}"); } //write to yml var serializer = new YamlDotNet.Serialization.SerializerBuilder() .DisableAliases() .Build(); string yaml; using (StringWriter w = new StringWriter()) { serializer.Serialize(w, parsed); yaml = w.ToString(); } using (StreamWriter w2 = new StreamWriter(ymlPath)) { w2.Write(yaml); Console.WriteLine("##############################"); Console.WriteLine($"YML wrote at {ymlPath}"); } // write to javascript string javascript = "exports.hardResume = " + json; string jsPath = files.JavaScriptPath; Console.WriteLine(jsPath); using (StreamWriter w3 = new StreamWriter(jsPath)) { w3.Write(javascript); Console.WriteLine("##############################"); Console.WriteLine($"JS wrote at {jsPath}"); } }