예제 #1
0
 /// <inheritdoc />
 /// <summary>
 /// Init this storage
 /// </summary>
 protected override void OnInit()
 {
     Ensure.ReferenceNotNull(BasePath, "The FileStorage BasePath, is null.");
     Core.Log.InfoBasic("Initializing FileStorage...");
     if (_handlers?.Any() == true)
     {
         Core.Log.InfoBasic("Disposing previous instances...");
         _handlers.Each(fsto => fsto.Dispose());
         _handlers = null;
     }
     if (!Directory.Exists(BasePath))
     {
         Core.Log.InfoBasic("Creating base folder");
         Directory.CreateDirectory(BasePath);
     }
     Core.Log.InfoBasic("Configuring {0} Subfolders", NumberOfSubFolders);
     _handlers = new FolderHandler[NumberOfSubFolders];
     for (var i = 0; i < NumberOfSubFolders; i++)
     {
         var folder = Path.Combine(BasePath, i.ToString());
         Core.Log.InfoBasic("Initializing Subfolder: {0} on {1}", i, folder);
         _handlers[i] = new FolderHandler(folder, this);
     }
     Core.Log.InfoBasic("Waiting the folder handlers to be loaded.");
     TaskHelper.SleepUntil(() => _handlers.All(s => s.Loaded)).WaitAsync();
     Core.Log.InfoBasic("All folder handlers are loaded, Index Count: {0}", Metas.Count());
     SetReady(true);
 }
예제 #2
0
 /// <inheritdoc />
 /// <summary>
 /// File Cache Storage
 /// </summary>
 public FileStorage(string basePath)
 {
     basePath = Factory.ResolveLowLowPath(basePath);
     BasePath = basePath;
     Core.Status.Attach(collection =>
     {
         collection.Add(nameof(BasePath), BasePath);
         collection.Add("Count", Metas?.Count(), StatusItemValueStatus.Ok);
         collection.Add(nameof(IndexSerializer), IndexSerializer);
         collection.Add(nameof(NumberOfSubFolders), NumberOfSubFolders, NumberOfSubFolders > 10 ? StatusItemValueStatus.Ok : NumberOfSubFolders > 2 ? StatusItemValueStatus.Warning : StatusItemValueStatus.Error);
         collection.Add(nameof(TransactionLogThreshold), TransactionLogThreshold);
         collection.Add(nameof(SlowDownWriteThreshold), SlowDownWriteThreshold);
         if (_handlers == null)
         {
             return;
         }
         foreach (var hnd in _handlers)
         {
             Core.Status.AttachChild(hnd, this);
         }
     }, this);
 }