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)); }
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."); }
/// <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); }
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); }
public Message(T body) { GuardHelper.ArgumentNotNull(() => body); Body = body; Properties = new MessageProperties(); MessageType = body.GetType(); }
public DefaultLifetimeScopeProvider(ILifetimeScopeAccessor accessor) { GuardHelper.ArgumentNotNull(() => accessor); this._accessor = accessor; AutofacRequestLifetimeHttpModule.SetLifetimeScopeProvider(this); }
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); }
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()); }
public void Set(string key, object value, CachePolicy cachePolicy = null) { GuardHelper.ArgumentNotEmpty(() => key); var cacheKey = new CacheKey(key); Set(cacheKey, value, cachePolicy); }
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)); }
public Message(T body, MessageProperties properties) { GuardHelper.ArgumentNotNull(() => body); GuardHelper.ArgumentNotNull(() => properties); Body = body; Properties = properties; MessageType = body.GetType(); }
public BaseResolver(IUnityContainer container) { if (container == null) { GuardHelper.ArgumentNotNull(() => container); } this.container = container; }
public ExchangeDeclareParam(string name, string type) { GuardHelper.CheckStringLength(() => name, 255); GuardHelper.CheckStringLength(() => type, 255); Name = name; Type = type; Durable = true; }
public DefaultLifetimeScopeAccessor(ILifetimeScope rootContainer) { GuardHelper.ArgumentNotNull(() => rootContainer); //rootContainer.ChildLifetimeScopeBeginning += OnScopeBeginning; this._rootContainer = rootContainer; this._state = new ContextState <ILifetimeScope>("CustomLifetimeScopeProvider.WorkScope"); }
public void Remove(string key) { GuardHelper.ArgumentNotEmpty(() => key); using (cacheProvider.EnterWriteLock()) { cacheProvider.Remove(key); } }
public PricingService(ISeatTypeViewRepository repository) { if (repository == null) { GuardHelper.ArgumentNotNull(() => repository); throw new ArgumentNullException("repository"); } this.repository = repository; }
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); }
public RedisCache(ISerializer serializer, IRedisWrapper redisWrapper = null) { GuardHelper.ArgumentNotNull(() => serializer); if (redisWrapper == null) { redisWrapper = RedisFactory.GetRedisWrapper(); } this.serializer = serializer; this.redisWrapper = redisWrapper; }
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); }
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; }
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); }
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); }
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); }
public T Get <T>(string key) { GuardHelper.ArgumentNotEmpty(() => key); if (cacheProvider.Contains(key)) { return(cacheProvider.Get <T>(key)); } else { return(default(T)); } }
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)); }
/// <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); }
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); } }
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); }