Пример #1
0
 public void Verify()
 {
     if (StorageEngine == null && BasePath != null)
     {
         StorageEngine = new FileStorageEngine(BasePath);
     }
 }
Пример #2
0
        private static IStorageEngine GetStorageEngine(string storageName, string basePath)
        {
            if (!Directory.Exists(basePath))
            {
                Directory.CreateDirectory(basePath);
            }
            IStorageEngine storageEngine = null;

            switch (storageName)
            {
            case nameof(FileStorageEngine):
                storageEngine = new FileStorageEngine(basePath);
                break;

            case nameof(ZipStorageEngine):
                storageEngine = new ZipStorageEngine(new MemoryStream(), ZipStorageEngineMode.Write, true);
                var dic      = new DirectoryInfo(basePath);
                var allFiles = dic.GetFiles("*", SearchOption.AllDirectories);
                foreach (var file in allFiles)
                {
                    var location    = file.FullName.Replace(dic.FullName, "").TrimStart('/').TrimStart('\\');
                    var fileContent = new FileContent(location, File.ReadAllText(file.FullName));
                    storageEngine.WriteFile(location, fileContent).GetAwaiter().GetResult();
                }
                break;

            default:
                throw new ArgumentOutOfRangeException(storageName);
            }

            return(storageEngine);
        }