Ejemplo n.º 1
0
        /// <summary>
        /// Responsible for loading data structures from the external data source.
        /// </summary>
        /// <param name="key">key to fetch from data source</param>
        /// <param name="dataType">type of data structure received</param>
        /// <returns>Data structure contained in ProviderCacheItem which can be enumerated</returns>
        public ProviderDataTypeItem <IEnumerable> LoadDataTypeFromSource(string key, DistributedDataType dataType)
        {
            // initialize ProviderDataTypeItem to return
            ProviderDataTypeItem <IEnumerable> providerItem = null;

            // create a switch to handle different Data Structures
            switch (dataType)
            {
            // incase of counter, the value will be a long data type
            case DistributedDataType.Counter:
                providerItem = new ProviderDataTypeItem <IEnumerable>(sqlDatasource.GetCustomerCountByCompanyName(key));
                break;

            // incase of all other data types, the result must be enumerable
            case DistributedDataType.Dictionary:
                providerItem = new ProviderDataTypeItem <IEnumerable>(sqlDatasource.LoadCustomersByCity(key));
                break;

            case DistributedDataType.List:
                providerItem = new ProviderDataTypeItem <IEnumerable>(sqlDatasource.LoadCustomersFromCountry(key));
                break;

            case DistributedDataType.Queue:
                providerItem = new ProviderDataTypeItem <IEnumerable>(sqlDatasource.LoadCustomersByOrder(key));
                break;

            case DistributedDataType.Set:
                // only primitive types can be used for HashSet
                providerItem = new ProviderDataTypeItem <IEnumerable>(sqlDatasource.LoadOrderIDsByCustomer(key));
                break;
            }

            return(providerItem);
        }
Ejemplo n.º 2
0
        public ProviderDataTypeItem <IEnumerable> LoadDataTypeFromSource(string key, DistributedDataType dataType)
        {
            IEnumerable value = null;
            ProviderDataTypeItem <IEnumerable> dataTypeItem = null;

            switch (dataType)
            {
            case DistributedDataType.List:
                value = new List <object>()
                {
                    LoadFromDataSource(key)
                };
                dataTypeItem = new ProviderDataTypeItem <IEnumerable>(value);
                break;

            case DistributedDataType.Dictionary:
                value = new Dictionary <string, object>()
                {
                    { key, LoadFromDataSource(key) }
                };
                dataTypeItem = new ProviderDataTypeItem <IEnumerable>(value);
                break;

            case DistributedDataType.Counter:
                dataTypeItem = new ProviderDataTypeItem <IEnumerable>(1000);
                break;
            }

            return(dataTypeItem);
        }
 public virtual void UpdateToDataType(string key, ProviderItemBase items, DistributedDataType dataType)
 {
     //update to data structure
     switch (dataType)
     {
     case DistributedDataType.List:
         //According to the user's logic
         break;
     }
 }
 public virtual void RemoveFromDataType(string keys, DistributedDataType dataType)
 {
     //Remove from data structure
     switch (dataType)
     {
     case DistributedDataType.List:
         //According to the user's logic
         break;
     }
 }
Ejemplo n.º 5
0
 /// <summary>
 /// LoadDataTypeFromSource to load data type from source.
 /// </summary>
 /// <param name="key">key of data type</param>
 /// <param name="dataType">type of datatype</param>
 /// <returns>It returns the ProviderDataTypeItem IEnerable</returns>
 public ProviderDataTypeItem <IEnumerable> LoadDataTypeFromSource(string key, DistributedDataType dataType)
 {
     try
     {
         //Data structures are avaialable in ProviderDataTypeItem<IEnumerable>
         return((ProviderDataTypeItem <IEnumerable>)PersistenceProvider.Get(new string[] { key })?[key]);
     }
     catch (Exception e)
     {
         Logger.LogError(e.Message);
         throw e;
     }
 }
        public ProviderDataTypeItem <IEnumerable> LoadDataTypeFromSource(
            string key,
            DistributedDataType dataType)
        {
            if (key.StartsWith("Customer:Country:"))
            {
                string country = key.Replace("Customer:Country:", "");

                var commandDefinition = new CommandDefinition(
                    $@" SELECT CustomerID 
                                                        FROM dbo.Customers 
                                                        WHERE Country = @cntry",
                    new { cntry = country },
                    flags: CommandFlags.NoCache);
                var customerIds = Connection.Query <string>(
                    commandDefinition);

                return(new ProviderDataTypeItem <IEnumerable>(customerIds)
                {
                    Dependency = GetCustomerIDsByCountrySqlDependency(country),
                    ResyncOptions = new ResyncOptions(true),
                    Expiration = new Expiration(
                        ExpirationType.Absolute,
                        TimeSpan.FromMinutes(10))
                });
            }
            else if (key == "Customer:CustomerID:All")
            {
                var commandDefinition = new CommandDefinition(
                    $@" SELECT CustomerID 
                                                        FROM dbo.Customers",
                    flags: CommandFlags.NoCache);

                var customerIds = Connection.Query <string>(
                    commandDefinition);

                return(new ProviderDataTypeItem <IEnumerable>(customerIds)
                {
                    Dependency = GetCustomerIDsSqlDependency(),
                    ResyncOptions = new ResyncOptions(true),
                    Expiration = new Expiration(
                        ExpirationType.Absolute,
                        TimeSpan.FromMinutes(10))
                });
            }

            return(null);
        }
 public void UpdateToDataType(string key, ProviderItemBase items, DistributedDataType dataType)
 {
     throw new NotImplementedException();
 }
 public void RemoveFromDataType(string keys, DistributedDataType dataType)
 {
     throw new NotImplementedException();
 }
 public ProviderDataTypeItem <IEnumerable> LoadDataTypeFromSource(string key, DistributedDataType dataType)
 {
     throw new NotImplementedException();
 }