1
Good people, I already have a project in the DDD model, which runs through a MVC project, only now I want the application to run as a windows service, has some practical way for it?
Method in MVC I want to start is Index:
private readonly IAwbApplication _awbApplication;
private readonly IMovimentoApplication _movimentoApplication;
public static List<string> LogAplicacao = new List<string>();
public AwbController(IAwbApplication awbApplication, IMovimentoApplication movimentoApplication)
{
_awbApplication = awbApplication;
_movimentoApplication = movimentoApplication;
}
public void Index()
{
try
{
var movimentos = _movimentoApplication.ObterMovimentos();
foreach (var movimento in movimentos)
{
var listaStatusWebServiceGol = _awbApplication.Pesquisar(movimento.nr_AWB.Trim()).ToList();
var listaStatusMovimento = _awbApplication.StatusPorMovimento(movimento.id_Movimento);
for (var i = listaStatusMovimento.Count(); i < listaStatusWebServiceGol.Count(); i++)
{
listaStatusWebServiceGol.ToList()[i].id_Movimento = movimento.id_Movimento;
_awbApplication.InserirMovimentoTracking(listaStatusWebServiceGol.ToList()[i]);
}
}
}
catch (Exception ex)
{
GravarLogAplicacaoValidacao(ex);
}
finally
{
var log = new GeradorLogUtil();
log.EscreverLog(LogAplicacao, @"C:\TrackingAwb\LogErro.txt");
}
}
Metodo Windows Service:
public void ExecutarRotina()
{
//AwbController.Index();
}
It is worth noting that I cannot put my vc Index method as Static
Your question is a little subjective. You have a Webapi and want to make it a Windows Service?
– Anderson Souza
@Andersonsouza at first was a normal web application (however there was no iteration with the user) only now I want it to run as a windows service, so I added in my solution a project like windows service, ai do not know exactly how to that apart from windows service I am creating it perform the method I have in mvc, give to understand? sorry for the difficulty in explaining
– Jhonatas Silva
Calm down, come on. The first thing is to determine the trigger for the call of this method, if it is via MVC project, you have to refocus the Windows Service (WS) project on the MVC project. If the trigger is in the WS project, you have to reference the MVC project in the WS project. To refocus right-click 'References' > 'Add Reference.. ' > 'Projects' > 'Solution' > (and the project). To use the declare using (referenced project) method and the method to be used.
– Anderson Souza
Yes I did this but when I try to call the Index method for example I can only reference it in windows service if it is with Static, but I can’t leave it like this, because if I don’t need to change the whole method of MVC and it would affect other features
– Jhonatas Silva
So ta facil rs, put the method you are calling in the MVC and how you are calling it in the WS!
– Anderson Souza
@Andersonsouza put the code in the question
– Jhonatas Silva