void IDispositioningServiceInternal.Dispatch(int operationId, string emkResourceId)
        {
            lock (SyncRoot)
            {
                using (var entities = EntityFrameworkHelper.CreateContext<DispositioningEntities>(EdmxPath))
                {
                    bool exists = entities.DispResources.Any(_ => _.Operation_Id == operationId && _.EmkResourceId == emkResourceId);
                    if (exists)
                    {
                        throw new InvalidOperationException(Properties.Resources.DispatchNotPossibleEntryAlreadyExists);
                    }

                    DispResourceData data = new DispResourceData();
                    data.Operation_Id = operationId;
                    data.EmkResourceId = emkResourceId;
                    data.Timestamp = DateTime.Now;

                    entities.DispResources.AddObject(data);
                    entities.SaveChanges();
                }
            }

            DispositionEventArgs args = new DispositionEventArgs(operationId, emkResourceId, DispositionEventArgs.ActionType.Dispatch);
            OnDispositionEventArgs(args);
        }
        void IDispositioningServiceInternal.Dispatch(int operationId, string emkResourceId)
        {
            lock (SyncRoot)
            {
                using (IUnitOfWork work = ServiceProvider.GetService<IDataContextFactory>().Get().Create())
                {
                    var repository = work.For<DispositionedResourceData>();

                    bool exists = repository.Query.Any(_ => _.OperationId == operationId && _.EmkResourceId == emkResourceId);
                    if (exists)
                    {
                        throw new InvalidOperationException(Properties.Resources.DispatchNotPossibleEntryAlreadyExists);
                    }

                    DispositionedResourceData data = repository.Create();
                    data.OperationId = operationId;
                    data.EmkResourceId = emkResourceId;
                    data.Timestamp = DateTime.Now;

                    repository.Insert(data);

                    work.Commit();
                }
            }

            DispositionEventArgs args = new DispositionEventArgs(operationId, emkResourceId, DispositionEventArgs.ActionType.Dispatch);
            OnDispositionEventArgs(args);
        }
 private void OnDispositionEventArgs(DispositionEventArgs e)
 {
     var copy = Dispositioning;
     if (copy != null)
     {
         copy(this, e);
     }
 }
Exemplo n.º 4
0
 void IDispositioningServiceCallback.OnEvent(DispositionEventArgs evt)
 {
     try
     {
         var copy = Event;
         if (copy != null)
         {
             copy(this, evt);
         }
     }
     catch (Exception ex)
     {
         // Callback methods shall always have a no-throw guarantee!
         Logger.Instance.LogException(this, ex);
     }
 }
 void IDispositioningServiceCallback.OnEvent(DispositionEventArgs evt)
 {
     try
     {
         var copy = Event;
         if (copy != null)
         {
             copy(this, evt);
         }
     }
     catch (Exception ex)
     {
         // Callback methods shall always have a no-throw guarantee!
         Logger.Instance.LogException(this, ex);
     }
 }
Exemplo n.º 6
0
 void IDispositioningServiceCallback.OnEvent(DispositionEventArgs args)
 {
     if (_operation.Id == args.OperationId)
     {
         switch (args.Action)
         {
             case DispositionEventArgs.ActionType.Dispatch:
                 EmkResource emk = _emkResources.FirstOrDefault(x => x.IsActive && x.Id == args.EmkResourceId);
                 Resources.Add(new ResourceViewModel(null, emk));
                 break;
             case DispositionEventArgs.ActionType.Recall:
                 if (Resources.Any(x => x.EmkResourceItem.Id == args.EmkResourceId))
                 {
                     Resources.Remove(Resources.First(x => x.EmkResourceItem.Id == args.EmkResourceId));
                 }
                 break;
         }
     }
 }
Exemplo n.º 7
0
        /// <summary>
        /// Called by the service after a resource was dispatched or recalled.
        /// </summary>
        /// <param name="evt">The event data that describes the event.</param>
        public void OnEvent(DispositionEventArgs evt)
        {
            if (CurrentOperation == null || evt.OperationId != CurrentOperation.Id)
            {
                return;
            }

            if (evt.Action == DispositionEventArgs.ActionType.Dispatch)
            {
                ResourceItem resource = Resources.FirstOrDefault(x => x.EmkResourceItem.Id == evt.EmkResourceId);
                if (resource != null && !resource.IsDispatched)
                {
                    resource.IsDispatched = true;
                    OnPropertyChanged("Resources");
                }
            }
            else if (evt.Action == DispositionEventArgs.ActionType.Recall)
            {
                ResourceItem resource = Resources.FirstOrDefault(x => x.EmkResourceItem.Id == evt.EmkResourceId);
                if (resource != null && resource.IsDispatched)
                {
                    resource.IsDispatched = false;
                    OnPropertyChanged("Resources");
                }
            }
        }
        void IDispositioningServiceInternal.Recall(int operationId, string emkResourceId)
        {
            lock (SyncRoot)
            {
                using (IUnitOfWork work = ServiceProvider.GetService<IDataContextFactory>().Get().Create())
                {
                    var repository = work.For<DispositionedResourceData>();

                    DispositionedResourceData exists = repository.Query.SingleOrDefault(_ => _.OperationId == operationId && _.EmkResourceId == emkResourceId);
                    if (exists == null)
                    {
                        throw new InvalidOperationException(Properties.Resources.RecallNotPossibleEntryDoesNotExist);
                    }

                    repository.Delete(exists);

                    work.Commit();
                }
            }

            DispositionEventArgs args = new DispositionEventArgs(operationId, emkResourceId, DispositionEventArgs.ActionType.Recall);
            OnDispositionEventArgs(args);
        }
        void IDispositioningServiceInternal.Recall(int operationId, string emkResourceId)
        {
            lock (SyncRoot)
            {
                using (var entities = EntityFrameworkHelper.CreateContext<DispositioningEntities>(EdmxPath))
                {
                    DispResourceData exists = entities.DispResources.SingleOrDefault(_ => _.Operation_Id == operationId && _.EmkResourceId == emkResourceId);
                    if (exists == null)
                    {
                        throw new InvalidOperationException(Properties.Resources.RecallNotPossibleEntryDoesNotExist);
                    }

                    entities.DispResources.DeleteObject(exists);
                    entities.SaveChanges();
                }
            }

            DispositionEventArgs args = new DispositionEventArgs(operationId, emkResourceId, DispositionEventArgs.ActionType.Recall);
            OnDispositionEventArgs(args);
        }