Exemplo n.º 1
1
		//private readonly IRepositoryBulkReader BulkReader;
		//private readonly Lazy<World>[] LazyWorlds = new Lazy<World>[512];

		public Context(IObjectFactory factory, IDatabaseQueryManager manager)
		{
			var scope = factory.CreateScope(null);
			scope.RegisterInterfaces(manager.StartQuery(false));
			WorldRepository = scope.Resolve<IPersistableRepository<World>>();
			FortuneRepository = scope.Resolve<IQueryableRepository<Fortune>>();
			//BulkReader = scope.BulkRead(ChunkedMemoryStream.Static());
		}
 public ChangeBrushEventHandler(
     IQueryableRepository <Artist> artistRepository,
     IPersistableRepository <Brush> brushRepository)
 {
     this.artistRepository = artistRepository;
     this.brushRepository  = brushRepository;
 }
Exemplo n.º 3
0
 public void RegisterRepository(IPersistableRepository repository)
 {
     if (!PersistableRepositories.Contains(repository))
     {
         PersistableRepositories.Add(repository);
     }
 }
Exemplo n.º 4
0
 public KadaEvents(
     IPersistableRepository <Kada> kade,
     IPersistableRepository <SlikeKade> slikeKade)
 {
     this.Kade      = kade;
     this.SlikeKade = slikeKade;
 }
Exemplo n.º 5
0
        /// <summary>
        /// Update changed aggregate root.
        /// Aggregate is modified in place.
        /// </summary>
        /// <typeparam name="TRoot">aggregate type</typeparam>
        /// <param name="repository">persistable repository</param>
        /// <param name="data">changed aggregate</param>
        public static void Update <TRoot>(this IPersistableRepository <TRoot> repository, TRoot data)
            where TRoot : IAggregateRoot
        {
            Contract.Requires(repository != null);

            repository.Update(new[] { data });
        }
 public MouseActionEventHandler(
     IRepository <Brush> brushRepository,
     IPersistableRepository <Segment> segmentRepository)
 {
     this.brushRepository   = brushRepository;
     this.segmentRepository = segmentRepository;
 }
