That’s the code for updating the projection. I make a loop to be sure it is trying several times. The projection has the status “stopping”.
ProjectionsManager pm = new ProjectionsManager(new ConsoleLogger(), new IPEndPoint(IPAddress.Parse(“127.0.0.1”), 2113));
bool update = true;
int i = 0;
string query = @"fromStream(‘Reservations’)
.when({
$init: function () {
return { body: ‘’, }; // initial state
},
ReservationEvent: function(s, e) {
var month = 0;
if(e.body.NewReservation !== null)
{
month = e.body.NewReservation.StartDate.split('-')[1];
if(month == 6 && e.body.NewReservation.IdFirm =='1dd70dbe-1913-4c8f-9435-01f41ed156a7')
{
s.body += e.bodyRaw;
}
}
else
{
month = e.body.OldReservation.StartDate.split('-')[1];
if(month == 6 && e.body.OldReservation.IdFirm =='1dd70dbe-1913-4c8f-9435-01f41ed156a7')
{
s.body += e.bodyRaw;
}
}
return s;
}
})";
do
{
try
{
pm.UpdateQuery(name, query, user);
update = true;
}
catch (Exception)
{
update = false;
Console.WriteLine(i++);
}
} while (!update);
``
And that the code for deleting.
bool deleted = true;
int i = 0;
do
{
try
{
pm.Delete(name, user);
deleted = true;
}
catch (Exception)
{
deleted = false;
Console.WriteLine(i++);
}
} while (!deleted);
``