Exemplo n.º 1
0
 /// <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);
 }
Exemplo n.º 2
0
 /// <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);
     }
 }
Exemplo n.º 3
0
        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
                                        };
            }
        }
Exemplo n.º 4
0
 /// <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;
 }
Exemplo n.º 5
0
 public IOperationResponse Create(bool status, ServiceOperationAction action, string message)
 {
     return status
             ? new ServiceOperationResponse(true, action) {StatusMessage = message}
             : new ServiceOperationResponse(false, action) {ErrorMessage = message};
 }
Exemplo n.º 6
0
 public IOperationResponse Create(bool status, ServiceOperationAction action)
 {
     return new ServiceOperationResponse(status, action);
 }
Exemplo n.º 7
0
 /// <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;
 }
Exemplo n.º 8
0
 /// <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;
 }