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()); } }
private void AnalyzeSecurityConfiguration(FileCreator creator, ListItem file, ClientContext ctx) { OnVerboseNotify("Analyzing security config"); if (file.HasUniqueRoleAssignments) { ctx.Load(file, l => l.RoleAssignments); ctx.Load(file.RoleAssignments, ras => ras.Include(ra => ra.Member, ra => ra.RoleDefinitionBindings)); ctx.Load(file.ParentList, l => l.RoleAssignments); ctx.Load(file.ParentList.RoleAssignments, ras => ras.Include(ra => ra.Member, ra => ra.RoleDefinitionBindings)); ctx.ExecuteQueryRetry(); if (creator.SecurityConfiguration == null) { creator.SecurityConfiguration = new SecureObjectCreator { SecureObjectType = SecureObjectType.File, GroupRoleDefinitions = new Dictionary <string, string>() }; } creator.SecurityConfiguration.Title = creator.Name; creator.SecurityConfiguration.Url = creator.Url; creator.SecurityConfiguration.BreakInheritance = true; //First loop thorugh and see if the parent has principals with assignments not found in the file CheckShouldCopyExistingPermissions(creator, file); //Next loop through the assignments on the file and build the output FillFileGroupRoleDefinitions(creator, file, ctx); } }
private void CheckShouldCopyExistingPermissions(FileCreator creator, ListItem file) { creator.SecurityConfiguration.CopyExisting = true; foreach (var roleAssignment in file.ParentList.RoleAssignments) { var principal = roleAssignment.Member; if (principal.PrincipalType == PrincipalType.SharePointGroup) { var foundMatch = false; foreach (var fileRoleAssignment in file.RoleAssignments) { if (fileRoleAssignment.Member.Id == roleAssignment.Member.Id) { foundMatch = true; break; } } //The first unique ancestor has one that isn't in the file, assume break inheritance if (!foundMatch) { creator.SecurityConfiguration.CopyExisting = false; break; } } } }
private void WriteSteps(Journey journey, FileCreator fileCreator) { foreach (var junction in journey.Steps) { fileCreator.WriteLine(junction.Id); } }
public void CreateNewFileWithRenameAttemptsExcessiveRenamesTest() { MockFileSystem mockFileSystem = new MockFileSystem(); FileCreator.CreateNewFileWithRenameAttempts("D:\\fakepath\\namecollision.txt", mockFileSystem, 1); FileCreator.CreateNewFileWithRenameAttempts("D:\\fakepath\\namecollision.txt", mockFileSystem, 1); }
internal static Trie <char, List <string> > Load(string binaryFilePath, string positionTriePath) { var ret = new Trie <char, List <string> >(); using (StreamReader strmReader = File.OpenText(positionTriePath)) using (var binReader = new BinaryReader(File.OpenRead(binaryFilePath))) { string line; while ((line = strmReader.ReadLine()) != null) { string word = line.Substring(0, line.IndexOf(" ")); long position = Convert.ToInt64(line.Substring(line.IndexOf(" ") + 1)); binReader.BaseStream.Position = position; int howMany = binReader.ReadInt32(); var list = new List <string>(); for (int i = 0; i < howMany; i++) { list.Add(binReader.ReadString()); } list = FileCreator.ReduceNumberOfNgrams(list, new int[] { 0, 1, 350, 245, 105 }); ret.Add(word, list); } } return(ret); }
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()); } }
static void Main(string[] args) { const int filesToCreate = 1000; const int fileSizeInBytes = 1024 * 10; IEnumerable <string> fileNames; FileCreator fileCreator = new FileCreator(); fileNames = GenerateFileNames(filesToCreate); fileCreator.BenchmarkSyncronousFileCreation(fileNames, fileSizeInBytes); fileCreator.Cleanup(fileNames); GC.Collect(); GC.WaitForPendingFinalizers(); fileNames = GenerateFileNames(filesToCreate); fileCreator.BenchmarkAsyncronousFileCreationInAForeachLoop(fileNames, fileSizeInBytes).Wait(); fileCreator.Cleanup(fileNames); GC.Collect(); GC.WaitForPendingFinalizers(); fileNames = GenerateFileNames(filesToCreate); fileCreator.BenchmarkAsyncronousFileCreationWithTaskWhenAll(fileNames, fileSizeInBytes).Wait(); fileCreator.Cleanup(fileNames); //Console.ReadKey(); }
protected override List <ExportError> ExportConversationAttachments(IConversation conversation, string exportFilename, out IAttachmentExportLocator exportLocator) { List <ExportError> exportErrors = new List <ExportError>(); string exportBasePath = Path.GetDirectoryName(exportFilename); AttachmentExportLocator attachmentExportLocator = new AttachmentExportLocator(exportBasePath); string attachmentDirectoryPath = null; bool exportedVideoAttachment = false; bool exportedAudioAttachment = false; foreach (IConversationMessage message in conversation) { if (!message.HasAttachments()) { continue; } if (attachmentDirectoryPath == null) { string attachmentDirectoryName = GenerateAttachmentExportDirectoryName(exportFilename); attachmentDirectoryPath = Path.Combine(exportBasePath, attachmentDirectoryName); attachmentDirectoryPath = FileCreator.CreateNewDirectoryWithRenameAttempts(attachmentDirectoryPath, _exportFileSystem, MaxRenameAttempts); } foreach (IMessageAttachment attachment in message.Attachments) { try { string exportedPath = ExportMessageAttachment(attachment, attachmentDirectoryPath); attachmentExportLocator.AddAttachmentExportLocation(attachment, exportedPath); if (attachment.Type == AttachmentType.Video) { exportedVideoAttachment = true; } else if (attachment.Type == AttachmentType.Audio) { exportedAudioAttachment = true; } } catch (Exception ex) { exportErrors.Add(new ExportError(conversation, ex)); } } } if (exportedVideoAttachment) { string videoIconPath = PlaceVideoIconFile(attachmentDirectoryPath); attachmentExportLocator.AddFileExportLocation(VideoIconOutputFilename, videoIconPath); } if (exportedAudioAttachment) { string audioIconPath = PlaceAudioIconFile(attachmentDirectoryPath); attachmentExportLocator.AddFileExportLocation(AudioIconOutputFilename, audioIconPath); } exportLocator = attachmentExportLocator; return(exportErrors); }
/// <include file="Tools/.Docs/.ManifestInstaller.xml" path="docs/method[@name='Install(string, ManifestComponents, bool)']/*"/> public static bool Install(string AppDirectory, ManifestComponents Components, bool ThrowExceptions) { foreach (var Component in Components.Values) { var InstallationPath = PathService.CombinePath(AppDirectory, Component.FileName); try { PathCreator.Create(PathService.GetDirectoryPath(InstallationPath)); FileCreator.Create(InstallationPath, Component.Data); } catch { if (ThrowExceptions) { throw; } else { return(false); } } } return(true); }
private void ProcessWebPartPage(ClientContext ctx, Web web, string fileUrl, File file, FileCreator newFileCreator, Dictionary <Guid, List> listIds) { OnVerboseNotify("Processing Web Part Page " + fileUrl); //Get the web part manager var webPartManager = TryToGetWebPartManager(ctx, file); if (webPartManager != null) { OnVerboseNotify("Processing web parts"); //Get each web part and do token replacements var webPartsXml = ReplaceWebPartWebSpecificIDsWithTokens(ctx, web, fileUrl, webPartManager, listIds); var webPartListViews = GetListViewWebPartViewSchemas(ctx, web, webPartsXml); newFileCreator.WebParts = webPartsXml; newFileCreator.WebPartPageWebPartListViews = webPartListViews; var page = RequestContextCredentials == null ? WebPartUtility.GetWebPartPage(ctx, web, fileUrl) : WebPartUtility.GetWebPartPage(web, RequestContextCredentials, fileUrl); newFileCreator.WebPartPageZoneMappings = WebPartPageUtility.GetWebPartZoneMappings(page, webPartsXml); } }
private void CreateDirectoryIfNotExists() { string directoryName = string.Empty; try { directoryName = Path.GetDirectoryName(filePath); } catch (IOException e) { Console.WriteLine($"Failed retrieving the directory from the supplied path! {e}"); } if (!Directory.Exists(directoryName)) { Console.WriteLine($"The directory {Path.GetDirectoryName(filePath)} doesn't exist! Attempting to create the directory"); try { FileCreator.CreateDirectory(filePath); } catch (Exception e) { Console.WriteLine($"Attempt failed! {e}"); } } }
private void WriteJourneys(List <Journey> journeys, FileCreator fileCreator) { foreach (Journey journey in journeys) { WriteJourney(journey, fileCreator); } }
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()); } }
/// <summary> /// Отображает меню программы. /// </summary> private static void ShowMenu() { Console.WriteLine("================================="); Console.WriteLine("Выберите создаваемый файл:"); Console.WriteLine("1. Список подсетей."); Console.WriteLine("2. Список групп."); Console.Write("Введите цифру выбранного пункта: "); if (int.TryParse(Console.ReadLine(), out int select)) { var fileCreator = new FileCreator(Environment.GetFolderPath(Environment.SpecialFolder.Desktop)); switch (select) { case 1: fileCreator.CreateSubnetsFile(); break; case 2: fileCreator.CreateGroupsFile(); break; default: Console.WriteLine("Введите номер из списка."); break; } } else { Console.WriteLine("Необходимо ввести номер из списка."); } }
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 void Generate(List <Journey> journeys) { using (FileCreator fileCreator = new FileCreator(FilePath)) { WriteNbCars(journeys, fileCreator); WriteJourneys(journeys, fileCreator); } }
/// <summary> /// Corrects the file extension according to the file type. /// </summary> private void FixFileExtenstion() { if (!string.IsNullOrWhiteSpace(txtFileName.Text)) { string ext = FileCreator.GetExtension(GetSelectedFileType()); txtFileName.Text = Path.ChangeExtension(txtFileName.Text, ext); } }
public Stream CreateFileStream(string filepath) { var tempFilePath = GetTempFilePathFromOriginalFilename(filepath).Replace('/', Path.PathSeparator); var fileStream = FileCreator.CreateFileAndPath(tempFilePath); var amazonStream = new AmazonDataLakeStream(_amazonAdapter, fileStream, _bucketName, filepath); return(amazonStream); }
private async Task CreateRootIndexFile() { var fileName = $"{CommonKeys.TEMP_FOLDER_NAME}/{Guid.NewGuid()}.txt"; var file = FileCreator.CreateFileAndPath(fileName); file.Close(); await _amazonAdapter.UploadObjectAsync(_bucketName, _rootIndexName, fileName); }
protected override string WriteIndexObjectToFile(HyperLogLog indexObject) { var outputFileName = Path.Combine(CommonKeys.TEMP_FOLDER_NAME, Guid.NewGuid().ToString()); var outputStream = FileCreator.OpenFileWriteAndCreatePath(outputFileName); indexObject.SerializeToStream(outputStream); return(outputFileName); }
public string[] ReadFiles(string FirstFileName, string SecondFileName) { var fileInput = new string[2]; fileInput[0] = FileCreator.readFile(FirstFileName); fileInput[1] = FileCreator.readFile(SecondFileName); return(fileInput); }
private void kbtnFileExport_Click(object sender, EventArgs e) { if (kmtxtFilePath.Text != "") { FileCreator fileCreator = new FileCreator(); fileCreator.WriteColourFile("A:\\Test Colour.txt", ColourUtilities.FormatColourARGBString(pbxDarkColour.BackColor), ColourUtilities.FormatColourARGBString(pbxMiddleColour.BackColor), ColourUtilities.FormatColourARGBString(pbxLightColour.BackColor), ColourUtilities.FormatColourARGBString(pbxLightestColour.BackColor)); } }
public TocDocumentProcessorTest() { _outputFolder = GetRandomFolder(); _inputFolder = GetRandomFolder(); _templateFolder = GetRandomFolder(); _applyTemplateSettings = new ApplyTemplateSettings(_inputFolder, _outputFolder); _applyTemplateSettings.RawModelExportSettings.Export = true; _fileCreator = new FileCreator(_inputFolder); }
private static async Task WriteIndexRowsToFile(string outputFileName, IAsyncEnumerable <RootIndexRow> outputRows) { using var outputFile = FileCreator.OpenFileWriteAndCreatePath(outputFileName); using var outputStreamWriter = new StreamWriter(outputFile); await foreach (var outputRow in outputRows) { await outputStreamWriter.WriteObjectToLineAsync(outputRow); } }
public TocDocumentProcessorTest() { _outputFolder = GetRandomFolder(); _inputFolder = GetRandomFolder(); _applyTemplateSettings = new ApplyTemplateSettings(_inputFolder, _outputFolder); _applyTemplateSettings.RawModelExportSettings.Export = true; _fileCreator = new FileCreator(_inputFolder); EnvironmentContext.SetBaseDirectory(_inputFolder); EnvironmentContext.SetOutputDirectory(_outputFolder); }
static void Main(string[] args) { Console.WriteLine($".NET Core version:\t{GetNetCoreVersion()}\r\n"); var fileCreator = new FileCreator(); var inputFileName = "inputFile"; var outputFileName = "inputFile_compressed"; var restoredFileName = "inputFile_restored"; ThreeSymbols50MBTest(fileCreator, inputFileName, outputFileName, restoredFileName); }
public void Serialize(ProblemData problemData) { using (FileCreator fc = new FileCreator(_outputPath)) { foreach (var car in problemData.CarsWhichCanTMoveAnymore) { WriteCarLine(fc, car); } } }
private string ExportMessageAttachment(IMessageAttachment attachment, string attachmentExportDirectory) { string attachmentExportPath = Path.Combine(attachmentExportDirectory, attachment.OriginalFilename); string createdAttachmentExportPath; using (Stream attachmentOutputStream = FileCreator.CreateNewFileWithRenameAttempts(attachmentExportPath, _exportFileSystem, MaxRenameAttempts, out createdAttachmentExportPath)) { _exportFileSystem.CopyFile(attachment.Path, attachmentOutputStream); } return(createdAttachmentExportPath); }
public void Interact() { string input; string[] splitted; Console.WriteLine("Для роботи, введіть ім'я та формат файлу."); while (true) { try { input = Console.ReadLine().Trim(); } catch (NullReferenceException e) { break; } catch (Exception e) { WriteError(e.Message); continue; } splitted = input.Split('.'); if (splitted.Length > 2 || splitted.Length <= 1) { WriteError("Невірний запис"); continue; } if (FileCreator.isAvailableExtension(splitted[1])) { string name = splitted[0]; string ext = splitted[1]; try { FileManager.GetInstance().CreateFile(name, ext); } catch (Exception e) { WriteError(e.Message); } } else { WriteError("Формат " + splitted[1] + " не підтримується"); } } }