/// <summary> /// Initializes a new instance of the <see cref="AsyncEventOperation"/> class. /// </summary> /// <param name="asyncEvent">The asynchronous event.</param> /// <param name="poolHandler">The pool handler.</param> /// <param name="eventLog">The event log.</param> public AsyncEventOperation(AsyncEvent asyncEvent, IAsyncEventExecutionEngine poolHandler, IMyEventLog eventLog) : base("AsyncEventOperation", eventLog) { AsyncEventOperation asyncEventOperation = this; this.AsyncEvent = asyncEvent; this._poolHander = poolHandler; this._eventAction = operation => asyncEventOperation.ReuseResource = !(asyncEventOperation._poolHander.ProcessAsyncEvent(asyncEvent) is AsyncInProgressResult); }
/// <summary> /// Executes the specified operation. /// </summary> /// <param name="operation">The operation.</param> /// <param name="operationParameter">The operation parameter.</param> public void Execute(ServiceOperationAction operation, IServiceOperation operationParameter) { var monitoredOperation = operationParameter as IMonitoredOperation; AsyncServiceException.Assert(monitoredOperation != null, "容错行为只能应用到继承于IMonitoredOperation的操作上。"); try { operation(monitoredOperation); } catch (Exception ex) { if (!this._service.IsRunningInSafeMode) throw; else monitoredOperation.MarkAsIncomplete(ex); } }
public IManyToManyRelationship SaveTranslation( ITranslation translation, out ServiceOperationAction action) { action = ServiceOperationAction.Update; if (!translationValidator.Validate(translation).Status) { throw new ValidationFailedException(); } using (var context = ContextFactory.Build()) { var targetTranslation = GetTranslation(translation.Id) ?? GetTranslation(translation.Source.Id, translation.Target.Id); if (targetTranslation == null) { targetTranslation = context.Translations.CreateObject<Translation>(); context.Translations.AddObject(targetTranslation); action = ServiceOperationAction.Create; } else { context.Attach(targetTranslation); action = ServiceOperationAction.Update; } targetTranslation.Source = context.Words.Single(item => item.Id == translation.Source.Id); targetTranslation.Target = context.Words.Single(item => item.Id == translation.Target.Id); context.SaveChanges(); // TODO: to factory return new ManyToManyRelationship { Id = targetTranslation.Id, SourceId = targetTranslation.SourceId, TargetId = targetTranslation.TargetId }; } }
/// <summary> /// Initializes a new instance of the <see cref="GenericMonitoredOperation"/> class. /// </summary> /// <param name="eventName">Name of the event.</param> /// <param name="eventAction">The event action.</param> /// <param name="eventLog">The event log.</param> protected GenericMonitoredOperation(string eventName, ServiceOperationAction eventAction, IMyEventLog eventLog) : base(eventName, eventLog) { this._eventAction = eventAction; }
public IOperationResponse Create(bool status, ServiceOperationAction action, string message) { return status ? new ServiceOperationResponse(true, action) {StatusMessage = message} : new ServiceOperationResponse(false, action) {ErrorMessage = message}; }
public IOperationResponse Create(bool status, ServiceOperationAction action) { return new ServiceOperationResponse(status, action); }
/// <summary> /// Creates the queue management operation. /// </summary> /// <param name="queueName">Name of the queue.</param> /// <param name="eventName">Name of the event.</param> /// <param name="eventAction">The event action.</param> /// <returns></returns> public IServiceOperation CreateQueueManagementOperation(string queueName, string eventName, IOrganizationConfiguration organizationConfiguration, ServiceOperationAction eventAction) { var managementOperation = new QueueManagementOperation(queueName, eventName, organizationConfiguration, eventAction, this.EventLog); this.ApplyBehaviors(managementOperation); return managementOperation; }
/// <summary> /// Creates the organization operation. /// </summary> /// <param name="name">The name.</param> /// <param name="organizationConfiguration">The organization configuration.</param> /// <param name="eventAction">The event action.</param> /// <returns></returns> public IServiceOperation CreateOrganizationOperation(string name, IOrganizationConfiguration organizationConfiguration, ServiceOperationAction eventAction) { var organizationOperation = new OrganizationOperation(name, organizationConfiguration, eventAction, this.EventLog); this.ApplyBehaviors( organizationOperation); return organizationOperation; }