Exemplo n.º 7
0
        /// <summary>
        /// Persist aggregate roots. Bulk persistance.
        /// Inserted aggregates will return new identifiers.
        /// Aggregate roots will be modified in place.
        /// For update aggregates, old aggregates will be loaded from change tracking or looked up using aggregate identifier.
        /// </summary>
        /// <typeparam name="TRoot">aggregate root type</typeparam>
        /// <param name="repository">persistable repository</param>
        /// <param name="insert">new aggregates</param>
        /// <param name="update">collection of changed aggregates</param>
        /// <param name="delete">remove aggregates</param>
        /// <returns>created identifiers</returns>
        public static string[] Persist <TRoot>(
            this IPersistableRepository <TRoot> repository,
            IEnumerable <TRoot> insert,
            IEnumerable <TRoot> update,
            IEnumerable <TRoot> delete)
            where TRoot : IAggregateRoot
        {
            Contract.Requires(repository != null);

            if (insert != null && insert.Any() ||
                update != null && update.Any() ||
                delete != null && delete.Any())
            {
                return
                    (repository.Persist(
                         insert,
                         update != null
                                                        ? (from u in update
                                                           let ct = u as IChangeTracking <TRoot>
                                                                    select new KeyValuePair <TRoot, TRoot>(ct != null ? ct.GetOriginalValue() : default(TRoot), u))
                         .ToList()
                                                        : null,
                         delete));
            }
            return(new string[0]);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Insert aggregate root.
        /// Return new identifier.
        /// Aggregate is modified in place.
        /// </summary>
        /// <typeparam name="TRoot">aggregate type</typeparam>
        /// <param name="repository">persistable repository</param>
        /// <param name="data">new aggregate</param>
        /// <returns>assigned identifier</returns>
        public static string Insert <TRoot>(this IPersistableRepository <TRoot> repository, TRoot data)
            where TRoot : IAggregateRoot
        {
            Contract.Requires(repository != null);
            Contract.Requires(data != null);

            return(repository.Insert(new[] { data })[0]);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Update changed aggregate root.
        /// Aggregate is modified in place.
        /// </summary>
        /// <typeparam name="TRoot">aggregate type</typeparam>
        /// <param name="repository">persistable repository</param>
        /// <param name="data">changed aggregate</param>
        public static void Update <TRoot>(this IPersistableRepository <TRoot> repository, TRoot data)
            where TRoot : IAggregateRoot
        {
            Contract.Requires(repository != null);

            var ct = data as IChangeTracking <TRoot>;

            repository.Persist(null, new[] { new KeyValuePair <TRoot, TRoot>(ct != null ? ct.GetOriginalValue() : default(TRoot), data) }, null);
        }
Exemplo n.º 10
0
 public static Task Update <T>(this IPersistableRepository <T> repository, T oldValue, T newValue)
     where T : class, IAggregateRoot
 {
     if (repository == null)
     {
         throw new ArgumentNullException("repository can't be null");
     }
     return(repository.Persist(null, new[] { new KeyValuePair <T, T>(oldValue, newValue) }, null));
 }
Exemplo n.º 11
0
 public static Task <string> Insert <T>(this IPersistableRepository <T> repository, T data)
     where T : class, IAggregateRoot
 {
     if (repository == null)
     {
         throw new ArgumentNullException("repository can't be null");
     }
     return(repository.Insert(new[] { data }).ContinueWith(t => t.Result.First()));
 }
Exemplo n.º 12
0
 public static Task Delete <T>(this IPersistableRepository <T> repository, T data)
     where T : class, IAggregateRoot
 {
     if (repository == null)
     {
         throw new ArgumentNullException("repository can't be null");
     }
     return(repository.Delete(new[] { data }));
 }
Exemplo n.º 13
0
        //private readonly IRepositoryBulkReader BulkReader;
        //private readonly Lazy<World>[] LazyWorlds = new Lazy<World>[512];

        public Context(IObjectFactory factory, IDatabaseQueryManager manager)
        {
            var scope = factory.CreateScope(null);

            scope.RegisterInterfaces(manager.StartQuery(false));
            WorldRepository   = scope.Resolve <IPersistableRepository <World> >();
            FortuneRepository = scope.Resolve <IQueryableRepository <Fortune> >();
            //BulkReader = scope.BulkRead(ChunkedMemoryStream.Static());
        }
Exemplo n.º 14
0
        /// <summary>
        /// Update changed aggregate root.
        /// Aggregate is modified in place.
        /// </summary>
        /// <typeparam name="TRoot">aggregate type</typeparam>
        /// <param name="repository">persistable repository</param>
        /// <param name="oldValue">old aggregate instance</param>
        /// <param name="newValue">new aggregate instance</param>
        public static void Update <TRoot>(this IPersistableRepository <TRoot> repository, TRoot oldValue, TRoot newValue)
            where TRoot : IAggregateRoot
        {
            Contract.Requires(repository != null);
            Contract.Requires(oldValue != null);
            Contract.Requires(newValue != null);

            repository.Persist(null, new[] { new KeyValuePair <TRoot, TRoot>(oldValue, newValue) }, null);
        }
Exemplo n.º 15
0
 public static Task Update <T>(this IPersistableRepository <T> repository, IEnumerable <T> data)
     where T : class, IAggregateRoot
 {
     if (repository == null)
     {
         throw new ArgumentNullException("repository can't be null");
     }
     return(repository.Persist(null, data, null));
 }
Exemplo n.º 16
0
        /// <summary>
        /// Delete aggregate roots.
        /// </summary>
        /// <typeparam name="TRoot">aggregate type</typeparam>
        /// <param name="repository">persistable repository</param>
        /// <param name="data">aggregates to delete</param>
        public static void Delete <TRoot>(this IPersistableRepository <TRoot> repository, IEnumerable <TRoot> data)
            where TRoot : IAggregateRoot
        {
            Contract.Requires(repository != null);

            if (data != null && data.Any())
            {
                repository.Persist(null, null, data);
            }
        }
Exemplo n.º 17
0
		public Context(IServiceProvider service)
		{
			Stream = ChunkedMemoryStream.Static();
			Writer = Stream.GetWriter();
			var dqm = service.Resolve<IDatabaseQueryManager>();
			var factory = service.Resolve<IObjectFactory>().CreateInnerFactory();
			factory.RegisterInterfaces(dqm.StartQuery(false));
			Repository = factory.Resolve<IPersistableRepository<World>>();
			BulkReader = factory.BulkRead(ChunkedMemoryStream.Static());
		}
Exemplo n.º 18
0
        /// <summary>
        /// Insert new aggregate roots.
        /// Aggregates are modified in place.
        /// </summary>
        /// <typeparam name="TRoot">aggregate type</typeparam>
        /// <param name="repository">persistable repository</param>
        /// <param name="data">new aggregates</param>
        /// <returns>created indentifiers</returns>
        public static string[] Insert <TRoot>(this IPersistableRepository <TRoot> repository, IEnumerable <TRoot> data)
            where TRoot : IAggregateRoot
        {
            Contract.Requires(repository != null);

            if (data != null && data.Any())
            {
                return(repository.Persist(data, null, null));
            }
            return(new string[0]);
        }
Exemplo n.º 19
0
        public Context(IServiceProvider service)
        {
            Stream = ChunkedMemoryStream.Static();
            Writer = Stream.GetWriter();
            var dqm     = service.Resolve <IDatabaseQueryManager>();
            var factory = service.Resolve <IObjectFactory>().CreateInnerFactory();

            factory.RegisterInterfaces(dqm.StartQuery(false));
            Repository = factory.Resolve <IPersistableRepository <World> >();
            BulkReader = factory.BulkRead(ChunkedMemoryStream.Static());
        }
Exemplo n.º 20
0
        /// <summary>
        /// Delete aggregate root defined by provided identifier.
        /// Deleted aggregate is returned.
        /// </summary>
        /// <typeparam name="TRoot">aggregate type</typeparam>
        /// <param name="repository">persistable repository</param>
        /// <param name="uri">aggregate identifier</param>
        /// <returns>deleted aggregate root</returns>
        public static TRoot Delete <TRoot>(this IPersistableRepository <TRoot> repository, string uri)
            where TRoot : IAggregateRoot
        {
            Contract.Requires(repository != null);
            Contract.Requires(uri != null);

            var oldValue = repository.Find(uri);

            if (oldValue == null)
            {
                throw new ArgumentException(string.Format("Can't find {0} with URI: {1}", typeof(TRoot).FullName, uri));
            }

            repository.Delete(new[] { oldValue });
            return(oldValue);
        }
Exemplo n.º 21
0
 public static Task <string[]> Persist <T>(
     this IPersistableRepository <T> repository,
     IEnumerable <T> insert,
     IEnumerable <T> update,
     IEnumerable <T> delete)
     where T : class, IAggregateRoot
 {
     if (repository == null)
     {
         throw new ArgumentNullException("repository can't be null");
     }
     return
         (repository.Persist(
              insert,
              update != null ? update.Select(it => new KeyValuePair <T, T>(default(T), it)) : null,
              delete));
 }
Exemplo n.º 22
0
        public static Task Delete <T>(this IPersistableRepository <T> repository, string uri)
            where T : class, IAggregateRoot
        {
            if (repository == null)
            {
                throw new ArgumentNullException("repository can't be null");
            }
            var oldValue = repository.Find(uri);

            return(oldValue.ContinueWith(t =>
            {
                if (t.Result == null)
                {
                    throw new ArgumentException(string.Format("Can't find {0} with URI: {1}", typeof(T).FullName, uri));
                }

                repository.Delete(new[] { t.Result }).Wait();
            }));
        }
Exemplo n.º 23
0
        public CrudController(
            IPersistableRepository <TRoot> repository,
            ICollectionView collectionView,
            Func <TRoot> getCurrent,
            Action <TRoot> setCurrent,
            Action <bool> stateChanged)
        {
            this.Repository     = repository;
            this.CollectionView = collectionView;
            this.GetCurrent     = getCurrent;
            this.SetCurrent     = setCurrent;
            this.StateChanged   = stateChanged;

            Bindings.Add(new CommandBinding(GlobalCommands.New, CreateNew, CanCreateNew));
            Bindings.Add(new CommandBinding(GlobalCommands.Edit, EditCurrent, CanEditOrDeleteCurrent));
            Bindings.Add(new CommandBinding(GlobalCommands.Delete, DeleteCurrent, CanEditOrDeleteCurrent));
            Bindings.Add(new CommandBinding(GlobalCommands.Save, SaveChanges, IsInEdit));
            Bindings.Add(new CommandBinding(GlobalCommands.Cancel, CancelChanges, IsInEdit));

            App.Current.MainWindow.CommandBindings.AddRange(Bindings);
        }
Exemplo n.º 24
0
        //TODO: remove!?
        /// <summary>
        /// Change aggregate root defined by identifier using provided action.
        /// </summary>
        /// <typeparam name="TRoot">aggregate type</typeparam>
        /// <param name="repository">persistable repository</param>
        /// <param name="uri">aggregate identifier</param>
        /// <param name="update">change method</param>
        /// <returns>found and changed aggregate</returns>
        public static TRoot Update <TRoot>(this IPersistableRepository <TRoot> repository, string uri, Action <TRoot> update)
            where TRoot : IAggregateRoot
        {
            Contract.Requires(repository != null);
            Contract.Requires(uri != null);
            Contract.Requires(update != null);

            var found = repository.Find(uri);

            if (found == null)
            {
                throw new ArgumentException(string.Format("Can't find {0} with URI: {1}", typeof(TRoot).FullName, uri));
            }

            var ct       = found as IChangeTracking <TRoot>;
            var original = ct != null
                                ? ct.GetOriginalValue()
                                : found is ICloneable ? (TRoot)((ICloneable)found).Clone() : default(TRoot);

            update(found);
            repository.Persist(null, new[] { new KeyValuePair <TRoot, TRoot>(original, found) }, null);
            return(found);
        }
Exemplo n.º 25
0
 public SigurnostEvents(IPersistableRepository <Korisnik> korisnici)
 {
     this.Korisnici = korisnici;
 }
Exemplo n.º 26
0
 public ModerirajService(IServiceLocator locator)
 {
     this.Locator           = locator;
     this.Kade              = locator.Resolve <IPersistableRepository <Kada> >();
     this.KadaIzvorPodataka = locator.Resolve <IQueryableRepository <KadaIzvorPodataka> >();
 }
Exemplo n.º 27
0
 public RegisterArtist(IPersistableRepository <Artist> artistRepository)
 {
     this.artistRepository = artistRepository;
 }
Exemplo n.º 28
0
 public static void Insert <T>(this IPersistableRepository <T> repository, T item)
     where T : IAggregateRoot
 {
     repository.Save(new[] { item }, null, null);
 }
Exemplo n.º 29
0
 public MarkDoneHandler(IPersistableRepository <Task> repository)
 {
     this.Repository = repository;
 }
Exemplo n.º 30
0
 public static void Delete <T>(this IPersistableRepository <T> repository, T item)
     where T : IAggregateRoot
 {
     repository.Save(null, null, new[] { item });
 }