Esempio n. 1
0
        public override T DoGet <T>(string key, Func <T> acquirer, CachePolicy cachePolicy, bool IsAllowDirtyRead)
        {
            GuardHelper.ArgumentNotEmpty(() => key);
            var cacheKey = new CacheKey(key);

            return(DoGet(cacheKey, acquirer, cachePolicy, IsAllowDirtyRead));
        }
Esempio n. 2
0
        public void InvokeChannelAction(Action <IModel> channelAction)
        {
            GuardHelper.ArgumentNotNull(() => channelAction);
            var startTime    = DateTime.UtcNow;
            var retryTimeout = TimeSpan.FromMilliseconds(50);

            while (!IsTimedOut(startTime))
            {
                try
                {
                    var channel = OpenChannel();
                    channelAction(channel);
                    return;
                }
                catch (OperationInterruptedException)
                {
                    CloseChannel();
                }
                catch (ZRabbitMqException)
                {
                    CloseChannel();
                }

                Thread.Sleep(retryTimeout);

                retryTimeout = retryTimeout.Double();
            }
            Logger.Error("Channel action timed out. Throwing exception to client.");
            throw new TimeoutException("The operation requested on PersistentChannel timed out.");
        }
Esempio n. 3
0
        /// <summary>
        /// Gets a value indicating whether the given min. required app version is assumed
        /// to be compatible with the current app version
        /// </summary>
        /// <remarks>
        /// A plugin is generally compatible when both app version and plugin's
        /// <c>MinorAppVersion</c> are equal, OR - when app version is greater - it is
        /// assumed to be compatible when no breaking changes occured since <c>MinorAppVersion</c>.
        /// </remarks>
        /// <param name="minAppVersion">The min. app version to check for</param>
        /// <returns><c>true</c> when the extension's version is assumed to be compatible</returns>
        public static bool IsAssumedCompatible(Version minAppVersion)
        {
            GuardHelper.ArgumentNotNull(() => minAppVersion);

            if (ZSharpVersion.Version == minAppVersion)
            {
                return(true);
            }

            if (ZSharpVersion.Version < minAppVersion)
            {
                return(false);
            }

            bool compatible = true;

            foreach (var version in ZSharpVersion.BreakingChangesHistory)
            {
                if (version > minAppVersion)
                {
                    // there was a breaking change in a version greater
                    // than plugin's MinorAppVersion.
                    compatible = false;
                    break;
                }

                if (version <= minAppVersion)
                {
                    break;
                }
            }

            return(compatible);
        }
Esempio n. 4
0
        public override void DoSet(string key, object value, CachePolicy cachePolicy)
        {
            GuardHelper.ArgumentNotEmpty(() => key);
            var cacheKey = new CacheKey(key);

            DoSet(cacheKey, value, cachePolicy);
        }
        public static IRedisConfiguration GetConfig(string redisConfigName)
        {
            GuardHelper.ArgumentNotNull(() => redisConfigName);

            var handler = ConfigurationManager.GetSection("redisConfig") as RedisConfigurationHandler;

            GuardHelper.ArgumentNotNull(() => handler);
            RedisHostGroup group = null;

            foreach (RedisHostGroup item in handler.HostGroups)
            {
                if (item.Name.Equals(redisConfigName, StringComparison.OrdinalIgnoreCase))
                {
                    group = item;
                    break;
                }
            }

            if (group == null)
            {
                throw new Exception(string.Format("Redis配置错误,根據服務器配置組名:{0}找不到Redis服務器组", redisConfigName));
            }

            return(group);
        }
Esempio n. 6
0
 public Message(T body)
 {
     GuardHelper.ArgumentNotNull(() => body);
     Body        = body;
     Properties  = new MessageProperties();
     MessageType = body.GetType();
 }
Esempio n. 7
0
        public DefaultLifetimeScopeProvider(ILifetimeScopeAccessor accessor)
        {
            GuardHelper.ArgumentNotNull(() => accessor);

            this._accessor = accessor;
            AutofacRequestLifetimeHttpModule.SetLifetimeScopeProvider(this);
        }
Esempio n. 8
0
        public virtual IServiceRegister Register <TService>(
            Func <IServiceProvider, TService> serviceFactory,
            DependencyLifecycle lifecycle = DependencyLifecycle.Singleton)
            where TService : class
        {
            GuardHelper.ArgumentNotNull(() => serviceFactory);
            CheckDependencyLifecycle(lifecycle);
            var serviceType = typeof(TService);

            if (ServiceIsRegistered(serviceType))
            {
                return(this);
            }
            lock (syncLock)
            {
                if (lifecycle == DependencyLifecycle.Singleton)
                {
                    var service = serviceFactory(this);
                    instances.TryAdd(serviceType, service);
                }
                else
                {
                    factories.TryAdd(serviceType, serviceFactory);
                }
            }
            return(this);
        }
