Beispiel #1
0
        /// <summary>
        /// Carrega os itens com base nas chaves.
        /// </summary>
        /// <param name="keys">Chaves do itens que serão carregados.</param>
        /// <returns>Dicionário dos itens encontrados.</returns>
        public Dictionary <string, ProviderCacheItem> ReadThru(string[] keys)
        {
            Dictionary <string, ProviderCacheItem> dictionary = null;

            try
            {
                dictionary = _provider.LoadFromSource(keys);
            }
            catch (Exception exception)
            {
                throw new OperationFailedException(ResourceMessageFormatter.Create(() => Properties.Resources.OperationFailedException_IReadThruProviderLoadFromSourceFailed).Format(), exception);
            }
            return(dictionary);
        }
        /// <summary>
        /// Responsible for loading the object from the external data source.
        /// Key is passed as parameter.
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        ///
        public void ReadThru(string key, out ProviderCacheItem item, OperationContext operationContext)
        {
            item = null;
            try
            {
                if (_dsReader is ICustomReadThru)
                {
                    if (operationContext.Contains(OperationContextFieldName.ReadThru))
                    {
                        ((ICustomReadThru)_dsReader).DoReadThru =
                            Convert.ToBoolean(operationContext.GetValueByField(OperationContextFieldName.ReadThru));
                    }
                    if (operationContext.Contains(OperationContextFieldName.ReadThru))
                    {
                        ((ICustomReadThru)_dsReader).ProviderName =
                            operationContext.GetValueByField(OperationContextFieldName.ReadThruProviderName) as string;
                    }

                    if (operationContext.Contains(OperationContextFieldName.GroupInfo))
                    {
                        GroupInfo gi = operationContext.GetValueByField(OperationContextFieldName.GroupInfo) as GroupInfo;
                        if (gi != null)
                        {
                            ((ICustomReadThru)_dsReader).Group    = gi.Group;
                            ((ICustomReadThru)_dsReader).SubGroup = gi.SubGroup;
                        }
                    }
                }

                Stopwatch readThruWatch = new Stopwatch();
                readThruWatch.Start();

                _dsReader.LoadFromSource(key, out item);
                readThruWatch.Stop();
                double elapsedByReadThru = readThruWatch.Elapsed.TotalSeconds;

                if (elapsedByReadThru > ServiceConfiguration.CommandExecutionThreshold &&
                    ServiceConfiguration.EnableCommandThresholdLogging)
                {
                    if (_context.NCacheLog != null)
                    {
                        _context.NCacheLog.Warn("ReadThruProviderMgr.ReadThru",
                                                "ReadThru took " + elapsedByReadThru +
                                                " seconds to complete. Which is longer than expected.");
                    }
                }

                this._context.PerfStatsColl.IncrementReadThruPerSec();
            }
            catch (Exception e)
            {
                //Client doesnt throw the inner exception
                //Client casts the thrown exception message into Operation failed Exception therefore the current inner exception will be casted
                //in Operation failed exception > Inner Exception > Inner Exception
                throw new OperationFailedException("IReadThruProvider.LoadFromSource failed. Error: " + e.ToString(), e);
            }
            finally
            {
                try
                {
                    // reset all here
                    ((ICustomReadThru)_dsReader).DoReadThru   = false;
                    ((ICustomReadThru)_dsReader).Group        = null;
                    ((ICustomReadThru)_dsReader).SubGroup     = null;
                    ((ICustomReadThru)_dsReader).ProviderName = null;
                }
                catch {}
            }
        }