Beispiel #1
0
        public void Watch(FeatureRuntimeCompilationOptions options)
        {
            var configFolderPath = Path.Combine(Directory.GetCurrentDirectory(), options.FeaturesPath);

            var watcher = new FileSystemWatcher()
            {
                Path                  = configFolderPath,
                NotifyFilter          = NotifyFilters.LastWrite | NotifyFilters.DirectoryName | NotifyFilters.FileName,
                IncludeSubdirectories = true,
                Filter                = "*.cs"
            };

            void changeEvent(object s, FileSystemEventArgs e)
            {
                _logger.LogInformation(e.ChangeType.ToString() + ": " + e.FullPath);

                var featurePath = Path.GetDirectoryName(e.FullPath);
                var metadata    = _metadataProvider.GetMetadataFor(featurePath);

                _featureUpdater.Update(metadata);
            }

            watcher.Created += changeEvent; // Create file
            watcher.Changed += changeEvent; // Rename file, Save file, Rename x.aaa -> x.cs
            watcher.Deleted += changeEvent; // Delete file
            watcher.Renamed += changeEvent; // Delete file

            // Not triggering: Delete or renaming directory containing cs, cshtml

            watcher.EnableRaisingEvents = true;
        }
Beispiel #2
0
        public IChangeToken Watch(string filter)
        {
            var fileInfo = _innerProvider.GetFileInfo(filter);

            if (fileInfo.Exists && !fileInfo.Name.StartsWith("_"))
            {
                var featurePath        = GetFeaturePath(fileInfo.PhysicalPath);
                var feature            = _metadataProvider.GetMetadataFor(featurePath);
                var featureChangeToken = _tokenProvider.GetToken(feature);

                var featureRelativePath = featurePath.Substring(_innerProvider.Root.Length).Replace("\\", "/");
                var fileChangeToken     = _innerProvider.Watch(featureRelativePath + "/**/*");

                return(new CompositeChangeToken(new[]
                {
                    fileChangeToken,
                    featureChangeToken
                }));
            }

            return(_innerProvider.Watch(filter));
        }
        public override Task SelectAsync(HttpContext httpContext, CandidateSet candidates)
        {
            if (candidates.Count == 0)
            {
                return(Task.CompletedTask);
            }

            // Find the last built endpoint
            var candidate = candidates[0];

            var feature = _metadataProvider.GetMetadataFor(candidate.Values);
            var result  = _featureCache.Get(feature);

            if (result != null)
            {
                if (!result.Success)
                {
                    throw new FeatureCompilationFailedException(_options.ProjectPath, result);
                }

                for (var i = candidates.Count - 1; i > 0; i--)
                {
                    var assembly = candidates[i].Endpoint.GetEndpointAssembly();
                    if (result.Assembly == assembly)
                    {
                        _logger.LogDebug($"Endpoint assembly: {assembly.FullName}");
                        candidate = candidates[i];
                        break;
                    }
                }
            }

            httpContext.SetEndpoint(candidate.Endpoint);
            httpContext.Request.RouteValues = candidate.Values;

            return(Task.CompletedTask);
        }