Esempio n. 9
0
        private IDisposable Consume(
            IQueue queue,
            Func <byte[], MessageProperties, MessageReceivedInfo, Task> onMessage,
            Action <IConsumerConfiguration> configure)
        {
            GuardHelper.ArgumentNotNull(() => queue);
            GuardHelper.ArgumentNotNull(() => onMessage);
            if (disposed)
            {
                throw new ZRabbitMqException("This bus has been disposed");
            }

            var consumerConfiguration = new ConsumerConfiguration(RabbitMqConfiguration.PrefetchCount);

            if (configure != null)
            {
                configure(consumerConfiguration);
            }

            var consumerFactory = ServiceLocator.GetInstance <IConsumerFactory>();
            var consumer        = consumerFactory.CreateConsumer(queue, (body, properties, receviedInfo) =>
            {
                var rawMessage = ProduceConsumeInterceptor.OnConsume(new RawMessage(properties, body));
                return(onMessage(rawMessage.Body, rawMessage.Properties, receviedInfo));
            }, connection, consumerConfiguration);

            return(consumer.StartConsuming());
        }
Esempio n. 10
0
        public void Set(string key, object value, CachePolicy cachePolicy = null)
        {
            GuardHelper.ArgumentNotEmpty(() => key);
            var cacheKey = new CacheKey(key);

            Set(cacheKey, value, cachePolicy);
        }
Esempio n. 11
0
        public T Get <T>(string key, Func <T> acquirer, CachePolicy cachePolicy = null)
        {
            GuardHelper.ArgumentNotEmpty(() => key);
            var cacheKey = new CacheKey(key);

            return(Get(cacheKey, acquirer, cachePolicy));
        }
Esempio n. 12
0
 public Message(T body, MessageProperties properties)
 {
     GuardHelper.ArgumentNotNull(() => body);
     GuardHelper.ArgumentNotNull(() => properties);
     Body        = body;
     Properties  = properties;
     MessageType = body.GetType();
 }
Esempio n. 13
0
 public BaseResolver(IUnityContainer container)
 {
     if (container == null)
     {
         GuardHelper.ArgumentNotNull(() => container);
     }
     this.container = container;
 }
Esempio n. 14
0
 public ExchangeDeclareParam(string name, string type)
 {
     GuardHelper.CheckStringLength(() => name, 255);
     GuardHelper.CheckStringLength(() => type, 255);
     Name    = name;
     Type    = type;
     Durable = true;
 }
Esempio n. 15
0
        public DefaultLifetimeScopeAccessor(ILifetimeScope rootContainer)
        {
            GuardHelper.ArgumentNotNull(() => rootContainer);

            //rootContainer.ChildLifetimeScopeBeginning += OnScopeBeginning;

            this._rootContainer = rootContainer;
            this._state         = new ContextState <ILifetimeScope>("CustomLifetimeScopeProvider.WorkScope");
        }
Esempio n. 16
0
        public void Remove(string key)
        {
            GuardHelper.ArgumentNotEmpty(() => key);

            using (cacheProvider.EnterWriteLock())
            {
                cacheProvider.Remove(key);
            }
        }
Esempio n. 17
0
        public PricingService(ISeatTypeViewRepository repository)
        {
            if (repository == null)
            {
                GuardHelper.ArgumentNotNull(() => repository);
                throw new ArgumentNullException("repository");
            }

            this.repository = repository;
        }
Esempio n. 18
0
        public static IMessage CreateInstance(Type messageType, object body)
        {
            GuardHelper.ArgumentNotNull(() => messageType);
            GuardHelper.ArgumentNotNull(() => body);

            var genericType = genericMessageTypesMap.GetOrAdd(messageType, t => typeof(Message <>).MakeGenericType(messageType));
            var message     = ReflectionHelper.CreateInstance(genericType, body);

            return((IMessage)message);
        }
Esempio n. 19
0
        public RedisCache(ISerializer serializer, IRedisWrapper redisWrapper = null)
        {
            GuardHelper.ArgumentNotNull(() => serializer);
            if (redisWrapper == null)
            {
                redisWrapper = RedisFactory.GetRedisWrapper();
            }

            this.serializer   = serializer;
            this.redisWrapper = redisWrapper;
        }
Esempio n. 20
0
        public async Task PublishAsync <T>(T message, string topic) where T : class
        {
            GuardHelper.ArgumentNotNull(() => message);
            GuardHelper.ArgumentNotEmpty(() => topic);
            var messageType   = typeof(T);
            var rabbitMessage = GetRabbitMessage(message, messageType);
            var exchange      = await publishExchangeDeclareStrategy.DeclareExchangeAsync(
                advancedBus, messageType, ExchangeType.Topic).ConfigureAwait(false);

            await advancedBus.PublishAsync(exchange, topic, rabbitMessage).ConfigureAwait(false);
        }
