Esempio n. 1
0
        /// <summary>
        /// Writes the section using an XML writer
        /// </summary>
        /// <param name="writer">XML writer to use</param>
        /// <param name="project">The project to generate .csproj for</param>
        /// <param name="context">Current .csproj generation context</param>
        public override void Write(XmlWriter writer, Project project, IMSBuildProjectGeneratorContext context)
        {
            writer.WriteStartElement("ItemGroup");

            var orderedFiles = GetOrderedFiles(project);

            foreach (var pair in orderedFiles)
            {
                var file          = pair.Item1;
                var sourceSetType = pair.Item2;

                var relativePath = ToProjectRelativePath(project, file, ProjectSourceSetName);
                var logicalPath  = GetLogicalPath(project, file, sourceSetType);

                // We have to skip .csproj files, which are generated by bari to the source set because otherwise
                // VisualStudio does not work as expected:
                if (!IgnoredExtensions.Any(ext => relativePath.EndsWith(ext, StringComparison.InvariantCultureIgnoreCase)))
                {
                    writer.WriteStartElement(GetElementNameFor(project, file));
                    writer.WriteAttributeString("Include", relativePath);

                    if (ProjectSourceSetName != sourceSetType)
                    {
                        writer.WriteElementString("LogicalName", logicalPath);
                    }

                    WriteAdditionalOptions(writer, project, file);

                    writer.WriteEndElement();
                }
            }
            writer.WriteEndElement();
        }
Esempio n. 2
0
        public void Search(IMatcher matcher)
        {
            cancelSource = new CancellationTokenSource();
            var cancelToken = new CancellationTokenSource().Token;

            var ig = IgnoredExtensions.ToDictionary(k => k, v => v);

            Task.Run(() =>
            {
                var watch = new Stopwatch();
                watch.Start();

                var files = FileScanner.GetFiles(ParentFolder, FilePattern, ig, SearchSubfolders);

                SearchStatusUpdate?.Invoke(new SearchStatus {
                    FilesComplete = 0, FilesRemaining = files.Count
                });

                var count = 1;

                Parallel.ForEach(files,
                                 (file, state) =>
                {
                    if (cancelSource.IsCancellationRequested)
                    {
                        state.Break();
                    }

                    matcher.Search(file, SearchTerm, ResultFound);

                    //throttle to speed things up
                    if (count++ % 30 == 0)
                    {
                        SearchStatusUpdate?.Invoke(
                            new SearchStatus {
                            FilesComplete = count, FilesRemaining = files.Count
                        });
                    }
                });

                SearchStatusUpdate?.Invoke(new SearchStatus {
                    FilesComplete = count, FilesRemaining = files.Count
                });

                watch.Stop();

                var metrics = new SearchMetrics
                {
                    ElapsedTime   = watch.Elapsed,
                    FilesSearched = files.Count
                };

                SearchComplete?.Invoke(metrics);
            }, cancelToken);
        }
Esempio n. 3
0
 public bool IsKnownExtension(string extension)
 {
     if (KnownExtensions.Contains(extension, StringComparer.OrdinalIgnoreCase))
     {
         return(true);
     }
     if (!IgnoredExtensions.Contains(extension, StringComparer.OrdinalIgnoreCase))
     {
         UnexpectedExtensions.Add(extension);
     }
     return(false);
 }
Esempio n. 4
0
        public static void WriteFilesToDatabase(DbFileContext ctx, Uri initialUri, DirectoryInfo root, int?id)
        {
            string virtualPath;
            string dirName;

            if (id == null)
            {
                virtualPath = "/";
                dirName     = null;
            }
            else
            {
                var currentUri   = new Uri(root.FullName);
                var tempRelative = initialUri.MakeRelativeUri(currentUri).ToString();
                var iof          = tempRelative.IndexOf('/');
                virtualPath = tempRelative.Substring(iof);

                dirName = root.Name;
            }

            foreach (var ignoredDirectory in IgnoredDirectories)
            {
                if (virtualPath.StartsWith(ignoredDirectory, StringComparison.OrdinalIgnoreCase))
                {
                    return;
                }
            }

            var dbFile = new DbFile
            {
                IsDirectory = true,
                Name        = dirName,
                VirtualPath = virtualPath,
                ParentId    = id
            };

            ctx.DbFiles.Add(dbFile);
            ctx.SaveChanges();

            foreach (var fi in root.EnumerateFiles())
            {
                bool ignore = IgnoredExtensions.Any(ignoredExtension => fi.Extension.StartsWith(ignoredExtension)) ||
                              IgnoredFiles.Any(x => x.Equals(fi.Name, StringComparison.OrdinalIgnoreCase));

                if (ignore)
                {
                    continue;
                }

                Console.WriteLine(fi.FullName);

                var dbFileFolder = new DbFile
                {
                    IsDirectory = false,
                    Name        = Path.GetFileNameWithoutExtension(fi.Name),
                    Extension   = fi.Extension,
                    VirtualPath = Path.Combine(virtualPath, fi.Name).Replace('\\', '/'),
                    ParentId    = dbFile.Id,
                };

                if (IsTextFile(fi.Extension))
                {
                    var text = File.ReadAllText(fi.FullName, Encoding.UTF8);
                    dbFileFolder.Texto = text;
                }
                else
                {
                    var bytes = File.ReadAllBytes(fi.FullName);
                    dbFileFolder.Bytes    = bytes;
                    dbFileFolder.IsBinary = true;
                }

                ctx.DbFiles.Add(dbFileFolder);
                ctx.SaveChanges();
            }

            foreach (var di in root.EnumerateDirectories())
            {
                WriteFilesToDatabase(ctx, initialUri, di, dbFile.Id);
            }
        }