/// <summary> /// Initialize /// </summary> public void Initialize() { if (type == StorageTypeAsync.None) { throw new NotSupportedException("Not support the type of none."); } storage = Activator.CreateInstance(Type.GetType(GetDescription(type))) as IStorageAsync; if (storage == null) { throw new DllNotFoundException("Can not find the type" + type.ToString()); } }
/// <summary> /// Cache pool item /// </summary> /// <param name="index">Item index</param> /// <param name="name">Pool item name</param> /// <param name="storage">Storage instance</param> /// <param name="mode">Storage mode inside the pool</param> /// <param name="pingDelay">Delays between ping tries in milliseconds</param> /// <param name="pingDelayOnError">Delay after a ping error for next try</param> public PoolAsyncItem(int index, string name, IStorageAsync storage, StorageItemMode mode, int pingDelay = 5000, int pingDelayOnError = 30000) { Index = index; Storage = storage; Mode = mode; PingTime = 0; PingDelay = pingDelay; PingDelayOnError = pingDelayOnError; Enabled = false; _tokenSource = new CancellationTokenSource(); _token = _tokenSource.Token; Name = name ?? storage?.ToString(); if (storage?.Type == StorageType.Memory) { Enabled = true; PingTime = 0; } else { _pingTask = PingTaskAsync(); } Core.Status.Attach(collection => { collection.Add(nameof(Name), Name); collection.Add(nameof(Storage), Storage); collection.Add(nameof(Mode), Mode); collection.Add(nameof(PingTime), PingTime); collection.Add(nameof(PingDelay), PingDelay); collection.Add(nameof(PingDelayOnError), PingDelayOnError); collection.Add(nameof(PingResponse), PingResponse, StatusItemValueStatus.Ok); collection.Add(nameof(PingFailure), PingFailure, StatusItemValueStatus.Warning); collection.Add(nameof(PingConsecutiveFailure), PingConsecutiveFailure, PingConsecutiveFailure == 0 ? StatusItemValueStatus.Ok : StatusItemValueStatus.Error); collection.Add(nameof(Enabled), Enabled, Enabled ? StatusItemValueStatus.Ok : StatusItemValueStatus.Error); Core.Status.AttachChild(Storage, this); }); }