public ProjectVisitor(bool fastLoader, string[] projects, ProjectFileFilter filter)
		{
			_fastLoader = fastLoader;
			_projects = new FileList();
			_projects.ProhibitedAttributes = FileAttributes.Hidden;
			_projects.FileFound += FileFound;
			if (filter != null)
				_projects.FileFound += delegate(object o, FileList.FileFoundEventArgs e) { e.Ignore |= filter(e.File); };
			_projects.Add(projects);
		}
示例#2
0
        public void detectDuplicates(FileList files)
        {
            if (files == null)
                return;
            calculateTotalNumberOfCmpOps(files);
            long fileLength = filesWithSameLengthAndDuplicates.fileLength;
            numberOfCmpOpPassed = 0;

            for (int i = 0;
                !searchingDuplicatesProgressDialog.stop &&
                i < files.Count - 1; i++,
                numberOfCmpOpPassed = fileLength * (2 * files.Count - i - 3) * i)
            {
                try
                {
                    var files_i = files[i];
                    if (files_i == null)
                        continue;

                    long lastNumberOfCmpOpPassed = numberOfCmpOpPassed;
                    FileStream f1 = files_i.OpenRead();
                    FileList same = null;

                    for (int j = i + 1;
                        !searchingDuplicatesProgressDialog.stop &&
                        j < files.Count;
                        numberOfCmpOpPassed = lastNumberOfCmpOpPassed +
                        fileLength * (j - i) * 2, j++)
                    {
                        try
                        {
                            var files_j = files[j];
                            if (files_j == null)
                                continue;

                            DateTime start = DateTime.Now;
                            numberOfBytesRead = 0;
                            /* OpenRead() may cause an IOEXception, WinIOError
                             * saying "Operation did not complete successfully
                             * because the file contains a virus or potentially
                             * unwanted software."
                             */
                            FileStream f2 = files_j.OpenRead();

                            if (compareFiles(f1, f2))
                            {
                                if (same == null)
                                {
                                    same = new FileList();
                                    same.Add(files_i);
                                }
                                same.Add(files_j);
                                files[j] = null;
                            }

                            f2.Close();

                            double elapsed = (DateTime.Now - start).TotalMilliseconds;

                            if (readTimes.ContainsKey(numberOfBytesRead))
                            {
                                readTimes[numberOfBytesRead] += elapsed;
                                readTimes[numberOfBytesRead] *= .5;
                            }
                            else
                            {
                                readTimes.Add(numberOfBytesRead, elapsed);
                            }
                        }
                        catch (Exception e)
                        {
                            Log.error(e);
                        }
                    }
                    if (same != null)
                    {
                        filesWithSameLengthAndDuplicates.AddDuplicate(same);
                    }
                    f1.Close();
                }
                catch (Exception e)
                {
                    Log.error(e);
                }

            }
        }
