Beispiel #1
0
 /// <inheritdoc />
 public void InsertAll(List <T> objects, KeyManagementStrategyType keyManagement = KeyManagementStrategyType.CollectionDecides)
 {
     foreach (var obj in objects)
     {
         Insert(obj, keyManagement);
     }
 }
Beispiel #2
0
 /// <inheritdoc />
 public void ReplaceAll(List <TDomainData> objects, KeyManagementStrategyType keyManagement = KeyManagementStrategyType.CollectionDecides)
 {
     RemoveAll();
     foreach (var obj in objects)
     {
         Insert(obj, keyManagement);
     }
 }
Beispiel #3
0
 public PersistableCatalog(
     IInMemoryCollection <T> collection,
     IPersistentSource <T> source,
     List <PersistencyOperations> supportedOperations,
     KeyManagementStrategyType keyManagementStrategy = KeyManagementStrategyType.CollectionDecides)
     : base(collection, source, supportedOperations, keyManagementStrategy)
 {
 }
Beispiel #4
0
 protected PersistableCatalogFull(
     IInMemoryCollection <TDomainData> collection,
     IPersistentSource <TPersistentData> source,
     List <PersistencyOperations> supportedOperations,
     KeyManagementStrategyType keyManagementStrategy = KeyManagementStrategyType.CollectionDecides)
     : base(collection, source, supportedOperations, keyManagementStrategy)
 {
     _persistentSource = source;
 }
Beispiel #5
0
        /// <inheritdoc />
        public int Insert(T obj, KeyManagementStrategyType keyManagement = KeyManagementStrategyType.CollectionDecides)
        {
            if (keyManagement == KeyManagementStrategyType.CollectionDecides)
            {
                obj.Key = NextKey();
            }
            _collection.Add(obj.Key, obj);

            return(obj.Key);
        }
Beispiel #6
0
        /// <summary>
        /// Creates a new domain object in the catalog,
        /// based on the data provided in the TVMO object
        /// </summary>
        /// <param name="vmObj">
        /// Object containing data for domain object creation
        /// </param>
        /// <param name="keyManagement">
        /// Strategy for selecting the key for the new domain object
        /// </param>
        public void Create(TVMO vmObj, KeyManagementStrategyType keyManagement = KeyManagementStrategyType.CollectionDecides)
        {
            // Create the new domain object (this is where it happens :-)).
            T obj = CreateDomainObjectFromVMO(vmObj);

            // Strategy for key selection (DataSource decides)
            // 1) Throw exception if Create operation is not supported,
            //    since choosing DataSourceDecides is then meaningless.
            // 2) Call Create on data source, and use returned key value
            //    as the new key for the object.
            // 3) Call Insert on the in-memory collection.
            if (keyManagement == KeyManagementStrategyType.DataSourceDecides)
            {
                if (!_supportedOperations.Contains(PersistencyOperations.Create))
                {
                    throw new NotSupportedException("The referenced data source does not support Create.");
                }

                obj.Key = _source.Create(CreateDTO(obj)).Result;
                _collection.Insert(obj, keyManagement);
            }

            // Strategy for key selection (Caller decides)
            // 1) If the data source supports the Create operation,
            //    call Create on data source. It is assumed that it
            //    is NOT an error to call this method, even if the
            //    data source does not support it.
            // 2) Call Insert on the in-memory collection.
            if (keyManagement == KeyManagementStrategyType.CallerDecides)
            {
                if (_supportedOperations.Contains(PersistencyOperations.Create))
                {
                    _source.Create(CreateDTO(obj));
                }
                _collection.Insert(obj, keyManagement);
            }

            // Strategy for key selection (Collection decides)
            // 1) Throw exception if Create operation is not supported,
            //    since choosing DataSourceDecides is then meaningless.
            // 2) If the data source supports the Create operation,
            //    call Create on data source. It is assumed that it
            //    is NOT an error to call this method, even if the
            //    data source does not support it.
            if (keyManagement == KeyManagementStrategyType.CollectionDecides)
            {
                obj.Key = _collection.Insert(obj, keyManagement);
                if (_supportedOperations.Contains(PersistencyOperations.Create))
                {
                    _source.Create(CreateDTO(obj));
                }
            }

            CatalogChanged?.Invoke(obj.Key);
        }
Beispiel #7
0
 protected CatalogFull(
     IInMemoryCollection <T> collection,
     IDataSourceCRUD <TPersistentData> source,
     List <PersistencyOperations> supportedOperations,
     KeyManagementStrategyType keyManagementStrategy = KeyManagementStrategyType.CollectionDecides)
 {
     _collection            = collection;
     _source                = source;
     _supportedOperations   = supportedOperations;
     _keyManagementStrategy = keyManagementStrategy;
 }
Beispiel #8
0
 protected RestApiCatalogFull(string url, string apiID, KeyManagementStrategyType kms)
     : base(new InMemoryCollection <TDomainData>(), new ConfiguredRestAPISource <TPersistentData>(url, apiID),
            new List <PersistencyOperations>
 {
     PersistencyOperations.Load,
     PersistencyOperations.Create,
     PersistencyOperations.Read,
     PersistencyOperations.Update,
     PersistencyOperations.Delete
 },
            kms)
 {
 }
Beispiel #9
0
 protected EFCoreCatalogFull(KeyManagementStrategyType kms)
     : base(new InMemoryCollection <TDomainData>(),
            new ConfiguredEFCoreSource <TDbContext, TPersistentData>(),
            new List <PersistencyOperations>
 {
     PersistencyOperations.Load,
     PersistencyOperations.Create,
     PersistencyOperations.Read,
     PersistencyOperations.Update,
     PersistencyOperations.Delete
 },
            kms)
 {
 }
Beispiel #10
0
 public RestApiCatalog(string url, string apiID, KeyManagementStrategyType kms) : base(url, apiID, kms)
 {
 }
Beispiel #11
0
 public EFCoreCatalog(KeyManagementStrategyType kms) : base(kms)
 {
 }