Example #1
0
 protected override bool Process(AssemblyStitcherContext context)
 {
     #if DEBUG
     var r = new Resolver(context.AssemblyResolver);
     var typeRef = context.Module.EntryPoint.Parameters[0].Type.Next.TryGetTypeRef();
     var fullType = r.Resolve(typeRef, context.Module);
     #endif
     return false;
 }
Example #2
0
        /// <summary>
        /// Processes the assembly based on given parameters.
        /// </summary>
        /// <param name="parameters">The parameters.</param>
        /// <param name="buildID">The build identifier.</param>
        /// <param name="buildTime">The build time.</param>
        /// <param name="entryAssemblyPath">The entry assembly path.</param>
        /// <returns></returns>
        public bool Process(StringDictionary parameters, Guid buildID, DateTime buildTime, string entryAssemblyPath)
        {
            var  configuration           = parameters["Configuration"];
            var  assemblyPath            = parameters["AssemblyPath"];
            var  literalSignAssembly     = parameters["SignAssembly"];
            var  referencePath           = parameters["ReferencePath"];
            var  referenceCopyLocalPaths = parameters["ReferenceCopyLocalPaths"];
            bool signAssembly            = false;

            if (literalSignAssembly != null)
            {
                bool.TryParse(literalSignAssembly, out signAssembly);
            }
            var assemblyOriginatorKeyFile = signAssembly ? parameters["AssemblyOriginatorKeyFile"] : null;

            bool success = true;

            using (var moduleHandler = LoadModule(assemblyPath))
            {
                bool ok;
                try
                {
                    var context = new AssemblyStitcherContext
                    {
                        Module           = moduleHandler?.Module,
                        Dependencies     = EnumerateDependencies(referencePath, referenceCopyLocalPaths).ToArray(),
                        AssemblyPath     = assemblyPath,
                        BuildID          = buildID,
                        BuildTime        = buildTime,
                        TaskAssemblyPath = entryAssemblyPath,
                        Configuration    = configuration,
                    };
                    context.AssemblyResolver = new ReadonlyAssemblyResolver(context.Dependencies.Select(d => d.Path));
                    ok = Process(context);
                }
                catch (Exception e)
                {
                    Logging.WriteError("Uncaught exception: {0}", e.ToString());
                    ok      = false;
                    success = false;
                }
                if (ok)
                {
                    moduleHandler?.Write(assemblyOriginatorKeyFile);
                }
            }

            var onModuleWritten = ModuleWritten;

            if (onModuleWritten != null)
            {
                onModuleWritten(this, EventArgs.Empty);
            }

            return(success);
        }
 /// <summary>
 /// Processes the specified module.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <returns></returns>
 protected override bool Process(AssemblyStitcherContext context)
 {
     try
     {
         var information = InformationProvider.GetInformation(context.Module.Location);
         var versions = LoadVersions(context.Module).ToArray();
         var update = ProcessStrings(context.Module, versions, s => ProcessVersionString(s, information))
             .OrAny(ProcessCustomVersion(context.Module, versions, context.BuildTime));
         if (update)
             SaveVersions(context.Module, versions);
         return update;
     }
     catch (OperationCanceledException) { }
     return false;
 }
Example #4
0
 /// <summary>
 /// Processes the specified module.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <returns></returns>
 protected abstract bool Process(AssemblyStitcherContext context);
Example #5
0
        /// <summary>
        /// Processes the assembly based on given parameters.
        /// </summary>
        /// <param name="parameters">The parameters.</param>
        /// <param name="entryAssemblyPath">The entry assembly path.</param>
        /// <returns></returns>
        public bool Process(IDictionary <string, string> parameters,
                            string entryAssemblyPath)
        {
            parameters.TryGetValue("AssemblyPath", out var assemblyPath);
            var assemblyMarkerPath = assemblyPath + ".❤" + Name;

            if (HasProcessed(assemblyPath, assemblyMarkerPath))
            {
                return(true);
            }
            parameters.TryGetValue("Configuration", out var configuration);
            parameters.TryGetValue("SignAssembly", out var literalSignAssembly);
            parameters.TryGetValue("ReferencePath", out var referencePath);
            parameters.TryGetValue("ReferenceCopyLocalPaths", out var referenceCopyLocalPaths);
            bool signAssembly = false;

            if (literalSignAssembly is not null)
            {
                bool.TryParse(literalSignAssembly, out signAssembly);
            }
            parameters.TryGetValue("AssemblyOriginatorKeyFile", out var assemblyOriginatorKeyFile);
            if (!signAssembly)
            {
                assemblyOriginatorKeyFile = null;
            }

            bool success = true;

            using (var moduleHandler = LoadModule(assemblyPath))
            {
                bool ok;
                try
                {
                    var context = new AssemblyStitcherContext
                    {
                        Module           = moduleHandler?.Module,
                        Dependencies     = EnumerateDependencies(referencePath, referenceCopyLocalPaths).ToArray(),
                        AssemblyPath     = assemblyPath,
                        TaskAssemblyPath = entryAssemblyPath,
                        Configuration    = configuration,
                    };
                    context.AssemblyResolver = new ReadonlyAssemblyResolver(context.Dependencies.Select(d => d.Path));
                    ok = Process(context);
                }
                catch (Exception e)
                {
                    Logging.WriteError("Uncaught exception: {0}", e.ToString());
                    ok      = false;
                    success = false;
                }

                if (ok)
                {
                    moduleHandler?.Write(assemblyOriginatorKeyFile);
                    SetProcessed(assemblyMarkerPath);
                }
            }

            var onModuleWritten = ModuleWritten;

            if (onModuleWritten is not null)
            {
                onModuleWritten(this, EventArgs.Empty);
            }

            return(success);
        }