internal static void Bind() { _beginDelegate = Library.GetProcAddress <BeginDelegate>("mdbx_txn_begin") as BeginDelegate; _commitDelegate = Library.GetProcAddress <CommitDelegate>("mdbx_txn_commit") as CommitDelegate; _abortDelegate = Library.GetProcAddress <AbortDelegate>("mdbx_txn_abort") as AbortDelegate; _resetDelegate = Library.GetProcAddress <ResetDelegate>("mdbx_txn_reset") as ResetDelegate; _renewDelegate = Library.GetProcAddress <RenewDelegate>("mdbx_txn_renew") as RenewDelegate; _getTxnIdDelegate = Library.GetProcAddress <GetTxnIdDelegate>("mdbx_txn_id") as GetTxnIdDelegate; }
/* * AUX METHODS */ private void BookNextSlot(Reservation res) { bool booked = false; //LOCK HERE foreach (ReservationSlot slot in res.Slots) { Monitor.Enter(_calendar[slot.SlotID]); CalendarSlot cSlot = _calendar[slot.SlotID]; if (slot.State != ReservationSlotState.ABORTED && !cSlot.Locked && (cSlot.State == CalendarSlotState.ACKNOWLEDGED || (cSlot.State == CalendarSlotState.BOOKED && res.ReservationID < cSlot.ReservationID))) { booked = true; BookCalendarSlot(res, slot); Monitor.Exit(_calendar[slot.SlotID]); Log.Show(_userName, "Starting book process of slot " + slot.SlotID + " from reservation " + res.ReservationID); foreach (string participantID in res.Participants) { if (!participantID.Equals(_userName)) { _msgDispatcher.SendMessage(MessageType.BOOK_SLOT, res.ReservationID, participantID, slot.SlotID); } } break; } else { Monitor.Exit(_calendar[slot.SlotID]); } } if (!booked) { Log.Show(_userName, "No available slots. Aborting reservation " + res.ReservationID); foreach (IBookingService client in res.ClientStubs.Values) { try { Log.Show(_userName, "Sending abort to client..."); AbortDelegate bookSlot = new AbortDelegate(client.AbortReservation); IAsyncResult RemAr = bookSlot.BeginInvoke(res.ReservationID, null, null); } catch (SocketException e) { Log.Show(_userName, "ERROR: Could not connect to client. Exception: " + e); } } AbortReservation(res.ReservationID); } }
static PersistenceIOParticipantExtensions() { #pragma warning disable IDE0007 // Use implicit type (https://github.com/dotnet/roslyn/issues/766) ParameterExpression instance = Expression.Parameter(typeof(System.Activities.Persistence.PersistenceIOParticipant), "this"); ParameterExpression readWriteValues = Expression.Parameter(typeof(IDictionary <XName, object>), nameof(readWriteValues)); ParameterExpression writeOnlyValues = Expression.Parameter(typeof(IDictionary <XName, object>), nameof(writeOnlyValues)); ParameterExpression timeout = Expression.Parameter(typeof(TimeSpan), nameof(timeout)); ParameterExpression callback = Expression.Parameter(typeof(AsyncCallback), nameof(callback)); ParameterExpression state = Expression.Parameter(typeof(object), nameof(state)); ParameterExpression result = Expression.Parameter(typeof(IAsyncResult), nameof(result)); MethodInfo method; #pragma warning restore IDE0007 // Use implicit type method = typeof(System.Activities.Persistence.PersistenceIOParticipant).GetMethod( PersistenceParticipantExtensions.IPersistencePipelineModuleFullName + nameof(BeginOnSave), BindingFlags.Instance | BindingFlags.NonPublic); beginOnSave = Expression.Lambda <BeginOnSaveDelegate>( Expression.Call(instance, method, readWriteValues, writeOnlyValues, timeout, callback, state), true, instance, readWriteValues, writeOnlyValues, timeout, callback, state).Compile(); method = typeof(System.Activities.Persistence.PersistenceIOParticipant).GetMethod( PersistenceParticipantExtensions.IPersistencePipelineModuleFullName + nameof(EndOnSave), BindingFlags.Instance | BindingFlags.NonPublic); endOnSave = Expression.Lambda <EndOnSaveDelegate>( Expression.Call(instance, method, result), true, instance, result).Compile(); method = typeof(System.Activities.Persistence.PersistenceIOParticipant).GetMethod( PersistenceParticipantExtensions.IPersistencePipelineModuleFullName + nameof(BeginOnLoad), BindingFlags.Instance | BindingFlags.NonPublic); beginOnLoad = Expression.Lambda <BeginOnLoadDelegate>( Expression.Call(instance, method, readWriteValues, timeout, callback, state), true, instance, readWriteValues, timeout, callback, state).Compile(); method = typeof(System.Activities.Persistence.PersistenceIOParticipant).GetMethod( PersistenceParticipantExtensions.IPersistencePipelineModuleFullName + nameof(EndOnLoad), BindingFlags.Instance | BindingFlags.NonPublic); endOnLoad = Expression.Lambda <EndOnLoadDelegate>( Expression.Call(instance, method, result), true, instance, result).Compile(); method = typeof(System.Activities.Persistence.PersistenceIOParticipant).GetMethod( PersistenceParticipantExtensions.IPersistencePipelineModuleFullName + nameof(Abort), BindingFlags.Instance | BindingFlags.NonPublic); abort = Expression.Lambda <AbortDelegate>( Expression.Call(instance, method), true, instance).Compile(); }
static PersistenceIOParticipantExtensions() { ParameterExpression instance = Expression.Parameter(typeof(System.Activities.Persistence.PersistenceIOParticipant), "this"); ParameterExpression readWriteValues = Expression.Parameter(typeof(IDictionary<XName, object>), nameof(readWriteValues)); ParameterExpression writeOnlyValues = Expression.Parameter(typeof(IDictionary<XName, object>), nameof(writeOnlyValues)); ParameterExpression timeout = Expression.Parameter(typeof(TimeSpan), nameof(timeout)); ParameterExpression callback = Expression.Parameter(typeof(AsyncCallback), nameof(callback)); ParameterExpression state = Expression.Parameter(typeof(object), nameof(state)); ParameterExpression result = Expression.Parameter(typeof(IAsyncResult), nameof(result)); MethodInfo method; method = typeof(System.Activities.Persistence.PersistenceIOParticipant).GetMethod( PersistenceParticipantExtensions.IPersistencePipelineModuleFullName + nameof(BeginOnSave), BindingFlags.Instance | BindingFlags.NonPublic); beginOnSave = Expression.Lambda<BeginOnSaveDelegate>( Expression.Call(instance, method, readWriteValues, writeOnlyValues, timeout, callback, state), true, instance, readWriteValues, writeOnlyValues, timeout, callback, state).Compile(); method = typeof(System.Activities.Persistence.PersistenceIOParticipant).GetMethod( PersistenceParticipantExtensions.IPersistencePipelineModuleFullName + nameof(EndOnSave), BindingFlags.Instance | BindingFlags.NonPublic); endOnSave = Expression.Lambda<EndOnSaveDelegate>( Expression.Call(instance, method, result), true, instance, result).Compile(); method = typeof(System.Activities.Persistence.PersistenceIOParticipant).GetMethod( PersistenceParticipantExtensions.IPersistencePipelineModuleFullName + nameof(BeginOnLoad), BindingFlags.Instance | BindingFlags.NonPublic); beginOnLoad = Expression.Lambda<BeginOnLoadDelegate>( Expression.Call(instance, method, readWriteValues, timeout, callback, state), true, instance, readWriteValues, timeout, callback, state).Compile(); method = typeof(System.Activities.Persistence.PersistenceIOParticipant).GetMethod( PersistenceParticipantExtensions.IPersistencePipelineModuleFullName + nameof(EndOnLoad), BindingFlags.Instance | BindingFlags.NonPublic); endOnLoad = Expression.Lambda<EndOnLoadDelegate>( Expression.Call(instance, method, result), true, instance, result).Compile(); method = typeof(System.Activities.Persistence.PersistenceIOParticipant).GetMethod( PersistenceParticipantExtensions.IPersistencePipelineModuleFullName + nameof(Abort), BindingFlags.Instance | BindingFlags.NonPublic); abort = Expression.Lambda<AbortDelegate>( Expression.Call(instance, method), true, instance).Compile(); }
/* * AUX METHODS */ private void BookNextSlot(Reservation res) { bool booked = false; //LOCK HERE foreach (ReservationSlot slot in res.Slots) { Monitor.Enter(_calendar[slot.SlotID]); CalendarSlot cSlot = _calendar[slot.SlotID]; if (slot.State != ReservationSlotState.ABORTED && !cSlot.Locked && (cSlot.State == CalendarSlotState.ACKNOWLEDGED || (cSlot.State == CalendarSlotState.BOOKED && res.ReservationID < cSlot.ReservationID))) { booked = true; BookCalendarSlot(res, slot); Monitor.Exit(_calendar[slot.SlotID]); Log.Show(_userName, "Starting book process of slot " + slot.SlotID + " from reservation " + res.ReservationID); foreach (string participantID in res.Participants) { if (!participantID.Equals(_userName)) { _msgDispatcher.SendMessage(MessageType.BOOK_SLOT, res.ReservationID, participantID, slot.SlotID); } } break; } else { Monitor.Exit(_calendar[slot.SlotID]); } } if (!booked) { Log.Show(_userName, "No available slots. Aborting reservation " + res.ReservationID); foreach (IBookingService client in res.ClientStubs.Values) { try { Log.Show(_userName, "Sending abort to client..."); AbortDelegate bookSlot = new AbortDelegate(client.AbortReservation); IAsyncResult RemAr = bookSlot.BeginInvoke(res.ReservationID, null, null); } catch (SocketException e) { Log.Show(_userName, "ERROR: Could not connect to client. Exception: " + e); } } AbortReservation(res.ReservationID); } }