I have a windows forms application which needs customized dll files to be built and for that I am using an online builder using asp.net. I am in no way a asp.net expert not even near a beginner but this is what I have come up with so far:
All the work is done by the Handler:
public void ProcessRequest(HttpContext context)
{
var assembly = AssemblyDefinition.ReadAssembly(context.Server.MapPath("D2.dll"));
var ctor = assembly.MainModule.Types.FirstOrDefault(t => t.FullName.Contains("ClassName") && t.Namespace.Contains("NameSpace"))
.Methods.FirstOrDefault(m => m.FullName.Contains("ctor"));
// Update Instructions
ctor.Body.Instructions[1].Operand = context.Request["A"];
ctor.Body.Instructions[4].Operand = context.Request["GM"];
ctor.Body.Instructions[7].Operand = context.Request["GI"];
ctor.Body.Instructions[10].Operand = context.Request["U"];
ctor.Body.Instructions[13].Operand = context.Request["CT"];
ctor.Body.Instructions[16].Operand = context.Request["MT"];
ctor.Body.Instructions[19].Operand = context.Request["D"];
// Optimize the Body - Required to allow proper build
ctor.Body.OptimizeMacros();
ctor.Body.SimplifyMacros();
// Write the Assembly to Stream so it can be converted to Byte[]
var memstream = new MemoryStream();
assembly.Write(memstream);
// Clear existing response.
context.Response.Clear();
// Write new response.
context.Response.ContentType = "application/octet-stream";
context.Response.AddHeader("Content-Disposition", "attachment; filename=Build.dll");
context.Response.AddHeader("Content-Length", memstream.Length.ToString());
context.Response.BinaryWrite(memstream.ToArray());
}
Currently using this approach/model I have a lot of problems mainly debugging and fixing errors.
I want to improve on this but due to my lack of knowledge in web applications I see no clear path to choose. I have looked at SignalR and it seems like a better approach as it can provide features such as Progress Responses from the server. But still I am confused.