示例#3
0
        static int Main(string[] raw)
        {
            ArgumentList args = new ArgumentList(raw);

            using (DisposingList dispose = new DisposingList())
            using (Log.AppStart(Environment.CommandLine))
            {
                if (args.Contains("nologo") == false)
                {
                    Console.WriteLine("XhtmlValidate.exe");
                    Console.WriteLine("Copyright 2010 by Roger Knapp, Licensed under the Apache License, Version 2.0");
                    Console.WriteLine("");
                }

                if ((args.Unnamed.Count == 0) || args.Contains("?") || args.Contains("help"))
                    return DoHelp();

                try
                {
                    FileList files = new FileList();
                    files.RecurseFolders = true;
                    foreach (string spec in args.Unnamed)
                    {
                        Uri uri;
                        if (Uri.TryCreate(spec, UriKind.Absolute, out uri) && !(uri.IsFile || uri.IsUnc))
                        {
                            using(WebClient wc = new WebClient())
                            {
                                TempFile tfile = new TempFile();
                                dispose.Add(tfile);
                                wc.DownloadFile(uri, tfile.TempPath);
                                files.Add(tfile.Info);
                            }
                        }
                        else
                            files.Add(spec);
                    }
                    if( files.Count == 0 )
                        return 1 + DoHelp();

                    XhtmlValidation validator = new XhtmlValidation(XhtmlDTDSpecification.Any);
                    foreach (FileInfo f in files)
                        validator.Validate(f.FullName);
                }
                catch (ApplicationException ae)
                {
                    Log.Error(ae);
                    Console.Error.WriteLine();
                    Console.Error.WriteLine(ae.Message);
                    Environment.ExitCode = -1;
                }
                catch (Exception e)
                {
                    Log.Error(e);
                    Console.Error.WriteLine();
                    Console.Error.WriteLine(e.ToString());
                    Environment.ExitCode = -1;
                }
            }

            if (args.Contains("wait"))
            {
                Console.WriteLine();
                Console.WriteLine("Press [Enter] to continue...");
                Console.ReadLine();
            }

            return Environment.ExitCode;
        }
示例#4
0
		public void Test()
		{
			FileList files = new FileList(BaseDirectory);
			Assert.AreEqual(3, files.Count);

			files = new FileList(Path.Combine(BaseDirectory, "file?.*"));
			Assert.AreEqual(3, files.Count);

			files = new FileList();
			files.Add(BaseDirectory);
			Assert.AreEqual(3, files.Count);

			files = new FileList(0, BaseDirectory);
			Assert.AreEqual(0, (int)files.ProhibitedAttributes);
			Assert.AreEqual(7, files.Count);

			files = new FileList();
			files.IgnoreFolderAttributes = true;
			Assert.IsTrue(files.IgnoreFolderAttributes);
			files.Add(BaseDirectory);
			Assert.AreEqual(7, files.Count);

			files = new FileList();
			files.RecurseFolders = false;
			Assert.IsFalse(files.RecurseFolders);
			files.Add(BaseDirectory);
			Assert.AreEqual(1, files.Count);

			files = new FileList();
			files.IgnoreFolderAttributes = true;
			files.FileFound += new EventHandler<FileList.FileFoundEventArgs>(
				delegate(object sender, FileList.FileFoundEventArgs e) { if(e.File.Extension != ".ini") e.Ignore = true; } );
			files.Add(BaseDirectory);
			Assert.AreEqual(new FileList(0, Path.Combine(BaseDirectory, "*.ini")).Count, files.Count);
			Assert.AreEqual(".ini", files[0].Extension);

			files = new FileList();
			files.ProhibitedAttributes = FileAttributes.Hidden;
			files.Add(BaseDirectory);
			Assert.AreEqual(3, files.Count);

			files = new FileList();
			files.ProhibitedAttributes = FileAttributes.ReadOnly;
			files.Add(BaseDirectory);
			Assert.AreEqual(5, files.Count);
			files.Add(Path.Combine(BaseDirectory, "file1.txt"));
			Assert.AreEqual(5, files.Count);
			Assert.AreEqual(5, files.ToArray().Length);

			string restoredDir = Environment.CurrentDirectory;
			try
			{
				Environment.CurrentDirectory = BaseDirectory;
				files = new FileList();
				files.ProhibitedAttributes = FileAttributes.ReadOnly;
				files.Add(".");
				Assert.AreEqual(5, files.Count);
				files.Add("file1.txt");
				Assert.AreEqual(5, files.Count);
				Assert.AreEqual(5, files.ToArray().Length);
			}
			finally { Environment.CurrentDirectory = restoredDir; }

			files = new FileList(Path.Combine(BaseDirectory, "*.none"));
			Assert.AreEqual(0, files.Count);//nothing matching wildcard - does not throw FileNotFound
		}
