public void should_create_file_with_specific_content() { fileCreator.CreateFile(fileInfo); Assert.That(File.Exists(FILE_PATH), Is.True); var files = Directory.GetFiles(Path.GetDirectoryName(FILE_PATH), Path.GetFileName(FILE_PATH) + ".bak.*"); Assert.That(files.Length, Is.EqualTo(0)); using (TextReader tr = new StreamReader(FILE_PATH)) { var line = tr.ReadLine(); Assert.That(line, Is.EqualTo(FILE_CONTENT)); } }
public static void Main() { using (SoftUniContext context = new SoftUniContext()) { Address newAddress = new Address() { AddressText = "Vitoshka 15", TownId = 4 }; Employee nakovEmployee = context.Employees.SingleOrDefault(ln => ln.LastName == "Nakov"); nakovEmployee.Address = newAddress; context.SaveChanges(); StringBuilder output = new StringBuilder(); context.Employees .Select(e => new { EmployeeAddressId = e.AddressId, AddtessText = e.Address.AddressText }) .OrderByDescending(aId => aId.EmployeeAddressId) .Take(10) .ToList() .ForEach(at => output.AppendLine(at.AddtessText)); FileCreator.CreateFile(output.ToString()); } }
public static void Main() { using (SoftUniContext context = new SoftUniContext()) { var employees = context.Employees .Select(e => new { e.EmployeeId, e.FirstName, e.LastName, e.MiddleName, e.JobTitle, e.Salary } ).ToArray(); StringBuilder output = new StringBuilder(); foreach (var e in employees.OrderBy(e => e.EmployeeId)) { output.AppendLine($"{e.FirstName} {e.LastName} {e.MiddleName} {e.JobTitle} {e.Salary:F2}"); } FileCreator.CreateFile(output.ToString()); } }
public static void Main() { using (SoftUniContext context = new SoftUniContext()) { try { EmployeeProject[] referenceTableRecordsToDelete = context.EmployeesProjects.Where(id => id.ProjectId == 2).ToArray(); context.EmployeesProjects.RemoveRange(referenceTableRecordsToDelete); Project toDelete = context.Projects.Single(id => id.ProjectId == 2); context.Projects.Remove(toDelete); context.SaveChanges(); } catch (System.Exception e) { System.Console.WriteLine(e.Message); } StringBuilder sb = new StringBuilder(); context.Projects .Select(n => new { n.Name }) .Take(10) .ToList() .ForEach(r => sb.AppendLine($"{r.Name}")); FileCreator.CreateFile(sb.ToString()); } }
public static void Main() { using (SoftUniContext db = new SoftUniContext()) { StringBuilder sb = new StringBuilder(); db.Employees .Where(ep => ep.EmployeesProjects.Any(epr => epr.Project.StartDate.Year >= 2001 && epr.Project.StartDate.Year <= 2003)) .Take(30) .Select(ep => new { EmplFirstName = ep.FirstName, EmplLastName = ep.LastName, ManagerFirstName = ep.Manager.FirstName, ManagerLastName = ep.Manager.LastName, Projects = (ep.EmployeesProjects.Any(p => p.Project.StartDate >= new DateTime(2001, 1, 1) && p.Project.StartDate <= new DateTime(2003, 1, 1)) ? ep.EmployeesProjects.Select(p => new { ProjectName = p.Project.Name, ProjectStartDate = p.Project.StartDate.ToString(@"M/d/yyyy h:mm:ss tt"), ProjectEndDate = p.Project.EndDate.HasValue ? p.Project.EndDate.Value.ToString(@"M/d/yyyy h:mm:ss tt") : "not finished", }).ToArray() : null) }) .Take(30) .Where(e => e.Projects != null) .ToList() .ForEach(e => sb.AppendLine($"{e.EmplFirstName} {e.EmplLastName} - Manager: {e.ManagerFirstName} {e.ManagerLastName}").AppendLine(string.Join(Environment.NewLine, e.Projects.Select(p => $"--{p.ProjectName} - {p.ProjectStartDate} - {p.ProjectEndDate}")))); FileCreator.CreateFile(sb.ToString()); } }
public void Generate() { LanguageFactory lFactory = null; switch (m_OutputLanguage) { case OutputLanguage.HTML: lFactory = new HTMLFactory("html"); break; case OutputLanguage.JSON: lFactory = new JSONFactory("json"); break; } foreach (GameElement ge in m_Factory.GameElements) { lFactory.AddContentFromElement(ge); } string content = lFactory.GetText(); m_FileCreator.CreateFile(content, "test", lFactory.Format); if (m_OutputLanguage == OutputLanguage.JSON) { m_Factory.Clear(); StartCoroutine(DelayedJSONLoad("test", lFactory.Format)); } }
/// <summary> /// Writes the file. /// </summary> /// <owner>Aleksey Beletsky</owner> private async void WriteFile() { this.IsCommandEnabled = false; try { switch (this.SelectedEngine) { case EngineType.AsyncAwait: { var creatorAsync = new FileCreatorAsync(); await creatorAsync.CreateFileAsync(this.Path, this.Text); break; } case EngineType.BeginEndInvoke: { var creator = new FileCreator(); var delegat = new Action <string, string>(creator.CreateFile); IAsyncResult result = delegat.BeginInvoke(this.Path, this.Text, null, null); result.AsyncWaitHandle.WaitOne(); delegat.EndInvoke(result); break; } case EngineType.TaskBasedAsyncPattern: var creatorTap = new FileCreator(); await Task.Run(() => { creatorTap.CreateFile(this.Path, this.Text); }); break; case EngineType.ThreadBased: var creatorThread = new FileCreator(this.Path, this.Text); var thread = new Thread(creatorThread.CreateFile); thread.Start(); break; } this.viewService.ProvideService("The file was created successfully."); this.IsCommandEnabled = true; } catch (Exception exception) { this.viewService.ProvideService(exception); } }
private void CreateFile() { try { if (FileCreator.CreateFile(filePath)) { Console.WriteLine($"File {filePath} created!"); filePath = string.Empty; } } catch (Exception e) { Console.WriteLine($"An error occured. {e}\nPlease supply a valid filePath this time! "); filePath = string.Empty; } }
public static void Main() { using (SoftUniContext context = new SoftUniContext()) { StringBuilder sb = new StringBuilder(); context.Employees .Where(em => em.EmployeeId == 147) .Select(e => new { Name = e.FirstName + " " + e.LastName, JobTitle = e.JobTitle, Projects = e.EmployeesProjects.Select(n => n.Project.Name).OrderBy(n => n).ToList() }) .ToList() .ForEach(r => sb.AppendLine($"{r.Name} - {r.JobTitle}").AppendLine(string.Join(Environment.NewLine, r.Projects))); FileCreator.CreateFile(sb.ToString()); } }
public static void Main() { using (SoftUniContext db = new SoftUniContext()) { StringBuilder sb = new StringBuilder(); db.Projects .Select(p => new { Name = p.Name, Description = p.Description, StartDate = p.StartDate }) .OrderByDescending(d => d.StartDate) .Take(10) .OrderBy(n => n.Name) .ToList() .ForEach(r => sb.AppendLine(r.Name).AppendLine(r.Description).AppendLine(r.StartDate.ToString("M/d/yyyy h:mm:ss tt"))); FileCreator.CreateFile(sb.ToString()); } }
public static void Main() { using (SoftUniContext context = new SoftUniContext()) { StringBuilder sb = new StringBuilder(); context.Departments .Where(ec => ec.Employees.Count > 5) .OrderBy(ec => ec.Employees.Count) .ThenBy(dn => dn.Name) .Select(e => new { DepartmentName = e.Name, ManagerName = e.Manager.FirstName + " " + e.Manager.LastName, Employeess = e.Employees.ToList() }) .ToList() .ForEach(r => sb.AppendLine($"{r.DepartmentName} - {r.ManagerName}").AppendLine(string.Join(Environment.NewLine, r.Employeess.OrderBy(fn => fn.FirstName).ThenBy(ln => ln.LastName).Select(em => $"{em.FirstName + " " + em.LastName} - {em.JobTitle}"))).AppendLine(new string('-', 10))); FileCreator.CreateFile(sb.ToString()); } }
public static void Main() { using (SoftUniContext context = new SoftUniContext()) { StringBuilder sb = new StringBuilder(); context.Addresses .Select(a => new { TownName = a.Town.Name, AddressText = a.AddressText, EmployeesCount = a.Employees.Count }) .OrderByDescending(ec => ec.EmployeesCount) .ThenBy(tn => tn.TownName) .ThenBy(at => at.AddressText) .Take(10) .ToList() .ForEach(r => sb.AppendLine($"{r.AddressText}, {r.TownName} - {r.EmployeesCount} employees")); FileCreator.CreateFile(sb.ToString()); } }
public static void Main() { using (SoftUniContext context = new SoftUniContext()) { StringBuilder sb = new StringBuilder(); context.Employees .Where(e => e.FirstName.StartsWith("Sa")) .Select(em => new { FirstName = em.FirstName, LastName = em.LastName, JobTitle = em.JobTitle, Salary = em.Salary }) .OrderBy(fn => fn.FirstName) .ThenBy(ln => ln.LastName) .ToList() .ForEach(r => sb.AppendLine($"{r.FirstName} {r.LastName} - {r.JobTitle} - (${r.Salary:F2})")); FileCreator.CreateFile(sb.ToString()); } }
public static void Main() { using (SoftUniContext context = new SoftUniContext()) { StringBuilder output = new StringBuilder(); context.Employees .Select(ed => new { FirstName = ed.FirstName, LastName = ed.LastName, Department = ed.Department, Salary = ed.Salary }) .Where(d => d.Department.Name == "Research and Development") .OrderBy(s => s.Salary) .ThenByDescending(fn => fn.FirstName) .ToList() .ForEach(e => output.AppendLine($"{e.FirstName} {e.LastName} from Research and Development - ${e.Salary:F2}")); FileCreator.CreateFile(output.ToString()); } }
public static void Main() { using (SoftUniContext context = new SoftUniContext()) { StringBuilder sb = new StringBuilder(); var emplToUpdate = context.Employees .Where(dn => dn.Department.Name == "Engineering" || dn.Department.Name == "Tool Design" || dn.Department.Name == "Marketing" || dn.Department.Name == "Information Services") .OrderBy(fn => fn.FirstName) .ThenBy(ln => ln.LastName) .ToList(); foreach (var e in emplToUpdate) { e.Salary *= 1.12m; sb.AppendLine($"{e.FirstName} {e.LastName} (${e.Salary:F2})"); } context.SaveChanges(); FileCreator.CreateFile(sb.ToString()); } }
public ConceptualDocumentProcessorTest() { _outputFolder = GetRandomFolder(); _inputFolder = GetRandomFolder(); _templateFolder = GetRandomFolder(); _fileCreator = new FileCreator(_inputFolder); _defaultFiles = new FileCollection(_inputFolder); _applyTemplateSettings = new ApplyTemplateSettings(_inputFolder, _outputFolder) { RawModelExportSettings = { Export = true }, TransformDocument = true }; EnvironmentContext.SetBaseDirectory(_inputFolder); EnvironmentContext.SetOutputDirectory(_outputFolder); // Prepare conceptual template var templateCreator = new FileCreator(_templateFolder); var file = templateCreator.CreateFile(@"{{{conceptual}}}", "conceptual.html.tmpl", "default"); _templateManager = new TemplateManager(null, null, new List <string> { "default" }, null, _templateFolder); }
public static void Main() { using (SoftUniContext context = new SoftUniContext()) { string[] names = context.Employees.Select(e => new { FirstName = e.FirstName, Salary = e.Salary }) .Where(s => s.Salary > 50000) .Select(n => n.FirstName) .OrderBy(n => n) .ToArray(); StringBuilder output = new StringBuilder(); foreach (var n in names) { output.AppendLine(n); } FileCreator.CreateFile(output.ToString()); } }
public void ProcessMarkdownTocWithComplexHrefShouldSucceed() { var fileName = "#ctor"; var href = HttpUtility.UrlEncode(fileName); var content = $@" #[Constructor]({href}.md) "; var file = _fileCreator.CreateFile(string.Empty, FileType.MarkdownContent, fileNameWithoutExtension: fileName); var toc = _fileCreator.CreateFile(content, FileType.MarkdownToc); FileCollection files = new FileCollection(_inputFolder); files.Add(DocumentType.Article, new[] { toc, file }); BuildDocument(files); var outputRawModelPath = Path.GetFullPath(Path.Combine(_outputFolder, Path.ChangeExtension(toc, RawModelFileExtension))); Assert.True(File.Exists(outputRawModelPath)); var model = JsonUtility.Deserialize <TocItemViewModel>(outputRawModelPath); var expectedModel = new TocItemViewModel { Items = new TocViewModel { new TocItemViewModel { Name = "Constructor", Href = $"{href}.md", TopicHref = $"{href}.md", } } }; AssertTocEqual(expectedModel, model); }
public void ProcessMarkdownTocWithAbsoluteHrefShouldSucceed() { var content = @" #[Topic1](/href1) ##Topic1.1 ###[Topic1.1.1](/href1.1.1) ##[Topic1.2]() #[Topic2](http://href.com) "; var toc = _fileCreator.CreateFile(content, FileType.MarkdownToc); FileCollection files = new FileCollection(_inputFolder); files.Add(DocumentType.Article, new[] { toc }); BuildDocument(files); var outputRawModelPath = Path.Combine(_outputFolder, Path.ChangeExtension(toc, RawModelFileExtension)); Assert.True(File.Exists(outputRawModelPath)); var model = JsonUtility.Deserialize <TocItemViewModel>(outputRawModelPath); var expectedModel = new TocItemViewModel { Items = new TocViewModel { new TocItemViewModel { Name = "Topic1", Href = "/href1", TopicHref = "/href1", Items = new TocViewModel { new TocItemViewModel { Name = "Topic1.1", Items = new TocViewModel { new TocItemViewModel { Name = "Topic1.1.1", Href = "/href1.1.1", TopicHref = "/href1.1.1" } } }, new TocItemViewModel { Name = "Topic1.2", Href = string.Empty, TopicHref = string.Empty } } }, new TocItemViewModel { Name = "Topic2", Href = "http://href.com", TopicHref = "http://href.com" } } }; AssertTocEqual(expectedModel, model); }