public override bool Execute()
        {
#if NETCOREAPP2_0
            string   taskAssemblyPath  = new Uri(this.GetType().GetTypeInfo().Assembly.CodeBase).LocalPath;
            var      ctxt              = new CustomAssemblyLoader(this);
            Assembly inContextAssembly = ctxt.LoadFromAssemblyPath(taskAssemblyPath);
            Type     innerTaskType     = inContextAssembly.GetType(this.GetType().FullName);
            object   innerTask         = Activator.CreateInstance(innerTaskType);

            var outerProperties     = this.GetType().GetRuntimeProperties().ToDictionary(i => i.Name);
            var innerProperties     = innerTaskType.GetRuntimeProperties().ToDictionary(i => i.Name);
            var propertiesDiscovery = from outerProperty in outerProperties.Values
                                      where outerProperty.SetMethod != null && outerProperty.GetMethod != null
                                      let innerProperty = innerProperties[outerProperty.Name]
                                                          select new { outerProperty, innerProperty };
            var propertiesMap       = propertiesDiscovery.ToArray();
            var outputPropertiesMap = propertiesMap.Where(pair => pair.outerProperty.GetCustomAttribute <OutputAttribute>() != null).ToArray();

            foreach (var propertyPair in propertiesMap)
            {
                object outerPropertyValue = propertyPair.outerProperty.GetValue(this);
                propertyPair.innerProperty.SetValue(innerTask, outerPropertyValue);
            }

            var  executeInnerMethod = innerTaskType.GetMethod(nameof(ExecuteInner), BindingFlags.Instance | BindingFlags.NonPublic);
            bool result             = (bool)executeInnerMethod.Invoke(innerTask, new object[0]);

            foreach (var propertyPair in outputPropertiesMap)
            {
                propertyPair.outerProperty.SetValue(this, propertyPair.innerProperty.GetValue(innerTask));
            }

            return(result);
#else
            // On .NET Framework (on Windows), we find native binaries by adding them to our PATH.
            if (this.UnmanagedDllDirectory != null)
            {
                string   pathEnvVar  = Environment.GetEnvironmentVariable("PATH");
                string[] searchPaths = pathEnvVar.Split(Path.PathSeparator);
                if (!searchPaths.Contains(this.UnmanagedDllDirectory, StringComparer.OrdinalIgnoreCase))
                {
                    pathEnvVar += Path.PathSeparator + this.UnmanagedDllDirectory;
                    Environment.SetEnvironmentVariable("PATH", pathEnvVar);
                }
            }

            return(this.ExecuteInner());
#endif
        }
        private IEnumerable <string> GenerateFilesForProject()
        {
            var generatorPlugins = GeneratorPlugins?.Select(gp => gp.ItemSpec).ToList() ?? new List <string>();

            string   taskAssemblyPath  = new Uri(this.GetType().GetTypeInfo().Assembly.CodeBase).LocalPath;
            var      ctxt              = new CustomAssemblyLoader();
            Assembly inContextAssembly = ctxt.LoadFromAssemblyPath(taskAssemblyPath);
            Type     innerTaskType     = inContextAssembly.GetType(typeof(FeatureFileCodeBehindGenerator).FullName);
            object   innerTask         = Activator.CreateInstance(innerTaskType);

            var executeInnerMethod = innerTaskType.GetMethod("GenerateFilesForProject", BindingFlags.Instance | BindingFlags.Public);

            var parameters = new object[] { ProjectPath, RootNamespace, FeatureFiles.Select(i => i.ItemSpec).ToList(), generatorPlugins, ProjectFolder, OutputPath };
            var result     = (IEnumerable <string>)executeInnerMethod.Invoke(innerTask, parameters);

            return(result);
        }
Exemple #3
0
        /// <summary>
        ///     Initializes a new instance of <see cref="CoreReflectionBasedDriver" /> with
        ///     the connection type name loaded from the specified assembly.
        /// </summary>
        /// <param name="driverAssemblyName"> Assembly to load the driver Type from. </param>
        /// <param name="connectionTypeName"> Name of the driver Type. </param>
        /// <param name="depsFile"> Dependency file of the project to migrate. </param>
        /// <param name="nugetPackageDir"> Path to the NuGet package folder. </param>
        /// <exception cref="EvolveCoreDriverException"></exception>
        public CoreReflectionBasedDriverEx(string driverAssemblyName, string connectionTypeName, string depsFile, string nugetPackageDir) : base(driverAssemblyName, connectionTypeName)
        {
            _depsFile                = Check.FileExists(depsFile, nameof(depsFile));
            NugetPackageDir          = Check.DirectoryExists(nugetPackageDir, nameof(nugetPackageDir));
            ProjectDependencyContext = LoadDependencyContext(depsFile);
            try
            {
                NuGetFallbackDir = GetNuGetFallbackFolder();
            }
            catch (Exception ex)
            {
                Debug.WriteLine($"NuGetFallbackFolder not found. {ex.Message}");
            }

#if NETCORE
            _assemblyLoader = new CustomAssemblyLoader(this);
#endif
        }
Exemple #4
0
        /// <summary>
        ///     Initializes a new instance of <see cref="CoreReflectionBasedDriver" /> with
        ///     the connection type name loaded from the specified assembly.
        /// </summary>
        /// <param name="driverAssemblyName"> Assembly to load the driver Type from. </param>
        /// <param name="connectionTypeName"> Name of the driver Type. </param>
        /// <param name="depsFile"> Dependency file of the project to migrate. </param>
        /// <param name="nugetPackageDir"> Path to the NuGet package folder. </param>
        public CoreReflectionBasedDriver(string driverAssemblyName, string connectionTypeName, string depsFile, string nugetPackageDir) : base(driverAssemblyName, connectionTypeName)
        {
            _depsFile                = Check.FileExists(depsFile, nameof(depsFile));
            NugetPackageDir          = Check.DirectoryExists(nugetPackageDir, nameof(nugetPackageDir));
            ProjectDependencyContext = LoadDependencyContext(_depsFile);
            NativeDependencies       = new List <string>();
            try
            {
                NuGetFallbackDir = Path.Combine(Path.GetFullPath(Path.Combine(Path.GetDirectoryName(
                                                                                  typeof(GC).GetTypeInfo().Assembly.Location), @"../../..")), "sdk/NuGetFallbackFolder");
            }
            catch (Exception ex)
            {
                Debug.WriteLine(string.Format(NuGetFallbackDirNotFound, ex.Message));
            }

#if NETCORE
            _assemblyLoader = new CustomAssemblyLoader(this);
#endif
        }