示例#5
0
		public void TestAddFileNotFound()
		{
			//A file name that does not contain wildcards and does not exist will throw FileNotFound
			FileList list = new FileList();
			list.RecurseFolders = false;
			list.Add(Path.Combine(@"C:\", Guid.NewGuid().ToString()));
		}
		static int Main(string[] raw)
        {
            String temp;
		    bool wait = ArgumentList.Remove(ref raw, "wait", out temp);
            bool addMissing = ArgumentList.Remove(ref raw, "add-missing", out temp);

            try
		    {
		        var entryAssembly = Assembly.GetEntryAssembly();
		        if (entryAssembly != null && !ArgumentList.Remove(ref raw, "nologo", out temp))
		        {
		            var aname = entryAssembly.GetName();
		            aname.CultureInfo = null;
		            Console.WriteLine("{0}", aname);
		            foreach (
		                AssemblyCopyrightAttribute a in
		                    entryAssembly.GetCustomAttributes(typeof (AssemblyCopyrightAttribute), false))
		                Console.WriteLine("{0}", a.Copyright);
		            Console.WriteLine();
		        }

		        if (ArgumentList.Remove(ref raw, "verbose", out temp) || ArgumentList.Remove(ref raw, "verbosity", out temp))
		        {
		            SourceLevels traceLevel;
		            try
		            {
		                traceLevel = (SourceLevels) Enum.Parse(typeof (SourceLevels), temp);
		            }
		            catch
		            {
		                traceLevel = SourceLevels.All;
		            }

		            Trace.Listeners.Add(new ConsoleTraceListener()
		            {
		                Filter = new EventTypeFilter(traceLevel),
		                IndentLevel = 0,
		                TraceOutputOptions = TraceOptions.None
		            });
		        }

		        var argsList = new List<string>();
		        foreach (string arg in raw)
		        {
		            if (arg.StartsWith("@"))
		            {
		                foreach (var line in File.ReadAllLines(arg.Substring(1)))
		                {
		                    if (!String.IsNullOrEmpty(line) && line.Trim().Length > 0)
		                        argsList.Add(line.Trim());
		                }
		            }
		            else
		            {
		                argsList.Add(arg);
		            }
		        }

		        raw = argsList.ToArray();
		        if (ArgumentList.Remove(ref raw, "?", out temp) || ArgumentList.Remove(ref raw, "help", out temp))
		            return DoHelp();

                var args = new ArgumentList(StringComparer.Ordinal, raw);
		        if (args.Unnamed.Count == 0 || args.Count == 0)
		            return DoHelp();

		        var files = new FileList();
		        files.ProhibitedAttributes = FileAttributes.Hidden | FileAttributes.System;
		        files.RecurseFolders = true;
		        files.FileFound +=
		            delegate(object sender, FileList.FileFoundEventArgs eventArgs)
		            {
		                eventArgs.Ignore = !eventArgs.File.Name.StartsWith("AssemblyInfo");
		            };

		        foreach (var arg in args.Unnamed)
		            files.Add(arg);

		        var processor = new AssemblyFileProcessor(args, addMissing);
		        foreach (FileInfo file in files.ToArray())
		        {
		            processor.ProcessFile(file);
		        }
		    }
		    catch (ApplicationException ae)
		    {
		        Trace.TraceError("{0}", ae);
		        Console.Error.WriteLine();
		        Console.Error.WriteLine(ae.Message);
		        Environment.ExitCode = -1;
		    }
		    catch (Exception e)
		    {
		        Trace.TraceError("{0}", e);
		        Console.Error.WriteLine();
		        Console.Error.WriteLine(e.ToString());
		        Environment.ExitCode = -1;
		    }
		    finally
		    {
		        if (wait)
		        {
		            Console.WriteLine();
		            Console.WriteLine("Press [Enter] to continue...");
		            Console.ReadLine();
		        }
		    }
		    return Environment.ExitCode;
		}
		void ResolveFiles(ReferenceFolder folder)
		{
			FileList found = new FileList();
			found.FileFound += new EventHandler<FileList.FileFoundEventArgs>(FileFound);
			found.RecurseFolders = folder.Recursive;
            found.Add(folder.AbsolutePath(_namedValues));

			ReferenceWorkItem item;
			
			foreach (FileInfo file in found)
			{
				string filenameonly = Path.GetFileNameWithoutExtension(file.Name);
				if(!_assemblyNameToFile.TryGetValue(filenameonly, out item))
					_assemblyNameToFile.Add(filenameonly, item = new ReferenceWorkItem());
				
				item.FullPath = file.FullName;
				item.FoundIn = folder;
			}
		}
示例#8
0
		static int Main(string[] raw)
		{
			ArgumentList args = new ArgumentList(raw);
			using (Log.AppStart(Environment.CommandLine))
			{
				if (args.Count == 0 || args.Unnamed.Count == 0 || args.Contains("?"))
					return DoHelp();
				if (args.Contains("nologo") == false)
				{
					Console.WriteLine("CSharpTest.Net.CoverageReport.exe");
					Console.WriteLine("Copyright 2009 by Roger Knapp, Licensed under the Apache License, Version 2.0");
					Console.WriteLine("");
				}

				try
				{
					List<string> filesFound = new List<string>();
					FileList files = new FileList();
					files.RecurseFolders = args.Contains("s");
					files.Add(new List<string>(args.Unnamed).ToArray());

					XmlParser parser = new XmlParser( args.SafeGet("exclude").Values );
					foreach (System.IO.FileInfo file in files)
					{
						filesFound.Add(file.FullName);
						using(Log.Start("parsing file: {0}", file.FullName))
							parser.Parse(file.FullName);
					}

					parser.Complete();

					if (args.Contains("module"))
					{
						using (Log.Start("Creating module report."))
						using (XmlReport rpt = new XmlReport(OpenText(args["module"]), parser, "Module Summary", filesFound.ToArray()))
							new MetricReport(parser.ByModule).Write(rpt);
					}

					if (args.Contains("namespace"))
					{
						using (Log.Start("Creating namespace report."))
						using (XmlReport rpt = new XmlReport(OpenText(args["namespace"]), parser, "Namespace Summary", filesFound.ToArray()))
							new MetricReport(parser.ByNamespace).Write(rpt);
					}

					if (args.Contains("class"))
					{
						using (Log.Start("Creating class report."))
						using (XmlReport rpt = new XmlReport(OpenText(args["class"]), parser, "Module Class Summary", filesFound.ToArray()))
							new MetricReport(parser.ByModule, parser.ByNamespace, parser.ByClass).Write(rpt);
					}

                    if (args.Contains("unused"))
                    {
                        using (Log.Start("Creating unused statement report."))
                        using (UnusedReport rpt = new UnusedReport(OpenText(args["unused"]), parser))
                            new MetricReport(parser.ByModule, parser.ByMethod).Write(rpt);
                    }

					if (args.Contains("combine"))
					{
						using (Log.Start("Creating combined coverage file."))
						using (XmlCoverageWriter wtr = new XmlCoverageWriter(OpenText(args["combine"]), parser))
							new MetricReport(parser.ByModule, parser.ByMethod).Write(wtr);
					}
					//foreach (ModuleInfo mi in parser)
					//    Console.WriteLine("{0} hit {1} of {2} for {3}", mi.Name, mi.VisitedPoints, mi.SequencePoints, mi.CoveragePercent);

				}
				catch (Exception e)
				{
					Log.Error(e);
					Console.Error.WriteLine();
					Console.Error.WriteLine("Exception: {0}", e.Message);
					Console.Error.WriteLine();
					Environment.ExitCode = -1;
				}
			}

			if (args.Contains("wait"))
			{
				Console.WriteLine("Press [Enter] to continue...");
				Console.ReadLine();
			}

			return Environment.ExitCode;
		}