private void SynchronizeWorkspaces(PostmanWorkspaces workspaces) { var directories = new DirectoryInfo(this.postmanConfiguration.LocalDirectory).GetDirectories(); foreach (var workspace in workspaces.Workspaces) { if (directories.All(d => d.Name != workspace.Name)) { this.logger.LogInformation($"Create directory for workspace {workspace.Name}"); Directory.CreateDirectory(Path.Combine(this.postmanConfiguration.LocalDirectory, workspace.Name)); } } foreach (var directory in directories) { if (directory.Name.StartsWith(".")) { continue; } if (workspaces.Workspaces.All(w => w.Name != directory.Name)) { this.logger.LogInformation($"Deleting directory for workspace {directory.Name}"); directory.Delete(); } } }
private bool VerifyDownloadFileNames(string[] expectedFileNames) { var fileNames = new DirectoryInfo(NewAppTestDir).GetFiles() .Where(x => new[] { ".jpg", ".pdf" }.Contains(x.Extension.ToLower())).Select(x => Path.GetFileNameWithoutExtension(x.Name).Trim()); var result = fileNames.All(x => expectedFileNames.Contains(x)) && expectedFileNames.All(x => fileNames.Contains(x)); return(result); }
public static bool CheckDir(string path) { Logger.DebugLog(string.Format("Check {0}", path)); var files = new DirectoryInfo(path).GetFiles(); foreach (var f in _files) { if (files.All(file => file.Name != f)) { return(false); } } return(true); }
static public IEnumerable <string> CollectNupkgFolder(string folderName, int leaveFiles) { List <string> targetFolderList = new List <string>(); var direcories = new DirectoryInfo(folderName).GetDirectories(); if (direcories.Length > leaveFiles) { SemVersion versionInfo; if (direcories.All(x => SemVersion.TryParse(x.Name, out versionInfo)) == true) { var removes = direcories.OrderBy(x => x.Name).SkipLast(leaveFiles).Select(x => x.FullName); targetFolderList.AddRange(removes); } } return(targetFolderList); }
public async Task CanLoadDatabaseAfterUsingVoronRecoveryOnItWithCopyOnWriteMode(bool compressed) { var dbPath = NewDataPath(prefix: Guid.NewGuid().ToString()); var recoveryExportPath = NewDataPath(prefix: Guid.NewGuid().ToString()); DatabaseStatistics databaseStatistics; // create db with sample data using (var store = GetDocumentStore(new Options() { Path = dbPath, ModifyDatabaseRecord = record => { if (compressed) { record.DocumentsCompression = new DocumentsCompressionConfiguration { Collections = new[] { "Orders", "Employees", "Companies", "Products" }, CompressRevisions = true }; } } })) { await CreateLegacyNorthwindDatabase(store); databaseStatistics = store.Maintenance.Send(new GetStatisticsOperation()); } var journals = new DirectoryInfo(Path.Combine(dbPath, "Journals")).GetFiles(); // run recovery using (var recovery = new Recovery(new VoronRecoveryConfiguration() { LoggingMode = Sparrow.Logging.LogMode.None, DataFileDirectory = dbPath, PathToDataFile = Path.Combine(dbPath, "Raven.voron"), OutputFileName = Path.Combine(recoveryExportPath, "recovery.ravendump"), })) { recovery.Execute(TextWriter.Null, CancellationToken.None); } // make sure no journal file was lost during the process - by default we use copy on write mode var journalsAfterRecovery = new DirectoryInfo(Path.Combine(dbPath, "Journals")).GetFiles(); Assert.Equal(journals.Length, journalsAfterRecovery.Length); Assert.True(journals.All(x => journalsAfterRecovery.Any(y => y.Name == x.Name))); // let's open the database using (var store = GetDocumentStore(new Options() { Path = dbPath })) { var currentStats = store.Maintenance.Send(new GetStatisticsOperation()); Assert.Equal(databaseStatistics.CountOfAttachments, currentStats.CountOfAttachments); Assert.Equal(databaseStatistics.CountOfDocuments, currentStats.CountOfDocuments); } // let's import the recovery files using (var store = GetDocumentStore()) { var op = await store.Smuggler.ImportAsync(new DatabaseSmugglerImportOptions() { }, Path.Combine(recoveryExportPath, "recovery-2-Documents.ravendump")); op.WaitForCompletion(TimeSpan.FromMinutes(2)); var currentStats = store.Maintenance.Send(new GetStatisticsOperation()); // + 1 as recovery adds some artificial items Assert.Equal(databaseStatistics.CountOfAttachments + 1, currentStats.CountOfAttachments); Assert.Equal(databaseStatistics.CountOfDocuments + 1, currentStats.CountOfDocuments); } }
private void btnLinq_Click(object sender, RoutedEventArgs e) { // 2867 IEnumerable <FileInfo> list = new DirectoryInfo (@"c:\windows\system32").GetFiles("*.*"); // Where var soloDll1 = from f in list where filtroPerDll(f) select f; var soloDll2 = list.Where(filtroPerDll); // list.Count() > 0 if (list != null && list.Any()) { } var filtroDaConfig = list .Where(f => f.Extension == ConfigurationManager.AppSettings["Extension"]) .ToList(); // Ne esiste almeno uno che....è più grande di 50K? bool esiste50K = list.Any(f => f.Length > 50 * 1024); FileInfo file50K = list.FirstOrDefault(f => f.Length > 50000 * 1024); bool esistonoTutti = list .All(f => f.CreationTime.Year < 2015 && !f.IsReadOnly); var xyz = list //.Where(f => f.CreationTime.Year < 2015) //.Where(f => !f.IsReadOnly) .Where(f => f.Extension == ".exe") .Average(f => f.Length) .ToString() + " bytes"; int soloNascosti1 = list .Count(f => f.Attributes == FileAttributes.Hidden); int soloNascosti2 = list .Where(f => f.Attributes == FileAttributes.Hidden) .Count(); FileInfo fi = list.ElementAtOrDefault(50000); var fileOrdinati = list .Where(f => f.Name.Contains("p")) .ToList() .OrderBy(f => f.Name) .ThenBy(f => f.Length) .ThenByDescending(f => f.DirectoryName); int elementPerPage = 20; var primaPagina = list.Skip(40) .Take(elementPerPage) .ToList(); var toolbar = list.TakeWhile(f => f.Extension != ".ini") .Select(f => new TemplateButton { Etichetta = f.Name, Colore = "Red", Big = f.Length > 500000 }) .ToList(); List <IGrouping <string, FileInfo> > raggruppati = list.GroupBy(f => f.Extension).ToList(); foreach (IGrouping <string, FileInfo> item in raggruppati) { // Key contiene l'estensione string ext = item.Key; foreach (FileInfo file in item) { } } var token = new CancellationTokenSource(); // PLINQ var ricerca = list.AsParallel() .WithDegreeOfParallelism(2) .WithCancellation(token.Token) .Where(f => f.Name.Contains("ll")) .ToList(); token.Cancel(); this.toolbar.ItemsSource = toolbar; if (file50K != null) { } foreach (var item in soloDll2) { } // Metodi di materializzazione (anche delle liste) // ToList() // FirstOrDefault() // First() // LastOrDefault() // Last() // SingleOrDefault() // Single() // Any() }
private static void GenerateAllSolutions(GenerationMethod a_method) { System.Console.WriteLine(); System.Console.WriteLine("Generating solutions..."); System.Console.WriteLine(); string dir = Directories.SolutionTrees + Path.DirectorySeparatorChar + "All"; new DirectoryInfo(dir).CreateOrEmpty(); FileInfo[] files1 = new DirectoryInfo(Directories.Examples).GetFiles(FileExtensions.XmlZipMask); FileInfo[] files2 = new DirectoryInfo(Directories.SolutionTrees).GetFiles(FileExtensions.XmlZipMask); var not_all = (from file1 in files1 where files2.Count(fi => Directories.ConvertName(fi.FullName) == file1.Name) < 4 select file1).ToArray(); var too_much = (from file2 in files2 where files1.All(fi => fi.Name != Directories.ConvertName(file2.Name)) select file2).ToArray(); if (not_all.Count() > 0) { System.Console.WriteLine("Is in 'Examples', but not in 'SolutionTrees' (run project 'SudokuGenerator'): " + not_all.First().FullName); System.Console.ReadKey(true); return; } if (too_much.Count() > 0) { System.Console.WriteLine("Is in 'SolutionTrees', but not in 'Examples': " + too_much.First().FullName); System.Console.ReadKey(true); return; } FileInfo[] files = (from file in new DirectoryInfo(Directories.SolutionTrees).GetFiles(FileExtensions.XmlZipMask) group file by Directories.ConvertName(file.Name) into gr select gr.First()).ToArray(); ShowProgress(0, 70); ConcurrentCounter counter = new ConcurrentCounter(); Parallel.ForEach(files, (file) => { SudokuSolutionNode root = SudokuSolutionNode.LoadFromFile(file.FullName); string file_name = Path.GetFileNameWithoutExtension(Directories.ConvertName(file.Name)); Dictionary <SudokuSolutionType, int> counters = new Dictionary <SudokuSolutionType, int>(); Dictionary <SudokuSolutionType, List <SudokuSolutionNode> > lists = new Dictionary <SudokuSolutionType, List <SudokuSolutionNode> >(); foreach (var type in Enum.GetValues(typeof(SudokuSolutionType)).Cast <SudokuSolutionType>()) { if (type == SudokuSolutionType.MarkImpossibles) { continue; } if (type == SudokuSolutionType.MarkSolved) { continue; } if (type == SudokuSolutionType.SinglesInUnit) { continue; } new DirectoryInfo(dir + Path.DirectorySeparatorChar + type).CreateOrEmpty(); lists[type] = new List <SudokuSolutionNode>(); counters[type] = 1; } foreach (var list in lists.Values) { list.Clear(); } foreach (SudokuSolutionNode node in root.GetAllNodesEnumerator()) { if (node.State != SudokuSolutionNodeState.State) { continue; } var nodes = (from n in node.Nodes where (n.Solution.Type != SudokuSolutionType.MarkImpossibles) && (n.Solution.Type != SudokuSolutionType.MarkSolved) && (n.Solution.Type != SudokuSolutionType.SinglesInUnit) select n).ToList(); var sols = SudokuSolutionNode.FilterByOptions(nodes.Select(n => n.Solution).ToList()); var nodes_gr = (from n in nodes where sols.Contains(n.Solution) group n by n.Solution.Type into gr select gr.ToList()).ToList(); if ((a_method == GenerationMethod.OneType) || (a_method == GenerationMethod.OneSolution)) { bool one_type = nodes_gr.Count(gr => gr.Any()) == 1; if (!one_type) { continue; } } if (a_method == GenerationMethod.OneSolution) { bool one_solution = nodes_gr.Count(gr => gr.Count == 1) == 1; if (!one_solution) { continue; } } foreach (var n in nodes) { lists[n.Solution.Type].Add(n); } } foreach (var list in lists.Values) { var uniques = from n in list group n by n.Solution into gr select gr.First(); var exclude = from n1 in uniques from n2 in uniques where !Object.ReferenceEquals(n1, n2) && n1.Solution.Removed.Contains(n2.Solution.Removed, Comparators.SudokuNumberRowColComparer.Instance) && n1.Solution.Stayed.Contains(n2.Solution.Stayed, Comparators.SudokuNumberRowColComparer.Instance) && n1.Solution.ColorUnits.Equals(n2.Solution.ColorUnits) select n2; var sols = uniques.Except(exclude); foreach (var n in sols) { SudokuIntermediateSolution intermediate_solution = new SudokuIntermediateSolution(n.Board, n.NextBoard, n.Solution); intermediate_solution.SaveToFile(dir + Path.DirectorySeparatorChar + n.Solution.Type + Path.DirectorySeparatorChar + file_name + " - " + counters[n.Solution.Type]++ + FileExtensions.XmlZipExt); } } counter.Increment(); lock (counter) { ShowProgress(counter.Value * 70 / files.Length, 70); } }); }
public async Task CanLoadDatabaseAfterUsingVoronRecoveryOnItWithCopyOnWriteMode() { var dbPath = NewDataPath(prefix: Guid.NewGuid().ToString()); var recoveryExportPath = NewDataPath(prefix: Guid.NewGuid().ToString()); DatabaseStatistics databaseStatistics; // create db with sample data using (var store = GetDocumentStore(new Options() { Path = dbPath })) { store.Maintenance.Send(new CreateSampleDataOperation()); databaseStatistics = store.Maintenance.Send(new GetStatisticsOperation()); } var journals = new DirectoryInfo(Path.Combine(dbPath, "Journals")).GetFiles(); // run recovery using (var recovery = new Recovery(new VoronRecoveryConfiguration() { DataFileDirectory = dbPath, PathToDataFile = Path.Combine(dbPath, "Raven.voron"), OutputFileName = Path.Combine(recoveryExportPath, "recovery.ravendump"), })) { recovery.Execute(CancellationToken.None); } // make sure no journal file was lost during the process - by default we use copy on write mode var journalsAfterRecovery = new DirectoryInfo(Path.Combine(dbPath, "Journals")).GetFiles(); Assert.Equal(journals.Length, journalsAfterRecovery.Length); Assert.True(journals.All(x => journalsAfterRecovery.Any(y => y.Name == x.Name))); // let's open the database using (var store = GetDocumentStore(new Options() { Path = dbPath })) { var currentStats = store.Maintenance.Send(new GetStatisticsOperation()); Assert.Equal(databaseStatistics.CountOfAttachments, currentStats.CountOfAttachments); Assert.Equal(databaseStatistics.CountOfDocuments, currentStats.CountOfDocuments); } // let's import the recovery files using (var store = GetDocumentStore()) { var op = await store.Smuggler.ImportAsync(new DatabaseSmugglerImportOptions() { }, Path.Combine(recoveryExportPath, "recovery-2-Documents.ravendump")); op.WaitForCompletion(TimeSpan.FromMinutes(2)); var currentStats = store.Maintenance.Send(new GetStatisticsOperation()); // + 1 as recovery adds some artificial items Assert.Equal(databaseStatistics.CountOfAttachments + 1, currentStats.CountOfAttachments); Assert.Equal(databaseStatistics.CountOfDocuments + 1, currentStats.CountOfDocuments); } }
private static void Main(string[] args) { try { var argset = new HashSet <string>(args); bool wantTools = (args.Any() && argset.Contains("-t")); bool wantReg = (args.Any() && argset.Contains("-r")); Console.WriteLine($"Analysing Visual Studio installations - use -t on the command line to check for tools."); Console.WriteLine(); Console.WriteLine("User local appdata entries for Visual Studio"); var privateRegistryList = new List <string>(); var userDirs = Directory.GetDirectories(@"c:\users"); foreach (var dir in userDirs) { var userPath = $@"{dir}\appdata\local\microsoft\visualstudio\"; if (Directory.Exists(userPath)) { var directories = Directory.GetDirectories(userPath); var nameList = directories.Where(x => Regex.Match(new DirectoryInfo(x).Name, vsDirPattern, RegexOptions.IgnoreCase).Success); foreach (var entry in nameList) { var privateRegPath = Path.Combine(entry, "privateregistry.bin"); bool exists = File.Exists(privateRegPath); var reportName = exists ? "privateregistry.bin" : ""; Console.WriteLine($" {entry} {reportName}"); if (exists) { privateRegistryList.Add(privateRegPath); } } } } var vsProgramDataFolder = @"C:\ProgramData\Microsoft\VisualStudio\Packages\_Instances"; Console.WriteLine(); Console.WriteLine(@"c:\programdata entries representing VS instances:"); var dirs = Directory.GetDirectories(vsProgramDataFolder); var instanceDirs = dirs.Where(x => Regex.Match(new DirectoryInfo(x).Name, vsProgDataDirPattern, RegexOptions.IgnoreCase).Success); foreach (var dir in instanceDirs) { Console.WriteLine($" {dir}"); } Console.WriteLine(); Console.WriteLine(@"c:\programdata details for VS instances (from the state.json file):"); foreach (var dir in instanceDirs) { var stateFile = Path.Combine(dir, "state.json"); Console.WriteLine($" {stateFile}"); if (File.Exists(stateFile)) { using (StreamReader reader = File.OpenText(stateFile)) { JObject vsJsonInfo = (JObject)JToken.ReadFrom(new JsonTextReader(reader)); var topLevelInfoObjects = new[] { "installationPath", "installDate", "updateDate", "layoutPath", "installationVersion" }; foreach (var tlObject in topLevelInfoObjects) { var value = vsJsonInfo[tlObject] ?? $"NOT FOUND IN {stateFile}"; Console.WriteLine($" {tlObject} - {value}"); } } } Console.WriteLine(); } Console.WriteLine(@"Checking c:\program files (x86)\Microsoft Visual Studio"); var progDirs = Directory.GetDirectories(@"c:\program files (x86)\Microsoft Visual Studio"); var dirList = new List <string>(); foreach (var dir in progDirs) { var lastPart = new DirectoryInfo(dir).Name; if (lastPart.All(char.IsDigit)) { var year = Convert.ToInt32(lastPart); if (year > 2015 && year < 2140) { dirList.Add(dir); } } } foreach (var dir in dirList) { var subDirs = Directory.GetDirectories(dir); foreach (var subDir in subDirs) { Console.WriteLine($" {subDir}"); } } Console.WriteLine(); Console.WriteLine("Printing registry uninstall entries:"); var regUninstallEntries = new List <RegUninstallEntry>(); RegUnInstall.GetProgEntries(regUninstallEntries); foreach (var entry in regUninstallEntries) { Console.WriteLine($" RegKey: {entry.Key}"); Console.WriteLine($" DisplayName: {entry.DisplayName}"); Console.WriteLine($" DisplayVersion: {entry.DisplayVersion}"); Console.WriteLine($" InstallDate: {entry.InstallDate:yyyy-MM-dd}"); Console.WriteLine($" InstallLocation: {entry.InstallLocation}"); Console.WriteLine($" ModifyPath: {entry.ModifyPath}"); Console.WriteLine($" RepairPath: {entry.RepairPath}"); Console.WriteLine($" UninstallString: {entry.UninstallString}"); Console.WriteLine(); } // we might not want to find exe tools because it could take a while, so get out if we don't: if (wantTools) { Console.WriteLine(); // the list of tools (executables) we are looking for. var toolList = new HashSet <string>(StringComparer.OrdinalIgnoreCase) { "cl", "csc", "link", "lib", "csc", "msbuild", "devenv", "dumpbin" }; Console.WriteLine($"Checking for tools: {string.Join(" ", toolList.Select(x => x + ".exe"))}"); var toolsFound = new List <string>(); var fileStack = new Stack <string>(); foreach (var dir in dirList) { fileStack.Push(dir); } // depth first search over filesystem under the program files directories we found earlier for // visual studio installations: while (fileStack.Any()) { var nextDir = fileStack.Pop(); var files = Directory.GetFiles(nextDir); foreach (var file in files) { var name = Path.GetFileNameWithoutExtension(file); var ext = Path.GetExtension(file); if (ext == ".exe" && toolList.Contains(name)) { toolsFound.Add(file); } } var directories = Directory.GetDirectories(nextDir); foreach (var dir in directories) { fileStack.Push(dir); } } toolsFound.ForEach(x => Console.WriteLine($" {x}")); } if (wantReg) { ProcessReg.Process(privateRegistryList); } } catch (Exception ex) { var fullname = System.Reflection.Assembly.GetEntryAssembly().Location; var progname = Path.GetFileNameWithoutExtension(fullname); Console.Error.WriteLine(progname + ": Error: " + ex.Message); } }
public void Test_Solution_Trees_vs_Examples() { ProgressIndicator pi = new ProgressIndicator(System.Reflection.MethodBase.GetCurrentMethod().Name); FileInfo[] files1 = new DirectoryInfo(Directories.Examples).GetFiles(FileExtensions.XmlZipMask); FileInfo[] files2 = new DirectoryInfo(Directories.SolutionTrees).GetFiles(FileExtensions.XmlZipMask); var not_all = (from file1 in files1 where files2.Count(fi => Directories.ConvertName(fi.FullName) == file1.Name) < 4 select file1).ToArray(); var too_much = (from file2 in files2 where files1.All(fi => fi.Name != Directories.ConvertName(file2.Name)) select file2).ToArray(); if (not_all.Count() > 0) { Assert.Fail("Is in 'Examples', but not in 'SolutionTrees' (run project 'SudokuGenerator'): " + not_all.First().FullName); } if (too_much.Count() > 0) { Assert.Fail("Is in 'SolutionTrees', but not in 'Examples': " + too_much.First().FullName); } string dir3 = Directories.SolutionTrees + Path.DirectorySeparatorChar + "Diffrencies"; new DirectoryInfo(dir3).CreateOrEmpty(); string dir4 = Directories.SolutionTrees + Path.DirectorySeparatorChar + "Diffrencies" + Path.DirectorySeparatorChar + "Added"; new DirectoryInfo(dir4).CreateOrEmpty(); string dir5 = Directories.SolutionTrees + Path.DirectorySeparatorChar + "Diffrencies" + Path.DirectorySeparatorChar + "Removed"; new DirectoryInfo(dir5).CreateOrEmpty(); bool b = false; ConcurrentBag <string> list = new ConcurrentBag <string>(); ConcurrentCounter counter = new ConcurrentCounter(); Parallel.ForEach(files2, (file2, state) => { counter.Increment(); pi.AddLine((counter.Value * 100 / files2.Length).ToString()); SudokuSolutionNode node2 = SudokuSolutionNode.LoadFromFile(file2.FullName); SudokuBoard board = SudokuBoard.LoadFromFile(files1.First(f => f.Name == Directories.ConvertName(file2.FullName)).FullName); board = board.Rotate(ExtractRotateNumber(file2.Name)); SudokuSolutionNode node1 = SudokuSolutionNode.CreateRoot(board); node1.SolveWithStepAll(); Assert.AreEqual(node1.State, node2.State, file2.FullName); Assert.AreEqual(node1.Board, node2.Board, file2.FullName); Assert.AreEqual(node1.Solution, node2.Solution, file2.FullName); b |= CompareNodes(node1, node2, file2, list, 1, 1); }); if (list.Count != 0) { string filename = dir3 + Path.DirectorySeparatorChar + "!Diffrencies.txt"; using (FileStream fs = new FileStream(filename, FileMode.Create)) { StreamWriter sw = new StreamWriter(fs); list.ForEach(s => sw.WriteLine(s)); sw.Flush(); } TestContext.AddResultFile(filename); } Assert.IsFalse(b); }