Esempio n. 21
0
        public LogSetting(Type type, NameValueCollection nvList)
        {
            GuardHelper.ArgumentNotNull(() => type);
            var msg = string.Format("Type {0} does not implement {1}",
                                    type.AssemblyQualifiedName, typeof(ILoggerAdapter).FullName);

            GuardHelper.Implements <ILoggerAdapter>(type, msg);

            factoryAdapterType = type;
            properties         = nvList;
        }
Esempio n. 22
0
        private void PreparePublish(IExchange exchange, string routingKey, IMessage <T> message)
        {
            GuardHelper.ArgumentNotNull(() => exchange);
            GuardHelper.ArgumentNotNull(() => routingKey);
            GuardHelper.ArgumentNotNull(() => message);
            this.exchange   = exchange;
            this.routingKey = routingKey;

            mandatory = RabbitMqConfiguration.Mandatory;
            SerializeMessage(message);
        }
Esempio n. 23
0
        public void Publish <T>(T message, string topic) where T : class
        {
            GuardHelper.ArgumentNotNull(() => message);

            var         messageType   = typeof(T);
            Message <T> rabbitMessage = GetRabbitMessage(message, messageType);
            var         exchange      = publishExchangeDeclareStrategy.DeclareExchange(
                advancedBus, messageType, ExchangeType.Topic);

            advancedBus.Publish(exchange, topic, rabbitMessage);
        }
Esempio n. 24
0
        public IHandlerRegistration Add <T>(Func <IMessage <T>, MessageReceivedInfo, Task> handler) where T : class
        {
            GuardHelper.ArgumentNotNull(() => handler);

            if (handlers.ContainsKey(typeof(T)))
            {
                throw new ZRabbitMqException("There is already a handler for message type '{0}'", typeof(T).Name);
            }

            handlers.Add(typeof(T), (iMessage, messageReceivedInfo) => handler((IMessage <T>)iMessage, messageReceivedInfo));
            return(this);
        }
Esempio n. 25
0
 public T Get <T>(string key)
 {
     GuardHelper.ArgumentNotEmpty(() => key);
     if (cacheProvider.Contains(key))
     {
         return(cacheProvider.Get <T>(key));
     }
     else
     {
         return(default(T));
     }
 }
Esempio n. 26
0
        public static bool HasDefaultConstructor(this Type type)
        {
            GuardHelper.ArgumentNotNull(() => type);

            if (type.IsValueType)
            {
                return(true);
            }

            return(type.GetConstructors(BindingFlags.Instance | BindingFlags.Public)
                   .Any(ctor => ctor.GetParameters().Length == 0));
        }
Esempio n. 27
0
        /// <summary>
        /// Mark plugin as uninstalled
        /// </summary>
        /// <param name="systemName">Plugin system name</param>
        public static void MarkPluginAsUninstalled(string systemName)
        {
            GuardHelper.ArgumentNotEmpty(() => systemName);

            var  installedPluginSystemNames = GetInstalledPluginNames();
            bool alreadyMarkedAsInstalled   = installedPluginSystemNames.Contains(systemName);

            if (alreadyMarkedAsInstalled)
            {
                installedPluginSystemNames.Remove(systemName);
            }
            PluginFileParser.SaveInstalledPluginsFile(installedPluginSystemNames);
        }
Esempio n. 28
0
        public override void DoRemove(string key)
        {
            GuardHelper.ArgumentNotEmpty(() => key);

            RealRemove(key);

            //如果採用臟讀寫入數據時,刪除時應該把相應的CacheSign的數據同時刪除
            var signKey = string.Format(CacheKeyTemplates.CacheSign, key);

            if (this.Contains(signKey))
            {
                RealRemove(signKey);
            }
        }
Esempio n. 29
0
        public string Serialize(Type type)
        {
            GuardHelper.ArgumentNotNull(() => type);

            return(serializedTypes.GetOrAdd(type, t =>
            {
                var typeName = t.FullName + ":" + t.Assembly.GetName().Name;
                if (typeName.Length > 255)
                {
                    throw new FrameworkException("The serialized name of type '{0}' exceeds the AMQP " +
                                                 "maximum short string length of 255 characters.", t.Name);
                }
                return typeName;
            }));
        }
 public bool TryStoreIconToFile(ImageSource icon, string storageFolder, out string iconID, out string iconPath)
 {
     GuardHelper.ArgumentNotNull(icon, "icon");
     byte[] iconBytes = null;
     try {
         iconBytes = ImageLoader2.ImageToByteArray(icon, baseUri);
     } catch (Exception) {
         iconID   = null;
         iconPath = null;
         return(false);
     }
     iconID   = NativeResourceManager.CreateFileName(GetImageHash(iconBytes)) + ".ico";
     iconPath = UnpackIcon(Path.Combine(storageFolder, iconID), iconBytes);
     return(iconPath != null);
 }